@kanso-labs/kanso-ui 0.45.21 → 0.45.22

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 (46) hide show
  1. package/dist/calendar/index.js +119 -11
  2. package/dist/calendar/index.js.map +1 -1
  3. package/dist/calendar/styles.js +19 -1
  4. package/dist/calendar/styles.js.map +1 -1
  5. package/dist/components/app-bar/index.d.ts +8 -2
  6. package/dist/components/app-bar/index.js +123 -73
  7. package/dist/components/app-bar/index.js.map +1 -1
  8. package/dist/components/calendar/index.d.ts +3 -3
  9. package/dist/components/calendar/index.js +8 -19
  10. package/dist/components/calendar/index.js.map +1 -1
  11. package/dist/components/carousel/index.d.ts +22 -3
  12. package/dist/components/carousel/index.js +26 -14
  13. package/dist/components/carousel/index.js.map +1 -1
  14. package/dist/components/chip-group/index.js +3 -0
  15. package/dist/components/chip-group/index.js.map +1 -1
  16. package/dist/components/color-picker/index.js +64 -46
  17. package/dist/components/color-picker/index.js.map +1 -1
  18. package/dist/components/color-swatch/index.js +20 -16
  19. package/dist/components/color-swatch/index.js.map +1 -1
  20. package/dist/components/copy-field/index.js +1 -0
  21. package/dist/components/copy-field/index.js.map +1 -1
  22. package/dist/components/date-range-picker/index.js +165 -81
  23. package/dist/components/date-range-picker/index.js.map +1 -1
  24. package/dist/components/index.d.ts +2 -2
  25. package/dist/components/popover/index.js +14 -4
  26. package/dist/components/popover/index.js.map +1 -1
  27. package/dist/components/range-calendar/index.js +53 -80
  28. package/dist/components/range-calendar/index.js.map +1 -1
  29. package/dist/components/segmented-button/index.js +261 -145
  30. package/dist/components/segmented-button/index.js.map +1 -1
  31. package/dist/components/sheet/index.js +149 -82
  32. package/dist/components/sheet/index.js.map +1 -1
  33. package/dist/components/table/index.js +251 -123
  34. package/dist/components/table/index.js.map +1 -1
  35. package/dist/hooks/useRipple.js +3 -2
  36. package/dist/hooks/useRipple.js.map +1 -1
  37. package/dist/index.d.ts +2 -2
  38. package/dist/segments/index.js +2 -1
  39. package/dist/segments/index.js.map +1 -1
  40. package/dist/segments/styles.js +5 -1
  41. package/dist/segments/styles.js.map +1 -1
  42. package/dist/styles/focus.js.map +1 -1
  43. package/dist/styles.css +40 -8
  44. package/dist/swatch/index.js +19 -0
  45. package/dist/swatch/index.js.map +1 -0
  46. package/package.json +3 -3
@@ -8,7 +8,7 @@ import { rowStyles as rowStyles$1 } from "../../row/styles.js";
8
8
  import { mergeStatefulStyles, mergeStyles } from "../../styles/merge.js";
9
9
  import Checkbox from "../checkbox/index.js";
10
10
  import { c } from "react/compiler-runtime";
11
- import { createContext, useContext } from "react";
11
+ import { createContext, useContext, useLayoutEffect, useState } from "react";
12
12
  import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
13
13
  import { Cell, Column, ColumnResizer, ResizableTableContainer, Row, Table, TableBody, TableFooter, TableHeader, TableLoadMoreItem } from "react-aria-components";
14
14
  // src/components/table/index.tsx
