Skip to content

Feature: more abilities for FacetGroup component #172

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 15, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 44 additions & 5 deletions src/plp/FacetGroup.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { makeStyles } from '@material-ui/core/styles'
import ExpandableSection from '../ExpandableSection'
import CheckboxFilterGroup from './CheckboxFilterGroup'
import ButtonFilterGroup from './ButtonFilterGroup'
import ListItem from '@material-ui/core/ListItem'

const styles = theme => ({
/**
Expand All @@ -23,7 +24,16 @@ const useStyles = makeStyles(styles, { name: 'RSFFacetGroup' })
* A grouping of facets used for filtering products.
*/
export default function FacetGroup(props) {
const { group, submitOnChange, defaultExpanded } = props
const {
group,
submitOnChange,
defaultExpanded,
ControlsComponent,
controlsProps,
listItemProps,
onClose,
isSimpleList
} = props
const classes = useStyles(props.classes)
const {
pageData: { filters },
Expand All @@ -40,11 +50,11 @@ export default function FacetGroup(props) {
}
}

let Controls
let Controls = ControlsComponent

if (group.ui === 'buttons') {
if (!Controls && group.ui === 'buttons') {
Controls = ButtonFilterGroup
} else {
} else if (!Controls) {
Controls = CheckboxFilterGroup
}

Expand All @@ -56,14 +66,32 @@ export default function FacetGroup(props) {
caption = `${selection.length} selected`
}

if (isSimpleList) {
return (
<ListItem {...listItemProps}>
<span className={classes.groupTitle}>{group.name}</span>
<Controls
onClose={onClose}
group={group}
submitOnChange={submitOnChange}
{...controlsProps}
/>
</ListItem>
)
}

return (
<ExpandableSection
title={group.name}
caption={caption}
defaultExpanded={defaultExpanded}
classes={{ title: classes.groupTitle }}
>
<Controls group={group} submitOnChange={submitOnChange} />
<Controls
group={group}
submitOnChange={submitOnChange}
{...controlsProps}
/>
</ExpandableSection>
)
}, [...Object.values(props), filters])
Expand All @@ -87,4 +115,15 @@ FacetGroup.propTypes = {
* If `true`, the group is expanded by default.
*/
defaultExpanded: PropTypes.bool,
/**
* Custom component to use own component.
*/
ControlsComponent: PropTypes.func,
controlsProps: PropTypes.object,
onClose: PropTypes.func,
listItemProps: PropTypes.object,
/**
* If `true` list will be displayed instead of expandable items.
*/
isSimpleList: PropTypes.bool,
}