@webiny/admin-ui 6.5.0 → 6.5.1-beta.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 (30) hide show
  1. package/DatePicker/DatePicker.stories.d.ts +10 -0
  2. package/DatePicker/DatePicker.stories.js +44 -1
  3. package/DatePicker/DatePicker.stories.js.map +1 -1
  4. package/DatePicker/primitives/BirthdayPicker.d.ts +13 -0
  5. package/DatePicker/primitives/BirthdayPicker.js +355 -0
  6. package/DatePicker/primitives/BirthdayPicker.js.map +1 -0
  7. package/DatePicker/primitives/BirthdayPickerCell.d.ts +14 -0
  8. package/DatePicker/primitives/BirthdayPickerCell.js +19 -0
  9. package/DatePicker/primitives/BirthdayPickerCell.js.map +1 -0
  10. package/DatePicker/primitives/BirthdayPickerSegments.d.ts +9 -0
  11. package/DatePicker/primitives/BirthdayPickerSegments.js +43 -0
  12. package/DatePicker/primitives/BirthdayPickerSegments.js.map +1 -0
  13. package/DatePicker/primitives/DatePickerPrimitive.js +3 -0
  14. package/DatePicker/primitives/DatePickerPrimitive.js.map +1 -1
  15. package/DatePicker/utils/birthdayHelpers.d.ts +77 -0
  16. package/DatePicker/utils/birthdayHelpers.js +145 -0
  17. package/DatePicker/utils/birthdayHelpers.js.map +1 -0
  18. package/DatePicker/utils/birthdayHelpers.test.d.ts +1 -0
  19. package/DatePicker/utils/birthdayHelpers.test.js +394 -0
  20. package/DatePicker/utils/birthdayHelpers.test.js.map +1 -0
  21. package/DatePicker/utils/index.d.ts +1 -0
  22. package/DatePicker/utils/index.js +1 -0
  23. package/DatePicker/utils/types.d.ts +13 -2
  24. package/Switch/Switch.d.ts +4 -4
  25. package/Switch/Switch.js +21 -7
  26. package/Switch/Switch.js.map +1 -1
  27. package/Switch/domains/SwitchItemDto.d.ts +1 -1
  28. package/Switch/primitives/SwitchPrimitive.js +4 -3
  29. package/Switch/primitives/SwitchPrimitive.js.map +1 -1
  30. package/package.json +6 -6
