Skip to content

Commit a15e8ee

Browse files
committed
#201 Added optional 'wrapper' around FilterBar with filters label
1 parent 27e0080 commit a15e8ee

File tree

2 files changed

+69
-22
lines changed

2 files changed

+69
-22
lines changed

packages/react-components/src/search/EventSearch/Layout.styles.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ export const cssFooter = ({theme}) => css`
4040

4141
export const cssFilter = ({theme}) => css`
4242
padding: 10px;
43-
border-bottom: 1px solid ${theme.paperBorderColor};
4443
`;
4544

4645
export const cssViews = ({theme}) => css`
Lines changed: 69 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
import { css, jsx } from '@emotion/react';
32
import React, { useContext } from 'react';
43
import get from 'lodash/get';
@@ -8,51 +7,100 @@ import ThemeContext from '../../style/themes/ThemeContext';
87
import { Trigger as MetaFilter } from '../../widgets/Filter/types/MetaFilter';
98

109
function getVisibleFilters(currentFilter, commonFilters) {
11-
const visibleFilters = union(commonFilters,
10+
const visibleFilters = union(
11+
commonFilters,
1212
Object.keys(get(currentFilter, 'must', {})),
13-
Object.keys(get(currentFilter, 'must_not', {})));
13+
Object.keys(get(currentFilter, 'must_not', {}))
14+
);
1415
return visibleFilters;
1516
}
1617

18+
const FilterBarContent = ({ className = '', config, filter, ...props }) => {
19+
const theme = useContext(ThemeContext);
20+
21+
const visibleFilters = getVisibleFilters(
22+
filter,
23+
config.defaultVisibleFilters
24+
);
25+
const availableFilters = visibleFilters.map((x) => config.filters[x]);
26+
27+
return (
28+
<div className={className} css={style(theme)} {...props}>
29+
{availableFilters.map((x, i) => {
30+
if (!x) return null; // if no widget is defined for this filter, then do not show anything
31+
return <x.Button key={i} />;
32+
})}
33+
{Object.keys(config.filters).length !==
34+
config.defaultVisibleFilters.length && (
35+
<div>
36+
<MetaFilter />
37+
</div>
38+
)}
39+
</div>
40+
);
41+
};
42+
1743
const FilterBar = ({
1844
className = '',
1945
config,
2046
filter,
47+
withWrapper = true,
2148
...props
2249
}) => {
2350
const theme = useContext(ThemeContext);
2451
const prefix = theme.prefix || 'gbif';
2552
const elementName = 'filterBar';
2653

27-
const visibleFilters = getVisibleFilters(filter, config.defaultVisibleFilters);
28-
const availableFilters = visibleFilters.map(x => config.filters[x]);
29-
30-
return <div className={`${className} ${prefix}-${elementName}`} css={css`${style(theme)}`} {...props}>
31-
{availableFilters.map((x, i) => {
32-
if (!x) return null; // if no widget is defined for this filter, then do not show anything
33-
return <x.Button key={i} />
34-
})}
35-
{Object.keys(config.filters).length !== config.defaultVisibleFilters.length &&
36-
<div>
37-
<MetaFilter />
38-
</div>}
39-
</div>
40-
}
54+
return withWrapper ? (
55+
<div
56+
className={`${className} ${prefix}-${elementName}`}
57+
css={cssFilter({ theme })}
58+
{...props}
59+
>
60+
<div css={title({ theme })}>FILTERS</div>
61+
<FilterBarContent config={config} filter={filter} />
62+
</div>
63+
) : (
64+
<FilterBarContent
65+
config={config}
66+
filter={filter}
67+
className={`${className} ${prefix}-${elementName}`}
68+
{...props}
69+
/>
70+
);
71+
};
4172

42-
FilterBar.propTypes = {
43-
}
73+
FilterBarContent.propTypes = {};
4474

4575
export const style = (theme) => css`
4676
display: flex;
4777
flex-direction: row;
4878
flex-wrap: wrap;
4979
margin-bottom: -4px;
50-
>div {
80+
> div {
5181
max-width: 100%;
52-
margin-right: 4px;
82+
margin-right: 4px;
5383
margin-bottom: 4px;
5484
}
5585
`;
5686

87+
export const title = ({ theme }) => css`
88+
position: absolute;
89+
font-size: 0.9em;
90+
font-weight: bold;
91+
color: ${theme.color500};
92+
top: -14px;
93+
left: 10px;
94+
background-color: ${theme.paperBackground};
95+
padding: 4px;
96+
`;
97+
98+
export const cssFilter = ({ theme }) => css`
99+
position: relative;
100+
padding: 12px;
101+
border: 1px solid ${theme.paperBorderColor};
102+
border-radius: ${theme.borderRadius}px;
103+
`;
104+
57105
const mapContextToProps = ({ filter }) => ({ filter });
58106
export default withFilter(mapContextToProps)(FilterBar);

0 commit comments

Comments
 (0)