Skip to content

Commit b58d82b

Browse files
committed
feat: SelectPicker - add support to show tippy on option
1 parent ddff3ac commit b58d82b

File tree

2 files changed

+45
-31
lines changed

2 files changed

+45
-31
lines changed

src/Shared/Components/SelectPicker/common.tsx

Lines changed: 40 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
* limitations under the License.
1515
*/
1616

17+
import Tippy, { TippyProps } from '@tippyjs/react'
1718
import {
1819
components,
1920
DropdownIndicatorProps,
@@ -31,14 +32,20 @@ import { ReactComponent as ICCaretDown } from '@Icons/ic-caret-down.svg'
3132
import { ReactComponent as ICClose } from '@Icons/ic-close.svg'
3233
import { ReactComponent as ICErrorExclamation } from '@Icons/ic-error-exclamation.svg'
3334
import { ChangeEvent } from 'react'
34-
import { noop } from '@Common/Helper'
35+
import { ConditionalWrap, noop } from '@Common/Helper'
3536
import { CHECKBOX_VALUE } from '@Common/Types'
3637
import { Checkbox } from '@Common/Checkbox'
3738
import { ReactSelectInputAction } from '@Common/Constants'
3839
import { isNullOrUndefined } from '@Shared/Helpers'
3940
import { SelectPickerGroupHeadingProps, SelectPickerOptionType, SelectPickerProps } from './type'
4041
import { getGroupCheckboxValue } from './utils'
4142

43+
const renderWithTippy = (tippyProps: TippyProps) => (children: React.ReactElement) => (
44+
<Tippy {...tippyProps} className={`default-tt ${tippyProps?.className || ''}`}>
45+
{children}
46+
</Tippy>
47+
)
48+
4249
export const SelectPickerDropdownIndicator = <OptionValue,>(
4350
props: DropdownIndicatorProps<SelectPickerOptionType<OptionValue>>,
4451
) => {
@@ -124,7 +131,7 @@ export const SelectPickerOption = <OptionValue, IsMulti extends boolean>({
124131
isDisabled,
125132
isSelected,
126133
} = props
127-
const { description, startIcon, endIcon } = data ?? {}
134+
const { description, startIcon, endIcon, tooltipProps } = data ?? {}
128135
const showDescription = !!description
129136
// __isNew__ denotes the new option to be created
130137
const isCreatableOption = '__isNew__' in data && data.__isNew__
@@ -137,39 +144,41 @@ export const SelectPickerOption = <OptionValue, IsMulti extends boolean>({
137144

138145
return (
139146
<components.Option {...props}>
140-
<div className="flexbox dc__align-items-center dc__gap-8">
141-
{isMulti && !isCreatableOption && (
142-
<Checkbox
143-
onChange={noop}
144-
onClick={handleChange}
145-
isChecked={isSelected || false}
146-
value={CHECKBOX_VALUE.CHECKED}
147-
rootClassName="mb-0 w-20 p-2 dc__align-self-start dc__no-shrink"
148-
disabled={isDisabled}
149-
/>
150-
)}
151-
<div className={`flex left ${showDescription ? 'top' : ''} dc__gap-8`}>
152-
{startIcon && (
153-
<div className="dc__no-shrink icon-dim-20 flex dc__fill-available-space">{startIcon}</div>
147+
<ConditionalWrap condition={!!tooltipProps?.content} wrap={renderWithTippy(tooltipProps)}>
148+
<div className="flexbox dc__align-items-center dc__gap-8">
149+
{isMulti && !isCreatableOption && (
150+
<Checkbox
151+
onChange={noop}
152+
onClick={handleChange}
153+
isChecked={isSelected || false}
154+
value={CHECKBOX_VALUE.CHECKED}
155+
rootClassName="mb-0 w-20 p-2 dc__align-self-start dc__no-shrink"
156+
disabled={isDisabled}
157+
/>
154158
)}
155-
<div className="flex-grow-1">
156-
<h4 className={`m-0 fs-13 ${isCreatableOption ? 'cb-5' : 'cn-9'} fw-4 lh-20 dc__truncate`}>
157-
{label}
158-
</h4>
159-
{/* Add support for custom ellipsis if required */}
160-
{showDescription && (
161-
<p
162-
className={`m-0 fs-12 fw-4 lh-18 cn-7 ${!disableDescriptionEllipsis ? 'dc__ellipsis-right__2nd-line' : ''}`}
163-
>
164-
{description}
165-
</p>
159+
<div className={`flex left ${showDescription ? 'top' : ''} dc__gap-8`}>
160+
{startIcon && (
161+
<div className="dc__no-shrink icon-dim-20 flex dc__fill-available-space">{startIcon}</div>
162+
)}
163+
<div className="flex-grow-1">
164+
<h4 className={`m-0 fs-13 ${isCreatableOption ? 'cb-5' : 'cn-9'} fw-4 lh-20 dc__truncate`}>
165+
{label}
166+
</h4>
167+
{/* Add support for custom ellipsis if required */}
168+
{showDescription && (
169+
<p
170+
className={`m-0 fs-12 fw-4 lh-18 cn-7 ${!disableDescriptionEllipsis ? 'dc__ellipsis-right__2nd-line' : ''}`}
171+
>
172+
{description}
173+
</p>
174+
)}
175+
</div>
176+
{endIcon && (
177+
<div className="dc__no-shrink icon-dim-20 flex dc__fill-available-space">{endIcon}</div>
166178
)}
167179
</div>
168-
{endIcon && (
169-
<div className="dc__no-shrink icon-dim-20 flex dc__fill-available-space">{endIcon}</div>
170-
)}
171180
</div>
172-
</div>
181+
</ConditionalWrap>
173182
</components.Option>
174183
)
175184
}

src/Shared/Components/SelectPicker/type.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import { GroupBase, GroupHeadingProps, Props as ReactSelectProps, SelectInstance
2222
import { CreatableProps } from 'react-select/creatable'
2323
// This import allows to extend the base interface in react-select module via module augmentation
2424
import type {} from 'react-select/base'
25+
import { TippyProps } from '@tippyjs/react'
2526

2627
export interface SelectPickerOptionType<OptionValue = string | number> extends OptionType<OptionValue, ReactNode> {
2728
/**
@@ -36,6 +37,10 @@ export interface SelectPickerOptionType<OptionValue = string | number> extends O
3637
* Icon at the end of the option
3738
*/
3839
endIcon?: ReactElement
40+
/**
41+
* Props passed to show the tippy on option
42+
*/
43+
tooltipProps?: TippyProps
3944
}
4045

4146
type SelectProps<OptionValue, IsMulti extends boolean> = ReactSelectProps<

0 commit comments

Comments
 (0)