Created
January 28, 2019 21:50
-
-
Save JasonStoltz/a19f241427f9daa9d866461df906845d to your computer and use it in GitHub Desktop.
StickyFacets
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<StickyFacets> | |
{({ facets }) => ( | |
<React.Fragment> | |
<Facet | |
facets={facets} | |
field="date_established" | |
label="Date Established" | |
view={SingleRangeSelectFacet} | |
/> | |
<Facet | |
facets={facets} | |
field="states" | |
label="States" | |
view={MultiValueFacet} | |
/> | |
<Facet | |
facets={facets} | |
field="acres" | |
label="Acres" | |
view={SingleRangeSelectFacet} | |
/> | |
<Facet | |
facets={facets} | |
field="visitors" | |
label="Visitors" | |
view={MultiValueFacet} | |
/> | |
</React.Fragment> | |
)} | |
</StickyFacets> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from "react"; | |
import { withSearch } from "@elastic/react-search-ui"; | |
class StickyFacets extends React.Component { | |
constructor() { | |
super(); | |
this.facetCache = {}; | |
} | |
render() { | |
const { children, facets, resultSearchTerm } = this.props; | |
if (resultSearchTerm !== null && this.facetCache[resultSearchTerm]) { | |
return children({ facets: this.facetCache[resultSearchTerm] }); | |
} else { | |
this.facetCache[resultSearchTerm] = facets; | |
return children({ facets: facets }); | |
} | |
} | |
} | |
export default withSearch(StickyFacets); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment