@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.
- package/LICENSE +21 -0
- package/README.md +19 -2
- package/dist/Accordion.d.ts +20 -0
- package/dist/Accordion.js +39 -0
- package/dist/Avatar.d.ts +9 -0
- package/dist/Avatar.js +10 -0
- package/dist/AvatarStack.d.ts +8 -0
- package/dist/AvatarStack.js +10 -0
- package/dist/Badge.d.ts +13 -0
- package/dist/Badge.js +9 -0
- package/dist/Banner.d.ts +23 -0
- package/dist/Banner.js +10 -0
- package/dist/Button.d.ts +14 -0
- package/dist/Button.js +31 -0
- package/dist/Card.d.ts +18 -0
- package/dist/Card.js +14 -0
- package/dist/Checkbox.d.ts +10 -0
- package/dist/Checkbox.js +5 -0
- package/dist/Chip.d.ts +12 -0
- package/dist/Chip.js +7 -0
- package/dist/ChipBar.d.ts +12 -0
- package/dist/ChipBar.js +5 -0
- package/dist/CountBadge.d.ts +12 -0
- package/dist/CountBadge.js +11 -0
- package/dist/DatePicker.d.ts +20 -0
- package/dist/DatePicker.js +33 -0
- package/dist/DateRangePicker.d.ts +24 -0
- package/dist/DateRangePicker.js +48 -0
- package/dist/Defaults.d.ts +17 -0
- package/dist/Defaults.js +13 -0
- package/dist/Dialog.d.ts +20 -0
- package/dist/Dialog.js +33 -0
- package/dist/Divider.d.ts +4 -0
- package/dist/Divider.js +5 -0
- package/dist/EmptyState.d.ts +12 -0
- package/dist/EmptyState.js +6 -0
- package/dist/Icon.d.ts +9 -0
- package/dist/Icon.js +9 -0
- package/dist/IconButton.d.ts +12 -0
- package/dist/IconButton.js +24 -0
- package/dist/ListRow.d.ts +21 -0
- package/dist/ListRow.js +15 -0
- package/dist/MediaCard.d.ts +20 -0
- package/dist/MediaCard.js +17 -0
- package/dist/Menu.d.ts +18 -0
- package/dist/Menu.js +68 -0
- package/dist/ProgressBar.d.ts +8 -0
- package/dist/ProgressBar.js +6 -0
- package/dist/RadioGroup.d.ts +15 -0
- package/dist/RadioGroup.js +15 -0
- package/dist/SearchField.d.ts +15 -0
- package/dist/SearchField.js +20 -0
- package/dist/SectionHeader.d.ts +14 -0
- package/dist/SectionHeader.js +8 -0
- package/dist/SegmentedControl.d.ts +12 -0
- package/dist/SegmentedControl.js +7 -0
- package/dist/Select.d.ts +18 -0
- package/dist/Select.js +66 -0
- package/dist/Sidebar.d.ts +21 -0
- package/dist/Sidebar.js +27 -0
- package/dist/Skeleton.d.ts +11 -0
- package/dist/Skeleton.js +8 -0
- package/dist/Slider.d.ts +13 -0
- package/dist/Slider.js +44 -0
- package/dist/Spinner.d.ts +9 -0
- package/dist/Spinner.js +8 -0
- package/dist/Switch.d.ts +13 -0
- package/dist/Switch.js +5 -0
- package/dist/Tabs.d.ts +14 -0
- package/dist/Tabs.js +21 -0
- package/dist/Text.d.ts +10 -0
- package/dist/Text.js +8 -0
- package/dist/TextField.d.ts +22 -0
- package/dist/TextField.js +30 -0
- package/dist/Thumbnail.d.ts +9 -0
- package/dist/Thumbnail.js +13 -0
- package/dist/Toast.d.ts +14 -0
- package/dist/Toast.js +33 -0
- package/dist/Tooltip.d.ts +26 -0
- package/dist/Tooltip.js +32 -0
- package/dist/index.d.ts +39 -0
- package/dist/index.js +39 -0
- package/dist/modal-popover.d.ts +7 -0
- package/dist/modal-popover.js +15 -0
- package/dist/picture.d.ts +11 -0
- package/dist/picture.js +21 -0
- package/dist/portal.d.ts +9 -0
- package/dist/portal.js +7 -0
- package/dist/presence.d.ts +6 -0
- package/dist/presence.js +13 -0
- package/dist/preview.d.ts +6 -0
- package/dist/preview.js +82 -0
- package/dist/root.d.ts +12 -0
- package/dist/root.js +0 -0
- package/dist/trigger.d.ts +17 -0
- package/dist/trigger.js +14 -0
- package/package.json +61 -4
- package/page.css +20 -0
- package/styles.css +3252 -0
- package/tailwind.css +2665 -0
package/dist/Dialog.js
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { classes, leaveEscapeToFields } from "@xds/core";
|
|
3
|
+
import * as dialog from "@zag-js/dialog";
|
|
4
|
+
import { mergeProps, normalizeProps, useMachine } from "@zag-js/react";
|
|
5
|
+
import { useId, useRef } from "react";
|
|
6
|
+
import { Portal } from "./portal.js";
|
|
7
|
+
import { usePresence } from "./presence.js";
|
|
8
|
+
import { TriggerContext } from "./trigger.js";
|
|
9
|
+
export function Dialog({ open, onClose, title, description, children, actions, dismissible = true, className, style, }) {
|
|
10
|
+
const backdrop = useRef(null);
|
|
11
|
+
const positioner = useRef(null);
|
|
12
|
+
const content = useRef(null);
|
|
13
|
+
const service = useMachine(dialog.machine, {
|
|
14
|
+
id: useId(),
|
|
15
|
+
open,
|
|
16
|
+
onOpenChange: (details) => {
|
|
17
|
+
if (!details.open)
|
|
18
|
+
onClose();
|
|
19
|
+
},
|
|
20
|
+
closeOnEscape: dismissible,
|
|
21
|
+
closeOnInteractOutside: dismissible,
|
|
22
|
+
onEscapeKeyDown: leaveEscapeToFields,
|
|
23
|
+
initialFocusEl: () => content.current,
|
|
24
|
+
});
|
|
25
|
+
const api = dialog.connect(service, normalizeProps);
|
|
26
|
+
const present = usePresence(api.open, () => [backdrop.current, positioner.current]);
|
|
27
|
+
if (!present)
|
|
28
|
+
return null;
|
|
29
|
+
return (_jsx(Portal, { children: _jsxs(TriggerContext, { value: null, children: [_jsx("div", { ...api.getBackdropProps(), ref: backdrop, hidden: false, onMouseDown: (event) => event.preventDefault(), className: "xds-dialog__backdrop" }), _jsx("div", { ...api.getPositionerProps(), ref: positioner, className: "xds-dialog__positioner", children: _jsxs("section", { ...mergeProps(api.getContentProps(), {
|
|
30
|
+
className: classes("xds-dialog", className),
|
|
31
|
+
style,
|
|
32
|
+
}), ref: content, hidden: false, children: [_jsx("h2", { ...api.getTitleProps(), className: "xds-dialog__title", children: title }), description && (_jsx("p", { ...api.getDescriptionProps(), className: "xds-dialog__description", children: description })), children != null && _jsx("div", { className: "xds-dialog__body", children: children }), actions != null && _jsx("div", { className: "xds-dialog__actions", children: actions })] }) })] }) }));
|
|
33
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { RootProps } from "./root.ts";
|
|
2
|
+
export type DividerProps = RootProps;
|
|
3
|
+
/** A line between groups of content. Decorative lines use the low-contrast border color. */
|
|
4
|
+
export declare function Divider({ className, style }: DividerProps): import("react").JSX.Element;
|
package/dist/Divider.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { type EmptyStateBaseProps } from "@xds/core";
|
|
2
|
+
import type { ReactNode } from "react";
|
|
3
|
+
import type { RootProps } from "./root.ts";
|
|
4
|
+
export type EmptyStateProps = EmptyStateBaseProps & RootProps & {
|
|
5
|
+
/** The one thing to do about it, usually a Button. */
|
|
6
|
+
action?: ReactNode;
|
|
7
|
+
};
|
|
8
|
+
/**
|
|
9
|
+
* What a screen or a list says when it has nothing to show. It centers itself in its container,
|
|
10
|
+
* also vertically when the container is a flex box with room to spare.
|
|
11
|
+
*/
|
|
12
|
+
export declare function EmptyState({ icon, title, description, action, className, style, }: EmptyStateProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { classes, EMPTY_STATE_PARTS, rootPart } from "@xds/core";
|
|
3
|
+
import { Icon } from "./Icon.js";
|
|
4
|
+
export function EmptyState({ icon, title, description, action, className, style, }) {
|
|
5
|
+
return (_jsxs("div", { className: classes(rootPart("EmptyState"), EMPTY_STATE_PARTS.root, className), style: style, children: [_jsx(Icon, { name: icon, size: "xl", className: EMPTY_STATE_PARTS.icon }), _jsx("p", { className: EMPTY_STATE_PARTS.title, children: title }), description && _jsx("p", { className: EMPTY_STATE_PARTS.description, children: description }), action != null && _jsx("div", { className: EMPTY_STATE_PARTS.action, children: action })] }));
|
|
6
|
+
}
|
package/dist/Icon.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { type IconBaseProps } from "@xds/core";
|
|
2
|
+
import type { RootProps } from "./root.ts";
|
|
3
|
+
export type { IconName, IconSize } from "@xds/core";
|
|
4
|
+
export type IconProps = IconBaseProps & RootProps;
|
|
5
|
+
/**
|
|
6
|
+
* An icon from design/icons. It takes the color of the text around it. An arrow or a chevron
|
|
7
|
+
* mirrors itself in a right-to-left layout when given `rtl:-scale-x-100` in `className`.
|
|
8
|
+
*/
|
|
9
|
+
export declare function Icon(props: IconProps): import("react").JSX.Element;
|
package/dist/Icon.js
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { icons } from "@xds/tokens";
|
|
3
|
+
import { classes, iconClass, rootPart } from "@xds/core";
|
|
4
|
+
import { useDefaults } from "./Defaults.js";
|
|
5
|
+
export function Icon(props) {
|
|
6
|
+
const defaults = useDefaults("Icon");
|
|
7
|
+
const { name, size = defaults.size, filled = false, label, className, style } = props;
|
|
8
|
+
return (_jsx("svg", { viewBox: "0 0 24 24", fill: filled ? "currentColor" : "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round", className: classes(rootPart("Icon"), iconClass(size), className), style: style, ...(label ? { role: "img", "aria-label": label } : { "aria-hidden": true }), children: icons[name].map((path) => (_jsx("path", { d: path }, path))) }));
|
|
9
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { type IconButtonBaseProps } from "@xds/core";
|
|
2
|
+
import type { RootProps } from "./root.ts";
|
|
3
|
+
export type IconButtonProps = IconButtonBaseProps & RootProps & {
|
|
4
|
+
onPress?: () => void;
|
|
5
|
+
};
|
|
6
|
+
/**
|
|
7
|
+
* A button that holds only an icon, in Button's variants, sizes and states. It is a square as
|
|
8
|
+
* tall as a Button of its size, and its pressable area is never smaller than the minimum
|
|
9
|
+
* target, even when the square is. Like Button, it opens a Menu or a Tooltip it is the trigger
|
|
10
|
+
* of.
|
|
11
|
+
*/
|
|
12
|
+
export declare function IconButton(props: IconButtonProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { buttonClass, classes, ICON_BUTTON_BOX, 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 IconButton(props) {
|
|
8
|
+
const defaults = useDefaults("IconButton");
|
|
9
|
+
const { icon, label, variant = defaults.variant ?? "ghost", size = defaults.size ?? "md", selected, disabled = false, loading = false, onPress, className, style, } = props;
|
|
10
|
+
const attributes = useTrigger({
|
|
11
|
+
className: classes(buttonClass({ variant, size, iconButton: true }), className),
|
|
12
|
+
style,
|
|
13
|
+
disabled,
|
|
14
|
+
"aria-disabled": loading || undefined,
|
|
15
|
+
"data-pending": loading ? "" : undefined,
|
|
16
|
+
"aria-pressed": selected,
|
|
17
|
+
"aria-label": label,
|
|
18
|
+
onClick: () => {
|
|
19
|
+
if (!loading)
|
|
20
|
+
onPress?.();
|
|
21
|
+
},
|
|
22
|
+
}, loading);
|
|
23
|
+
return (_jsx("button", { ...attributes, type: "button", children: loading ? (_jsx("span", { className: ICON_BUTTON_BOX[size], children: _jsx(Spinner, { size: "sm" }) })) : (_jsx(Icon, { name: icon, size: size, filled: isHeld({ variant, selected, disabled }) })) }));
|
|
24
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { type ListRowBaseProps } from "@xds/core";
|
|
2
|
+
import type { ReactNode } from "react";
|
|
3
|
+
import type { RootProps } from "./root.ts";
|
|
4
|
+
export type ListRowProps = ListRowBaseProps & RootProps & {
|
|
5
|
+
/** In front of the title: an avatar or an icon. */
|
|
6
|
+
leading?: ReactNode;
|
|
7
|
+
/** At the far end: a value, a badge or a switch. */
|
|
8
|
+
trailing?: ReactNode;
|
|
9
|
+
/** Makes the whole row a button. Do not put another control in `trailing` then. */
|
|
10
|
+
onPress?: () => void;
|
|
11
|
+
};
|
|
12
|
+
/** One line of a list or a settings screen. Separate rows with a Divider. */
|
|
13
|
+
export declare function ListRow(props: ListRowProps): import("react").JSX.Element;
|
|
14
|
+
/**
|
|
15
|
+
* A ListRow that says what kind of current item its selected state is. A Sidebar's rows are the
|
|
16
|
+
* places of an app, so its selected row is the current page. Only for this package's own
|
|
17
|
+
* components: the index does not export it.
|
|
18
|
+
*/
|
|
19
|
+
export declare function PlaceRow({ title, description, leading, trailing, chevron, selected, compact, onPress, disabled, current, className, style, }: ListRowProps & {
|
|
20
|
+
current: "true" | "page";
|
|
21
|
+
}): import("react").JSX.Element;
|
package/dist/ListRow.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { LIST_ROW_PARTS, classes, listRowClass, listRowDescriptionClass, listRowTitleClass, rootPart, } from "@xds/core";
|
|
3
|
+
import { Icon } from "./Icon.js";
|
|
4
|
+
export function ListRow(props) {
|
|
5
|
+
return _jsx(PlaceRow, { ...props, current: "true" });
|
|
6
|
+
}
|
|
7
|
+
export function PlaceRow({ title, description, leading, trailing, chevron = false, selected = false, compact = false, onPress, disabled = false, current, className, style, }) {
|
|
8
|
+
const row = classes(rootPart("ListRow"), listRowClass({ compact, selected, pressable: onPress !== undefined }), className);
|
|
9
|
+
const currentProps = selected ? { "aria-current": current } : {};
|
|
10
|
+
const content = (_jsxs(_Fragment, { children: [leading, _jsxs("span", { className: LIST_ROW_PARTS.text, children: [_jsx("span", { className: listRowTitleClass({ compact, selected, disabled }), children: title }), description && _jsx("span", { className: listRowDescriptionClass(compact), children: description })] }), trailing, chevron && _jsx(Icon, { name: "chevron-right", size: "sm", className: LIST_ROW_PARTS.chevron })] }));
|
|
11
|
+
if (!onPress) {
|
|
12
|
+
return (_jsx("div", { ...currentProps, className: row, style: style, children: content }));
|
|
13
|
+
}
|
|
14
|
+
return (_jsx("button", { ...currentProps, type: "button", disabled: disabled, onClick: onPress, className: row, style: style, children: content }));
|
|
15
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { type MediaCardBaseProps } from "@xds/core";
|
|
2
|
+
import { type ReactNode } from "react";
|
|
3
|
+
import type { RootProps } from "./root.ts";
|
|
4
|
+
export type MediaCardProps = MediaCardBaseProps & RootProps & {
|
|
5
|
+
/** Before the text in the vertical layout, such as an Avatar. */
|
|
6
|
+
leading?: ReactNode;
|
|
7
|
+
/** At the end of the text: an IconButton or a Menu. It stays a control of its own. */
|
|
8
|
+
action?: ReactNode;
|
|
9
|
+
/** Makes the whole card one button. */
|
|
10
|
+
onPress?: () => void;
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* A thumbnail with its title and details: a video in a feed, an article in a list.
|
|
14
|
+
*
|
|
15
|
+
* With `onPress` the whole card is one button with no surface at rest: under a pointer and
|
|
16
|
+
* while pressed it takes the card's fills, and it has a focus ring. The button is named by the
|
|
17
|
+
* title followed by the details. `action` is a separate control beside it, so pressing it does
|
|
18
|
+
* not press the card.
|
|
19
|
+
*/
|
|
20
|
+
export declare function MediaCard(props: MediaCardProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { classes, MEDIA_CARD_PARTS, mediaCardContentClass, mediaCardIds, mediaCardThumbnailClass, rootPart, } from "@xds/core";
|
|
3
|
+
import { useId } from "react";
|
|
4
|
+
import { useDefaults } from "./Defaults.js";
|
|
5
|
+
import { Thumbnail } from "./Thumbnail.js";
|
|
6
|
+
export function MediaCard(props) {
|
|
7
|
+
const defaults = useDefaults("MediaCard");
|
|
8
|
+
const { layout = defaults.layout ?? "vertical", src, alt = "", ratio = "16:9", badge, progress, title, meta = [], leading, action, onPress, className, style, } = props;
|
|
9
|
+
const ids = mediaCardIds(useId(), meta);
|
|
10
|
+
const part = onPress ? { "aria-hidden": true } : {};
|
|
11
|
+
const horizontal = layout === "horizontal";
|
|
12
|
+
const content = (_jsxs("div", { className: mediaCardContentClass({ horizontal, pressable: onPress !== undefined }), children: [_jsx("span", { ...part, className: mediaCardThumbnailClass(horizontal), children: _jsx(Thumbnail, { src: src, alt: alt, ratio: ratio, badge: badge, progress: progress }) }), _jsxs("div", { className: MEDIA_CARD_PARTS.body, children: [!horizontal && leading != null && (_jsx("span", { ...part, className: MEDIA_CARD_PARTS.leading, children: leading })), _jsxs("span", { ...part, className: MEDIA_CARD_PARTS.text, children: [_jsx("span", { id: ids.title, className: MEDIA_CARD_PARTS.title, children: title }), meta.map((line, index) => (_jsx("span", { id: ids.details[index], className: MEDIA_CARD_PARTS.meta, children: line }, index)))] }), action != null && _jsx("div", { className: MEDIA_CARD_PARTS.action, children: action })] })] }));
|
|
13
|
+
if (!onPress) {
|
|
14
|
+
return (_jsx("div", { role: "group", "aria-labelledby": ids.names, className: classes(rootPart("MediaCard"), MEDIA_CARD_PARTS.group, className), style: style, children: content }));
|
|
15
|
+
}
|
|
16
|
+
return (_jsxs("div", { className: classes(rootPart("MediaCard"), MEDIA_CARD_PARTS.pressable, className), style: style, children: [_jsx("button", { type: "button", onClick: onPress, "aria-labelledby": ids.names, className: MEDIA_CARD_PARTS.button }), content] }));
|
|
17
|
+
}
|
package/dist/Menu.d.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { type MenuBaseProps } from "@xds/core";
|
|
2
|
+
import { type ReactNode } from "react";
|
|
3
|
+
import type { RootProps } from "./root.ts";
|
|
4
|
+
export type { MenuItem } from "@xds/core";
|
|
5
|
+
/** `className` and `style` are for the menu itself, the list that opens, not for its trigger. */
|
|
6
|
+
export type MenuProps = MenuBaseProps & RootProps & {
|
|
7
|
+
/** The control that opens the menu: a Button or an IconButton. */
|
|
8
|
+
trigger: ReactNode;
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* A list of actions that opens from a control. Choosing an item calls its `onSelect` and
|
|
12
|
+
* closes the menu; a press outside or Escape closes it too, and focus goes back to the
|
|
13
|
+
* trigger.
|
|
14
|
+
*
|
|
15
|
+
* The trigger reports that it opens a menu and whether the menu is open. The arrow keys move
|
|
16
|
+
* the highlight and Enter chooses.
|
|
17
|
+
*/
|
|
18
|
+
export declare function Menu({ trigger, label, items, align, className, style }: MenuProps): import("react").JSX.Element;
|
package/dist/Menu.js
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { space } from "@xds/tokens";
|
|
3
|
+
import { classes, firstMenuValue, keepListKeys, layoutRect, leaveEscapeToFields, menuItemClass, opensOnPress, } from "@xds/core";
|
|
4
|
+
import * as menu from "@zag-js/menu";
|
|
5
|
+
import { mergeProps, normalizeProps, useMachine } from "@zag-js/react";
|
|
6
|
+
import { useId, useRef } from "react";
|
|
7
|
+
import { Icon } from "./Icon.js";
|
|
8
|
+
import { useModalPopover } from "./modal-popover.js";
|
|
9
|
+
import { Portal } from "./portal.js";
|
|
10
|
+
import { usePresence } from "./presence.js";
|
|
11
|
+
import { TriggerContext, useProvideTrigger } from "./trigger.js";
|
|
12
|
+
export function Menu({ trigger, label, items, align = "start", className, style }) {
|
|
13
|
+
const service = useMachine(menu.machine, {
|
|
14
|
+
id: useId(),
|
|
15
|
+
"aria-label": label,
|
|
16
|
+
positioning: {
|
|
17
|
+
placement: `bottom-${align}`,
|
|
18
|
+
gutter: space[1],
|
|
19
|
+
getAnchorRect: (anchor) => (anchor instanceof HTMLElement ? layoutRect(anchor) : null),
|
|
20
|
+
},
|
|
21
|
+
onSelect: (details) => {
|
|
22
|
+
const item = items[Number(details.value)];
|
|
23
|
+
if (item && item !== "separator")
|
|
24
|
+
item.onSelect();
|
|
25
|
+
},
|
|
26
|
+
onEscapeKeyDown: leaveEscapeToFields,
|
|
27
|
+
loopFocus: true,
|
|
28
|
+
});
|
|
29
|
+
const api = menu.connect(service, normalizeProps);
|
|
30
|
+
const { onPointerDown: _onPointerDown, ...triggerProps } = api.getTriggerProps();
|
|
31
|
+
const pressOpened = useRef(false);
|
|
32
|
+
const provided = useProvideTrigger(mergeProps(triggerProps, {
|
|
33
|
+
className: "xds-menu__trigger",
|
|
34
|
+
onPointerDown: (event) => {
|
|
35
|
+
pressOpened.current = opensOnPress(event) && !api.open;
|
|
36
|
+
if (pressOpened.current)
|
|
37
|
+
api.setOpen(true);
|
|
38
|
+
},
|
|
39
|
+
onClick: (event) => {
|
|
40
|
+
const pointer = event.detail !== 0;
|
|
41
|
+
if (pressOpened.current && pointer) {
|
|
42
|
+
pressOpened.current = false;
|
|
43
|
+
event.preventDefault();
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
if (pointer)
|
|
47
|
+
return;
|
|
48
|
+
requestAnimationFrame(() => {
|
|
49
|
+
const now = menu.connect(service, normalizeProps);
|
|
50
|
+
if (!now.open)
|
|
51
|
+
return;
|
|
52
|
+
const first = firstMenuValue(items);
|
|
53
|
+
if (first !== undefined)
|
|
54
|
+
now.setHighlightedValue(first);
|
|
55
|
+
});
|
|
56
|
+
},
|
|
57
|
+
}));
|
|
58
|
+
const positioner = useRef(null);
|
|
59
|
+
const surface = useRef(null);
|
|
60
|
+
useModalPopover(api.open, () => positioner.current);
|
|
61
|
+
const present = usePresence(api.open, () => [surface.current]);
|
|
62
|
+
const content = mergeProps(api.getContentProps(), {
|
|
63
|
+
className: classes("xds-menu", className),
|
|
64
|
+
style,
|
|
65
|
+
onKeyDown: (event) => keepListKeys(event, surface.current, ".xds-menu__item:not([data-disabled])", (value) => api.setHighlightedValue(value)),
|
|
66
|
+
});
|
|
67
|
+
return (_jsxs(_Fragment, { children: [_jsx(TriggerContext, { value: provided, children: trigger }), _jsx(Portal, { children: _jsxs(TriggerContext, { value: null, children: [api.open && (_jsx("div", { className: "xds-menu__underlay", onMouseDown: (event) => event.preventDefault() })), _jsx("div", { ...api.getPositionerProps(), ref: positioner, className: "xds-menu__positioner", children: _jsx("div", { ...content, ref: surface, hidden: !present, children: items.map((item, index) => item === "separator" ? (_jsx("div", { ...api.getSeparatorProps(), className: "xds-menu__separator" }, index)) : (_jsxs("div", { ...api.getItemProps({ value: String(index), disabled: item.disabled }), className: menuItemClass(item.danger), children: [item.icon && (_jsx(Icon, { name: item.icon, size: "sm", className: "xds-menu__item-icon" })), _jsx("span", { className: "flex-1", children: item.label }), item.selected && _jsx(Icon, { name: "check", size: "sm", label: "Selected" })] }, index))) }) })] }) })] }));
|
|
68
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { type ProgressBarBaseProps } from "@xds/core";
|
|
2
|
+
import type { RootProps } from "./root.ts";
|
|
3
|
+
export type ProgressBarProps = ProgressBarBaseProps & RootProps;
|
|
4
|
+
/**
|
|
5
|
+
* How far along something is, from 0 to 1. For work of unknown length use a Spinner.
|
|
6
|
+
* `label` says what is progressing; a screen reader reads it with the percentage.
|
|
7
|
+
*/
|
|
8
|
+
export declare function ProgressBar({ value, label, className, style }: ProgressBarProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { classes, progressBarClass, progressBarFillClass, progressPercent, rootPart, } from "@xds/core";
|
|
3
|
+
export function ProgressBar({ value, label, className, style }) {
|
|
4
|
+
const percent = progressPercent(value);
|
|
5
|
+
return (_jsx("div", { role: "progressbar", "aria-label": label, "aria-valuemin": 0, "aria-valuemax": 100, "aria-valuenow": percent, className: classes(rootPart("ProgressBar"), progressBarClass, className), style: style, children: _jsx("div", { className: progressBarFillClass, style: { width: `${percent}%` } }) }));
|
|
6
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { type RadioGroupBaseProps } from "@xds/core";
|
|
2
|
+
import type { RootProps } from "./root.ts";
|
|
3
|
+
export type { RadioOption } from "@xds/core";
|
|
4
|
+
export type RadioGroupProps<Value extends string = string> = RadioGroupBaseProps<Value> & RootProps & {
|
|
5
|
+
onChange: (value: Value) => void;
|
|
6
|
+
};
|
|
7
|
+
/**
|
|
8
|
+
* One choice among a few, applied later with the form it belongs to. For a choice that takes
|
|
9
|
+
* effect at once among two to four options, a SegmentedControl is the usual pick.
|
|
10
|
+
*
|
|
11
|
+
* The chosen option has a dot and a thicker ring, so the choice does not depend on color. The
|
|
12
|
+
* options are native radio buttons, hidden and drawn beside, in a group named by the legend:
|
|
13
|
+
* the arrow keys move between them, and the error is tied to the group and announced.
|
|
14
|
+
*/
|
|
15
|
+
export declare function RadioGroup<Value extends string = string>({ label, options, value, onChange, disabled, error, name, className, style, }: RadioGroupProps<Value>): import("react").JSX.Element;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { classes } from "@xds/core";
|
|
3
|
+
import { useId } from "react";
|
|
4
|
+
export function RadioGroup({ label, options, value, onChange, disabled = false, error, name, className, style, }) {
|
|
5
|
+
const id = useId();
|
|
6
|
+
const labelId = `${id}-label`;
|
|
7
|
+
const errorId = `${id}-error`;
|
|
8
|
+
const invalid = error !== undefined;
|
|
9
|
+
return (_jsxs("div", { role: "radiogroup", "aria-labelledby": labelId, "aria-describedby": invalid ? errorId : undefined, "aria-invalid": invalid || undefined, "aria-disabled": disabled || undefined, "aria-orientation": "vertical", className: classes("xds-radio-group", className), style: style, children: [_jsx("span", { id: labelId, className: "xds-radio-group__label", children: label }), _jsx("div", { className: "xds-radio-group__options", children: options.map((option, index) => (_jsxs("label", { className: "xds-radio-group__option", children: [_jsx("input", { type: "radio", className: "xds-radio-group__input sr-only", name: name ?? id, value: option.value, checked: option.value === value, disabled: disabled, "aria-labelledby": `${id}-${index}`, "aria-describedby": [
|
|
10
|
+
option.description ? `${id}-${index}-description` : undefined,
|
|
11
|
+
invalid ? errorId : undefined,
|
|
12
|
+
]
|
|
13
|
+
.filter(Boolean)
|
|
14
|
+
.join(" ") || undefined, "aria-invalid": invalid || undefined, onChange: () => onChange(option.value) }), _jsxs("span", { className: "xds-radio-group__row", children: [_jsx("span", { className: "xds-radio-group__circle-line", children: _jsx("span", { className: "xds-radio-group__circle", children: _jsx("span", { className: "xds-radio-group__dot" }) }) }), _jsxs("span", { className: "xds-radio-group__words", children: [_jsx("span", { id: `${id}-${index}`, className: "xds-radio-group__text", children: option.label }), option.description && (_jsx("span", { id: `${id}-${index}-description`, className: "xds-radio-group__description", children: option.description }))] })] })] }, option.value))) }), _jsx("div", { "aria-live": "polite", children: invalid && (_jsx("span", { id: errorId, className: "xds-radio-group__error", children: error })) })] }));
|
|
15
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { type SearchFieldBaseProps } from "@xds/core";
|
|
2
|
+
import type { RootProps } from "./root.ts";
|
|
3
|
+
export type SearchFieldProps = SearchFieldBaseProps & RootProps & {
|
|
4
|
+
onChange: (value: string) => void;
|
|
5
|
+
/** Called with the query on Enter, or on the search key of a software keyboard. */
|
|
6
|
+
onSubmit?: (value: string) => void;
|
|
7
|
+
};
|
|
8
|
+
/**
|
|
9
|
+
* A text field for a query: TextField's box as a pill, with a search icon in front and, while
|
|
10
|
+
* there is a value, a control that clears it. Escape clears too.
|
|
11
|
+
*
|
|
12
|
+
* Use it to filter or search what is on the screen. For a value that is saved with a form,
|
|
13
|
+
* use a TextField, which has a visible label.
|
|
14
|
+
*/
|
|
15
|
+
export declare function SearchField({ value, onChange, onSubmit, label, placeholder, disabled, clearLabel, className, style, }: SearchFieldProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { classes, rootPart } from "@xds/core";
|
|
3
|
+
import { useRef } from "react";
|
|
4
|
+
import { Icon } from "./Icon.js";
|
|
5
|
+
export function SearchField({ value, onChange, onSubmit, label, placeholder, disabled = false, clearLabel = "Clear", className, style, }) {
|
|
6
|
+
const input = useRef(null);
|
|
7
|
+
return (_jsx("div", { className: classes("xds-text-field", rootPart("SearchField"), className), style: style, children: _jsxs("div", { className: "xds-text-field__control xds-text-field__control--pill xds-text-field__group", children: [_jsx("span", { className: "xds-text-field__slot xds-text-field__slot--leading", children: _jsx(Icon, { name: "search", size: "sm" }) }), _jsx("input", { ref: input, type: "text", className: "xds-text-field__input", "aria-label": label, enterKeyHint: "search", placeholder: placeholder, value: value, disabled: disabled, "data-uses-escape": value !== "" ? "" : undefined, onChange: (event) => onChange(event.currentTarget.value), onKeyDown: (event) => {
|
|
8
|
+
if (event.nativeEvent.isComposing)
|
|
9
|
+
return;
|
|
10
|
+
if (event.key === "Enter")
|
|
11
|
+
onSubmit?.(value);
|
|
12
|
+
if (event.key === "Escape" && value !== "") {
|
|
13
|
+
event.stopPropagation();
|
|
14
|
+
onChange("");
|
|
15
|
+
}
|
|
16
|
+
} }), value !== "" && !disabled && (_jsx("span", { className: "xds-text-field__slot xds-text-field__slot--trailing", children: _jsx("button", { type: "button", "aria-label": clearLabel, onClick: () => {
|
|
17
|
+
onChange("");
|
|
18
|
+
input.current?.focus();
|
|
19
|
+
}, className: "-me-1 flex size-xds-target-min cursor-pointer items-center justify-center rounded-xds-full hover:text-xds-field-text focus-visible:outline-(length:--xds-focus-width) focus-visible:outline-xds-border-focus focus-visible:outline-solid", children: _jsx(Icon, { name: "circle-x", size: "sm" }) }) }))] }) }));
|
|
20
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { type SectionHeaderBaseProps } from "@xds/core";
|
|
2
|
+
import type { RootProps } from "./root.ts";
|
|
3
|
+
export type SectionHeaderProps = SectionHeaderBaseProps & RootProps & {
|
|
4
|
+
/** A link-like action at the end, such as "See all". */
|
|
5
|
+
action?: {
|
|
6
|
+
label: string;
|
|
7
|
+
onPress: () => void;
|
|
8
|
+
};
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* The title row of a group of content. The title is a heading at `level`; the action is a quiet
|
|
12
|
+
* button with a chevron at its end edge, which points the other way in a right-to-left layout.
|
|
13
|
+
*/
|
|
14
|
+
export declare function SectionHeader({ title, description, icon, action, level, className, style, }: SectionHeaderProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { classes, rootPart, SECTION_HEADER_PARTS, } from "@xds/core";
|
|
3
|
+
import { Button } from "./Button.js";
|
|
4
|
+
import { Icon } from "./Icon.js";
|
|
5
|
+
export function SectionHeader({ title, description, icon, action, level = 2, className, style, }) {
|
|
6
|
+
const Heading = `h${level}`;
|
|
7
|
+
return (_jsxs("div", { className: classes(rootPart("SectionHeader"), SECTION_HEADER_PARTS.root, className), style: style, children: [_jsxs("div", { className: SECTION_HEADER_PARTS.lead, children: [icon && (_jsx("span", { className: SECTION_HEADER_PARTS.icon, children: _jsx(Icon, { name: icon, size: "md" }) })), _jsxs("div", { className: SECTION_HEADER_PARTS.text, children: [_jsx(Heading, { className: SECTION_HEADER_PARTS.title, children: title }), description && _jsx("p", { className: SECTION_HEADER_PARTS.description, children: description })] })] }), action && (_jsx("span", { className: SECTION_HEADER_PARTS.action, children: _jsxs(Button, { variant: "ghost", size: "sm", onPress: action.onPress, children: [action.label, _jsx(Icon, { name: "chevron-right", size: "sm", className: SECTION_HEADER_PARTS.chevron })] }) }))] }));
|
|
8
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { type SegmentedControlBaseProps } from "@xds/core";
|
|
2
|
+
import type { RootProps } from "./root.ts";
|
|
3
|
+
export type SegmentedControlProps<Value extends string> = SegmentedControlBaseProps<Value> & RootProps & {
|
|
4
|
+
onChange: (value: Value) => void;
|
|
5
|
+
};
|
|
6
|
+
/**
|
|
7
|
+
* A choice between a few views or modes, all visible at once. The selected segment is outlined
|
|
8
|
+
* as well as filled, so the choice does not depend on telling two greys apart.
|
|
9
|
+
*
|
|
10
|
+
* It is a group of native radio buttons, so the arrow keys move between segments.
|
|
11
|
+
*/
|
|
12
|
+
export declare function SegmentedControl<Value extends string>({ options, value, onChange, fullWidth, className, style, ...aria }: SegmentedControlProps<Value>): import("react").JSX.Element;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { classes, rootPart, segmentedControlClass, segmentedControlOptionClass, segmentedControlSegmentClass, } from "@xds/core";
|
|
3
|
+
import { useId } from "react";
|
|
4
|
+
export function SegmentedControl({ options, value, onChange, fullWidth = false, className, style, ...aria }) {
|
|
5
|
+
const name = useId();
|
|
6
|
+
return (_jsx("div", { ...aria, role: "radiogroup", className: classes(rootPart("SegmentedControl"), segmentedControlClass(fullWidth), className), style: style, children: options.map((option) => (_jsxs("label", { className: segmentedControlOptionClass(fullWidth), children: [_jsx("input", { type: "radio", name: name, value: option.value, className: "peer sr-only", checked: option.value === value, onChange: () => onChange(option.value) }), _jsx("span", { className: segmentedControlSegmentClass, children: option.label })] }, option.value))) }));
|
|
7
|
+
}
|
package/dist/Select.d.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { type SelectBaseProps } from "@xds/core";
|
|
2
|
+
import type { RootProps } from "./root.ts";
|
|
3
|
+
export type { SelectOption } from "@xds/core";
|
|
4
|
+
/** `className` and `style` are for the field, not for the list that opens from it. */
|
|
5
|
+
export type SelectProps<Value extends string = string> = SelectBaseProps<Value> & RootProps & {
|
|
6
|
+
onChange: (value: Value) => void;
|
|
7
|
+
};
|
|
8
|
+
/**
|
|
9
|
+
* A field for choosing one option from a list too long to show at once. Closed, it looks like a
|
|
10
|
+
* TextField; pressed, it opens the list under itself with a Menu's surface, as wide as the
|
|
11
|
+
* field. Choosing an option calls `onChange` and closes the list; a press outside or Escape
|
|
12
|
+
* closes it too.
|
|
13
|
+
*
|
|
14
|
+
* The field is a button that says it opens a list box and whether the list is open. In the list
|
|
15
|
+
* the arrow keys move, typing jumps to an option, and Enter chooses. The chosen option is
|
|
16
|
+
* selected for assistive technology and marked with a check.
|
|
17
|
+
*/
|
|
18
|
+
export declare function Select<Value extends string = string>({ label, options, value, onChange, placeholder, description, error, name, disabled, className, style, }: SelectProps<Value>): import("react").JSX.Element;
|
package/dist/Select.js
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { space } from "@xds/tokens";
|
|
3
|
+
import { classes, keepListKeys, selectOptionIds, } from "@xds/core";
|
|
4
|
+
import { mergeProps, normalizeProps, useMachine } from "@zag-js/react";
|
|
5
|
+
import * as select from "@zag-js/select";
|
|
6
|
+
import { useId, useMemo, useRef } from "react";
|
|
7
|
+
import { Icon } from "./Icon.js";
|
|
8
|
+
import { useModalPopover } from "./modal-popover.js";
|
|
9
|
+
import { Portal } from "./portal.js";
|
|
10
|
+
import { usePresence } from "./presence.js";
|
|
11
|
+
export function Select({ label, options, value, onChange, placeholder, description, error, name, disabled = false, className, style, }) {
|
|
12
|
+
const id = useId();
|
|
13
|
+
const valueId = `${id}-value`;
|
|
14
|
+
const descriptionId = `${id}-description`;
|
|
15
|
+
const errorId = `${id}-error`;
|
|
16
|
+
const invalid = error !== undefined;
|
|
17
|
+
const collection = useMemo(() => select.collection({
|
|
18
|
+
items: [...options],
|
|
19
|
+
itemToValue: (option) => option.value,
|
|
20
|
+
itemToString: (option) => option.label,
|
|
21
|
+
}), [options]);
|
|
22
|
+
const service = useMachine(select.machine, {
|
|
23
|
+
id,
|
|
24
|
+
collection,
|
|
25
|
+
value: value === undefined ? [] : [value],
|
|
26
|
+
onValueChange: (details) => {
|
|
27
|
+
const next = details.value[0];
|
|
28
|
+
if (next !== undefined)
|
|
29
|
+
onChange(next);
|
|
30
|
+
},
|
|
31
|
+
disabled,
|
|
32
|
+
invalid,
|
|
33
|
+
name,
|
|
34
|
+
positioning: {
|
|
35
|
+
placement: "bottom-start",
|
|
36
|
+
gutter: space[1],
|
|
37
|
+
sameWidth: true,
|
|
38
|
+
overflowPadding: space[3],
|
|
39
|
+
},
|
|
40
|
+
});
|
|
41
|
+
const api = select.connect(service, normalizeProps);
|
|
42
|
+
const current = () => select.connect(service, normalizeProps);
|
|
43
|
+
const { htmlFor: _for, ...labelProps } = api.getLabelProps();
|
|
44
|
+
const { role: _role, "aria-invalid": _invalid, "aria-required": _required, onKeyDown: _onTriggerKeyDown, ...triggerProps } = api.getTriggerProps();
|
|
45
|
+
const positioner = useRef(null);
|
|
46
|
+
const surface = useRef(null);
|
|
47
|
+
const { onKeyDown: _onContentKeyDown, ...contentProps } = api.getContentProps();
|
|
48
|
+
const content = {
|
|
49
|
+
...contentProps,
|
|
50
|
+
onKeyDown: (event) => {
|
|
51
|
+
keepListKeys(event, surface.current, ".xds-select__item:not([data-disabled])", (row) => api.setHighlightedValue(row));
|
|
52
|
+
current().getContentProps().onKeyDown?.(event);
|
|
53
|
+
},
|
|
54
|
+
};
|
|
55
|
+
useModalPopover(api.open, () => positioner.current);
|
|
56
|
+
const present = usePresence(api.open, () => [surface.current]);
|
|
57
|
+
return (_jsxs("div", { ...mergeProps(api.getRootProps(), { className: classes("xds-select", className), style }), children: [_jsx("span", { ...labelProps, className: "xds-select__label", children: label }), _jsxs("button", { ...triggerProps, "aria-labelledby": `${valueId} ${labelProps.id}`, "aria-describedby": invalid ? errorId : description ? descriptionId : undefined, onKeyDown: (event) => {
|
|
58
|
+
const now = current();
|
|
59
|
+
if (!now.open && (event.key === "Home" || event.key === "End"))
|
|
60
|
+
return;
|
|
61
|
+
now.getTriggerProps().onKeyDown?.(event);
|
|
62
|
+
}, type: "button", className: "xds-select__trigger", children: [_jsx("span", { ...api.getValueTextProps(), id: valueId, className: "xds-select__value", children: api.valueAsString || placeholder }), _jsx(Icon, { name: "chevrons-up-down", size: "sm", className: "text-xds-field-placeholder" })] }), (invalid || description) && (_jsx("div", { className: "xds-select__footer", children: invalid ? (_jsx("span", { id: errorId, className: "xds-select__error", children: error })) : (_jsx("span", { id: descriptionId, className: "xds-select__description", children: description })) })), _jsxs("select", { ...api.getHiddenSelectProps(), children: [_jsx("option", { value: "" }), options.map((option) => (_jsx("option", { value: option.value, children: option.label }, option.value)))] }), _jsxs(Portal, { children: [api.open && (_jsx("div", { className: "xds-select__underlay", onMouseDown: (event) => event.preventDefault() })), _jsx("div", { ...api.getPositionerProps(), ref: positioner, className: "xds-select__positioner", children: _jsx("div", { ...content, ref: surface, hidden: !present, className: "xds-select__content", children: _jsx("div", { ...api.getListProps(), className: "xds-select__list", children: collection.items.map((option, index) => {
|
|
63
|
+
const ids = selectOptionIds(id, index);
|
|
64
|
+
return (_jsxs("div", { ...api.getItemProps({ item: option }), "aria-labelledby": ids.label, "aria-describedby": option.description ? ids.description : undefined, className: "xds-select__item", children: [_jsxs("span", { className: "xds-select__item-words", children: [_jsx("span", { ...api.getItemTextProps({ item: option }), id: ids.label, className: "xds-select__item-label", children: option.label }), option.description && (_jsx("span", { id: ids.description, className: "xds-select__item-description", children: option.description }))] }), api.getItemState({ item: option }).selected && _jsx(Icon, { name: "check", size: "sm" })] }, option.value));
|
|
65
|
+
}) }) }) })] })] }));
|
|
66
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { type SidebarBaseProps } from "@xds/core";
|
|
2
|
+
import { type ReactNode } from "react";
|
|
3
|
+
import type { RootProps } from "./root.ts";
|
|
4
|
+
export type { SidebarItem, SidebarSection } from "@xds/core";
|
|
5
|
+
export type SidebarProps<Value extends string = string> = SidebarBaseProps<Value> & RootProps & {
|
|
6
|
+
onChange: (value: Value) => void;
|
|
7
|
+
/** At the top, such as the app's name. It has to fit the rail itself while collapsed. */
|
|
8
|
+
header?: ReactNode;
|
|
9
|
+
/** At the bottom, such as an account row. It has to fit the rail itself while collapsed. */
|
|
10
|
+
footer?: ReactNode;
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* The top-level places of an app used with a pointer: the counterpart of TabBar on touch. Each
|
|
14
|
+
* row is a compact list row; the current one is selected, its title heavier and its icon
|
|
15
|
+
* filled, so the place does not depend on the tint alone.
|
|
16
|
+
*
|
|
17
|
+
* It is navigation named by `label`, and the current row says it is the current page.
|
|
18
|
+
* Collapsed, the rows keep their names, and show them in a Tooltip under a pointer and on
|
|
19
|
+
* keyboard focus.
|
|
20
|
+
*/
|
|
21
|
+
export declare function Sidebar<Value extends string = string>({ sections, value, onChange, label, collapsed, header, footer, className, style, }: SidebarProps<Value>): import("react").JSX.Element;
|
package/dist/Sidebar.js
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { classes, rootPart, SIDEBAR_PARTS, sidebarClass, sidebarCount, sidebarIconClass, sidebarRailButtonClass, sidebarSectionClass, sidebarTitleClass, } from "@xds/core";
|
|
3
|
+
import { useId } from "react";
|
|
4
|
+
import { Icon } from "./Icon.js";
|
|
5
|
+
import { PlaceRow } from "./ListRow.js";
|
|
6
|
+
import { TooltipBeside } from "./Tooltip.js";
|
|
7
|
+
import { useTrigger } from "./trigger.js";
|
|
8
|
+
export function Sidebar({ sections, value, onChange, label, collapsed = false, header, footer, className, style, }) {
|
|
9
|
+
const id = useId();
|
|
10
|
+
return (_jsxs("nav", { "aria-label": label, className: classes(rootPart("Sidebar"), sidebarClass(collapsed), className), style: style, children: [header != null && _jsx("div", { className: SIDEBAR_PARTS.edge, children: header }), _jsx("div", { className: SIDEBAR_PARTS.places, children: sections.map((section, index) => {
|
|
11
|
+
const title = `${id}-${index}`;
|
|
12
|
+
return (_jsxs("div", { className: sidebarSectionClass(index, collapsed), children: [section.title && (_jsx("p", { id: title, className: sidebarTitleClass(collapsed), children: section.title })), collapsed && index > 0 && _jsx("div", { "aria-hidden": "true", className: SIDEBAR_PARTS.rule }), _jsx("ul", { ...(section.title ? { "aria-labelledby": title } : {}), className: SIDEBAR_PARTS.list, children: section.items.map((item) => {
|
|
13
|
+
const selected = item.value === value;
|
|
14
|
+
const count = sidebarCount(item.count);
|
|
15
|
+
return (_jsx("li", { className: SIDEBAR_PARTS.item, children: collapsed ? (_jsx(TooltipBeside, { label: item.label, children: _jsx(RailButton, { label: item.label, icon: item.icon, selected: selected, onPress: () => onChange(item.value) }) })) : (_jsx(PlaceRow, { compact: true, current: "page", selected: selected, onPress: () => onChange(item.value), title: item.label, leading: _jsx(Icon, { name: item.icon, size: "md", filled: selected, className: sidebarIconClass(selected) }), trailing: count !== undefined && (_jsx("span", { className: SIDEBAR_PARTS.count, children: count })) })) }, item.value));
|
|
16
|
+
}) })] }, index));
|
|
17
|
+
}) }), footer != null && _jsx("div", { className: SIDEBAR_PARTS.edge, children: footer })] }));
|
|
18
|
+
}
|
|
19
|
+
function RailButton({ label, icon, selected, onPress, }) {
|
|
20
|
+
const attributes = useTrigger({
|
|
21
|
+
className: sidebarRailButtonClass(selected),
|
|
22
|
+
"aria-label": label,
|
|
23
|
+
"aria-current": selected ? "page" : undefined,
|
|
24
|
+
onClick: onPress,
|
|
25
|
+
});
|
|
26
|
+
return (_jsx("button", { ...attributes, type: "button", children: _jsx(Icon, { name: icon, size: "md", filled: selected }) }));
|
|
27
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { type SkeletonBaseProps } from "@xds/core";
|
|
2
|
+
import type { RootProps } from "./root.ts";
|
|
3
|
+
export type SkeletonProps = SkeletonBaseProps & RootProps;
|
|
4
|
+
/**
|
|
5
|
+
* Holds the place of content that is loading, in the shape the content will have. It pulses,
|
|
6
|
+
* and stands still for people who ask for less motion.
|
|
7
|
+
*
|
|
8
|
+
* It is hidden from assistive technology: the screen that shows skeletons says that it is
|
|
9
|
+
* loading, once, instead of every placeholder saying so.
|
|
10
|
+
*/
|
|
11
|
+
export declare function Skeleton(props: SkeletonProps): import("react").JSX.Element;
|
package/dist/Skeleton.js
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { classes, rootPart, skeletonClass, skeletonSize, } from "@xds/core";
|
|
3
|
+
import { useDefaults } from "./Defaults.js";
|
|
4
|
+
export function Skeleton(props) {
|
|
5
|
+
const defaults = useDefaults("Skeleton");
|
|
6
|
+
const { shape = defaults.shape, width, height, className, style } = props;
|
|
7
|
+
return (_jsx("span", { "aria-hidden": "true", className: classes(rootPart("Skeleton"), skeletonClass(shape), className), style: { ...skeletonSize({ shape, width, height }), ...style } }));
|
|
8
|
+
}
|