@xds/core 1.0.1 → 1.2.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 (101) hide show
  1. package/dist/banner.d.ts +4 -1
  2. package/dist/breadcrumb.d.ts +39 -0
  3. package/dist/breadcrumb.js +7 -0
  4. package/dist/checkbox.d.ts +20 -3
  5. package/dist/checkbox.js +3 -1
  6. package/dist/combobox.d.ts +59 -0
  7. package/dist/combobox.js +40 -0
  8. package/dist/date-picker.d.ts +10 -4
  9. package/dist/date-picker.js +5 -4
  10. package/dist/date-range-picker.d.ts +10 -4
  11. package/dist/date-range-picker.js +9 -8
  12. package/dist/index.d.ts +17 -6
  13. package/dist/index.js +16 -5
  14. package/dist/labels.d.ts +34 -0
  15. package/dist/labels.js +26 -0
  16. package/dist/link.d.ts +49 -0
  17. package/dist/link.js +12 -0
  18. package/dist/pagination.d.ts +51 -0
  19. package/dist/pagination.js +25 -0
  20. package/dist/popover.d.ts +33 -0
  21. package/dist/popover.js +8 -0
  22. package/dist/preview/components.d.ts +71 -17
  23. package/dist/preview/components.js +1 -0
  24. package/dist/preview/design.d.ts +22 -3
  25. package/dist/preview/design.js +65 -34
  26. package/dist/preview/fixtures.d.ts +0 -76
  27. package/dist/preview/fixtures.js +0 -126
  28. package/dist/preview/kit.d.ts +48 -32
  29. package/dist/preview/kit.js +3 -0
  30. package/dist/preview/page.d.ts +1 -1
  31. package/dist/preview/page.js +1 -0
  32. package/dist/preview/sections/accordion.d.ts +1 -0
  33. package/dist/preview/sections/accordion.js +40 -0
  34. package/dist/preview/sections/badges.d.ts +1 -0
  35. package/dist/preview/sections/badges.js +13 -0
  36. package/dist/preview/sections/banners.d.ts +1 -0
  37. package/dist/preview/sections/banners.js +13 -0
  38. package/dist/preview/sections/buttons.d.ts +2 -0
  39. package/dist/preview/sections/buttons.js +30 -0
  40. package/dist/preview/sections/card.d.ts +1 -0
  41. package/dist/preview/sections/card.js +33 -0
  42. package/dist/preview/sections/chips.d.ts +1 -0
  43. package/dist/preview/sections/chips.js +23 -0
  44. package/dist/preview/sections/controls.d.ts +1 -0
  45. package/dist/preview/sections/controls.js +143 -0
  46. package/dist/preview/sections/dialog.d.ts +1 -0
  47. package/dist/preview/sections/dialog.js +25 -0
  48. package/dist/preview/sections/empty-state.d.ts +1 -0
  49. package/dist/preview/sections/empty-state.js +13 -0
  50. package/dist/preview/sections/links.d.ts +1 -0
  51. package/dist/preview/sections/links.js +8 -0
  52. package/dist/preview/sections/list.d.ts +1 -0
  53. package/dist/preview/sections/list.js +119 -0
  54. package/dist/preview/sections/media.d.ts +1 -0
  55. package/dist/preview/sections/media.js +90 -0
  56. package/dist/preview/sections/menu.d.ts +1 -0
  57. package/dist/preview/sections/menu.js +46 -0
  58. package/dist/preview/sections/navigation.d.ts +1 -0
  59. package/dist/preview/sections/navigation.js +20 -0
  60. package/dist/preview/sections/selection.d.ts +1 -0
  61. package/dist/preview/sections/selection.js +33 -0
  62. package/dist/preview/sections/sidebar.d.ts +1 -0
  63. package/dist/preview/sections/sidebar.js +45 -0
  64. package/dist/preview/sections/skeleton.d.ts +1 -0
  65. package/dist/preview/sections/skeleton.js +5 -0
  66. package/dist/preview/sections/tabs.d.ts +1 -0
  67. package/dist/preview/sections/tabs.js +24 -0
  68. package/dist/preview/sections/text-fields.d.ts +1 -0
  69. package/dist/preview/sections/text-fields.js +75 -0
  70. package/dist/preview/sections/toast.d.ts +2 -0
  71. package/dist/preview/sections/toast.js +28 -0
  72. package/dist/preview/specimens.js +1 -1
  73. package/dist/progress-bar.d.ts +7 -4
  74. package/dist/progress-bar.js +2 -2
  75. package/dist/radio-group.d.ts +7 -1
  76. package/dist/root.d.ts +25 -0
  77. package/dist/root.js +25 -0
  78. package/dist/rows.d.ts +23 -0
  79. package/dist/rows.js +67 -0
  80. package/dist/segmented-control.d.ts +5 -2
  81. package/dist/segmented-control.js +1 -1
  82. package/dist/select.d.ts +29 -1
  83. package/dist/select.js +7 -0
  84. package/dist/slider.d.ts +4 -1
  85. package/dist/switch.d.ts +5 -2
  86. package/dist/switch.js +2 -1
  87. package/dist/table.d.ts +62 -0
  88. package/dist/table.js +25 -0
  89. package/dist/tabs.d.ts +4 -2
  90. package/dist/text-field.d.ts +19 -3
  91. package/dist/theme-scope.d.ts +6 -4
  92. package/dist/theme-scope.js +21 -15
  93. package/dist/time-picker.d.ts +57 -0
  94. package/dist/time-picker.js +53 -0
  95. package/dist/toast-queue.d.ts +40 -0
  96. package/dist/toast-queue.js +17 -0
  97. package/dist/toast.d.ts +1 -1
  98. package/dist/toast.js +1 -1
  99. package/package.json +2 -2
  100. package/dist/preview/sections.d.ts +0 -20
  101. package/dist/preview/sections.js +0 -517
