datocms-react-ui 0.3.24 → 0.3.28
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/SelectInput/index.js +2 -2
- package/dist/cjs/SelectInput/index.js.map +1 -1
- package/dist/esm/SelectInput/index.js +2 -2
- package/dist/esm/SelectInput/index.js.map +1 -1
- package/package.json +4 -3
- package/src/Button/index.tsx +173 -0
- package/src/Button/styles.module.css +149 -0
- package/src/Button/styles.module.css.json +1 -0
- package/src/ButtonGroup/Button/index.tsx +40 -0
- package/src/ButtonGroup/Button/styles.module.css +72 -0
- package/src/ButtonGroup/Button/styles.module.css.json +1 -0
- package/src/ButtonGroup/Group/index.tsx +31 -0
- package/src/ButtonGroup/Group/styles.module.css +6 -0
- package/src/ButtonGroup/Group/styles.module.css.json +1 -0
- package/src/ButtonGroup/index.ts +4 -0
- package/src/Canvas/index.tsx +556 -0
- package/src/Canvas/styles.module.css +75 -0
- package/src/Canvas/styles.module.css.json +1 -0
- package/src/ContextInspector/index.tsx +316 -0
- package/src/ContextInspector/styles.module.css +90 -0
- package/src/ContextInspector/styles.module.css.json +1 -0
- package/src/Dropdown/Dropdown.tsx +171 -0
- package/src/Dropdown/DropdownContext.tsx +10 -0
- package/src/Dropdown/Group.tsx +16 -0
- package/src/Dropdown/Menu.tsx +351 -0
- package/src/Dropdown/MenuContext.tsx +18 -0
- package/src/Dropdown/Option.tsx +148 -0
- package/src/Dropdown/OptionAction.tsx +42 -0
- package/src/Dropdown/Portal.tsx +46 -0
- package/src/Dropdown/Separator.tsx +13 -0
- package/src/Dropdown/Text.tsx +8 -0
- package/src/Dropdown/index.tsx +26 -0
- package/src/Dropdown/styles.module.css +331 -0
- package/src/Dropdown/styles.module.css.json +1 -0
- package/src/FieldError/index.tsx +10 -0
- package/src/FieldError/styles.module.css +6 -0
- package/src/FieldError/styles.module.css.json +1 -0
- package/src/FieldGroup/index.tsx +25 -0
- package/src/FieldGroup/styles.module.css +12 -0
- package/src/FieldGroup/styles.module.css.json +1 -0
- package/src/FieldHint/index.tsx +10 -0
- package/src/FieldHint/styles.module.css +6 -0
- package/src/FieldHint/styles.module.css.json +1 -0
- package/src/Form/index.tsx +145 -0
- package/src/Form/styles.module.css +19 -0
- package/src/Form/styles.module.css.json +1 -0
- package/src/FormLabel/index.tsx +36 -0
- package/src/FormLabel/styles.module.css +31 -0
- package/src/FormLabel/styles.module.css.json +1 -0
- package/src/Section/index.tsx +104 -0
- package/src/Section/styles.module.css +100 -0
- package/src/Section/styles.module.css.json +1 -0
- package/src/SelectField/index.tsx +244 -0
- package/src/SelectInput/index.tsx +233 -0
- package/src/SidebarPanel/index.tsx +110 -0
- package/src/SidebarPanel/styles.module.css +49 -0
- package/src/SidebarPanel/styles.module.css.json +1 -0
- package/src/Spinner/index.tsx +68 -0
- package/src/Spinner/styles.module.css +31 -0
- package/src/Spinner/styles.module.css.json +1 -0
- package/src/SwitchField/index.tsx +67 -0
- package/src/SwitchField/styles.module.css +25 -0
- package/src/SwitchField/styles.module.css.json +1 -0
- package/src/SwitchInput/index.tsx +74 -0
- package/src/SwitchInput/styles.module.css +100 -0
- package/src/SwitchInput/styles.module.css.json +1 -0
- package/src/TextField/index.tsx +58 -0
- package/src/TextField/styles.module.css +0 -0
- package/src/TextField/styles.module.css.json +1 -0
- package/src/TextInput/index.tsx +73 -0
- package/src/TextInput/styles.module.css +52 -0
- package/src/TextInput/styles.module.css.json +1 -0
- package/src/Toolbar/Button/index.tsx +32 -0
- package/src/Toolbar/Button/styles.module.css +43 -0
- package/src/Toolbar/Button/styles.module.css.json +1 -0
- package/src/Toolbar/Stack/index.tsx +33 -0
- package/src/Toolbar/Stack/styles.module.css +18 -0
- package/src/Toolbar/Stack/styles.module.css.json +1 -0
- package/src/Toolbar/Title/index.tsx +17 -0
- package/src/Toolbar/Title/styles.module.css +12 -0
- package/src/Toolbar/Title/styles.module.css.json +1 -0
- package/src/Toolbar/Toolbar/index.tsx +112 -0
- package/src/Toolbar/Toolbar/styles.module.css +15 -0
- package/src/Toolbar/Toolbar/styles.module.css.json +1 -0
- package/src/Toolbar/index.ts +8 -0
- package/src/base.css +89 -0
- package/src/generateStyleFromCtx/index.ts +25 -0
- package/src/global.css +23 -0
- package/src/icons.tsx +108 -0
- package/src/index.ts +23 -0
- package/src/mergeRefs/index.ts +8 -0
- package/src/useClickOutside/index.ts +30 -0
- package/src/useMediaQuery/index.ts +185 -0
- package/types.json +8 -8
|
@@ -0,0 +1,331 @@
|
|
|
1
|
+
.Dropdown {
|
|
2
|
+
position: relative;
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
.Dropdown__spacer {
|
|
6
|
+
position: absolute;
|
|
7
|
+
inset: 0;
|
|
8
|
+
pointer-events: none;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
.Dropdown__menu__search {
|
|
12
|
+
padding: 7px;
|
|
13
|
+
border-bottom: 1px solid var(--border-color);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
.Dropdown__menu__search__input {
|
|
17
|
+
display: block;
|
|
18
|
+
box-sizing: border-box;
|
|
19
|
+
width: 100%;
|
|
20
|
+
border: 1px solid var(--border-color);
|
|
21
|
+
appearance: none;
|
|
22
|
+
background-image: none;
|
|
23
|
+
transition: border 0.2s var(--material-ease);
|
|
24
|
+
resize: none;
|
|
25
|
+
font-family: inherit;
|
|
26
|
+
padding: 8px;
|
|
27
|
+
border-radius: 3px;
|
|
28
|
+
font-size: 0.9em;
|
|
29
|
+
|
|
30
|
+
&::placeholder {
|
|
31
|
+
color: var(--placeholder-body-color);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
&:hover {
|
|
35
|
+
border-color: var(--darker-border-color);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
&:focus {
|
|
39
|
+
outline: 0;
|
|
40
|
+
border-color: var(--accent-color);
|
|
41
|
+
box-shadow: 0 0 0 3px var(--semi-transparent-accent-color);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
.Dropdown__menu-container {
|
|
46
|
+
position: fixed;
|
|
47
|
+
visibility: hidden;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
.Dropdown__menu {
|
|
51
|
+
min-width: 200px;
|
|
52
|
+
background-color: white;
|
|
53
|
+
box-shadow: 0 3px 10px rgba(0, 0, 0, 0.2);
|
|
54
|
+
border-radius: 4px;
|
|
55
|
+
margin-bottom: var(--spacing-xl);
|
|
56
|
+
padding: 1px 0;
|
|
57
|
+
text-align: initial;
|
|
58
|
+
margin-top: 10px;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
.Dropdown__menu__inner {
|
|
62
|
+
margin: 7px 0;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
.Dropdown__menu--fullscreen {
|
|
66
|
+
position: fixed;
|
|
67
|
+
top: var(--spacing-xl);
|
|
68
|
+
right: var(--spacing-l);
|
|
69
|
+
bottom: 1em;
|
|
70
|
+
margin-bottom: var(--spacing-xxl);
|
|
71
|
+
left: var(--spacing-l);
|
|
72
|
+
z-index: 2;
|
|
73
|
+
pointer-events: auto;
|
|
74
|
+
animation: FullscreenDropdown__appear 0.2s ease-out forwards;
|
|
75
|
+
}
|
|
76
|
+
@keyframes FullscreenDropdown__appear {
|
|
77
|
+
0% {
|
|
78
|
+
opacity: 0;
|
|
79
|
+
transform: translateY(100%);
|
|
80
|
+
}
|
|
81
|
+
100% {
|
|
82
|
+
opacity: 1;
|
|
83
|
+
transform: translateY(0);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
.Dropdown__menu__close {
|
|
88
|
+
position: fixed;
|
|
89
|
+
text-align: center;
|
|
90
|
+
top: auto;
|
|
91
|
+
right: var(--spacing-l);
|
|
92
|
+
bottom: var(--spacing-l);
|
|
93
|
+
left: var(--spacing-l);
|
|
94
|
+
z-index: 2;
|
|
95
|
+
margin-bottom: 0;
|
|
96
|
+
animation: FullscreenDropdown__appear 0.25s ease-out forwards;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
.Dropdown__menu__group__title {
|
|
100
|
+
padding: 5px 15px 3px;
|
|
101
|
+
color: var(--light-body-color);
|
|
102
|
+
background-color: var(--light-bg-color);
|
|
103
|
+
text-transform: uppercase;
|
|
104
|
+
font-size: var(--font-size-xs);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
.Dropdown__menu__group__content {
|
|
108
|
+
margin: 8px 0;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
.Dropdown__menu__text {
|
|
112
|
+
text-align: left;
|
|
113
|
+
padding: 4px 15px;
|
|
114
|
+
color: var(--light-body-color);
|
|
115
|
+
position: relative;
|
|
116
|
+
display: block;
|
|
117
|
+
line-height: 1.2;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
.Dropdown__menu__option {
|
|
121
|
+
text-align: left;
|
|
122
|
+
padding: 4px 15px;
|
|
123
|
+
color: var(--base-body-color);
|
|
124
|
+
position: relative;
|
|
125
|
+
text-decoration: none;
|
|
126
|
+
white-space: nowrap;
|
|
127
|
+
display: flex;
|
|
128
|
+
align-items: center;
|
|
129
|
+
|
|
130
|
+
&:hover,
|
|
131
|
+
&:focus {
|
|
132
|
+
background-color: var(--light-bg-color);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
& > a {
|
|
136
|
+
display: block;
|
|
137
|
+
text-decoration: none;
|
|
138
|
+
color: inherit;
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
.Dropdown__menu__option--is-selected {
|
|
143
|
+
background-color: var(--light-bg-color);
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
.Dropdown__menu__option--is-disabled {
|
|
147
|
+
opacity: 0.5;
|
|
148
|
+
|
|
149
|
+
.Dropdown__menu__option__content {
|
|
150
|
+
cursor: not-allowed;
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
.Dropdown__menu__option--is-dangerous {
|
|
155
|
+
color: var(--alert-color);
|
|
156
|
+
|
|
157
|
+
svg {
|
|
158
|
+
fill: var(--alert-color);
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
&:hover,
|
|
162
|
+
&:focus {
|
|
163
|
+
background-color: var(--alert-color);
|
|
164
|
+
color: white;
|
|
165
|
+
|
|
166
|
+
svg {
|
|
167
|
+
fill: white;
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
.Dropdown__menu__option--is-active {
|
|
173
|
+
font-weight: 500;
|
|
174
|
+
|
|
175
|
+
&:hover,
|
|
176
|
+
&:focus {
|
|
177
|
+
background-color: none;
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
.Dropdown__menu__option--is-valid {
|
|
182
|
+
padding-left: 35px;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
.Dropdown__menu__option--is-invalid {
|
|
186
|
+
padding-left: 35px;
|
|
187
|
+
|
|
188
|
+
&:before {
|
|
189
|
+
content: '';
|
|
190
|
+
position: absolute;
|
|
191
|
+
top: 50%;
|
|
192
|
+
transform: translateY(-50%);
|
|
193
|
+
left: 15px;
|
|
194
|
+
font-size: 12px;
|
|
195
|
+
border-radius: 4px;
|
|
196
|
+
height: 8px;
|
|
197
|
+
width: 8px;
|
|
198
|
+
background-color: var(--alert-color);
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
.Dropdown__menu__option__content {
|
|
203
|
+
flex: 1;
|
|
204
|
+
text-align: left;
|
|
205
|
+
font-family: inherit;
|
|
206
|
+
cursor: pointer;
|
|
207
|
+
line-height: inherit;
|
|
208
|
+
background-color: transparent;
|
|
209
|
+
color: inherit;
|
|
210
|
+
-webkit-appearance: none;
|
|
211
|
+
-moz-appearance: none;
|
|
212
|
+
box-sizing: border-box;
|
|
213
|
+
border: 0;
|
|
214
|
+
padding: 0;
|
|
215
|
+
font-size: inherit;
|
|
216
|
+
font-weight: inherit;
|
|
217
|
+
|
|
218
|
+
> svg {
|
|
219
|
+
font-size: 13px;
|
|
220
|
+
padding-right: 8px;
|
|
221
|
+
display: inline-block;
|
|
222
|
+
vertical-align: middle;
|
|
223
|
+
color: var(--light-body-color);
|
|
224
|
+
fill: var(--light-body-color);
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
.Dropdown__menu__option__icons {
|
|
229
|
+
padding-left: 15px;
|
|
230
|
+
display: flex;
|
|
231
|
+
align-items: center;
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
.Dropdown__menu__option__icon {
|
|
235
|
+
font-family: inherit;
|
|
236
|
+
cursor: pointer;
|
|
237
|
+
line-height: inherit;
|
|
238
|
+
background-color: transparent;
|
|
239
|
+
color: var(--base-body-color);
|
|
240
|
+
-webkit-appearance: none;
|
|
241
|
+
-moz-appearance: none;
|
|
242
|
+
box-sizing: border-box;
|
|
243
|
+
border: 0;
|
|
244
|
+
padding: 0;
|
|
245
|
+
width: 100%;
|
|
246
|
+
font-size: inherit;
|
|
247
|
+
width: auto;
|
|
248
|
+
opacity: 0;
|
|
249
|
+
line-height: 10px;
|
|
250
|
+
color: var(--light-body-color);
|
|
251
|
+
padding: 3px;
|
|
252
|
+
font-size: 13px;
|
|
253
|
+
position: relative;
|
|
254
|
+
top: -1px;
|
|
255
|
+
display: inline-block;
|
|
256
|
+
transition: transform 0.1s ease-in-out;
|
|
257
|
+
|
|
258
|
+
.Dropdown__menu__option:hover & {
|
|
259
|
+
opacity: 1;
|
|
260
|
+
}
|
|
261
|
+
.Dropdown__menu__option:focus & {
|
|
262
|
+
opacity: 1;
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
&:hover,
|
|
266
|
+
&:focus {
|
|
267
|
+
transform: scale(1.2);
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
svg {
|
|
271
|
+
fill: var(--light-body-color);
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
.Dropdown__menu__option__icon--delete {
|
|
276
|
+
color: var(--alert-color);
|
|
277
|
+
svg {
|
|
278
|
+
fill: var(--alert-color);
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
.Dropdown__menu__separator {
|
|
283
|
+
margin: 8px 0;
|
|
284
|
+
height: 1px;
|
|
285
|
+
background-color: var(--border-color);
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
.Dropdown__menu {
|
|
289
|
+
overflow-y: auto;
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
.Dropdown__menu__mobile-container {
|
|
293
|
+
position: fixed;
|
|
294
|
+
top: 0;
|
|
295
|
+
left: 0;
|
|
296
|
+
right: 0;
|
|
297
|
+
bottom: 0;
|
|
298
|
+
z-index: 10002;
|
|
299
|
+
overflow: auto;
|
|
300
|
+
|
|
301
|
+
.Dropdown__menu {
|
|
302
|
+
-webkit-overflow-scrolling: touch;
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
.Modal__backdrop {
|
|
307
|
+
background: linear-gradient(
|
|
308
|
+
to bottom,
|
|
309
|
+
rgba(48, 48, 47, 0.9),
|
|
310
|
+
rgba(48, 48, 47, 0.7)
|
|
311
|
+
);
|
|
312
|
+
position: fixed;
|
|
313
|
+
top: 0;
|
|
314
|
+
left: 0;
|
|
315
|
+
right: 0;
|
|
316
|
+
bottom: 0;
|
|
317
|
+
z-index: 1;
|
|
318
|
+
animation: Modal__appear 0.2s var(--material-ease);
|
|
319
|
+
animation-fill-mode: both;
|
|
320
|
+
pointer-events: none;
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
@keyframes Modal__appear {
|
|
324
|
+
0% {
|
|
325
|
+
opacity: 0;
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
100% {
|
|
329
|
+
opacity: 1;
|
|
330
|
+
}
|
|
331
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"Dropdown":"_Dropdown_1hebg_1","Dropdown__spacer":"_Dropdown__spacer_1hebg_5","Dropdown__menu__search":"_Dropdown__menu__search_1hebg_11","Dropdown__menu__search__input":"_Dropdown__menu__search__input_1hebg_16","Dropdown__menu-container":"_Dropdown__menu-container_1hebg_45","Dropdown__menu":"_Dropdown__menu_1hebg_11","Dropdown__menu__inner":"_Dropdown__menu__inner_1hebg_61","Dropdown__menu--fullscreen":"_Dropdown__menu--fullscreen_1hebg_65","FullscreenDropdown__appear":"_FullscreenDropdown__appear_1hebg_1","Dropdown__menu__close":"_Dropdown__menu__close_1hebg_87","Dropdown__menu__group__title":"_Dropdown__menu__group__title_1hebg_99","Dropdown__menu__group__content":"_Dropdown__menu__group__content_1hebg_107","Dropdown__menu__text":"_Dropdown__menu__text_1hebg_111","Dropdown__menu__option":"_Dropdown__menu__option_1hebg_120","Dropdown__menu__option--is-selected":"_Dropdown__menu__option--is-selected_1hebg_142","Dropdown__menu__option--is-disabled":"_Dropdown__menu__option--is-disabled_1hebg_146","Dropdown__menu__option__content":"_Dropdown__menu__option__content_1hebg_149","Dropdown__menu__option--is-dangerous":"_Dropdown__menu__option--is-dangerous_1hebg_154","Dropdown__menu__option--is-active":"_Dropdown__menu__option--is-active_1hebg_172","Dropdown__menu__option--is-valid":"_Dropdown__menu__option--is-valid_1hebg_181","Dropdown__menu__option--is-invalid":"_Dropdown__menu__option--is-invalid_1hebg_185","Dropdown__menu__option__icons":"_Dropdown__menu__option__icons_1hebg_228","Dropdown__menu__option__icon":"_Dropdown__menu__option__icon_1hebg_228","Dropdown__menu__option__icon--delete":"_Dropdown__menu__option__icon--delete_1hebg_275","Dropdown__menu__separator":"_Dropdown__menu__separator_1hebg_282","Dropdown__menu__mobile-container":"_Dropdown__menu__mobile-container_1hebg_292","Modal__backdrop":"_Modal__backdrop_1hebg_306","Modal__appear":"_Modal__appear_1hebg_1"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import React, { ReactNode } from 'react';
|
|
2
|
+
import s from './styles.module.css.json';
|
|
3
|
+
|
|
4
|
+
type FieldErrorProps = {
|
|
5
|
+
children: ReactNode;
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
export function FieldError({ children }: FieldErrorProps): JSX.Element {
|
|
9
|
+
return <div className={s.fieldError}>{children}</div>;
|
|
10
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"fieldError":"_fieldError_qi0xk_1"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import cn from 'classnames';
|
|
3
|
+
import styles from './styles.module.css.json';
|
|
4
|
+
|
|
5
|
+
export interface FieldGroupProps {
|
|
6
|
+
className?: string;
|
|
7
|
+
children: React.ReactNode;
|
|
8
|
+
style?: React.CSSProperties;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export function FieldGroup({
|
|
12
|
+
children,
|
|
13
|
+
className,
|
|
14
|
+
...otherProps
|
|
15
|
+
}: FieldGroupProps): JSX.Element {
|
|
16
|
+
const classNames = cn(styles.FieldGroup, className);
|
|
17
|
+
|
|
18
|
+
return (
|
|
19
|
+
<div {...otherProps} className={classNames}>
|
|
20
|
+
{React.Children.map(children, (child) => (
|
|
21
|
+
<div className={styles.FieldGroup__item}>{child}</div>
|
|
22
|
+
))}
|
|
23
|
+
</div>
|
|
24
|
+
);
|
|
25
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"FieldGroup":"_FieldGroup_uz9ju_1","FieldGroup__item":"_FieldGroup__item_uz9ju_5"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import React, { ReactNode } from 'react';
|
|
2
|
+
import s from './styles.module.css.json';
|
|
3
|
+
|
|
4
|
+
type FieldHintProps = {
|
|
5
|
+
children: ReactNode;
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
export function FieldHint({ children }: FieldHintProps): JSX.Element {
|
|
9
|
+
return <div className={s.fieldHint}>{children}</div>;
|
|
10
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"fieldHint":"_fieldHint_1dor2_1"}
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
import React, {
|
|
2
|
+
Children,
|
|
3
|
+
useCallback,
|
|
4
|
+
CSSProperties,
|
|
5
|
+
FormEventHandler,
|
|
6
|
+
FormEvent,
|
|
7
|
+
ReactNode,
|
|
8
|
+
} from 'react';
|
|
9
|
+
import cn from 'classnames';
|
|
10
|
+
import styles from './styles.module.css.json';
|
|
11
|
+
|
|
12
|
+
export interface FormProps {
|
|
13
|
+
onSubmit?: FormEventHandler;
|
|
14
|
+
spacing?: 'condensed' | 'default';
|
|
15
|
+
style?: CSSProperties;
|
|
16
|
+
className?: string;
|
|
17
|
+
children: ReactNode;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* @example Full example
|
|
22
|
+
*
|
|
23
|
+
* ```js
|
|
24
|
+
* <Canvas ctx={ctx}>
|
|
25
|
+
* <Form onSubmit={() => console.log('onSubmit')}>
|
|
26
|
+
* <FieldGroup>
|
|
27
|
+
* <TextField
|
|
28
|
+
* required
|
|
29
|
+
* name="name"
|
|
30
|
+
* id="name"
|
|
31
|
+
* label="Name"
|
|
32
|
+
* value="Mark Smith"
|
|
33
|
+
* placeholder="Enter full name"
|
|
34
|
+
* hint="Provide a full name"
|
|
35
|
+
* onChange={(newValue) => console.log(newValue)}
|
|
36
|
+
* />
|
|
37
|
+
* <TextField
|
|
38
|
+
* required
|
|
39
|
+
* name="email"
|
|
40
|
+
* id="email"
|
|
41
|
+
* label="Email"
|
|
42
|
+
* type="email"
|
|
43
|
+
* value=""
|
|
44
|
+
* placeholder="your@email.com"
|
|
45
|
+
* error="Please enter an email!"
|
|
46
|
+
* hint="Enter email address"
|
|
47
|
+
* onChange={(newValue) => console.log(newValue)}
|
|
48
|
+
* />
|
|
49
|
+
* <TextField
|
|
50
|
+
* required
|
|
51
|
+
* name="apiToken"
|
|
52
|
+
* id="apiToken"
|
|
53
|
+
* label="API Token"
|
|
54
|
+
* value="XXXYYY123"
|
|
55
|
+
* hint="Enter a valid API token"
|
|
56
|
+
* textInputProps={{ monospaced: true }}
|
|
57
|
+
* onChange={(newValue) => console.log(newValue)}
|
|
58
|
+
* />
|
|
59
|
+
* <SelectField
|
|
60
|
+
* name="option"
|
|
61
|
+
* id="option"
|
|
62
|
+
* label="Option"
|
|
63
|
+
* hint="Select one of the options"
|
|
64
|
+
* value={{ label: 'Option 1', value: 'option1' }}
|
|
65
|
+
* selectInputProps={{
|
|
66
|
+
* options: [
|
|
67
|
+
* { label: 'Option 1', value: 'option1' },
|
|
68
|
+
* { label: 'Option 2', value: 'option2' },
|
|
69
|
+
* { label: 'Option 3', value: 'option3' },
|
|
70
|
+
* ],
|
|
71
|
+
* }}
|
|
72
|
+
* onChange={(newValue) => console.log(newValue)}
|
|
73
|
+
* />
|
|
74
|
+
* <SelectField
|
|
75
|
+
* name="multipleOption"
|
|
76
|
+
* id="multipleOption"
|
|
77
|
+
* label="Multiple options"
|
|
78
|
+
* hint="Select one of the options"
|
|
79
|
+
* value={[
|
|
80
|
+
* { label: 'Option 1', value: 'option1' },
|
|
81
|
+
* { label: 'Option 2', value: 'option2' },
|
|
82
|
+
* ]}
|
|
83
|
+
* selectInputProps={{
|
|
84
|
+
* isMulti: true,
|
|
85
|
+
* options: [
|
|
86
|
+
* { label: 'Option 1', value: 'option1' },
|
|
87
|
+
* { label: 'Option 2', value: 'option2' },
|
|
88
|
+
* { label: 'Option 3', value: 'option3' },
|
|
89
|
+
* ],
|
|
90
|
+
* }}
|
|
91
|
+
* onChange={(newValue) => console.log(newValue)}
|
|
92
|
+
* />
|
|
93
|
+
* <SwitchField
|
|
94
|
+
* name="debugMode"
|
|
95
|
+
* id="debugMode"
|
|
96
|
+
* label="Debug mode active?"
|
|
97
|
+
* hint="Logs messages to console"
|
|
98
|
+
* value={true}
|
|
99
|
+
* onChange={(newValue) => console.log(newValue)}
|
|
100
|
+
* />
|
|
101
|
+
* </FieldGroup>
|
|
102
|
+
* <FieldGroup>
|
|
103
|
+
* <Button fullWidth buttonType="primary">
|
|
104
|
+
* Submit
|
|
105
|
+
* </Button>
|
|
106
|
+
* </FieldGroup>
|
|
107
|
+
* </Form>
|
|
108
|
+
* </Canvas>;
|
|
109
|
+
* ```
|
|
110
|
+
*/
|
|
111
|
+
export const Form = ({
|
|
112
|
+
children,
|
|
113
|
+
className,
|
|
114
|
+
onSubmit,
|
|
115
|
+
spacing = 'default',
|
|
116
|
+
...otherProps
|
|
117
|
+
}: FormProps): JSX.Element => {
|
|
118
|
+
const classNames = cn(styles.Form, className);
|
|
119
|
+
|
|
120
|
+
const formItemClassNames = cn(
|
|
121
|
+
styles.Form__item,
|
|
122
|
+
styles[`Form__item--${spacing}`],
|
|
123
|
+
);
|
|
124
|
+
|
|
125
|
+
const handleSubmit = useCallback(
|
|
126
|
+
(event: FormEvent) => {
|
|
127
|
+
event.preventDefault();
|
|
128
|
+
if (onSubmit) {
|
|
129
|
+
onSubmit(event);
|
|
130
|
+
}
|
|
131
|
+
},
|
|
132
|
+
[onSubmit],
|
|
133
|
+
);
|
|
134
|
+
|
|
135
|
+
return (
|
|
136
|
+
<form className={classNames} onSubmit={handleSubmit} {...otherProps}>
|
|
137
|
+
{Children.map(children, (child) => {
|
|
138
|
+
if (child) {
|
|
139
|
+
return <div className={formItemClassNames}>{child}</div>;
|
|
140
|
+
}
|
|
141
|
+
return null;
|
|
142
|
+
})}
|
|
143
|
+
</form>
|
|
144
|
+
);
|
|
145
|
+
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
.Form {
|
|
2
|
+
display: block;
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
.Form__item {
|
|
6
|
+
display: block;
|
|
7
|
+
|
|
8
|
+
&:last-child {
|
|
9
|
+
margin-bottom: 0;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
.Form__item--default {
|
|
14
|
+
margin-bottom: var(--spacing-l);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
.Form__item--condensed {
|
|
18
|
+
margin-bottom: var(--spacing-m);
|
|
19
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"Form":"_Form_5qspp_1","Form__item":"_Form__item_5qspp_5","Form__item--default":"_Form__item--default_5qspp_13","Form__item--condensed":"_Form__item--condensed_5qspp_17"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import cn from 'classnames';
|
|
3
|
+
import s from './styles.module.css.json';
|
|
4
|
+
|
|
5
|
+
export interface FormLabelProps {
|
|
6
|
+
htmlFor: string;
|
|
7
|
+
children: React.ReactNode;
|
|
8
|
+
className?: string;
|
|
9
|
+
required?: boolean;
|
|
10
|
+
error?: boolean;
|
|
11
|
+
code?: React.ReactNode;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export const FormLabel = ({
|
|
15
|
+
children,
|
|
16
|
+
className,
|
|
17
|
+
htmlFor,
|
|
18
|
+
code,
|
|
19
|
+
required = false,
|
|
20
|
+
error = false,
|
|
21
|
+
...otherProps
|
|
22
|
+
}: FormLabelProps): JSX.Element => {
|
|
23
|
+
const classNames = cn(s.formLabel, className, {
|
|
24
|
+
[s['formLabel--error']]: error,
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
return (
|
|
28
|
+
<label className={classNames} htmlFor={htmlFor} {...otherProps}>
|
|
29
|
+
<span className={s.formLabel__label}>
|
|
30
|
+
{children}
|
|
31
|
+
{required && <span className={s.formLabel__required}>*</span>}
|
|
32
|
+
</span>
|
|
33
|
+
{code && <span className={s.formLabel__code}>{code}</span>}
|
|
34
|
+
</label>
|
|
35
|
+
);
|
|
36
|
+
};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
.formLabel {
|
|
2
|
+
display: flex;
|
|
3
|
+
color: var(--light-body-color);
|
|
4
|
+
margin-bottom: var(--spacing-s);
|
|
5
|
+
align-items: center;
|
|
6
|
+
|
|
7
|
+
&:hover {
|
|
8
|
+
.formLabel__code {
|
|
9
|
+
opacity: 1;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
.formLabel--error {
|
|
15
|
+
color: var(--alert-color);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
.formLabel__label {
|
|
19
|
+
flex: 1;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
.formLabel__code {
|
|
23
|
+
font-family: var(--monospaced-font-family);
|
|
24
|
+
font-size: 0.95em;
|
|
25
|
+
position: absolute;
|
|
26
|
+
opacity: 0;
|
|
27
|
+
transition: opacity 0.2s var(--material-ease);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
.formLabel__required {
|
|
31
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"formLabel":"_formLabel_tcjrv_1","formLabel__code":"_formLabel__code_tcjrv_8","formLabel--error":"_formLabel--error_tcjrv_14","formLabel__label":"_formLabel__label_tcjrv_18","formLabel__required":"_formLabel__required_tcjrv_30"}
|