@xds/core 0.0.0-stage → 0.1.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 (109) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +4 -2
  3. package/dist/accordion.d.ts +38 -0
  4. package/dist/accordion.js +32 -0
  5. package/dist/animation.d.ts +10 -0
  6. package/dist/animation.js +11 -0
  7. package/dist/avatar-stack.d.ts +29 -0
  8. package/dist/avatar-stack.js +23 -0
  9. package/dist/avatar.d.ts +23 -0
  10. package/dist/avatar.js +18 -0
  11. package/dist/badge.d.ts +21 -0
  12. package/dist/badge.js +12 -0
  13. package/dist/banner.d.ts +45 -0
  14. package/dist/banner.js +40 -0
  15. package/dist/button.d.ts +95 -0
  16. package/dist/button.js +25 -0
  17. package/dist/card.d.ts +29 -0
  18. package/dist/card.js +20 -0
  19. package/dist/checkbox.d.ts +20 -0
  20. package/dist/checkbox.js +5 -0
  21. package/dist/chip-bar.d.ts +11 -0
  22. package/dist/chip-bar.js +1 -0
  23. package/dist/chip.d.ts +21 -0
  24. package/dist/chip.js +8 -0
  25. package/dist/count-badge.d.ts +18 -0
  26. package/dist/count-badge.js +9 -0
  27. package/dist/date-picker.d.ts +136 -0
  28. package/dist/date-picker.js +117 -0
  29. package/dist/date-range-picker.d.ts +156 -0
  30. package/dist/date-range-picker.js +146 -0
  31. package/dist/defaults.d.ts +78 -0
  32. package/dist/defaults.js +28 -0
  33. package/dist/dialog.d.ts +12 -0
  34. package/dist/dialog.js +0 -0
  35. package/dist/divider.d.ts +2 -0
  36. package/dist/divider.js +1 -0
  37. package/dist/empty-state.d.ts +17 -0
  38. package/dist/empty-state.js +7 -0
  39. package/dist/escape.d.ts +5 -0
  40. package/dist/escape.js +4 -0
  41. package/dist/focus.d.ts +7 -0
  42. package/dist/focus.js +5 -0
  43. package/dist/icon.d.ts +26 -0
  44. package/dist/icon.js +10 -0
  45. package/dist/index.d.ts +43 -0
  46. package/dist/index.js +40 -0
  47. package/dist/initials.d.ts +2 -0
  48. package/dist/initials.js +8 -0
  49. package/dist/list-row.d.ts +40 -0
  50. package/dist/list-row.js +27 -0
  51. package/dist/media-card.d.ts +51 -0
  52. package/dist/media-card.js +23 -0
  53. package/dist/menu.d.ts +50 -0
  54. package/dist/menu.js +25 -0
  55. package/dist/page-keys.d.ts +19 -0
  56. package/dist/page-keys.js +22 -0
  57. package/dist/parts.d.ts +9 -0
  58. package/dist/parts.js +6 -0
  59. package/dist/preview/components.d.ts +218 -0
  60. package/dist/preview/components.js +11 -0
  61. package/dist/preview/design.d.ts +22 -0
  62. package/dist/preview/design.js +97 -0
  63. package/dist/preview/fixtures.d.ts +80 -0
  64. package/dist/preview/fixtures.js +131 -0
  65. package/dist/preview/index.d.ts +3 -0
  66. package/dist/preview/index.js +3 -0
  67. package/dist/preview/kit.d.ts +53 -0
  68. package/dist/preview/kit.js +5 -0
  69. package/dist/preview/model.d.ts +135 -0
  70. package/dist/preview/model.js +84 -0
  71. package/dist/preview/page.d.ts +34 -0
  72. package/dist/preview/page.js +39 -0
  73. package/dist/preview/sections.d.ts +20 -0
  74. package/dist/preview/sections.js +517 -0
  75. package/dist/preview/specimens.d.ts +4 -0
  76. package/dist/preview/specimens.js +29 -0
  77. package/dist/progress-bar.d.ts +13 -0
  78. package/dist/progress-bar.js +5 -0
  79. package/dist/radio-group.d.ts +20 -0
  80. package/dist/radio-group.js +0 -0
  81. package/dist/section-header.d.ts +22 -0
  82. package/dist/section-header.js +11 -0
  83. package/dist/segmented-control.d.ts +21 -0
  84. package/dist/segmented-control.js +8 -0
  85. package/dist/select.d.ts +31 -0
  86. package/dist/select.js +4 -0
  87. package/dist/sidebar.d.ts +45 -0
  88. package/dist/sidebar.js +30 -0
  89. package/dist/skeleton.d.ts +21 -0
  90. package/dist/skeleton.js +24 -0
  91. package/dist/slider.d.ts +49 -0
  92. package/dist/slider.js +22 -0
  93. package/dist/spinner.d.ts +14 -0
  94. package/dist/spinner.js +8 -0
  95. package/dist/switch.d.ts +21 -0
  96. package/dist/switch.js +5 -0
  97. package/dist/tabs.d.ts +24 -0
  98. package/dist/tabs.js +8 -0
  99. package/dist/text-field.d.ts +35 -0
  100. package/dist/text-field.js +0 -0
  101. package/dist/text.d.ts +29 -0
  102. package/dist/text.js +22 -0
  103. package/dist/thumbnail.d.ts +33 -0
  104. package/dist/thumbnail.js +22 -0
  105. package/dist/toast.d.ts +21 -0
  106. package/dist/toast.js +6 -0
  107. package/dist/tooltip.d.ts +15 -0
  108. package/dist/tooltip.js +3 -0
  109. package/package.json +42 -4
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 kjmin-dev
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,5 @@
1
- # Temporary Holding Version
1
+ # @xds/core
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ What the xds web component libraries share. Install the package for your framework instead: `@xds/react`, `@xds/solid`, `@xds/vue` or `@xds/svelte`.
4
+
5
+ See [xds as a library](https://github.com/kjmin-dev/xds/blob/main/docs/library.md).
@@ -0,0 +1,38 @@
1
+ /** An item of an Accordion in every framework, short of its body. */
2
+ export type AccordionItemBase<Value extends string = string> = {
3
+ value: Value;
4
+ title: string;
5
+ /** A line under the title, shown whether the item is open or not. */
6
+ description?: string;
7
+ };
8
+ /** Accordion's props in every framework, short of its items and `onChange`. */
9
+ export type AccordionBaseProps<Value extends string = string> = {
10
+ /** The values of the open items. */
11
+ expanded: readonly Value[];
12
+ /** Lets several items be open at once. Without it, opening one closes the others. */
13
+ multiple?: boolean;
14
+ };
15
+ export declare const ACCORDION_PARTS: {
16
+ /** The title and the description, beside the chevron. */
17
+ readonly text: "flex min-w-0 flex-1 flex-col gap-0.5";
18
+ readonly title: "text-xds-body-strong text-xds-text-primary";
19
+ readonly description: "text-xds-detail text-xds-text-secondary";
20
+ readonly chevron: "text-xds-accordion-icon transition-transform duration-(--xds-motion-duration-normal) ease-(--xds-motion-easing-standard) group-aria-expanded:rotate-180 motion-reduce:transition-none";
21
+ };
22
+ /**
23
+ * Opens or closes an item's panel (`.xds-accordion__panel`): its height moves between zero and the
24
+ * height of what it holds, and it is hidden only once it has finished closing, with
25
+ * `hidden="until-found"`, so the browser's find in page still opens it. Call it on every change
26
+ * of `open`, with `animate` false the first time, when there is nothing to move from. Returns
27
+ * the function that stops the change from settling: call it before the next change, which
28
+ * takes over.
29
+ */
30
+ export declare function setPanelOpen(panel: HTMLElement, open: boolean, animate: boolean): () => void;
31
+ /**
32
+ * For a click on an item's title, ahead of Zag's handler. Zag toggles the item only while its
33
+ * title has the focus, which a press gives it but a click from a script or from assistive
34
+ * technology does not. Focused here first, the title takes those clicks too.
35
+ */
36
+ export declare function focusTitleOnClick(event: {
37
+ currentTarget: EventTarget | null;
38
+ }): void;
@@ -0,0 +1,32 @@
1
+ import { afterAnimations } from "./animation.js";
2
+ import { focusWithoutRing } from "./focus.js";
3
+ export const ACCORDION_PARTS = {
4
+ text: "flex min-w-0 flex-1 flex-col gap-0.5",
5
+ title: "text-xds-body-strong text-xds-text-primary",
6
+ description: "text-xds-detail text-xds-text-secondary",
7
+ chevron: "text-xds-accordion-icon transition-transform duration-(--xds-motion-duration-normal) ease-(--xds-motion-easing-standard) group-aria-expanded:rotate-180 motion-reduce:transition-none",
8
+ };
9
+ export function setPanelOpen(panel, open, animate) {
10
+ const height = (value) => panel.style.setProperty("--accordion-panel-height", value);
11
+ if (!animate) {
12
+ if (open)
13
+ panel.removeAttribute("hidden");
14
+ else
15
+ panel.setAttribute("hidden", "until-found");
16
+ height(open ? "auto" : "0px");
17
+ return () => { };
18
+ }
19
+ if (open) {
20
+ panel.removeAttribute("hidden");
21
+ height(`${panel.scrollHeight}px`);
22
+ return afterAnimations([panel], () => height("auto"));
23
+ }
24
+ height(`${panel.scrollHeight}px`);
25
+ void getComputedStyle(panel).height;
26
+ height("0px");
27
+ return afterAnimations([panel], () => panel.setAttribute("hidden", "until-found"));
28
+ }
29
+ export function focusTitleOnClick(event) {
30
+ if (event.currentTarget instanceof HTMLElement)
31
+ focusWithoutRing(event.currentTarget);
32
+ }
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Calls `done` once the animations and transitions running on the elements themselves have
3
+ * finished, or in a microtask when none is running, as under reduced motion. An overlay marked
4
+ * closed leaves the page this way only after its exit animation, which the stylesheet starts
5
+ * on `[data-state="closed"]`, and an accordion panel is hidden only once it has closed.
6
+ *
7
+ * Returns the function that stops waiting: call it when the next change takes over, since the
8
+ * animation it cuts short counts as finished.
9
+ */
10
+ export declare function afterAnimations(elements: readonly (Element | null | undefined)[], done: () => void): () => void;
@@ -0,0 +1,11 @@
1
+ export function afterAnimations(elements, done) {
2
+ let waiting = true;
3
+ const running = elements.flatMap((element) => element?.getAnimations() ?? []);
4
+ void Promise.allSettled(running.map((animation) => animation.finished)).then(() => {
5
+ if (waiting)
6
+ done();
7
+ });
8
+ return () => {
9
+ waiting = false;
10
+ };
11
+ }
@@ -0,0 +1,29 @@
1
+ import { type AvatarSize } from "./avatar.ts";
2
+ /** AvatarStack's props in every framework. */
3
+ export type AvatarStackBaseProps = {
4
+ people: readonly {
5
+ name: string;
6
+ src?: string | undefined;
7
+ }[];
8
+ /** How many avatars to draw. The rest are counted in a "+3" at the end. */
9
+ max?: number;
10
+ size?: AvatarSize;
11
+ /** Replaces the list of names that assistive technology reads. */
12
+ label?: string;
13
+ };
14
+ export declare const avatarStackClass = "inline-flex shrink-0 items-center";
15
+ /** The ring around each avatar of the stack. */
16
+ export declare function avatarStackItemClass(size?: AvatarSize): string;
17
+ /** The "+3" after the avatars, in an avatar's box. */
18
+ export declare function avatarStackRestClass(size?: AvatarSize): string;
19
+ /**
20
+ * The avatars drawn, how many people the "+3" counts, and the name of the whole stack, which
21
+ * includes those who did not fit.
22
+ */
23
+ export declare function avatarStack<Person extends {
24
+ name: string;
25
+ }>(people: readonly Person[], max?: number, label?: string): {
26
+ shown: readonly Person[];
27
+ rest: number;
28
+ name: string;
29
+ };
@@ -0,0 +1,23 @@
1
+ import { AVATAR_SIZE } from "./avatar.js";
2
+ const OVERLAP = {
3
+ sm: "not-first:ms-[calc(var(--xds-size-avatar-sm)/-4)]",
4
+ md: "not-first:ms-[calc(var(--xds-size-avatar-md)/-4)]",
5
+ lg: "not-first:ms-[calc(var(--xds-size-avatar-lg)/-4)]",
6
+ xl: "not-first:ms-[calc(var(--xds-size-avatar-xl)/-4)]",
7
+ };
8
+ const RING = "rounded-full outline-solid outline-(length:--xds-border-width-thick) outline-xds-avatar-ring";
9
+ export const avatarStackClass = "inline-flex shrink-0 items-center";
10
+ export function avatarStackItemClass(size = "md") {
11
+ return `inline-flex ${RING} ${OVERLAP[size]}`;
12
+ }
13
+ export function avatarStackRestClass(size = "md") {
14
+ return `inline-flex select-none items-center justify-center bg-xds-avatar-overflow-background text-xds-avatar-overflow-text ${AVATAR_SIZE[size]} ${RING} ${OVERLAP[size]}`;
15
+ }
16
+ export function avatarStack(people, max = 4, label) {
17
+ const shown = people.slice(0, max);
18
+ return {
19
+ shown,
20
+ rest: people.length - shown.length,
21
+ name: label ?? people.map((person) => person.name).join(", "),
22
+ };
23
+ }
@@ -0,0 +1,23 @@
1
+ export declare const AVATAR_SIZE: {
2
+ readonly sm: "size-xds-avatar-sm text-xds-footnote";
3
+ readonly md: "size-xds-avatar-md text-xds-label";
4
+ readonly lg: "size-xds-avatar-lg text-xds-body-strong";
5
+ readonly xl: "size-xds-avatar-xl text-xds-title";
6
+ };
7
+ export type AvatarSize = keyof typeof AVATAR_SIZE;
8
+ /** Avatar's props in every framework. */
9
+ export type AvatarBaseProps = {
10
+ name: string;
11
+ /** The URL of a picture. The initials show while it loads, and stay if it fails. */
12
+ src?: string | undefined;
13
+ size?: AvatarSize;
14
+ };
15
+ export declare function avatarClass(size?: AvatarSize): string;
16
+ /** The letters an avatar of `size` shows: the small size has room for one. */
17
+ export declare function avatarInitials(name: string, size?: AvatarSize): string;
18
+ /**
19
+ * The class of a picture over a placeholder: Avatar's initials, Thumbnail's icon. It is not
20
+ * shown until it has loaded: a picture that is half there, or broken, would cover the
21
+ * placeholder with nothing.
22
+ */
23
+ export declare function pictureClass(loaded: boolean): string;
package/dist/avatar.js ADDED
@@ -0,0 +1,18 @@
1
+ import { initials } from "./initials.js";
2
+ export const AVATAR_SIZE = {
3
+ sm: "size-xds-avatar-sm text-xds-footnote",
4
+ md: "size-xds-avatar-md text-xds-label",
5
+ lg: "size-xds-avatar-lg text-xds-body-strong",
6
+ xl: "size-xds-avatar-xl text-xds-title",
7
+ };
8
+ export function avatarClass(size = "md") {
9
+ return `relative inline-flex shrink-0 select-none items-center justify-center overflow-hidden rounded-full bg-xds-avatar-background text-xds-avatar-text ${AVATAR_SIZE[size]}`;
10
+ }
11
+ export function avatarInitials(name, size = "md") {
12
+ return initials(name, size === "sm" ? 1 : 2);
13
+ }
14
+ export function pictureClass(loaded) {
15
+ return loaded
16
+ ? "absolute inset-0 size-full object-cover"
17
+ : "invisible absolute inset-0 size-full object-cover";
18
+ }
@@ -0,0 +1,21 @@
1
+ import type { IconName } from "@xds/tokens";
2
+ declare const TONE: {
3
+ readonly neutral: "bg-xds-badge-neutral-background text-xds-badge-neutral-text";
4
+ readonly accent: "bg-xds-badge-accent-background text-xds-badge-accent-text";
5
+ readonly success: "bg-xds-badge-success-background text-xds-badge-success-text";
6
+ readonly warning: "bg-xds-badge-warning-background text-xds-badge-warning-text";
7
+ readonly danger: "bg-xds-badge-danger-background text-xds-badge-danger-text";
8
+ /** For a badge that sits on a picture: the same in both color modes. */
9
+ readonly overlay: "bg-xds-badge-overlay-background text-xds-badge-overlay-text";
10
+ };
11
+ export type BadgeTone = keyof typeof TONE;
12
+ /** Badge's props in every framework, short of its words. */
13
+ export type BadgeBaseProps = {
14
+ tone?: BadgeTone;
15
+ dot?: boolean;
16
+ icon?: IconName;
17
+ };
18
+ export declare function badgeClass(tone?: BadgeTone): string;
19
+ /** The mark of a badge with `dot`, in the color of its words. */
20
+ export declare const badgeDotClass = "size-1.5 rounded-full bg-current";
21
+ export {};
package/dist/badge.js ADDED
@@ -0,0 +1,12 @@
1
+ const TONE = {
2
+ neutral: "bg-xds-badge-neutral-background text-xds-badge-neutral-text",
3
+ accent: "bg-xds-badge-accent-background text-xds-badge-accent-text",
4
+ success: "bg-xds-badge-success-background text-xds-badge-success-text",
5
+ warning: "bg-xds-badge-warning-background text-xds-badge-warning-text",
6
+ danger: "bg-xds-badge-danger-background text-xds-badge-danger-text",
7
+ overlay: "bg-xds-badge-overlay-background text-xds-badge-overlay-text",
8
+ };
9
+ export function badgeClass(tone = "neutral") {
10
+ return `inline-flex h-xds-badge w-fit shrink-0 items-center gap-1.5 whitespace-nowrap rounded-full px-2.5 text-xds-footnote ${TONE[tone]}`;
11
+ }
12
+ export const badgeDotClass = "size-1.5 rounded-full bg-current";
@@ -0,0 +1,45 @@
1
+ declare const TONE: {
2
+ readonly info: {
3
+ readonly surface: "bg-xds-banner-info-background";
4
+ readonly accent: "text-xds-banner-info-accent";
5
+ readonly icon: "M12 2a10 10 0 1 0 0 20 10 10 0 0 0 0-20Zm0 5.2a1.3 1.3 0 1 1 0 2.6 1.3 1.3 0 0 1 0-2.6ZM10.9 11h2.2v6h-2.2v-6Z";
6
+ };
7
+ readonly success: {
8
+ readonly surface: "bg-xds-banner-success-background";
9
+ readonly accent: "text-xds-banner-success-accent";
10
+ readonly icon: "M12 2a10 10 0 1 0 0 20 10 10 0 0 0 0-20Zm4.7 7.7-5.5 6a1 1 0 0 1-1.5 0l-2.4-2.6 1.5-1.4 1.6 1.8 4.8-5.2 1.5 1.4Z";
11
+ };
12
+ readonly warning: {
13
+ readonly surface: "bg-xds-banner-warning-background";
14
+ readonly accent: "text-xds-banner-warning-accent";
15
+ readonly icon: "M12 2.5 1.5 20.5h21L12 2.5Zm-1.1 6.5h2.2v6h-2.2V9Zm1.1 7.3a1.3 1.3 0 1 1 0 2.6 1.3 1.3 0 0 1 0-2.6Z";
16
+ };
17
+ readonly danger: {
18
+ readonly surface: "bg-xds-banner-danger-background";
19
+ readonly accent: "text-xds-banner-danger-accent";
20
+ readonly icon: "M12 2a10 10 0 1 0 0 20 10 10 0 0 0 0-20Zm-1.1 5h2.2v7h-2.2V7Zm1.1 8.2a1.3 1.3 0 1 1 0 2.6 1.3 1.3 0 0 1 0-2.6Z";
21
+ };
22
+ };
23
+ export type BannerTone = keyof typeof TONE;
24
+ /** Banner's props in every framework, short of its message, its action and `onDismiss`. */
25
+ export type BannerBaseProps = {
26
+ tone?: BannerTone;
27
+ title?: string;
28
+ /** Names the close control for assistive technology. */
29
+ dismissLabel?: string;
30
+ };
31
+ export declare function bannerClass(tone?: BannerTone): string;
32
+ /** The class of the tone's icon, a 24 by 24 drawing of `bannerIconPath(tone)`. */
33
+ export declare function bannerIconClass(tone?: BannerTone): string;
34
+ /** Each tone has its own icon shape, so the tone does not depend on color. */
35
+ export declare function bannerIconPath(tone?: BannerTone): string;
36
+ /** Problems interrupt a screen reader; `info` and `success` wait their turn. */
37
+ export declare function bannerRole(tone?: BannerTone): "alert" | "status";
38
+ export declare const BANNER_PARTS: {
39
+ /** The title, the message and the action, beside the icon. */
40
+ readonly body: "flex min-w-0 flex-1 flex-col gap-0.5 text-xds-detail";
41
+ readonly title: "text-xds-label";
42
+ readonly action: "mt-2";
43
+ readonly dismiss: "-m-1 flex shrink-0";
44
+ };
45
+ export {};
package/dist/banner.js ADDED
@@ -0,0 +1,40 @@
1
+ const TONE = {
2
+ info: {
3
+ surface: "bg-xds-banner-info-background",
4
+ accent: "text-xds-banner-info-accent",
5
+ icon: "M12 2a10 10 0 1 0 0 20 10 10 0 0 0 0-20Zm0 5.2a1.3 1.3 0 1 1 0 2.6 1.3 1.3 0 0 1 0-2.6ZM10.9 11h2.2v6h-2.2v-6Z",
6
+ },
7
+ success: {
8
+ surface: "bg-xds-banner-success-background",
9
+ accent: "text-xds-banner-success-accent",
10
+ icon: "M12 2a10 10 0 1 0 0 20 10 10 0 0 0 0-20Zm4.7 7.7-5.5 6a1 1 0 0 1-1.5 0l-2.4-2.6 1.5-1.4 1.6 1.8 4.8-5.2 1.5 1.4Z",
11
+ },
12
+ warning: {
13
+ surface: "bg-xds-banner-warning-background",
14
+ accent: "text-xds-banner-warning-accent",
15
+ icon: "M12 2.5 1.5 20.5h21L12 2.5Zm-1.1 6.5h2.2v6h-2.2V9Zm1.1 7.3a1.3 1.3 0 1 1 0 2.6 1.3 1.3 0 0 1 0-2.6Z",
16
+ },
17
+ danger: {
18
+ surface: "bg-xds-banner-danger-background",
19
+ accent: "text-xds-banner-danger-accent",
20
+ icon: "M12 2a10 10 0 1 0 0 20 10 10 0 0 0 0-20Zm-1.1 5h2.2v7h-2.2V7Zm1.1 8.2a1.3 1.3 0 1 1 0 2.6 1.3 1.3 0 0 1 0-2.6Z",
21
+ },
22
+ };
23
+ export function bannerClass(tone = "info") {
24
+ return `flex items-start gap-3 rounded-xds-md p-3 text-xds-banner-text ${TONE[tone].surface}`;
25
+ }
26
+ export function bannerIconClass(tone = "info") {
27
+ return `mt-0.5 size-xds-icon-md shrink-0 ${TONE[tone].accent}`;
28
+ }
29
+ export function bannerIconPath(tone = "info") {
30
+ return TONE[tone].icon;
31
+ }
32
+ export function bannerRole(tone = "info") {
33
+ return tone === "danger" || tone === "warning" ? "alert" : "status";
34
+ }
35
+ export const BANNER_PARTS = {
36
+ body: "flex min-w-0 flex-1 flex-col gap-0.5 text-xds-detail",
37
+ title: "text-xds-label",
38
+ action: "mt-2",
39
+ dismiss: "-m-1 flex shrink-0",
40
+ };
@@ -0,0 +1,95 @@
1
+ import type { IconName } from "@xds/tokens";
2
+ export type ButtonVariant = "primary" | "secondary" | "ghost" | "danger";
3
+ export type ControlSize = "sm" | "md" | "lg";
4
+ /** Button's props in every framework, short of its label and its press handler. */
5
+ export type ButtonBaseProps = {
6
+ /**
7
+ * `primary` is the one action a view is for; use it once per view. `secondary` is any other
8
+ * action, `ghost` an action that should stay out of the way, `danger` one that destroys.
9
+ */
10
+ variant?: ButtonVariant;
11
+ size?: ControlSize;
12
+ /** An icon in front of the label. */
13
+ iconStart?: IconName;
14
+ /** An icon after the label. */
15
+ iconEnd?: IconName;
16
+ /**
17
+ * Makes the button a toggle: given at all, its state is reported to assistive technology.
18
+ * While `true`, a `secondary` or a `ghost` button is drawn held down and its `iconStart` is
19
+ * filled. `primary` and `danger` keep their look and only report the state.
20
+ */
21
+ selected?: boolean;
22
+ disabled?: boolean;
23
+ /**
24
+ * Shows a spinner and ignores presses. The label stays, and the spinner stands where
25
+ * `iconStart` was, so the button keeps its width.
26
+ */
27
+ loading?: boolean;
28
+ fullWidth?: boolean;
29
+ type?: "button" | "submit" | "reset";
30
+ /** Names the button for assistive technology when it has no text, such as an icon button. */
31
+ "aria-label"?: string;
32
+ };
33
+ /** IconButton's props in every framework, short of its press handler. */
34
+ export type IconButtonBaseProps = {
35
+ icon: IconName;
36
+ /** The accessible name: there is no visible text. Say what pressing it does. */
37
+ label: string;
38
+ /** As Button's. Defaults to `ghost`, since an icon button usually stays out of the way. */
39
+ variant?: ButtonVariant;
40
+ size?: ControlSize;
41
+ /**
42
+ * Makes the button a toggle: given at all, its state is reported to assistive technology.
43
+ * While `true`, a `secondary` or a `ghost` button is drawn held down and its icon is filled.
44
+ */
45
+ selected?: boolean;
46
+ disabled?: boolean;
47
+ /** Shows a spinner in the icon's place and ignores presses. */
48
+ loading?: boolean;
49
+ };
50
+ /**
51
+ * The classes of a Button, or of an IconButton with `iconButton`. Part of the look comes from
52
+ * attributes the button carries: `disabled`, `aria-pressed`, and `aria-disabled` with
53
+ * `data-pending` while loading.
54
+ */
55
+ export declare function buttonClass(options: {
56
+ variant: ButtonVariant;
57
+ size: ControlSize;
58
+ /** A Button with icons and no label: as wide as it is tall. */
59
+ iconOnly?: boolean;
60
+ iconButton?: boolean;
61
+ fullWidth?: boolean;
62
+ }): string;
63
+ /**
64
+ * Only the two quiet variants change their look when selected, and a disabled button looks
65
+ * disabled whatever its state, so the filled icon follows the same conditions.
66
+ */
67
+ export declare function isHeld(options: {
68
+ variant: ButtonVariant;
69
+ selected?: boolean | undefined;
70
+ disabled?: boolean | undefined;
71
+ }): boolean;
72
+ /**
73
+ * The icons of a Button. A large button has larger text, so its icons are a step larger too.
74
+ * The box is what a spinner is centered in while it stands in for an icon.
75
+ */
76
+ export declare const BUTTON_ICON: {
77
+ readonly sm: {
78
+ readonly size: "sm";
79
+ readonly box: "inline-flex shrink-0 items-center justify-center size-xds-icon-sm";
80
+ };
81
+ readonly md: {
82
+ readonly size: "sm";
83
+ readonly box: "inline-flex shrink-0 items-center justify-center size-xds-icon-sm";
84
+ };
85
+ readonly lg: {
86
+ readonly size: "md";
87
+ readonly box: "inline-flex shrink-0 items-center justify-center size-xds-icon-md";
88
+ };
89
+ };
90
+ /** The box a spinner is centered in while it stands in for an IconButton's icon. */
91
+ export declare const ICON_BUTTON_BOX: {
92
+ readonly sm: "inline-flex shrink-0 items-center justify-center size-xds-icon-sm";
93
+ readonly md: "inline-flex shrink-0 items-center justify-center size-xds-icon-md";
94
+ readonly lg: "inline-flex shrink-0 items-center justify-center size-xds-icon-lg";
95
+ };
package/dist/button.js ADDED
@@ -0,0 +1,25 @@
1
+ export function buttonClass(options) {
2
+ const { variant, size, iconOnly = false, iconButton = false, fullWidth = false } = options;
3
+ let classes = `xds-button xds-button--${variant} xds-button--${size}`;
4
+ if (iconButton)
5
+ classes += " xds-icon-button";
6
+ else if (iconOnly)
7
+ classes += " xds-button--icon-only";
8
+ if (fullWidth)
9
+ classes += " xds-button--full-width";
10
+ return classes;
11
+ }
12
+ export function isHeld(options) {
13
+ const { variant, selected, disabled } = options;
14
+ return selected === true && !disabled && (variant === "secondary" || variant === "ghost");
15
+ }
16
+ export const BUTTON_ICON = {
17
+ sm: { size: "sm", box: "inline-flex shrink-0 items-center justify-center size-xds-icon-sm" },
18
+ md: { size: "sm", box: "inline-flex shrink-0 items-center justify-center size-xds-icon-sm" },
19
+ lg: { size: "md", box: "inline-flex shrink-0 items-center justify-center size-xds-icon-md" },
20
+ };
21
+ export const ICON_BUTTON_BOX = {
22
+ sm: "inline-flex shrink-0 items-center justify-center size-xds-icon-sm",
23
+ md: "inline-flex shrink-0 items-center justify-center size-xds-icon-md",
24
+ lg: "inline-flex shrink-0 items-center justify-center size-xds-icon-lg",
25
+ };
package/dist/card.d.ts ADDED
@@ -0,0 +1,29 @@
1
+ /** Card's props in every framework, short of `onPress`, its content, `actions` and `media`. */
2
+ export type CardBaseProps = {
3
+ title?: string;
4
+ description?: string;
5
+ /** No padding and no gaps: for a card that holds a list, whose rows run edge to edge. */
6
+ flush?: boolean;
7
+ /**
8
+ * Outlines the card as the current choice. Given at all on a pressable card, it also makes
9
+ * the card a toggle that reports its state to assistive technology.
10
+ */
11
+ selected?: boolean;
12
+ };
13
+ /** The surface: a `section`, or a `button` with `pressable`. */
14
+ export declare function cardClass(options: {
15
+ selected?: boolean | undefined;
16
+ flush?: boolean | undefined;
17
+ pressable?: boolean | undefined;
18
+ }): string;
19
+ /** The box of `media`, pulled out through the padding to the edges. */
20
+ export declare function cardMediaClass(flush?: boolean): string;
21
+ export declare const CARD_PARTS: {
22
+ /** Around everything in a `flush` card. */
23
+ readonly flush: "flex flex-1 flex-col overflow-hidden rounded-[calc(var(--xds-radius-lg)-var(--xds-border-width-thin))]";
24
+ readonly header: "flex items-start justify-between gap-3";
25
+ readonly heading: "flex min-w-0 flex-col gap-0.5";
26
+ readonly title: "text-xds-heading text-xds-text-primary";
27
+ readonly description: "text-xds-detail text-xds-text-secondary";
28
+ readonly actions: "flex shrink-0 items-center gap-2";
29
+ };
package/dist/card.js ADDED
@@ -0,0 +1,20 @@
1
+ const SELECTED = "border-xds-card-border-selected after:pointer-events-none after:absolute after:-inset-(--xds-border-width-thin) after:rounded-xds-lg after:border-(length:--xds-border-width-thick) after:border-xds-card-border-selected";
2
+ const CLIP = "overflow-hidden rounded-[calc(var(--xds-radius-lg)-var(--xds-border-width-thin))]";
3
+ const CLIP_TOP = "overflow-hidden rounded-t-[calc(var(--xds-radius-lg)-var(--xds-border-width-thin))]";
4
+ const PRESSABLE = "w-full cursor-pointer text-start transition-colors duration-(--xds-motion-duration-fast) hover:bg-xds-card-background-hover active:bg-xds-card-background-pressed focus-visible:outline-solid focus-visible:outline-(length:--xds-focus-width) focus-visible:outline-offset-(--xds-focus-offset) focus-visible:outline-xds-border-focus";
5
+ export function cardClass(options) {
6
+ const { selected = false, flush = false, pressable = false } = options;
7
+ const surface = `relative flex flex-col rounded-xds-lg border bg-xds-background-surface shadow-xds-subtle ${selected ? SELECTED : "border-xds-border-default"}${flush ? "" : " gap-4 p-4"}`;
8
+ return pressable ? `${PRESSABLE} ${surface}` : surface;
9
+ }
10
+ export function cardMediaClass(flush = false) {
11
+ return flush ? `flex flex-col ${CLIP_TOP}` : `flex flex-col ${CLIP_TOP} -mx-4 -mt-4`;
12
+ }
13
+ export const CARD_PARTS = {
14
+ flush: `flex flex-1 flex-col ${CLIP}`,
15
+ header: "flex items-start justify-between gap-3",
16
+ heading: "flex min-w-0 flex-col gap-0.5",
17
+ title: "text-xds-heading text-xds-text-primary",
18
+ description: "text-xds-detail text-xds-text-secondary",
19
+ actions: "flex shrink-0 items-center gap-2",
20
+ };
@@ -0,0 +1,20 @@
1
+ export { switchClass as checkboxClass, switchLabelClass as checkboxLabelClass } from "./switch.ts";
2
+ /** Checkbox's props in every framework, short of `onChange`. */
3
+ export type CheckboxBaseProps = {
4
+ checked: boolean;
5
+ /** Shown beside the box. Pressing it toggles too. */
6
+ label?: string;
7
+ /** Names the checkbox for assistive technology when there is no visible label. */
8
+ "aria-label"?: string;
9
+ name?: string;
10
+ disabled?: boolean;
11
+ };
12
+ /**
13
+ * The box, drawn beside the hidden input. The outline is what makes an empty box visible; a
14
+ * filled one does not need it.
15
+ */
16
+ export declare const checkboxBoxClass = "flex size-xds-checkbox shrink-0 items-center justify-center rounded-xds-sm border-2 border-xds-checkbox-border text-xds-checkbox-mark peer-checked:border-0 peer-checked:bg-xds-checkbox-background-checked peer-disabled:border-0 peer-disabled:bg-xds-checkbox-disabled-background peer-disabled:text-xds-checkbox-disabled-mark *:opacity-0 peer-checked:*:opacity-100 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";
17
+ /** The check mark inside the box: a 16 by 16 path, `CHECKBOX_MARK`. */
18
+ export declare const checkboxMarkClass = "size-3/4";
19
+ /** The path of the check mark, in a `0 0 16 16` view box. */
20
+ export declare const CHECKBOX_MARK = "m3.5 8.5 3 3 6-7";
@@ -0,0 +1,5 @@
1
+ import { PEER_FOCUS } from "./switch.js";
2
+ export { switchClass as checkboxClass, switchLabelClass as checkboxLabelClass } from "./switch.js";
3
+ export const checkboxBoxClass = `flex size-xds-checkbox shrink-0 items-center justify-center rounded-xds-sm border-2 border-xds-checkbox-border text-xds-checkbox-mark peer-checked:border-0 peer-checked:bg-xds-checkbox-background-checked peer-disabled:border-0 peer-disabled:bg-xds-checkbox-disabled-background peer-disabled:text-xds-checkbox-disabled-mark *:opacity-0 peer-checked:*:opacity-100 ${PEER_FOCUS}`;
4
+ export const checkboxMarkClass = "size-3/4";
5
+ export const CHECKBOX_MARK = "m3.5 8.5 3 3 6-7";
@@ -0,0 +1,11 @@
1
+ /** ChipBar's props in every framework, short of the chips. */
2
+ export type ChipBarBaseProps = {
3
+ /** Says what the chips filter, for assistive technology. */
4
+ label: string;
5
+ };
6
+ /**
7
+ * The scrolling row. It is as tall as the chips' pressable area, which would otherwise be cut
8
+ * off by the scrolling box. The padding leaves room for a focus ring for the same reason, and
9
+ * the margin takes that room back so the first chip lines up with the content around the bar.
10
+ */
11
+ export declare const chipBarClass = "-m-1 flex min-h-[calc(var(--xds-size-target-min)+var(--xds-space-2))] items-center gap-2 overflow-x-auto p-1 [scrollbar-width:none] [&::-webkit-scrollbar]:hidden";
@@ -0,0 +1 @@
1
+ export const chipBarClass = "-m-1 flex min-h-[calc(var(--xds-size-target-min)+var(--xds-space-2))] items-center gap-2 overflow-x-auto p-1 [scrollbar-width:none] [&::-webkit-scrollbar]:hidden";
package/dist/chip.d.ts ADDED
@@ -0,0 +1,21 @@
1
+ import type { IconName } from "@xds/tokens";
2
+ /** Chip's props in every framework, short of `onPress`. */
3
+ export type ChipBaseProps = {
4
+ label: string;
5
+ /** Whether the chip's filter is on. The app holds this state. */
6
+ selected?: boolean;
7
+ /** An icon in front of the label. A selected chip shows a check mark in its place. */
8
+ iconStart?: IconName;
9
+ disabled?: boolean;
10
+ };
11
+ /**
12
+ * The classes of a Chip, a native toggle button. The border is there on every chip,
13
+ * transparent until selected, so selecting does not change the size. The `before` box is the
14
+ * pressable area, which is taller than the chip where fingers need it to be.
15
+ */
16
+ export declare function chipClass(selected?: boolean): string;
17
+ /** The icon in front of the label: a check while selected, so the state is not color alone. */
18
+ export declare function chipIcon(options: {
19
+ selected?: boolean | undefined;
20
+ iconStart?: IconName | undefined;
21
+ }): IconName | undefined;
package/dist/chip.js ADDED
@@ -0,0 +1,8 @@
1
+ export function chipClass(selected = false) {
2
+ return `relative inline-flex h-xds-chip shrink-0 cursor-pointer items-center gap-1.5 whitespace-nowrap rounded-xds-full border px-3 text-xds-label transition-colors duration-(--xds-motion-duration-fast) before:absolute before:inset-x-0 before:top-1/2 before:h-[max(100%,var(--xds-size-target-min))] before:-translate-y-1/2 focus-visible:outline-solid focus-visible:outline-(length:--xds-focus-width) focus-visible:outline-offset-(--xds-focus-offset) focus-visible:outline-xds-border-focus disabled:cursor-not-allowed disabled:border-transparent disabled:bg-xds-chip-disabled-background disabled:text-xds-chip-disabled-text ${selected
3
+ ? "border-xds-chip-selected-border bg-xds-chip-selected-background text-xds-chip-selected-text enabled:hover:bg-xds-chip-selected-background-hover enabled:active:bg-xds-chip-selected-background-pressed"
4
+ : "border-transparent bg-xds-chip-background text-xds-chip-text enabled:hover:bg-xds-chip-background-hover enabled:active:bg-xds-chip-background-pressed"}`;
5
+ }
6
+ export function chipIcon(options) {
7
+ return options.selected ? "check" : options.iconStart;
8
+ }
@@ -0,0 +1,18 @@
1
+ /** CountBadge's props in every framework, short of the child it sits on. */
2
+ export type CountBadgeBaseProps = {
3
+ /** Zero or less draws no badge. */
4
+ count: number;
5
+ /** The largest number shown. A larger count reads "99+". */
6
+ max?: number;
7
+ /**
8
+ * Says what is counted, such as "3 unread notifications". Without it assistive technology
9
+ * reads the number alone.
10
+ */
11
+ label?: string;
12
+ };
13
+ /** The badge, laid out inline or, with `onChild`, on the top end corner of a child. */
14
+ export declare function countBadgeClass(onChild: boolean): string;
15
+ /** The box around a child that a badge sits on. */
16
+ export declare const countBadgeAnchorClass = "relative inline-flex w-fit shrink-0";
17
+ /** What the badge reads: the count, or "99+" past `max`. */
18
+ export declare function countBadgeText(count: number, max?: number): string;
@@ -0,0 +1,9 @@
1
+ export function countBadgeClass(onChild) {
2
+ return onChild
3
+ ? "absolute end-[calc(var(--xds-size-count-badge)/-4)] top-[calc(var(--xds-size-count-badge)/-4)] inline-flex h-xds-count-badge min-w-xds-count-badge shrink-0 select-none items-center justify-center whitespace-nowrap rounded-full bg-xds-badge-count-background px-1 text-xds-badge-count-text text-xds-footnote"
4
+ : "inline-flex h-xds-count-badge min-w-xds-count-badge shrink-0 select-none items-center justify-center whitespace-nowrap rounded-full bg-xds-badge-count-background px-1 text-xds-badge-count-text text-xds-footnote";
5
+ }
6
+ export const countBadgeAnchorClass = "relative inline-flex w-fit shrink-0";
7
+ export function countBadgeText(count, max = 99) {
8
+ return count > max ? `${max}+` : String(count);
9
+ }