forked from vtex-apps/search-result
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDepartmentFilters.js
72 lines (66 loc) · 1.76 KB
/
DepartmentFilters.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import classNames from 'classnames'
import React from 'react'
import { FormattedMessage } from 'react-intl'
import { NoSSR } from 'vtex.render-runtime'
import Collapsible from './Collapsible'
import CategoryFilter from './CategoryFilter'
import styles from '../searchResult.css'
const DepartmentFilters = ({
title,
isVisible,
tree,
onCategorySelect,
hideBorder = false,
}) => {
if (!isVisible) {
return null
}
const showAllDepartments = tree.every(category => !category.selected)
return (
<div className={classNames({ 'bb b--muted-4': !hideBorder })}>
{title && (
<div className={classNames(styles.filter, 'pt4')}>
<div
className={classNames(
styles.filterTitle,
't-mini c-muted-2 flex items-center justify-between'
)}
>
<FormattedMessage id={title} />
</div>
</div>
)}
<div
className={classNames(
styles.categoriesContainer,
'pb5 flex flex-column'
)}
>
{showAllDepartments ? (
<NoSSR>
<Collapsible
maxItems={8}
threshold={2}
items={tree}
openLabel="store/filter.more-departments"
render={category => (
<CategoryFilter
key={category.id}
category={category}
shallow
onCategorySelect={onCategorySelect}
/>
)}
/>
</NoSSR>
) : (
<CategoryFilter
category={tree.find(category => category.selected)}
onCategorySelect={onCategorySelect}
/>
)}
</div>
</div>
)
}
export default DepartmentFilters