@wirecore/wirelayer-recipes 0.4.1 → 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.
Files changed (166) hide show
  1. package/dist/app.js +2 -2
  2. package/dist/app.js.map +1 -1
  3. package/dist/button.js +8 -8
  4. package/dist/button.js.map +1 -1
  5. package/dist/card.d.ts +1 -1
  6. package/dist/card.js +1 -1
  7. package/dist/card.js.map +1 -1
  8. package/dist/control-ids.d.ts +10 -0
  9. package/dist/control-ids.d.ts.map +1 -0
  10. package/dist/control-ids.js +15 -0
  11. package/dist/control-ids.js.map +1 -0
  12. package/dist/data-table.d.ts +10 -0
  13. package/dist/data-table.d.ts.map +1 -1
  14. package/dist/data-table.js +16 -0
  15. package/dist/data-table.js.map +1 -1
  16. package/dist/data.d.ts +70 -0
  17. package/dist/data.d.ts.map +1 -1
  18. package/dist/data.js +20 -0
  19. package/dist/data.js.map +1 -1
  20. package/dist/dev.d.ts +5 -0
  21. package/dist/dev.d.ts.map +1 -1
  22. package/dist/dev.js +13 -0
  23. package/dist/dev.js.map +1 -1
  24. package/dist/extras.d.ts.map +1 -1
  25. package/dist/extras.js +7 -3
  26. package/dist/extras.js.map +1 -1
  27. package/dist/field.d.ts +9 -9
  28. package/dist/field.js +10 -10
  29. package/dist/field.js.map +1 -1
  30. package/dist/i18n.d.ts +1 -0
  31. package/dist/i18n.d.ts.map +1 -1
  32. package/dist/i18n.js +1 -0
  33. package/dist/i18n.js.map +1 -1
  34. package/dist/index.d.ts +6 -5
  35. package/dist/index.d.ts.map +1 -1
  36. package/dist/index.js +5 -4
  37. package/dist/index.js.map +1 -1
  38. package/dist/inputs.d.ts +51 -0
  39. package/dist/inputs.d.ts.map +1 -1
  40. package/dist/inputs.js +77 -40
  41. package/dist/inputs.js.map +1 -1
  42. package/dist/list-items.d.ts +21 -3
  43. package/dist/list-items.d.ts.map +1 -1
  44. package/dist/list-items.js +32 -6
  45. package/dist/list-items.js.map +1 -1
  46. package/dist/locales/ar.d.ts.map +1 -1
  47. package/dist/locales/ar.js +1 -0
  48. package/dist/locales/ar.js.map +1 -1
  49. package/dist/locales/cs.d.ts.map +1 -1
  50. package/dist/locales/cs.js +1 -0
  51. package/dist/locales/cs.js.map +1 -1
  52. package/dist/locales/de.d.ts +1 -0
  53. package/dist/locales/de.d.ts.map +1 -1
  54. package/dist/locales/de.js +1 -0
  55. package/dist/locales/de.js.map +1 -1
  56. package/dist/locales/es.d.ts.map +1 -1
  57. package/dist/locales/es.js +1 -0
  58. package/dist/locales/es.js.map +1 -1
  59. package/dist/locales/fr.d.ts.map +1 -1
  60. package/dist/locales/fr.js +1 -0
  61. package/dist/locales/fr.js.map +1 -1
  62. package/dist/locales/hu.d.ts.map +1 -1
  63. package/dist/locales/hu.js +1 -0
  64. package/dist/locales/hu.js.map +1 -1
  65. package/dist/locales/it.d.ts.map +1 -1
  66. package/dist/locales/it.js +1 -0
  67. package/dist/locales/it.js.map +1 -1
  68. package/dist/locales/lv.d.ts.map +1 -1
  69. package/dist/locales/lv.js +1 -0
  70. package/dist/locales/lv.js.map +1 -1
  71. package/dist/locales/nl.d.ts.map +1 -1
  72. package/dist/locales/nl.js +1 -0
  73. package/dist/locales/nl.js.map +1 -1
  74. package/dist/locales/pl.d.ts.map +1 -1
  75. package/dist/locales/pl.js +1 -0
  76. package/dist/locales/pl.js.map +1 -1
  77. package/dist/locales/pt-BR.d.ts.map +1 -1
  78. package/dist/locales/pt-BR.js +1 -0
  79. package/dist/locales/pt-BR.js.map +1 -1
  80. package/dist/locales/pt.d.ts.map +1 -1
  81. package/dist/locales/pt.js +1 -0
  82. package/dist/locales/pt.js.map +1 -1
  83. package/dist/locales/tr.d.ts.map +1 -1
  84. package/dist/locales/tr.js +1 -0
  85. package/dist/locales/tr.js.map +1 -1
  86. package/dist/media.d.ts +24 -0
  87. package/dist/media.d.ts.map +1 -1
  88. package/dist/media.js +15 -0
  89. package/dist/media.js.map +1 -1
  90. package/dist/native/charts.d.ts +3 -3
  91. package/dist/native/controls.d.ts +18 -0
  92. package/dist/native/controls.d.ts.map +1 -1
  93. package/dist/native/controls.js +4 -0
  94. package/dist/native/controls.js.map +1 -1
  95. package/dist/navigation.d.ts.map +1 -1
  96. package/dist/navigation.js +7 -3
  97. package/dist/navigation.js.map +1 -1
  98. package/dist/overlay.d.ts +39 -3
  99. package/dist/overlay.d.ts.map +1 -1
  100. package/dist/overlay.js +17 -8
  101. package/dist/overlay.js.map +1 -1
  102. package/dist/overrides.d.ts +27 -2
  103. package/dist/overrides.d.ts.map +1 -1
  104. package/dist/overrides.js +100 -11
  105. package/dist/overrides.js.map +1 -1
  106. package/dist/selection.d.ts.map +1 -1
  107. package/dist/selection.js +2 -1
  108. package/dist/selection.js.map +1 -1
  109. package/dist/sources/button.css +1 -1
  110. package/dist/sources/card.css +1 -1
  111. package/dist/sources/colorPicker.css +1 -1
  112. package/dist/sources/combobox.css +1 -1
  113. package/dist/sources/dataTable.css +1 -1
  114. package/dist/sources/datePicker.css +1 -1
  115. package/dist/sources/dialog.css +1 -1
  116. package/dist/sources/drawer.css +1 -1
  117. package/dist/sources/iconButton.css +1 -1
  118. package/dist/sources/input.css +1 -1
  119. package/dist/sources/multiSelect.css +1 -1
  120. package/dist/sources/nativeSelect.css +1 -1
  121. package/dist/sources/numberInput.css +1 -1
  122. package/dist/sources/passwordInput.css +1 -1
  123. package/dist/sources/segmentedControl.css +1 -1
  124. package/dist/sources/select.css +1 -1
  125. package/dist/sources/slider.css +1 -1
  126. package/dist/sources/tagsInput.css +1 -1
  127. package/dist/sources/textarea.css +1 -1
  128. package/dist/vite.d.ts +19 -0
  129. package/dist/vite.d.ts.map +1 -0
  130. package/dist/vite.js +161 -0
  131. package/dist/vite.js.map +1 -0
  132. package/dist/widgets.d.ts +3 -3
  133. package/package.json +15 -2
  134. package/src/app.ts +2 -2
  135. package/src/button.ts +8 -8
  136. package/src/card.ts +1 -1
  137. package/src/control-ids.ts +21 -0
  138. package/src/data-table.ts +27 -0
  139. package/src/data.ts +24 -0
  140. package/src/dev.ts +14 -0
  141. package/src/extras.ts +7 -3
  142. package/src/field.ts +10 -10
  143. package/src/i18n.ts +1 -0
  144. package/src/index.ts +11 -2
  145. package/src/inputs.ts +82 -40
  146. package/src/list-items.ts +45 -4
  147. package/src/locales/ar.ts +1 -0
  148. package/src/locales/cs.ts +1 -0
  149. package/src/locales/de.ts +1 -0
  150. package/src/locales/es.ts +1 -0
  151. package/src/locales/fr.ts +1 -0
  152. package/src/locales/hu.ts +1 -0
  153. package/src/locales/it.ts +1 -0
  154. package/src/locales/lv.ts +1 -0
  155. package/src/locales/nl.ts +1 -0
  156. package/src/locales/pl.ts +1 -0
  157. package/src/locales/pt-BR.ts +1 -0
  158. package/src/locales/pt.ts +1 -0
  159. package/src/locales/tr.ts +1 -0
  160. package/src/media.ts +15 -0
  161. package/src/native/controls.ts +4 -0
  162. package/src/navigation.ts +9 -3
  163. package/src/overlay.ts +17 -8
  164. package/src/overrides.ts +130 -15
  165. package/src/selection.ts +2 -1
  166. package/src/vite.ts +162 -0
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
 
