@@ -10,12 +10,13 @@ import { EndAdornmentText, FilterTitleButton } from './style';
1010interface FilterSectionProps {
1111 filterKey : string ;
1212 sectionDisplayName ?: string ;
13- options : FilterOption [ ] ;
13+ options ? : FilterOption [ ] ;
1414 filters : FilterValues ;
1515 openSections : Record < string , boolean > ;
16- onCheckboxChange : ( filterKey : string , value : string , checked : boolean ) => void ;
16+ onCheckboxChange ? : ( filterKey : string , value : string , checked : boolean ) => void ;
1717 onSectionToggle : ( filterKey : string ) => void ;
1818 styleProps : StyleProps ;
19+ customComponent ?: React . ComponentType ;
1920}
2021
2122/**
@@ -33,12 +34,13 @@ interface FilterSectionProps {
3334const FilterSection : React . FC < FilterSectionProps > = ( {
3435 filterKey,
3536 sectionDisplayName,
36- options,
37+ options = [ ] ,
3738 filters,
3839 openSections,
3940 onCheckboxChange,
4041 onSectionToggle,
41- styleProps
42+ styleProps,
43+ customComponent : CustomComponent
4244} ) => {
4345 const [ searchQuery , setSearchQuery ] = useState < string > ( '' ) ;
4446
@@ -47,9 +49,10 @@ const FilterSection: React.FC<FilterSectionProps> = ({
4749 } , [ ] ) ;
4850
4951 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 ;
5356
5457 return (
5558 < >
@@ -65,59 +68,66 @@ const FilterSection: React.FC<FilterSectionProps> = ({
6568 { openSections [ filterKey ] ? < ExpandLessIcon /> : < ExpandMoreIcon /> }
6669 </ FilterTitleButton >
6770 < 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 >
10390 }
104- onChange = { ( e ) => onCheckboxChange ( filterKey , option . value , e . target . checked ) }
105- value = { option . value }
10691 />
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+ />
107116
108- { option . Icon && < option . Icon width = "20px" height = "20px" /> }
117+ { option . Icon && < option . Icon width = "20px" height = "20px" /> }
109118
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 >
111127 </ 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+ ) }
121131 </ Collapse >
122132 </ >
123133 ) ;
0 commit comments