import { SegmentedControls } from '@uhg-abyss/mobile';() => { const form = useForm({ defaultValues: { 'segmented-controls-sandbox': 'one', }, });
return ( <FormProvider state={form}> <SegmentedControls model="segmented-controls-sandbox"> <SegmentedControls.Tab label="One" value="one" /> <SegmentedControls.Tab label="Two" value="two" /> <SegmentedControls.Tab label="Three" value="three" /> </SegmentedControls> </FormProvider> );};useForm (recommended)
Using the useForm hook with FormProvider sets state for the component.
useState
Using the useState hook gets values from the component state.
Label
The label prop is used to define the display in each Tab. The label can be an Icon or text.
Structure
Segmented controls consist of a parent element and several children. The parent element <SegmentedControls /> handles the active Tab state.
While the children define the segments of the component.
Each child is a Tab: <SegmentedControls.Tab /> A new child is required for every segment.
Shrink
The shrink prop toggles whether the component will take up the full width of the parent container. When true, they will automatically size based on the number of tabs and their content. Defaults to false.
Example
Dynamic Type
SegmentedControls scale to 3XL. Any icons passed to the label prop will need to set maxFontSizeMultiplier={1.3}.
SegmentedControls Props
| Prop Name | Type | Default | Description |
|---|---|---|---|
| children | node | - | Defines the tab children |
| onChange | function | - | Callback fired when the active tab changes |
| shrink | boolean | false | Toggles between width filling parent and width matching tabs and content |
| value | string | number | - | The SegmentedControls Tabs |
SegmentedControls.Tab Props
| Prop Name | Type | Default | Description |
|---|---|---|---|
| label | string | number | node | - | Defines the label of the tab, which can be a node for icons |
| value | string | - | Defines the value of the tab |
SegmentedControls Classes
| Class Name | Description |
|---|---|
| abyss-segmented-controls-root | Segmented controls root element |
| abyss-segmented-controls-selected-tab | Selected tab in the controls |
SegmentedControls.Tab Classes
| Class Name | Description |
|---|---|
| abyss-segmented-controls-tab-root | Segmented controls root element |
SegmentedControls Tokens
| Token Name | Value | |
|---|---|---|
| segmented-control.color.surface.container | #F3F3F3 | |
| segmented-control.color.surface.option | #FFFFFF | |
| segmented-control.color.text.rest | #4B4D4F | |
| segmented-control.color.text.active | #323334 | |
| segmented-control.border-radius.all.container | 500 | |
| segmented-control.border-radius.all.option | 500 | |
| segmented-control.spacing.padding.all.container | 6 | |
| segmented-control.spacing.padding.horizontal.option | 12 | |
| segmented-control.spacing.padding.vertical.option | 6 | |
| segmented-control.box-shadow.option |
|