@@ -13,6 +15,8 @@ export interface ListItemAccessors<T = unknown> {
13
15
  itemLabel?: ItemAccessor<T, string>;
14
16
  itemDisabled?: ItemAccessor<T, boolean>;
15
17
  itemGroup?: ItemAccessor<T, string | null | undefined>;
18
+ /** More text the search finds an item by, besides its label (e.g. the name of its category) */
19
+ itemKeywords?: ItemAccessor<T, string | readonly string[] | null | undefined>;
16
20
  // The value type is unknown here – any accessor of the component's value type fits
17
21
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
18
22
  valueKey?: ItemAccessor<any, string | number>;
@@ -27,8 +31,12 @@ export interface ListOption<T = unknown> {
27
31
  group?: string;
28
32
  description?: string;
29
33
  icon?: unknown;
34
+ /** More text the search finds the option by (`itemKeywords`, otherwise the item's `keywords`) */
35
+ keywords?: string[];
30
36
  /** The original item (for slots and render functions) */
31
37
  item: T;
38
+ /** A chosen value that is not among the items – shown as its text (see checkListValues) */
39
+ unknown?: boolean;
32
40
  }
33
41
 
34
42
  /** Options under one heading; `label` is undefined for items without a group */
@@ -78,6 +86,7 @@ export function toListOption<T>(item: T, accessors: ListItemAccessors<T> = {}):
78
86
  accessors.itemLabel !== undefined ? read(item, accessors.itemLabel, 'label') : read(item, 'label', '');
79
87
  const group = read(item, accessors.itemGroup, 'group');
80
88
  const description = read(item, undefined, 'description');
89
+ const keywords = read(item, accessors.itemKeywords, 'keywords');
81
90
  return {
82
91
  key: listValueKey(value, accessors.valueKey),
83
92
  value,
@@ -86,6 +95,10 @@ export function toListOption<T>(item: T, accessors: ListItemAccessors<T> = {}):
86
95
  group: group === null || group === undefined || group === '' ? undefined : String(group),
87
96
  description: typeof description === 'string' ? description : undefined,
88
97
  icon: read(item, undefined, 'icon'),
98
+ keywords:
99
+ keywords === null || keywords === undefined || keywords === ''
100
+ ? undefined
101
+ : (Array.isArray(keywords) ? keywords : [keywords]).map(String),
89
102
  item,
90
103
  };
91
104
  }
