@charcoal-ui/react 2.0.0-alpha.20 → 2.0.0-alpha.22
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/README.md +16 -0
- package/dist/components/LoadingSpinner/index.d.ts +15 -0
- package/dist/components/LoadingSpinner/index.d.ts.map +1 -0
- package/dist/components/LoadingSpinner/index.story.d.ts +10 -0
- package/dist/components/LoadingSpinner/index.story.d.ts.map +1 -0
- package/dist/components/TextField/index.d.ts +3 -0
- package/dist/components/TextField/index.d.ts.map +1 -1
- package/dist/components/TextField/index.story.d.ts.map +1 -1
- package/dist/core/SSRProvider.d.ts +2 -0
- package/dist/core/SSRProvider.d.ts.map +1 -0
- package/dist/index.cjs +1120 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.modern.js +1006 -36
- package/dist/index.modern.js.map +1 -1
- package/dist/index.module.js +1097 -1
- package/dist/index.module.js.map +1 -1
- package/package.json +8 -7
- package/src/components/LoadingSpinner/index.story.tsx +52 -0
- package/src/components/LoadingSpinner/index.tsx +87 -0
- package/src/components/TextField/index.story.tsx +2 -8
- package/src/components/TextField/index.tsx +5 -4
- package/src/core/SSRProvider.tsx +1 -0
- package/src/index.ts +7 -0
package/dist/index.modern.js
CHANGED
|
@@ -1,11 +1,126 @@
|
|
|
1
|
-
import
|
|
1
|
+
import React, { useContext, useCallback, createContext, useMemo, useRef, useState, useEffect, useImperativeHandle } from 'react';
|
|
2
|
+
export { SSRProvider } from '@react-aria/ssr';
|
|
3
|
+
import styled, { css, keyframes } from 'styled-components';
|
|
4
|
+
import { createTheme } from '@charcoal-ui/styled';
|
|
5
|
+
import { disabledSelector, px } from '@charcoal-ui/utils';
|
|
6
|
+
import warning from 'warning';
|
|
7
|
+
import { useSwitch } from '@react-aria/switch';
|
|
8
|
+
import { useToggleState } from 'react-stately';
|
|
9
|
+
import { useTextField } from '@react-aria/textfield';
|
|
10
|
+
import { useVisuallyHidden } from '@react-aria/visually-hidden';
|
|
11
|
+
import '@charcoal-ui/icons';
|
|
12
|
+
import { transparentize } from 'polished';
|
|
13
|
+
|
|
14
|
+
function _extends() {
|
|
15
|
+
_extends = Object.assign || function (target) {
|
|
16
|
+
for (var i = 1; i < arguments.length; i++) {
|
|
17
|
+
var source = arguments[i];
|
|
18
|
+
|
|
19
|
+
for (var key in source) {
|
|
20
|
+
if (Object.prototype.hasOwnProperty.call(source, key)) {
|
|
21
|
+
target[key] = source[key];
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
return target;
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
return _extends.apply(this, arguments);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function _objectWithoutPropertiesLoose(source, excluded) {
|
|
33
|
+
if (source == null) return {};
|
|
34
|
+
var target = {};
|
|
35
|
+
var sourceKeys = Object.keys(source);
|
|
36
|
+
var key, i;
|
|
37
|
+
|
|
38
|
+
for (i = 0; i < sourceKeys.length; i++) {
|
|
39
|
+
key = sourceKeys[i];
|
|
40
|
+
if (excluded.indexOf(key) >= 0) continue;
|
|
41
|
+
target[key] = source[key];
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
return target;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const _excluded$7 = ["to", "children"];
|
|
48
|
+
const DefaultLink = React.forwardRef(function DefaultLink(_ref, ref) {
|
|
49
|
+
let {
|
|
50
|
+
to,
|
|
51
|
+
children
|
|
52
|
+
} = _ref,
|
|
53
|
+
rest = _objectWithoutPropertiesLoose(_ref, _excluded$7);
|
|
54
|
+
|
|
55
|
+
return /*#__PURE__*/React.createElement("a", _extends({
|
|
56
|
+
href: to,
|
|
57
|
+
ref: ref
|
|
58
|
+
}, rest), children);
|
|
59
|
+
});
|
|
60
|
+
const DefaultValue = {
|
|
61
|
+
Link: DefaultLink
|
|
62
|
+
};
|
|
63
|
+
const ComponentAbstractionContext = React.createContext(DefaultValue);
|
|
64
|
+
function ComponentAbstraction({
|
|
65
|
+
children,
|
|
66
|
+
components
|
|
67
|
+
}) {
|
|
68
|
+
return /*#__PURE__*/React.createElement(ComponentAbstractionContext.Provider, {
|
|
69
|
+
value: _extends({}, DefaultValue, components)
|
|
70
|
+
}, children);
|
|
71
|
+
}
|
|
72
|
+
function useComponentAbstraction() {
|
|
73
|
+
return useContext(ComponentAbstractionContext);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* 今後ポートされる予定の汎用的な関数群
|
|
78
|
+
*/
|
|
79
|
+
function unreachable(value) {
|
|
80
|
+
throw new Error(arguments.length === 0 ? 'unreachable' : `unreachable (${JSON.stringify(value)})`);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
const theme$2 = createTheme(styled);
|
|
84
|
+
|
|
85
|
+
let _$8 = t => t,
|
|
86
|
+
_t$8,
|
|
87
|
+
_t2$6,
|
|
88
|
+
_t3$6;
|
|
89
|
+
|
|
90
|
+
const _excluded$6 = ["onClick", "disabled"];
|
|
91
|
+
const Clickable = React.forwardRef(function Clickable(props, ref) {
|
|
92
|
+
const {
|
|
93
|
+
Link
|
|
94
|
+
} = useComponentAbstraction();
|
|
95
|
+
|
|
96
|
+
if ('to' in props) {
|
|
97
|
+
const {
|
|
98
|
+
onClick,
|
|
99
|
+
disabled = false
|
|
100
|
+
} = props,
|
|
101
|
+
rest = _objectWithoutPropertiesLoose(props, _excluded$6);
|
|
102
|
+
|
|
103
|
+
return /*#__PURE__*/React.createElement(A, _extends({}, rest, {
|
|
104
|
+
as: disabled ? undefined : Link,
|
|
105
|
+
onClick: disabled ? undefined : onClick,
|
|
106
|
+
"aria-disabled": disabled,
|
|
107
|
+
ref: ref
|
|
108
|
+
}));
|
|
109
|
+
} else {
|
|
110
|
+
return /*#__PURE__*/React.createElement(Button$1, _extends({}, props, {
|
|
111
|
+
ref: ref
|
|
112
|
+
}));
|
|
113
|
+
}
|
|
114
|
+
});
|
|
115
|
+
const clickableCss = css(_t$8 || (_t$8 = _$8`
|
|
2
116
|
/* Clickable style */
|
|
3
117
|
cursor: pointer;
|
|
4
118
|
|
|
5
119
|
${0} {
|
|
6
120
|
cursor: default;
|
|
7
121
|
}
|
|
8
|
-
`),
|
|
122
|
+
`), disabledSelector);
|
|
123
|
+
const Button$1 = styled.button(_t2$6 || (_t2$6 = _$8`
|
|
9
124
|
/* Reset button appearance */
|
|
10
125
|
appearance: none;
|
|
11
126
|
background: transparent;
|
|
@@ -40,7 +155,8 @@ import e,{useContext as t,useCallback as r,createContext as n,useMemo as a,useRe
|
|
|
40
155
|
}
|
|
41
156
|
|
|
42
157
|
${0}
|
|
43
|
-
`),
|
|
158
|
+
`), clickableCss);
|
|
159
|
+
const A = styled.span(_t3$6 || (_t3$6 = _$8`
|
|
44
160
|
/* Reset a-tag appearance */
|
|
45
161
|
color: inherit;
|
|
46
162
|
|
|
@@ -53,7 +169,37 @@ import e,{useContext as t,useCallback as r,createContext as n,useMemo as a,useRe
|
|
|
53
169
|
}
|
|
54
170
|
|
|
55
171
|
${0}
|
|
56
|
-
`),
|
|
172
|
+
`), clickableCss);
|
|
173
|
+
|
|
174
|
+
let _$7 = t => t,
|
|
175
|
+
_t$7;
|
|
176
|
+
|
|
177
|
+
const _excluded$5 = ["children", "variant", "size", "fixed", "disabled"];
|
|
178
|
+
const Button = React.forwardRef(function Button(_ref, ref) {
|
|
179
|
+
let {
|
|
180
|
+
children,
|
|
181
|
+
variant = 'Default',
|
|
182
|
+
size = 'M',
|
|
183
|
+
fixed = false,
|
|
184
|
+
disabled = false
|
|
185
|
+
} = _ref,
|
|
186
|
+
rest = _objectWithoutPropertiesLoose(_ref, _excluded$5);
|
|
187
|
+
|
|
188
|
+
return /*#__PURE__*/React.createElement(StyledButton, _extends({}, rest, {
|
|
189
|
+
disabled: disabled,
|
|
190
|
+
variant: variant,
|
|
191
|
+
size: size,
|
|
192
|
+
fixed: fixed,
|
|
193
|
+
ref: ref
|
|
194
|
+
}), children);
|
|
195
|
+
});
|
|
196
|
+
const StyledButton = styled(Clickable).withConfig({
|
|
197
|
+
shouldForwardProp(prop) {
|
|
198
|
+
// fixed は <button> 要素に渡ってはいけない
|
|
199
|
+
return prop !== 'fixed';
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
}).attrs(styledProps$1)(_t$7 || (_t$7 = _$7`
|
|
57
203
|
width: ${0};
|
|
58
204
|
display: inline-grid;
|
|
59
205
|
align-items: center;
|
|
@@ -66,7 +212,87 @@ import e,{useContext as t,useCallback as r,createContext as n,useMemo as a,useRe
|
|
|
66
212
|
|
|
67
213
|
/* よく考えたらheight=32って定義が存在しないな... */
|
|
68
214
|
height: ${0}px;
|
|
69
|
-
`),
|
|
215
|
+
`), p => p.fixed ? 'stretch' : 'min-content', p => theme$2(o => [o.font[p.font].hover.press, o.bg[p.background].hover.press, o.typography(14).bold.preserveHalfLeading, o.padding.horizontal(p.padding), o.disabled, o.borderRadius('oval'), o.outline.default.focus]), p => p.height);
|
|
216
|
+
|
|
217
|
+
function styledProps$1(props) {
|
|
218
|
+
return _extends({}, props, variantToProps$1(props.variant), sizeToProps$1(props.size));
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
function variantToProps$1(variant) {
|
|
222
|
+
switch (variant) {
|
|
223
|
+
case 'Overlay':
|
|
224
|
+
return {
|
|
225
|
+
font: 'text5',
|
|
226
|
+
background: 'surface4'
|
|
227
|
+
};
|
|
228
|
+
|
|
229
|
+
case 'Default':
|
|
230
|
+
return {
|
|
231
|
+
font: 'text2',
|
|
232
|
+
background: 'surface3'
|
|
233
|
+
};
|
|
234
|
+
|
|
235
|
+
case 'Primary':
|
|
236
|
+
return {
|
|
237
|
+
font: 'text5',
|
|
238
|
+
background: 'brand'
|
|
239
|
+
};
|
|
240
|
+
|
|
241
|
+
case 'Navigation':
|
|
242
|
+
return {
|
|
243
|
+
font: 'text5',
|
|
244
|
+
background: 'surface6'
|
|
245
|
+
};
|
|
246
|
+
|
|
247
|
+
case 'Danger':
|
|
248
|
+
return {
|
|
249
|
+
font: 'text5',
|
|
250
|
+
background: 'assertive'
|
|
251
|
+
};
|
|
252
|
+
|
|
253
|
+
default:
|
|
254
|
+
return unreachable(variant);
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
function sizeToProps$1(size) {
|
|
259
|
+
switch (size) {
|
|
260
|
+
case 'S':
|
|
261
|
+
return {
|
|
262
|
+
height: 32,
|
|
263
|
+
padding: 16
|
|
264
|
+
};
|
|
265
|
+
|
|
266
|
+
case 'M':
|
|
267
|
+
return {
|
|
268
|
+
height: 40,
|
|
269
|
+
padding: 24
|
|
270
|
+
};
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
let _$6 = t => t,
|
|
275
|
+
_t$6;
|
|
276
|
+
|
|
277
|
+
const _excluded$4 = ["variant", "size", "icon"];
|
|
278
|
+
const IconButton = React.forwardRef(function IconButtonInner(_ref, ref) {
|
|
279
|
+
let {
|
|
280
|
+
variant = 'Default',
|
|
281
|
+
size = 'M',
|
|
282
|
+
icon
|
|
283
|
+
} = _ref,
|
|
284
|
+
rest = _objectWithoutPropertiesLoose(_ref, _excluded$4);
|
|
285
|
+
|
|
286
|
+
validateIconSize(size, icon);
|
|
287
|
+
return /*#__PURE__*/React.createElement(StyledIconButton, _extends({}, rest, {
|
|
288
|
+
ref: ref,
|
|
289
|
+
variant: variant,
|
|
290
|
+
size: size
|
|
291
|
+
}), /*#__PURE__*/React.createElement("pixiv-icon", {
|
|
292
|
+
name: icon
|
|
293
|
+
}));
|
|
294
|
+
});
|
|
295
|
+
const StyledIconButton = styled(Clickable).attrs(styledProps)(_t$6 || (_t$6 = _$6`
|
|
70
296
|
user-select: none;
|
|
71
297
|
|
|
72
298
|
width: ${0}px;
|
|
@@ -76,7 +302,125 @@ import e,{useContext as t,useCallback as r,createContext as n,useMemo as a,useRe
|
|
|
76
302
|
justify-content: center;
|
|
77
303
|
|
|
78
304
|
${0}
|
|
79
|
-
`),
|
|
305
|
+
`), p => p.width, p => p.height, ({
|
|
306
|
+
font,
|
|
307
|
+
background
|
|
308
|
+
}) => theme$2(o => [o.font[font], o.bg[background].hover.press, o.disabled, o.borderRadius('oval'), o.outline.default.focus]));
|
|
309
|
+
|
|
310
|
+
function styledProps(props) {
|
|
311
|
+
return _extends({}, props, variantToProps(props.variant), sizeToProps(props.size));
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
function variantToProps(variant) {
|
|
315
|
+
switch (variant) {
|
|
316
|
+
case 'Default':
|
|
317
|
+
return {
|
|
318
|
+
font: 'text3',
|
|
319
|
+
background: 'transparent'
|
|
320
|
+
};
|
|
321
|
+
|
|
322
|
+
case 'Overlay':
|
|
323
|
+
return {
|
|
324
|
+
font: 'text5',
|
|
325
|
+
background: 'surface4'
|
|
326
|
+
};
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
function sizeToProps(size) {
|
|
331
|
+
switch (size) {
|
|
332
|
+
case 'XS':
|
|
333
|
+
return {
|
|
334
|
+
width: 20,
|
|
335
|
+
height: 20
|
|
336
|
+
};
|
|
337
|
+
|
|
338
|
+
case 'S':
|
|
339
|
+
return {
|
|
340
|
+
width: 32,
|
|
341
|
+
height: 32
|
|
342
|
+
};
|
|
343
|
+
|
|
344
|
+
case 'M':
|
|
345
|
+
return {
|
|
346
|
+
width: 40,
|
|
347
|
+
height: 40
|
|
348
|
+
};
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
/**
|
|
352
|
+
* validates matches of size and icon
|
|
353
|
+
*/
|
|
354
|
+
|
|
355
|
+
|
|
356
|
+
function validateIconSize(size, icon) {
|
|
357
|
+
let requiredIconSize;
|
|
358
|
+
|
|
359
|
+
switch (size) {
|
|
360
|
+
case 'XS':
|
|
361
|
+
requiredIconSize = '16';
|
|
362
|
+
break;
|
|
363
|
+
|
|
364
|
+
case 'S':
|
|
365
|
+
case 'M':
|
|
366
|
+
requiredIconSize = '24';
|
|
367
|
+
break;
|
|
368
|
+
} // アイコン名は サイズ/名前
|
|
369
|
+
|
|
370
|
+
|
|
371
|
+
const result = /^[0-9]*/.exec(icon);
|
|
372
|
+
|
|
373
|
+
if (result == null) {
|
|
374
|
+
throw new Error('Invalid icon name');
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
const [iconSize] = result;
|
|
378
|
+
|
|
379
|
+
if (iconSize !== requiredIconSize) {
|
|
380
|
+
// eslint-disable-next-line no-console
|
|
381
|
+
console.warn(`IconButton with size "${size}" expect icon size "${requiredIconSize}, but got "${iconSize}"`);
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
let _$5 = t => t,
|
|
386
|
+
_t$5,
|
|
387
|
+
_t2$5,
|
|
388
|
+
_t3$5,
|
|
389
|
+
_t4$3;
|
|
390
|
+
function Radio({
|
|
391
|
+
value,
|
|
392
|
+
forceChecked = false,
|
|
393
|
+
disabled = false,
|
|
394
|
+
children
|
|
395
|
+
}) {
|
|
396
|
+
const {
|
|
397
|
+
name,
|
|
398
|
+
selected,
|
|
399
|
+
disabled: isParentDisabled,
|
|
400
|
+
readonly,
|
|
401
|
+
hasError,
|
|
402
|
+
onChange
|
|
403
|
+
} = useContext(RadioGroupContext);
|
|
404
|
+
warning( // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
405
|
+
name !== undefined, `"name" is not Provided for <Radio>. Perhaps you forgot to wrap with <RadioGroup> ?`);
|
|
406
|
+
const isSelected = value === selected;
|
|
407
|
+
const isDisabled = disabled || isParentDisabled;
|
|
408
|
+
const isReadonly = readonly && !isSelected;
|
|
409
|
+
const handleChange = useCallback(e => {
|
|
410
|
+
onChange(e.currentTarget.value);
|
|
411
|
+
}, [onChange]);
|
|
412
|
+
return /*#__PURE__*/React.createElement(RadioRoot, {
|
|
413
|
+
"aria-disabled": isDisabled || isReadonly
|
|
414
|
+
}, /*#__PURE__*/React.createElement(RadioInput, {
|
|
415
|
+
name: name,
|
|
416
|
+
value: value,
|
|
417
|
+
checked: forceChecked || isSelected,
|
|
418
|
+
hasError: hasError,
|
|
419
|
+
onChange: handleChange,
|
|
420
|
+
disabled: isDisabled || isReadonly
|
|
421
|
+
}), children != null && /*#__PURE__*/React.createElement(RadioLabel, null, children));
|
|
422
|
+
}
|
|
423
|
+
const RadioRoot = styled.label(_t$5 || (_t$5 = _$5`
|
|
80
424
|
display: grid;
|
|
81
425
|
grid-template-columns: auto 1fr;
|
|
82
426
|
grid-gap: ${0};
|
|
@@ -84,7 +428,12 @@ import e,{useContext as t,useCallback as r,createContext as n,useMemo as a,useRe
|
|
|
84
428
|
cursor: pointer;
|
|
85
429
|
|
|
86
430
|
${0}
|
|
87
|
-
`),({
|
|
431
|
+
`), ({
|
|
432
|
+
theme
|
|
433
|
+
}) => px(theme.spacing[4]), theme$2(o => [o.disabled]));
|
|
434
|
+
const RadioInput = styled.input.attrs({
|
|
435
|
+
type: 'radio'
|
|
436
|
+
})(_t2$5 || (_t2$5 = _$5`
|
|
88
437
|
/** Make prior to browser default style */
|
|
89
438
|
&[type='radio'] {
|
|
90
439
|
appearance: none;
|
|
@@ -120,13 +469,140 @@ import e,{useContext as t,useCallback as r,createContext as n,useMemo as a,useRe
|
|
|
120
469
|
|
|
121
470
|
${0}
|
|
122
471
|
}
|
|
123
|
-
`),({
|
|
472
|
+
`), ({
|
|
473
|
+
hasError: _hasError = false
|
|
474
|
+
}) => theme$2(o => [o.borderRadius('oval'), o.bg.text5.hover.press, _hasError && o.outline.assertive]), ({
|
|
475
|
+
theme
|
|
476
|
+
}) => theme.color.text4, theme$2(o => o.bg.brand.hover.press), theme$2(o => [o.bg.text5.hover.press, o.borderRadius('oval')]), theme$2(o => o.outline.default.focus));
|
|
477
|
+
const RadioLabel = styled.div(_t3$5 || (_t3$5 = _$5`
|
|
124
478
|
${0}
|
|
125
|
-
`),
|
|
479
|
+
`), theme$2(o => [o.typography(14)])); // TODO: use (or polyfill) flex gap
|
|
480
|
+
|
|
481
|
+
const StyledRadioGroup = styled.div(_t4$3 || (_t4$3 = _$5`
|
|
126
482
|
display: grid;
|
|
127
483
|
grid-template-columns: 1fr;
|
|
128
484
|
grid-gap: ${0};
|
|
129
|
-
`),
|
|
485
|
+
`), ({
|
|
486
|
+
theme
|
|
487
|
+
}) => px(theme.spacing[8]));
|
|
488
|
+
const RadioGroupContext = React.createContext({
|
|
489
|
+
name: undefined,
|
|
490
|
+
selected: undefined,
|
|
491
|
+
disabled: false,
|
|
492
|
+
readonly: false,
|
|
493
|
+
hasError: false,
|
|
494
|
+
|
|
495
|
+
onChange() {
|
|
496
|
+
throw new Error('Cannot find onChange() handler. Perhaps you forgot to wrap with <RadioGroup> ?');
|
|
497
|
+
}
|
|
498
|
+
|
|
499
|
+
});
|
|
500
|
+
function RadioGroup({
|
|
501
|
+
className,
|
|
502
|
+
value,
|
|
503
|
+
label,
|
|
504
|
+
name,
|
|
505
|
+
onChange,
|
|
506
|
+
disabled,
|
|
507
|
+
readonly,
|
|
508
|
+
hasError,
|
|
509
|
+
children
|
|
510
|
+
}) {
|
|
511
|
+
const handleChange = useCallback(next => {
|
|
512
|
+
onChange(next);
|
|
513
|
+
}, [onChange]);
|
|
514
|
+
return /*#__PURE__*/React.createElement(RadioGroupContext.Provider, {
|
|
515
|
+
value: {
|
|
516
|
+
name,
|
|
517
|
+
selected: value,
|
|
518
|
+
disabled: disabled != null ? disabled : false,
|
|
519
|
+
readonly: readonly != null ? readonly : false,
|
|
520
|
+
hasError: hasError != null ? hasError : false,
|
|
521
|
+
onChange: handleChange
|
|
522
|
+
}
|
|
523
|
+
}, /*#__PURE__*/React.createElement(StyledRadioGroup, {
|
|
524
|
+
role: "radiogroup",
|
|
525
|
+
"aria-orientation": "vertical",
|
|
526
|
+
"aria-label": label,
|
|
527
|
+
"aria-invalid": hasError,
|
|
528
|
+
className: className
|
|
529
|
+
}, children));
|
|
530
|
+
}
|
|
531
|
+
|
|
532
|
+
const SelectGroupContext = createContext({
|
|
533
|
+
name: undefined,
|
|
534
|
+
selected: [],
|
|
535
|
+
disabled: false,
|
|
536
|
+
readonly: false,
|
|
537
|
+
hasError: false,
|
|
538
|
+
|
|
539
|
+
onChange() {
|
|
540
|
+
throw new Error('Cannot find `onChange()` handler. Perhaps you forgot to wrap it with `<SelectGroup />` ?');
|
|
541
|
+
}
|
|
542
|
+
|
|
543
|
+
});
|
|
544
|
+
|
|
545
|
+
let _$4 = t => t,
|
|
546
|
+
_t$4,
|
|
547
|
+
_t2$4,
|
|
548
|
+
_t3$4,
|
|
549
|
+
_t4$2,
|
|
550
|
+
_t5$1;
|
|
551
|
+
function Select({
|
|
552
|
+
value,
|
|
553
|
+
forceChecked = false,
|
|
554
|
+
disabled = false,
|
|
555
|
+
onChange,
|
|
556
|
+
variant = 'default',
|
|
557
|
+
children
|
|
558
|
+
}) {
|
|
559
|
+
const {
|
|
560
|
+
name,
|
|
561
|
+
selected,
|
|
562
|
+
disabled: parentDisabled,
|
|
563
|
+
readonly,
|
|
564
|
+
hasError,
|
|
565
|
+
onChange: parentOnChange
|
|
566
|
+
} = useContext(SelectGroupContext);
|
|
567
|
+
warning( // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
568
|
+
name !== undefined, `"name" is not Provided for <Select>. Perhaps you forgot to wrap with <SelectGroup> ?`);
|
|
569
|
+
const isSelected = selected.includes(value) || forceChecked;
|
|
570
|
+
const isDisabled = disabled || parentDisabled || readonly;
|
|
571
|
+
const handleChange = useCallback(event => {
|
|
572
|
+
if (!(event.currentTarget instanceof HTMLInputElement)) {
|
|
573
|
+
return;
|
|
574
|
+
}
|
|
575
|
+
|
|
576
|
+
if (onChange) onChange({
|
|
577
|
+
value,
|
|
578
|
+
selected: event.currentTarget.checked
|
|
579
|
+
});
|
|
580
|
+
parentOnChange({
|
|
581
|
+
value,
|
|
582
|
+
selected: event.currentTarget.checked
|
|
583
|
+
});
|
|
584
|
+
}, [onChange, parentOnChange, value]);
|
|
585
|
+
return /*#__PURE__*/React.createElement(SelectRoot, {
|
|
586
|
+
"aria-disabled": isDisabled
|
|
587
|
+
}, /*#__PURE__*/React.createElement(SelectInput, {
|
|
588
|
+
name,
|
|
589
|
+
value,
|
|
590
|
+
hasError,
|
|
591
|
+
checked: isSelected,
|
|
592
|
+
disabled: isDisabled,
|
|
593
|
+
onChange: handleChange,
|
|
594
|
+
overlay: variant === 'overlay',
|
|
595
|
+
"aria-invalid": hasError
|
|
596
|
+
}), /*#__PURE__*/React.createElement(SelectInputOverlay, {
|
|
597
|
+
overlay: variant === 'overlay',
|
|
598
|
+
hasError: hasError,
|
|
599
|
+
"aria-hidden": true
|
|
600
|
+
}, /*#__PURE__*/React.createElement("pixiv-icon", {
|
|
601
|
+
name: "24/Check",
|
|
602
|
+
"unsafe-non-guideline-scale": 16 / 24
|
|
603
|
+
})), Boolean(children) && /*#__PURE__*/React.createElement(SelectLabel, null, children));
|
|
604
|
+
}
|
|
605
|
+
const SelectRoot = styled.label(_t$4 || (_t$4 = _$4`
|
|
130
606
|
display: grid;
|
|
131
607
|
grid-template-columns: auto 1fr;
|
|
132
608
|
align-items: center;
|
|
@@ -137,11 +613,17 @@ import e,{useContext as t,useCallback as r,createContext as n,useMemo as a,useRe
|
|
|
137
613
|
}
|
|
138
614
|
gap: ${0};
|
|
139
615
|
${0}
|
|
140
|
-
`),
|
|
616
|
+
`), disabledSelector, ({
|
|
617
|
+
theme
|
|
618
|
+
}) => px(theme.spacing[4]), theme$2(o => o.disabled));
|
|
619
|
+
const SelectLabel = styled.div(_t2$4 || (_t2$4 = _$4`
|
|
141
620
|
display: flex;
|
|
142
621
|
align-items: center;
|
|
143
622
|
${0}
|
|
144
|
-
`),
|
|
623
|
+
`), theme$2(o => [o.typography(14), o.font.text1]));
|
|
624
|
+
const SelectInput = styled.input.attrs({
|
|
625
|
+
type: 'checkbox'
|
|
626
|
+
})(_t3$4 || (_t3$4 = _$4`
|
|
145
627
|
&[type='checkbox'] {
|
|
146
628
|
appearance: none;
|
|
147
629
|
display: block;
|
|
@@ -155,7 +637,11 @@ import e,{useContext as t,useCallback as r,createContext as n,useMemo as a,useRe
|
|
|
155
637
|
|
|
156
638
|
${0};
|
|
157
639
|
}
|
|
158
|
-
`),
|
|
640
|
+
`), theme$2(o => o.bg.brand.hover.press), ({
|
|
641
|
+
hasError,
|
|
642
|
+
overlay
|
|
643
|
+
}) => theme$2(o => [o.bg.text3.hover.press, o.borderRadius('oval'), hasError && !overlay && o.outline.assertive, overlay && o.bg.surface4]));
|
|
644
|
+
const SelectInputOverlay = styled.div(_t4$2 || (_t4$2 = _$4`
|
|
159
645
|
position: absolute;
|
|
160
646
|
top: -2px;
|
|
161
647
|
left: -2px;
|
|
@@ -167,11 +653,92 @@ import e,{useContext as t,useCallback as r,createContext as n,useMemo as a,useRe
|
|
|
167
653
|
${0}
|
|
168
654
|
|
|
169
655
|
${0}
|
|
170
|
-
`),({
|
|
656
|
+
`), ({
|
|
657
|
+
hasError,
|
|
658
|
+
overlay
|
|
659
|
+
}) => theme$2(o => [o.width.px(24), o.height.px(24), o.borderRadius('oval'), o.font.text5, hasError && overlay && o.outline.assertive]), ({
|
|
660
|
+
overlay
|
|
661
|
+
}) => overlay && css(_t5$1 || (_t5$1 = _$4`
|
|
171
662
|
border-color: ${0};
|
|
172
663
|
border-width: 2px;
|
|
173
664
|
border-style: solid;
|
|
174
|
-
`),
|
|
665
|
+
`), ({
|
|
666
|
+
theme
|
|
667
|
+
}) => theme.color.text5));
|
|
668
|
+
function SelectGroup({
|
|
669
|
+
className,
|
|
670
|
+
name,
|
|
671
|
+
ariaLabel,
|
|
672
|
+
selected,
|
|
673
|
+
onChange,
|
|
674
|
+
disabled = false,
|
|
675
|
+
readonly = false,
|
|
676
|
+
hasError = false,
|
|
677
|
+
children
|
|
678
|
+
}) {
|
|
679
|
+
const handleChange = useCallback(payload => {
|
|
680
|
+
const index = selected.indexOf(payload.value);
|
|
681
|
+
|
|
682
|
+
if (payload.selected) {
|
|
683
|
+
if (index < 0) {
|
|
684
|
+
onChange([...selected, payload.value]);
|
|
685
|
+
}
|
|
686
|
+
} else {
|
|
687
|
+
if (index >= 0) {
|
|
688
|
+
onChange([...selected.slice(0, index), ...selected.slice(index + 1)]);
|
|
689
|
+
}
|
|
690
|
+
}
|
|
691
|
+
}, [onChange, selected]);
|
|
692
|
+
return /*#__PURE__*/React.createElement(SelectGroupContext.Provider, {
|
|
693
|
+
value: {
|
|
694
|
+
name,
|
|
695
|
+
selected: Array.from(new Set(selected)),
|
|
696
|
+
disabled,
|
|
697
|
+
readonly,
|
|
698
|
+
hasError,
|
|
699
|
+
onChange: handleChange
|
|
700
|
+
}
|
|
701
|
+
}, /*#__PURE__*/React.createElement("div", {
|
|
702
|
+
className: className,
|
|
703
|
+
"aria-label": ariaLabel,
|
|
704
|
+
"data-testid": "SelectGroup"
|
|
705
|
+
}, children));
|
|
706
|
+
}
|
|
707
|
+
|
|
708
|
+
let _$3 = t => t,
|
|
709
|
+
_t$3,
|
|
710
|
+
_t2$3,
|
|
711
|
+
_t3$3;
|
|
712
|
+
|
|
713
|
+
const _excluded$3 = ["className", "type"];
|
|
714
|
+
function SwitchCheckbox(props) {
|
|
715
|
+
const {
|
|
716
|
+
disabled,
|
|
717
|
+
className
|
|
718
|
+
} = props;
|
|
719
|
+
const ariaSwitchProps = useMemo(() => _extends({}, props, {
|
|
720
|
+
// children がいない場合は aria-label をつけないといけない
|
|
721
|
+
'aria-label': 'children' in props ? undefined : props.label,
|
|
722
|
+
isDisabled: props.disabled,
|
|
723
|
+
isSelected: props.checked
|
|
724
|
+
}), [props]);
|
|
725
|
+
const state = useToggleState(ariaSwitchProps);
|
|
726
|
+
const ref = useRef(null);
|
|
727
|
+
|
|
728
|
+
const _useSwitch = useSwitch(ariaSwitchProps, state, ref),
|
|
729
|
+
rest = _objectWithoutPropertiesLoose(_useSwitch.inputProps, _excluded$3);
|
|
730
|
+
|
|
731
|
+
return /*#__PURE__*/React.createElement(Label$1, {
|
|
732
|
+
className: className,
|
|
733
|
+
"aria-disabled": disabled
|
|
734
|
+
}, /*#__PURE__*/React.createElement(SwitchInput, _extends({}, rest, {
|
|
735
|
+
ref: ref
|
|
736
|
+
})), 'children' in props ?
|
|
737
|
+
/*#__PURE__*/
|
|
738
|
+
// eslint-disable-next-line react/destructuring-assignment
|
|
739
|
+
React.createElement(LabelInner, null, props.children) : undefined);
|
|
740
|
+
}
|
|
741
|
+
const Label$1 = styled.label(_t$3 || (_t$3 = _$3`
|
|
175
742
|
display: inline-grid;
|
|
176
743
|
grid-template-columns: auto 1fr;
|
|
177
744
|
gap: ${0};
|
|
@@ -183,9 +750,15 @@ import e,{useContext as t,useCallback as r,createContext as n,useMemo as a,useRe
|
|
|
183
750
|
${0} {
|
|
184
751
|
cursor: default;
|
|
185
752
|
}
|
|
186
|
-
`),({
|
|
753
|
+
`), ({
|
|
754
|
+
theme
|
|
755
|
+
}) => px(theme.spacing[4]), theme$2(o => o.disabled), disabledSelector);
|
|
756
|
+
const LabelInner = styled.div(_t2$3 || (_t2$3 = _$3`
|
|
187
757
|
${0}
|
|
188
|
-
`),
|
|
758
|
+
`), theme$2(o => o.typography(14)));
|
|
759
|
+
const SwitchInput = styled.input.attrs({
|
|
760
|
+
type: 'checkbox'
|
|
761
|
+
})(_t3$3 || (_t3$3 = _$3`
|
|
189
762
|
&[type='checkbox'] {
|
|
190
763
|
appearance: none;
|
|
191
764
|
display: inline-flex;
|
|
@@ -218,13 +791,44 @@ import e,{useContext as t,useCallback as r,createContext as n,useMemo as a,useRe
|
|
|
218
791
|
}
|
|
219
792
|
}
|
|
220
793
|
}
|
|
221
|
-
`),
|
|
794
|
+
`), theme$2(o => [o.borderRadius(16), o.height.px(16), o.bg.text4.hover.press, o.outline.default.focus]), theme$2(o => [o.bg.text5.hover.press, o.borderRadius('oval')]), theme$2(o => o.bg.brand.hover.press));
|
|
795
|
+
|
|
796
|
+
let _$2 = t => t,
|
|
797
|
+
_t$2,
|
|
798
|
+
_t2$2,
|
|
799
|
+
_t3$2,
|
|
800
|
+
_t4$1;
|
|
801
|
+
|
|
802
|
+
const _excluded$2 = ["style", "className", "label", "required", "requiredText", "subLabel"];
|
|
803
|
+
const FieldLabel = React.forwardRef(function FieldLabel(_ref, ref) {
|
|
804
|
+
let {
|
|
805
|
+
style,
|
|
806
|
+
className,
|
|
807
|
+
label,
|
|
808
|
+
required = false,
|
|
809
|
+
requiredText,
|
|
810
|
+
subLabel
|
|
811
|
+
} = _ref,
|
|
812
|
+
labelProps = _objectWithoutPropertiesLoose(_ref, _excluded$2);
|
|
813
|
+
|
|
814
|
+
return /*#__PURE__*/React.createElement(FieldLabelWrapper, {
|
|
815
|
+
style: style,
|
|
816
|
+
className: className
|
|
817
|
+
}, /*#__PURE__*/React.createElement(Label, _extends({
|
|
818
|
+
ref: ref
|
|
819
|
+
}, labelProps), label), required && /*#__PURE__*/React.createElement(RequiredText, null, requiredText), /*#__PURE__*/React.createElement(SubLabelClickable, null, /*#__PURE__*/React.createElement("span", null, subLabel)));
|
|
820
|
+
});
|
|
821
|
+
const theme$1 = createTheme(styled);
|
|
822
|
+
const Label = styled.label(_t$2 || (_t$2 = _$2`
|
|
222
823
|
${0}
|
|
223
|
-
`),
|
|
824
|
+
`), theme$1(o => [o.typography(14).bold, o.font.text1]));
|
|
825
|
+
const RequiredText = styled.span(_t2$2 || (_t2$2 = _$2`
|
|
224
826
|
${0}
|
|
225
|
-
`),
|
|
827
|
+
`), theme$1(o => [o.typography(14), o.font.text3]));
|
|
828
|
+
const SubLabelClickable = styled.div(_t3$2 || (_t3$2 = _$2`
|
|
226
829
|
${0}
|
|
227
|
-
`),
|
|
830
|
+
`), theme$1(o => [o.typography(14), o.font.text3.hover.press, o.outline.default.focus]));
|
|
831
|
+
const FieldLabelWrapper = styled.div(_t4$1 || (_t4$1 = _$2`
|
|
228
832
|
display: inline-flex;
|
|
229
833
|
align-items: center;
|
|
230
834
|
|
|
@@ -235,23 +839,280 @@ import e,{useContext as t,useCallback as r,createContext as n,useMemo as a,useRe
|
|
|
235
839
|
> ${0} {
|
|
236
840
|
${0}
|
|
237
841
|
}
|
|
238
|
-
`),
|
|
842
|
+
`), RequiredText, theme$1(o => o.margin.left(4)), SubLabelClickable, theme$1(o => o.margin.left('auto')));
|
|
843
|
+
|
|
844
|
+
let _$1 = t => t,
|
|
845
|
+
_t$1,
|
|
846
|
+
_t2$1,
|
|
847
|
+
_t3$1,
|
|
848
|
+
_t4,
|
|
849
|
+
_t5,
|
|
850
|
+
_t6,
|
|
851
|
+
_t7,
|
|
852
|
+
_t8,
|
|
853
|
+
_t9,
|
|
854
|
+
_t10,
|
|
855
|
+
_t11,
|
|
856
|
+
_t12,
|
|
857
|
+
_t13,
|
|
858
|
+
_t14;
|
|
859
|
+
|
|
860
|
+
const _excluded$1 = ["onChange"],
|
|
861
|
+
_excluded2 = ["onChange"];
|
|
862
|
+
const theme = createTheme(styled);
|
|
863
|
+
|
|
864
|
+
function mergeRefs(...refs) {
|
|
865
|
+
return value => {
|
|
866
|
+
for (const ref of refs) {
|
|
867
|
+
if (typeof ref === 'function') {
|
|
868
|
+
ref(value);
|
|
869
|
+
} else if (ref !== null) {
|
|
870
|
+
ref.current = value;
|
|
871
|
+
}
|
|
872
|
+
}
|
|
873
|
+
};
|
|
874
|
+
}
|
|
875
|
+
|
|
876
|
+
function countCodePointsInString(string) {
|
|
877
|
+
// [...string] とするとproduction buildで動かなくなる
|
|
878
|
+
// cf. https://twitter.com/f_subal/status/1497214727511891972
|
|
879
|
+
return Array.from(string).length;
|
|
880
|
+
}
|
|
881
|
+
|
|
882
|
+
const TextField = React.forwardRef(function TextField(props, ref) {
|
|
883
|
+
return props.multiline !== undefined && props.multiline ? /*#__PURE__*/React.createElement(MultiLineTextField, _extends({
|
|
884
|
+
ref: ref
|
|
885
|
+
}, props)) : /*#__PURE__*/React.createElement(SingleLineTextField, _extends({
|
|
886
|
+
ref: ref
|
|
887
|
+
}, props));
|
|
888
|
+
});
|
|
889
|
+
const SingleLineTextField = React.forwardRef(function SingleLineTextFieldInner(_ref, forwardRef) {
|
|
890
|
+
var _props$value;
|
|
891
|
+
|
|
892
|
+
let {
|
|
893
|
+
onChange
|
|
894
|
+
} = _ref,
|
|
895
|
+
props = _objectWithoutPropertiesLoose(_ref, _excluded$1);
|
|
896
|
+
|
|
897
|
+
const {
|
|
898
|
+
className,
|
|
899
|
+
showLabel = false,
|
|
900
|
+
showCount = false,
|
|
901
|
+
label,
|
|
902
|
+
requiredText,
|
|
903
|
+
subLabel,
|
|
904
|
+
disabled = false,
|
|
905
|
+
required,
|
|
906
|
+
invalid = false,
|
|
907
|
+
assistiveText,
|
|
908
|
+
maxLength,
|
|
909
|
+
prefix = null,
|
|
910
|
+
suffix = null
|
|
911
|
+
} = props;
|
|
912
|
+
const {
|
|
913
|
+
visuallyHiddenProps
|
|
914
|
+
} = useVisuallyHidden();
|
|
915
|
+
const ariaRef = useRef(null);
|
|
916
|
+
const prefixRef = useRef(null);
|
|
917
|
+
const suffixRef = useRef(null);
|
|
918
|
+
const [count, setCount] = useState(countCodePointsInString((_props$value = props.value) != null ? _props$value : ''));
|
|
919
|
+
const [prefixWidth, setPrefixWidth] = useState(0);
|
|
920
|
+
const [suffixWidth, setSuffixWidth] = useState(0);
|
|
921
|
+
const nonControlled = props.value === undefined;
|
|
922
|
+
const handleChange = useCallback(value => {
|
|
923
|
+
const count = countCodePointsInString(value);
|
|
924
|
+
|
|
925
|
+
if (maxLength !== undefined && count > maxLength) {
|
|
926
|
+
return;
|
|
927
|
+
}
|
|
928
|
+
|
|
929
|
+
if (nonControlled) {
|
|
930
|
+
setCount(count);
|
|
931
|
+
}
|
|
932
|
+
|
|
933
|
+
onChange == null ? void 0 : onChange(value);
|
|
934
|
+
}, [maxLength, nonControlled, onChange]);
|
|
935
|
+
useEffect(() => {
|
|
936
|
+
var _props$value2;
|
|
937
|
+
|
|
938
|
+
setCount(countCodePointsInString((_props$value2 = props.value) != null ? _props$value2 : ''));
|
|
939
|
+
}, [props.value]);
|
|
940
|
+
const {
|
|
941
|
+
inputProps,
|
|
942
|
+
labelProps,
|
|
943
|
+
descriptionProps,
|
|
944
|
+
errorMessageProps
|
|
945
|
+
} = useTextField(_extends({
|
|
946
|
+
inputElementType: 'input',
|
|
947
|
+
isDisabled: disabled,
|
|
948
|
+
isRequired: required,
|
|
949
|
+
validationState: invalid ? 'invalid' : 'valid',
|
|
950
|
+
description: !invalid && assistiveText,
|
|
951
|
+
errorMessage: invalid && assistiveText,
|
|
952
|
+
onChange: handleChange
|
|
953
|
+
}, props), ariaRef);
|
|
954
|
+
useEffect(() => {
|
|
955
|
+
const prefixObserver = new ResizeObserver(entries => {
|
|
956
|
+
setPrefixWidth(entries[0].contentRect.width);
|
|
957
|
+
});
|
|
958
|
+
const suffixObserver = new ResizeObserver(entries => {
|
|
959
|
+
setSuffixWidth(entries[0].contentRect.width);
|
|
960
|
+
});
|
|
961
|
+
|
|
962
|
+
if (prefixRef.current !== null) {
|
|
963
|
+
prefixObserver.observe(prefixRef.current);
|
|
964
|
+
}
|
|
965
|
+
|
|
966
|
+
if (suffixRef.current !== null) {
|
|
967
|
+
suffixObserver.observe(suffixRef.current);
|
|
968
|
+
}
|
|
969
|
+
|
|
970
|
+
return () => {
|
|
971
|
+
suffixObserver.disconnect();
|
|
972
|
+
prefixObserver.disconnect();
|
|
973
|
+
};
|
|
974
|
+
}, []);
|
|
975
|
+
return /*#__PURE__*/React.createElement(TextFieldRoot, {
|
|
976
|
+
className: className,
|
|
977
|
+
isDisabled: disabled
|
|
978
|
+
}, /*#__PURE__*/React.createElement(TextFieldLabel, _extends({
|
|
979
|
+
label: label,
|
|
980
|
+
requiredText: requiredText,
|
|
981
|
+
required: required,
|
|
982
|
+
subLabel: subLabel
|
|
983
|
+
}, labelProps, !showLabel ? visuallyHiddenProps : {})), /*#__PURE__*/React.createElement(StyledInputContainer, null, /*#__PURE__*/React.createElement(PrefixContainer, {
|
|
984
|
+
ref: prefixRef
|
|
985
|
+
}, /*#__PURE__*/React.createElement(Affix, null, prefix)), /*#__PURE__*/React.createElement(StyledInput, _extends({
|
|
986
|
+
ref: mergeRefs(forwardRef, ariaRef),
|
|
987
|
+
invalid: invalid,
|
|
988
|
+
extraLeftPadding: prefixWidth,
|
|
989
|
+
extraRightPadding: suffixWidth
|
|
990
|
+
}, inputProps)), /*#__PURE__*/React.createElement(SuffixContainer, {
|
|
991
|
+
ref: suffixRef
|
|
992
|
+
}, /*#__PURE__*/React.createElement(Affix, null, suffix), showCount && /*#__PURE__*/React.createElement(SingleLineCounter, null, maxLength !== undefined ? `${count}/${maxLength}` : count))), assistiveText != null && assistiveText.length !== 0 && /*#__PURE__*/React.createElement(AssistiveText, _extends({
|
|
993
|
+
invalid: invalid
|
|
994
|
+
}, invalid ? errorMessageProps : descriptionProps), assistiveText));
|
|
995
|
+
});
|
|
996
|
+
const MultiLineTextField = React.forwardRef(function MultiLineTextFieldInner(_ref2, forwardRef) {
|
|
997
|
+
var _props$value3;
|
|
998
|
+
|
|
999
|
+
let {
|
|
1000
|
+
onChange
|
|
1001
|
+
} = _ref2,
|
|
1002
|
+
props = _objectWithoutPropertiesLoose(_ref2, _excluded2);
|
|
1003
|
+
|
|
1004
|
+
const {
|
|
1005
|
+
className,
|
|
1006
|
+
showCount = false,
|
|
1007
|
+
showLabel = false,
|
|
1008
|
+
label,
|
|
1009
|
+
requiredText,
|
|
1010
|
+
subLabel,
|
|
1011
|
+
disabled = false,
|
|
1012
|
+
required,
|
|
1013
|
+
invalid = false,
|
|
1014
|
+
assistiveText,
|
|
1015
|
+
maxLength,
|
|
1016
|
+
autoHeight = false,
|
|
1017
|
+
rows: initialRows = 4
|
|
1018
|
+
} = props;
|
|
1019
|
+
const {
|
|
1020
|
+
visuallyHiddenProps
|
|
1021
|
+
} = useVisuallyHidden();
|
|
1022
|
+
const textareaRef = useRef(null);
|
|
1023
|
+
const ariaRef = useRef(null);
|
|
1024
|
+
const [count, setCount] = useState(countCodePointsInString((_props$value3 = props.value) != null ? _props$value3 : ''));
|
|
1025
|
+
const [rows, setRows] = useState(initialRows);
|
|
1026
|
+
const syncHeight = useCallback(textarea => {
|
|
1027
|
+
var _$match$length, _$match;
|
|
1028
|
+
|
|
1029
|
+
const rows = ((_$match$length = (_$match = `${textarea.value}\n`.match(/\n/g)) == null ? void 0 : _$match.length) != null ? _$match$length : 0) || 1;
|
|
1030
|
+
setRows(initialRows <= rows ? rows : initialRows);
|
|
1031
|
+
}, [initialRows]);
|
|
1032
|
+
const nonControlled = props.value === undefined;
|
|
1033
|
+
const handleChange = useCallback(value => {
|
|
1034
|
+
const count = countCodePointsInString(value);
|
|
1035
|
+
|
|
1036
|
+
if (maxLength !== undefined && count > maxLength) {
|
|
1037
|
+
return;
|
|
1038
|
+
}
|
|
1039
|
+
|
|
1040
|
+
if (nonControlled) {
|
|
1041
|
+
setCount(count);
|
|
1042
|
+
}
|
|
1043
|
+
|
|
1044
|
+
if (autoHeight && textareaRef.current !== null) {
|
|
1045
|
+
syncHeight(textareaRef.current);
|
|
1046
|
+
}
|
|
1047
|
+
|
|
1048
|
+
onChange == null ? void 0 : onChange(value);
|
|
1049
|
+
}, [autoHeight, maxLength, nonControlled, onChange, syncHeight]);
|
|
1050
|
+
useEffect(() => {
|
|
1051
|
+
var _props$value4;
|
|
1052
|
+
|
|
1053
|
+
setCount(countCodePointsInString((_props$value4 = props.value) != null ? _props$value4 : ''));
|
|
1054
|
+
}, [props.value]);
|
|
1055
|
+
const {
|
|
1056
|
+
inputProps,
|
|
1057
|
+
labelProps,
|
|
1058
|
+
descriptionProps,
|
|
1059
|
+
errorMessageProps
|
|
1060
|
+
} = useTextField(_extends({
|
|
1061
|
+
inputElementType: 'textarea',
|
|
1062
|
+
isDisabled: disabled,
|
|
1063
|
+
isRequired: required,
|
|
1064
|
+
validationState: invalid ? 'invalid' : 'valid',
|
|
1065
|
+
description: !invalid && assistiveText,
|
|
1066
|
+
errorMessage: invalid && assistiveText,
|
|
1067
|
+
onChange: handleChange
|
|
1068
|
+
}, props), ariaRef);
|
|
1069
|
+
useEffect(() => {
|
|
1070
|
+
if (autoHeight && textareaRef.current !== null) {
|
|
1071
|
+
syncHeight(textareaRef.current);
|
|
1072
|
+
}
|
|
1073
|
+
}, [autoHeight, syncHeight]);
|
|
1074
|
+
return /*#__PURE__*/React.createElement(TextFieldRoot, {
|
|
1075
|
+
className: className,
|
|
1076
|
+
isDisabled: disabled
|
|
1077
|
+
}, /*#__PURE__*/React.createElement(TextFieldLabel, _extends({
|
|
1078
|
+
label: label,
|
|
1079
|
+
requiredText: requiredText,
|
|
1080
|
+
required: required,
|
|
1081
|
+
subLabel: subLabel
|
|
1082
|
+
}, labelProps, !showLabel ? visuallyHiddenProps : {})), /*#__PURE__*/React.createElement(StyledTextareaContainer, {
|
|
1083
|
+
invalid: invalid,
|
|
1084
|
+
rows: showCount ? rows + 1 : rows
|
|
1085
|
+
}, /*#__PURE__*/React.createElement(StyledTextarea, _extends({
|
|
1086
|
+
ref: mergeRefs(textareaRef, forwardRef, ariaRef),
|
|
1087
|
+
rows: rows,
|
|
1088
|
+
noBottomPadding: showCount
|
|
1089
|
+
}, inputProps)), showCount && /*#__PURE__*/React.createElement(MultiLineCounter, null, maxLength !== undefined ? `${count}/${maxLength}` : count)), assistiveText != null && assistiveText.length !== 0 && /*#__PURE__*/React.createElement(AssistiveText, _extends({
|
|
1090
|
+
invalid: invalid
|
|
1091
|
+
}, invalid ? errorMessageProps : descriptionProps), assistiveText));
|
|
1092
|
+
});
|
|
1093
|
+
const TextFieldRoot = styled.div(_t$1 || (_t$1 = _$1`
|
|
239
1094
|
display: flex;
|
|
240
1095
|
flex-direction: column;
|
|
241
1096
|
|
|
242
1097
|
${0}
|
|
243
|
-
`),
|
|
1098
|
+
`), p => p.isDisabled && {
|
|
1099
|
+
opacity: p.theme.elementEffect.disabled.opacity
|
|
1100
|
+
});
|
|
1101
|
+
const TextFieldLabel = styled(FieldLabel)(_t2$1 || (_t2$1 = _$1`
|
|
244
1102
|
${0}
|
|
245
|
-
`),
|
|
1103
|
+
`), theme(o => o.margin.bottom(8)));
|
|
1104
|
+
const StyledInputContainer = styled.div(_t3$1 || (_t3$1 = _$1`
|
|
246
1105
|
height: 40px;
|
|
247
1106
|
display: grid;
|
|
248
1107
|
position: relative;
|
|
249
|
-
`))
|
|
1108
|
+
`));
|
|
1109
|
+
const PrefixContainer = styled.span(_t4 || (_t4 = _$1`
|
|
250
1110
|
position: absolute;
|
|
251
1111
|
top: 50%;
|
|
252
1112
|
left: 8px;
|
|
253
1113
|
transform: translateY(-50%);
|
|
254
|
-
`))
|
|
1114
|
+
`));
|
|
1115
|
+
const SuffixContainer = styled.span(_t5 || (_t5 = _$1`
|
|
255
1116
|
position: absolute;
|
|
256
1117
|
top: 50%;
|
|
257
1118
|
right: 8px;
|
|
@@ -259,11 +1120,13 @@ import e,{useContext as t,useCallback as r,createContext as n,useMemo as a,useRe
|
|
|
259
1120
|
|
|
260
1121
|
display: flex;
|
|
261
1122
|
gap: 8px;
|
|
262
|
-
`))
|
|
1123
|
+
`));
|
|
1124
|
+
const Affix = styled.span(_t6 || (_t6 = _$1`
|
|
263
1125
|
user-select: none;
|
|
264
1126
|
|
|
265
1127
|
${0}
|
|
266
|
-
`),
|
|
1128
|
+
`), theme(o => [o.typography(14).preserveHalfLeading, o.font.text2]));
|
|
1129
|
+
const StyledInput = styled.input(_t7 || (_t7 = _$1`
|
|
267
1130
|
border: none;
|
|
268
1131
|
box-sizing: border-box;
|
|
269
1132
|
outline: none;
|
|
@@ -288,7 +1151,8 @@ import e,{useContext as t,useCallback as r,createContext as n,useMemo as a,useRe
|
|
|
288
1151
|
&::placeholder {
|
|
289
1152
|
${0}
|
|
290
1153
|
}
|
|
291
|
-
`),
|
|
1154
|
+
`), p => p.extraLeftPadding, p => p.extraRightPadding, p => theme(o => [o.bg.surface3.hover, o.outline.default.focus, p.invalid && o.outline.assertive, o.font.text2]), theme(o => o.font.text3));
|
|
1155
|
+
const StyledTextareaContainer = styled.div(_t8 || (_t8 = _$1`
|
|
292
1156
|
position: relative;
|
|
293
1157
|
overflow: hidden;
|
|
294
1158
|
padding: 0 8px;
|
|
@@ -300,9 +1164,12 @@ import e,{useContext as t,useCallback as r,createContext as n,useMemo as a,useRe
|
|
|
300
1164
|
}
|
|
301
1165
|
|
|
302
1166
|
${0};
|
|
303
|
-
`),
|
|
1167
|
+
`), p => theme(o => [o.bg.surface3.hover, p.invalid && o.outline.assertive, o.font.text2, o.borderRadius(4)]), p => theme(o => p.invalid ? o.outline.assertive : o.outline.default), ({
|
|
1168
|
+
rows
|
|
1169
|
+
}) => css(_t9 || (_t9 = _$1`
|
|
304
1170
|
height: calc(22px * ${0} + 18px);
|
|
305
|
-
`),
|
|
1171
|
+
`), rows));
|
|
1172
|
+
const StyledTextarea = styled.textarea(_t10 || (_t10 = _$1`
|
|
306
1173
|
border: none;
|
|
307
1174
|
outline: none;
|
|
308
1175
|
resize: none;
|
|
@@ -335,17 +1202,120 @@ import e,{useContext as t,useCallback as r,createContext as n,useMemo as a,useRe
|
|
|
335
1202
|
/* Hide scrollbar for IE, Edge and Firefox */
|
|
336
1203
|
-ms-overflow-style: none; /* IE and Edge */
|
|
337
1204
|
scrollbar-width: none; /* Firefox */
|
|
338
|
-
`),
|
|
1205
|
+
`), p => p.noBottomPadding ? 0 : '', ({
|
|
1206
|
+
rows: _rows = 1
|
|
1207
|
+
}) => css(_t11 || (_t11 = _$1`
|
|
339
1208
|
height: calc(22px / 0.875 * ${0});
|
|
340
|
-
`),
|
|
1209
|
+
`), _rows), theme(o => o.font.text3));
|
|
1210
|
+
const SingleLineCounter = styled.span(_t12 || (_t12 = _$1`
|
|
341
1211
|
${0}
|
|
342
|
-
`),
|
|
1212
|
+
`), theme(o => [o.typography(14).preserveHalfLeading, o.font.text3]));
|
|
1213
|
+
const MultiLineCounter = styled.span(_t13 || (_t13 = _$1`
|
|
343
1214
|
position: absolute;
|
|
344
1215
|
bottom: 9px;
|
|
345
1216
|
right: 8px;
|
|
346
1217
|
|
|
347
1218
|
${0}
|
|
348
|
-
`),
|
|
1219
|
+
`), theme(o => [o.typography(14).preserveHalfLeading, o.font.text3]));
|
|
1220
|
+
const AssistiveText = styled.p(_t14 || (_t14 = _$1`
|
|
349
1221
|
${0}
|
|
350
|
-
`),
|
|
1222
|
+
`), p => theme(o => [o.typography(14), o.margin.top(8), o.margin.bottom(0), o.font[p.invalid ? 'assertive' : 'text1']]));
|
|
1223
|
+
|
|
1224
|
+
const _excluded = ["name", "scale", "unsafeNonGuidelineScale", "className"];
|
|
1225
|
+
const Icon$1 = React.forwardRef(function IconInner(_ref, ref) {
|
|
1226
|
+
let {
|
|
1227
|
+
name,
|
|
1228
|
+
scale,
|
|
1229
|
+
unsafeNonGuidelineScale,
|
|
1230
|
+
className
|
|
1231
|
+
} = _ref,
|
|
1232
|
+
rest = _objectWithoutPropertiesLoose(_ref, _excluded);
|
|
1233
|
+
|
|
1234
|
+
return /*#__PURE__*/React.createElement("pixiv-icon", _extends({
|
|
1235
|
+
ref: ref,
|
|
1236
|
+
name: name,
|
|
1237
|
+
scale: scale,
|
|
1238
|
+
"unsafe-non-guideline-scale": unsafeNonGuidelineScale,
|
|
1239
|
+
class: className
|
|
1240
|
+
}, rest));
|
|
1241
|
+
});
|
|
1242
|
+
|
|
1243
|
+
let _ = t => t,
|
|
1244
|
+
_t,
|
|
1245
|
+
_t2,
|
|
1246
|
+
_t3;
|
|
1247
|
+
function LoadingSpinner({
|
|
1248
|
+
size = 48,
|
|
1249
|
+
padding = 16,
|
|
1250
|
+
transparent = false
|
|
1251
|
+
}) {
|
|
1252
|
+
return /*#__PURE__*/React.createElement(LoadingSpinnerRoot, {
|
|
1253
|
+
size: size,
|
|
1254
|
+
padding: padding,
|
|
1255
|
+
transparent: transparent
|
|
1256
|
+
}, /*#__PURE__*/React.createElement(LoadingSpinnerIcon, null));
|
|
1257
|
+
}
|
|
1258
|
+
const LoadingSpinnerRoot = styled.div.attrs({
|
|
1259
|
+
role: 'progressbar'
|
|
1260
|
+
})(_t || (_t = _`
|
|
1261
|
+
margin: auto;
|
|
1262
|
+
padding: ${0}px;
|
|
1263
|
+
border-radius: 8px;
|
|
1264
|
+
font-size: ${0}px;
|
|
1265
|
+
width: ${0}px;
|
|
1266
|
+
height: ${0}px;
|
|
1267
|
+
background-color: ${0};
|
|
1268
|
+
color: ${0};
|
|
1269
|
+
`), props => props.padding, props => props.size, props => props.size, props => props.size, ({
|
|
1270
|
+
theme,
|
|
1271
|
+
transparent
|
|
1272
|
+
}) => transparent ? 'transparent' : transparentize(0.32, theme.color.background1), ({
|
|
1273
|
+
theme
|
|
1274
|
+
}) => theme.color.text4);
|
|
1275
|
+
const scaleout = keyframes(_t2 || (_t2 = _`
|
|
1276
|
+
from {
|
|
1277
|
+
transform: scale(0);
|
|
1278
|
+
opacity: 1;
|
|
1279
|
+
}
|
|
1280
|
+
|
|
1281
|
+
to {
|
|
1282
|
+
transform: scale(1);
|
|
1283
|
+
opacity: 0;
|
|
1284
|
+
}
|
|
1285
|
+
`));
|
|
1286
|
+
const Icon = styled.div.attrs({
|
|
1287
|
+
role: 'presentation'
|
|
1288
|
+
})(_t3 || (_t3 = _`
|
|
1289
|
+
width: 1em;
|
|
1290
|
+
height: 1em;
|
|
1291
|
+
border-radius: 1em;
|
|
1292
|
+
background-color: currentColor;
|
|
1293
|
+
animation: ${0} 1s both ease-out;
|
|
1294
|
+
animation-iteration-count: ${0};
|
|
1295
|
+
|
|
1296
|
+
&[data-reset-animation] {
|
|
1297
|
+
animation: none;
|
|
1298
|
+
}
|
|
1299
|
+
`), scaleout, p => p.once ? 1 : 'infinite');
|
|
1300
|
+
const LoadingSpinnerIcon = React.forwardRef(function LoadingSpinnerIcon({
|
|
1301
|
+
once = false
|
|
1302
|
+
}, ref) {
|
|
1303
|
+
const iconRef = useRef(null);
|
|
1304
|
+
useImperativeHandle(ref, () => ({
|
|
1305
|
+
restart: () => {
|
|
1306
|
+
if (!iconRef.current) {
|
|
1307
|
+
return;
|
|
1308
|
+
}
|
|
1309
|
+
|
|
1310
|
+
iconRef.current.dataset.resetAnimation = 'true'; // Force reflow hack!
|
|
1311
|
+
delete iconRef.current.dataset.resetAnimation;
|
|
1312
|
+
}
|
|
1313
|
+
}));
|
|
1314
|
+
return /*#__PURE__*/React.createElement(Icon, {
|
|
1315
|
+
ref: iconRef,
|
|
1316
|
+
once: once
|
|
1317
|
+
});
|
|
1318
|
+
});
|
|
1319
|
+
|
|
1320
|
+
export { Button, Clickable, ComponentAbstraction, Icon$1 as Icon, IconButton, LoadingSpinner, LoadingSpinnerIcon, Radio, RadioGroup, Select, SelectGroup, SwitchCheckbox as Switch, TextField, useComponentAbstraction };
|
|
351
1321
|
//# sourceMappingURL=index.modern.js.map
|