@@ -104,6 +104,9 @@ const styles = {
104
104
  const ResizeLabelContext = createContext(void 0);
105
105
  const ResizableContext = createContext(false);
106
106
  const StickyHeaderContext = createContext(false);
107
+ const NO_MIN_WIDTHS = /* @__PURE__ */ new Map();
108
+ const ColumnMinWidthsContext = createContext(NO_MIN_WIDTHS);
109
+ const REACT_ARIA_MIN_WIDTH = 75;
107
110
  function cellContent(children, selection, label) {
108
111
  if (!selection) return children;
109
112
  return /* @__PURE__ */ jsx(Checkbox, {
@@ -143,8 +146,28 @@ function emptyContent(renderEmptyState) {
143
146
  children: renderEmptyState(state)
144
147
  });
145
148
  }
149
+ /**
150
+ * Each header cell's width with the table laid out to its content. A fixed
151
+ * layout never reads a cell's content, so the table is laid out the other
152
+ * way for the length of the measurement: automatically, at no width, and
153
+ * with the widths React Aria put on the header cells lifted, which leaves
154
+ * every column at the width of the longest word it holds, its padding
155
+ * included. The styles are put back before returning, so nothing is painted
156
+ * in between.
157
+ */
158
+ function measureColumns(table) {
159
+ const headers = [];
160
+ for (const row of table.tHead?.rows ?? []) headers.push(...row.cells);
161
+ const held = [table, ...headers].map((element) => [element, element.style.cssText]);
162
+ table.style.tableLayout = "auto";
163
+ table.style.width = "0px";
164
+ for (const header of headers) header.style.width = "";
165
+ const widths = new Map(headers.map((header) => [header, Math.ceil(header.getBoundingClientRect().width)]));
166
+ for (const [element, css] of held) element.style.cssText = css;
167
+ return widths;
168
+ }
146
169
  function resizableContainerClassName() {
147
- return { className: "x9f619 xh8yej3 xw2csxc" }.className ?? "";
170
+ return { className: "x9f619 xh8yej3 x1h4wwuj xw2csxc" }.className ?? "";
148
171
  }
149
172
  function resizerRule(state) {
150
173
  return /* @__PURE__ */ jsx("span", { ...{
@@ -190,129 +213,142 @@ function sortArrowFor(direction) {
190
213
  * element a layout positions.
191
214
  */
192
215
  function Table$1(t0) {
193
- const $ = c(35);
194
- let T0;
216
+ const $ = c(41);
195
217
  let onResize;
196
218
  let onResizeEnd;
197
- let resizable;
219
+ let props;
198
220
  let resizeLabel;
199
221
  let selectAllLabel;
200
222
  let selectLabel;
201
- let stickyHeader;
202
223
  let t1;
203
224
  let t2;
204
225
  if ($[0] !== t0) {
205
- const { onResize: t3, onResizeEnd: t4, resizable: t5, resizeLabel: t6, selectAllLabel: t7, selectLabel: t8, stickyHeader: t9, ...props } = t0;
206
- onResize = t3;
207
- onResizeEnd = t4;
208
- resizeLabel = t6;
209
- selectAllLabel = t7;
210
- selectLabel = t8;
211
- resizable = t5 === void 0 ? false : t5;
212
- stickyHeader = t9 === void 0 ? false : t9;
213
- T0 = Table;
214
- t1 = props;
215
- t2 = mergeStatefulStyles(tableClasses, props);
226
+ ({onResize, onResizeEnd, resizable: t1, resizeLabel, selectAllLabel, selectLabel, stickyHeader: t2, ...props} = t0);
216
227
  $[0] = t0;
217
- $[1] = T0;
218
- $[2] = onResize;
219
- $[3] = onResizeEnd;
220
- $[4] = resizable;
221
- $[5] = resizeLabel;
222
- $[6] = selectAllLabel;
223
- $[7] = selectLabel;
224
- $[8] = stickyHeader;
225
- $[9] = t1;
226
- $[10] = t2;
228
+ $[1] = onResize;
229
+ $[2] = onResizeEnd;
230
+ $[3] = props;
231
+ $[4] = resizeLabel;
232
+ $[5] = selectAllLabel;
233
+ $[6] = selectLabel;
234
+ $[7] = t1;
235
+ $[8] = t2;
227
236
  } else {
228
- T0 = $[1];
229
- onResize = $[2];
230
- onResizeEnd = $[3];
231
- resizable = $[4];
232
- resizeLabel = $[5];
233
- selectAllLabel = $[6];
234
- selectLabel = $[7];
235
- stickyHeader = $[8];
236
- t1 = $[9];
237
- t2 = $[10];
237
+ onResize = $[1];
238
+ onResizeEnd = $[2];
239
+ props = $[3];
240
+ resizeLabel = $[4];
241
+ selectAllLabel = $[5];
242
+ selectLabel = $[6];
243
+ t1 = $[7];
244
+ t2 = $[8];
238
245
  }
246
+ const resizable = t1 === void 0 ? false : t1;
247
+ const stickyHeader = t2 === void 0 ? false : t2;
248
+ const [element, setElement] = useState(null);
239
249
  let t3;
240
- if ($[11] !== T0 || $[12] !== t1 || $[13] !== t2) {
241
- t3 = /* @__PURE__ */ jsx(T0, {
242
- ...t1,
243
- ...t2
244
- });
245
- $[11] = T0;
246
- $[12] = t1;
247
- $[13] = t2;
248
- $[14] = t3;
249
- } else t3 = $[14];
250
- const table = t3;
250
+ if ($[9] !== props.ref || $[10] !== resizable) {
251
+ t3 = resizable ? mergeRefs(setElement, props.ref ?? void 0) : props.ref;
252
+ $[9] = props.ref;
253
+ $[10] = resizable;
254
+ $[11] = t3;
255
+ } else t3 = $[11];
256
+ const ref = t3;
257
+ const minWidths = useColumnMinWidths(resizable ? element : null);
251
258
  let t4;
252
- if ($[15] !== onResize || $[16] !== onResizeEnd || $[17] !== resizable || $[18] !== table) {
253
- t4 = resizable ? /* @__PURE__ */ jsx(ResizableTableContainer, {
259
+ if ($[12] !== props) {
260
+ t4 = mergeStatefulStyles(tableClasses, props);
261
+ $[12] = props;
262
+ $[13] = t4;
263
+ } else t4 = $[13];
264
+ let t5;
265
+ if ($[14] !== props || $[15] !== ref || $[16] !== t4) {
266
+ t5 = /* @__PURE__ */ jsx(Table, {
267
+ ...props,
268
+ ...t4,
269
+ ref
270
+ });
271
+ $[14] = props;
272
+ $[15] = ref;
273
+ $[16] = t4;
274
+ $[17] = t5;
275
+ } else t5 = $[17];
276
+ const table = t5;
277
+ let t6;
278
+ if ($[18] !== onResize || $[19] !== onResizeEnd || $[20] !== resizable || $[21] !== table) {
279
+ t6 = resizable ? /* @__PURE__ */ jsx(ResizableTableContainer, {
254
280
  className: resizableContainerClassName(),
255
281
  onResize,
256
282
  onResizeEnd,
257
283
  children: table
258
284
  }) : table;
259
- $[15] = onResize;
260
- $[16] = onResizeEnd;
261
- $[17] = resizable;
262
- $[18] = table;
263
- $[19] = t4;
264
- } else t4 = $[19];
265
- let t5;
266
- if ($[20] !== stickyHeader || $[21] !== t4) {
267
- t5 = /* @__PURE__ */ jsx(StickyHeaderContext, {
285
+ $[18] = onResize;
286
+ $[19] = onResizeEnd;
287
+ $[20] = resizable;
288
+ $[21] = table;
289
+ $[22] = t6;
290
+ } else t6 = $[22];
291
+ let t7;
292
+ if ($[23] !== minWidths || $[24] !== t6) {
293
+ t7 = /* @__PURE__ */ jsx(ColumnMinWidthsContext, {
294
+ value: minWidths,
295
+ children: t6
296
+ });
297
+ $[23] = minWidths;
298
+ $[24] = t6;
299
+ $[25] = t7;
300
+ } else t7 = $[25];
301
+ let t8;
302
+ if ($[26] !== stickyHeader || $[27] !== t7) {
303
+ t8 = /* @__PURE__ */ jsx(StickyHeaderContext, {
268
304
  value: stickyHeader,
269
- children: t4
305
+ children: t7
270
306
  });
271
- $[20] = stickyHeader;
272
- $[21] = t4;
273
- $[22] = t5;
274
- } else t5 = $[22];
275
- let t6;
276
- if ($[23] !== resizable || $[24] !== t5) {
277
- t6 = /* @__PURE__ */ jsx(ResizableContext, {
307
+ $[26] = stickyHeader;
308
+ $[27] = t7;
309
+ $[28] = t8;
310
+ } else t8 = $[28];
311
+ let t9;
312
+ if ($[29] !== resizable || $[30] !== t8) {
313
+ t9 = /* @__PURE__ */ jsx(ResizableContext, {
278
314
  value: resizable,
279
- children: t5
315
+ children: t8
280
316
  });
281
- $[23] = resizable;
282
- $[24] = t5;
283
- $[25] = t6;
284
- } else t6 = $[25];
285
- let t7;
286
- if ($[26] !== resizeLabel || $[27] !== t6) {
287
- t7 = /* @__PURE__ */ jsx(ResizeLabelContext, {
317
+ $[29] = resizable;
318
+ $[30] = t8;
319
+ $[31] = t9;
320
+ } else t9 = $[31];
321
+ let t10;
322
+ if ($[32] !== resizeLabel || $[33] !== t9) {
323
+ t10 = /* @__PURE__ */ jsx(ResizeLabelContext, {
288
324
  value: resizeLabel,
289
- children: t6
325
+ children: t9
290
326
  });
291
- $[26] = resizeLabel;
292
- $[27] = t6;
293
- $[28] = t7;
294
- } else t7 = $[28];
295
- let t8;
296
- if ($[29] !== selectLabel || $[30] !== t7) {
297
- t8 = /* @__PURE__ */ jsx(SelectLabelContext, {
327
+ $[32] = resizeLabel;
328
+ $[33] = t9;
329
+ $[34] = t10;
330
+ } else t10 = $[34];
331
+ let t11;
332
+ if ($[35] !== selectLabel || $[36] !== t10) {
333
+ t11 = /* @__PURE__ */ jsx(SelectLabelContext, {
298
334
  value: selectLabel,
299
- children: t7
335
+ children: t10
300
336
  });
301
- $[29] = selectLabel;
302
- $[30] = t7;
303
- $[31] = t8;
304
- } else t8 = $[31];
305
- let t9;
306
- if ($[32] !== selectAllLabel || $[33] !== t8) {
307
- t9 = /* @__PURE__ */ jsx(SelectAllLabelContext, {
337
+ $[35] = selectLabel;
338
+ $[36] = t10;
339
+ $[37] = t11;
340
+ } else t11 = $[37];
341
+ let t12;
342
+ if ($[38] !== selectAllLabel || $[39] !== t11) {
343
+ t12 = /* @__PURE__ */ jsx(SelectAllLabelContext, {
308
344
  value: selectAllLabel,
309
- children: t8
345
+ children: t11
310
346
  });
311
- $[32] = selectAllLabel;
312
- $[33] = t8;
313
- $[34] = t9;
314
- } else t9 = $[34];
315
- return t9;
347
+ $[38] = selectAllLabel;
348
+ $[39] = t11;
349
+ $[40] = t12;
350
+ } else t12 = $[40];
351
+ return t12;
316
352
  }
317
353
  /**
318
354
  * The rows. `renderEmptyState` is what it shows when there are none — a table
@@ -402,41 +438,85 @@ function tableClasses(state) {
402
438
  * the table with no columns at all.
403
439
  */
404
440
  function TableColumn(t0) {
405
- const $ = c(11);
406
- const { children, resizable: t1, selection: t2, ...props } = t0;
441
+ const $ = c(27);
442
+ let children;
443
+ let props;
444
+ let t1;
445
+ let t2;
446
+ if ($[0] !== t0) {
447
+ ({children, resizable: t1, selection: t2, ...props} = t0);
448
+ $[0] = t0;
449
+ $[1] = children;
450
+ $[2] = props;
451
+ $[3] = t1;
452
+ $[4] = t2;
453
+ } else {
454
+ children = $[1];
455
+ props = $[2];
456
+ t1 = $[3];
457
+ t2 = $[4];
458
+ }
407
459
  const resizable = t1 === void 0 ? false : t1;
408
460
  const selection = t2 === void 0 ? false : t2;
409
461
  const label = useContext(SelectAllLabelContext);
410
462
  const resizeLabel = useContext(ResizeLabelContext);
411
463
  const resizableTable = useContext(ResizableContext);
412
464
  const sticky = useContext(StickyHeaderContext);
413
- const T0 = Column;
414
- const t3 = mergeStatefulStyles(columnStyles(selection, sticky), props);
415
- const t4 = resizable && resizableTable;
465
+ const [element, setElement] = useState(null);
466
+ let t3;
467
+ if ($[5] !== props.ref || $[6] !== resizableTable) {
468
+ t3 = resizableTable ? mergeRefs(setElement, props.ref ?? void 0) : props.ref;
469
+ $[5] = props.ref;
470
+ $[6] = resizableTable;
471
+ $[7] = t3;
472
+ } else t3 = $[7];
473
+ const ref = t3;
474
+ const minWidths = useContext(ColumnMinWidthsContext);
475
+ let t4;
476
+ if ($[8] !== element || $[9] !== minWidths) {
477
+ t4 = element === null ? void 0 : minWidths.get(element);
478
+ $[8] = element;
479
+ $[9] = minWidths;
480
+ $[10] = t4;
481
+ } else t4 = $[10];
482
+ const measured = t4;
416
483
  let t5;
417
- if ($[0] !== children || $[1] !== label || $[2] !== resizeLabel || $[3] !== selection || $[4] !== t4) {
418
- t5 = columnContent(children, selection, label, t4, resizeLabel);
419
- $[0] = children;
420
- $[1] = label;
421
- $[2] = resizeLabel;
422
- $[3] = selection;
423
- $[4] = t4;
424
- $[5] = t5;
425
- } else t5 = $[5];
426
- let t6;
427
- if ($[6] !== T0 || $[7] !== props || $[8] !== t3 || $[9] !== t5) {
428
- t6 = /* @__PURE__ */ jsx(T0, {
484
+ if ($[11] !== props || $[12] !== selection || $[13] !== sticky) {
485
+ t5 = mergeStatefulStyles(columnStyles(selection, sticky), props);
486
+ $[11] = props;
487
+ $[12] = selection;
488
+ $[13] = sticky;
489
+ $[14] = t5;
490
+ } else t5 = $[14];
491
+ const t6 = props.minWidth ?? (measured === void 0 ? void 0 : Math.max(measured, REACT_ARIA_MIN_WIDTH));
492
+ const t7 = resizable && resizableTable;
493
+ let t8;
494
+ if ($[15] !== children || $[16] !== label || $[17] !== resizeLabel || $[18] !== selection || $[19] !== t7) {
495
+ t8 = columnContent(children, selection, label, t7, resizeLabel);
496
+ $[15] = children;
497
+ $[16] = label;
498
+ $[17] = resizeLabel;
499
+ $[18] = selection;
500
+ $[19] = t7;
501
+ $[20] = t8;
502
+ } else t8 = $[20];
503
+ let t9;
504
+ if ($[21] !== props || $[22] !== ref || $[23] !== t5 || $[24] !== t6 || $[25] !== t8) {
505
+ t9 = /* @__PURE__ */ jsx(Column, {
429
506
  ...props,
430
- ...t3,
431
- children: t5
507
+ ...t5,
508
+ minWidth: t6,
509
+ ref,
510
+ children: t8
432
511
  });
433
- $[6] = T0;
434
- $[7] = props;
435
- $[8] = t3;
436
- $[9] = t5;
437
- $[10] = t6;
438
- } else t6 = $[10];
439
- return t6;
512
+ $[21] = props;
513
+ $[22] = ref;
514
+ $[23] = t5;
515
+ $[24] = t6;
516
+ $[25] = t8;
517
+ $[26] = t9;
518
+ } else t9 = $[26];
519
+ return t9;
440
520
  }
441
521
  /**
442
522
  * A row under the body, for totals and the like. It is not part of the
@@ -585,6 +665,54 @@ function TableRow(props) {
585
665
  } else t1 = $[4];
586
666
  return t1;
587
667
  }
668
+ /**
669
+ * The narrowest each column of a resizable table can be with none of its
670
+ * words broken, by the column's header cell, for the columns to take as
671
+ * their minimum — see the header.
672
+ *
673
+ * Measured again when a row, a cell or its text changes, and when a font
674
+ * finishes loading, which is when a word's width changes; never when the
675
+ * table is resized, since what a column holds does not change with it.
676
+ */
677
+ function useColumnMinWidths(table) {
678
+ const $ = c(3);
679
+ const [widths, setWidths] = useState(NO_MIN_WIDTHS);
680
+ let t0;
681
+ let t1;
682
+ if ($[0] !== table) {
683
+ t0 = () => {
684
+ if (table === null) return;
685
+ const measure = () => {
686
+ const next = measureColumns(table);
687
+ setWidths((current) => current.size === next.size && [...next].every((t2) => {
688
+ const [header, width] = t2;
689
+ return current.get(header) === width;
690
+ }) ? current : next);
691
+ };
692
+ measure();
693
+ const changes = new MutationObserver(measure);
694
+ changes.observe(table, {
695
+ characterData: true,
696
+ childList: true,
697
+ subtree: true
698
+ });
699
+ document.fonts.addEventListener("loadingdone", measure);
700
+ return () => {
701
+ changes.disconnect();
702
+ document.fonts.removeEventListener("loadingdone", measure);
703
+ };
704
+ };
705
+ t1 = [table];
706
+ $[0] = table;
707
+ $[1] = t0;
708
+ $[2] = t1;
709
+ } else {
710
+ t0 = $[1];
711
+ t1 = $[2];
712
+ }
713
+ useLayoutEffect(t0, t1);
714
+ return widths;
715
+ }
588
716
  Table$1.Body = TableBody$1;
589
717
  Table$1.Cell = TableCell;
590
718
  Table$1.Column = TableColumn;