Skip to content

Commit ddf7516

Browse files
authored
Merge pull request #15 from FoxComm/feature/omit-parenthesis-on-filters-count
Add property to filterGroup using which we can omit putting parentheses on filters count
2 parents a3a661e + 27f7d9c commit ddf7516

4 files changed

Lines changed: 20 additions & 5 deletions

File tree

src/components/core/filters/filter-checkboxes.jsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,12 @@ import type { FilterValue, FilterTypeProps } from './types';
55
import styles from './filter-checkboxes.css';
66

77
const FilterCheckboxes = (props: FilterTypeProps): Element<*> => {
8+
89
const term = (props.term || '').toUpperCase();
910
const {
1011
onSelectFacet = (a, b, c) => {},
1112
values = [],
13+
renderCount,
1214
} = props;
1315

1416
const controls = values.map((facetValue) => {
@@ -28,7 +30,7 @@ const FilterCheckboxes = (props: FilterTypeProps): Element<*> => {
2830
/>
2931
<div styleName="filter-label">
3032
{label}
31-
<span styleName="count">&nbsp;({count})</span>
33+
<span styleName="count">&nbsp;{renderCount(count)}</span>
3234
</div>
3335
</label>
3436
</div>

src/components/core/filters/filter-group.jsx

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,18 @@ type State = {
1111
expanded: boolean,
1212
};
1313

14+
type DefaultProps = {
15+
renderCount: (count: number) => string,
16+
};
17+
1418
export default class FilterGroup extends Component {
1519
props: FilterGroupProps;
1620
state: State = { expanded: this.props.initiallyExpanded };
1721

22+
static defaultProps: DefaultProps = {
23+
renderCount: (count: number): string => `(${count})`,
24+
}
25+
1826
selectedCount = () => {
1927
const { values = [] } = this.props;
2028
return values.reduce((acc, val) => {
@@ -26,20 +34,21 @@ export default class FilterGroup extends Component {
2634
toggleExpansion = () => this.setState({ expanded: !this.state.expanded });
2735

2836
render() {
29-
const { children, label, term, values } = this.props;
37+
const { children, label, term, values, renderCount } = this.props;
3038
const {
3139
onClearFacet = () => {},
3240
onSelectFacet = () => {},
3341
} = this.props;
3442
const { expanded } = this.state;
3543

3644
const updatedChildren = React.Children.map(children, (child) => {
37-
return React.cloneElement(child, { onSelectFacet, term, values });
45+
return React.cloneElement(child, { onSelectFacet, term, values, renderCount });
3846
});
3947

4048
return (
4149
<div styleName="group">
4250
<FilterHeader
51+
renderCount={renderCount}
4352
count={this.selectedCount()}
4453
expanded={expanded}
4554
onClear={onClearFacet}

src/components/core/filters/filter-header.jsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,12 @@ type Props = {
99
expanded: boolean,
1010
onClear: Function,
1111
onClick: Function,
12+
renderCount: (count: number) => string,
1213
};
1314

1415
const FilterHeader = (props: Props): Element<*> => {
15-
const { children, count, expanded, onClear, onClick } = props;
16+
17+
const { children, count, expanded, onClear, onClick, renderCount } = props;
1618
const iconStyle = expanded ? 'icon-minus' : 'icon-plus';
1719

1820
return (
@@ -26,7 +28,7 @@ const FilterHeader = (props: Props): Element<*> => {
2628
>
2729
{children}
2830
{count > 0 && (
29-
<span styleName="count">&nbsp;({count})</span>
31+
<span styleName="count">&nbsp;{renderCount(count)}</span>
3032
)}
3133
</a>
3234
</span>

src/components/core/filters/types.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ export type FilterTypeProps = {
1616
onSelectFacet?: Function,
1717
term?: string,
1818
values?: Array<FilterValue>,
19+
renderCount: (count: number) => string,
1920
};
2021

2122

@@ -27,4 +28,5 @@ export type FilterGroupProps = {
2728
onClearFacet?: Function,
2829
onSelectFacet?: Function,
2930
initiallyExpanded?: boolean,
31+
renderCount?: (count: number) => string,
3032
};

0 commit comments

Comments
 (0)