forked from vtex-apps/search-result
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSearchFilter.js
38 lines (32 loc) · 1.09 KB
/
SearchFilter.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import PropTypes from 'prop-types'
import React from 'react'
import { injectIntl, intlShape } from 'react-intl'
import FilterOptionTemplate from './FilterOptionTemplate'
import FacetItem from './FacetItem'
import { facetOptionShape } from '../constants/propTypes'
import { getFilterTitle } from '../constants/SearchHelpers'
import useSelectedFilters from '../hooks/useSelectedFilters'
import styles from '../searchResult.css'
/**
* Search Filter Component.
*/
const SearchFilter = ({ title = 'Default Title', facets = [], intl }) => {
const filtersWithSelected = useSelectedFilters(facets)
return (
<FilterOptionTemplate
title={getFilterTitle(title, intl)}
filters={filtersWithSelected}
>
{facet => <FacetItem key={facet.name} facet={facet} className={styles.filterItem} />}
</FilterOptionTemplate>
)
}
SearchFilter.propTypes = {
/** SearchFilter's title. */
title: PropTypes.string.isRequired,
/** SearchFilter's options. */
facets: PropTypes.arrayOf(facetOptionShape),
/** Intl instance. */
intl: intlShape.isRequired,
}
export default injectIntl(SearchFilter)