-
Notifications
You must be signed in to change notification settings - Fork 646
Adds draft SegmentedControl docs #2081
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
Changes from 1 commit
c906d65
5f85457
b8421bd
bda37f3
b53ad39
2947400
ffae4ae
c754dfd
6edd979
266bce9
07d1382
0272ead
b0b7848
33a9474
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,190 @@ | ||
| --- | ||
| title: SegmentedControl | ||
| status: Draft | ||
| description: Used to select an option from a short list and immediately apply the selection | ||
| --- | ||
mperrotti marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| ## Examples | ||
|
|
||
| ### Simple | ||
|
|
||
| ```jsx live drafts | ||
| <SegmentedControl aria-label="File view"> | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How would you indicate which Button is selected?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. By passing
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If it'll be common for consumers to explicitly set the |
||
| <SegmentedControl.Item>Preview</SegmentedControl.Item> | ||
|
||
| <SegmentedControl.Item>Raw</SegmentedControl.Item> | ||
| <SegmentedControl.Item>Blame</SegmentedControl.Item> | ||
| </SegmentedControl> | ||
| ``` | ||
|
|
||
| ### With icons and labels | ||
|
|
||
| ```jsx live drafts | ||
| <SegmentedControl aria-label="File view"> | ||
| <SegmentedControl.Item leadingIcon={EyeIcon}>Preview</SegmentedControl.Item> | ||
|
||
| <SegmentedControl.Item leadingIcon={FileCodeIcon}>Raw</SegmentedControl.Item> | ||
| <SegmentedControl.Item leadingIcon={PeopleIcon}>Blame</SegmentedControl.Item> | ||
| </SegmentedControl> | ||
| ``` | ||
|
|
||
| ### With icons only | ||
|
|
||
| ```jsx live drafts | ||
| <SegmentedControl aria-label="File view"> | ||
| <SegmentedControl.IconItem icon={EyeIcon} aria-label="Preview" /> | ||
| <SegmentedControl.IconItem icon={FileCodeIcon} aria-label="Raw" /> | ||
| <SegmentedControl.IconItem icon={PeopleIcon} aria-label="Blame" /> | ||
| </SegmentedControl> | ||
| ``` | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Alternate idea: <SegmentedControl aria-label="File view" hideLabels>
<SegmentedControl.Item leadingIcon={EyeIcon}>Preview</SegmentedControl.Item>
<SegmentedControl.Item leadingIcon={FileCodeIcon}>Raw</SegmentedControl.Item>
<SegmentedControl.Item leadingIcon={PeopleIcon}>Blame</SegmentedControl.Item>
</SegmentedControl>
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How do you feel about using aria-label instead of <SegmentedControl aria-label="File view">
<SegmentedControl.Item leadingIcon={EyeIcon} aria-label="Preview" />
<SegmentedControl.Item leadingIcon={FileCodeIcon} aria-label="Raw" />
<SegmentedControl.Item leadingIcon={PeopleIcon} aria-label="Blame" />
</SegmentedControl>alt: similar to IconButton: <SegmentedControl aria-label="File view">
<SegmentedControl.IconButton icon={EyeIcon} aria-label="Preview" />
<SegmentedControl.IconButton icon={FileCodeIcon} aria-label="Raw" />
<SegmentedControl.IconButton icon={PeopleIcon} aria-label="Blame" />
</SegmentedControl>
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm good with I think the only difference between that and what I have now is the name |
||
|
|
||
| ### With labels hidden on smaller viewports | ||
|
|
||
| ```jsx live drafts | ||
| <SegmentedControl aria-label="File view" hideLabels={{narrow: false, large: true}}> | ||
| <SegmentedControl.Item leadingIcon={EyeIcon}>Preview</SegmentedControl.Item> | ||
| <SegmentedControl.Item leadingIcon={FileCodeIcon}>Raw</SegmentedControl.Item> | ||
| <SegmentedControl.Item leadingIcon={PeopleIcon}>Blame</SegmentedControl.Item> | ||
| </SegmentedControl> | ||
| ``` | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Alternate idea: <SegmentedControl aria-label="File view" variant={{narrow: 'hideLabels', regular: 'none'}}>
<SegmentedControl.Item leadingIcon={EyeIcon}>Preview</SegmentedControl.Item>
<SegmentedControl.Item leadingIcon={FileCodeIcon}>Raw</SegmentedControl.Item>
<SegmentedControl.Item leadingIcon={PeopleIcon}>Blame</SegmentedControl.Item>
</SegmentedControl> |
||
|
|
||
| ### Convert to a dropdown on smaller viewports | ||
|
|
||
| ```jsx live drafts | ||
| <SegmentedControl aria-label="File view" asDropdown={{narrow: true, large: false}}> | ||
| <SegmentedControl.Item leadingIcon={EyeIcon}>Preview</SegmentedControl.Item> | ||
| <SegmentedControl.Item leadingIcon={FileCodeIcon}>Raw</SegmentedControl.Item> | ||
| <SegmentedControl.Item leadingIcon={PeopleIcon}>Blame</SegmentedControl.Item> | ||
| </SegmentedControl> | ||
| ``` | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Alternate idea: <SegmentedControl aria-label="File view" variant={{narrow: 'dropdown', regular: 'none'}}>
<SegmentedControl.Item leadingIcon={EyeIcon}>Preview</SegmentedControl.Item>
<SegmentedControl.Item leadingIcon={FileCodeIcon}>Raw</SegmentedControl.Item>
<SegmentedControl.Item leadingIcon={PeopleIcon}>Blame</SegmentedControl.Item>
</SegmentedControl>
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I like the idea this alternate of using variant for dropdown more! I think we can have 3 variants: dropdown, compact / without-labels, expanded?? (names TBD 😅) And then have a responsive format for
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What would happen if the variant was "compact" and the buttons didn't have any icons?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think anything would happen because there would be no icons to hide |
||
|
|
||
| ### Fill width of parent | ||
|
|
||
| ```jsx live drafts | ||
| <SegmentedControl block aria-label="File view"> | ||
|
||
| <SegmentedControl.Item>Preview</SegmentedControl.Item> | ||
| <SegmentedControl.Item>Raw</SegmentedControl.Item> | ||
| <SegmentedControl.Item>Blame</SegmentedControl.Item> | ||
| </SegmentedControl> | ||
| ``` | ||
|
|
||
| ### In a loading state | ||
|
|
||
| ```jsx live drafts | ||
| <SegmentedControl loading aria-label="File view"> | ||
| <SegmentedControl.Item>Preview</SegmentedControl.Item> | ||
| <SegmentedControl.Item>Raw</SegmentedControl.Item> | ||
| <SegmentedControl.Item>Blame</SegmentedControl.Item> | ||
| </SegmentedControl> | ||
| ``` | ||
|
|
||
| ### With a label and caption on the left | ||
|
|
||
| ```jsx live drafts | ||
| <Box display="flex"> | ||
| <Box flexGrow={1}> | ||
| <Text fontSize={2} fontWeight="bold" id="scLabel-vert" display="block"> | ||
| File view | ||
| </Text> | ||
| <Text color="fg.subtle" fontSize={1} id="scCaption-vert" display="block"> | ||
| Change the way the file is viewed | ||
| </Text> | ||
| </Box> | ||
| <SegmentedControl aria-labelledby="scLabel-vert" aria-describedby="scCaption-vert"> | ||
| <SegmentedControl.Item>Preview</SegmentedControl.Item> | ||
| <SegmentedControl.Item>Raw</SegmentedControl.Item> | ||
| <SegmentedControl.Item>Blame</SegmentedControl.Item> | ||
| </SegmentedControl> | ||
| </Box> | ||
| ``` | ||
|
|
||
| ### With a label above and caption below | ||
|
|
||
| ```jsx live drafts | ||
| <FormControl> | ||
| <FormControl.Label id="scLabel-horiz">File view</FormControl.Label> | ||
| <SegmentedControl aria-labelledby="scLabel-horiz" aria-describedby="scCaption-horiz"> | ||
| <SegmentedControl.Item>Preview</SegmentedControl.Item> | ||
| <SegmentedControl.Item>Raw</SegmentedControl.Item> | ||
| <SegmentedControl.Item>Blame</SegmentedControl.Item> | ||
| </SegmentedControl> | ||
| <FormControl.Caption id="scCaption-horiz">Change the way the file is viewed</FormControl.Caption> | ||
| </FormControl> | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ooh that's interesting! Is this in the context of a Form or otherwise as well?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Otherwise as well. This component is not a substitute for
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 The name threw me off a bit 😅 |
||
| ``` | ||
|
|
||
| ### With something besides the first option selected | ||
|
|
||
| ```jsx live drafts | ||
| <SegmentedControl aria-label="File view"> | ||
| <SegmentedControl.Item>Preview</SegmentedControl.Item> | ||
| <SegmentedControl.Item selected>Raw</SegmentedControl.Item> | ||
| <SegmentedControl.Item>Blame</SegmentedControl.Item> | ||
| </SegmentedControl> | ||
| ``` | ||
|
|
||
| ### With a selection change handler | ||
|
|
||
| ```jsx live drafts | ||
| <SegmentedControl | ||
| aria-label="File view" | ||
| onChange={selectedIndex => { | ||
| alert(`Segment ${selectedIndex}`) | ||
| }} | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Because the items are buttons, adding an onClick would also automatically work. Do we want to support both onClick on item and onChange on parent?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I like the |
||
| > | ||
| <SegmentedControl.Item>Preview</SegmentedControl.Item> | ||
| <SegmentedControl.Item>Raw</SegmentedControl.Item> | ||
| <SegmentedControl.Item>Blame</SegmentedControl.Item> | ||
| </SegmentedControl> | ||
| ``` | ||
|
|
||
| ## Props | ||
|
|
||
| ### SegmentedControl | ||
|
|
||
| <PropsTable> | ||
| <PropsTableRow name="aria-label" type="string" /> | ||
| <PropsTableRow name="aria-labelledby" type="string" /> | ||
| <PropsTableRow name="aria-describedby" type="string" /> | ||
| <PropsTableRow name="block" type="boolean" description="Whether the control fills the width of its parent" /> | ||
| <PropsTableRow name="loading" type="boolean" description="Whether the selected segment is being calculated" /> | ||
| <PropsTableRow | ||
| name="onChange" | ||
| type="(selectedIndex?: number) => void" | ||
| description="The handler that gets called when a segment is selected" | ||
| /> | ||
| </PropsTable> | ||
|
|
||
| ### SegmentedControl.Item | ||
|
|
||
| <PropsTable> | ||
| <PropsTableRow name="aria-label" type="string" /> | ||
| <PropsTableRow name="leadingIcon" type="Component" description="The leading icon comes before item label" /> | ||
| <PropsTableRow name="selected" type="boolean" description="Whether the segment is selected" /> | ||
| </PropsTable> | ||
mperrotti marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| ### SegmentedControl.IconItem | ||
|
|
||
| <PropsTable> | ||
| <PropsTableRow name="aria-label" type="string" /> | ||
| <PropsTableRow name="icon" type="Component" description="The icon that represents the segmented control item" /> | ||
| <PropsTableRow name="selected" type="boolean" description="Whether the segment is selected" /> | ||
| </PropsTable> | ||
|
|
||
| ## Status | ||
|
|
||
| <ComponentChecklist | ||
| items={{ | ||
| propsDocumented: true, | ||
| noUnnecessaryDeps: false, | ||
| adaptsToThemes: false, | ||
| adaptsToScreenSizes: false, | ||
| fullTestCoverage: false, | ||
| usedInProduction: false, | ||
| usageExamplesDocumented: false, | ||
| hasStorybookStories: false, | ||
| designReviewed: false, | ||
| a11yReviewed: false, | ||
| stableApi: false, | ||
| addressedApiFeedback: false, | ||
| hasDesignGuidelines: false, | ||
| hasFigmaComponent: false | ||
| }} | ||
| /> | ||
Uh oh!
There was an error while loading. Please reload this page.