1- import React , { useState } from 'react' ;
1+ import React from 'react' ;
22import {
33 Accordion ,
44 AccordionContent ,
@@ -10,106 +10,71 @@ import {
1010 Text ,
1111} from 'opub-ui' ;
1212
13+ import { toTitleCase } from '@/lib/utils' ;
1314import { Icons } from '@/components/icons' ;
1415
1516interface FilterProps {
1617 setOpen ?: ( isOpen : boolean ) => void ;
18+ options : Record < string , { label : string ; value : string } [ ] > ;
19+ setSelectedOptions : ( category : string , values : string [ ] ) => void ;
20+ selectedOptions : Record < string , string [ ] > ;
1721}
1822
19- const Filter : React . FC < FilterProps > = ( { setOpen } ) => {
20- const filtersData = [
21- {
22- title : 'Organization' ,
23- Options : [
24- {
25- label : 'Option1' ,
26- value : 'Option1' ,
27- } ,
28- {
29- label : 'Option2' ,
30- value : 'Option2' ,
31- } ,
32- {
33- label : 'Option3' ,
34- value : 'Option3' ,
35- } ,
36- ] ,
37- } ,
38- {
39- title : 'Sector' ,
40- Options : [
41- {
42- label : 'Option21' ,
43- value : 'Option21' ,
44- } ,
45- {
46- label : 'Option22' ,
47- value : 'Option22' ,
48- } ,
49- {
50- label : 'Option23' ,
51- value : 'Option23' ,
52- } ,
53- ] ,
54- } ,
55- {
56- title : 'Category' ,
57- Options : [
58- {
59- label : 'Option31' ,
60- value : 'Option31' ,
61- } ,
62- {
63- label : 'Option32' ,
64- value : 'Option32' ,
65- } ,
66- {
67- label : 'Option33' ,
68- value : 'Option33' ,
69- } ,
70- ] ,
71- } ,
72- ] ;
73- const [ selectedOptions , setSelectedOptions ] = useState < string [ ] > ( [ ] ) ;
23+ const Filter : React . FC < FilterProps > = ( {
24+ setOpen,
25+ options,
26+ setSelectedOptions,
27+ selectedOptions,
28+ } ) => {
29+ const handleReset = ( ) => {
30+ Object . keys ( options ) . forEach ( ( category ) => {
31+ setSelectedOptions ( category , [ ] ) ; // Reset selected options for each category
32+ } ) ;
33+ } ;
34+
7435 return (
75- < div className = "rounded-2 border-2 border-solid border-baseGraySlateSolid5 px-4 py-6" >
76- < div className = "mb-5 flex justify-between " >
77- < div >
78- < Text variant = "headingMd" > Filters</ Text >
36+ < div className = "rounded-2 border-2 border-solid border-baseGraySlateSolid5 px-4 py-6" >
37+ < div className = "mb-5 flex justify-between" >
38+ < div className = "flex w-full justify-between" >
39+ < div >
40+ < Text variant = "headingMd" > Filters</ Text >
41+ </ div >
42+ < div >
43+ < Button kind = "tertiary" onClick = { handleReset } >
44+ Reset
45+ </ Button >
46+ </ div >
7947 </ div >
8048 { setOpen && (
81- < div className = "align-center mr-2 " >
82- < Button onClick = { ( e ) => setOpen ( false ) } kind = "tertiary" >
49+ < div className = "align-center mx-3 " >
50+ < Button onClick = { ( ) => setOpen ( false ) } kind = "tertiary" >
8351 < Icon source = { Icons . cross } size = { 24 } color = "default" />
8452 </ Button >
8553 </ div >
8654 ) }
8755 </ div >
88- < div className = "flex flex-col gap-5 " >
89- { filtersData . map ( ( item , index ) => (
56+ < div className = "flex flex-col gap-5" >
57+ { Object . entries ( options ) . map ( ( [ category , data ] , index ) => (
9058 < div key = { index } >
9159 < Accordion type = "single" collapsible className = "w-full" >
92- < AccordionItem value = { item . title } >
93- < AccordionTrigger className = "flex w-full flex-wrap items-center gap-2 rounded-1 bg-baseIndigoSolid5 py-2 hover:no-underline " >
94- < Text > { item . title } </ Text >
60+ < AccordionItem value = { category } >
61+ < AccordionTrigger className = "flex w-full flex-wrap items-center gap-2 rounded-1 bg-baseIndigoSolid5 py-2 hover:no-underline" >
62+ < Text > { toTitleCase ( category ) } </ Text >
9563 </ AccordionTrigger >
9664 < AccordionContent
97- className = "flex w-full flex-col px-3 pb-0 pt-2 "
65+ className = "flex w-full flex-col px-3 pb-0 pt-2"
9866 style = { {
99- backgroundColor : 'var( --base-pure-white)' ,
100- outline : '1px solid var( --base-pure-white)' ,
67+ backgroundColor : 'var(--base-pure-white)' ,
68+ outline : '1px solid var(--base-pure-white)' ,
10169 } }
10270 >
10371 < CheckboxGroup
104- name = "checkbox"
105- options = { item . Options . map ( ( Option ) => ( {
106- label : Option . label ,
107- value : Option . value ,
108- } ) ) }
72+ name = { category }
73+ options = { data }
10974 title = { undefined }
110- value = { selectedOptions }
111- onChange = { ( e ) => {
112- setSelectedOptions ( e ) , console . log ( e ) ;
75+ value = { selectedOptions [ category ] || [ ] }
76+ onChange = { ( values ) => {
77+ setSelectedOptions ( category , values as string [ ] ) ;
11378 } }
11479 />
11580 </ AccordionContent >
0 commit comments