-
Notifications
You must be signed in to change notification settings - Fork 4.3k
/
Copy pathindex.story.tsx
198 lines (188 loc) · 4.31 KB
/
index.story.tsx
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
/**
* External dependencies
*/
import type { Meta, StoryFn } from '@storybook/react';
/**
* WordPress dependencies
*/
import {
alignCenter,
alignLeft,
alignRight,
code,
formatBold,
formatItalic,
formatStrikethrough,
link,
more,
paragraph,
arrowUp,
arrowDown,
arrowLeft,
arrowRight,
chevronDown,
} from '@wordpress/icons';
import { SVG, Path } from '@wordpress/primitives';
/**
* Internal dependencies
*/
import {
Toolbar,
ToolbarButton,
ToolbarGroup,
ToolbarItem,
ToolbarDropdownMenu,
} from '..';
import DropdownMenu from '../../dropdown-menu';
const meta: Meta< typeof Toolbar > = {
title: 'Components/Toolbar',
component: Toolbar,
subcomponents: {
// @ts-expect-error - See https://github.com/storybookjs/storybook/issues/23170
ToolbarButton,
// @ts-expect-error - See https://github.com/storybookjs/storybook/issues/23170
ToolbarGroup,
// @ts-expect-error - See https://github.com/storybookjs/storybook/issues/23170
ToolbarItem,
// @ts-expect-error - See https://github.com/storybookjs/storybook/issues/23170
ToolbarDropdownMenu,
},
argTypes: {
children: { control: { type: null } },
variant: {
options: [ undefined, 'unstyled' ],
control: { type: 'radio' },
},
},
parameters: {
controls: { expanded: true },
docs: { canvas: { sourceState: 'shown' } },
},
};
export default meta;
function InlineImageIcon() {
return (
<SVG xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24">
<Path d="M4 18.5h16V17H4v1.5zM16 13v1.5h4V13h-4zM5.1 15h7.8c.6 0 1.1-.5 1.1-1.1V6.1c0-.6-.5-1.1-1.1-1.1H5.1C4.5 5 4 5.5 4 6.1v7.8c0 .6.5 1.1 1.1 1.1zm.4-8.5h7V10l-1-1c-.3-.3-.8-.3-1 0l-1.6 1.5-1.2-.7c-.3-.2-.6-.2-.9 0l-1.3 1V6.5zm0 6.1l1.8-1.3 1.3.8c.3.2.7.2.9-.1l1.5-1.4 1.5 1.4v1.5h-7v-.9z" />
</SVG>
);
}
const Template: StoryFn< typeof Toolbar > = ( props ) => (
<div style={ { height: 280 } }>
<Toolbar { ...props } />
</div>
);
export const Default = Template.bind( {} );
Default.args = {
label: 'Options',
id: 'options-toolbar',
children: (
<>
<ToolbarGroup>
<ToolbarButton icon={ paragraph } text="Paragraph" />
</ToolbarGroup>
<ToolbarGroup>
<ToolbarItem>
{ ( toggleProps ) => (
<DropdownMenu
icon={ alignLeft }
label="Align"
controls={ [
{
icon: alignLeft,
title: 'Align left',
isActive: true,
},
{
icon: alignCenter,
title: 'Align center',
},
{
icon: alignRight,
title: 'Align right',
},
] }
toggleProps={ toggleProps }
/>
) }
</ToolbarItem>
</ToolbarGroup>
<ToolbarGroup>
<ToolbarButton>Text</ToolbarButton>
<ToolbarButton icon={ formatBold } label="Bold" isPressed />
<ToolbarButton icon={ formatItalic } label="Italic" />
<ToolbarButton icon={ link } label="Link" />
<ToolbarGroup
isCollapsed
icon={ null }
title="More rich text controls"
controls={ [
{ icon: code, title: 'Inline code' },
{ icon: <InlineImageIcon />, title: 'Inline image' },
{
icon: formatStrikethrough,
title: 'Strikethrough',
},
] }
/>
</ToolbarGroup>
<ToolbarGroup
icon={ more }
title="Align"
isCollapsed
controls={ [
{
icon: alignLeft,
title: 'Align left',
isActive: true,
},
{ icon: alignCenter, title: 'Align center' },
{ icon: alignRight, title: 'Align right' },
] }
/>
<ToolbarDropdownMenu
icon={ chevronDown }
label="Select a direction"
controls={ [
{
title: 'Up',
icon: arrowUp,
},
{
title: 'Right',
icon: arrowRight,
},
{
title: 'Down',
icon: arrowDown,
},
{
title: 'Left',
icon: arrowLeft,
},
] }
/>
</>
),
};
export const WithoutGroup = Template.bind( {} );
WithoutGroup.args = {
label: 'Options',
id: 'options-toolbar-without-group',
children: (
<>
<ToolbarButton icon={ formatBold } label="Bold" isPressed />
<ToolbarButton icon={ formatItalic } label="Italic" />
<ToolbarButton icon={ link } label="Link" />
</>
),
};
/**
* Set the variant to `unstyled` to remove default border styles.
* Otherwise, leave it as `undefined` for default styles.
*/
export const Unstyled = Template.bind( {} );
Unstyled.args = {
...Default.args,
variant: 'unstyled',
};