Skip to content

Commit

Permalink
feat(bar): support initialHiddeIds prop
Browse files Browse the repository at this point in the history
  • Loading branch information
wyze committed Jun 28, 2021
1 parent 33a0cdb commit 29a80c6
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
4 changes: 3 additions & 1 deletion packages/bar/src/Bar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,11 @@ export const Bar = <RawDatum extends BarDatum>({
renderWrapper,
role = svgDefaultProps.role,

initialHiddenIds,

...props
}: BarSvgProps<RawDatum>) => {
const [hiddenIds, setHiddenIds] = useState<string[]>([])
const [hiddenIds, setHiddenIds] = useState(initialHiddenIds ?? [])
const toggleSerie = useCallback(id => {
setHiddenIds(state =>
state.indexOf(id) > -1 ? state.filter(item => item !== id) : [...state, id]
Expand Down
1 change: 1 addition & 0 deletions packages/bar/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ export type BarSvgProps<RawDatum extends BarDatum> = Partial<BarCommonProps<RawD
Dimensions &
ModernMotionProps &
Partial<{
initialHiddenIds: string[]
layers: BarLayer<RawDatum>[]
role: string
}>
Expand Down
18 changes: 18 additions & 0 deletions packages/bar/stories/bar.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -402,3 +402,21 @@ const RaceChart = () => {
}

stories.add('race chart', () => <RaceChart />)

stories.add('initial hidden ids', () => (
<Bar
{...commonProps}
initialHiddenIds={keys.slice(2, 4)}
legends={[
{
anchor: 'bottom',
dataFrom: 'keys',
direction: 'row',
itemHeight: 20,
itemWidth: 80,
toggleSerie: true,
translateY: 50,
},
]}
/>
))

0 comments on commit 29a80c6

Please sign in to comment.