@@ -0,0 +1,394 @@
1
+ import { describe, expect, it } from "vitest";
2
+ import { birthdayYears, daysInMonth, formatBirthdayValue, isDayDisabled, isMonthDisabled, isYearDisabled, nextBirthdayStep, parseBirthdayValue, pickDay, pickMonth, pickYear } from "./birthdayHelpers.js";
3
+ describe("birthdayHelpers", ()=>{
4
+ it("should read the parts of a date-only value", ()=>{
5
+ expect(parseBirthdayValue("1990-02-09")).toEqual({
6
+ day: 9,
7
+ month: 2,
8
+ year: 1990
9
+ });
10
+ });
11
+ it("should read the date part of a value that carries a time", ()=>{
12
+ expect(parseBirthdayValue("1990-02-09T00:00:00.000Z")).toEqual({
13
+ day: 9,
14
+ month: 2,
15
+ year: 1990
16
+ });
17
+ });
18
+ it("should read no parts from an empty or impossible value", ()=>{
19
+ expect(parseBirthdayValue(void 0)).toEqual({});
20
+ expect(parseBirthdayValue("")).toEqual({});
21
+ expect(parseBirthdayValue("not a date")).toEqual({});
22
+ expect(parseBirthdayValue("1990-02-30")).toEqual({});
23
+ });
24
+ it("should write a value only once every part is set", ()=>{
25
+ expect(formatBirthdayValue({
26
+ day: 9,
27
+ month: 2,
28
+ year: 1990
29
+ })).toBe("1990-02-09");
30
+ expect(formatBirthdayValue({
31
+ day: 9,
32
+ month: 2
33
+ })).toBeUndefined();
34
+ });
35
+ it("should give February 29 days until a non-leap year is known", ()=>{
36
+ expect(daysInMonth(2)).toBe(29);
37
+ expect(daysInMonth(2, 2000)).toBe(29);
38
+ expect(daysInMonth(2, 1900)).toBe(28);
39
+ expect(daysInMonth(2, 1990)).toBe(28);
40
+ });
41
+ it("should dim the months that can't hold the 31st", ()=>{
42
+ const dimmed = Array.from({
43
+ length: 12
44
+ }, (_, i)=>i + 1).filter((month)=>isMonthDisabled(month, {
45
+ day: 31
46
+ }));
47
+ expect(dimmed).toEqual([
48
+ 2,
49
+ 4,
50
+ 6,
51
+ 9,
52
+ 11
53
+ ]);
54
+ });
55
+ it("should dim no month before a day is picked", ()=>{
56
+ expect(isMonthDisabled(2, {})).toBe(false);
57
+ });
58
+ it("should clear a month that can't hold the newly picked day and keep the year", ()=>{
59
+ expect(pickDay({
60
+ day: 9,
61
+ month: 2,
62
+ year: 1990
63
+ }, 31)).toEqual({
64
+ day: 31,
65
+ month: void 0,
66
+ year: 1990
67
+ });
68
+ });
69
+ it("should keep a month that holds the newly picked day", ()=>{
70
+ expect(pickDay({
71
+ day: 9,
72
+ month: 8,
73
+ year: 1990
74
+ }, 31)).toEqual({
75
+ day: 31,
76
+ month: 8,
77
+ year: 1990
78
+ });
79
+ });
80
+ it("should clear a non-leap year when 29 February is picked", ()=>{
81
+ expect(pickDay({
82
+ day: 9,
83
+ month: 2,
84
+ year: 1990
85
+ }, 29)).toEqual({
86
+ day: 29,
87
+ month: 2,
88
+ year: void 0
89
+ });
90
+ expect(pickMonth({
91
+ day: 29,
92
+ month: 1,
93
+ year: 1990
94
+ }, 2)).toEqual({
95
+ day: 29,
96
+ month: 2,
97
+ year: void 0
98
+ });
99
+ expect(pickMonth({
100
+ day: 29,
101
+ month: 1,
102
+ year: 1992
103
+ }, 2)).toEqual({
104
+ day: 29,
105
+ month: 2,
106
+ year: 1992
107
+ });
108
+ });
109
+ it("should dim non-leap years for 29 February only", ()=>{
110
+ expect(isYearDisabled(1990, {
111
+ day: 29,
112
+ month: 2
113
+ })).toBe(true);
114
+ expect(isYearDisabled(1992, {
115
+ day: 29,
116
+ month: 2
117
+ })).toBe(false);
118
+ expect(isYearDisabled(1990, {
119
+ day: 28,
120
+ month: 2
121
+ })).toBe(false);
122
+ expect(isYearDisabled(1990, {
123
+ day: 29
124
+ })).toBe(false);
125
+ });
126
+ it("should set the year", ()=>{
127
+ expect(pickYear({
128
+ day: 31,
129
+ month: 8
130
+ }, 1990)).toEqual({
131
+ day: 31,
132
+ month: 8,
133
+ year: 1990
134
+ });
135
+ });
136
+ it("should list years newest first", ()=>{
137
+ expect(birthdayYears([
138
+ 1985,
139
+ 1990
140
+ ])).toEqual([
141
+ 1990,
142
+ 1989,
143
+ 1988,
144
+ 1987,
145
+ 1986,
146
+ 1985
147
+ ]);
148
+ expect(birthdayYears([
149
+ 1990,
150
+ 1985
151
+ ])).toEqual([
152
+ 1990,
153
+ 1989,
154
+ 1988,
155
+ 1987,
156
+ 1986,
157
+ 1985
158
+ ]);
159
+ });
160
+ it("should default to this year back 120 years", ()=>{
161
+ const currentYear = new Date().getFullYear();
162
+ const years = birthdayYears();
163
+ expect(years[0]).toBe(currentYear);
164
+ expect(years[years.length - 1]).toBe(currentYear - 120);
165
+ });
166
+ it("should include a set year that falls outside the range", ()=>{
167
+ expect(birthdayYears([
168
+ 1985,
169
+ 1987
170
+ ], 1980)).toEqual([
171
+ 1987,
172
+ 1986,
173
+ 1985,
174
+ 1984,
175
+ 1983,
176
+ 1982,
177
+ 1981,
178
+ 1980
179
+ ]);
180
+ });
181
+ describe("within minDate and maxDate", ()=>{
182
+ const range = {
183
+ years: birthdayYears([
184
+ 2000,
185
+ 2026
186
+ ]),
187
+ minDate: new Date(2000, 2, 10),
188
+ maxDate: new Date(2026, 9, 15)
189
+ };
190
+ it("should dim the years outside the limits", ()=>{
191
+ const wide = {
192
+ ...range,
193
+ years: birthdayYears([
194
+ 1995,
195
+ 2030
196
+ ])
197
+ };
198
+ expect(isYearDisabled(1999, {}, wide)).toBe(true);
199
+ expect(isYearDisabled(2000, {}, wide)).toBe(false);
200
+ expect(isYearDisabled(2026, {}, wide)).toBe(false);
201
+ expect(isYearDisabled(2027, {}, wide)).toBe(true);
202
+ });
203
+ it("should dim the last year when the picked day and month fall after maxDate", ()=>{
204
+ expect(isYearDisabled(2026, {
205
+ day: 16,
206
+ month: 10
207
+ }, range)).toBe(true);
208
+ expect(isYearDisabled(2026, {
209
+ day: 15,
210
+ month: 10
211
+ }, range)).toBe(false);
212
+ expect(isYearDisabled(2026, {
213
+ day: 1,
214
+ month: 11
215
+ }, range)).toBe(true);
216
+ expect(isYearDisabled(2025, {
217
+ day: 1,
218
+ month: 11
219
+ }, range)).toBe(false);
220
+ });
221
+ it("should dim the first year when the picked day and month fall before minDate", ()=>{
222
+ expect(isYearDisabled(2000, {
223
+ day: 9,
224
+ month: 3
225
+ }, range)).toBe(true);
226
+ expect(isYearDisabled(2000, {
227
+ day: 10,
228
+ month: 3
229
+ }, range)).toBe(false);
230
+ });
231
+ it("should dim the months and days that no date in range has", ()=>{
232
+ const oneYear = {
233
+ ...range,
234
+ years: [
235
+ 2026
236
+ ]
237
+ };
238
+ expect(isMonthDisabled(10, {}, oneYear)).toBe(false);
239
+ expect(isMonthDisabled(11, {}, oneYear)).toBe(true);
240
+ expect(isMonthDisabled(10, {
241
+ day: 16
242
+ }, oneYear)).toBe(true);
243
+ const oneMonth = {
244
+ years: [
245
+ 2026
246
+ ],
247
+ minDate: new Date(2026, 9, 1),
248
+ maxDate: new Date(2026, 9, 15)
249
+ };
250
+ expect(isDayDisabled(15, oneMonth)).toBe(false);
251
+ expect(isDayDisabled(16, oneMonth)).toBe(true);
252
+ expect(isDayDisabled(16, range)).toBe(false);
253
+ });
254
+ it("should keep 29 February when the range offers a leap year", ()=>{
255
+ expect(isMonthDisabled(2, {
256
+ day: 29
257
+ }, range)).toBe(false);
258
+ expect(isMonthDisabled(2, {
259
+ day: 29
260
+ }, {
261
+ ...range,
262
+ years: [
263
+ 2025
264
+ ]
265
+ })).toBe(true);
266
+ });
267
+ it("should clear a year the newly picked part puts past a limit", ()=>{
268
+ expect(pickDay({
269
+ day: 1,
270
+ month: 10,
271
+ year: 2026
272
+ }, 20, range)).toEqual({
273
+ day: 20,
274
+ month: 10,
275
+ year: void 0
276
+ });
277
+ expect(pickMonth({
278
+ day: 1,
279
+ month: 10,
280
+ year: 2026
281
+ }, 12, range)).toEqual({
282
+ day: 1,
283
+ month: 12,
284
+ year: void 0
285
+ });
286
+ expect(pickDay({
287
+ day: 1,
288
+ month: 10,
289
+ year: 2026
290
+ }, 15, range)).toEqual({
291
+ day: 15,
292
+ month: 10,
293
+ year: 2026
294
+ });
295
+ });
296
+ it("should end the default years at maxDate and start them at minDate", ()=>{
297
+ const years = birthdayYears(void 0, void 0, {
298
+ maxDate: new Date(2000, 0, 1)
299
+ });
300
+ expect(years[0]).toBe(2000);
301
+ expect(years[years.length - 1]).toBe(1880);
302
+ expect(birthdayYears(void 0, void 0, {
303
+ minDate: new Date(1990, 0, 1),
304
+ maxDate: new Date(1995, 0, 1)
305
+ })).toEqual([
306
+ 1995,
307
+ 1994,
308
+ 1993,
309
+ 1992,
310
+ 1991,
311
+ 1990
312
+ ]);
313
+ });
314
+ it("should start the default years at a maxDate in the future", ()=>{
315
+ const currentYear = new Date().getFullYear();
316
+ const years = birthdayYears(void 0, void 0, {
317
+ maxDate: new Date(currentYear + 2, 0, 1)
318
+ });
319
+ expect(years[0]).toBe(currentYear + 2);
320
+ expect(years[years.length - 1]).toBe(currentYear + 2 - 120);
321
+ });
322
+ it("should run the default years from this year down to an old minDate", ()=>{
323
+ const currentYear = new Date().getFullYear();
324
+ const years = birthdayYears(void 0, void 0, {
325
+ minDate: new Date(1850, 0, 1)
326
+ });
327
+ expect(years[0]).toBe(currentYear);
328
+ expect(years[years.length - 1]).toBe(1850);
329
+ });
330
+ it("should start the default years at a minDate in the future", ()=>{
331
+ const currentYear = new Date().getFullYear();
332
+ const years = birthdayYears(void 0, void 0, {
333
+ minDate: new Date(currentYear + 3, 0, 1)
334
+ });
335
+ expect(years).toEqual([
336
+ currentYear + 3
337
+ ]);
338
+ });
339
+ it("should ignore an invalid limit", ()=>{
340
+ expect(isYearDisabled(2026, {}, {
341
+ years: [
342
+ 2026
343
+ ],
344
+ maxDate: new Date("nope")
345
+ })).toBe(false);
346
+ });
347
+ });
348
+ it("should go to the next missing part after a pick", ()=>{
349
+ expect(nextBirthdayStep({
350
+ day: 9
351
+ }, "day", new Set([
352
+ "day"
353
+ ]))).toBe("month");
354
+ expect(nextBirthdayStep({
355
+ month: 2,
356
+ year: 1990
357
+ }, "year", new Set([
358
+ "year"
359
+ ]))).toBe("day");
360
+ });
361
+ it("should close once a pick out of order completes the date", ()=>{
362
+ const picked = new Set([
363
+ "year",
364
+ "day",
365
+ "month"
366
+ ]);
367
+ expect(nextBirthdayStep({
368
+ day: 9,
369
+ month: 2,
370
+ year: 1990
371
+ }, "month", picked)).toBe(void 0);
372
+ });
373
+ it("should walk on through the later steps when editing a saved date", ()=>{
374
+ const date = {
375
+ day: 9,
376
+ month: 2,
377
+ year: 1990
378
+ };
379
+ expect(nextBirthdayStep(date, "day", new Set([
380
+ "day"
381
+ ]))).toBe("month");
382
+ expect(nextBirthdayStep(date, "month", new Set([
383
+ "day",
384
+ "month"
385
+ ]))).toBe("year");
386
+ expect(nextBirthdayStep(date, "year", new Set([
387
+ "day",
388
+ "month",
389
+ "year"
390
+ ]))).toBe(void 0);
391
+ });
392
+ });
393
+
394
+ //# sourceMappingURL=birthdayHelpers.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"DatePicker/utils/birthdayHelpers.test.js","sources":["../../../src/DatePicker/utils/birthdayHelpers.test.ts"],"sourcesContent":["import { describe, expect, it } from \"vitest\";\nimport {\n birthdayYears,\n daysInMonth,\n formatBirthdayValue,\n isDayDisabled,\n isMonthDisabled,\n isYearDisabled,\n nextBirthdayStep,\n parseBirthdayValue,\n pickDay,\n pickMonth,\n pickYear\n} from \"./birthdayHelpers.js\";\n\ndescribe(\"birthdayHelpers\", () => {\n it(\"should read the parts of a date-only value\", () => {\n expect(parseBirthdayValue(\"1990-02-09\")).toEqual({ day: 9, month: 2, year: 1990 });\n });\n\n it(\"should read the date part of a value that carries a time\", () => {\n expect(parseBirthdayValue(\"1990-02-09T00:00:00.000Z\")).toEqual({\n day: 9,\n month: 2,\n year: 1990\n });\n });\n\n it(\"should read no parts from an empty or impossible value\", () => {\n expect(parseBirthdayValue(undefined)).toEqual({});\n expect(parseBirthdayValue(\"\")).toEqual({});\n expect(parseBirthdayValue(\"not a date\")).toEqual({});\n expect(parseBirthdayValue(\"1990-02-30\")).toEqual({});\n });\n\n it(\"should write a value only once every part is set\", () => {\n expect(formatBirthdayValue({ day: 9, month: 2, year: 1990 })).toBe(\"1990-02-09\");\n expect(formatBirthdayValue({ day: 9, month: 2 })).toBeUndefined();\n });\n\n it(\"should give February 29 days until a non-leap year is known\", () => {\n expect(daysInMonth(2)).toBe(29);\n expect(daysInMonth(2, 2000)).toBe(29);\n expect(daysInMonth(2, 1900)).toBe(28);\n expect(daysInMonth(2, 1990)).toBe(28);\n });\n\n it(\"should dim the months that can't hold the 31st\", () => {\n const dimmed = Array.from({ length: 12 }, (_, i) => i + 1).filter(month =>\n isMonthDisabled(month, { day: 31 })\n );\n expect(dimmed).toEqual([2, 4, 6, 9, 11]);\n });\n\n it(\"should dim no month before a day is picked\", () => {\n expect(isMonthDisabled(2, {})).toBe(false);\n });\n\n it(\"should clear a month that can't hold the newly picked day and keep the year\", () => {\n expect(pickDay({ day: 9, month: 2, year: 1990 }, 31)).toEqual({\n day: 31,\n month: undefined,\n year: 1990\n });\n });\n\n it(\"should keep a month that holds the newly picked day\", () => {\n expect(pickDay({ day: 9, month: 8, year: 1990 }, 31)).toEqual({\n day: 31,\n month: 8,\n year: 1990\n });\n });\n\n it(\"should clear a non-leap year when 29 February is picked\", () => {\n expect(pickDay({ day: 9, month: 2, year: 1990 }, 29)).toEqual({\n day: 29,\n month: 2,\n year: undefined\n });\n expect(pickMonth({ day: 29, month: 1, year: 1990 }, 2)).toEqual({\n day: 29,\n month: 2,\n year: undefined\n });\n expect(pickMonth({ day: 29, month: 1, year: 1992 }, 2)).toEqual({\n day: 29,\n month: 2,\n year: 1992\n });\n });\n\n it(\"should dim non-leap years for 29 February only\", () => {\n expect(isYearDisabled(1990, { day: 29, month: 2 })).toBe(true);\n expect(isYearDisabled(1992, { day: 29, month: 2 })).toBe(false);\n expect(isYearDisabled(1990, { day: 28, month: 2 })).toBe(false);\n expect(isYearDisabled(1990, { day: 29 })).toBe(false);\n });\n\n it(\"should set the year\", () => {\n expect(pickYear({ day: 31, month: 8 }, 1990)).toEqual({ day: 31, month: 8, year: 1990 });\n });\n\n it(\"should list years newest first\", () => {\n expect(birthdayYears([1985, 1990])).toEqual([1990, 1989, 1988, 1987, 1986, 1985]);\n expect(birthdayYears([1990, 1985])).toEqual([1990, 1989, 1988, 1987, 1986, 1985]);\n });\n\n it(\"should default to this year back 120 years\", () => {\n const currentYear = new Date().getFullYear();\n const years = birthdayYears();\n expect(years[0]).toBe(currentYear);\n expect(years[years.length - 1]).toBe(currentYear - 120);\n });\n\n it(\"should include a set year that falls outside the range\", () => {\n expect(birthdayYears([1985, 1987], 1980)).toEqual([\n 1987, 1986, 1985, 1984, 1983, 1982, 1981, 1980\n ]);\n });\n\n describe(\"within minDate and maxDate\", () => {\n const range = {\n years: birthdayYears([2000, 2026]),\n minDate: new Date(2000, 2, 10),\n maxDate: new Date(2026, 9, 15)\n };\n\n it(\"should dim the years outside the limits\", () => {\n const wide = { ...range, years: birthdayYears([1995, 2030]) };\n expect(isYearDisabled(1999, {}, wide)).toBe(true);\n expect(isYearDisabled(2000, {}, wide)).toBe(false);\n expect(isYearDisabled(2026, {}, wide)).toBe(false);\n expect(isYearDisabled(2027, {}, wide)).toBe(true);\n });\n\n it(\"should dim the last year when the picked day and month fall after maxDate\", () => {\n expect(isYearDisabled(2026, { day: 16, month: 10 }, range)).toBe(true);\n expect(isYearDisabled(2026, { day: 15, month: 10 }, range)).toBe(false);\n expect(isYearDisabled(2026, { day: 1, month: 11 }, range)).toBe(true);\n expect(isYearDisabled(2025, { day: 1, month: 11 }, range)).toBe(false);\n });\n\n it(\"should dim the first year when the picked day and month fall before minDate\", () => {\n expect(isYearDisabled(2000, { day: 9, month: 3 }, range)).toBe(true);\n expect(isYearDisabled(2000, { day: 10, month: 3 }, range)).toBe(false);\n });\n\n it(\"should dim the months and days that no date in range has\", () => {\n const oneYear = { ...range, years: [2026] };\n expect(isMonthDisabled(10, {}, oneYear)).toBe(false);\n expect(isMonthDisabled(11, {}, oneYear)).toBe(true);\n expect(isMonthDisabled(10, { day: 16 }, oneYear)).toBe(true);\n\n const oneMonth = {\n years: [2026],\n minDate: new Date(2026, 9, 1),\n maxDate: new Date(2026, 9, 15)\n };\n expect(isDayDisabled(15, oneMonth)).toBe(false);\n expect(isDayDisabled(16, oneMonth)).toBe(true);\n expect(isDayDisabled(16, range)).toBe(false);\n });\n\n it(\"should keep 29 February when the range offers a leap year\", () => {\n expect(isMonthDisabled(2, { day: 29 }, range)).toBe(false);\n expect(isMonthDisabled(2, { day: 29 }, { ...range, years: [2025] })).toBe(true);\n });\n\n it(\"should clear a year the newly picked part puts past a limit\", () => {\n expect(pickDay({ day: 1, month: 10, year: 2026 }, 20, range)).toEqual({\n day: 20,\n month: 10,\n year: undefined\n });\n expect(pickMonth({ day: 1, month: 10, year: 2026 }, 12, range)).toEqual({\n day: 1,\n month: 12,\n year: undefined\n });\n expect(pickDay({ day: 1, month: 10, year: 2026 }, 15, range)).toEqual({\n day: 15,\n month: 10,\n year: 2026\n });\n });\n\n it(\"should end the default years at maxDate and start them at minDate\", () => {\n const years = birthdayYears(undefined, undefined, { maxDate: new Date(2000, 0, 1) });\n expect(years[0]).toBe(2000);\n expect(years[years.length - 1]).toBe(1880);\n expect(\n birthdayYears(undefined, undefined, {\n minDate: new Date(1990, 0, 1),\n maxDate: new Date(1995, 0, 1)\n })\n ).toEqual([1995, 1994, 1993, 1992, 1991, 1990]);\n });\n\n it(\"should start the default years at a maxDate in the future\", () => {\n const currentYear = new Date().getFullYear();\n const years = birthdayYears(undefined, undefined, {\n maxDate: new Date(currentYear + 2, 0, 1)\n });\n expect(years[0]).toBe(currentYear + 2);\n expect(years[years.length - 1]).toBe(currentYear + 2 - 120);\n });\n\n it(\"should run the default years from this year down to an old minDate\", () => {\n const currentYear = new Date().getFullYear();\n const years = birthdayYears(undefined, undefined, { minDate: new Date(1850, 0, 1) });\n expect(years[0]).toBe(currentYear);\n expect(years[years.length - 1]).toBe(1850);\n });\n\n it(\"should start the default years at a minDate in the future\", () => {\n const currentYear = new Date().getFullYear();\n const years = birthdayYears(undefined, undefined, {\n minDate: new Date(currentYear + 3, 0, 1)\n });\n expect(years).toEqual([currentYear + 3]);\n });\n\n it(\"should ignore an invalid limit\", () => {\n expect(isYearDisabled(2026, {}, { years: [2026], maxDate: new Date(\"nope\") })).toBe(\n false\n );\n });\n });\n\n it(\"should go to the next missing part after a pick\", () => {\n expect(nextBirthdayStep({ day: 9 }, \"day\", new Set([\"day\"]))).toBe(\"month\");\n expect(nextBirthdayStep({ month: 2, year: 1990 }, \"year\", new Set([\"year\"]))).toBe(\"day\");\n });\n\n it(\"should close once a pick out of order completes the date\", () => {\n const picked = new Set([\"year\", \"day\", \"month\"] as const);\n expect(nextBirthdayStep({ day: 9, month: 2, year: 1990 }, \"month\", picked)).toBe(undefined);\n });\n\n it(\"should walk on through the later steps when editing a saved date\", () => {\n const date = { day: 9, month: 2, year: 1990 };\n expect(nextBirthdayStep(date, \"day\", new Set([\"day\"]))).toBe(\"month\");\n expect(nextBirthdayStep(date, \"month\", new Set([\"day\", \"month\"]))).toBe(\"year\");\n expect(nextBirthdayStep(date, \"year\", new Set([\"day\", \"month\", \"year\"]))).toBe(undefined);\n });\n});\n"],"names":["describe","it","expect","parseBirthdayValue","undefined","formatBirthdayValue","daysInMonth","dimmed","Array","_","i","month","isMonthDisabled","pickDay","pickMonth","isYearDisabled","pickYear","birthdayYears","currentYear","Date","years","range","wide","oneYear","oneMonth","isDayDisabled","nextBirthdayStep","Set","picked","date"],"mappings":";;AAeAA,SAAS,mBAAmB;IACxBC,GAAG,8CAA8C;QAC7CC,OAAOC,mBAAmB,eAAe,OAAO,CAAC;YAAE,KAAK;YAAG,OAAO;YAAG,MAAM;QAAK;IACpF;IAEAF,GAAG,4DAA4D;QAC3DC,OAAOC,mBAAmB,6BAA6B,OAAO,CAAC;YAC3D,KAAK;YACL,OAAO;YACP,MAAM;QACV;IACJ;IAEAF,GAAG,0DAA0D;QACzDC,OAAOC,mBAAmBC,SAAY,OAAO,CAAC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KAAKD,cAAc,GAAG,GAAG;YAC1C;YACAhB,OAAOkB,OAAO,OAAO,CAAC;gBAACF,cAAc;aAAE;QAC3C;QAEAjB,GAAG,kCAAkC;YACjCC,OAAOa,eAAe,MAAM,CAAC,GAAG;gBAAE,OAAO;oBAAC;iBAAK;gBAAE,SAAS,IAAII,KAAK;YAAQ,IAAI,IAAI,CAC/E;QAER;IACJ;IAEAlB,GAAG,mDAAmD;QAClDC,OAAOwB,iBAAiB;YAAE,KAAK;QAAE,GAAG,OAAO,IAAIC,IAAI;YAAC;SAAM,IAAI,IAAI,CAAC;QACnEzB,OAAOwB,iBAAiB;YAAE,OAAO;YAAG,MAAM;QAAK,GAAG,QAAQ,IAAIC,IAAI;YAAC;SAAO,IAAI,IAAI,CAAC;IACvF;IAEA1B,GAAG,4DAA4D;QAC3D,MAAM2B,SAAS,IAAID,IAAI;YAAC;YAAQ;YAAO;SAAQ;QAC/CzB,OAAOwB,iBAAiB;YAAE,KAAK;YAAG,OAAO;YAAG,MAAM;QAAK,GAAG,SAASE,SAAS,IAAI,CAACxB;IACrF;IAEAH,GAAG,oEAAoE;QACnE,MAAM4B,OAAO;YAAE,KAAK;YAAG,OAAO;YAAG,MAAM;QAAK;QAC5C3B,OAAOwB,iBAAiBG,MAAM,OAAO,IAAIF,IAAI;YAAC;SAAM,IAAI,IAAI,CAAC;QAC7DzB,OAAOwB,iBAAiBG,MAAM,SAAS,IAAIF,IAAI;YAAC;YAAO;SAAQ,IAAI,IAAI,CAAC;QACxEzB,OAAOwB,iBAAiBG,MAAM,QAAQ,IAAIF,IAAI;YAAC;YAAO;YAAS;SAAO,IAAI,IAAI,CAACvB;IACnF;AACJ"}
@@ -1,3 +1,4 @@
1
1
  export * from "./types.js";
