@xds/core 1.1.0 → 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 (90) hide show
  1. package/dist/breadcrumb.d.ts +39 -0
  2. package/dist/breadcrumb.js +7 -0
  3. package/dist/checkbox.d.ts +16 -2
  4. package/dist/checkbox.js +3 -1
  5. package/dist/combobox.d.ts +59 -0
  6. package/dist/combobox.js +40 -0
  7. package/dist/index.d.ts +16 -7
  8. package/dist/index.js +15 -6
  9. package/dist/labels.d.ts +12 -5
  10. package/dist/labels.js +12 -5
  11. package/dist/link.d.ts +49 -0
  12. package/dist/link.js +12 -0
  13. package/dist/pagination.d.ts +51 -0
  14. package/dist/pagination.js +25 -0
  15. package/dist/popover.d.ts +33 -0
  16. package/dist/popover.js +8 -0
  17. package/dist/preview/components.d.ts +36 -0
  18. package/dist/preview/components.js +1 -0
  19. package/dist/preview/design.d.ts +22 -3
  20. package/dist/preview/design.js +65 -34
  21. package/dist/preview/fixtures.d.ts +0 -76
  22. package/dist/preview/fixtures.js +0 -126
  23. package/dist/preview/kit.d.ts +48 -32
  24. package/dist/preview/kit.js +3 -0
  25. package/dist/preview/page.d.ts +1 -1
  26. package/dist/preview/page.js +1 -0
  27. package/dist/preview/sections/accordion.d.ts +1 -0
  28. package/dist/preview/sections/accordion.js +40 -0
  29. package/dist/preview/sections/badges.d.ts +1 -0
  30. package/dist/preview/sections/badges.js +13 -0
  31. package/dist/preview/sections/banners.d.ts +1 -0
  32. package/dist/preview/sections/banners.js +13 -0
  33. package/dist/preview/sections/buttons.d.ts +2 -0
  34. package/dist/preview/sections/buttons.js +30 -0
  35. package/dist/preview/sections/card.d.ts +1 -0
  36. package/dist/preview/sections/card.js +33 -0
  37. package/dist/preview/sections/chips.d.ts +1 -0
  38. package/dist/preview/sections/chips.js +23 -0
  39. package/dist/preview/sections/controls.d.ts +1 -0
  40. package/dist/preview/sections/controls.js +143 -0
  41. package/dist/preview/sections/dialog.d.ts +1 -0
  42. package/dist/preview/sections/dialog.js +25 -0
  43. package/dist/preview/sections/empty-state.d.ts +1 -0
  44. package/dist/preview/sections/empty-state.js +13 -0
  45. package/dist/preview/sections/links.d.ts +1 -0
  46. package/dist/preview/sections/links.js +8 -0
  47. package/dist/preview/sections/list.d.ts +1 -0
  48. package/dist/preview/sections/list.js +119 -0
  49. package/dist/preview/sections/media.d.ts +1 -0
  50. package/dist/preview/sections/media.js +90 -0
  51. package/dist/preview/sections/menu.d.ts +1 -0
  52. package/dist/preview/sections/menu.js +46 -0
  53. package/dist/preview/sections/navigation.d.ts +1 -0
  54. package/dist/preview/sections/navigation.js +20 -0
  55. package/dist/preview/sections/selection.d.ts +1 -0
  56. package/dist/preview/sections/selection.js +33 -0
  57. package/dist/preview/sections/sidebar.d.ts +1 -0
  58. package/dist/preview/sections/sidebar.js +45 -0
  59. package/dist/preview/sections/skeleton.d.ts +1 -0
  60. package/dist/preview/sections/skeleton.js +5 -0
  61. package/dist/preview/sections/tabs.d.ts +1 -0
  62. package/dist/preview/sections/tabs.js +24 -0
  63. package/dist/preview/sections/text-fields.d.ts +1 -0
  64. package/dist/preview/sections/text-fields.js +75 -0
  65. package/dist/preview/sections/toast.d.ts +2 -0
  66. package/dist/preview/sections/toast.js +28 -0
  67. package/dist/preview/specimens.js +1 -1
  68. package/dist/progress-bar.d.ts +7 -4
  69. package/dist/progress-bar.js +2 -2
  70. package/dist/rows.d.ts +23 -0
  71. package/dist/rows.js +67 -0
  72. package/dist/segmented-control.d.ts +1 -1
  73. package/dist/segmented-control.js +1 -1
  74. package/dist/select.d.ts +22 -0
  75. package/dist/select.js +7 -0
  76. package/dist/switch.d.ts +1 -1
  77. package/dist/switch.js +2 -1
  78. package/dist/table.d.ts +62 -0
  79. package/dist/table.js +25 -0
  80. package/dist/theme-scope.d.ts +6 -4
  81. package/dist/theme-scope.js +21 -15
  82. package/dist/time-picker.d.ts +57 -0
  83. package/dist/time-picker.js +53 -0
  84. package/dist/toast-queue.d.ts +40 -0
  85. package/dist/toast-queue.js +17 -0
  86. package/dist/toast.d.ts +1 -1
  87. package/dist/toast.js +1 -1
  88. package/package.json +2 -2
  89. package/dist/preview/sections.d.ts +0 -20
  90. package/dist/preview/sections.js +0 -517
@@ -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
+ }
package/dist/toast.d.ts CHANGED
@@ -15,7 +15,7 @@ export type ToastBaseProps = {
15
15
  };
