-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathbuttonGroup.stories.js
More file actions
55 lines (49 loc) · 1.11 KB
/
buttonGroup.stories.js
File metadata and controls
55 lines (49 loc) · 1.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import React, { useCallback, useState } from "react"
import { ButtonGroup } from "."
export const RadioButtonGroup = args => {
const [checked, setChecked] = useState(args.checked)
return (
<ButtonGroup
items={args.items.map(item => ({ ...item }))}
checked={checked}
buttonProps={args}
onChange={setChecked}
/>
)
}
export const MultiButtonGroup = args => {
const [checked, setChecked] = useState([args.checked])
const onChange = useCallback(
value => {
setChecked(prev => {
if (prev.includes(value)) return prev.filter(v => v !== value)
return [...prev, value]
})
},
[setChecked]
)
return (
<ButtonGroup
items={args.items.map(item => ({ ...item }))}
checked={checked}
buttonProps={args}
onChange={onChange}
/>
)
}
export default {
component: ButtonGroup,
tags: ["autodocs"],
args: {
items: [
{ label: "One", value: 1 },
{ label: "Two", value: 2 },
{ label: "Three", value: 3 },
],
checked: 1,
buttonProps: {},
},
argTypes: {
checked: { control: "text" },
},
}