package/dist/root.js ADDED
@@ -0,0 +1,25 @@
1
+ export function rootAttributes(props) {
2
+ const attributes = {};
3
+ for (const [name, value] of Object.entries(props)) {
4
+ if (name === "id" || name.startsWith("data-"))
5
+ attributes[name] = value;
6
+ }
7
+ return attributes;
8
+ }
9
+ export function isControlled(props, name) {
10
+ return name in props;
11
+ }
12
+ export function onFormReset(element, reset) {
13
+ const form = element?.closest("form");
14
+ if (!form)
15
+ return () => { };
16
+ let timer;
17
+ const listener = () => {
18
+ timer = setTimeout(reset);
19
+ };
20
+ form.addEventListener("reset", listener);
21
+ return () => {
22
+ form.removeEventListener("reset", listener);
23
+ clearTimeout(timer);
24
+ };
25
+ }
package/dist/rows.d.ts ADDED
@@ -0,0 +1,23 @@
1
+ type Props = object;
2
+ /**
3
+ * Whether two sets of the props that a Zag machine gives one item draw the same: the same
4
+ * attributes, and a handler wherever the other has one. Zag makes the handlers anew each time,
5
+ * but they close over nothing that the item's attributes do not show (its value, whether it is
6
+ * disabled, highlighted or chosen) and send to the machine, which stays the same, so the earlier
7
+ * ones do what the later ones would.
8
+ */
9
+ export declare function sameItemProps(a: Props, b: Props): boolean;
10
+ /**
11
+ * Whether a row drawn with props `a` draws the same with `b`: each prop the same, where an
12
+ * object, such as the props Zag gives one of the row's parts or the option the row shows, is
13
+ * compared by `sameItemProps`. For a row whose props are what it draws, with no handler of its
14
+ * own: a function in them is taken to do the same as the one before it.
15
+ */
16
+ export declare function sameRowProps(a: Props, b: Props): boolean;
17
+ /**
18
+ * For a framework that compares what a row is given by identity: hands back the props last given
19
+ * under `key` for as long as the next ones draw the same (`sameItemProps`), so the row's
20
+ * attributes and handlers stay as they are. One cache for one list, kept while the list is.
21
+ */
22
+ export declare function createItemPropsCache(): <T extends Props>(key: string, props: T) => T;
23
+ export {};
package/dist/rows.js ADDED
@@ -0,0 +1,67 @@
1
+ function values(props) {
2
+ return props;
3
+ }
4
+ export function sameItemProps(a, b) {
5
+ if (a === b)
6
+ return true;
7
+ const before = values(a);
8
+ const after = values(b);
9
+ let count = 0;
10
+ for (const key in before) {
11
+ count += 1;
12
+ const was = before[key];
13
+ const is = after[key];
14
+ if (was === is) {
15
+ if (was === undefined && !(key in after))
16
+ return false;
17
+ continue;
18
+ }
19
+ if (typeof was === "function" && typeof is === "function")
20
+ continue;
21
+ if (!Object.is(was, is))
22
+ return false;
23
+ }
24
+ for (const _ in after)
25
+ count -= 1;
26
+ return count === 0;
27
+ }
28
+ function isPlainObject(value) {
29
+ if (typeof value !== "object" || value === null)
30
+ return false;
31
+ const prototype = Object.getPrototypeOf(value);
32
+ return prototype === Object.prototype || prototype === null;
33
+ }
34
+ export function sameRowProps(a, b) {
35
+ if (a === b)
36
+ return true;
37
+ const before = values(a);
38
+ const after = values(b);
39
+ let count = 0;
40
+ for (const key in before) {
41
+ count += 1;
42
+ const was = before[key];
43
+ const is = after[key];
44
+ if (was === is) {
45
+ if (was === undefined && !(key in after))
46
+ return false;
47
+ continue;
48
+ }
49
+ if (isPlainObject(was) && isPlainObject(is) && sameItemProps(was, is))
50
+ continue;
51
+ if (!Object.is(was, is))
52
+ return false;
53
+ }
54
+ for (const _ in after)
55
+ count -= 1;
56
+ return count === 0;
57
+ }
58
+ export function createItemPropsCache() {
59
+ const last = new Map();
60
+ return (key, props) => {
61
+ const before = last.get(key);
62
+ if (before !== undefined && sameItemProps(before, props))
63
+ return before;
64
+ last.set(key, props);
65
+ return props;
66
+ };
67
+ }
@@ -4,7 +4,10 @@ export type SegmentedControlBaseProps<Value extends string> = {
4
4
  value: Value;
5
5
  label: string;
6
6
  }[];
7
- value: Value;
7
+ /** The chosen segment. Leave it out for a control that keeps its own, from `defaultValue`. */
8
+ value?: Value;
9
+ /** The first segment of a control that keeps its own, without `value`. Defaults to the first. */
10
+ defaultValue?: Value;
8
11
  /** Says what is being chosen, for assistive technology. */