@@ -119,14 +132,21 @@ export function groupListOptions<T>(options: readonly ListOption<T>[]): ListGrou
119
132
  return groups;
120
133
  }
121
134
 
122
- /** Options whose label contains the query; `contains` decides about case and accents (Ark's useFilter) */
135
+ /**
136
+ * Options whose label or one of their keywords contains the query; `contains` decides about case and accents (Ark's
137
+ * useFilter)
138
+ */
123
139
  export function filterListOptions<T>(
124
140
  options: readonly ListOption<T>[],
125
141
  query: string,
126
142
  contains: (text: string, query: string) => boolean
127
143
  ): ListOption<T>[] {
128
144
  const text = query.trim();
129
- return text ? options.filter((option) => contains(option.label, text)) : [...options];
145
+ return text
146
+ ? options.filter(
147
+ (option) => contains(option.label, text) || !!option.keywords?.some((keyword) => contains(keyword, text))
148
+ )
149
+ : [...options];
130
150
  }
131
151
 
132
152
  /** Looks options up by key; earlier lists win (e.g. the current items before remembered ones) */
@@ -157,12 +177,33 @@ export function listOptionsForValues<T>(
157
177
  label: String(value),
158
178
  disabled: false,
159
179
  item: value as T,
180
+ unknown: true,
160
181
  };
161
182
  });
162
183
  }
163
184
 
164
- /** The value of a single choice as a list: null/undefined → [] */
165
- export const listValues = (value: unknown): unknown[] => (value === null || value === undefined ? [] : [value]);
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
+
201
+ /**
202
+ * The value of a single choice as a list: undefined → [], null → [] – unless one of the options has the value null
203
+ * (e.g. "All"): then null chooses it.
204
+ */
205
+ export const listValues = (value: unknown, options: readonly ListOption[] = []): unknown[] =>
206
+ value === undefined || (value === null && !options.some((option) => option.value === null)) ? [] : [value];
166
207
 
