@xds/react 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 (100) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +19 -2
  3. package/dist/Accordion.d.ts +20 -0
  4. package/dist/Accordion.js +39 -0
  5. package/dist/Avatar.d.ts +9 -0
  6. package/dist/Avatar.js +10 -0
  7. package/dist/AvatarStack.d.ts +8 -0
  8. package/dist/AvatarStack.js +10 -0
  9. package/dist/Badge.d.ts +13 -0
  10. package/dist/Badge.js +9 -0
  11. package/dist/Banner.d.ts +23 -0
  12. package/dist/Banner.js +10 -0
  13. package/dist/Button.d.ts +14 -0
  14. package/dist/Button.js +31 -0
  15. package/dist/Card.d.ts +18 -0
  16. package/dist/Card.js +14 -0
  17. package/dist/Checkbox.d.ts +10 -0
  18. package/dist/Checkbox.js +5 -0
  19. package/dist/Chip.d.ts +12 -0
  20. package/dist/Chip.js +7 -0
  21. package/dist/ChipBar.d.ts +12 -0
  22. package/dist/ChipBar.js +5 -0
  23. package/dist/CountBadge.d.ts +12 -0
  24. package/dist/CountBadge.js +11 -0
  25. package/dist/DatePicker.d.ts +20 -0
  26. package/dist/DatePicker.js +33 -0
  27. package/dist/DateRangePicker.d.ts +24 -0
  28. package/dist/DateRangePicker.js +48 -0
  29. package/dist/Defaults.d.ts +17 -0
  30. package/dist/Defaults.js +13 -0
  31. package/dist/Dialog.d.ts +20 -0
  32. package/dist/Dialog.js +33 -0
  33. package/dist/Divider.d.ts +4 -0
  34. package/dist/Divider.js +5 -0
  35. package/dist/EmptyState.d.ts +12 -0
  36. package/dist/EmptyState.js +6 -0
  37. package/dist/Icon.d.ts +9 -0
  38. package/dist/Icon.js +9 -0
  39. package/dist/IconButton.d.ts +12 -0
  40. package/dist/IconButton.js +24 -0
  41. package/dist/ListRow.d.ts +21 -0
  42. package/dist/ListRow.js +15 -0
  43. package/dist/MediaCard.d.ts +20 -0
  44. package/dist/MediaCard.js +17 -0
  45. package/dist/Menu.d.ts +18 -0
  46. package/dist/Menu.js +68 -0
  47. package/dist/ProgressBar.d.ts +8 -0
  48. package/dist/ProgressBar.js +6 -0
  49. package/dist/RadioGroup.d.ts +15 -0
  50. package/dist/RadioGroup.js +15 -0
  51. package/dist/SearchField.d.ts +15 -0
  52. package/dist/SearchField.js +20 -0
  53. package/dist/SectionHeader.d.ts +14 -0
  54. package/dist/SectionHeader.js +8 -0
  55. package/dist/SegmentedControl.d.ts +12 -0
  56. package/dist/SegmentedControl.js +7 -0
  57. package/dist/Select.d.ts +18 -0
  58. package/dist/Select.js +66 -0
  59. package/dist/Sidebar.d.ts +21 -0
  60. package/dist/Sidebar.js +27 -0
  61. package/dist/Skeleton.d.ts +11 -0
  62. package/dist/Skeleton.js +8 -0
  63. package/dist/Slider.d.ts +13 -0
  64. package/dist/Slider.js +44 -0
  65. package/dist/Spinner.d.ts +9 -0
  66. package/dist/Spinner.js +8 -0
  67. package/dist/Switch.d.ts +13 -0
  68. package/dist/Switch.js +5 -0
  69. package/dist/Tabs.d.ts +14 -0
  70. package/dist/Tabs.js +21 -0
  71. package/dist/Text.d.ts +10 -0
  72. package/dist/Text.js +8 -0
  73. package/dist/TextField.d.ts +22 -0
  74. package/dist/TextField.js +30 -0
  75. package/dist/Thumbnail.d.ts +9 -0
  76. package/dist/Thumbnail.js +13 -0
  77. package/dist/Toast.d.ts +14 -0
  78. package/dist/Toast.js +33 -0
  79. package/dist/Tooltip.d.ts +26 -0
  80. package/dist/Tooltip.js +32 -0
  81. package/dist/index.d.ts +39 -0
  82. package/dist/index.js +39 -0
  83. package/dist/modal-popover.d.ts +7 -0
  84. package/dist/modal-popover.js +15 -0
  85. package/dist/picture.d.ts +11 -0
  86. package/dist/picture.js +21 -0
  87. package/dist/portal.d.ts +9 -0
  88. package/dist/portal.js +7 -0
  89. package/dist/presence.d.ts +6 -0
  90. package/dist/presence.js +13 -0
  91. package/dist/preview.d.ts +6 -0
  92. package/dist/preview.js +82 -0
  93. package/dist/root.d.ts +12 -0
  94. package/dist/root.js +0 -0
  95. package/dist/trigger.d.ts +17 -0
  96. package/dist/trigger.js +14 -0
  97. package/package.json +61 -4
  98. package/page.css +20 -0
  99. package/styles.css +3252 -0
  100. package/tailwind.css +2665 -0
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,20 @@
1
- # Temporary Holding Version
1
+ # @xds/react
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
+ The components of the xds design system for React, with the look of an app made with `xds create`.
4
+
5
+ ```sh
6
+ npm install @xds/react
7
+ ```
8
+
9
+ Import the stylesheet once, then use the components:
10
+
11
+ ```js
12
+ import "@xds/react/styles.css";
13
+ import { Button } from "@xds/react";
14
+ ```
15
+
16
+ `<Button>` and every other component take the app's class and style on their root element, which also carries a stable class such as `xds-button`. The `Defaults` component sets what the components inside it take when the app passes no variant, size or tone.
17
+
18
+ The stylesheet keeps to the `xds` cascade layer and to the library's own elements, so the app's styles win. `@xds/react/page.css` gives the page the library's background, text color and font. An app with Tailwind CSS 4.1 or later can import `@xds/react/tailwind.css` before Tailwind instead of `styles.css`.
19
+
20
+ This channel is a preview while its behavior library, Zag.js 2, is a prerelease. See [xds as a library](https://github.com/kjmin-dev/xds/blob/main/docs/library.md) for modes, themes and the rest of the customization.
@@ -0,0 +1,20 @@
1
+ import { type AccordionBaseProps, type AccordionItemBase } from "@xds/core";
2
+ import { type ReactNode } from "react";
3
+ import type { RootProps } from "./root.ts";
4
+ export type AccordionItem<Value extends string = string> = AccordionItemBase<Value> & {
5
+ /** The body, shown under the title while the item is open. */
6
+ content: ReactNode;
7
+ };
8
+ export type AccordionProps<Value extends string = string> = AccordionBaseProps<Value> & RootProps & {
9
+ items: readonly AccordionItem<Value>[];
10
+ onChange: (expanded: Value[]) => void;
11
+ };
12
+ /**
13
+ * Items whose bodies open and close under their titles, separated by hairlines. The chevron
14
+ * turns over when an item is open, so the state does not depend on color. Opening and closing
15
+ * animate the height, and do not for people who ask for less motion.
16
+ *
17
+ * Each title is a heading holding a button that says whether its body is expanded and which
18
+ * body it controls. A closed body is hidden, but the browser's find in page still opens it.
19
+ */
20
+ export declare function Accordion<Value extends string = string>({ items, expanded, onChange, multiple, className, style, }: AccordionProps<Value>): import("react").JSX.Element;
@@ -0,0 +1,39 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { ACCORDION_PARTS, classes, focusTitleOnClick, setPanelOpen, } from "@xds/core";
3
+ import * as accordion from "@zag-js/accordion";
4
+ import { mergeProps, normalizeProps, useMachine } from "@zag-js/react";
5
+ import { useId, useLayoutEffect, useRef, useState, } from "react";
6
+ import { Icon } from "./Icon.js";
7
+ export function Accordion({ items, expanded, onChange, multiple = false, className, style, }) {
8
+ const service = useMachine(accordion.machine, {
9
+ id: useId(),
10
+ value: [...expanded],
11
+ onValueChange: (details) => onChange(details.value),
12
+ multiple,
13
+ collapsible: true,
14
+ hiddenUntilFound: true,
15
+ });
16
+ const api = accordion.connect(service, normalizeProps);
17
+ return (_jsx("div", { ...mergeProps(api.getRootProps(), {
18
+ className: classes("xds-accordion", className),
19
+ style,
20
+ }), children: items.map((item) => {
21
+ const { hidden: _hidden, ...body } = api.getItemContentProps({ value: item.value });
22
+ return (_jsxs("div", { ...api.getItemProps({ value: item.value }), className: "xds-accordion__item", children: [_jsx("h3", { ...api.getItemHeaderProps({ value: item.value }), className: "xds-accordion__heading", children: _jsxs("button", { ...mergeProps(api.getItemTriggerProps({ value: item.value }), {
23
+ onClick: focusTitleOnClick,
24
+ }), type: "button", className: "xds-accordion__trigger group", children: [_jsxs("span", { className: ACCORDION_PARTS.text, children: [_jsx("span", { className: ACCORDION_PARTS.title, children: item.title }), item.description && (_jsx("span", { className: ACCORDION_PARTS.description, children: item.description }))] }), _jsx(Icon, { name: "chevron-down", size: "sm", className: ACCORDION_PARTS.chevron })] }) }), _jsx(Panel, { open: api.value.includes(item.value), attributes: body, children: item.content })] }, item.value));
25
+ }) }));
26
+ }
27
+ function Panel({ open, attributes, children, }) {
28
+ const panel = useRef(null);
29
+ const shown = useRef(undefined);
30
+ const [closedAtFirst] = useState(!open);
31
+ useLayoutEffect(() => {
32
+ if (!panel.current)
33
+ return;
34
+ const stop = setPanelOpen(panel.current, open, shown.current !== undefined && shown.current !== open);
35
+ shown.current = open;
36
+ return stop;
37
+ }, [open]);
38
+ return (_jsx("div", { ...attributes, ref: panel, hidden: closedAtFirst || undefined, role: "group", "aria-hidden": open ? undefined : true, className: "xds-accordion__panel", children: _jsx("div", { className: "xds-accordion__body", children: children }) }));
39
+ }
@@ -0,0 +1,9 @@
1
+ import { type AvatarBaseProps } from "@xds/core";
2
+ import type { RootProps } from "./root.ts";
3
+ export type { AvatarSize } from "@xds/core";
4
+ export type AvatarProps = AvatarBaseProps & RootProps;
5
+ /**
6
+ * Stands for a person or a team by a picture, or by their initials when there is none.
7
+ * Assistive technology gets the full name either way. The small size has room for one letter.
8
+ */
9
+ export declare function Avatar(props: AvatarProps): import("react").JSX.Element;
package/dist/Avatar.js ADDED
@@ -0,0 +1,10 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { avatarClass, avatarInitials, classes, pictureClass, rootPart, } from "@xds/core";
3
+ import { useDefaults } from "./Defaults.js";
4
+ import { usePicture } from "./picture.js";
5
+ export function Avatar(props) {
6
+ const defaults = useDefaults("Avatar");
7
+ const { name, src, size = defaults.size, className, style } = props;
8
+ const picture = usePicture(src);
9
+ return (_jsxs("span", { role: "img", "aria-label": name, className: classes(rootPart("Avatar"), avatarClass(size), className), style: style, children: [avatarInitials(name, size), src && picture.loaded !== false && (_jsx("img", { src: src, alt: "", "aria-hidden": "true", className: pictureClass(picture.loaded === true), ref: picture.ref, onLoad: picture.onLoad, onError: picture.onError }))] }));
10
+ }
@@ -0,0 +1,8 @@
1
+ import { type AvatarStackBaseProps } from "@xds/core";
2
+ import type { RootProps } from "./root.ts";
3
+ export type AvatarStackProps = AvatarStackBaseProps & RootProps;
4
+ /**
5
+ * Several people in the room of one. Assistive technology gets one image named after
6
+ * everyone in it, including those who did not fit.
7
+ */
8
+ export declare function AvatarStack(props: AvatarStackProps): import("react").JSX.Element;
@@ -0,0 +1,10 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { avatarStack, avatarStackClass, avatarStackItemClass, avatarStackRestClass, classes, rootPart, } from "@xds/core";
3
+ import { Avatar } from "./Avatar.js";
4
+ import { useDefaults } from "./Defaults.js";
5
+ export function AvatarStack(props) {
6
+ const defaults = useDefaults("AvatarStack");
7
+ const { people, max, size = defaults.size ?? "md", label, className, style } = props;
8
+ const stack = avatarStack(people, max, label);
9
+ return (_jsxs("span", { role: "img", "aria-label": stack.name, className: classes(rootPart("AvatarStack"), avatarStackClass, className), style: style, children: [stack.shown.map((person, index) => (_jsx("span", { "aria-hidden": "true", className: avatarStackItemClass(size), children: _jsx(Avatar, { name: person.name, src: person.src, size: size }) }, index))), stack.rest > 0 && (_jsxs("span", { "aria-hidden": "true", className: avatarStackRestClass(size), children: ["+", stack.rest] }))] }));
10
+ }
@@ -0,0 +1,13 @@
1
+ import { type BadgeBaseProps } from "@xds/core";
2
+ import type { ReactNode } from "react";
3
+ import type { RootProps } from "./root.ts";
4
+ export type { BadgeTone } from "@xds/core";
5
+ export type BadgeProps = BadgeBaseProps & RootProps & {
6
+ children: ReactNode;
7
+ };
8
+ /**
9
+ * A short status or category. The words carry the meaning; the color only reinforces it, so a
10
+ * badge still reads for someone who cannot tell the tones apart. `dot` adds a small mark for
11
+ * live states such as "connected", and `icon` a drawing in front of the words.
12
+ */
13
+ export declare function Badge(props: BadgeProps): import("react").JSX.Element;
package/dist/Badge.js ADDED
@@ -0,0 +1,9 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { badgeClass, badgeDotClass, classes, rootPart } from "@xds/core";
3
+ import { useDefaults } from "./Defaults.js";
4
+ import { Icon } from "./Icon.js";
5
+ export function Badge(props) {
6
+ const defaults = useDefaults("Badge");
7
+ const { tone = defaults.tone, dot = false, icon, className, style, children } = props;
8
+ return (_jsxs("span", { className: classes(rootPart("Badge"), badgeClass(tone), className), style: style, children: [dot && _jsx("span", { "aria-hidden": true, className: badgeDotClass }), icon && _jsx(Icon, { name: icon, size: "xs" }), children] }));
9
+ }
@@ -0,0 +1,23 @@
1
+ import { type BannerBaseProps } from "@xds/core";
2
+ import type { ReactNode } from "react";
3
+ import type { RootProps } from "./root.ts";
4
+ export type { BannerTone } from "@xds/core";
5
+ export type BannerProps = BannerBaseProps & RootProps & {
6
+ /** What the person can do about the message. Drawn under it as a small secondary button. */
7
+ action?: {
8
+ label: string;
9
+ onPress: () => void;
10
+ };
11
+ /**
12
+ * Shows a close control. The banner does not hide itself: the handler decides what happens
13
+ * to it.
14
+ */
15
+ onDismiss?: () => void;
16
+ children: ReactNode;
17
+ };
18
+ /**
19
+ * A message about the whole view or a section of it. Each tone has its own icon shape, so the
20
+ * tone does not depend on color. Problems (`warning`, `danger`) interrupt a screen reader;
21
+ * `info` and `success` wait their turn.
22
+ */
23
+ export declare function Banner(props: BannerProps): import("react").JSX.Element;
package/dist/Banner.js ADDED
@@ -0,0 +1,10 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { BANNER_PARTS, bannerClass, bannerIconClass, bannerIconPath, bannerRole, classes, rootPart, } from "@xds/core";
3
+ import { Button } from "./Button.js";
4
+ import { useDefaults } from "./Defaults.js";
5
+ import { IconButton } from "./IconButton.js";
6
+ export function Banner(props) {
7
+ const defaults = useDefaults("Banner");
8
+ const { tone = defaults.tone, title, action, onDismiss, dismissLabel = "Dismiss", className, style, children, } = props;
9
+ return (_jsxs("div", { role: bannerRole(tone), className: classes(rootPart("Banner"), bannerClass(tone), className), style: style, children: [_jsx("svg", { viewBox: "0 0 24 24", "aria-hidden": "true", className: bannerIconClass(tone), children: _jsx("path", { fill: "currentColor", d: bannerIconPath(tone) }) }), _jsxs("div", { className: BANNER_PARTS.body, children: [title && _jsx("p", { className: BANNER_PARTS.title, children: title }), _jsx("div", { children: children }), action && (_jsx("div", { className: BANNER_PARTS.action, children: _jsx(Button, { variant: "secondary", size: "sm", onPress: action.onPress, children: action.label }) }))] }), onDismiss && (_jsx("div", { className: BANNER_PARTS.dismiss, children: _jsx(IconButton, { icon: "x", label: dismissLabel, variant: "ghost", size: "sm", onPress: onDismiss }) }))] }));
10
+ }
@@ -0,0 +1,14 @@
1
+ import { type ButtonBaseProps } from "@xds/core";
2
+ import type { ReactNode } from "react";
3
+ import type { RootProps } from "./root.ts";
4
+ export type { ButtonVariant, ControlSize } from "@xds/core";
5
+ export type ButtonProps = ButtonBaseProps & RootProps & {
6
+ onPress?: () => void;
7
+ /** Leave it out for a button that holds only an icon, and name that one with `aria-label`. */
8
+ children?: ReactNode;
9
+ };
10
+ /**
11
+ * A native button. It also opens a Menu or a Tooltip it is the trigger of: their props reach
12
+ * it through context.
13
+ */
14
+ export declare function Button(props: ButtonProps): import("react").JSX.Element;
package/dist/Button.js ADDED
@@ -0,0 +1,31 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { BUTTON_ICON, buttonClass, classes, isHeld } from "@xds/core";
3
+ import { useDefaults } from "./Defaults.js";
4
+ import { Icon } from "./Icon.js";
5
+ import { Spinner } from "./Spinner.js";
6
+ import { useTrigger } from "./trigger.js";
7
+ export function Button(props) {
8
+ const defaults = useDefaults("Button");
9
+ const { variant = defaults.variant ?? "secondary", size = defaults.size ?? "md", iconStart, iconEnd, selected, disabled = false, loading = false, fullWidth = false, type = "button", onPress, "aria-label": label, className, style, children, } = props;
10
+ const icon = BUTTON_ICON[size];
11
+ const attributes = useTrigger({
12
+ className: classes(buttonClass({
13
+ variant,
14
+ size,
15
+ iconOnly: children == null && (iconStart !== undefined || iconEnd !== undefined),
16
+ fullWidth,
17
+ }), className),
18
+ style,
19
+ disabled,
20
+ "aria-disabled": loading || undefined,
21
+ "data-pending": loading ? "" : undefined,
22
+ "aria-pressed": selected,
23
+ "aria-label": label,
24
+ onClick: () => {
25
+ if (!loading)
26
+ onPress?.();
27
+ },
28
+ }, loading);
29
+ return (_jsxs("button", { ...attributes, type: type, children: [loading &&
30
+ (iconStart ? (_jsx("span", { className: icon.box, children: _jsx(Spinner, { size: "sm" }) })) : (_jsx(Spinner, { size: "sm" }))), iconStart && !loading && (_jsx(Icon, { name: iconStart, size: icon.size, filled: isHeld({ variant, selected, disabled }) })), children, iconEnd && _jsx(Icon, { name: iconEnd, size: icon.size })] }));
31
+ }
package/dist/Card.d.ts ADDED
@@ -0,0 +1,18 @@
1
+ import { type CardBaseProps } from "@xds/core";
2
+ import type { ReactNode } from "react";
3
+ import type { RootProps } from "./root.ts";
4
+ export type CardProps = CardBaseProps & RootProps & {
5
+ /** Sit across from the title. A pressable card takes none: it is one button already. */
6
+ actions?: ReactNode;
7
+ /** A picture or a drawing at the top, running edge to edge above the padding. */
8
+ media?: ReactNode;
9
+ /** Makes the whole card one button. Put no other control inside it then. */
10
+ onPress?: () => void;
11
+ children?: ReactNode;
12
+ };
13
+ /**
14
+ * A surface that groups related content. A hairline outline and a trace of shadow lift it off
15
+ * the page; in dark mode, where shadows barely show, the lighter fill does that. `title`
16
+ * renders as a heading; `actions` sit across from it.
17
+ */
18
+ export declare function Card({ title, description, actions, media, flush, onPress, selected, className, style, children, }: CardProps): import("react").JSX.Element;
package/dist/Card.js ADDED
@@ -0,0 +1,14 @@
1
+ import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { CARD_PARTS, cardClass, cardMediaClass, classes, rootPart, } from "@xds/core";
3
+ export function Card({ title, description, actions, media, flush = false, onPress, selected, className, style, children, }) {
4
+ const surface = classes(rootPart("Card"), cardClass({ selected, flush, pressable: onPress !== undefined }), className);
5
+ const [Header, Box, Title, Line] = onPress
6
+ ? ["span", "span", "span", "span"]
7
+ : ["header", "div", "h2", "p"];
8
+ const parts = (_jsxs(_Fragment, { children: [media != null && _jsx(Box, { className: cardMediaClass(flush), children: media }), (title || (actions && !onPress)) && (_jsxs(Header, { className: CARD_PARTS.header, children: [_jsxs(Box, { className: CARD_PARTS.heading, children: [title && _jsx(Title, { className: CARD_PARTS.title, children: title }), description && _jsx(Line, { className: CARD_PARTS.description, children: description })] }), actions && !onPress && _jsx("div", { className: CARD_PARTS.actions, children: actions })] })), children] }));
9
+ const content = flush ? _jsx(Box, { className: CARD_PARTS.flush, children: parts }) : parts;
10
+ if (!onPress) {
11
+ return (_jsx("section", { ...(selected ? { "aria-current": "true" } : {}), className: surface, style: style, children: content }));
12
+ }
13
+ return (_jsx("button", { type: "button", onClick: onPress, ...(selected === undefined ? {} : { "aria-pressed": selected }), className: surface, style: style, children: content }));
14
+ }
@@ -0,0 +1,10 @@
1
+ import { type CheckboxBaseProps } from "@xds/core";
2
+ import type { RootProps } from "./root.ts";
3
+ export type CheckboxProps = CheckboxBaseProps & RootProps & {
4
+ onChange: (checked: boolean) => void;
5
+ };
6
+ /**
7
+ * A choice that is applied later, with the form it belongs to. A native checkbox: the input is
8
+ * hidden and the box is drawn beside it.
9
+ */
10
+ export declare function Checkbox({ checked, onChange, label, name, disabled, className, style, ...aria }: CheckboxProps): import("react").JSX.Element;
@@ -0,0 +1,5 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { CHECKBOX_MARK, checkboxBoxClass, checkboxClass, checkboxLabelClass, checkboxMarkClass, classes, rootPart, } from "@xds/core";
3
+ export function Checkbox({ checked, onChange, label, name, disabled = false, className, style, ...aria }) {
4
+ return (_jsxs("label", { className: classes(rootPart("Checkbox"), checkboxClass, className), style: style, children: [_jsx("input", { ...aria, type: "checkbox", className: "peer sr-only", checked: checked, disabled: disabled, onChange: (event) => onChange(event.target.checked), ...(name ? { name } : {}) }), _jsx("span", { className: checkboxBoxClass, children: _jsx("svg", { viewBox: "0 0 16 16", fill: "none", "aria-hidden": "true", className: checkboxMarkClass, children: _jsx("path", { d: CHECKBOX_MARK, stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round" }) }) }), label && _jsx("span", { className: checkboxLabelClass, children: label })] }));
5
+ }
package/dist/Chip.d.ts ADDED
@@ -0,0 +1,12 @@
1
+ import { type ChipBaseProps } from "@xds/core";
2
+ import type { RootProps } from "./root.ts";
3
+ export type ChipProps = ChipBaseProps & RootProps & {
4
+ onPress?: () => void;
5
+ };
6
+ /**
7
+ * A choice that filters what is shown. Unlike a Badge it is pressed. A selected chip is tinted,
8
+ * outlined and marked with a check, so the state does not depend on color.
9
+ *
10
+ * It is a toggle button: assistive technology hears whether it is pressed.
11
+ */
12
+ export declare function Chip({ label, selected, onPress, iconStart, disabled, className, style, }: ChipProps): import("react").JSX.Element;
package/dist/Chip.js ADDED
@@ -0,0 +1,7 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { chipClass, chipIcon, classes, rootPart } from "@xds/core";
3
+ import { Icon } from "./Icon.js";
4
+ export function Chip({ label, selected = false, onPress, iconStart, disabled = false, className, style, }) {
5
+ const icon = chipIcon({ selected, iconStart });
6
+ return (_jsxs("button", { type: "button", "aria-pressed": selected, disabled: disabled, onClick: onPress, className: classes(rootPart("Chip"), chipClass(selected), className), style: style, children: [icon && _jsx(Icon, { name: icon, size: "sm" }), label] }));
7
+ }
@@ -0,0 +1,12 @@
1
+ import { type ChipBarBaseProps } from "@xds/core";
2
+ import type { ReactNode } from "react";
3
+ import type { RootProps } from "./root.ts";
4
+ export type ChipBarProps = ChipBarBaseProps & RootProps & {
5
+ /** The chips. Which of them are selected is the app's business: the bar holds no state. */
6
+ children: ReactNode;
7
+ };
8
+ /**
9
+ * One row of chips. It scrolls sideways when the chips do not fit and never wraps, so the
10
+ * content under it stays where it is.
11
+ */
12
+ export declare function ChipBar({ label, className, style, children }: ChipBarProps): import("react").JSX.Element;
@@ -0,0 +1,5 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { chipBarClass, classes, rootPart } from "@xds/core";
3
+ export function ChipBar({ label, className, style, children }) {
4
+ return (_jsx("div", { role: "group", "aria-label": label, className: classes(rootPart("ChipBar"), chipBarClass, className), style: style, children: children }));
5
+ }
@@ -0,0 +1,12 @@
1
+ import { type CountBadgeBaseProps } from "@xds/core";
2
+ import type { ReactNode } from "react";
3
+ import type { RootProps } from "./root.ts";
4
+ export type CountBadgeProps = CountBadgeBaseProps & RootProps & {
5
+ /** What the count belongs to: an icon, an avatar, a button. The badge sits on its corner. */
6
+ children?: ReactNode;
7
+ };
8
+ /**
9
+ * A count of something waiting: unread messages, items in a cart. On its own it is laid out
10
+ * inline; around a child it sits on the child's top end corner.
11
+ */
12
+ export declare function CountBadge({ count, max, label, className, style, children }: CountBadgeProps): import("react").JSX.Element | null;
@@ -0,0 +1,11 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { countBadgeAnchorClass, countBadgeClass, classes, countBadgeText, rootPart, } from "@xds/core";
3
+ export function CountBadge({ count, max, label, className, style, children }) {
4
+ const anchored = children !== undefined;
5
+ const badge = count > 0 && (_jsx("span", { ...(label ? { role: "img", "aria-label": label } : {}), className: anchored
6
+ ? countBadgeClass(true)
7
+ : classes(rootPart("CountBadge"), countBadgeClass(false), className), style: anchored ? undefined : style, children: countBadgeText(count, max) }));
8
+ if (!anchored)
9
+ return badge || null;
10
+ return (_jsxs("span", { className: classes(rootPart("CountBadge"), countBadgeAnchorClass, className), style: style, children: [children, badge] }));
11
+ }
@@ -0,0 +1,20 @@
1
+ import { type DatePickerBaseProps, type IsoDate } from "@xds/core";
2
+ import type { RootProps } from "./root.ts";
3
+ export type { IsoDate } from "@xds/core";
4
+ export type DatePickerProps = DatePickerBaseProps & RootProps & {
5
+ onChange: (value: IsoDate) => void;
6
+ };
7
+ /**
8
+ * A field for choosing one day. Closed, it looks like a Select: the chosen day in the locale's
9
+ * medium form, or the placeholder. Pressed, it opens a calendar of one month under itself, on
10
+ * the chosen day, or on today while none is. A press on a day, or Enter on the focused one,
11
+ * calls `onChange` with the day as `YYYY-MM-DD` and closes the calendar; Escape or a press
12
+ * outside closes it without a choice.
13
+ *
14
+ * The field is a button that says it opens a dialog and whether it is open. In the calendar the
15
+ * arrow keys move a day or a week, Page Up and Page Down a month (a year with Shift), and Home
16
+ * and End to the first and the last day of the month, never past `min` or `max`. Tab goes round
17
+ * the month buttons and the focused day. The chosen day is selected for assistive technology,
18
+ * and today is the current date.
19
+ */
20
+ export declare function DatePicker({ onChange, className, style, ...props }: DatePickerProps): import("react").JSX.Element;
@@ -0,0 +1,33 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { classes, DATE_PICKER_NAV_CLASS, datePickerContentAttrs, datePickerIds, datePickerLocale, datePickerMachineProps, datePickerTriggerAttrs, focusOpeningDay, formatDay, keepCalendarFocus, keepDayFocused, } from "@xds/core";
3
+ import * as datePicker from "@zag-js/date-picker";
4
+ import { mergeProps, normalizeProps, useMachine } from "@zag-js/react";
5
+ import { useEffect, useId, useRef } from "react";
6
+ import { Icon } from "./Icon.js";
7
+ import { useModalPopover } from "./modal-popover.js";
8
+ import { Portal } from "./portal.js";
9
+ import { usePresence } from "./presence.js";
10
+ export function DatePicker({ onChange, className, style, ...props }) {
11
+ const { label, value, placeholder, description, error, name } = props;
12
+ const id = useId();
13
+ const ids = datePickerIds(id);
14
+ const locale = datePickerLocale();
15
+ const service = useMachine(datePicker.machine, datePickerMachineProps(props, { id, locale, onChange }));
16
+ const api = datePicker.connect(service, normalizeProps);
17
+ const trigger = api.getTriggerProps();
18
+ const positioner = useRef(null);
19
+ const surface = useRef(null);
20
+ useModalPopover(api.open, () => positioner.current);
21
+ const present = usePresence(api.open, () => [surface.current]);
22
+ const focused = api.focusedValue.toString();
23
+ const month = api.visibleRange.start.toString();
24
+ useEffect(() => keepDayFocused(api.open, surface.current), [api.open, focused, month]);
25
+ const invalid = error !== undefined;
26
+ return (_jsxs("div", { ...mergeProps(api.getRootProps(), {
27
+ className: classes("xds-date-picker", className),
28
+ style,
29
+ }), children: [_jsx("span", { id: ids.label, className: "xds-date-picker__label", children: label }), _jsx("div", { ...api.getControlProps(), className: "xds-date-picker__control", children: _jsxs("button", { ...trigger, ...datePickerTriggerAttrs(props, ids), type: "button", onClick: (event) => {
30
+ focusOpeningDay(api, props);
31
+ trigger.onClick?.(event);
32
+ }, className: "xds-date-picker__trigger", children: [_jsx("span", { id: ids.value, className: "xds-date-picker__value", children: value === undefined ? placeholder : formatDay(value, locale) }), _jsx(Icon, { name: "calendar", size: "sm", className: "text-xds-field-placeholder" })] }) }), (invalid || description) && (_jsx("div", { className: "xds-date-picker__footer", children: invalid ? (_jsx("span", { id: ids.error, className: "xds-date-picker__error", children: error })) : (_jsx("span", { id: ids.description, className: "xds-date-picker__description", children: description })) })), name !== undefined && _jsx("input", { type: "hidden", name: name, value: value ?? "" }), _jsxs(Portal, { children: [api.open && (_jsx("div", { className: "xds-date-picker__underlay", onMouseDown: (event) => event.preventDefault() })), _jsx("div", { ...api.getPositionerProps(), ref: positioner, className: "xds-date-picker__positioner", children: _jsxs("div", { ...api.getContentProps(), ...datePickerContentAttrs(ids), ref: surface, hidden: !present, onKeyDown: (event) => keepCalendarFocus(event, surface.current), className: "xds-date-picker__content", children: [_jsxs("div", { className: "xds-date-picker__header", children: [_jsx("button", { ...api.getPreviousTriggerProps(), type: "button", className: DATE_PICKER_NAV_CLASS, children: _jsx(Icon, { name: "chevron-left", size: "sm" }) }), _jsx("span", { ...api.getRangeTextProps(), className: "xds-date-picker__heading", children: api.visibleRangeText.start }), _jsx("button", { ...api.getNextTriggerProps(), type: "button", className: DATE_PICKER_NAV_CLASS, children: _jsx(Icon, { name: "chevron-right", size: "sm" }) })] }), _jsxs("table", { ...api.getTableProps({ view: "day" }), className: "xds-date-picker__grid", children: [_jsx("thead", { ...api.getTableHeadProps({ view: "day" }), children: _jsx("tr", { ...api.getTableRowProps({ view: "day" }), children: api.weekDays.map((weekDay) => (_jsx("th", { scope: "col", className: "xds-date-picker__weekday", children: weekDay.narrow }, weekDay.long))) }) }), _jsx("tbody", { ...api.getTableBodyProps({ view: "day" }), children: api.weeks.map((week) => (_jsx("tr", { ...api.getTableRowProps({ view: "day" }), children: week.map((date) => (_jsx("td", { ...api.getDayTableCellProps({ value: date }), className: "xds-date-picker__cell", children: _jsx("div", { ...api.getDayTableCellTriggerProps({ value: date }), className: "xds-date-picker__day", children: date.day }) }, date.toString()))) }, week[0]?.toString()))) })] })] }) })] })] }));
33
+ }
@@ -0,0 +1,24 @@
1
+ import { type DateRange, type DateRangePickerBaseProps } from "@xds/core";
2
+ import type { RootProps } from "./root.ts";
3
+ export type { DateRange } from "@xds/core";
4
+ export type DateRangePickerProps = DateRangePickerBaseProps & RootProps & {
5
+ onChange: (value: DateRange) => void;
6
+ };
7
+ /**
8
+ * A field for choosing a range of days, a start and an end, as for a stay. Closed, it looks like
9
+ * a DatePicker and shows both days in the locale's medium form ("Mar 10 – 14, 2026"), or the
10
+ * placeholder. Pressed, it opens a calendar under itself, two months side by side where the
11
+ * window has room and one where it does not, on the start's month, or on today's while nothing
12
+ * is chosen.
13
+ *
14
+ * The first day pressed starts the range, and the band previews it to the day under the pointer
15
+ * or the keyboard's focus. The second ends it, if the days between are at least `minLength` and
16
+ * at most `maxLength`, which leave the other days unavailable meanwhile: `onChange` gets the
17
+ * range and the calendar closes. A day before the start starts again from there. Escape or a
18
+ * press outside closes the calendar without a change.
19
+ *
20
+ * The keys are DatePicker's, and Page Up and Page Down move a month whether one or two are
21
+ * shown. Each month is a grid named by its month; every day of the range is selected, and the
22
+ * two ends are named by `startLabel` and `endLabel` before the day.
23
+ */
24
+ export declare function DateRangePicker({ onChange, className, style, ...props }: DateRangePickerProps): import("react").JSX.Element;
@@ -0,0 +1,48 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { classes, DATE_PICKER_NAV_CLASS, dateRangeMachineProps, datePickerContentAttrs, datePickerIds, datePickerLocale, datePickerTriggerAttrs, endRangeChoiceOnClose, focusOpeningDay, formatRange, keepCalendarFocus, keepDayFocused, keepRangePreview, rangeDayClick, rangeGridKeyDown, rangeMonths, rangeMonthViews, rangeSummary, shownRange, } from "@xds/core";
3
+ import * as datePicker from "@zag-js/date-picker";
4
+ import { mergeProps, normalizeProps, useMachine } from "@zag-js/react";
5
+ import { useEffect, useId, useRef, useState } from "react";
6
+ import { Icon } from "./Icon.js";
7
+ import { useModalPopover } from "./modal-popover.js";
8
+ import { Portal } from "./portal.js";
9
+ import { usePresence } from "./presence.js";
10
+ export function DateRangePicker({ onChange, className, style, ...props }) {
11
+ const { label, value, placeholder, description, error, startName, endName } = props;
12
+ const id = useId();
13
+ const ids = datePickerIds(id);
14
+ const locale = datePickerLocale();
15
+ const [draft, setDraft] = useState(null);
16
+ const [months, setMonths] = useState(1);
17
+ const shown = shownRange(value, draft);
18
+ const service = useMachine(datePicker.machine, dateRangeMachineProps(props, shown, { id, locale, months, onDraft: setDraft, onChange }));
19
+ const api = datePicker.connect(service, normalizeProps);
20
+ const trigger = api.getTriggerProps();
21
+ const positioner = useRef(null);
22
+ const surface = useRef(null);
23
+ useModalPopover(api.open, () => positioner.current);
24
+ const present = usePresence(api.open, () => [surface.current]);
25
+ const focused = api.focusedValue.toString();
26
+ const month = api.visibleRange.start.toString();
27
+ useEffect(() => keepDayFocused(api.open, surface.current), [api.open, focused, month]);
28
+ useEffect(() => endRangeChoiceOnClose(service, api.open), [api.open]);
29
+ useEffect(() => keepRangePreview(service, shown, api.open), [focused]);
30
+ const summary = rangeSummary(shown, props, locale);
31
+ const invalid = error !== undefined;
32
+ return (_jsxs("div", { ...mergeProps(api.getRootProps(), {
33
+ className: classes("xds-date-picker xds-date-range-picker", className),
34
+ style,
35
+ }), children: [_jsx("span", { id: ids.label, className: "xds-date-picker__label", children: label }), _jsx("div", { ...api.getControlProps(), className: "xds-date-picker__control", children: _jsxs("button", { ...trigger, ...datePickerTriggerAttrs(props, ids), type: "button", onClick: (event) => {
36
+ if (!api.open)
37
+ setMonths(rangeMonths());
38
+ focusOpeningDay(api, { ...props, value: value?.start });
39
+ trigger.onClick?.(event);
40
+ }, className: "xds-date-picker__trigger", children: [_jsx("span", { id: ids.value, className: "xds-date-picker__value", children: value === undefined ? placeholder : formatRange(value, locale) }), _jsx(Icon, { name: "calendar", size: "sm", className: "text-xds-field-placeholder" })] }) }), (invalid || description) && (_jsx("div", { className: "xds-date-picker__footer", children: invalid ? (_jsx("span", { id: ids.error, className: "xds-date-picker__error", children: error })) : (_jsx("span", { id: ids.description, className: "xds-date-picker__description", children: description })) })), startName !== undefined && (_jsx("input", { type: "hidden", name: startName, value: value?.start ?? "" })), endName !== undefined && _jsx("input", { type: "hidden", name: endName, value: value?.end ?? "" }), _jsxs(Portal, { children: [api.open && (_jsx("div", { className: "xds-date-picker__underlay", onMouseDown: (event) => event.preventDefault() })), _jsx("div", { ...api.getPositionerProps(), ref: positioner, className: "xds-date-picker__positioner", children: _jsxs("div", { ...api.getContentProps(), ...datePickerContentAttrs(ids), ref: surface, hidden: !present, onKeyDown: (event) => keepCalendarFocus(event, surface.current), className: "xds-date-picker__content xds-date-range-picker__content", children: [_jsxs("div", { className: "xds-date-range-picker__summary", "aria-live": "polite", children: [_jsx("span", { children: summary.start }), _jsx("span", { children: summary.end })] }), _jsx("div", { className: "xds-date-range-picker__months", children: rangeMonthViews(api, months).map((view) => {
41
+ const table = api.getTableProps({ view: "day", id: view.table.id });
42
+ return (_jsxs("div", { className: "xds-date-range-picker__month", children: [_jsxs("div", { className: "xds-date-picker__header", children: [view.index === 0 ? (_jsx("button", { ...api.getPreviousTriggerProps(), type: "button", className: DATE_PICKER_NAV_CLASS, children: _jsx(Icon, { name: "chevron-left", size: "sm" }) })) : (_jsx("span", { className: "xds-date-range-picker__nav-space" })), _jsx("span", { ...api.getRangeTextProps(), className: "xds-date-picker__heading", children: view.name }), view.index === months - 1 ? (_jsx("button", { ...api.getNextTriggerProps(), type: "button", className: DATE_PICKER_NAV_CLASS, children: _jsx(Icon, { name: "chevron-right", size: "sm" }) })) : (_jsx("span", { className: "xds-date-range-picker__nav-space" }))] }), _jsxs("table", { ...table, ...view.table, onKeyDown: (event) => rangeGridKeyDown(event, api, shown, props, table.onKeyDown), className: "xds-date-picker__grid", children: [_jsx("thead", { ...api.getTableHeadProps({ view: "day" }), children: _jsx("tr", { ...api.getTableRowProps({ view: "day" }), children: api.weekDays.map((weekDay) => (_jsx("th", { scope: "col", className: "xds-date-picker__weekday", children: weekDay.narrow }, weekDay.long))) }) }), _jsx("tbody", { ...api.getTableBodyProps({ view: "day" }), children: view.weeks.map((week) => (_jsx("tr", { ...api.getTableRowProps({ view: "day" }), children: week.map((date) => {
43
+ const cell = { value: date, visibleRange: view.visibleRange };
44
+ const day = api.getDayTableCellTriggerProps(cell);
45
+ return (_jsx("td", { ...api.getDayTableCellProps(cell), className: "xds-date-picker__cell", children: _jsx("div", { ...day, onClick: (event) => rangeDayClick(event, api, shown, props, date, view.visibleRange, day.onClick), className: "xds-date-picker__day", children: date.day }) }, date.toString()));
46
+ }) }, week[0]?.toString()))) })] })] }, view.index));
47
+ }) })] }) })] })] }));
48
+ }
@@ -0,0 +1,17 @@
1
+ import { type ComponentDefaults, type DefaultedComponent } from "@xds/core";
2
+ import { type ReactNode } from "react";
3
+ export type { ComponentDefaults } from "@xds/core";
4
+ export type DefaultsProps = {
5
+ /** By component, what it takes for an option it is not given, such as Button's `variant`. */
6
+ value: ComponentDefaults;
7
+ children: ReactNode;
8
+ };
9
+ /**
10
+ * Gives the components inside it their defaults: a component takes the value for an option
11
+ * the app leaves out from the closest Defaults around it, and its own built-in default when no
12
+ * Defaults names one. A Defaults inside another keeps the outer one's values and replaces those
13
+ * it names, option by option.
14
+ */
15
+ export declare function Defaults({ value, children }: DefaultsProps): import("react").JSX.Element;
16
+ /** The defaults that the closest Defaults gives component `name`, or none. */
17
+ export declare function useDefaults<N extends DefaultedComponent>(name: N): NonNullable<ComponentDefaults[N]>;
@@ -0,0 +1,13 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { mergeDefaults } from "@xds/core";
3
+ import { createContext, useContext, useMemo } from "react";
4
+ const DefaultsContext = createContext({});
5
+ export function Defaults({ value, children }) {
6
+ const outer = useContext(DefaultsContext);
7
+ const key = JSON.stringify(value);
8
+ const merged = useMemo(() => mergeDefaults(outer, value), [outer, key]);
9
+ return _jsx(DefaultsContext, { value: merged, children: children });
10
+ }
11
+ export function useDefaults(name) {
12
+ return useContext(DefaultsContext)[name] ?? {};
13
+ }
@@ -0,0 +1,20 @@
1
+ import { type DialogBaseProps } from "@xds/core";
2
+ import { type ReactNode } from "react";
3
+ import type { RootProps } from "./root.ts";
4
+ /** `className` and `style` are for the dialog's panel, not for the backdrop around it. */
5
+ export type DialogProps = DialogBaseProps & RootProps & {
6
+ /** Called on Escape and on a press outside the dialog. Set `open` to false in it. */
7
+ onClose: () => void;
8
+ /** The body, between the description and the actions. It scrolls when it is too tall. */
9
+ children?: ReactNode;
10
+ /** Buttons, in a row at the end edge. Put the main action last. */
11
+ actions?: ReactNode;
12
+ };
13
+ /**
14
+ * A window that interrupts the screen for a confirmation or a short task. Everything behind it
15
+ * is dimmed and cannot be reached until it closes.
16
+ *
17
+ * It is a modal dialog named by its title and described by its description. Focus moves into
18
+ * it, stays inside it, and returns to where it was when it closes.
19
+ */
20
+ export declare function Dialog({ open, onClose, title, description, children, actions, dismissible, className, style, }: DialogProps): import("react").JSX.Element | null;