@@ -10,12 +10,13 @@ import { EndAdornmentText, FilterTitleButton } from './style';
10
10
interface FilterSectionProps {
11
11
filterKey : string ;
12
12
sectionDisplayName ?: string ;
13
- options : FilterOption [ ] ;
13
+ options ? : FilterOption [ ] ;
14
14
filters : FilterValues ;
15
15
openSections : Record < string , boolean > ;
16
- onCheckboxChange : ( filterKey : string , value : string , checked : boolean ) => void ;
16
+ onCheckboxChange ? : ( filterKey : string , value : string , checked : boolean ) => void ;
17
17
onSectionToggle : ( filterKey : string ) => void ;
18
18
styleProps : StyleProps ;
19
+ customComponent ?: React . ComponentType ;
19
20
}
20
21
21
22
/**
@@ -33,12 +34,13 @@ interface FilterSectionProps {
33
34
const FilterSection : React . FC < FilterSectionProps > = ( {
34
35
filterKey,
35
36
sectionDisplayName,
36
- options,
37
+ options = [ ] ,
37
38
filters,
38
39
openSections,
39
40
onCheckboxChange,
40
41
onSectionToggle,
41
- styleProps
42
+ styleProps,
43
+ customComponent : CustomComponent
42
44
} ) => {
43
45
const [ searchQuery , setSearchQuery ] = useState < string > ( '' ) ;
44
46
@@ -47,9 +49,10 @@ const FilterSection: React.FC<FilterSectionProps> = ({
47
49
} , [ ] ) ;
48
50
49
51
const showSearch = options . length > 10 ;
50
- const searchedOptions = searchQuery
51
- ? options . filter ( ( option ) => option . label . toLowerCase ( ) . includes ( searchQuery . toLowerCase ( ) ) )
52
- : options ;
52
+ const searchedOptions =
53
+ searchQuery && options . length
54
+ ? options . filter ( ( option ) => option . label . toLowerCase ( ) . includes ( searchQuery . toLowerCase ( ) ) )
55
+ : options ;
53
56
54
57
return (
55
58
< >
@@ -65,59 +68,66 @@ const FilterSection: React.FC<FilterSectionProps> = ({
65
68
{ openSections [ filterKey ] ? < ExpandLessIcon /> : < ExpandMoreIcon /> }
66
69
</ FilterTitleButton >
67
70
< Collapse in = { openSections [ filterKey ] } timeout = "auto" unmountOnExit >
68
- < List
69
- component = "div"
70
- sx = { {
71
- overflowY : 'auto' ,
72
- maxHeight : '25rem' ,
73
- backgroundColor : styleProps . backgroundColor
74
- } }
75
- >
76
- { showSearch && (
77
- < Box px = { '0.5rem' } mb = { '0.5rem' } >
78
- < StyledSearchBar
79
- value = { searchQuery }
80
- onChange = { handleTextFieldChange }
81
- placeholder = "Search"
82
- endAdornment = {
83
- < EndAdornmentText > Total : { searchedOptions . length ?? 0 } </ EndAdornmentText >
84
- }
85
- />
86
- </ Box >
87
- ) }
88
- { searchedOptions . map ( ( option , index ) => (
89
- < Stack
90
- key = { `${ option . value } -${ index } ` }
91
- direction = "row"
92
- alignItems = "center"
93
- px = { '0.5rem' }
94
- justifyContent = "space-between"
95
- >
96
- < Stack direction = "row" alignItems = "center" gap = "0.35rem" >
97
- < Checkbox
98
- id = { `checkbox-${ option . label } ` }
99
- checked = {
100
- Array . isArray ( filters [ filterKey ] )
101
- ? ( filters [ filterKey ] as string [ ] ) . includes ( option . value )
102
- : filters [ filterKey ] === option . value
71
+ { CustomComponent ? (
72
+ < CustomComponent />
73
+ ) : (
74
+ < List
75
+ component = "div"
76
+ sx = { {
77
+ overflowY : 'auto' ,
78
+ maxHeight : '25rem' ,
79
+ backgroundColor : styleProps . backgroundColor
80
+ } }
81
+ >
82
+ { showSearch && (
83
+ < Box px = { '0.5rem' } mb = { '0.5rem' } >
84
+ < StyledSearchBar
85
+ value = { searchQuery }
86
+ onChange = { handleTextFieldChange }
87
+ placeholder = "Search"
88
+ endAdornment = {
89
+ < EndAdornmentText > Total : { searchedOptions . length ?? 0 } </ EndAdornmentText >
103
90
}
104
- onChange = { ( e ) => onCheckboxChange ( filterKey , option . value , e . target . checked ) }
105
- value = { option . value }
106
91
/>
92
+ </ Box >
93
+ ) }
94
+ { searchedOptions . map ( ( option , index ) => (
95
+ < Stack
96
+ key = { `${ option . value } -${ index } ` }
97
+ direction = "row"
98
+ alignItems = "center"
99
+ px = { '0.5rem' }
100
+ justifyContent = "space-between"
101
+ >
102
+ < Stack direction = "row" alignItems = "center" gap = "0.35rem" >
103
+ < Checkbox
104
+ id = { `checkbox-${ option . label } ` }
105
+ checked = {
106
+ Array . isArray ( filters [ filterKey ] )
107
+ ? ( filters [ filterKey ] as string [ ] ) . includes ( option . value )
108
+ : filters [ filterKey ] === option . value
109
+ }
110
+ onChange = { ( e ) =>
111
+ onCheckboxChange &&
112
+ onCheckboxChange ( filterKey , option . value , e . target . checked )
113
+ }
114
+ value = { option . value }
115
+ />
107
116
108
- { option . Icon && < option . Icon width = "20px" height = "20px" /> }
117
+ { option . Icon && < option . Icon width = "20px" height = "20px" /> }
109
118
110
- < Typography fontFamily = { styleProps . fontFamily } > { option . label } </ Typography >
119
+ < Typography fontFamily = { styleProps . fontFamily } > { option . label } </ Typography >
120
+ </ Stack >
121
+ < Stack direction = "row" alignItems = "center" gap = "0.35rem" >
122
+ { option . totalCount !== undefined && `(${ option . totalCount || 0 } )` }
123
+ { option . description && (
124
+ < InfoTooltip variant = "standard" helpText = { option . description } />
125
+ ) }
126
+ </ Stack >
111
127
</ Stack >
112
- < Stack direction = "row" alignItems = "center" gap = "0.35rem" >
113
- { option . totalCount !== undefined && `(${ option . totalCount || 0 } )` }
114
- { option . description && (
115
- < InfoTooltip variant = "standard" helpText = { option . description } />
116
- ) }
117
- </ Stack >
118
- </ Stack >
119
- ) ) }
120
- </ List >
128
+ ) ) }
129
+ </ List >
130
+ ) }
121
131
</ Collapse >
122
132
</ >
123
133
) ;
0 commit comments