167
208
  /**
168
209
  * "Select all": the selectable options in view (filtered, enabled) are added – or removed when all of them are
package/src/locales/ar.ts CHANGED
@@ -790,6 +790,7 @@ export const ar: Translations = {
790
790
  exportAll: 'كل الصفوف',
791
791
  exportSelection: 'الصفوف المحددة',
792
792
  filterToggle: 'عرض الفلاتر',
793
+ resetFilters: 'إعادة تعيين الفلاتر',
793
794
  rowCount: (count) => plural(count, { ...rows, zero: 'لا توجد صفوف' }),
794
795
  filteredCount: (count) => `${count} بعد التصفية`,
795
796
  copy: (header, value) => `نسخ ${value}، ${header}`,
package/src/locales/cs.ts CHANGED
@@ -645,6 +645,7 @@ export const cs: Translations = {
645
645
  exportAll: 'Všechny řádky',
646
646
  exportSelection: 'Vybrané řádky',
647
647
  filterToggle: 'Zobrazit filtry',
648
+ resetFilters: 'Zrušit filtry',
648
649
  rowCount: (count) => plural(count, { one: '{count} řádek', few: '{count} řádky', other: '{count} řádků' }),
649
650
  filteredCount: (count) =>
650
651
  plural(count, {
package/src/locales/de.ts CHANGED
@@ -589,6 +589,7 @@ export const de = {
589
589
  exportAll: 'Alle Zeilen',
590
590
  exportSelection: 'Ausgewählte Zeilen',
591
591
  filterToggle: 'Filter anzeigen',
592
+ resetFilters: 'Filter zurücksetzen',
592
593
  rowCount: (count: number) => (count === 1 ? '1 Zeile' : `${count} Zeilen`),
593
594
  filteredCount: (count: number) => `${count} gefiltert`,
594
595
  copy: (header: string, value: string) => `${value}, ${header} kopieren`,
package/src/locales/es.ts CHANGED
@@ -570,6 +570,7 @@ export const es: Translations = {
570
570
  exportAll: 'Todas las filas',
571
571
  exportSelection: 'Filas seleccionadas',
572
572
  filterToggle: 'Mostrar filtros',
573
+ resetFilters: 'Restablecer filtros',
573
574
  rowCount: (count) => plural(count, { one: '{count} fila', other: '{count} filas' }),
574
575
  filteredCount: (count) => plural(count, { one: '{count} filtrada', other: '{count} filtradas' }),
575
576
  copy: (header, value) => `Copiar ${value}, ${header}`,
package/src/locales/fr.ts CHANGED
@@ -583,6 +583,7 @@ export const fr: Translations = {
583
583
  exportAll: 'Toutes les lignes',
584
584
  exportSelection: 'Lignes sélectionnées',
585
585
  filterToggle: 'Afficher les filtres',
586
+ resetFilters: 'Réinitialiser les filtres',
586
587
  rowCount: (count) => plural(count, { one: '{count} ligne', other: '{count} lignes' }),
587
588
  filteredCount: (count) => plural(count, { one: '{count} filtrée', other: '{count} filtrées' }),
588
589
  copy: (header, value) => `Copier ${value}, ${header}`,
package/src/locales/hu.ts CHANGED
@@ -605,6 +605,7 @@ export const hu: Translations = {
605
605
  exportAll: 'Összes sor',
606
606
  exportSelection: 'Kiválasztott sorok',
607
607
  filterToggle: 'Szűrők megjelenítése',
608
+ resetFilters: 'Szűrők törlése',
608
609
  rowCount: (count) => rows(count),
609
610
  filteredCount: (count) => plural(count, { one: '{count} szűrve', other: '{count} szűrve' }),
610
611
  copy: (header, value) => `${value}, ${header} másolása`,
package/src/locales/it.ts CHANGED
@@ -596,6 +596,7 @@ export const it: Translations = {
596
596
  exportAll: 'Tutte le righe',
597
597
  exportSelection: 'Righe selezionate',
598
598
  filterToggle: 'Mostra filtri',
599
+ resetFilters: 'Reimposta filtri',
599
600
  rowCount: (count) => plural(count, lines),
600
601
  filteredCount: (count) => plural(count, { one: '{count} filtrato', other: '{count} filtrati' }),
601
602
  copy: (header, value) => `Copia ${value}, ${header}`,
package/src/locales/lv.ts CHANGED
@@ -605,6 +605,7 @@ export const lv: Translations = {
605
605
  exportAll: 'Visas rindas',
606
606
  exportSelection: 'Atlasītās rindas',
607
607
  filterToggle: 'Rādīt filtrus',
608
+ resetFilters: 'Atiestatīt filtrus',
608
609
  rowCount: (count) => plural(count, forms('{count} rinda', '{count} rindas')),
609
610
  filteredCount: (count) => plural(count, forms('{count} filtrēta', '{count} filtrētas')),
610
611
  copy: (header, value) => `Kopēt: ${value}, ${header}`,
package/src/locales/nl.ts CHANGED
@@ -557,6 +557,7 @@ export const nl: Translations = {
557
557
  exportAll: 'Alle rijen',
558
558
  exportSelection: 'Geselecteerde rijen',
559
559
  filterToggle: 'Filters weergeven',
560
+ resetFilters: 'Filters wissen',
560
561
  rowCount: (count) => plural(count, { one: '{count} rij', other: '{count} rijen' }),
561
562
  filteredCount: (count) => `${count} gefilterd`,
562
563
  copy: (header, value) => `${value}, ${header} kopiëren`,
package/src/locales/pl.ts CHANGED
@@ -660,6 +660,7 @@ export const pl: Translations = {
660
660
  exportAll: 'Wszystkie wiersze',
661
661
  exportSelection: 'Zaznaczone wiersze',
662
662
  filterToggle: 'Pokaż filtry',
663
+ resetFilters: 'Wyczyść filtry',
663
664
  rowCount: (count) => rows(count),
664
665
  filteredCount: (count) => `Po filtrowaniu: ${count}`,
665
666
  copy: (header, value) => `Kopiuj: ${value}, ${header}`,
@@ -120,6 +120,7 @@ export const ptBR: Translations = {
120
120
  sortAscending: 'Classificar em ordem crescente',
121
121
  sortDescending: 'Classificar em ordem decrescente',
122
122
  clearSort: 'Remover classificação',
123
+ resetFilters: 'Redefinir filtros',
123
124
  sortPriority: (position, desc) => `nível de classificação ${position}, ${desc ? 'decrescente' : 'crescente'}`,
124
125
  pinEnd: 'Fixar no final',
125
126
  columnMoved: (header, position, count) => `${header} agora é a coluna ${position} de ${count}`,
package/src/locales/pt.ts CHANGED
@@ -576,6 +576,7 @@ export const pt: Translations = {
576
576
  exportAll: 'Todas as linhas',
577
577
  exportSelection: 'Linhas selecionadas',
578
578
  filterToggle: 'Mostrar filtros',
579
+ resetFilters: 'Repor filtros',
579
580
  rowCount: (count) => plural(count, { one: '{count} linha', other: '{count} linhas' }),
580
581
  filteredCount: (count) => plural(count, { one: '{count} filtrada', other: '{count} filtradas' }),
581
582
  copy: (header, value) => `Copiar ${value}, ${header}`,
package/src/locales/tr.ts CHANGED
@@ -554,6 +554,7 @@ export const tr: Translations = {
554
554
  exportAll: 'Tüm satırlar',
555
555
  exportSelection: 'Seçili satırlar',
556
556
  filterToggle: 'Filtreleri göster',
557
+ resetFilters: 'Filtreleri sıfırla',
557
558
  rowCount: (count) => plural(count, { one: '{count} satır', other: '{count} satır' }),
558
559
  filteredCount: (count) => plural(count, { one: '{count} filtrelendi', other: '{count} filtrelendi' }),
559
560
  copy: (header, value) => `Kopyala: ${value}, ${header}`,
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({
@@ -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-10 w-full cursor-pointer items-center justify-between gap-2.5 rounded-lg border border-line-strong bg-bg pe-2.5 ps-3 text-start text-[15px] text-fg',
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: { trigger: 'h-8 rounded-md ps-2.5 pe-2 text-[13px]' },
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: { trigger: 'h-12 rounded-[10px] ps-4 pe-3 text-base' },
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,12 +96,13 @@ 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-black/60',
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',
103
103
  content: [
104
- 'flex w-full max-w-[400px] flex-col rounded-[14px] border border-line-2 bg-card text-fg outline-none',
104
+ // Width from --wc-dialog-w: set by `size`, or your own, e.g. style="--wc-dialog-w: 36rem"
105
+ 'flex w-full max-w-[var(--wc-dialog-w,400px)] flex-col rounded-[14px] border border-line-2 bg-card text-fg outline-none',
105
106
  'shadow-[0_24px_48px_-20px_rgba(0,0,0,.55)]',
106
107
  'motion-safe:data-[state=open]:animate-dialog-in motion-safe:data-[state=closed]:animate-dialog-out',
107
108
  ],
@@ -125,6 +126,10 @@ export const dialog = tv({
125
126
  maximizeIcon: 'size-4',
126
127
  },
127
128
  variants: {
129
+ /** The title only for screen readers – it still names the dialog */
130
+ hideTitle: {
131
+ true: { title: 'sr-only' },
132
+ },
128
133
  status: {
129
134
  neutral: { iconBox: 'bg-line text-fg' },
130
135
  success: { iconBox: 'bg-success/14 text-success' },
@@ -132,12 +137,12 @@ export const dialog = tv({
132
137
  warn: { iconBox: 'bg-warn/14 text-warn' },
133
138
  danger: { iconBox: 'bg-danger/14 text-danger' },
134
139
  },
135
- /** Maximum width; without it 400px (md) */
140
+ /** Maximum width: sm 320px (20rem), md 400px (25rem, default), lg 560px (35rem), xl 800px (50rem) */
136
141
  size: {
137
- sm: { content: 'max-w-[320px]' },
138
- md: { content: 'max-w-[400px]' },
139
- lg: { content: 'max-w-[560px]' },
140
- xl: { content: 'max-w-[800px]' },
142
+ sm: { content: '[--wc-dialog-w:320px]' },
143
+ md: { content: '[--wc-dialog-w:400px]' },
144
+ lg: { content: '[--wc-dialog-w:560px]' },
145
+ xl: { content: '[--wc-dialog-w:800px]' },
141
146
  full: { content: 'max-w-none' },
142
147
  },
143
148
  /** Where the dialog sits on the screen; without it centred */
@@ -188,7 +193,7 @@ const drawerSizes: OverlaySize[] = ['sm', 'md', 'lg', 'xl', 'full'];
188
193
  export const drawer = tv({
189
194
  slots: {
190
195
  backdrop: [
191
- 'fixed inset-0 z-50 bg-black/60',
196
+ 'fixed inset-0 z-50 bg-[var(--wc-backdrop,rgb(0_0_0/0.6))]',
192
197
  'motion-safe:data-[state=open]:animate-fade-in motion-safe:data-[state=closed]:animate-fade-out',
193
198
  ],
194
199
  positioner: 'fixed inset-0 z-50 flex',
@@ -209,6 +214,10 @@ export const drawer = tv({
209
214
  footer: 'flex flex-wrap justify-end gap-2 border-t border-line px-5 py-3',
210
215
  },
211
216
  variants: {
217
+ /** The title only for screen readers – it still names the drawer */
218
+ hideTitle: {
219
+ true: { title: 'sr-only' },
220
+ },
212
221
  placement: {
213
222
  right: {
214
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
- /** Inner overrides win: defaults per variant, classes per part are joined (later ones win in tailwind-merge) */
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), classes are added to their part before the class the component passes for it.
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 classes = active.reduce<Record<string, ClassValue> | undefined>(
71
- (all, override) => joinClasses(all, override.classes as Record<string, ClassValue> | undefined),
72
- undefined
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 = Object.fromEntries(Object.entries(props).filter(([, value]) => value !== undefined));
183
+ const given = defined(props);
76
184
  const variants = { ...defaults, ...given };
77
- if (!classes) return recipe(variants);
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') return recipe({ ...variants, class: [classes.base, given.class] });
81
- // Slot recipes: every part gets its classes before the class passed for it
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
- classes[slot]
87
- ? (slotProps: Record<string, unknown> = {}) =>
88
- part({ ...slotProps, class: [classes[slot], slotProps.class] })
89
- : part,
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
  );
package/src/selection.ts CHANGED
@@ -110,7 +110,8 @@ export type SegmentedControlSize = 'sm' | 'md';
110
110
 
111
111
  export const segmentedControl = tv({
112
112
  slots: {
113
- base: 'inline-flex items-center gap-0.5 rounded-full border border-line-2 p-[3px]',
113
+ // As wide as its segments – also as a flex item of a column (inside a Field)
114
+ base: 'inline-flex w-fit items-center gap-0.5 rounded-full border border-line-2 p-[3px]',
114
115
  label: 'sr-only',
115
116
  item: [
116
117
  'inline-flex cursor-pointer items-center gap-1.5 rounded-full whitespace-nowrap text-muted',