Skip to content

Commit 85a149c

Browse files
committed
feat: add support for disabled tippy
1 parent 4e4276a commit 85a149c

File tree

2 files changed

+37
-21
lines changed

2 files changed

+37
-21
lines changed

src/Shared/Components/SelectPicker/SelectPicker.component.tsx

Lines changed: 33 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
import ReactSelect, { ControlProps, MenuProps } from 'react-select'
2-
import { useCallback, useMemo } from 'react'
2+
import { ReactElement, useCallback, useMemo } from 'react'
33
import { ReactComponent as ErrorIcon } from '@Icons/ic-warning.svg'
44
import { ReactComponent as ICInfoFilledOverride } from '@Icons/ic-info-filled-override.svg'
55
import { ComponentSizeType } from '@Shared/constants'
6+
import { ConditionalWrap } from '@Common/Helper'
7+
import Tippy from '@tippyjs/react'
68
import { getCommonSelectStyle } from './utils'
79
import {
810
SelectPickerClearIndicator,
@@ -23,9 +25,10 @@ const SelectPicker = ({
2325
label,
2426
showSelectedOptionIcon = true,
2527
size = ComponentSizeType.medium,
28+
disabledTippyContent,
2629
...props
2730
}: SelectPickerProps) => {
28-
const { inputId, required } = props
31+
const { inputId, required, isDisabled } = props
2932

3033
const selectStyles = useMemo(
3134
() =>
@@ -50,6 +53,12 @@ const SelectPicker = ({
5053
[],
5154
)
5255

56+
const renderDisabledTippy = (children: ReactElement) => (
57+
<Tippy content={disabledTippyContent} placement="top" className="default-tt" arrow={false}>
58+
{children}
59+
</Tippy>
60+
)
61+
5362
return (
5463
<div className="flex column left top dc__gap-4">
5564
{/* TODO Eshank: Common out for fields */}
@@ -70,25 +79,28 @@ const SelectPicker = ({
7079
)}
7180
</label>
7281
)}
73-
<ReactSelect<SelectPickerOptionType, boolean>
74-
{...props}
75-
placeholder={placeholder}
76-
components={{
77-
IndicatorSeparator: null,
78-
LoadingIndicator: SelectPickerLoadingIndicator,
79-
DropdownIndicator: SelectPickerDropdownIndicator,
80-
Control: renderControl,
81-
Option: SelectPickerOption,
82-
Menu: renderMenu,
83-
ClearIndicator: SelectPickerClearIndicator,
84-
}}
85-
styles={selectStyles}
86-
className="w-100"
87-
menuPlacement="auto"
88-
menuPosition="fixed"
89-
menuShouldScrollIntoView
90-
backspaceRemovesValue={false}
91-
/>
82+
<ConditionalWrap condition={isDisabled && !!disabledTippyContent} wrap={renderDisabledTippy}>
83+
<div className="w-100">
84+
<ReactSelect<SelectPickerOptionType, boolean>
85+
{...props}
86+
placeholder={placeholder}
87+
components={{
88+
IndicatorSeparator: null,
89+
LoadingIndicator: SelectPickerLoadingIndicator,
90+
DropdownIndicator: SelectPickerDropdownIndicator,
91+
Control: renderControl,
92+
Option: SelectPickerOption,
93+
Menu: renderMenu,
94+
ClearIndicator: SelectPickerClearIndicator,
95+
}}
96+
styles={selectStyles}
97+
menuPlacement="auto"
98+
menuPosition="fixed"
99+
menuShouldScrollIntoView
100+
backspaceRemovesValue={false}
101+
/>
102+
</div>
103+
</ConditionalWrap>
92104
</div>
93105
{error && (
94106
<div className="flex left dc__gap-4 cr-5 fs-11 lh-16 fw-4">

src/Shared/Components/SelectPicker/type.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,8 @@ export interface SelectPickerProps
4848
* @default 'ComponentSizeType.medium'
4949
*/
5050
size?: Extract<ComponentSizeType, ComponentSizeType.medium | ComponentSizeType.large>
51+
/**
52+
* Content to be shown in a tippy when disabled
53+
*/
54+
disabledTippyContent?: ReactNode
5155
}

0 commit comments

Comments
 (0)