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