Skip to content

Commit 3d92d9b

Browse files
committed
feat: add support for options
1 parent 5b486b0 commit 3d92d9b

File tree

4 files changed

+48
-8
lines changed

4 files changed

+48
-8
lines changed

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,13 @@ import ReactSelect, { ControlProps, Props as ReactSelectProps } from 'react-sele
22
import { ReactNode, useCallback, useMemo } from 'react'
33
import { ReactComponent as ErrorIcon } from '@Icons/ic-warning.svg'
44
import { getCommonSelectStyle } from './utils'
5-
import { ControlWithIcon, DropdownIndicator, LoadingIndicator } from './common'
5+
import { ControlWithIcon, DropdownIndicator, SingleSelectOption, LoadingIndicator } from './common'
6+
import { SelectPickerOptionType } from './type'
67

78
export interface SelectPickerProps
89
extends Pick<
910
ReactSelectProps,
1011
| 'isMulti'
11-
| 'options'
12-
| 'value'
1312
| 'onChange'
1413
| 'isSearchable'
1514
| 'isClearable'
@@ -25,6 +24,8 @@ export interface SelectPickerProps
2524
> {
2625
icon?: ReactNode
2726
error?: ReactNode
27+
options: SelectPickerOptionType[]
28+
value?: SelectPickerOptionType
2829
}
2930

3031
const SelectPicker = ({ error, icon, placeholder = 'Select a option', ...props }: SelectPickerProps) => {
@@ -43,15 +44,15 @@ const SelectPicker = ({ error, icon, placeholder = 'Select a option', ...props }
4344

4445
return (
4546
<div>
46-
<ReactSelect
47+
<ReactSelect<SelectPickerOptionType, boolean>
4748
{...props}
4849
placeholder={placeholder}
4950
components={{
5051
IndicatorSeparator: null,
5152
LoadingIndicator,
5253
DropdownIndicator,
5354
Control: renderControl,
54-
// Option,
55+
Option: SingleSelectOption,
5556
// ValueContainer,
5657
}}
5758
styles={selectStyles}

src/Shared/Components/SelectPicker/common.tsx

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
import { components, DropdownIndicatorProps, ControlProps } from 'react-select'
1+
import { components, DropdownIndicatorProps, ControlProps, OptionProps } from 'react-select'
22
import { ReactComponent as ICCaretDown } from '@Icons/ic-caret-down.svg'
33
import { Progressing } from '@Common/Progressing'
44
import { SelectPickerProps } from './SelectPicker.component'
5+
import { SelectPickerOptionType } from './type'
56

67
export const DropdownIndicator = (props: DropdownIndicatorProps) => {
78
const { isDisabled } = props
@@ -25,3 +26,25 @@ export const ControlWithIcon = ({ icon, ...props }: ControlProps & Pick<SelectPi
2526
}
2627

2728
export const LoadingIndicator = () => <Progressing />
29+
30+
export const SingleSelectOption = (props: OptionProps<SelectPickerOptionType>) => {
31+
const { label, data } = props
32+
const { description, startIcon, endIcon } = data ?? {}
33+
const showDescription = !!description
34+
35+
return (
36+
<components.Option {...props}>
37+
<div className={`flex left ${showDescription ? 'top' : ''} dc__gap-8`}>
38+
{startIcon && (
39+
<div className="dc__no-shrink icon-dim-16 flex dc__fill-available-space">{startIcon}</div>
40+
)}
41+
<div className="flex-grow-1">
42+
<h4 className="m-0 cn-9 fs-13 fw-4 lh-20 dc__truncate">{label}</h4>
43+
{/* TODO Eshank: Add support for custom ellipsis */}
44+
{showDescription && <p className="m-0 fs-12 fw-4 lh-18 cn-7 dc__truncate">{description}</p>}
45+
</div>
46+
{endIcon && <div className="dc__no-shrink icon-dim-16 flex dc__fill-available-space">{endIcon}</div>}
47+
</div>
48+
</components.Option>
49+
)
50+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { OptionType } from '@Common/Types'
2+
import { ReactNode } from 'react'
3+
4+
// TODO Eshank: Make this configurable
5+
export interface SelectPickerOptionType extends OptionType<number | string, ReactNode> {
6+
description?: string
7+
startIcon?: ReactNode
8+
endIcon?: ReactNode
9+
}

src/Shared/Components/SelectPicker/utils.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,13 @@ export const getCommonSelectStyle = ({ hasError }: { hasError: boolean }) => ({
66
pointerEvents: 'auto',
77
}),
88
}),
9+
menu: (base) => ({
10+
...base,
11+
overflow: 'hidden',
12+
marginBlock: '4px',
13+
backgroundColor: 'var(--N0)',
14+
boxShadow: '0px 2px 4px 0px rgba(0, 0, 0, 0.20)',
15+
}),
916
menuList: (base) => ({
1017
...base,
1118
padding: 0,
@@ -35,8 +42,8 @@ export const getCommonSelectStyle = ({ hasError }: { hasError: boolean }) => ({
3542
...base,
3643
color: 'var(--N900)',
3744
// eslint-disable-next-line no-nested-ternary
38-
backgroundColor: state.isSelected ? 'var(--B100)' : state.isFocused ? 'var(--N100)' : 'white',
39-
padding: '10px 12px',
45+
backgroundColor: state.isSelected ? 'var(--B100)' : state.isFocused ? 'var(--N50)' : 'var(--N0)',
46+
padding: '6px 8px',
4047
cursor: 'pointer',
4148
fontSize: '13px',
4249
lineHeight: '20px',

0 commit comments

Comments
 (0)