Skip to content

Commit 02cc0dd

Browse files
committed
feat: add support for rendering footer
1 parent 3d92d9b commit 02cc0dd

File tree

3 files changed

+51
-19
lines changed

3 files changed

+51
-19
lines changed

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

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
1-
import ReactSelect, { ControlProps, Props as ReactSelectProps } from 'react-select'
2-
import { ReactNode, useCallback, useMemo } from 'react'
1+
import ReactSelect, { ControlProps, MenuProps, Props as ReactSelectProps } from 'react-select'
2+
import { ReactElement, ReactNode, useCallback, useMemo } from 'react'
33
import { ReactComponent as ErrorIcon } from '@Icons/ic-warning.svg'
44
import { getCommonSelectStyle } from './utils'
5-
import { ControlWithIcon, DropdownIndicator, SingleSelectOption, LoadingIndicator } from './common'
5+
import {
6+
SelectPickerControl,
7+
SelectPickerDropdownIndicator,
8+
SelectPickerMenu,
9+
SelectPickerOption,
10+
SelectPickerLoadingIndicator,
11+
} from './common'
612
import { SelectPickerOptionType } from './type'
713

814
export interface SelectPickerProps
@@ -22,13 +28,20 @@ export interface SelectPickerProps
2228
| 'isLoading'
2329
| 'inputId'
2430
> {
25-
icon?: ReactNode
31+
icon?: ReactElement
2632
error?: ReactNode
2733
options: SelectPickerOptionType[]
2834
value?: SelectPickerOptionType
35+
renderMenuListFooter: () => ReactNode
2936
}
3037

31-
const SelectPicker = ({ error, icon, placeholder = 'Select a option', ...props }: SelectPickerProps) => {
38+
const SelectPicker = ({
39+
error,
40+
icon,
41+
renderMenuListFooter,
42+
placeholder = 'Select a option',
43+
...props
44+
}: SelectPickerProps) => {
3245
const selectStyles = useMemo(
3346
() =>
3447
getCommonSelectStyle({
@@ -38,24 +51,30 @@ const SelectPicker = ({ error, icon, placeholder = 'Select a option', ...props }
3851
)
3952

4053
const renderControl = useCallback(
41-
(controlProps: ControlProps) => <ControlWithIcon {...controlProps} icon={icon} />,
54+
(controlProps: ControlProps) => <SelectPickerControl {...controlProps} icon={icon} />,
4255
[icon],
4356
)
4457

58+
const renderMenu = useCallback(
59+
(menuProps: MenuProps) => <SelectPickerMenu {...menuProps} renderMenuListFooter={renderMenuListFooter} />,
60+
[],
61+
)
62+
4563
return (
4664
<div>
4765
<ReactSelect<SelectPickerOptionType, boolean>
4866
{...props}
4967
placeholder={placeholder}
5068
components={{
5169
IndicatorSeparator: null,
52-
LoadingIndicator,
53-
DropdownIndicator,
70+
LoadingIndicator: SelectPickerLoadingIndicator,
71+
DropdownIndicator: SelectPickerDropdownIndicator,
5472
Control: renderControl,
55-
Option: SingleSelectOption,
56-
// ValueContainer,
73+
Option: SelectPickerOption,
74+
Menu: renderMenu,
5775
}}
5876
styles={selectStyles}
77+
menuIsOpen
5978
/>
6079
{error && (
6180
<div className="flex left dc__gap-4 cr-5 fs-11 lh-16 fw-4">

src/Shared/Components/SelectPicker/common.tsx

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
import { components, DropdownIndicatorProps, ControlProps, OptionProps } from 'react-select'
1+
import { components, DropdownIndicatorProps, ControlProps, OptionProps, MenuProps } 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'
55
import { SelectPickerOptionType } from './type'
66

7-
export const DropdownIndicator = (props: DropdownIndicatorProps) => {
7+
export const SelectPickerDropdownIndicator = (props: DropdownIndicatorProps) => {
88
const { isDisabled } = props
99

1010
return (
@@ -14,7 +14,7 @@ export const DropdownIndicator = (props: DropdownIndicatorProps) => {
1414
)
1515
}
1616

17-
export const ControlWithIcon = ({ icon, ...props }: ControlProps & Pick<SelectPickerProps, 'icon'>) => {
17+
export const SelectPickerControl = ({ icon, ...props }: ControlProps & Pick<SelectPickerProps, 'icon'>) => {
1818
const { children } = props
1919

2020
return (
@@ -25,9 +25,9 @@ export const ControlWithIcon = ({ icon, ...props }: ControlProps & Pick<SelectPi
2525
)
2626
}
2727

28-
export const LoadingIndicator = () => <Progressing />
28+
export const SelectPickerLoadingIndicator = () => <Progressing />
2929

30-
export const SingleSelectOption = (props: OptionProps<SelectPickerOptionType>) => {
30+
export const SelectPickerOption = (props: OptionProps<SelectPickerOptionType>) => {
3131
const { label, data } = props
3232
const { description, startIcon, endIcon } = data ?? {}
3333
const showDescription = !!description
@@ -48,3 +48,17 @@ export const SingleSelectOption = (props: OptionProps<SelectPickerOptionType>) =
4848
</components.Option>
4949
)
5050
}
51+
52+
export const SelectPickerMenu = ({
53+
renderMenuListFooter,
54+
...props
55+
}: MenuProps & Pick<SelectPickerProps, 'renderMenuListFooter'>) => {
56+
const { children } = props
57+
58+
return (
59+
<components.Menu {...props}>
60+
{children}
61+
{renderMenuListFooter()}
62+
</components.Menu>
63+
)
64+
}
Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
import { OptionType } from '@Common/Types'
2-
import { ReactNode } from 'react'
2+
import { ReactElement, ReactNode } from 'react'
33

4-
// TODO Eshank: Make this configurable
54
export interface SelectPickerOptionType extends OptionType<number | string, ReactNode> {
65
description?: string
7-
startIcon?: ReactNode
8-
endIcon?: ReactNode
6+
startIcon?: ReactElement
7+
endIcon?: ReactElement
98
}

0 commit comments

Comments
 (0)