2
2
  export * from "./dateHelpers.js";
3
3
  export * from "./constants.js";
4
+ export * from "./birthdayHelpers.js";
@@ -1,3 +1,4 @@
1
1
  export * from "./types.js";
2
2
  export * from "./dateHelpers.js";
3
3
  export * from "./constants.js";
4
+ export * from "./birthdayHelpers.js";
@@ -23,6 +23,17 @@ interface DateOnlyPickerProps extends DatePickerBaseProps {
23
23
  onChange?: (value: string | undefined) => void;
24
24
  presets?: DatePickerPreset[];
25
25
  }
26
+ /**
27
+ * Picks a date as day, then month, then year. The value is a `YYYY-MM-DD` string, the same as
28
+ * the `date` picker's. `yearRange` sets the years offered. By default they run from `maxDate`'s
29
+ * year (or this year) down to `minDate`'s year (or 120 years back). Days, months and years that
30
+ * can't make a date between `minDate` and `maxDate` can't be picked.
31
+ */
32
+ interface BirthdayPickerProps extends DatePickerBaseProps {
33
+ type: "birthday";
34
+ value?: string;
35
+ onChange?: (value: string | undefined) => void;
36
+ }
26
37
  interface TimeOnlyPickerProps extends DatePickerBaseProps {
27
38
  type: "time";
28
39
  value?: string;
@@ -79,5 +90,5 @@ interface MultipleYearsPickerProps extends DatePickerBaseProps {
79
90
  value?: number[];
80
91
  onChange?: (value: number[]) => void;
81
92
  }
82
- type DatePickerPrimitiveProps = DateOnlyPickerProps | TimeOnlyPickerProps | DateTimeLocalPickerProps | DateTimeTzPickerProps | MonthPickerProps | WeekPickerProps | YearPickerProps | DateRangePickerProps | MultipleDatesPickerProps | MultipleMonthsPickerProps | MultipleYearsPickerProps;
83
- export { type DatePickerPreset, type DatePickerBaseProps, type DatePickerPrimitiveProps, type DateOnlyPickerProps, type TimeOnlyPickerProps, type DateTimeLocalPickerProps, type DateTimeTzPickerProps, type MonthPickerProps, type WeekPickerProps, type YearPickerProps, type DateRangePickerProps, type MultipleDatesPickerProps, type MultipleMonthsPickerProps, type MultipleYearsPickerProps };
93
+ type DatePickerPrimitiveProps = DateOnlyPickerProps | BirthdayPickerProps | TimeOnlyPickerProps | DateTimeLocalPickerProps | DateTimeTzPickerProps | MonthPickerProps | WeekPickerProps | YearPickerProps | DateRangePickerProps | MultipleDatesPickerProps | MultipleMonthsPickerProps | MultipleYearsPickerProps;
94
+ export { type DatePickerPreset, type DatePickerBaseProps, type DatePickerPrimitiveProps, type DateOnlyPickerProps, type BirthdayPickerProps, type TimeOnlyPickerProps, type DateTimeLocalPickerProps, type DateTimeTzPickerProps, type MonthPickerProps, type WeekPickerProps, type YearPickerProps, type DateRangePickerProps, type MultipleDatesPickerProps, type MultipleMonthsPickerProps, type MultipleYearsPickerProps };
@@ -1,8 +1,8 @@
1
1
  import React from "react";
2
2
  import type { SwitchPrimitiveProps } from "./primitives/index.js";
3
- import type { FormComponentProps } from "../FormComponent/index.js";
4
- type SwitchProps = SwitchPrimitiveProps & FormComponentProps;
5
- declare const DecoratableSwitch: ({ note, validation, ...props }: SwitchProps) => React.JSX.Element;
3
+ import { type FormComponentProps } from "../FormComponent/index.js";
4
+ type SwitchProps = Omit<SwitchPrimitiveProps, "label"> & FormComponentProps;
5
+ declare const DecoratableSwitch: ({ label, description, hint, note, required, disabled, validation, ...props }: SwitchProps) => React.JSX.Element;
6
6
  declare const Switch: typeof DecoratableSwitch & {
7
7
  original: typeof DecoratableSwitch;
8
8
  originalName: string;
@@ -22,4 +22,4 @@ declare const Switch: typeof DecoratableSwitch & {
22
22
  displayName: string;
23
23
  }>) => (props: unknown) => React.JSX.Element;
24
24
  };
