Skip to content

Commit 56a73c0

Browse files
committed
docs: improve segmented control documentation
1 parent 30e9c12 commit 56a73c0

File tree

3 files changed

+67
-6
lines changed

3 files changed

+67
-6
lines changed
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import {
2+
Meta,
3+
Controls,
4+
Description,
5+
Primary,
6+
Source,
7+
Stories,
8+
Subtitle,
9+
Title,
10+
} from '@storybook/addon-docs/blocks';
11+
12+
import * as SegmentedControlStories from './segmented-control.stories';
13+
14+
<Meta of={SegmentedControlStories} />
15+
16+
<Title />
17+
<Subtitle />
18+
<Description />
19+
<Primary />
20+
<Controls />
21+
22+
## Code Examples
23+
24+
### Controlling state
25+
26+
You must manage the state of the active segment yourself by listening to the
27+
`scoutChange` event and updating the `value` prop accordingly.
28+
29+
<Source
30+
language="tsx"
31+
code={`
32+
import { useState } from "react";
33+
import { ScoutSegmentedControl } from "@scouterna/ui-react";
34+
35+
const [activeSegment, setActiveSegment] = useState(0);
36+
37+
return (
38+
<ScoutSegmentedControl
39+
value={activeSegment}
40+
onScoutChange={(e) => setActiveSegment(e.detail.value)}
41+
>
42+
<button type="button">Alla</button>
43+
<button type="button">Bokade</button>
44+
</ScoutSegmentedControl>
45+
);
46+
`}
47+
/>
48+
49+
## Stories
50+
51+
<Stories title={false} />

packages/ui-webc/src/components/segmented-control/readme.md

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,14 @@
55

66
## Overview
77

8-
The segmented control component is used to create a segmented interface. It
9-
manages the state of which segment is active and displays an indicator under
10-
the active segment. Use button elements to define the individual segments.
8+
The segmented control component presents a set of options where exactly one
9+
option is active at a time.
10+
11+
The component displays an indicator under the selected option and emits a
12+
`scoutChange` event when the user picks a different option, so you can update
13+
`value`.
14+
15+
Use button elements as the slotted segment options.
1116

1217
## Properties
1318

packages/ui-webc/src/components/segmented-control/segmented-control.tsx

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,14 @@ import {
1515
export type Size = "small" | "medium";
1616

1717
/**
18-
* The segmented control component is used to create a segmented interface. It
19-
* manages the state of which segment is active and displays an indicator under
20-
* the active segment. Use button elements to define the individual segments.
18+
* The segmented control component presents a set of options where exactly one
19+
* option is active at a time.
20+
*
21+
* The component displays an indicator under the selected option and emits a
22+
* `scoutChange` event when the user picks a different option, so you can update
23+
* `value`.
24+
*
25+
* Use button elements as the slotted segment options.
2126
*/
2227
@Component({
2328
tag: "scout-segmented-control",

0 commit comments

Comments
 (0)