-
Notifications
You must be signed in to change notification settings - Fork 4.3k
/
index.js
182 lines (172 loc) · 4.36 KB
/
index.js
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
/**
* WordPress dependencies
*/
import {
alignCenter,
alignLeft,
alignRight,
code,
formatBold,
formatItalic,
formatStrikethrough,
link,
more,
paragraph,
} from '@wordpress/icons';
/**
* Internal dependencies
*/
import Toolbar from '../';
import {
SVG,
Path,
ToolbarButton,
ToolbarGroup,
__experimentalToolbarItem as ToolbarItem,
DropdownMenu,
} from '../../';
export default { title: 'Components/Toolbar', component: Toolbar };
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>
);
}
/* eslint-disable no-restricted-syntax */
export const _default = () => {
return (
// id is required for server side rendering
<Toolbar
__experimentalAccessibilityLabel="Options"
id="options-toolbar"
>
<ToolbarGroup>
<ToolbarButton icon={ paragraph } label="Paragraph" />
</ToolbarGroup>
<ToolbarGroup>
<ToolbarItem>
{ ( toggleProps ) => (
<DropdownMenu
hasArrowIndicator
icon={ alignLeft }
label="Change text alignment"
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={ false }
label="More rich text controls"
controls={ [
{ icon: code, title: 'Inline code' },
{ icon: <InlineImageIcon />, title: 'Inline image' },
{
icon: formatStrikethrough,
title: 'Strikethrough',
},
] }
/>
</ToolbarGroup>
<ToolbarGroup
icon={ more }
label="Change text alignment"
isCollapsed
controls={ [
{
icon: alignLeft,
title: 'Align left',
isActive: true,
},
{ icon: alignCenter, title: 'Align center' },
{ icon: alignRight, title: 'Align right' },
] }
/>
</Toolbar>
);
};
export const withoutGroup = () => {
return (
// id is required for server side rendering
<Toolbar
__experimentalAccessibilityLabel="Options"
id="options-toolbar-without-group"
>
<ToolbarButton icon={ formatBold } label="Bold" isPressed />
<ToolbarButton icon={ formatItalic } label="Italic" />
<ToolbarButton icon={ link } label="Link" />
</Toolbar>
);
};
/* eslint-enable no-restricted-syntax */
export const toolbars = () => {
return (
<div>
<div style={ { padding: '20px' } }>
<h2>Icon-only Toolbar</h2>
<Toolbar>
<ToolbarButton icon={ formatBold } title="Bold" />
<ToolbarButton
icon={ formatItalic }
title="Italic"
isActive
/>
<ToolbarButton icon={ link } title="Link" />
</Toolbar>
</div>
<div style={ { padding: '20px' } }>
<h2>Text-only Toolbar</h2>
<Toolbar>
<ToolbarButton>Bold Format</ToolbarButton>
<ToolbarButton isActive>Italic Format</ToolbarButton>
<ToolbarButton>Link Format</ToolbarButton>
</Toolbar>
</div>
<div style={ { padding: '20px' } }>
<h2>Text and Icon Toolbar</h2>
<Toolbar>
<ToolbarButton icon={ formatBold } title="Bold" />
<ToolbarButton isActive>Bold Format</ToolbarButton>
<ToolbarButton icon={ formatItalic } title="Italic" />
<ToolbarButton>Italic Format</ToolbarButton>
<ToolbarButton icon={ link } title="Link" />
<ToolbarButton>Link Format</ToolbarButton>
</Toolbar>
</div>
<div style={ { padding: '20px' } }>
<h2>Single Icon Button Toolbar</h2>
<Toolbar>
<ToolbarButton icon={ formatBold } title="Bold" />
</Toolbar>
</div>
<div style={ { padding: '20px' } }>
<h2>Single Text Button toolbar</h2>
<Toolbar>
<ToolbarButton>Bold Toolbar</ToolbarButton>
</Toolbar>
</div>
</div>
);
};