@wirecore/wirelayer-recipes 0.5.0 → 0.6.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/dist/app.js +2 -2
- package/dist/app.js.map +1 -1
- package/dist/button.js +8 -8
- package/dist/button.js.map +1 -1
- package/dist/card.d.ts +1 -1
- package/dist/card.js +1 -1
- package/dist/card.js.map +1 -1
- package/dist/control-ids.d.ts +10 -0
- package/dist/control-ids.d.ts.map +1 -0
- package/dist/control-ids.js +15 -0
- package/dist/control-ids.js.map +1 -0
- package/dist/data.d.ts +70 -0
- package/dist/data.d.ts.map +1 -1
- package/dist/data.js +20 -0
- package/dist/data.js.map +1 -1
- package/dist/dev.d.ts +5 -0
- package/dist/dev.d.ts.map +1 -1
- package/dist/dev.js +13 -0
- package/dist/dev.js.map +1 -1
- package/dist/extras.d.ts.map +1 -1
- package/dist/extras.js +7 -3
- package/dist/extras.js.map +1 -1
- package/dist/field.d.ts +9 -9
- package/dist/field.js +10 -10
- package/dist/field.js.map +1 -1
- package/dist/index.d.ts +5 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -3
- package/dist/index.js.map +1 -1
- package/dist/inputs.d.ts +39 -0
- package/dist/inputs.d.ts.map +1 -1
- package/dist/inputs.js +73 -40
- package/dist/inputs.js.map +1 -1
- package/dist/list-items.d.ts +8 -0
- package/dist/list-items.d.ts.map +1 -1
- package/dist/list-items.js +16 -2
- package/dist/list-items.js.map +1 -1
- package/dist/media.d.ts +24 -0
- package/dist/media.d.ts.map +1 -1
- package/dist/media.js +15 -0
- package/dist/media.js.map +1 -1
- package/dist/native/controls.d.ts +18 -0
- package/dist/native/controls.d.ts.map +1 -1
- package/dist/native/controls.js +4 -0
- package/dist/native/controls.js.map +1 -1
- package/dist/navigation.d.ts.map +1 -1
- package/dist/navigation.js +7 -3
- package/dist/navigation.js.map +1 -1
- package/dist/overlay.d.ts +36 -0
- package/dist/overlay.d.ts.map +1 -1
- package/dist/overlay.js +10 -2
- package/dist/overlay.js.map +1 -1
- package/dist/overrides.d.ts +27 -2
- package/dist/overrides.d.ts.map +1 -1
- package/dist/overrides.js +100 -11
- package/dist/overrides.js.map +1 -1
- package/dist/sources/button.css +1 -1
- package/dist/sources/card.css +1 -1
- package/dist/sources/colorPicker.css +1 -1
- package/dist/sources/combobox.css +1 -1
- package/dist/sources/dataTable.css +1 -1
- package/dist/sources/datePicker.css +1 -1
- package/dist/sources/dialog.css +1 -1
- package/dist/sources/drawer.css +1 -1
- package/dist/sources/iconButton.css +1 -1
- package/dist/sources/input.css +1 -1
- package/dist/sources/multiSelect.css +1 -1
- package/dist/sources/nativeSelect.css +1 -1
- package/dist/sources/numberInput.css +1 -1
- package/dist/sources/passwordInput.css +1 -1
- package/dist/sources/select.css +1 -1
- package/dist/sources/slider.css +1 -1
- package/dist/sources/tagsInput.css +1 -1
- package/dist/sources/textarea.css +1 -1
- package/dist/vite.d.ts +19 -0
- package/dist/vite.d.ts.map +1 -0
- package/dist/vite.js +161 -0
- package/dist/vite.js.map +1 -0
- package/package.json +15 -2
- package/src/app.ts +2 -2
- package/src/button.ts +8 -8
- package/src/card.ts +1 -1
- package/src/control-ids.ts +21 -0
- package/src/data.ts +24 -0
- package/src/dev.ts +14 -0
- package/src/extras.ts +7 -3
- package/src/field.ts +10 -10
- package/src/index.ts +7 -2
- package/src/inputs.ts +77 -40
- package/src/list-items.ts +21 -0
- package/src/media.ts +15 -0
- package/src/native/controls.ts +4 -0
- package/src/navigation.ts +9 -3
- package/src/overlay.ts +10 -2
- package/src/overrides.ts +130 -15
- package/src/vite.ts +162 -0
package/src/inputs.ts
CHANGED
|
@@ -7,12 +7,12 @@ import { tv } from './tv.js';
|
|
|
7
7
|
|
|
8
8
|
/** The bordered box around a text control – like Input */
|
|
9
9
|
const box = [
|
|
10
|
-
'flex w-full items-stretch overflow-hidden rounded-
|
|
10
|
+
'flex w-full items-stretch overflow-hidden rounded-[var(--wc-control-radius-md,0.5rem)] border border-line-strong bg-bg text-fg',
|
|
11
11
|
'transition-colors motion-reduce:transition-none focus-within:border-primary',
|
|
12
12
|
'data-invalid:border-danger data-disabled:cursor-not-allowed data-disabled:border-line data-disabled:bg-bg-2 data-disabled:text-muted',
|
|
13
13
|
];
|
|
14
14
|
const boxInput =
|
|
15
|
-
'h-full min-w-0 flex-1 bg-transparent px-3 text-[15px] text-inherit outline-none placeholder:text-muted disabled:cursor-not-allowed';
|
|
15
|
+
'h-full min-w-0 flex-1 bg-transparent px-3 text-[length:var(--wc-control-text-md,15px)] text-inherit outline-none placeholder:text-muted disabled:cursor-not-allowed';
|
|
16
16
|
/** Square button inside the box (password toggle, calendar, clear) */
|
|
17
17
|
const boxButton = [
|
|
18
18
|
'flex w-10 shrink-0 cursor-pointer items-center justify-center text-muted transition-colors hover:text-fg motion-reduce:transition-none',
|
|
@@ -32,7 +32,7 @@ const boxSuccess = { true: { control: 'border-success focus-within:border-succes
|
|
|
32
32
|
export const numberInput = tv({
|
|
33
33
|
slots: {
|
|
34
34
|
base: 'flex w-full flex-col',
|
|
35
|
-
control: [...box, 'h-
|
|
35
|
+
control: [...box, 'h-[var(--wc-control-h-md,2.5rem)]'],
|
|
36
36
|
input: [boxInput, 'tabular-nums'],
|
|
37
37
|
// Side by side, the full height: 24 × 24 px touch targets at least (WCAG 2.5.8)
|
|
38
38
|
button: [
|
|
@@ -49,9 +49,17 @@ export const numberInput = tv({
|
|
|
49
49
|
},
|
|
50
50
|
variants: {
|
|
51
51
|
size: {
|
|
52
|
-
sm: {
|
|
52
|
+
sm: {
|
|
53
|
+
control: 'h-[var(--wc-control-h-sm,2rem)] rounded-[var(--wc-control-radius-sm,0.375rem)]',
|
|
54
|
+
input: 'px-2.5 text-[length:var(--wc-control-text-sm,13px)]',
|
|
55
|
+
button: 'w-8',
|
|
56
|
+
},
|
|
53
57
|
md: {},
|
|
54
|
-
lg: {
|
|
58
|
+
lg: {
|
|
59
|
+
control: 'h-[var(--wc-control-h-lg,3rem)] rounded-[var(--wc-control-radius-lg,10px)]',
|
|
60
|
+
input: 'px-4 text-[length:var(--wc-control-text-lg,1rem)] leading-normal',
|
|
61
|
+
button: 'w-11',
|
|
62
|
+
},
|
|
55
63
|
},
|
|
56
64
|
// Up above down at the end; the field is 48px high so both keep a 24px target (WCAG 2.5.8)
|
|
57
65
|
stacked: {
|
|
@@ -67,7 +75,7 @@ export const numberInput = tv({
|
|
|
67
75
|
export const passwordInput = tv({
|
|
68
76
|
slots: {
|
|
69
77
|
base: 'flex w-full flex-col',
|
|
70
|
-
control: [...box, 'h-
|
|
78
|
+
control: [...box, 'h-[var(--wc-control-h-md,2.5rem)]'],
|
|
71
79
|
input: boxInput,
|
|
72
80
|
toggle: boxButton,
|
|
73
81
|
toggleIcon: 'size-4',
|
|
@@ -90,9 +98,17 @@ export const passwordInput = tv({
|
|
|
90
98
|
},
|
|
91
99
|
variants: {
|
|
92
100
|
size: {
|
|
93
|
-
sm: {
|
|
101
|
+
sm: {
|
|
102
|
+
control: 'h-[var(--wc-control-h-sm,2rem)] rounded-[var(--wc-control-radius-sm,0.375rem)]',
|
|
103
|
+
input: 'px-2.5 text-[length:var(--wc-control-text-sm,13px)]',
|
|
104
|
+
toggle: 'w-8',
|
|
105
|
+
},
|
|
94
106
|
md: {},
|
|
95
|
-
lg: {
|
|
107
|
+
lg: {
|
|
108
|
+
control: 'h-[var(--wc-control-h-lg,3rem)] rounded-[var(--wc-control-radius-lg,10px)]',
|
|
109
|
+
input: 'px-4 text-[length:var(--wc-control-text-lg,1rem)] leading-normal',
|
|
110
|
+
toggle: 'w-12',
|
|
111
|
+
},
|
|
96
112
|
},
|
|
97
113
|
success: boxSuccess,
|
|
98
114
|
},
|
|
@@ -143,6 +159,14 @@ export const slider = tv({
|
|
|
143
159
|
control: 'mb-6 data-[orientation=vertical]:mb-0 data-[orientation=vertical]:me-14',
|
|
144
160
|
},
|
|
145
161
|
},
|
|
162
|
+
/** The label for screen readers only (`hideLabel`) – it still names the thumbs; the value stays at the end */
|
|
163
|
+
hideLabel: {
|
|
164
|
+
true: { header: 'justify-end', label: 'sr-only' },
|
|
165
|
+
},
|
|
166
|
+
/** Neither label nor value visible: the header takes no room */
|
|
167
|
+
hideHeader: {
|
|
168
|
+
true: { header: 'sr-only' },
|
|
169
|
+
},
|
|
146
170
|
},
|
|
147
171
|
});
|
|
148
172
|
|
|
@@ -150,7 +174,7 @@ export const multiSelect = tv({
|
|
|
150
174
|
slots: {
|
|
151
175
|
base: 'flex w-full flex-col',
|
|
152
176
|
trigger: [
|
|
153
|
-
'flex h-
|
|
177
|
+
'flex h-[var(--wc-control-h-md,2.5rem)] w-full cursor-pointer items-center justify-between gap-2.5 rounded-[var(--wc-control-radius-md,0.5rem)] border border-line-strong bg-bg pe-2.5 ps-3 text-start text-[length:var(--wc-control-text-md,15px)] text-fg',
|
|
154
178
|
'outline-none transition-colors motion-reduce:transition-none focus-visible:border-primary data-[state=open]:border-primary',
|
|
155
179
|
'data-invalid:border-danger data-disabled:cursor-not-allowed data-disabled:border-line data-disabled:bg-bg-2 data-disabled:text-muted',
|
|
156
180
|
],
|
|
@@ -175,13 +199,13 @@ export const multiSelect = tv({
|
|
|
175
199
|
/** Wraps trigger and clear button (clearable); with chips the bordered box around chips and trigger */
|
|
176
200
|
control: 'relative flex',
|
|
177
201
|
chipsControl: [
|
|
178
|
-
'relative flex min-h-
|
|
202
|
+
'relative flex min-h-[var(--wc-control-h-md,2.5rem)] w-full flex-wrap items-center gap-1 rounded-[var(--wc-control-radius-md,0.5rem)] border border-line-strong bg-bg py-[5px] pe-2.5 ps-1.5 text-fg',
|
|
179
203
|
'transition-colors motion-reduce:transition-none focus-within:border-primary data-[state=open]:border-primary',
|
|
180
204
|
'data-invalid:border-danger data-disabled:cursor-not-allowed data-disabled:border-line data-disabled:bg-bg-2 data-disabled:text-muted',
|
|
181
205
|
],
|
|
182
206
|
/** The trigger next to the chips: fills the rest of the row, no border of its own */
|
|
183
207
|
chipsTrigger: [
|
|
184
|
-
'flex h-7 min-w-16 flex-1 cursor-pointer items-center justify-between gap-2.5 ps-1.5 text-start text-[15px] text-fg outline-none',
|
|
208
|
+
'flex h-7 min-w-16 flex-1 cursor-pointer items-center justify-between gap-2.5 ps-1.5 text-start text-[length:var(--wc-control-text-md,15px)] text-fg outline-none',
|
|
185
209
|
'data-disabled:cursor-not-allowed data-disabled:text-muted',
|
|
186
210
|
],
|
|
187
211
|
chip: 'inline-flex h-7 max-w-full min-w-0 items-center gap-1 rounded-md bg-line pe-0.5 ps-2 text-sm text-fg',
|
|
@@ -213,15 +237,18 @@ export const multiSelect = tv({
|
|
|
213
237
|
variants: {
|
|
214
238
|
size: {
|
|
215
239
|
sm: {
|
|
216
|
-
trigger:
|
|
217
|
-
|
|
218
|
-
|
|
240
|
+
trigger:
|
|
241
|
+
'h-[var(--wc-control-h-sm,2rem)] rounded-[var(--wc-control-radius-sm,0.375rem)] ps-2.5 pe-2 text-[length:var(--wc-control-text-sm,13px)]',
|
|
242
|
+
chipsControl:
|
|
243
|
+
'min-h-[var(--wc-control-h-sm,2rem)] rounded-[var(--wc-control-radius-sm,0.375rem)] py-0.5',
|
|
244
|
+
chipsTrigger: 'text-[length:var(--wc-control-text-sm,13px)]',
|
|
219
245
|
},
|
|
220
246
|
md: {},
|
|
221
247
|
lg: {
|
|
222
|
-
trigger:
|
|
223
|
-
|
|
224
|
-
|
|
248
|
+
trigger:
|
|
249
|
+
'h-[var(--wc-control-h-lg,3rem)] rounded-[var(--wc-control-radius-lg,10px)] ps-4 pe-3 text-[length:var(--wc-control-text-lg,1rem)] leading-normal',
|
|
250
|
+
chipsControl: 'min-h-[var(--wc-control-h-lg,3rem)] rounded-[var(--wc-control-radius-lg,10px)] py-[9px]',
|
|
251
|
+
chipsTrigger: 'text-[length:var(--wc-control-text-lg,1rem)] leading-normal',
|
|
225
252
|
},
|
|
226
253
|
},
|
|
227
254
|
// Room for the clear button between value and arrow
|
|
@@ -237,7 +264,7 @@ export const multiSelect = tv({
|
|
|
237
264
|
export const combobox = tv({
|
|
238
265
|
slots: {
|
|
239
266
|
base: 'flex w-full flex-col',
|
|
240
|
-
control: [...box, 'h-
|
|
267
|
+
control: [...box, 'h-[var(--wc-control-h-md,2.5rem)]'],
|
|
241
268
|
input: boxInput,
|
|
242
269
|
clear: [...boxButton, 'w-8'],
|
|
243
270
|
clearIcon: 'size-3.5',
|
|
@@ -257,9 +284,18 @@ export const combobox = tv({
|
|
|
257
284
|
},
|
|
258
285
|
variants: {
|
|
259
286
|
size: {
|
|
260
|
-
sm: {
|
|
287
|
+
sm: {
|
|
288
|
+
control: 'h-[var(--wc-control-h-sm,2rem)] rounded-[var(--wc-control-radius-sm,0.375rem)]',
|
|
289
|
+
input: 'px-2.5 text-[length:var(--wc-control-text-sm,13px)]',
|
|
290
|
+
trigger: 'w-8',
|
|
291
|
+
clear: 'w-7',
|
|
292
|
+
},
|
|
261
293
|
md: {},
|
|
262
|
-
lg: {
|
|
294
|
+
lg: {
|
|
295
|
+
control: 'h-[var(--wc-control-h-lg,3rem)] rounded-[var(--wc-control-radius-lg,10px)]',
|
|
296
|
+
input: 'px-4 text-[length:var(--wc-control-text-lg,1rem)] leading-normal',
|
|
297
|
+
trigger: 'w-11',
|
|
298
|
+
},
|
|
263
299
|
},
|
|
264
300
|
},
|
|
265
301
|
defaultVariants: {
|
|
@@ -270,15 +306,15 @@ export const combobox = tv({
|
|
|
270
306
|
export const datePicker = tv({
|
|
271
307
|
slots: {
|
|
272
308
|
base: 'flex w-full flex-col',
|
|
273
|
-
control: [...box, 'h-
|
|
309
|
+
control: [...box, 'h-[var(--wc-control-h-md,2.5rem)]'],
|
|
274
310
|
// Segmented date field (DateInput): one spin button per part, separators come from the locale
|
|
275
311
|
dateInput: 'relative flex min-w-0 flex-1 items-center px-3',
|
|
276
312
|
// Holds one date, or start – end of a range, in a row; invisible (still usable) while the placeholder shows
|
|
277
313
|
dateControl: 'flex min-w-0 items-center data-placeholder-shown:opacity-0',
|
|
278
314
|
/** Own placeholder of the empty field (`placeholder`) – gives way to the parts on focus */
|
|
279
315
|
placeholder:
|
|
280
|
-
'absolute inset-0 flex cursor-text items-center overflow-hidden px-3 text-[15px] whitespace-nowrap text-muted data-hidden:pointer-events-none data-hidden:opacity-0',
|
|
281
|
-
segments: 'flex items-center text-[15px]',
|
|
316
|
+
'absolute inset-0 flex cursor-text items-center overflow-hidden px-3 text-[length:var(--wc-control-text-md,15px)] whitespace-nowrap text-muted data-hidden:pointer-events-none data-hidden:opacity-0',
|
|
317
|
+
segments: 'flex items-center text-[length:var(--wc-control-text-md,15px)]',
|
|
282
318
|
segment: [
|
|
283
319
|
'rounded-sm px-px text-fg tabular-nums outline-none data-placeholder-shown:text-muted',
|
|
284
320
|
// Tabular figures would make the separators as wide as a digit
|
|
@@ -364,7 +400,8 @@ export const datePicker = tv({
|
|
|
364
400
|
'focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-fg',
|
|
365
401
|
],
|
|
366
402
|
/** Chosen dates as text in the field (selectionMode multiple), muted while empty */
|
|
367
|
-
multiValue:
|
|
403
|
+
multiValue:
|
|
404
|
+
'min-w-0 flex-1 truncate px-3 text-[length:var(--wc-control-text-md,15px)] data-placeholder:text-muted',
|
|
368
405
|
/** Short zone name after the time (showTimeZone) */
|
|
369
406
|
timeZone: 'shrink-0 self-center pe-1 text-xs text-muted',
|
|
370
407
|
/** Narrow screens (responsive): the calendar as a sheet at the bottom over a backdrop */
|
|
@@ -372,34 +409,34 @@ export const datePicker = tv({
|
|
|
372
409
|
backdrop: 'fixed inset-0 z-40 bg-black/40 motion-safe:animate-fade-in',
|
|
373
410
|
/** QuarterPicker: typed quarter ("Q4 2026"), the year above the quarters, the quarters */
|
|
374
411
|
textInput:
|
|
375
|
-
'h-full min-w-0 flex-1 bg-transparent px-3 text-[15px] text-inherit outline-none placeholder:text-muted disabled:cursor-not-allowed',
|
|
412
|
+
'h-full min-w-0 flex-1 bg-transparent px-3 text-[length:var(--wc-control-text-md,15px)] text-inherit outline-none placeholder:text-muted disabled:cursor-not-allowed',
|
|
376
413
|
yearLabel: 'text-sm font-semibold tabular-nums',
|
|
377
414
|
quarterGrid: 'grid grid-cols-2 gap-1',
|
|
378
415
|
/** DurationInput: unit after a part ("hr") */
|
|
379
|
-
unit: 'px-1 text-[15px] text-muted',
|
|
416
|
+
unit: 'px-1 text-[length:var(--wc-control-text-md,15px)] text-muted',
|
|
380
417
|
},
|
|
381
418
|
variants: {
|
|
382
419
|
size: {
|
|
383
420
|
sm: {
|
|
384
|
-
control: 'h-
|
|
421
|
+
control: 'h-[var(--wc-control-h-sm,2rem)] rounded-[var(--wc-control-radius-sm,0.375rem)]',
|
|
385
422
|
dateInput: 'px-2.5',
|
|
386
|
-
placeholder: 'px-2.5 text-[13px]',
|
|
387
|
-
segments: 'text-[13px]',
|
|
388
|
-
multiValue: 'px-2.5 text-[13px]',
|
|
389
|
-
textInput: 'px-2.5 text-[13px]',
|
|
390
|
-
unit: 'text-[13px]',
|
|
423
|
+
placeholder: 'px-2.5 text-[length:var(--wc-control-text-sm,13px)]',
|
|
424
|
+
segments: 'text-[length:var(--wc-control-text-sm,13px)]',
|
|
425
|
+
multiValue: 'px-2.5 text-[length:var(--wc-control-text-sm,13px)]',
|
|
426
|
+
textInput: 'px-2.5 text-[length:var(--wc-control-text-sm,13px)]',
|
|
427
|
+
unit: 'text-[length:var(--wc-control-text-sm,13px)]',
|
|
391
428
|
trigger: 'w-8',
|
|
392
429
|
clear: 'w-7',
|
|
393
430
|
},
|
|
394
431
|
md: {},
|
|
395
432
|
lg: {
|
|
396
|
-
control: 'h-
|
|
433
|
+
control: 'h-[var(--wc-control-h-lg,3rem)] rounded-[var(--wc-control-radius-lg,10px)]',
|
|
397
434
|
dateInput: 'px-4',
|
|
398
|
-
placeholder: 'px-4 text-
|
|
399
|
-
segments: 'text-
|
|
400
|
-
multiValue: 'px-4 text-
|
|
401
|
-
textInput: 'px-4 text-
|
|
402
|
-
unit: 'text-
|
|
435
|
+
placeholder: 'px-4 text-[length:var(--wc-control-text-lg,1rem)] leading-normal',
|
|
436
|
+
segments: 'text-[length:var(--wc-control-text-lg,1rem)] leading-normal',
|
|
437
|
+
multiValue: 'px-4 text-[length:var(--wc-control-text-lg,1rem)] leading-normal',
|
|
438
|
+
textInput: 'px-4 text-[length:var(--wc-control-text-lg,1rem)] leading-normal',
|
|
439
|
+
unit: 'text-[length:var(--wc-control-text-lg,1rem)] leading-normal',
|
|
403
440
|
trigger: 'w-11',
|
|
404
441
|
},
|
|
405
442
|
},
|
|
@@ -630,9 +667,9 @@ export const knob = tv({
|
|
|
630
667
|
export const colorPicker = tv({
|
|
631
668
|
slots: {
|
|
632
669
|
base: 'flex w-full flex-col',
|
|
633
|
-
control: [...box, 'h-
|
|
670
|
+
control: [...box, 'h-[var(--wc-control-h-md,2.5rem)]'],
|
|
634
671
|
trigger: [
|
|
635
|
-
'flex min-w-0 flex-1 cursor-pointer items-center gap-2.5 px-3 text-start text-[15px] text-fg outline-none',
|
|
672
|
+
'flex min-w-0 flex-1 cursor-pointer items-center gap-2.5 px-3 text-start text-[length:var(--wc-control-text-md,15px)] text-fg outline-none',
|
|
636
673
|
'focus-visible:outline-2 focus-visible:-outline-offset-2 focus-visible:outline-fg',
|
|
637
674
|
],
|
|
638
675
|
swatch: 'size-5 shrink-0 rounded-md shadow-[inset_0_0_0_1px_rgba(0,0,0,.15)]',
|
package/src/list-items.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { warnInDevelopment } from './dev.js';
|
|
2
|
+
|
|
1
3
|
// Shared logic of the option lists (Select, MultiSelect, Combobox, Autocomplete, Listbox, TagsInput, VirtualSelect):
|
|
2
4
|
// items of any shape, values of any type, stable string keys for Ark, groups and filtering.
|
|
3
5
|
|
|
@@ -33,6 +35,8 @@ export interface ListOption<T = unknown> {
|
|
|
33
35
|
keywords?: string[];
|
|
34
36
|
/** The original item (for slots and render functions) */
|
|
35
37
|
item: T;
|
|
38
|
+
/** A chosen value that is not among the items – shown as its text (see checkListValues) */
|
|
39
|
+
unknown?: boolean;
|
|
36
40
|
}
|
|
37
41
|
|
|
38
42
|
/** Options under one heading; `label` is undefined for items without a group */
|
|
@@ -173,10 +177,27 @@ export function listOptionsForValues<T>(
|
|
|
173
177
|
label: String(value),
|
|
174
178
|
disabled: false,
|
|
175
179
|
item: value as T,
|
|
180
|
+
unknown: true,
|
|
176
181
|
};
|
|
177
182
|
});
|
|
178
183
|
}
|
|
179
184
|
|
|
185
|
+
/**
|
|
186
|
+
* Development only: warns about chosen values that are not among the loaded items – they show as raw text, e.g. a
|
|
187
|
+
* country code while the items carry country names. Call it once the items are there (not while loading, not while a
|
|
188
|
+
* data source can still resolve the value, not for free text).
|
|
189
|
+
*/
|
|
190
|
+
export function checkListValues(component: string, selected: readonly ListOption[]) {
|
|
191
|
+
for (const option of selected) {
|
|
192
|
+
if (!option.unknown) continue;
|
|
193
|
+
warnInDevelopment(
|
|
194
|
+
`${component}: the value ${JSON.stringify(option.value)} is not among its items and shows as text. ` +
|
|
195
|
+
'Check `itemValue`/`valueKey` against the values of the items – a value the items load later can be ' +
|
|
196
|
+
'resolved by a data source (`getItemsByKeys`).'
|
|
197
|
+
);
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
|
|
180
201
|
/**
|
|
181
202
|
* The value of a single choice as a list: undefined → [], null → [] – unless one of the options has the value null
|
|
182
203
|
* (e.g. "All"): then null chooses it.
|
package/src/media.ts
CHANGED
|
@@ -14,6 +14,8 @@ export const carousel = tv({
|
|
|
14
14
|
control:
|
|
15
15
|
'flex items-center gap-2 rtl:[&_[data-part=prev-trigger]_svg]:-scale-x-100 rtl:[&_[data-part=next-trigger]_svg]:-scale-x-100',
|
|
16
16
|
indicatorGroup: 'flex flex-1 flex-wrap items-center justify-center',
|
|
17
|
+
/** `controlsPosition: 'sides'`: previous button, slides and next button in a row */
|
|
18
|
+
stage: 'flex min-w-0 items-center gap-2 rtl:[&_[data-part=prev-trigger]_svg]:-scale-x-100 rtl:[&_[data-part=next-trigger]_svg]:-scale-x-100',
|
|
17
19
|
// 24 × 24 px target (WCAG 2.5.8) around a small dot; the current one is wider, not only coloured
|
|
18
20
|
indicator: [
|
|
19
21
|
'flex size-6 cursor-pointer items-center justify-center rounded-full',
|
|
@@ -34,7 +36,20 @@ export const carousel = tv({
|
|
|
34
36
|
'[&_[data-part=prev-trigger]_svg]:rotate-90 [&_[data-part=next-trigger]_svg]:rotate-90 rtl:[&_[data-part=prev-trigger]_svg]:scale-x-100 rtl:[&_[data-part=next-trigger]_svg]:scale-x-100',
|
|
35
37
|
},
|
|
36
38
|
},
|
|
39
|
+
/** Previous and next beside the slides (`controlsPosition: 'sides'`) – without it in the row below them */
|
|
40
|
+
controlsPosition: {
|
|
41
|
+
sides: { itemGroup: 'min-w-0 flex-1' },
|
|
42
|
+
},
|
|
37
43
|
},
|
|
44
|
+
compoundVariants: [
|
|
45
|
+
{
|
|
46
|
+
vertical: true,
|
|
47
|
+
controlsPosition: 'sides',
|
|
48
|
+
class: {
|
|
49
|
+
stage: 'flex-col [&_[data-part=prev-trigger]_svg]:rotate-90 [&_[data-part=next-trigger]_svg]:rotate-90 rtl:[&_[data-part=prev-trigger]_svg]:scale-x-100 rtl:[&_[data-part=next-trigger]_svg]:scale-x-100',
|
|
50
|
+
},
|
|
51
|
+
},
|
|
52
|
+
],
|
|
38
53
|
});
|
|
39
54
|
|
|
40
55
|
export const gallery = tv({
|
package/src/native/controls.ts
CHANGED
|
@@ -163,6 +163,10 @@ export const slider = tv({
|
|
|
163
163
|
markLabel: 'mt-0',
|
|
164
164
|
},
|
|
165
165
|
},
|
|
166
|
+
/** Without the visible label (`hideLabel`): the value stays at the end */
|
|
167
|
+
hideLabel: {
|
|
168
|
+
true: { header: 'justify-end' },
|
|
169
|
+
},
|
|
166
170
|
},
|
|
167
171
|
defaultVariants: {
|
|
168
172
|
orientation: 'horizontal',
|
package/src/navigation.ts
CHANGED
|
@@ -67,7 +67,7 @@ export const select = tv({
|
|
|
67
67
|
slots: {
|
|
68
68
|
base: 'flex w-full flex-col',
|
|
69
69
|
trigger: [
|
|
70
|
-
'flex h-
|
|
70
|
+
'flex h-[var(--wc-control-h-md,2.5rem)] w-full cursor-pointer items-center justify-between gap-2.5 rounded-[var(--wc-control-radius-md,0.5rem)] border border-line-strong bg-bg pe-2.5 ps-3 text-start text-[length:var(--wc-control-text-md,15px)] text-fg',
|
|
71
71
|
'outline-none transition-colors motion-reduce:transition-none focus-visible:border-primary data-[state=open]:border-primary',
|
|
72
72
|
'data-invalid:border-danger data-disabled:cursor-not-allowed data-disabled:border-line data-disabled:bg-bg-2 data-disabled:text-muted',
|
|
73
73
|
],
|
|
@@ -90,9 +90,15 @@ export const select = tv({
|
|
|
90
90
|
},
|
|
91
91
|
variants: {
|
|
92
92
|
size: {
|
|
93
|
-
sm: {
|
|
93
|
+
sm: {
|
|
94
|
+
trigger:
|
|
95
|
+
'h-[var(--wc-control-h-sm,2rem)] rounded-[var(--wc-control-radius-sm,0.375rem)] ps-2.5 pe-2 text-[length:var(--wc-control-text-sm,13px)]',
|
|
96
|
+
},
|
|
94
97
|
md: {},
|
|
95
|
-
lg: {
|
|
98
|
+
lg: {
|
|
99
|
+
trigger:
|
|
100
|
+
'h-[var(--wc-control-h-lg,3rem)] rounded-[var(--wc-control-radius-lg,10px)] ps-4 pe-3 text-[length:var(--wc-control-text-lg,1rem)] leading-normal',
|
|
101
|
+
},
|
|
96
102
|
},
|
|
97
103
|
// Room for the clear button between value and arrow
|
|
98
104
|
clearable: {
|
package/src/overlay.ts
CHANGED
|
@@ -96,7 +96,7 @@ export type DialogStatus = 'neutral' | 'success' | 'info' | 'warn' | 'danger';
|
|
|
96
96
|
export const dialog = tv({
|
|
97
97
|
slots: {
|
|
98
98
|
backdrop: [
|
|
99
|
-
'fixed inset-0 z-50 bg-
|
|
99
|
+
'fixed inset-0 z-50 bg-[var(--wc-backdrop,rgb(0_0_0/0.6))]',
|
|
100
100
|
'motion-safe:data-[state=open]:animate-fade-in motion-safe:data-[state=closed]:animate-fade-out',
|
|
101
101
|
],
|
|
102
102
|
positioner: 'fixed inset-0 z-50 flex items-center justify-center overflow-y-auto p-4',
|
|
@@ -126,6 +126,10 @@ export const dialog = tv({
|
|
|
126
126
|
maximizeIcon: 'size-4',
|
|
127
127
|
},
|
|
128
128
|
variants: {
|
|
129
|
+
/** The title only for screen readers – it still names the dialog */
|
|
130
|
+
hideTitle: {
|
|
131
|
+
true: { title: 'sr-only' },
|
|
132
|
+
},
|
|
129
133
|
status: {
|
|
130
134
|
neutral: { iconBox: 'bg-line text-fg' },
|
|
131
135
|
success: { iconBox: 'bg-success/14 text-success' },
|
|
@@ -189,7 +193,7 @@ const drawerSizes: OverlaySize[] = ['sm', 'md', 'lg', 'xl', 'full'];
|
|
|
189
193
|
export const drawer = tv({
|
|
190
194
|
slots: {
|
|
191
195
|
backdrop: [
|
|
192
|
-
'fixed inset-0 z-50 bg-
|
|
196
|
+
'fixed inset-0 z-50 bg-[var(--wc-backdrop,rgb(0_0_0/0.6))]',
|
|
193
197
|
'motion-safe:data-[state=open]:animate-fade-in motion-safe:data-[state=closed]:animate-fade-out',
|
|
194
198
|
],
|
|
195
199
|
positioner: 'fixed inset-0 z-50 flex',
|
|
@@ -210,6 +214,10 @@ export const drawer = tv({
|
|
|
210
214
|
footer: 'flex flex-wrap justify-end gap-2 border-t border-line px-5 py-3',
|
|
211
215
|
},
|
|
212
216
|
variants: {
|
|
217
|
+
/** The title only for screen readers – it still names the drawer */
|
|
218
|
+
hideTitle: {
|
|
219
|
+
true: { title: 'sr-only' },
|
|
220
|
+
},
|
|
213
221
|
placement: {
|
|
214
222
|
right: {
|
|
215
223
|
positioner: 'justify-end',
|
package/src/overrides.ts
CHANGED
|
@@ -13,12 +13,28 @@ type Variants<R extends AnyRecipe> = NonNullable<Parameters<R>[0]>;
|
|
|
13
13
|
export type RecipeSlot<R extends AnyRecipe> = ReturnType<R> extends string ? 'base' : keyof ReturnType<R> & string;
|
|
14
14
|
/** Extra classes per part, e.g. `{ base: 'rounded-none', icon: 'text-primary' }` */
|
|
15
15
|
export type RecipeClasses<R extends AnyRecipe> = Partial<Record<RecipeSlot<R>, ClassValue>>;
|
|
16
|
+
/** Names of the variants of a recipe (`size`, `invalid` …) */
|
|
17
|
+
export type RecipeVariantName<R extends AnyRecipe> = Exclude<keyof Variants<R>, 'class' | 'className'> & string;
|
|
18
|
+
/** The values of a variant as the recipe writes them: `'sm' | 'md'`, `'true' | 'false'` for a flag */
|
|
19
|
+
type ValueKey<V> = V extends boolean ? 'true' | 'false' : V extends string | number ? `${V}` : never;
|
|
20
|
+
/** Extra classes per part for single values of a variant, e.g. `{ size: { md: { base: 'h-11' } } }` */
|
|
21
|
+
export type RecipeVariantClasses<R extends AnyRecipe> = {
|
|
22
|
+
[K in RecipeVariantName<R>]?: { [V in ValueKey<NonNullable<Variants<R>[K]>>]?: RecipeClasses<R> };
|
|
23
|
+
};
|
|
24
|
+
/** Extra classes per part when all the given variants match, e.g. `{ size: 'md', shape: 'rounded', classes: … }` */
|
|
25
|
+
export type RecipeCompoundClasses<R extends AnyRecipe> = {
|
|
26
|
+
[K in RecipeVariantName<R>]?: NonNullable<Variants<R>[K]> | NonNullable<Variants<R>[K]>[];
|
|
27
|
+
} & { classes: RecipeClasses<R> };
|
|
16
28
|
|
|
17
29
|
/** Defaults and classes for one recipe */
|
|
18
30
|
export interface RecipeOverride<R extends AnyRecipe = AnyRecipe> {
|
|
19
31
|
/** Variants used when a component does not set them, e.g. `{ size: 'sm' }` */
|
|
20
32
|
defaultVariants?: Partial<Omit<Variants<R>, 'class' | 'className'>>;
|
|
21
33
|
classes?: RecipeClasses<R>;
|
|
34
|
+
/** Classes per part for single values of a variant, e.g. `{ size: { md: { base: 'h-11' } } }` */
|
|
35
|
+
variants?: RecipeVariantClasses<R>;
|
|
36
|
+
/** Classes per part for combinations of variants, e.g. `[{ size: 'md', shape: 'rounded', classes: … }]` */
|
|
37
|
+
compoundVariants?: RecipeCompoundClasses<R>[];
|
|
22
38
|
}
|
|
23
39
|
|
|
24
40
|
/** Overrides by recipe name (the export name: `button`, `iconButton`, `dataTable` …) */
|
|
@@ -32,7 +48,10 @@ export type RecipeName = {
|
|
|
32
48
|
/** Typed overrides for RecipesProvider: variants and part names per recipe */
|
|
33
49
|
export type RecipeConfig = { [K in RecipeName]?: RecipeOverride<Extract<Exports[K], AnyRecipe>> };
|
|
34
50
|
|
|
35
|
-
/**
|
|
51
|
+
/**
|
|
52
|
+
* Inner overrides win: defaults per variant, classes per part (also per variant value) are joined and compound
|
|
53
|
+
* variants appended – later ones win in tailwind-merge
|
|
54
|
+
*/
|
|
36
55
|
export function mergeRecipeOverrides(outer: RecipeOverrides, inner: RecipeOverrides): RecipeOverrides {
|
|
37
56
|
const merged: RecipeOverrides = { ...outer };
|
|
38
57
|
for (const [name, override] of Object.entries(inner)) {
|
|
@@ -42,12 +61,28 @@ export function mergeRecipeOverrides(outer: RecipeOverrides, inner: RecipeOverri
|
|
|
42
61
|
? {
|
|
43
62
|
defaultVariants: { ...before.defaultVariants, ...override.defaultVariants },
|
|
44
63
|
classes: joinClasses(before.classes, override.classes),
|
|
64
|
+
variants: joinVariants(before.variants, override.variants),
|
|
65
|
+
compoundVariants: [...(before.compoundVariants ?? []), ...(override.compoundVariants ?? [])],
|
|
45
66
|
}
|
|
46
67
|
: override;
|
|
47
68
|
}
|
|
48
69
|
return merged;
|
|
49
70
|
}
|
|
50
71
|
|
|
72
|
+
type VariantClasses = Record<string, Record<string, Record<string, ClassValue> | undefined> | undefined>;
|
|
73
|
+
|
|
74
|
+
function joinVariants(first: VariantClasses | undefined, second: VariantClasses | undefined) {
|
|
75
|
+
if (!first) return second;
|
|
76
|
+
if (!second) return first;
|
|
77
|
+
const joined: VariantClasses = { ...first };
|
|
78
|
+
for (const [variant, values] of Object.entries(second)) {
|
|
79
|
+
const all = { ...joined[variant] };
|
|
80
|
+
for (const [value, classes] of Object.entries(values ?? {})) all[value] = joinClasses(all[value], classes);
|
|
81
|
+
joined[variant] = all;
|
|
82
|
+
}
|
|
83
|
+
return joined;
|
|
84
|
+
}
|
|
85
|
+
|
|
51
86
|
function joinClasses(
|
|
52
87
|
first: Record<string, ClassValue> | undefined,
|
|
53
88
|
second: Record<string, ClassValue> | undefined
|
|
@@ -59,34 +94,114 @@ function joinClasses(
|
|
|
59
94
|
return joined;
|
|
60
95
|
}
|
|
61
96
|
|
|
97
|
+
/**
|
|
98
|
+
* Variants that are states: with classes for a part, the classes of an active state are added again after them – a
|
|
99
|
+
* changed border keeps the red of an invalid field. The class passed to the part comes last and still wins.
|
|
100
|
+
*/
|
|
101
|
+
const STATE_VARIANTS = new Set([
|
|
102
|
+
'invalid',
|
|
103
|
+
'success',
|
|
104
|
+
'disabled',
|
|
105
|
+
'readOnly',
|
|
106
|
+
'current',
|
|
107
|
+
'selected',
|
|
108
|
+
'checked',
|
|
109
|
+
'loading',
|
|
110
|
+
]);
|
|
111
|
+
|
|
112
|
+
type PartClasses = Record<string, ClassValue[]>;
|
|
113
|
+
/** A recipe (tv: `class` per value, a string for the base part) or an override (`classes` per part) */
|
|
114
|
+
interface VariantSource {
|
|
115
|
+
classes?: Record<string, ClassValue>;
|
|
116
|
+
variants?: Record<string, Record<string, unknown> | undefined>;
|
|
117
|
+
compoundVariants?: Record<string, unknown>[];
|
|
118
|
+
defaultVariants?: Record<string, unknown>;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/** Adds classes of a variant (a class value for the base part or classes per part) */
|
|
122
|
+
function addClasses(into: PartClasses, value: unknown) {
|
|
123
|
+
if (value === undefined || value === null || value === '') return;
|
|
124
|
+
if (typeof value === 'string' || Array.isArray(value)) (into.base ??= []).push(value as ClassValue);
|
|
125
|
+
else
|
|
126
|
+
for (const [slot, classes] of Object.entries(value as Record<string, ClassValue>))
|
|
127
|
+
(into[slot] ??= []).push(classes);
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
const matches = (value: unknown, condition: unknown) =>
|
|
131
|
+
Array.isArray(condition)
|
|
132
|
+
? condition.some((item) => String(item) === String(value))
|
|
133
|
+
: String(condition) === String(value);
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* Adds the classes of the matching variant values and compound variants of `source` – either those of states (a state
|
|
137
|
+
* variant, or a compound variant with one) or all others
|
|
138
|
+
*/
|
|
139
|
+
function addMatching(into: PartClasses, source: VariantSource, active: Record<string, unknown>, states: boolean) {
|
|
140
|
+
for (const [name, values] of Object.entries(source.variants ?? {})) {
|
|
141
|
+
if (STATE_VARIANTS.has(name) === states && active[name] !== undefined)
|
|
142
|
+
addClasses(into, values?.[String(active[name])]);
|
|
143
|
+
}
|
|
144
|
+
for (const { class: value, className, classes, ...conditions } of source.compoundVariants ?? []) {
|
|
145
|
+
const names = Object.keys(conditions);
|
|
146
|
+
if (names.some((name) => STATE_VARIANTS.has(name)) !== states) continue;
|
|
147
|
+
if (names.every((name) => matches(active[name], conditions[name])))
|
|
148
|
+
addClasses(into, classes ?? value ?? className);
|
|
149
|
+
}
|
|
150
|
+
return into;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
const defined = (props: Record<string, unknown>) =>
|
|
154
|
+
Object.fromEntries(Object.entries(props).filter(([, value]) => value !== undefined));
|
|
155
|
+
|
|
62
156
|
/**
|
|
63
157
|
* The recipe with the overrides applied, outer first: provider defaults fill the variants a component left open
|
|
64
|
-
* (explicit values win)
|
|
158
|
+
* (explicit values win). Each part then gets, in this order: the override classes, the override classes of matching
|
|
159
|
+
* variant values and compound variants, the classes of the active states (see STATE_VARIANTS), the override classes
|
|
160
|
+
* of those states – and last the class the component passes for it.
|
|
65
161
|
*/
|
|
66
162
|
export function withRecipeOverrides<R extends AnyRecipe>(recipe: R, overrides: (RecipeOverride | undefined)[]): R {
|
|
67
|
-
const active = overrides.filter((override): override is RecipeOverride => !!override);
|
|
163
|
+
const active = overrides.filter((override): override is RecipeOverride => !!override) as VariantSource[];
|
|
68
164
|
if (active.length === 0) return recipe;
|
|
69
165
|
const defaults = Object.assign({}, ...active.map((override) => override.defaultVariants));
|
|
70
|
-
const
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
)
|
|
166
|
+
const styled = active.some((override) => override.classes || override.variants || override.compoundVariants);
|
|
167
|
+
const own = recipe as unknown as VariantSource;
|
|
168
|
+
/** Classes for the parts with the given variants: undefined for a part without overrides */
|
|
169
|
+
const partClasses = (variants: Record<string, unknown>) => {
|
|
170
|
+
const current = { ...own.defaultVariants, ...variants };
|
|
171
|
+
const look: PartClasses = {};
|
|
172
|
+
const states: PartClasses = {};
|
|
173
|
+
for (const override of active) {
|
|
174
|
+
addClasses(look, override.classes);
|
|
175
|
+
addMatching(look, override, current, false);
|
|
176
|
+
}
|
|
177
|
+
for (const override of active) addMatching(states, override, current, true);
|
|
178
|
+
const recipeStates = addMatching({}, own, current, true);
|
|
179
|
+
return (slot: string) =>
|
|
180
|
+
look[slot] || states[slot] ? [look[slot], recipeStates[slot], states[slot]] : undefined;
|
|
181
|
+
};
|
|
74
182
|
return ((props: Record<string, unknown> = {}) => {
|
|
75
|
-
const given =
|
|
183
|
+
const given = defined(props);
|
|
76
184
|
const variants = { ...defaults, ...given };
|
|
77
|
-
if (!
|
|
185
|
+
if (!styled) return recipe(variants);
|
|
78
186
|
const result = recipe(variants);
|
|
79
187
|
// Recipes without parts: the classes join the class of the call
|
|
80
|
-
if (typeof result === 'string')
|
|
81
|
-
|
|
188
|
+
if (typeof result === 'string') {
|
|
189
|
+
const classes = partClasses(variants)('base');
|
|
190
|
+
return classes ? recipe({ ...variants, class: [classes, given.class] }) : result;
|
|
191
|
+
}
|
|
192
|
+
// Slot recipes: the parts with overrides get them (with variants passed to the part as well)
|
|
193
|
+
const forCall = partClasses(variants);
|
|
82
194
|
return Object.fromEntries(
|
|
83
195
|
Object.entries(result as Record<string, (slotProps?: Record<string, unknown>) => string>).map(
|
|
84
196
|
([slot, part]) => [
|
|
85
197
|
slot,
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
198
|
+
(slotProps: Record<string, unknown> = {}) => {
|
|
199
|
+
const passed = defined(slotProps);
|
|
200
|
+
const classes = Object.keys(passed).some((key) => key !== 'class' && key !== 'className')
|
|
201
|
+
? partClasses({ ...variants, ...passed })(slot)
|
|
202
|
+
: forCall(slot);
|
|
203
|
+
return classes ? part({ ...slotProps, class: [classes, slotProps.class] }) : part(slotProps);
|
|
204
|
+
},
|
|
90
205
|
]
|
|
91
206
|
)
|
|
92
207
|
);
|