16
16
  export declare const TOAST_PARTS: {
17
17
  readonly region: "pointer-events-none fixed inset-x-0 top-auto bottom-0 m-0 w-full max-w-none justify-center overflow-visible border-0 bg-transparent p-4 pb-[calc(var(--xds-space-4)+env(safe-area-inset-bottom))] [&:popover-open]:flex";
18
- readonly toast: "pointer-events-auto flex max-w-xds-toast animate-[xds-toast-enter_var(--xds-motion-duration-normal)_var(--xds-motion-easing-enter)] items-center gap-4 rounded-xds-md bg-xds-toast-background px-4 py-3 text-xds-toast-text shadow-xds-raised motion-reduce:animate-none";
18
+ readonly toast: "pointer-events-auto flex max-w-xds-toast animate-[xds-toast-enter_var(--xds-motion-duration-normal)_var(--xds-motion-easing-enter)] items-center gap-4 rounded-xds-md bg-xds-toast-background px-4 py-3 text-xds-toast-text shadow-xds-raised motion-reduce:animate-none forced-colors:outline forced-colors:outline-(length:--xds-border-width-thin) forced-colors:outline-[CanvasText]";
19
19
  readonly message: "min-w-0 text-xds-detail";
20
20
  readonly action: "-my-2 min-h-xds-target-min min-w-xds-target-min shrink-0 cursor-pointer rounded-xds-sm text-xds-label text-xds-toast-action hover:underline focus-visible:outline-solid focus-visible:outline-(length:--xds-focus-width) focus-visible:outline-offset-(--xds-focus-offset) focus-visible:outline-current";
21
21
  };
package/dist/toast.js CHANGED
@@ -1,6 +1,6 @@
1
1
  export const TOAST_PARTS = {
2
2
  region: "pointer-events-none fixed inset-x-0 top-auto bottom-0 m-0 w-full max-w-none justify-center overflow-visible border-0 bg-transparent p-4 pb-[calc(var(--xds-space-4)+env(safe-area-inset-bottom))] [&:popover-open]:flex",
3
- toast: "pointer-events-auto flex max-w-xds-toast animate-[xds-toast-enter_var(--xds-motion-duration-normal)_var(--xds-motion-easing-enter)] items-center gap-4 rounded-xds-md bg-xds-toast-background px-4 py-3 text-xds-toast-text shadow-xds-raised motion-reduce:animate-none",
3
+ toast: "pointer-events-auto flex max-w-xds-toast animate-[xds-toast-enter_var(--xds-motion-duration-normal)_var(--xds-motion-easing-enter)] items-center gap-4 rounded-xds-md bg-xds-toast-background px-4 py-3 text-xds-toast-text shadow-xds-raised motion-reduce:animate-none forced-colors:outline forced-colors:outline-(length:--xds-border-width-thin) forced-colors:outline-[CanvasText]",
4
4
  message: "min-w-0 text-xds-detail",
5
5
  action: "-my-2 min-h-xds-target-min min-w-xds-target-min shrink-0 cursor-pointer rounded-xds-sm text-xds-label text-xds-toast-action hover:underline focus-visible:outline-solid focus-visible:outline-(length:--xds-focus-width) focus-visible:outline-offset-(--xds-focus-offset) focus-visible:outline-current",
6
6
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xds/core",
3
- "version": "1.1.0",
3
+ "version": "1.2.0",
4
4
  "description": "What the xds web component libraries share: prop types, class recipes and DOM helpers. Install a framework's package instead.",
5
5
  "keywords": [
6
6
  "design-system",
@@ -34,7 +34,7 @@
34
34
  "dist"
35
35
  ],
36
36
  "dependencies": {
37
- "@xds/tokens": "1.1.0",
37
+ "@xds/tokens": "1.2.0",
38
38
  "@internationalized/date": "3.12.4",
39
39
  "@zag-js/date-picker": "2.0.0-next.4"
40
40
  },
@@ -1,20 +0,0 @@
1
- import { type DesignState } from "./kit.ts";
2
- import type { Overlay } from "./page.ts";
3
- export declare const buttons: (open: Overlay | undefined) => import("./model.ts").PreviewNode<DesignState>[];
4
- export declare const textFields: () => import("./model.ts").PreviewNode<DesignState>[];
5
- export declare const selection: () => import("./model.ts").PreviewNode<DesignState>[];
6
- export declare const controls: () => import("./model.ts").PreviewNode<DesignState>[];
7
- export declare const chips: () => import("./model.ts").PreviewNode<DesignState>[];
8
- export declare const tabs: () => import("./model.ts").PreviewNode<DesignState>[];
9
- export declare const badges: () => import("./model.ts").PreviewNode<DesignState>[];
10
- export declare const banners: () => import("./model.ts").PreviewNode<DesignState>[];
11
- export declare const card: () => import("./model.ts").PreviewNode<DesignState>[];
12
- export declare const media: () => import("./model.ts").PreviewNode<DesignState>[];
13
- export declare const list: () => import("./model.ts").PreviewNode<DesignState>[];
14
- export declare const sidebar: () => import("./model.ts").PreviewNode<DesignState>[];
15
- export declare const accordion: () => import("./model.ts").PreviewNode<DesignState>[];
16
- export declare const menu: () => import("./model.ts").PreviewNode<DesignState>[];
17
- export declare const dialog: () => import("./model.ts").PreviewNode<DesignState>[];
18
- export declare const toast: (open: Overlay | undefined) => import("./model.ts").PreviewNode<DesignState>[];
19
- export declare const skeleton: () => import("./model.ts").PreviewNode<DesignState>[];
20
- export declare const emptyState: () => import("./model.ts").PreviewNode<DesignState>[];