9
12
  "aria-label": string;
10
13
  /** Stretches to the width of its container. */
@@ -18,4 +21,4 @@ export declare function segmentedControlOptionClass(fullWidth?: boolean): string
18
21
  * The segment drawn beside the hidden radio button. The border is there on every segment,
19
22
  * transparent until selected, so selecting does not move the text.
20
23
  */
21
- export declare const segmentedControlSegmentClass = "flex w-full items-center justify-center whitespace-nowrap rounded-[calc(var(--xds-radius-md)-2px)] border border-transparent px-4 text-xds-label text-xds-segmented-text peer-checked:border-xds-segmented-selected-border peer-checked:bg-xds-segmented-selected-background peer-checked:text-xds-segmented-selected-text peer-checked:shadow-xds-subtle peer-focus-visible:outline-solid peer-focus-visible:outline-(length:--xds-focus-width) peer-focus-visible:outline-offset-(--xds-focus-offset) peer-focus-visible:outline-xds-border-focus";
24
+ export declare const segmentedControlSegmentClass = "flex w-full items-center justify-center whitespace-nowrap rounded-[calc(var(--xds-radius-md)-2px)] border border-transparent px-4 text-xds-label text-xds-segmented-text peer-checked:border-xds-segmented-selected-border peer-checked:bg-xds-segmented-selected-background peer-checked:text-xds-segmented-selected-text peer-checked:shadow-xds-subtle forced-colors:peer-checked:bg-[Highlight] forced-colors:peer-checked:text-[HighlightText] forced-colors:peer-checked:forced-color-adjust-none peer-focus-visible:outline-solid peer-focus-visible:outline-(length:--xds-focus-width) peer-focus-visible:outline-offset-(--xds-focus-offset) peer-focus-visible:outline-xds-border-focus";
@@ -5,4 +5,4 @@ export function segmentedControlClass(fullWidth = false) {
5
5
  export function segmentedControlOptionClass(fullWidth = false) {
6
6
  return `relative flex cursor-pointer ${fullWidth ? "flex-1" : ""}`;
7
7
  }
8
- export const segmentedControlSegmentClass = `flex w-full items-center justify-center whitespace-nowrap rounded-[calc(var(--xds-radius-md)-2px)] border border-transparent px-4 text-xds-label text-xds-segmented-text peer-checked:border-xds-segmented-selected-border peer-checked:bg-xds-segmented-selected-background peer-checked:text-xds-segmented-selected-text peer-checked:shadow-xds-subtle ${PEER_FOCUS}`;
8
+ export const segmentedControlSegmentClass = `flex w-full items-center justify-center whitespace-nowrap rounded-[calc(var(--xds-radius-md)-2px)] border border-transparent px-4 text-xds-label text-xds-segmented-text peer-checked:border-xds-segmented-selected-border peer-checked:bg-xds-segmented-selected-background peer-checked:text-xds-segmented-selected-text peer-checked:shadow-xds-subtle forced-colors:peer-checked:bg-[Highlight] forced-colors:peer-checked:text-[HighlightText] forced-colors:peer-checked:forced-color-adjust-none ${PEER_FOCUS}`;
package/dist/select.d.ts CHANGED
@@ -9,8 +9,14 @@ export type SelectBaseProps<Value extends string = string> = {
9
9
  /** Always visible, like a TextField's. */
10
10
  label: string;
11
11
  options: readonly SelectOption<Value>[];
12
- /** The chosen option. Leave it out while nothing is chosen. */
12
+ /**
13
+ * The chosen option, `undefined` while nothing is chosen. Leave it out for a select that keeps
14
+ * its own choice, from `defaultValue`: it is controlled whenever `value` is given, even as
15
+ * `undefined`.
16
+ */
13
17
  value?: Value | undefined;
18
+ /** The first choice of a select that keeps its own, without `value`. */
19
+ defaultValue?: Value | undefined;
14
20
  /** Shown in the field while nothing is chosen. */
15
21
  placeholder?: string;
16
22
  /** Help shown under the field. Replaced by `error` while there is one. */
@@ -20,7 +26,29 @@ export type SelectBaseProps<Value extends string = string> = {
20
26
  /** The name the choice is submitted under with a form. */
21
27
  name?: string;
22
28
  disabled?: boolean;
29
+ /**
30
+ * Lets the person choose any number of options, with `values` in place of `value`. The list
31
+ * stays open as options are chosen and unchosen, each chosen one marked with a check, and the
32
+ * field shows their labels in the options' order.
33
+ */
34
+ multiple?: boolean;
35
+ /**
36
+ * The chosen options of a select with `multiple`. Leave it out for one that keeps its own
37
+ * choice, from `defaultValues`.
38
+ */
39
+ values?: readonly Value[] | undefined;
40
+ /** The first choice of a select with `multiple` that keeps its own, without `values`. */
41
+ defaultValues?: readonly Value[] | undefined;
23
42
  };
43
+ /**
44
+ * What the field of a select with `multiple` shows: the chosen options' labels in the options'
45
+ * order, joined by commas, or `undefined` while none is chosen, for the placeholder. In the
46
+ * options' order, not the order they were chosen in, so the field reads the same however the
47
+ * person got there.
48
+ */
49
+ export declare function selectedLabels<Value extends string>(options: readonly SelectOption<Value>[], values: readonly Value[]): string | undefined;
50
+ /** `values` in the options' order, which is the order a select with `multiple` reports. */
51
+ export declare function orderedValues<Value extends string>(options: readonly SelectOption<Value>[], values: readonly Value[]): Value[];
24
52
  /**
25
53
  * The ids of the label and the help line of the option at `index`, under the Select's own id.
26
54
  * The option is named by its label alone, as the field shows it, and described by the help.
package/dist/select.js CHANGED
@@ -1,3 +1,10 @@
1
+ export function selectedLabels(options, values) {
2
+ const chosen = options.filter((option) => values.includes(option.value));
3
+ return chosen.length === 0 ? undefined : chosen.map((option) => option.label).join(", ");
4
+ }
5
+ export function orderedValues(options, values) {
6
+ return options.map((option) => option.value).filter((value) => values.includes(value));
7
+ }
1
8
  export function selectOptionIds(id, index) {
2
9
  const label = `${id}-option-${index}`;
3
10
  return { label, description: `${label}-description` };
package/dist/slider.d.ts CHANGED
@@ -2,7 +2,10 @@
2
2
  export type SliderBaseProps = {
3
3
  /** Shown above the track, and names the slider for assistive technology. */
4
4
  label: string;
5
- value: number;
5
+ /** Leave it out for a slider that keeps its own value, from `defaultValue`. */
6
+ value?: number;
7
+ /** The first value of a slider that keeps its own, without `value`. Defaults to `min`. */
8
+ defaultValue?: number;
6
9
  /** Defaults to 0. */
7
10
  min?: number;
8
11
  /** Defaults to 100. */
package/dist/switch.d.ts CHANGED
@@ -1,6 +1,9 @@
1
1
  /** Switch's props in every framework, short of `onChange`. */
2
2
  export type SwitchBaseProps = {
3
- checked: boolean;
3
+ /** Leave it out for a switch that keeps its own state, from `defaultChecked`. */
4
+ checked?: boolean;
5
+ /** Whether a switch that keeps its own state starts on. */
6
+ defaultChecked?: boolean;
4
7
  /** Shown beside the switch. Pressing it toggles too. */
5
8
  label?: string;
6
9
  /** Names the switch for assistive technology when there is no visible label. */
@@ -14,7 +17,7 @@ export declare const PEER_FOCUS = "peer-focus-visible:outline-solid peer-focus-v
14
17
  */
15
18
  export declare const switchClass = "relative inline-flex min-h-xds-target-min w-fit cursor-pointer items-center gap-2 has-disabled:cursor-not-allowed";
16
19
  /** The track, drawn beside the hidden input. */
17
- export declare const switchTrackClass = "flex h-xds-switch-height w-xds-switch-width shrink-0 rounded-full bg-xds-switch-track p-0.5 transition-colors duration-(--xds-motion-duration-fast) peer-checked:bg-xds-switch-track-on peer-disabled:bg-xds-switch-disabled-track peer-checked:*:translate-x-[calc(var(--xds-size-switch-width)-var(--xds-size-switch-height))] peer-disabled:*:bg-xds-switch-disabled-thumb peer-focus-visible:outline-solid peer-focus-visible:outline-(length:--xds-focus-width) peer-focus-visible:outline-offset-(--xds-focus-offset) peer-focus-visible:outline-xds-border-focus";
20
+ export declare const switchTrackClass = "flex h-xds-switch-height w-xds-switch-width shrink-0 rounded-full bg-xds-switch-track p-0.5 transition-colors duration-(--xds-motion-duration-fast) peer-checked:bg-xds-switch-track-on peer-disabled:bg-xds-switch-disabled-track peer-checked:*:translate-x-[calc(var(--xds-size-switch-width)-var(--xds-size-switch-height))] peer-disabled:*:bg-xds-switch-disabled-thumb forced-colors:border forced-colors:border-[CanvasText] forced-colors:p-px forced-colors:*:bg-[CanvasText] forced-colors:peer-checked:border-[Highlight] forced-colors:peer-checked:bg-[Highlight] forced-colors:peer-checked:*:bg-[HighlightText] forced-colors:peer-disabled:border-[GrayText] forced-colors:peer-disabled:*:bg-[GrayText] peer-focus-visible:outline-solid peer-focus-visible:outline-(length:--xds-focus-width) peer-focus-visible:outline-offset-(--xds-focus-offset) peer-focus-visible:outline-xds-border-focus";
18
21
  /** The thumb inside the track. */
19
22
  export declare const switchThumbClass = "aspect-square h-full rounded-full bg-xds-switch-thumb transition-transform duration-(--xds-motion-duration-fast) ease-(--xds-motion-easing-standard) motion-reduce:transition-none";
20
23
  /** The visible label after the track, which is also a Checkbox's. */
package/dist/switch.js CHANGED
@@ -1,5 +1,6 @@
1
1
  export const PEER_FOCUS = "peer-focus-visible:outline-solid peer-focus-visible:outline-(length:--xds-focus-width) peer-focus-visible:outline-offset-(--xds-focus-offset) peer-focus-visible:outline-xds-border-focus";
2
2
  export const switchClass = "relative inline-flex min-h-xds-target-min w-fit cursor-pointer items-center gap-2 has-disabled:cursor-not-allowed";
3
- export const switchTrackClass = `flex h-xds-switch-height w-xds-switch-width shrink-0 rounded-full bg-xds-switch-track p-0.5 transition-colors duration-(--xds-motion-duration-fast) peer-checked:bg-xds-switch-track-on peer-disabled:bg-xds-switch-disabled-track peer-checked:*:translate-x-[calc(var(--xds-size-switch-width)-var(--xds-size-switch-height))] peer-disabled:*:bg-xds-switch-disabled-thumb ${PEER_FOCUS}`;
3
+ const FORCED_COLORS = "forced-colors:border forced-colors:border-[CanvasText] forced-colors:p-px forced-colors:*:bg-[CanvasText] forced-colors:peer-checked:border-[Highlight] forced-colors:peer-checked:bg-[Highlight] forced-colors:peer-checked:*:bg-[HighlightText] forced-colors:peer-disabled:border-[GrayText] forced-colors:peer-disabled:*:bg-[GrayText]";
4
+ export const switchTrackClass = `flex h-xds-switch-height w-xds-switch-width shrink-0 rounded-full bg-xds-switch-track p-0.5 transition-colors duration-(--xds-motion-duration-fast) peer-checked:bg-xds-switch-track-on peer-disabled:bg-xds-switch-disabled-track peer-checked:*:translate-x-[calc(var(--xds-size-switch-width)-var(--xds-size-switch-height))] peer-disabled:*:bg-xds-switch-disabled-thumb ${FORCED_COLORS} ${PEER_FOCUS}`;
4
5
  export const switchThumbClass = "aspect-square h-full rounded-full bg-xds-switch-thumb transition-transform duration-(--xds-motion-duration-fast) ease-(--xds-motion-easing-standard) motion-reduce:transition-none";
5
6
  export const switchLabelClass = "text-xds-body text-xds-text-primary peer-disabled:text-xds-text-secondary";
@@ -0,0 +1,62 @@
1
+ /** A column of a Table. */
2
+ export type TableColumn = {
3
+ /** Names the column, for `sort`. */
4
+ key: string;
5
+ /** The column's header. */
6
+ label: string;
7
+ /** `end` for numbers, so that their digits line up. `start` unless set. */
8
+ align?: "start" | "end";
9
+ /** Its header is a button that asks for the rows sorted by it, through `onSortChange`. */
10
+ sortable?: boolean;
11
+ };
12
+ /** A row of a Table: its values, one for each column, in the columns' order. */
13
+ export type TableRow = {
14
+ /** Tells the row from the others. */
15
+ id: string;
16
+ cells: readonly string[];
17
+ };
18
+ export type SortDirection = "ascending" | "descending";
19
+ /** The column the rows are sorted by, by its `key`, and in which order. */
20
+ export type TableSort = {
21
+ column: string;
22
+ direction: SortDirection;
23
+ };
24
+ /** Table's props in every framework, short of `onSortChange`. */
25
+ export type TableBaseProps = {
26
+ /** Names the table for assistive technology. */
27
+ label: string;
28
+ columns: readonly TableColumn[];
29
+ /** Shown in the order given: the table does not sort them. */
30
+ rows: readonly TableRow[];
31
+ /** The column the app sorted the rows by, which its header shows. */
32
+ sort?: TableSort | undefined;
33
+ /** Said in the table while it has no rows. */
34
+ empty?: string;
35
+ };
36
+ /**
37
+ * The sort a press on a sortable column's header asks for: ascending, or the other way for
38
+ * the column the rows are sorted by already.
39
+ */
40
+ export declare function nextSort(sort: TableSort | undefined, column: string): TableSort;
41
+ /** The order of a column's rows, or none for a column they are not sorted by. */
42
+ export declare function columnSort(sort: TableSort | undefined, column: string): SortDirection | undefined;
43
+ /**
44
+ * The arrow at the end of a sortable column's header: up while the rows are sorted ascending
45
+ * by it, down while descending, and both ways while they are sorted by another column.
46
+ */
47
+ export declare function sortIcon(direction: SortDirection | undefined): "arrow-down" | "arrow-up" | "arrow-up-down";
48
+ /**
49
+ * The classes of a Table's parts beside its root, `xds-table`, the frame that scrolls sideways
50
+ * when the columns do not fit: the `<table>`, a header cell, the button of a sortable one, a
51
+ * row, a cell, and the cell that says the table is empty. A cell of a column aligned to the end
52
+ * takes `end` too.
53
+ */
54
+ export declare const TABLE_PARTS: {
55
+ readonly table: "xds-table__table";
56
+ readonly header: "xds-table__header";
57
+ readonly sort: "xds-table__sort";
58
+ readonly row: "xds-table__row";
59
+ readonly cell: "xds-table__cell";
60
+ readonly empty: "xds-table__empty";
61
+ readonly end: "xds-table__cell--end";
62
+ };
package/dist/table.js ADDED
@@ -0,0 +1,25 @@
1
+ export function nextSort(sort, column) {
2
+ return {
3
+ column,
4
+ direction: sort?.column === column && sort.direction === "ascending" ? "descending" : "ascending",
5
+ };
6
+ }
7
+ export function columnSort(sort, column) {
8
+ return sort?.column === column ? sort.direction : undefined;
9
+ }
10
+ export function sortIcon(direction) {
11
+ return direction === "ascending"
12
+ ? "arrow-up"
13
+ : direction === "descending"
14
+ ? "arrow-down"
15
+ : "arrow-up-down";
16
+ }
17
+ export const TABLE_PARTS = {
18
+ table: "xds-table__table",
19
+ header: "xds-table__header",
20
+ sort: "xds-table__sort",
21
+ row: "xds-table__row",
22
+ cell: "xds-table__cell",
23
+ empty: "xds-table__empty",
24
+ end: "xds-table__cell--end",
25
+ };
package/dist/tabs.d.ts CHANGED
@@ -6,8 +6,10 @@ export type TabsBaseProps<Value extends string> = {
6
6
  label: string;
7
7
  icon?: IconName;
8
8
  }[];
9
- /** The selected tab. */
10
- value: Value;
9
+ /** The selected tab. Leave it out for tabs that keep their own, from `defaultValue`. */
10
+ value?: Value;
11
+ /** The first tab of tabs that keep their own, without `value`. Defaults to the first. */
12
+ defaultValue?: Value;
11
13
  /** Says what the tabs switch between, for assistive technology. */
12
14
  label: string;
13
15
  /** The tabs share the width equally instead of being as wide as their labels. */
@@ -2,7 +2,15 @@
2
2
  export type TextFieldBaseProps = {
3
3
  /** Always visible. A placeholder is not a label: it disappears as soon as the person types. */
4
4
  label: string;
5
- value: string;
5
+ /**
6
+ * The text. Leave it out for a field that keeps its own, from `defaultValue`: the field is
7
+ * controlled whenever `value` is given.
8
+ */
9
+ value?: string;
10
+ /** The first text of a field that keeps its own, without `value`. */
11
+ defaultValue?: string;
12
+ /** The text can be selected and copied but not changed, and is still submitted with a form. */
13
+ readOnly?: boolean;
6
14
  /** Help shown under the field. Replaced by `error` while there is one. */
7
15
  description?: string;
8
16
  /** What is wrong and how to fix it. Clear it when the value changes. */
@@ -25,11 +33,19 @@ export type TextFieldBaseProps = {
25
33
  export type TextFieldType = "text" | "email" | "password" | "search" | "tel" | "url" | "number" | (string & {});
26
34
  /** SearchField's props in every framework, short of `onChange` and `onSubmit`. */
27
35
  export type SearchFieldBaseProps = {
28
- value: string;
36
+ /** The query. Leave it out for a field that keeps its own, from `defaultValue`. */
37
+ value?: string;
38
+ /** The first query of a field that keeps its own, without `value`. */
39
+ defaultValue?: string;
40
+ /** The query can be selected and copied but not changed. */
41
+ readOnly?: boolean;
29
42
  /** The accessible name. It is not shown: the search icon says what the field is for. */
30
43
  label: string;
31
44
  placeholder?: string;
32
45
  disabled?: boolean;
33
- /** Names the control that empties the field, for assistive technology. */
46
+ /**
47
+ * Names the control that empties the field, for assistive technology. The `clear` label of a
48
+ * `Labels` provider unless set.
49
+ */
34
50
  clearLabel?: string;
35
51
  };
@@ -1,15 +1,17 @@
1
1
  export type ThemeScope = {
2
2
  mode?: string;
3
3
  theme?: string;
4
+ contrast?: string;
4
5
  };
5
6
  /**
6
- * Finds the nearest subtree color mode and theme attributes around `origin`, ignoring attributes
7
- * on `<html>` because those already inherit into `document.body`.
7
+ * Finds the nearest subtree color mode, theme and contrast attributes around `origin`, ignoring
8
+ * attributes on `<html>` because those already inherit into `document.body`.
8
9
  */
9
10
  export declare function readThemeScope(origin: Element | null | undefined): ThemeScope;
10
11
  /**
11
- * Mirrors the nearest subtree `[data-theme]` and `[data-xds-theme]` onto `target` (typically a
12
- * portaled overlay wrapper in `document.body`) and keeps them synchronized when ancestors change.
12
+ * Mirrors the nearest subtree `[data-theme]`, `[data-xds-theme]` and `[data-contrast]` onto
13
+ * `target` (typically a portaled overlay wrapper in `document.body`) and keeps them synchronized
14
+ * when ancestors change.
13
15
  */
14
16
  export declare function syncThemeScope(origin: Element | null | undefined, target: HTMLElement | null | undefined): () => void;
15
17
  /**
@@ -1,28 +1,31 @@
1
1
  const MODE_ATTR = "data-theme";
2
2
  const THEME_ATTR = "data-xds-theme";
3
+ const CONTRAST_ATTR = "data-contrast";
3
4
  export function readThemeScope(origin) {
4
5
  if (!origin || typeof document === "undefined")
5
6
  return {};
6
7
  const root = document.documentElement;
7
- const modeHost = origin.closest(`[${MODE_ATTR}]`);
8
- const themeHost = origin.closest(`[${THEME_ATTR}]`);
9
- const mode = modeHost && modeHost !== root ? (modeHost.getAttribute(MODE_ATTR) ?? undefined) : undefined;
10
- const theme = themeHost && themeHost !== root ? (themeHost.getAttribute(THEME_ATTR) ?? undefined) : undefined;
11
- return { mode, theme };
8
+ const read = (name) => {
9
+ const host = origin.closest(`[${name}]`);
10
+ return host && host !== root ? (host.getAttribute(name) ?? undefined) : undefined;
11
+ };
12
+ return { mode: read(MODE_ATTR), theme: read(THEME_ATTR), contrast: read(CONTRAST_ATTR) };
12
13
  }
13
14
  export function syncThemeScope(origin, target) {
14
15
  if (!origin || !target || typeof document === "undefined")
15
16
  return () => { };
16
17
  const apply = () => {
17
- const { mode, theme } = readThemeScope(origin);
18
- if (mode !== undefined)
19
- target.setAttribute(MODE_ATTR, mode);
20
- else
21
- target.removeAttribute(MODE_ATTR);
22
- if (theme !== undefined)
23
- target.setAttribute(THEME_ATTR, theme);
24
- else
25
- target.removeAttribute(THEME_ATTR);
18
+ const scope = readThemeScope(origin);
19
+ for (const [name, value] of [
20
+ [MODE_ATTR, scope.mode],
21
+ [THEME_ATTR, scope.theme],
22
+ [CONTRAST_ATTR, scope.contrast],
23
+ ]) {
24
+ if (value !== undefined)
25
+ target.setAttribute(name, value);
26
+ else
27
+ target.removeAttribute(name);
28
+ }
26
29
  };
27
30
  apply();
28
31
  if (typeof MutationObserver === "undefined")
@@ -30,7 +33,10 @@ export function syncThemeScope(origin, target) {
30
33
  const observer = new MutationObserver(apply);
31
34
  let node = origin;
32
35
  while (node && node !== document.documentElement) {
33
- observer.observe(node, { attributes: true, attributeFilter: [MODE_ATTR, THEME_ATTR] });
36
+ observer.observe(node, {
37
+ attributes: true,
38
+ attributeFilter: [MODE_ATTR, THEME_ATTR, CONTRAST_ATTR],
39
+ });
34
40
  node = node.parentElement;
35
41
  }
36
42
  return () => observer.disconnect();
@@ -0,0 +1,57 @@
1
+ import type { SelectOption } from "./select.ts";
2
+ /** A time of day without a date or a time zone, as `HH:MM` on a 24-hour clock. */
3
+ export type IsoTime = string;
4
+ /** TimePicker's props in every framework, short of `onChange`. */
5
+ export type TimePickerBaseProps = {
6
+ /** Always visible, like a TextField's. */
7
+ label: string;
8
+ /**
9
+ * The chosen time, `undefined` while none is chosen. Leave it out for a picker that keeps its
10
+ * own choice, from `defaultValue`: it is controlled whenever `value` is given, even as
11
+ * `undefined`.
12
+ */
13
+ value?: IsoTime | undefined;
14
+ /** The first choice of a picker that keeps its own, without `value`. */
15
+ defaultValue?: IsoTime | undefined;
16
+ /** The first time offered. Midnight unless set. */
17
+ min?: IsoTime | undefined;
18
+ /** The last time that may be offered. A minute to midnight unless set. */
19
+ max?: IsoTime | undefined;
20
+ /** Minutes from one time offered to the next, from `min`. 30 unless set. */
21
+ step?: number;
22
+ /** Shown in the field while no time is chosen. */
23
+ placeholder?: string;
24
+ /** Help shown under the field. Replaced by `error` while there is one. */
25
+ description?: string;
26
+ /** What is wrong and how to fix it. Clear it when the value changes. */
27
+ error?: string | undefined;
28
+ /** The name the time is submitted under with a form, as `HH:MM`. */
29
+ name?: string;
30
+ disabled?: boolean;
31
+ /** Formats the times in a fixed locale (avoids SSR locale mismatches). */
32
+ locale?: string;
33
+ };
34
+ export declare const TIME_PICKER_DEFAULT_STEP = 30;
35
+ /** Minutes after midnight of a strict `HH:MM` time, or `undefined` for anything else. */
36
+ export declare function parseIsoTime(value: IsoTime | undefined): number | undefined;
37
+ /** Minutes after midnight written as `HH:MM`. */
38
+ export declare function isoTime(minutes: number): IsoTime;
39
+ /**
40
+ * The time as the field and the list show it: the locale's hours and minutes, on its own clock
41
+ * ("9:30 AM", "09:30", "오전 9:30"). Formatted in UTC, so no time zone moves it.
42
+ */
43
+ export declare function formatTime(value: IsoTime, locale: string): string;
44
+ /**
45
+ * The times a picker offers: from `min` to `max`, `step` minutes apart. A step that is not a
46
+ * whole number of minutes from 1 to a day is taken as 30. A chosen time between two steps, or
47
+ * outside them, is offered too, in its place, so the field and the list both show it.
48
+ */
49
+ export declare function timeOptions({ min, max, step, value }: Pick<TimePickerBaseProps, "min" | "max" | "step" | "value">, locale: string): SelectOption<IsoTime>[];
50
+ /** The locale times are shown in: the given one, or the browser's. */
51
+ export declare function timePickerLocale(locale?: string): string;
52
+ /** The ids of the parts the library names itself, under the TimePicker's own id. */
53
+ export declare function timePickerIds(id: string): {
54
+ value: string;
55
+ description: string;
56
+ error: string;
57
+ };
@@ -0,0 +1,53 @@
1
+ export const TIME_PICKER_DEFAULT_STEP = 30;
2
+ const MINUTES_IN_DAY = 24 * 60;
3
+ export function parseIsoTime(value) {
4
+ const match = value === undefined ? null : /^(\d{2}):(\d{2})$/.exec(value);
5
+ if (!match)
6
+ return undefined;
7
+ const hours = Number(match[1]);
8
+ const minutes = Number(match[2]);
9
+ return hours < 24 && minutes < 60 ? hours * 60 + minutes : undefined;
10
+ }
11
+ export function isoTime(minutes) {
12
+ const hours = Math.floor(minutes / 60);
13
+ return `${String(hours).padStart(2, "0")}:${String(minutes % 60).padStart(2, "0")}`;
14
+ }
15
+ export function formatTime(value, locale) {
16
+ const minutes = parseIsoTime(value);
17
+ if (minutes === undefined)
18
+ return "";
19
+ return new Intl.DateTimeFormat(locale, {
20
+ hour: "numeric",
21
+ minute: "2-digit",
22
+ timeZone: "UTC",
23
+ }).format(new Date(Date.UTC(2000, 0, 1, Math.floor(minutes / 60), minutes % 60)));
24
+ }
25
+ export function timeOptions({ min, max, step, value }, locale) {
26
+ const first = parseIsoTime(min) ?? 0;
27
+ const last = parseIsoTime(max) ?? MINUTES_IN_DAY - 1;
28
+ const every = step !== undefined && Number.isInteger(step) && step >= 1 && step <= MINUTES_IN_DAY
29
+ ? step
30
+ : TIME_PICKER_DEFAULT_STEP;
31
+ const times = [];
32
+ for (let minutes = first; minutes <= last; minutes += every)
33
+ times.push(minutes);
34
+ const chosen = parseIsoTime(value);
35
+ if (chosen !== undefined && !times.includes(chosen)) {
36
+ times.push(chosen);
37
+ times.sort((a, b) => a - b);
38
+ }
39
+ return times.map((minutes) => {
40
+ const time = isoTime(minutes);
41
+ return { value: time, label: formatTime(time, locale) };
42
+ });
43
+ }
44
+ export function timePickerLocale(locale) {
45
+ return locale ?? (typeof navigator === "undefined" ? "en-US" : navigator.language);
46
+ }
47
+ export function timePickerIds(id) {
48
+ return {
49
+ value: `${id}-value`,
50
+ description: `${id}-description`,
51
+ error: `${id}-error`,
52
+ };
53
+ }
@@ -0,0 +1,40 @@
1
+ import type { ToastAction } from "./toast.ts";
2
+ /** A toast in a ToastQueue: what Toast shows, with the id the queue reports it by. */
3
+ export type QueuedToast = {
4
+ /** Names the toast to the app, in `onClose`. */
5
+ id: string | number;
6
+ message: string;
7
+ /** One thing the person can do about the message, such as undoing it. */
8
+ action?: ToastAction;
9
+ /** How long it stays once it shows, in milliseconds. 0 keeps it until the app removes it. */
10
+ duration?: number;
11
+ };
12
+ /** ToastQueue's props in every framework, short of `onClose`. */
13
+ export type ToastQueueBaseProps = {
14
+ /**
15
+ * The toasts to show, oldest first. The queue shows the first, and the rest wait their turn.
16
+ * Add one with `queueToast`, and take one out when the queue closes it.
17
+ */
18
+ toasts: readonly QueuedToast[];
19
+ };
20
+ /**
21
+ * How many toasts wait behind the one shown. A toast says what just happened, and one that has
22
+ * waited behind three others, for several seconds each, no longer does: `queueToast` lets the
23
+ * oldest that waits make way for a new one.
24
+ */
25
+ export declare const TOAST_QUEUE_WAITING = 3;
26
+ /**
27
+ * `toasts` with `toast` added at the end. The one shown, the first, stays; one that says what
28
+ * the last to wait says takes that one's place, so a save repeated five times leaves one
29
+ * "Saved" waiting, not five; and no more than `TOAST_QUEUE_WAITING` wait, the oldest making way.
30
+ */
31
+ export declare function queueToast<T extends QueuedToast>(toasts: readonly T[], toast: T): T[];
32
+ /**
33
+ * What a queue shows: the toast it shows, if any. A queue shows the first toast; when the app
34
+ * takes that one out it closes, and the next comes `motion.duration.normal` later, not at once:
35
+ * the time a toast takes to leave where it slides away, so the two are never on screen together
36
+ * or read as one, a screen reader announces the next as a message of its own, and the next
37
+ * one's time starts afresh. `visible` is the id of the toast on screen, which the
38
+ * queue keeps, and the result is what it does next.
39
+ */
40
+ export declare function toastQueueStep(toasts: readonly QueuedToast[], visible: QueuedToast["id"] | undefined): "keep" | "close" | "wait" | "idle";
@@ -0,0 +1,17 @@
1
+ export const TOAST_QUEUE_WAITING = 3;
2
+ export function queueToast(toasts, toast) {
3
+ const [shown, ...waiting] = toasts;
4
+ if (shown === undefined)
5
+ return [toast];
6
+ const last = waiting.at(-1);
7
+ const next = last !== undefined && last.message === toast.message
8
+ ? [...waiting.slice(0, -1), toast]
9
+ : [...waiting, toast];
10
+ return [shown, ...next.slice(-TOAST_QUEUE_WAITING)];
11
+ }
12
+ export function toastQueueStep(toasts, visible) {
13
+ const first = toasts[0];
14
+ if (visible !== undefined)
15
+ return first?.id === visible ? "keep" : "close";
16
+ return first === undefined ? "idle" : "wait";
17
+ }