File tree Expand file tree Collapse file tree 2 files changed +52
-2
lines changed Expand file tree Collapse file tree 2 files changed +52
-2
lines changed Original file line number Diff line number Diff line change 11import { RefinementListItem } from "instantsearch.js/es/connectors/refinement-list/connectRefinementList"
2- import { useRefinements } from "../useRefinements"
2+ import { useBasicRefinements } from "../useRefinements"
33import { useCallback } from "react"
44
55export const useTestimonyRefinements = ( ) => {
@@ -37,5 +37,5 @@ export const useTestimonyRefinements = () => {
3737 }
3838 ]
3939
40- return useRefinements ( { refinementProps : propsList } )
40+ return useBasicRefinements ( { refinementProps : propsList } )
4141}
Original file line number Diff line number Diff line change @@ -87,3 +87,53 @@ export const useRefinements = ({
8787 )
8888 }
8989}
90+
91+ export const useBasicRefinements = ( {
92+ refinementProps
93+ } : {
94+ refinementProps : any [ ]
95+ } ) => {
96+ const inline = useMediaQuery ( "(min-width: 768px)" )
97+ const [ show , setShow ] = useState ( false )
98+ const handleClose = useCallback ( ( ) => setShow ( false ) , [ ] )
99+ const handleOpen = useCallback ( ( ) => setShow ( true ) , [ ] )
100+
101+ const refinements = (
102+ < >
103+ { refinementProps . map ( ( p , i ) => (
104+ < RefinementList className = "mb-4" key = { i } { ...( p as any ) } />
105+ ) ) }
106+ </ >
107+ )
108+
109+ const hasRefinements = useHasRefinements ( )
110+
111+ const { t } = useTranslation ( "billSearch" )
112+
113+ return {
114+ options : inline ? (
115+ < >
116+ < div > { refinements } </ div >
117+ </ >
118+ ) : (
119+ < Offcanvas show = { show } onHide = { handleClose } >
120+ < Offcanvas . Header closeButton >
121+ < Offcanvas . Title > { t ( "filter" ) } </ Offcanvas . Title >
122+ </ Offcanvas . Header >
123+ < Offcanvas . Body >
124+ < SearchContainer > { refinements } </ SearchContainer >
125+ </ Offcanvas . Body >
126+ </ Offcanvas >
127+ ) ,
128+ show : inline ? null : (
129+ < FilterButton
130+ variant = "secondary"
131+ active = { show }
132+ onClick = { handleOpen }
133+ className = { hasRefinements ? "ais-FilterButton-has-refinements" : "" }
134+ >
135+ < FontAwesomeIcon icon = { faFilter } /> { t ( "filter" ) }
136+ </ FilterButton >
137+ )
138+ }
139+ }
You can’t perform that action at this time.
0 commit comments