This repository has been archived by the owner on Mar 4, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(Toolbar): add support for radio & checkbox groups (#1920)
* wip! * wip * wip * add UT * wip! * wip! * add behaviors to tests * fix UTs * add CH * rename to `toggle` * rename to `toggle` * fix TS issues * nit fixes * fix CI * add role presentation on li to enable reader narrate position * restore type change * add UT, fix TS error * remove tabIndex * add activeIndex to ToolbarRadioGroup * remove test for `tabIndex` * rename to active
- Loading branch information
1 parent
79cabdc
commit 94c7905
Showing
21 changed files
with
459 additions
and
15 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
54 changes: 54 additions & 0 deletions
54
docs/src/examples/components/Toolbar/Content/ToolbarExampleMenuItemToggle.shorthand.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,54 @@ | ||
import { Toolbar, ToolbarMenuItemProps } from '@stardust-ui/react' | ||
import * as _ from 'lodash' | ||
import * as React from 'react' | ||
|
||
const ToolbarExampleMenuItemToggle = () => { | ||
const [menuOpen, setMenuOpen] = React.useState(false) | ||
const [activeIndexes, setActiveIndexes] = React.useState<number[]>([]) | ||
|
||
const handleToggleClick = (e: React.SyntheticEvent, props: ToolbarMenuItemProps) => { | ||
if (_.includes(activeIndexes, props.index)) { | ||
setActiveIndexes(_.without(activeIndexes, props.index)) | ||
} else { | ||
setActiveIndexes([...activeIndexes, props.index]) | ||
} | ||
} | ||
|
||
return ( | ||
<Toolbar | ||
items={[ | ||
{ | ||
key: 'more', | ||
active: menuOpen, | ||
icon: 'more', | ||
menu: [ | ||
{ | ||
key: 'bold', | ||
active: _.includes(activeIndexes, 0), | ||
content: 'Bold', | ||
kind: 'toggle', | ||
icon: 'bold', | ||
index: 0, | ||
onClick: handleToggleClick, | ||
}, | ||
{ | ||
key: 'italic', | ||
active: _.includes(activeIndexes, 1), | ||
content: 'Italic', | ||
kind: 'toggle', | ||
icon: 'italic', | ||
index: 1, | ||
onClick: handleToggleClick, | ||
}, | ||
{ key: 'divider', kind: 'divider' }, | ||
'About...', | ||
], | ||
menuOpen, | ||
onMenuOpenChange: (e, { menuOpen }) => setMenuOpen(menuOpen), | ||
}, | ||
]} | ||
/> | ||
) | ||
} | ||
|
||
export default ToolbarExampleMenuItemToggle |
41 changes: 41 additions & 0 deletions
41
docs/src/examples/components/Toolbar/Content/ToolbarExampleMenuRadioGroup.shorthand.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,41 @@ | ||
import { Toolbar } from '@stardust-ui/react' | ||
import * as React from 'react' | ||
|
||
const ToolbarExampleMenuRadioGroup = () => { | ||
const [activeIndex, setActiveIndex] = React.useState(0) | ||
const [menuOpen, setMenuOpen] = React.useState() | ||
|
||
return ( | ||
<Toolbar | ||
items={[ | ||
{ | ||
key: 'more', | ||
active: menuOpen, | ||
icon: 'more', | ||
menu: [ | ||
{ | ||
key: 'group', | ||
activeIndex, | ||
kind: 'group', | ||
items: [ | ||
{ key: 'left', content: 'Left' }, | ||
{ key: 'center', content: 'Center' }, | ||
{ key: 'right', content: 'Right' }, | ||
{ key: 'justify', content: 'Justify' }, | ||
], | ||
onItemClick: (e, data) => setActiveIndex(data.index), | ||
}, | ||
{ key: 'divider', kind: 'divider' }, | ||
'About...', | ||
], | ||
menuOpen, | ||
onMenuOpenChange: (e, { menuOpen }) => { | ||
setMenuOpen(menuOpen) | ||
}, | ||
}, | ||
]} | ||
/> | ||
) | ||
} | ||
|
||
export default ToolbarExampleMenuRadioGroup |
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
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
Oops, something went wrong.