@godxjp/ui 28.3.1 → 28.5.0
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 +58 -0
- package/dist/app/theme-axes.js +6 -0
- package/dist/components/data-display/scroll-area.js +2 -0
- package/dist/components/data-entry/calendar.d.ts +5 -0
- package/dist/components/data-entry/calendar.js +6 -2
- package/dist/components/data-entry/date-picker.js +12 -0
- package/dist/components/data-entry/index.d.ts +3 -0
- package/dist/components/data-entry/index.js +5 -0
- package/dist/components/data-entry/time-picker.d.ts +1 -1
- package/dist/components/data-entry/time-picker.js +8 -1
- package/dist/contracts/measurement.json +1 -1
- package/dist/props/components/data-display.prop.d.ts +22 -0
- package/dist/props/components/data-entry.prop.d.ts +14 -0
- package/dist/props/registry.d.ts +9 -0
- package/dist/props/registry.js +11 -0
- package/dist/styles/base.css +5 -3
- package/dist/styles/card-layout.css +11 -6
- package/dist/styles/control.css +19 -10
- package/dist/styles/data-display-layout.css +44 -18
- package/dist/styles/data-entry-layout.css +3 -3
- package/dist/styles/table-layout.css +9 -6
- package/dist/styles/text-layout.css +1 -1
- package/dist/theme/famgia.service.css +2 -4
- package/dist/tokens/components/control.css +4 -3
- package/dist/tokens/components/scroll-area.css +3 -0
- package/dist/tokens/derived.css +20 -0
- package/dist/tokens/foundation.css +6 -13
- package/docs/CUSTOMER-THEMING.md +82 -3
- package/docs/FRAME-COVERAGE-REPORT.md +1 -1
- package/docs/data-display/scroll-area.tsx +6 -2
- package/docs/data-entry/upload-crop-dialog.tsx +110 -0
- package/package.json +99 -92
|
@@ -92,15 +92,15 @@
|
|
|
92
92
|
}
|
|
93
93
|
|
|
94
94
|
.ui-password-strength-segment[data-tone="destructive"] {
|
|
95
|
-
background: hsl(var(--mark-destructive));
|
|
95
|
+
background: hsl(var(--mark-destructive, var(--text-error)));
|
|
96
96
|
}
|
|
97
97
|
|
|
98
98
|
.ui-password-strength-segment[data-tone="warning"] {
|
|
99
|
-
background: hsl(var(--mark-warning));
|
|
99
|
+
background: hsl(var(--mark-warning, var(--text-warning)));
|
|
100
100
|
}
|
|
101
101
|
|
|
102
102
|
.ui-password-strength-segment[data-tone="success"] {
|
|
103
|
-
background: hsl(var(--mark-success));
|
|
103
|
+
background: hsl(var(--mark-success, var(--text-success)));
|
|
104
104
|
}
|
|
105
105
|
|
|
106
106
|
.ui-password-strength-meta {
|
|
@@ -16,27 +16,30 @@
|
|
|
16
16
|
}
|
|
17
17
|
|
|
18
18
|
.ui-table-row[data-tone="primary"] {
|
|
19
|
-
--table-row-tone-color: var(
|
|
19
|
+
--table-row-tone-color: var(
|
|
20
|
+
--mark-primary,
|
|
21
|
+
var(--text-primary, from hsl(var(--primary)) var(--text-primary-channels))
|
|
22
|
+
);
|
|
20
23
|
}
|
|
21
24
|
|
|
22
25
|
.ui-table-row[data-tone="success"] {
|
|
23
|
-
--table-row-tone-color: var(--mark-success);
|
|
26
|
+
--table-row-tone-color: var(--mark-success, var(--text-success));
|
|
24
27
|
}
|
|
25
28
|
|
|
26
29
|
.ui-table-row[data-tone="warning"] {
|
|
27
|
-
--table-row-tone-color: var(--mark-warning);
|
|
30
|
+
--table-row-tone-color: var(--mark-warning, var(--text-warning));
|
|
28
31
|
}
|
|
29
32
|
|
|
30
33
|
.ui-table-row[data-tone="info"] {
|
|
31
|
-
--table-row-tone-color: var(--mark-info);
|
|
34
|
+
--table-row-tone-color: var(--mark-info, var(--text-info));
|
|
32
35
|
}
|
|
33
36
|
|
|
34
37
|
.ui-table-row[data-tone="attention"] {
|
|
35
|
-
--table-row-tone-color: var(--mark-attention);
|
|
38
|
+
--table-row-tone-color: var(--mark-attention, var(--attention));
|
|
36
39
|
}
|
|
37
40
|
|
|
38
41
|
.ui-table-row[data-tone="destructive"] {
|
|
39
|
-
--table-row-tone-color: var(--mark-destructive);
|
|
42
|
+
--table-row-tone-color: var(--mark-destructive, var(--text-error));
|
|
40
43
|
}
|
|
41
44
|
|
|
42
45
|
.ui-table-row[data-tone] {
|
|
@@ -134,7 +134,7 @@
|
|
|
134
134
|
}
|
|
135
135
|
|
|
136
136
|
[data-slot="text"][data-link][data-tone="primary"]:not([data-disabled]) {
|
|
137
|
-
color: hsl(var(--text-link));
|
|
137
|
+
color: hsl(var(--text-link, from hsl(var(--primary)) var(--text-link-channels)));
|
|
138
138
|
}
|
|
139
139
|
[data-slot="text"][data-link]:hover,
|
|
140
140
|
[data-slot="text"][data-link]:focus-visible {
|
|
@@ -7,8 +7,7 @@
|
|
|
7
7
|
|
|
8
8
|
--primary: 221 83% 53%;
|
|
9
9
|
--primary-foreground: 0 0% 100%;
|
|
10
|
-
|
|
11
|
-
--primary-active: 226 71% 40%;
|
|
10
|
+
|
|
12
11
|
--ring: 221 83% 53%;
|
|
13
12
|
|
|
14
13
|
--text-link: 224 76% 45%;
|
|
@@ -25,8 +24,7 @@
|
|
|
25
24
|
.dark {
|
|
26
25
|
--primary: 221 90% 66%;
|
|
27
26
|
--primary-foreground: 222 47% 11%;
|
|
28
|
-
|
|
29
|
-
--primary-active: 221 90% 60%;
|
|
27
|
+
|
|
30
28
|
--ring: 221 90% 66%;
|
|
31
29
|
--text-link: 221 90% 72%;
|
|
32
30
|
--text-brand: 221 90% 70%;
|
|
@@ -39,7 +39,8 @@
|
|
|
39
39
|
|
|
40
40
|
--control-count-font-size: var(--font-size-sm);
|
|
41
41
|
--control-count-color: var(--muted-foreground);
|
|
42
|
-
|
|
42
|
+
|
|
43
|
+
--control-count-exceeded-color: initial;
|
|
43
44
|
--control-count-space-inline: var(--space-1);
|
|
44
45
|
--textarea-count-inset-block-end: var(--space-1);
|
|
45
46
|
--textarea-count-inset-inline-end: var(--space-2);
|
|
@@ -388,9 +389,9 @@
|
|
|
388
389
|
--control-borderless-shadow: none;
|
|
389
390
|
|
|
390
391
|
--control-status-error-border-color: hsl(var(--destructive));
|
|
391
|
-
--control-status-warning-border-color:
|
|
392
|
+
--control-status-warning-border-color: initial;
|
|
392
393
|
|
|
393
|
-
--control-status-warning-outline-color:
|
|
394
|
+
--control-status-warning-outline-color: initial;
|
|
394
395
|
}
|
|
395
396
|
|
|
396
397
|
@media (pointer: coarse) {
|
package/dist/tokens/derived.css
CHANGED
|
@@ -20,6 +20,15 @@
|
|
|
20
20
|
--control-outline-channels: h s calc(l - 5.3);
|
|
21
21
|
--control-outline-alpha: 0.11;
|
|
22
22
|
|
|
23
|
+
--text-link: initial;
|
|
24
|
+
--text-brand: initial;
|
|
25
|
+
--text-primary: initial;
|
|
26
|
+
|
|
27
|
+
--text-link-channels: var(--primary-hover-channels);
|
|
28
|
+
--text-brand-channels: var(--primary-hover-channels);
|
|
29
|
+
|
|
30
|
+
--text-primary-channels: var(--primary-active-channels);
|
|
31
|
+
|
|
23
32
|
--destructive-hover: 359 50.6% 53.1%;
|
|
24
33
|
--destructive-active: 355 70.6% 33.3%;
|
|
25
34
|
|
|
@@ -39,6 +48,11 @@
|
|
|
39
48
|
--control-outline-channels: h calc(s * 0.99) calc(l - 25.1);
|
|
40
49
|
--control-outline-alpha: 0.29;
|
|
41
50
|
|
|
51
|
+
--text-link-channels: h s l;
|
|
52
|
+
--text-brand-channels: h s l;
|
|
53
|
+
|
|
54
|
+
--text-primary-channels: var(--primary-hover-channels);
|
|
55
|
+
|
|
42
56
|
--destructive-hover: 358.8 42.3% 53.1%;
|
|
43
57
|
--destructive-active: 357.3 50.6% 34.1%;
|
|
44
58
|
|
|
@@ -54,6 +68,9 @@
|
|
|
54
68
|
--primary-active: 268.7 100% 34.5%;
|
|
55
69
|
--primary-border: 268.7 68% 66%;
|
|
56
70
|
--control-outline: 268.7 100% 44.7%;
|
|
71
|
+
--text-link: 268.7 100% 41.6%;
|
|
72
|
+
--text-brand: 268.7 100% 41.6%;
|
|
73
|
+
--text-primary: 268.7 100% 34.5%;
|
|
57
74
|
}
|
|
58
75
|
|
|
59
76
|
.dark,
|
|
@@ -62,5 +79,8 @@
|
|
|
62
79
|
--primary-active: 268.7 100% 81.1%;
|
|
63
80
|
--primary-border: 268.7 46.7% 23.5%;
|
|
64
81
|
--control-outline: 268.7 99% 61.8%;
|
|
82
|
+
--text-link: 268.7 100% 86.9%;
|
|
83
|
+
--text-brand: 268.7 100% 86.9%;
|
|
84
|
+
--text-primary: 268.7 100% 92.7%;
|
|
65
85
|
}
|
|
66
86
|
}
|
|
@@ -40,21 +40,17 @@
|
|
|
40
40
|
--text-tertiary: 44 5% 55%;
|
|
41
41
|
--text-disabled: 40 6% 68%;
|
|
42
42
|
|
|
43
|
-
--text-link: 268.3 100% 41.6%;
|
|
44
|
-
--text-brand: 268.3 100% 41.6%;
|
|
45
|
-
|
|
46
|
-
--text-primary: 268 100% 34.5%;
|
|
47
43
|
--text-success: 152 84% 22%;
|
|
48
44
|
--text-warning: 36 100% 28%;
|
|
49
45
|
--text-info: 221 70% 38%;
|
|
50
46
|
--text-error: 357 75% 38%;
|
|
51
47
|
|
|
52
|
-
--mark-primary:
|
|
53
|
-
--mark-success:
|
|
54
|
-
--mark-warning:
|
|
55
|
-
--mark-info:
|
|
56
|
-
--mark-destructive:
|
|
57
|
-
--mark-attention:
|
|
48
|
+
--mark-primary: initial;
|
|
49
|
+
--mark-success: initial;
|
|
50
|
+
--mark-warning: initial;
|
|
51
|
+
--mark-info: initial;
|
|
52
|
+
--mark-destructive: initial;
|
|
53
|
+
--mark-attention: initial;
|
|
58
54
|
|
|
59
55
|
--secondary-hover: 45 15% 91%;
|
|
60
56
|
--secondary-active: 45 15% 88%;
|
|
@@ -349,10 +345,7 @@
|
|
|
349
345
|
|
|
350
346
|
--text-tertiary: 44 6% 56%;
|
|
351
347
|
--text-disabled: 45 6% 40%;
|
|
352
|
-
--text-link: 268.7 100% 86.9%;
|
|
353
|
-
--text-brand: 268.7 100% 86.9%;
|
|
354
348
|
|
|
355
|
-
--text-primary: 262.7 100% 92.7%;
|
|
356
349
|
--text-success: 146 55% 64%;
|
|
357
350
|
--text-warning: 44 95% 62%;
|
|
358
351
|
--text-info: 221 70% 72%;
|
package/docs/CUSTOMER-THEMING.md
CHANGED
|
@@ -6,6 +6,82 @@ The design system ships a complete, **zero-config default theme**. Two audiences
|
|
|
6
6
|
|
|
7
7
|
---
|
|
8
8
|
|
|
9
|
+
## The order to reach for things — read this before anything below
|
|
10
|
+
|
|
11
|
+
This document lists a lot of ways to change how the system looks. They are not alternatives; they
|
|
12
|
+
are a **priority order**, and the whole point of the order is that you stop at the first level that
|
|
13
|
+
does the job. Ant Design states the same rule for the same reason — _"In most cases, using Seed
|
|
14
|
+
Tokens is sufficient for custom themes"_ — and the cost of skipping down a level is real, not
|
|
15
|
+
stylistic.
|
|
16
|
+
|
|
17
|
+
| level | what it is | when | what you give up by going lower |
|
|
18
|
+
| ---------------- | --------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------- | ------------------------------------------------------------------------- |
|
|
19
|
+
| **1 · seed** | `--primary`, `--radius`, `--font-size-base`, `--shadow-color` — the handful everything derives from. `pnpm gen:brand '#RRGGBB'` writes them for you | **almost always** | nothing — this is the main road |
|
|
20
|
+
| **2 · role** | a named semantic token: `--text-link`, `--accent`, `--card-radius` | when the seed is right but ONE role must differ | that role stops following the seed; a later brand change will not move it |
|
|
21
|
+
| **3 · scope** | the same token under `[data-tenant]` / `.dark` / any subtree | multi-tenant, or one region that differs | nothing extra, provided you set the token and not a literal |
|
|
22
|
+
| **4 · instance** | a documented prop, or `style={{ "--x": … }}` on one element | this one element, this one time | it is invisible to every audit and every future theme |
|
|
23
|
+
|
|
24
|
+
**Why the order matters more than the count of knobs.** Every level below the first is a value that
|
|
25
|
+
has stopped being derived. A literal at level 4 is not "more control" — it is a pixel that has left
|
|
26
|
+
the system, and nothing will tell you when the brand moves past it. That is why the generator
|
|
27
|
+
writes three tokens and not thirty: the ones it leaves out are not missing, they are _downstream_.
|
|
28
|
+
|
|
29
|
+
**If you find yourself at level 4 twice for the same reason, the token is missing.** File it —
|
|
30
|
+
`docs/COMPOSITION-VS-COMPONENT.md` has the test for whether it is a token or a composition. Adding
|
|
31
|
+
the knob is how the system absorbs the change; repeating the literal is how it drifts.
|
|
32
|
+
|
|
33
|
+
---
|
|
34
|
+
|
|
35
|
+
## Start from one hex — `pnpm gen:brand`
|
|
36
|
+
|
|
37
|
+
Everything below this section is the manual route, and it is worth reading because it says what each
|
|
38
|
+
role means. But the colour half of a brand file is mechanical, and two of its decisions are ones CSS
|
|
39
|
+
cannot make at all, so there is a generator:
|
|
40
|
+
|
|
41
|
+
```sh
|
|
42
|
+
pnpm gen:brand '#2563EB' --name acme --out src/theme
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
It writes `acme.service.css` and `acme.email.ts`, and prints what it measured:
|
|
46
|
+
|
|
47
|
+
```
|
|
48
|
+
light seed #2563eb · dark seed #5586ef (lifted 10.4%)
|
|
49
|
+
|
|
50
|
+
✓ primary label on fill (light) 5.17:1 (needs 4.5:1)
|
|
51
|
+
✓ primary label on fill (dark) 6.03:1 (needs 4.5:1)
|
|
52
|
+
✓ primary fill on canvas (light) 5.09:1 (needs 3:1)
|
|
53
|
+
✓ primary fill on canvas (dark) 5.10:1 (needs 3:1)
|
|
54
|
+
✓ link ink on canvas (light) 6.73:1 (needs 4.5:1)
|
|
55
|
+
✓ link ink on canvas (dark) 6.36:1 (needs 4.5:1)
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
It exits non-zero when a ratio misses, so a brand that cannot meet AA says so at the point you
|
|
59
|
+
choose the colour rather than at the point a user cannot read a link.
|
|
60
|
+
|
|
61
|
+
**The two things it does that hand-authoring keeps getting wrong:**
|
|
62
|
+
|
|
63
|
+
- **A dark seed.** Nothing in CSS lifts a light seed onto the dark spine, so a brand file that sets
|
|
64
|
+
`--primary` only in `:root` keeps the GoDX violet in dark mode and nothing says so. The generator
|
|
65
|
+
holds your hue and saturation and moves lightness until the dark seed reads against the dark
|
|
66
|
+
canvas the way the light seed reads against the light one.
|
|
67
|
+
- **Email.** `src/email/tokens.generated.ts` bakes literal hex at build time, because Gmail strips
|
|
68
|
+
`<style>` and Outlook ignores custom properties. Those literals are _this package's_ seed, so a
|
|
69
|
+
re-themed product still sends GoDX-violet mail — the one surface no amount of CSS reaches. The
|
|
70
|
+
emitted `acme.email.ts` is the override that corrects it.
|
|
71
|
+
|
|
72
|
+
**What it deliberately leaves out**, because writing them would be a regression:
|
|
73
|
+
|
|
74
|
+
- `--primary-hover`, `--primary-active`, `--primary-border`, `--control-outline` — these DERIVE from
|
|
75
|
+
the `--primary` in scope at the element that paints them (gh#678). A literal pins them to one seed
|
|
76
|
+
and stops them following the next change.
|
|
77
|
+
- `--brand` / `--brand-foreground` — the identity role is independent of the action colour on
|
|
78
|
+
purpose (gh#250), so the logo does not retint when a tenant changes its button colour.
|
|
79
|
+
|
|
80
|
+
The output is a starting point, not a ceiling: every role in the tables below can still be set by
|
|
81
|
+
hand in the generated file, and an explicit value always beats a derived default.
|
|
82
|
+
|
|
83
|
+
---
|
|
84
|
+
|
|
9
85
|
## Internal apps — zero config
|
|
10
86
|
|
|
11
87
|
```ts
|
|
@@ -165,17 +241,20 @@ Import the styles, then set anchor tokens in your app's `theme.css` (loaded afte
|
|
|
165
241
|
|
|
166
242
|
### Focus ring — THE SWITCH FIRST, then three levels of override
|
|
167
243
|
|
|
168
|
-
**The indicator ships
|
|
244
|
+
**The indicator ships ON.** `--focus-outline` is `1` (`src/tokens/foundation.css`), and every painted focus length multiplies by it, so a focus mark paints by default and the package meets WCAG 2.2 SC 2.4.7. It did ship `0` once, and that earlier default — with its stated cost, a forfeited SC 2.4.7 and JIS X 8341-3 AA claim — is recorded in `docs/DESIGN-AUTHORITY.md`; gh#544 flipped it. Nothing has to be opted into.
|
|
245
|
+
|
|
246
|
+
Switching the paint is ONE attribute on the root element, no CSS:
|
|
169
247
|
|
|
170
248
|
```html
|
|
171
249
|
<html data-focus-outline="on"></html>
|
|
250
|
+
<html data-focus-outline="off"></html>
|
|
172
251
|
```
|
|
173
252
|
|
|
174
253
|
(`AppProvider` has the equivalent.) Every `:focus-visible` selector is present either way; only the paint is switched.
|
|
175
254
|
|
|
176
255
|
Every ring is then drawn by a single rule (`src/styles/focus-ring.css`) reading the tokens above. Nothing else paints one; a test fails the build if a stylesheet tries.
|
|
177
256
|
|
|
178
|
-
**Thickness is `--focus-ring-weight`, never `--focus-ring-width`.** The width is DERIVED — `calc(var(--focus-ring-weight) * var(--focus-outline))` — so assigning it directly paints a ring even
|
|
257
|
+
**Thickness is `--focus-ring-weight`, never `--focus-ring-width`.** The width is DERIVED — `calc(var(--focus-ring-weight) * var(--focus-outline))` — so assigning it directly paints a ring even where the indicator is switched off, and that is exactly what the build-failing test forbids a stylesheet to do.
|
|
179
258
|
|
|
180
259
|
```css
|
|
181
260
|
:root {
|
|
@@ -203,7 +282,7 @@ Every ring is then drawn by a single rule (`src/styles/focus-ring.css`) reading
|
|
|
203
282
|
<div style={{ "--focus-ring-color": "0 84% 60%" } as React.CSSProperties}>…</div>
|
|
204
283
|
```
|
|
205
284
|
|
|
206
|
-
**Turning it
|
|
285
|
+
**Turning it off** — set `--focus-outline: 0` (or `data-focus-outline="off"`). Do NOT reach for `--focus-ring-width`: it is derived from the weight and the switch, and pinning it to any value is the same mistake in the other direction. Note the cost: with no visible focus indicator the package no longer meets WCAG 2.2 SC 2.4.7, so this is a claim you are giving up, not a style preference.
|
|
207
286
|
|
|
208
287
|
**Adding your own component to the system**: put `ui-focus-ring` (or `ui-focus-ring-outline` when the mark needs a gap) on the focusable element.
|
|
209
288
|
|
|
@@ -135,7 +135,7 @@ Legend: ✓ covered · N/A reasoned skip · · UNTESTED (blank cell = UNTESTED).
|
|
|
135
135
|
| TreeSelect | ✓ | ✓ | · | · | · | · | · | · | · | · |
|
|
136
136
|
| Transfer | ✓ | N/A | · | · | · | · | · | · | · | · |
|
|
137
137
|
| Upload | ✓ | ✓ | · | · | · | · | · | · | · | · |
|
|
138
|
-
| UploadCropDialog | ✓ |
|
|
138
|
+
| UploadCropDialog | ✓ | N/A | N/A | · | · | · | · | · | · | · |
|
|
139
139
|
| ColorPicker | ✓ | N/A | · | · | · | · | · | · | · | · |
|
|
140
140
|
| Slider | ✓ | N/A | · | · | · | · | · | · | · | · |
|
|
141
141
|
| Calendar | ✓ | N/A | · | N/A | · | · | · | · | · | · |
|
|
@@ -16,8 +16,12 @@ import { Flex, PageContainer, ResponsiveGrid } from "@godxjp/ui/layout";
|
|
|
16
16
|
/**
|
|
17
17
|
* ScrollArea — a native scrolling box. ALWAYS give it an explicit height/max-height
|
|
18
18
|
* (vertical) or width (horizontal), or nothing ever overflows and no scrollbar appears.
|
|
19
|
-
* `orientation` decides which axes may scroll
|
|
20
|
-
* the --scroll-area-* tokens
|
|
19
|
+
* `orientation` decides which axes may scroll. By default the PLATFORM draws the bar,
|
|
20
|
+
* styled from the --scroll-area-* tokens — and on macOS/iPadOS with the system default
|
|
21
|
+
* "Show scroll bars: when scrolling" that bar is an OVERLAY: it exists only while the
|
|
22
|
+
* reader is already scrolling, so a wide area does not look scrollable at rest (gh#798).
|
|
23
|
+
* `scrollbar="always"` forces a classic bar that occupies layout, from the same tokens.
|
|
24
|
+
* Composed only from real @godxjp/ui components.
|
|
21
25
|
*/
|
|
22
26
|
const entries = Array.from(
|
|
23
27
|
{ length: 18 },
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import { useRef, useState } from "react";
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
Avatar,
|
|
5
|
+
AvatarFallback,
|
|
6
|
+
AvatarImage,
|
|
7
|
+
Card,
|
|
8
|
+
CardContent,
|
|
9
|
+
CardDescription,
|
|
10
|
+
CardHeader,
|
|
11
|
+
CardTitle,
|
|
12
|
+
} from "@godxjp/ui/data-display";
|
|
13
|
+
import { Upload, UploadCropDialog } from "@godxjp/ui/data-entry";
|
|
14
|
+
import { Button, Text } from "@godxjp/ui/general";
|
|
15
|
+
import { Flex, PageContainer } from "@godxjp/ui/layout";
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* UploadCropDialog — the square-crop step of an avatar flow, on its own.
|
|
19
|
+
*
|
|
20
|
+
* MOST SCREENS SHOULD NOT REACH FOR THIS. `<Upload variant="avatar-crop">` already embeds this
|
|
21
|
+
* dialog and owns the picker, the object URL and the commit; mounting both double-mounts the
|
|
22
|
+
* dialog. The standalone component exists for the case where the FILE ARRIVES FROM SOMEWHERE ELSE
|
|
23
|
+
* — a drag-drop zone you already own, a paste handler, a file already on the server — and only the
|
|
24
|
+
* crop step is wanted. That is the case this frame shows, beside the composed one for contrast.
|
|
25
|
+
*
|
|
26
|
+
* It is fully controlled: `open`, `file` and `onConfirm` are all required, and the dialog never
|
|
27
|
+
* opens itself. It creates and revokes its own object URL, so a caller passes the raw `File` and
|
|
28
|
+
* does NOT pre-create one. The result is always a 256×256 image/jpeg.
|
|
29
|
+
*/
|
|
30
|
+
export default function Demo() {
|
|
31
|
+
const [cropFile, setCropFile] = useState<File | null>(null);
|
|
32
|
+
const [avatar, setAvatar] = useState<string | null>(null);
|
|
33
|
+
const [lastResult, setLastResult] = useState<string | null>(null);
|
|
34
|
+
const pickerRef = useRef<HTMLInputElement>(null);
|
|
35
|
+
|
|
36
|
+
return (
|
|
37
|
+
<PageContainer title="UploadCropDialog" subtitle="切り抜きだけを単体で使う場合">
|
|
38
|
+
<Flex direction="col" gap="lg">
|
|
39
|
+
<Card>
|
|
40
|
+
<CardHeader>
|
|
41
|
+
<CardTitle level={2}>単体で使う</CardTitle>
|
|
42
|
+
<CardDescription>
|
|
43
|
+
ファイルの取得は呼び出し側の責任です。ここではブラウザのピッカーから受け取り、
|
|
44
|
+
切り抜き結果だけをこのダイアログから受け取ります。
|
|
45
|
+
</CardDescription>
|
|
46
|
+
</CardHeader>
|
|
47
|
+
<CardContent>
|
|
48
|
+
<Flex direction="col" gap="md">
|
|
49
|
+
<Flex direction="row" gap="md" align="center" wrap>
|
|
50
|
+
<Avatar size="lg">
|
|
51
|
+
{avatar ? <AvatarImage src={avatar} alt="切り抜いたプロフィール写真" /> : null}
|
|
52
|
+
<AvatarFallback>田</AvatarFallback>
|
|
53
|
+
</Avatar>
|
|
54
|
+
<Button onClick={() => pickerRef.current?.click()}>写真を選ぶ</Button>
|
|
55
|
+
</Flex>
|
|
56
|
+
|
|
57
|
+
{/* The picker is the CONSUMER's, not the dialog's — that is the whole point of using
|
|
58
|
+
this component standalone. It is hidden because the Button above is the affordance;
|
|
59
|
+
a visible raw control beside a godx Button would be two controls for one job. */}
|
|
60
|
+
<input
|
|
61
|
+
ref={pickerRef}
|
|
62
|
+
type="file"
|
|
63
|
+
accept="image/*"
|
|
64
|
+
className="sr-only"
|
|
65
|
+
aria-hidden
|
|
66
|
+
tabIndex={-1}
|
|
67
|
+
onChange={(event) => {
|
|
68
|
+
const file = event.target.files?.[0] ?? null;
|
|
69
|
+
setCropFile(file);
|
|
70
|
+
// Clear the input so re-picking the SAME file fires change again.
|
|
71
|
+
event.target.value = "";
|
|
72
|
+
}}
|
|
73
|
+
/>
|
|
74
|
+
|
|
75
|
+
<Text size="sm" tone="muted" aria-live="polite">
|
|
76
|
+
{lastResult ?? "まだ切り抜いていません。"}
|
|
77
|
+
</Text>
|
|
78
|
+
|
|
79
|
+
<UploadCropDialog
|
|
80
|
+
open={cropFile !== null}
|
|
81
|
+
// Always clear the held File on close, or the next open shows a stale image.
|
|
82
|
+
onOpenChange={(open) => !open && setCropFile(null)}
|
|
83
|
+
file={cropFile}
|
|
84
|
+
onConfirm={(cropped) => {
|
|
85
|
+
setAvatar(URL.createObjectURL(cropped));
|
|
86
|
+
setLastResult(
|
|
87
|
+
`${cropped.name} · ${cropped.type} · ${Math.round(cropped.size / 1024)} KB`,
|
|
88
|
+
);
|
|
89
|
+
}}
|
|
90
|
+
/>
|
|
91
|
+
</Flex>
|
|
92
|
+
</CardContent>
|
|
93
|
+
</Card>
|
|
94
|
+
|
|
95
|
+
<Card>
|
|
96
|
+
<CardHeader>
|
|
97
|
+
<CardTitle level={2}>通常はこちら</CardTitle>
|
|
98
|
+
<CardDescription>
|
|
99
|
+
`Upload variant="avatar-crop"` は同じダイアログを内部に持ち、ピッカーも
|
|
100
|
+
オブジェクトURLも引き受けます。両方を同時に置いてはいけません。
|
|
101
|
+
</CardDescription>
|
|
102
|
+
</CardHeader>
|
|
103
|
+
<CardContent>
|
|
104
|
+
<Upload variant="avatar-crop" accept="image/*" />
|
|
105
|
+
</CardContent>
|
|
106
|
+
</Card>
|
|
107
|
+
</Flex>
|
|
108
|
+
</PageContainer>
|
|
109
|
+
);
|
|
110
|
+
}
|