25
- export { Switch };
25
+ export { Switch, type SwitchProps };
package/Switch/Switch.js CHANGED
@@ -1,24 +1,38 @@
1
1
  import react, { useMemo } from "react";
2
- import { makeDecoratable } from "../utils.js";
2
+ import { generateId, makeDecoratable } from "../utils.js";
3
3
  import { SwitchPrimitive } from "./primitives/index.js";
4
- import { FormComponentErrorMessage, FormComponentNote } from "../FormComponent/index.js";
5
- const DecoratableSwitch = ({ note, validation, ...props })=>{
4
+ import { FormComponentDescription, FormComponentErrorMessage, FormComponentLabel, FormComponentNote } from "../FormComponent/index.js";
5
+ const DecoratableSwitch = ({ label, description, hint, note, required, disabled, validation, ...props })=>{
6
6
  const { isValid: validationIsValid, message: validationMessage } = validation || {};
7
+ const id = useMemo(()=>generateId(props.id), [
8
+ props.id
9
+ ]);
7
10
  const invalid = useMemo(()=>false === validationIsValid, [
8
11
  validationIsValid
9
12
  ]);
10
13
  return /*#__PURE__*/ react.createElement("div", {
11
14
  className: "w-full"
12
- }, /*#__PURE__*/ react.createElement(SwitchPrimitive, {
15
+ }, /*#__PURE__*/ react.createElement(FormComponentLabel, {
16
+ htmlFor: id,
17
+ text: label,
18
+ required: required,
19
+ disabled: disabled,
20
+ invalid: invalid,
21
+ hint: hint
22
+ }), /*#__PURE__*/ react.createElement(FormComponentDescription, {
23
+ text: description,
24
+ disabled: disabled
25
+ }), /*#__PURE__*/ react.createElement(SwitchPrimitive, {
13
26
  ...props,
14
- disabled: props.disabled
27
+ id: id,
28
+ disabled: disabled
15
29
  }), /*#__PURE__*/ react.createElement(FormComponentErrorMessage, {
16
30
  text: validationMessage,
17
31
  invalid: invalid,
18
- disabled: props.disabled
32
+ disabled: disabled
19
33
  }), /*#__PURE__*/ react.createElement(FormComponentNote, {
20
34
  text: note,
21
- disabled: props.disabled
35
+ disabled: disabled
22
36
  }));
23
37
  };
24
38
  const Switch = makeDecoratable("Switch", DecoratableSwitch);
@@ -1 +1 @@
1
- {"version":3,"file":"Switch/Switch.js","sources":["../../src/Switch/Switch.tsx"],"sourcesContent":["import React, { useMemo } from \"react\";\nimport { makeDecoratable } from \"~/utils.js\";\nimport type { SwitchPrimitiveProps } from \"./primitives/index.js\";\nimport { SwitchPrimitive } from \"./primitives/index.js\";\nimport type { FormComponentProps } from \"~/FormComponent/index.js\";\nimport { FormComponentErrorMessage, FormComponentNote } from \"~/FormComponent/index.js\";\n\ntype SwitchProps = SwitchPrimitiveProps & FormComponentProps;\n\nconst DecoratableSwitch = ({ note, validation, ...props }: SwitchProps) => {\n const { isValid: validationIsValid, message: validationMessage } = validation || {};\n const invalid = useMemo(() => validationIsValid === false, [validationIsValid]);\n\n return (\n <div className={\"w-full\"}>\n <SwitchPrimitive {...props} disabled={props.disabled} />\n <FormComponentErrorMessage\n text={validationMessage}\n invalid={invalid}\n disabled={props.disabled}\n />\n <FormComponentNote text={note} disabled={props.disabled} />\n </div>\n );\n};\n\nconst Switch = makeDecoratable(\"Switch\", DecoratableSwitch);\n\nexport { Switch };\n"],"names":["DecoratableSwitch","note","validation","props","validationIsValid","validationMessage","invalid","useMemo","SwitchPrimitive","FormComponentErrorMessage","FormComponentNote","Switch","makeDecoratable"],"mappings":";;;;AASA,MAAMA,oBAAoB,CAAC,EAAEC,IAAI,EAAEC,UAAU,EAAE,GAAGC,OAAoB;IAClE,MAAM,EAAE,SAASC,iBAAiB,EAAE,SAASC,iBAAiB,EAAE,GAAGH,cAAc,CAAC;IAClF,MAAMI,UAAUC,QAAQ,IAAMH,AAAsB,UAAtBA,mBAA6B;QAACA;KAAkB;IAE9E,OAAO,WAAP,GACI,oBAAC;QAAI,WAAW;qBACZ,oBAACI,iBAAeA;QAAE,GAAGL,KAAK;QAAE,UAAUA,MAAM,QAAQ;sBACpD,oBAACM,2BAAyBA;QACtB,MAAMJ;QACN,SAASC;QACT,UAAUH,MAAM,QAAQ;sBAE5B,oBAACO,mBAAiBA;QAAC,MAAMT;QAAM,UAAUE,MAAM,QAAQ;;AAGnE;AAEA,MAAMQ,SAASC,gBAAgB,UAAUZ"}
1
+ {"version":3,"file":"Switch/Switch.js","sources":["../../src/Switch/Switch.tsx"],"sourcesContent":["import React, { useMemo } from \"react\";\nimport { generateId, makeDecoratable } from \"~/utils.js\";\nimport type { SwitchPrimitiveProps } from \"./primitives/index.js\";\nimport { SwitchPrimitive } from \"./primitives/index.js\";\nimport {\n FormComponentDescription,\n FormComponentErrorMessage,\n FormComponentLabel,\n FormComponentNote,\n type FormComponentProps\n} from \"~/FormComponent/index.js\";\n\ntype SwitchProps = Omit<SwitchPrimitiveProps, \"label\"> & FormComponentProps;\n\nconst DecoratableSwitch = ({\n label,\n description,\n hint,\n note,\n required,\n disabled,\n validation,\n ...props\n}: SwitchProps) => {\n const { isValid: validationIsValid, message: validationMessage } = validation || {};\n const id = useMemo(() => generateId(props.id), [props.id]);\n const invalid = useMemo(() => validationIsValid === false, [validationIsValid]);\n\n return (\n <div className={\"w-full\"}>\n <FormComponentLabel\n htmlFor={id}\n text={label}\n required={required}\n disabled={disabled}\n invalid={invalid}\n hint={hint}\n />\n <FormComponentDescription text={description} disabled={disabled} />\n <SwitchPrimitive {...props} id={id} disabled={disabled} />\n <FormComponentErrorMessage\n text={validationMessage}\n invalid={invalid}\n disabled={disabled}\n />\n <FormComponentNote text={note} disabled={disabled} />\n </div>\n );\n};\n\nconst Switch = makeDecoratable(\"Switch\", DecoratableSwitch);\n\nexport { Switch, type SwitchProps };\n"],"names":["DecoratableSwitch","label","description","hint","note","required","disabled","validation","props","validationIsValid","validationMessage","id","useMemo","generateId","invalid","FormComponentLabel","FormComponentDescription","SwitchPrimitive","FormComponentErrorMessage","FormComponentNote","Switch","makeDecoratable"],"mappings":";;;;AAcA,MAAMA,oBAAoB,CAAC,EACvBC,KAAK,EACLC,WAAW,EACXC,IAAI,EACJC,IAAI,EACJC,QAAQ,EACRC,QAAQ,EACRC,UAAU,EACV,GAAGC,OACO;IACV,MAAM,EAAE,SAASC,iBAAiB,EAAE,SAASC,iBAAiB,EAAE,GAAGH,cAAc,CAAC;IAClF,MAAMI,KAAKC,QAAQ,IAAMC,WAAWL,MAAM,EAAE,GAAG;QAACA,MAAM,EAAE;KAAC;IACzD,MAAMM,UAAUF,QAAQ,IAAMH,AAAsB,UAAtBA,mBAA6B;QAACA;KAAkB;IAE9E,OAAO,WAAP,GACI,oBAAC;QAAI,WAAW;qBACZ,oBAACM,oBAAkBA;QACf,SAASJ;QACT,MAAMV;QACN,UAAUI;QACV,UAAUC;QACV,SAASQ;QACT,MAAMX;sBAEV,oBAACa,0BAAwBA;QAAC,MAAMd;QAAa,UAAUI;sBACvD,oBAACW,iBAAeA;QAAE,GAAGT,KAAK;QAAE,IAAIG;QAAI,UAAUL;sBAC9C,oBAACY,2BAAyBA;QACtB,MAAMR;QACN,SAASI;QACT,UAAUR;sBAEd,oBAACa,mBAAiBA;QAAC,MAAMf;QAAM,UAAUE;;AAGrD;AAEA,MAAMc,SAASC,gBAAgB,UAAUrB"}
@@ -1,7 +1,7 @@
1
1
  import type React from "react";
2
2
  export interface SwitchItemDto {
3
3
  id?: string;
4
- label: React.ReactNode;
4
+ label?: React.ReactNode;
5
5
  value?: number | string | boolean;
6
6
  checked?: boolean;
7
7
  disabled?: boolean;
@@ -18,7 +18,7 @@ const SwitchRenderer = ({ id, label, changeChecked, description, className, labe
18
18
  className: cn(switchVariants({
19
19
  labelPosition
20
20
  }), className)
21
- }, /*#__PURE__*/ __rspack_external_react.createElement(Label, {
21
+ }, label && /*#__PURE__*/ __rspack_external_react.createElement(Label, {
22
22
  htmlFor: id,
23
23
  text: label,
24
24
  disabled: disabled,
@@ -30,10 +30,11 @@ const SwitchRenderer = ({ id, label, changeChecked, description, className, labe
30
30
  id: id,
31
31
  checked: checked,
32
32
  className: cn([
33
- "peer inline-flex h-md w-[26px] mt-xxs shrink-0 cursor-pointer items-center rounded-xxl border-sm transition-colors",
33
+ "peer inline-flex h-md w-[26px] shrink-0 cursor-pointer items-center rounded-xxl border-sm transition-colors",
34
34
  "border-transparent data-[state=checked]:bg-secondary data-[state=unchecked]:bg-neutral-strong",
35
35
  "focus-visible:outline-none focus-visible:border-success focus-visible:ring-lg focus-visible:ring-primary-dimmed",
36
- "disabled:cursor-not-allowed disabled:bg-neutral-muted disabled:data-[state=checked]:bg-neutral-muted"
36
+ "disabled:cursor-not-allowed disabled:bg-neutral-muted disabled:data-[state=checked]:bg-neutral-muted",
37
+ label && "mt-xxs"
37
38
  ]),
38
39
  disabled: disabled,
39
40
  onCheckedChange: changeChecked
@@ -1 +1 @@
1
- {"version":3,"file":"Switch/primitives/SwitchPrimitive.js","sources":["../../../src/Switch/primitives/SwitchPrimitive.tsx"],"sourcesContent":["import * as React from \"react\";\nimport { Switch as SwitchPrimitives } from \"radix-ui\";\nimport { cn, cva, makeDecoratable, type VariantProps } from \"~/utils.js\";\nimport { Label } from \"~/Label/index.js\";\nimport { useSwitch } from \"./useSwitch.js\";\nimport type { SwitchItemDto, SwitchItemFormatted } from \"../domains/index.js\";\n\n/**\n * Switch Renderer\n */\n\nconst switchVariants = cva(\"inline-flex items-start space-x-sm\", {\n variants: {\n labelPosition: {\n start: \"\",\n end: \"flex-row-reverse space-x-sm-extra space-x-reverse\"\n }\n },\n defaultVariants: {\n labelPosition: \"start\"\n }\n});\n\ntype SwitchPrimitiveProps = Omit<\n SwitchPrimitives.SwitchProps,\n \"defaultChecked\" | \"onCheckedChange\" | \"onChange\"\n> &\n VariantProps<typeof switchVariants> &\n SwitchItemDto & {\n onChange?: (checked: boolean) => void;\n };\n\ntype SwitchPrimitivVm = {\n item?: SwitchItemFormatted;\n};\n\ntype SwitchRendererProps = Omit<SwitchPrimitiveProps, \"onCheckedChange\"> &\n NonNullable<SwitchPrimitivVm[\"item\"]> & {\n changeChecked: (checked: boolean) => void;\n description?: React.ReactNode;\n };\n\nconst SwitchRenderer = ({\n id,\n label,\n changeChecked,\n description,\n className,\n labelPosition,\n disabled,\n required,\n checked\n}: SwitchRendererProps) => {\n return (\n <div className={cn(switchVariants({ labelPosition }), className)}>\n <Label\n htmlFor={id}\n text={label}\n disabled={disabled}\n required={required}\n hint={description}\n weight={\"light\"}\n className={\"text-md\"}\n />\n <SwitchPrimitives.Root\n id={id}\n checked={checked}\n className={cn([\n \"peer inline-flex h-md w-[26px] mt-xxs shrink-0 cursor-pointer items-center rounded-xxl border-sm transition-colors\",\n \"border-transparent data-[state=checked]:bg-secondary data-[state=unchecked]:bg-neutral-strong\",\n \"focus-visible:outline-none focus-visible:border-success focus-visible:ring-lg focus-visible:ring-primary-dimmed\",\n \"disabled:cursor-not-allowed disabled:bg-neutral-muted disabled:data-[state=checked]:bg-neutral-muted\"\n ])}\n disabled={disabled}\n onCheckedChange={changeChecked}\n >\n <SwitchPrimitives.Thumb\n className={cn(\n \"pointer-events-none block h-sm-plus w-sm-plus rounded-xxl bg-neutral-base shadow-lg ring-0 transition-transform data-[state=checked]:translate-x-sm-extra data-[state=unchecked]:translate-x-xxs\"\n )}\n />\n </SwitchPrimitives.Root>\n </div>\n );\n};\n\n/**\n * Switch\n */\nconst DecoratableSwitchPrimitive = (props: SwitchPrimitiveProps) => {\n const { vm, changeChecked } = useSwitch(props);\n\n if (!vm.item) {\n return null;\n }\n\n return <SwitchRenderer {...props} {...vm.item} changeChecked={changeChecked} />;\n};\nconst SwitchPrimitive = makeDecoratable(\"SwitchPrimitive\", DecoratableSwitchPrimitive);\n\nexport { SwitchPrimitive, type SwitchPrimitiveProps, type SwitchPrimitivVm };\n"],"names":["switchVariants","cva","SwitchRenderer","id","label","changeChecked","description","className","labelPosition","disabled","required","checked","cn","Label","SwitchPrimitives","DecoratableSwitchPrimitive","props","vm","useSwitch","SwitchPrimitive","makeDecoratable"],"mappings":";;;;;AAWA,MAAMA,iBAAiBC,IAAI,sCAAsC;IAC7D,UAAU;QACN,eAAe;YACX,OAAO;YACP,KAAK;QACT;IACJ;IACA,iBAAiB;QACb,eAAe;IACnB;AACJ;AAqBA,MAAMC,iBAAiB,CAAC,EACpBC,EAAE,EACFC,KAAK,EACLC,aAAa,EACbC,WAAW,EACXC,SAAS,EACTC,aAAa,EACbC,QAAQ,EACRC,QAAQ,EACRC,OAAO,EACW,GACX,WAAP,GACI,sCAAC;QAAI,WAAWC,GAAGZ,eAAe;YAAEQ;QAAc,IAAID;qBAClD,sCAACM,OAAKA;QACF,SAASV;QACT,MAAMC;QACN,UAAUK;QACV,UAAUC;QACV,MAAMJ;QACN,QAAQ;QACR,WAAW;sBAEf,sCAACQ,OAAAA,IAAqB;QAClB,IAAIX;QACJ,SAASQ;QACT,WAAWC,GAAG;YACV;YACA;YACA;YACA;SACH;QACD,UAAUH;QACV,iBAAiBJ;qBAEjB,sCAACS,OAAAA,KAAsB;QACnB,WAAWF,GACP;;AAWxB,MAAMG,6BAA6B,CAACC;IAChC,MAAM,EAAEC,EAAE,EAAEZ,aAAa,EAAE,GAAGa,UAAUF;IAExC,IAAI,CAACC,GAAG,IAAI,EACR,OAAO;IAGX,OAAO,WAAP,GAAO,sCAACf,gBAAcA;QAAE,GAAGc,KAAK;QAAG,GAAGC,GAAG,IAAI;QAAE,eAAeZ;;AAClE;AACA,MAAMc,kBAAkBC,gBAAgB,mBAAmBL"}
1
+ {"version":3,"file":"Switch/primitives/SwitchPrimitive.js","sources":["../../../src/Switch/primitives/SwitchPrimitive.tsx"],"sourcesContent":["import * as React from \"react\";\nimport { Switch as SwitchPrimitives } from \"radix-ui\";\nimport { cn, cva, makeDecoratable, type VariantProps } from \"~/utils.js\";\nimport { Label } from \"~/Label/index.js\";\nimport { useSwitch } from \"./useSwitch.js\";\nimport type { SwitchItemDto, SwitchItemFormatted } from \"../domains/index.js\";\n\n/**\n * Switch Renderer\n */\n\nconst switchVariants = cva(\"inline-flex items-start space-x-sm\", {\n variants: {\n labelPosition: {\n start: \"\",\n end: \"flex-row-reverse space-x-sm-extra space-x-reverse\"\n }\n },\n defaultVariants: {\n labelPosition: \"start\"\n }\n});\n\ntype SwitchPrimitiveProps = Omit<\n SwitchPrimitives.SwitchProps,\n \"defaultChecked\" | \"onCheckedChange\" | \"onChange\"\n> &\n VariantProps<typeof switchVariants> &\n SwitchItemDto & {\n onChange?: (checked: boolean) => void;\n };\n\ntype SwitchPrimitivVm = {\n item?: SwitchItemFormatted;\n};\n\ntype SwitchRendererProps = Omit<SwitchPrimitiveProps, \"onCheckedChange\"> &\n NonNullable<SwitchPrimitivVm[\"item\"]> & {\n changeChecked: (checked: boolean) => void;\n description?: React.ReactNode;\n };\n\nconst SwitchRenderer = ({\n id,\n label,\n changeChecked,\n description,\n className,\n labelPosition,\n disabled,\n required,\n checked\n}: SwitchRendererProps) => {\n return (\n <div className={cn(switchVariants({ labelPosition }), className)}>\n {label && (\n <Label\n htmlFor={id}\n text={label}\n disabled={disabled}\n required={required}\n hint={description}\n weight={\"light\"}\n className={\"text-md\"}\n />\n )}\n <SwitchPrimitives.Root\n id={id}\n checked={checked}\n className={cn([\n \"peer inline-flex h-md w-[26px] shrink-0 cursor-pointer items-center rounded-xxl border-sm transition-colors\",\n \"border-transparent data-[state=checked]:bg-secondary data-[state=unchecked]:bg-neutral-strong\",\n \"focus-visible:outline-none focus-visible:border-success focus-visible:ring-lg focus-visible:ring-primary-dimmed\",\n \"disabled:cursor-not-allowed disabled:bg-neutral-muted disabled:data-[state=checked]:bg-neutral-muted\",\n // Nudges the switch down to line up with the inline label's text.\n label && \"mt-xxs\"\n ])}\n disabled={disabled}\n onCheckedChange={changeChecked}\n >\n <SwitchPrimitives.Thumb\n className={cn(\n \"pointer-events-none block h-sm-plus w-sm-plus rounded-xxl bg-neutral-base shadow-lg ring-0 transition-transform data-[state=checked]:translate-x-sm-extra data-[state=unchecked]:translate-x-xxs\"\n )}\n />\n </SwitchPrimitives.Root>\n </div>\n );\n};\n\n/**\n * Switch\n */\nconst DecoratableSwitchPrimitive = (props: SwitchPrimitiveProps) => {\n const { vm, changeChecked } = useSwitch(props);\n\n if (!vm.item) {\n return null;\n }\n\n return <SwitchRenderer {...props} {...vm.item} changeChecked={changeChecked} />;\n};\nconst SwitchPrimitive = makeDecoratable(\"SwitchPrimitive\", DecoratableSwitchPrimitive);\n\nexport { SwitchPrimitive, type SwitchPrimitiveProps, type SwitchPrimitivVm };\n"],"names":["switchVariants","cva","SwitchRenderer","id","label","changeChecked","description","className","labelPosition","disabled","required","checked","cn","Label","SwitchPrimitives","DecoratableSwitchPrimitive","props","vm","useSwitch","SwitchPrimitive","makeDecoratable"],"mappings":";;;;;AAWA,MAAMA,iBAAiBC,IAAI,sCAAsC;IAC7D,UAAU;QACN,eAAe;YACX,OAAO;YACP,KAAK;QACT;IACJ;IACA,iBAAiB;QACb,eAAe;IACnB;AACJ;AAqBA,MAAMC,iBAAiB,CAAC,EACpBC,EAAE,EACFC,KAAK,EACLC,aAAa,EACbC,WAAW,EACXC,SAAS,EACTC,aAAa,EACbC,QAAQ,EACRC,QAAQ,EACRC,OAAO,EACW,GACX,WAAP,GACI,sCAAC;QAAI,WAAWC,GAAGZ,eAAe;YAAEQ;QAAc,IAAID;OACjDH,SAAS,WAATA,GACG,sCAACS,OAAKA;QACF,SAASV;QACT,MAAMC;QACN,UAAUK;QACV,UAAUC;QACV,MAAMJ;QACN,QAAQ;QACR,WAAW;sBAGnB,sCAACQ,OAAAA,IAAqB;QAClB,IAAIX;QACJ,SAASQ;QACT,WAAWC,GAAG;YACV;YACA;YACA;YACA;YAEAR,SAAS;SACZ;QACD,UAAUK;QACV,iBAAiBJ;qBAEjB,sCAACS,OAAAA,KAAsB;QACnB,WAAWF,GACP;;AAWxB,MAAMG,6BAA6B,CAACC;IAChC,MAAM,EAAEC,EAAE,EAAEZ,aAAa,EAAE,GAAGa,UAAUF;IAExC,IAAI,CAACC,GAAG,IAAI,EACR,OAAO;IAGX,OAAO,WAAP,GAAO,sCAACf,gBAAcA;QAAE,GAAGc,KAAK;QAAG,GAAGC,GAAG,IAAI;QAAE,eAAeZ;;AAClE;AACA,MAAMc,kBAAkBC,gBAAgB,mBAAmBL"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@webiny/admin-ui",
3
- "version": "6.5.0",
3
+ "version": "6.5.1-beta.0",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": "./index.js",
@@ -19,9 +19,9 @@
19
19
  "@monaco-editor/react": "4.7.0",
20
20
  "@radix-ui/react-scroll-area": "1.4.0",
21
21
  "@tanstack/react-table": "9.3.1",
22
- "@webiny/icons": "6.5.0",
23
- "@webiny/react-composition": "6.5.0",
24
- "@webiny/utils": "6.5.0",
22
+ "@webiny/icons": "6.5.1-beta.0",
23
+ "@webiny/react-composition": "6.5.1-beta.0",
24
+ "@webiny/utils": "6.5.1-beta.0",
25
25
  "bytes": "3.1.2",
26
26
  "class-variance-authority": "0.7.1",
27
27
  "clsx": "2.1.1",
@@ -56,8 +56,8 @@
56
56
  "@types/react-color": "3.0.13",
57
57
  "@types/react-custom-scrollbars": "4.0.13",
58
58
  "@types/react-virtualized": "9.22.4",
59
- "@webiny/build-tools": "6.5.0",
60
- "@webiny/project": "6.5.0",
59
+ "@webiny/build-tools": "6.5.1-beta.0",
60
+ "@webiny/project": "6.5.1-beta.0",
61
61
  "chalk": "6.0.1",
62
62
  "oxfmt": "0.73.0",
63
63
  "rimraf": "6.1.3",