Skip to content

Commit c777e95

Browse files
committed
feat: add helper text and update disabled state
1 parent 50737bf commit c777e95

File tree

2 files changed

+74
-36
lines changed

2 files changed

+74
-36
lines changed

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

Lines changed: 70 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,57 @@
11
import ReactSelect, { ControlProps, MenuProps, Props as ReactSelectProps } from 'react-select'
22
import { ReactElement, ReactNode, useCallback, useMemo } from 'react'
33
import { ReactComponent as ErrorIcon } from '@Icons/ic-warning.svg'
4+
import { ReactComponent as ICInfoFilledOverride } from '@Icons/ic-info-filled-override.svg'
45
import { getCommonSelectStyle } from './utils'
56
import {
67
SelectPickerControl,
78
SelectPickerDropdownIndicator,
9+
SelectPickerLoadingIndicator,
810
SelectPickerMenu,
911
SelectPickerOption,
10-
SelectPickerLoadingIndicator,
1112
} from './common'
1213
import { SelectPickerOptionType } from './type'
1314

15+
type SelectProps = ReactSelectProps<SelectPickerOptionType>
16+
1417
export interface SelectPickerProps
1518
extends Pick<
16-
ReactSelectProps<SelectPickerOptionType>,
17-
| 'options'
18-
| 'value'
19-
| 'isMulti'
20-
| 'onChange'
21-
| 'isSearchable'
22-
| 'isClearable'
23-
| 'isLoading'
24-
| 'placeholder'
25-
| 'hideSelectedOptions'
26-
| 'controlShouldRenderValue'
27-
| 'backspaceRemovesValue'
28-
| 'closeMenuOnSelect'
29-
| 'isDisabled'
30-
| 'isLoading'
31-
| 'inputId'
32-
> {
19+
SelectProps,
20+
| 'options'
21+
| 'value'
22+
| 'isMulti'
23+
| 'onChange'
24+
| 'isSearchable'
25+
| 'isClearable'
26+
| 'isLoading'
27+
| 'placeholder'
28+
| 'hideSelectedOptions'
29+
| 'controlShouldRenderValue'
30+
| 'backspaceRemovesValue'
31+
| 'closeMenuOnSelect'
32+
| 'isDisabled'
33+
| 'isLoading'
34+
| 'required'
35+
>,
36+
Required<Pick<SelectProps, 'classNamePrefix' | 'inputId'>> {
3337
icon?: ReactElement
3438
error?: ReactNode
3539
renderMenuListFooter?: () => ReactNode
40+
helperText?: ReactNode
41+
label?: ReactNode
3642
}
3743

3844
const SelectPicker = ({
3945
error,
4046
icon,
4147
renderMenuListFooter,
48+
helperText,
4249
placeholder = 'Select a option',
50+
label,
4351
...props
4452
}: SelectPickerProps) => {
53+
const { inputId, required } = props
54+
4555
const selectStyles = useMemo(
4656
() =>
4757
getCommonSelectStyle({
@@ -61,26 +71,53 @@ const SelectPicker = ({
6171
)
6272

6373
return (
64-
<div>
65-
<ReactSelect<SelectPickerOptionType, boolean>
66-
{...props}
67-
placeholder={placeholder}
68-
components={{
69-
IndicatorSeparator: null,
70-
LoadingIndicator: SelectPickerLoadingIndicator,
71-
DropdownIndicator: SelectPickerDropdownIndicator,
72-
Control: renderControl,
73-
Option: SelectPickerOption,
74-
Menu: renderMenu,
75-
}}
76-
styles={selectStyles}
77-
/>
74+
<div className="flex column left top dc__gap-4">
75+
{/* TODO Eshank: Common out for fields */}
76+
<div className="flex column left top dc__gap-6 w-100">
77+
{label && (
78+
<label
79+
className="fs-13 lh-20 cn-7 fw-4 dc__block mb-0"
80+
htmlFor={inputId}
81+
data-testid={`label-${inputId}`}
82+
>
83+
{typeof label === 'string' ? (
84+
<span className={`flex left ${required ? 'dc__required-field' : ''}`}>
85+
<span className="dc__truncate">{label}</span>
86+
</span>
87+
) : (
88+
label
89+
)}
90+
</label>
91+
)}
92+
<ReactSelect<SelectPickerOptionType, boolean>
93+
{...props}
94+
placeholder={placeholder}
95+
components={{
96+
IndicatorSeparator: null,
97+
LoadingIndicator: SelectPickerLoadingIndicator,
98+
DropdownIndicator: SelectPickerDropdownIndicator,
99+
Control: renderControl,
100+
Option: SelectPickerOption,
101+
Menu: renderMenu,
102+
// TODO Eshank: need to export variants of ValueContainer: Icon, No Icon etc
103+
}}
104+
styles={selectStyles}
105+
className="w-100"
106+
/>
107+
</div>
78108
{error && (
79109
<div className="flex left dc__gap-4 cr-5 fs-11 lh-16 fw-4">
80110
<div className="dc__no-shrink dc__align-self-start p-2">
81111
<ErrorIcon className="icon-dim-12 form__icon--error" />
82112
</div>
83-
<span>{error}</span>
113+
<span className="dc__ellipsis-right__2nd-line">{error}</span>
114+
</div>
115+
)}
116+
{/* TODO Eshank: Common out for input fields */}
117+
{helperText && (
118+
<div className="flex left dc__gap-4 fs-11 lh-16 cn-7">
119+
<ICInfoFilledOverride className="icon-dim-16 dc__no-shrink dc__align-self-start" />
120+
<span className="dc__ellipsis-right__2nd-line">{helperText}</span>
84121
</div>
85122
)}
86123
</div>

src/Shared/Components/SelectPicker/utils.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,12 @@ export const getCommonSelectStyle = ({ hasError }: { hasError: boolean }) => ({
2424
// Add support for configurable: 36px, 28px
2525
minHeight: 'auto',
2626
boxShadow: 'none',
27-
backgroundColor: state.isDisabled ? 'var(--N100)' : 'var(--N50)',
27+
backgroundColor: 'var(--N50)',
2828
border: `1px solid ${hasError ? 'var(--R500)' : 'var(--N200)'}`,
2929
cursor: state.isDisabled ? 'not-allowed' : 'pointer',
3030
padding: '5px 8px',
3131
gap: '8px',
32+
opacity: state.isDisabled ? 0.5 : 1,
3233

3334
'&:hover': {
3435
borderColor: state.isDisabled ? 'var(--N200)' : 'var(--N300)',
@@ -100,9 +101,9 @@ export const getCommonSelectStyle = ({ hasError }: { hasError: boolean }) => ({
100101
fontWeight: 400,
101102
lineHeight: '20px',
102103
}),
103-
placeholder: (base, state) => ({
104+
placeholder: (base) => ({
104105
...base,
105-
color: state.isDisabled ? 'var(--N600)' : 'var(--N500)',
106+
color: 'var(--N500)',
106107
fontSize: '13px',
107108
lineHeight: '20px',
108109
fontWeight: 400,

0 commit comments

Comments
 (0)