-
Notifications
You must be signed in to change notification settings - Fork 114
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs(listbox-primitive): add stories (#3265)
* test(reakit): add stories for composite * test(listbox-primitive): improve stories for listboxprimitive * docs: fix story keyboard usage bug * fix: undo * fix: annoying linter
- Loading branch information
Showing
4 changed files
with
217 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
93 changes: 93 additions & 0 deletions
93
packages/paste-libraries/reakit/stories/composite.stories.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
import * as React from 'react'; | ||
|
||
import {useCompositeState, Composite, CompositeGroup, CompositeItem} from '../src'; | ||
|
||
// eslint-disable-next-line import/no-default-export | ||
export default { | ||
title: 'Libraries/Reakit/Composite', | ||
component: Composite, | ||
subcomponents: {Composite, CompositeItem}, | ||
}; | ||
|
||
const onClick = | ||
(num: number): (() => void) => | ||
() => | ||
// eslint-disable-next-line no-console | ||
console.log(`clicked ${num}`); | ||
|
||
export const BasicUsage = (): React.ReactNode => { | ||
const composite = useCompositeState(); | ||
|
||
return ( | ||
<Composite {...composite} role="toolbar" aria-label="My toolbar"> | ||
<CompositeItem {...composite} onClick={onClick(1)}> | ||
Item 1 | ||
</CompositeItem> | ||
<CompositeItem {...composite} onClick={onClick(2)}> | ||
Item 2 | ||
</CompositeItem> | ||
<CompositeItem {...composite} onClick={onClick(3)}> | ||
Item 3 | ||
</CompositeItem> | ||
</Composite> | ||
); | ||
}; | ||
|
||
// https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Attributes/aria-activedescendant | ||
export const AriaActivedescendant = (): React.ReactNode => { | ||
const composite = useCompositeState({unstable_virtual: true}); | ||
return ( | ||
<Composite {...composite} role="toolbar" aria-label="My toolbar"> | ||
<CompositeItem {...composite} onClick={onClick(1)}> | ||
Item 1 | ||
</CompositeItem> | ||
<CompositeItem {...composite} onClick={onClick(2)}> | ||
Item 2 | ||
</CompositeItem> | ||
<CompositeItem {...composite} onClick={onClick(3)}> | ||
Item 3 | ||
</CompositeItem> | ||
</Composite> | ||
); | ||
}; | ||
|
||
const Grid: React.FC<any> = (props) => { | ||
return <Composite role="grid" {...props} />; | ||
}; | ||
|
||
const GridRow: React.FC<any> = (props) => { | ||
return <CompositeGroup role="row" {...props} style={{display: 'flex', columnGap: '10px'}} />; | ||
}; | ||
|
||
const GridCell: React.FC<any> = (props) => { | ||
return <CompositeItem as="div" role="gridcell" {...props} onClick={onClick(props.currentId)} />; | ||
}; | ||
|
||
export const TwoDimensional = (): React.ReactNode => { | ||
const composite = useCompositeState({wrap: true}); | ||
return ( | ||
<Grid {...composite} aria-label="My grid"> | ||
<GridRow {...composite}> | ||
<GridCell {...composite}>Item</GridCell> | ||
<GridCell {...composite}>Item</GridCell> | ||
<GridCell {...composite}>Item</GridCell> | ||
<GridCell {...composite}>Item</GridCell> | ||
<GridCell {...composite}>Item</GridCell> | ||
</GridRow> | ||
<GridRow {...composite}> | ||
<GridCell {...composite}>Item</GridCell> | ||
<GridCell {...composite}>Item</GridCell> | ||
<GridCell {...composite}>Item</GridCell> | ||
<GridCell {...composite}>Item</GridCell> | ||
<GridCell {...composite}>Item</GridCell> | ||
</GridRow> | ||
<GridRow {...composite}> | ||
<GridCell {...composite}>Item</GridCell> | ||
<GridCell {...composite}>Item</GridCell> | ||
<GridCell {...composite}>Item</GridCell> | ||
<GridCell {...composite}>Item</GridCell> | ||
<GridCell {...composite}>Item</GridCell> | ||
</GridRow> | ||
</Grid> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters