@xds/react 0.0.0-stage → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +19 -2
- package/dist/Accordion.d.ts +20 -0
- package/dist/Accordion.js +197 -0
- package/dist/Avatar.d.ts +9 -0
- package/dist/Avatar.js +69 -0
- package/dist/AvatarStack.d.ts +8 -0
- package/dist/AvatarStack.js +105 -0
- package/dist/Badge.d.ts +13 -0
- package/dist/Badge.js +66 -0
- package/dist/Banner.d.ts +23 -0
- package/dist/Banner.js +166 -0
- package/dist/Button.d.ts +14 -0
- package/dist/Button.js +159 -0
- package/dist/Card.d.ts +18 -0
- package/dist/Card.js +173 -0
- package/dist/Checkbox.d.ts +10 -0
- package/dist/Checkbox.js +140 -0
- package/dist/Chip.d.ts +12 -0
- package/dist/Chip.js +74 -0
- package/dist/ChipBar.d.ts +12 -0
- package/dist/ChipBar.js +38 -0
- package/dist/CountBadge.d.ts +12 -0
- package/dist/CountBadge.js +64 -0
- package/dist/DatePicker.d.ts +20 -0
- package/dist/DatePicker.js +429 -0
- package/dist/DateRangePicker.d.ts +24 -0
- package/dist/DateRangePicker.js +370 -0
- package/dist/Defaults.d.ts +17 -0
- package/dist/Defaults.js +48 -0
- package/dist/Dialog.d.ts +20 -0
- package/dist/Dialog.js +137 -0
- package/dist/Divider.d.ts +4 -0
- package/dist/Divider.js +31 -0
- package/dist/EmptyState.d.ts +12 -0
- package/dist/EmptyState.js +86 -0
- package/dist/Icon.d.ts +9 -0
- package/dist/Icon.js +79 -0
- package/dist/IconButton.d.ts +12 -0
- package/dist/IconButton.js +119 -0
- package/dist/ListRow.d.ts +21 -0
- package/dist/ListRow.js +185 -0
- package/dist/MediaCard.d.ts +20 -0
- package/dist/MediaCard.js +279 -0
- package/dist/Menu.d.ts +18 -0
- package/dist/Menu.js +244 -0
- package/dist/ProgressBar.d.ts +8 -0
- package/dist/ProgressBar.js +65 -0
- package/dist/RadioGroup.d.ts +15 -0
- package/dist/RadioGroup.js +176 -0
- package/dist/SearchField.d.ts +15 -0
- package/dist/SearchField.js +152 -0
- package/dist/SectionHeader.d.ts +14 -0
- package/dist/SectionHeader.js +124 -0
- package/dist/SegmentedControl.d.ts +12 -0
- package/dist/SegmentedControl.js +106 -0
- package/dist/Select.d.ts +18 -0
- package/dist/Select.js +318 -0
- package/dist/Sidebar.d.ts +21 -0
- package/dist/Sidebar.js +220 -0
- package/dist/Skeleton.d.ts +11 -0
- package/dist/Skeleton.js +64 -0
- package/dist/Slider.d.ts +13 -0
- package/dist/Slider.js +151 -0
- package/dist/Spinner.d.ts +9 -0
- package/dist/Spinner.js +97 -0
- package/dist/Switch.d.ts +13 -0
- package/dist/Switch.js +116 -0
- package/dist/Tabs.d.ts +14 -0
- package/dist/Tabs.js +137 -0
- package/dist/Text.d.ts +10 -0
- package/dist/Text.js +46 -0
- package/dist/TextField.d.ts +22 -0
- package/dist/TextField.js +213 -0
- package/dist/Thumbnail.d.ts +9 -0
- package/dist/Thumbnail.js +152 -0
- package/dist/Toast.d.ts +14 -0
- package/dist/Toast.js +121 -0
- package/dist/Tooltip.d.ts +26 -0
- package/dist/Tooltip.js +166 -0
- package/dist/base.d.ts +11 -0
- package/dist/base.js +10 -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 +37 -0
- package/dist/picture.d.ts +13 -0
- package/dist/picture.js +76 -0
- package/dist/portal.d.ts +9 -0
- package/dist/portal.js +27 -0
- package/dist/presence.d.ts +6 -0
- package/dist/presence.js +34 -0
- package/dist/preview.d.ts +17 -0
- package/dist/preview.js +126 -0
- package/dist/root.d.ts +12 -0
- package/dist/root.js +1 -0
- package/dist/trigger.d.ts +24 -0
- package/dist/trigger.js +47 -0
- package/eject/files/Accordion.tsx +157 -0
- package/eject/files/Avatar.tsx +41 -0
- package/eject/files/AvatarStack.tsx +47 -0
- package/eject/files/Badge.tsx +33 -0
- package/eject/files/Banner.tsx +70 -0
- package/eject/files/Button.tsx +88 -0
- package/eject/files/Card.tsx +85 -0
- package/eject/files/Checkbox.tsx +59 -0
- package/eject/files/Chip.tsx +43 -0
- package/eject/files/ChipBar.tsx +31 -0
- package/eject/files/CountBadge.tsx +50 -0
- package/eject/files/DatePicker.tsx +192 -0
- package/eject/files/DateRangePicker.tsx +271 -0
- package/eject/files/Dialog.tsx +108 -0
- package/eject/files/Divider.tsx +13 -0
- package/eject/files/EmptyState.tsx +39 -0
- package/eject/files/Icon.tsx +38 -0
- package/eject/files/IconButton.tsx +62 -0
- package/eject/files/ListRow.tsx +86 -0
- package/eject/files/MediaCard.tsx +111 -0
- package/eject/files/Menu.tsx +168 -0
- package/eject/files/ProgressBar.tsx +34 -0
- package/eject/files/RadioGroup.tsx +112 -0
- package/eject/files/SearchField.tsx +88 -0
- package/eject/files/SectionHeader.tsx +56 -0
- package/eject/files/SegmentedControl.tsx +57 -0
- package/eject/files/Select.tsx +228 -0
- package/eject/files/Sidebar.tsx +149 -0
- package/eject/files/Skeleton.tsx +28 -0
- package/eject/files/Slider.tsx +109 -0
- package/eject/files/Spinner.tsx +36 -0
- package/eject/files/Switch.tsx +53 -0
- package/eject/files/Tabs.tsx +71 -0
- package/eject/files/Text.tsx +31 -0
- package/eject/files/TextField.tsx +122 -0
- package/eject/files/Thumbnail.tsx +66 -0
- package/eject/files/Toast.tsx +88 -0
- package/eject/files/Tooltip.tsx +120 -0
- package/eject/files/accordion.css +89 -0
- package/eject/files/accordion.ts +67 -0
- package/eject/files/avatar-stack.ts +57 -0
- package/eject/files/avatar.ts +42 -0
- package/eject/files/badge.ts +30 -0
- package/eject/files/banner.ts +68 -0
- package/eject/files/base.css +38 -0
- package/eject/files/button.css +241 -0
- package/eject/files/button.ts +106 -0
- package/eject/files/card.ts +58 -0
- package/eject/files/checkbox.ts +32 -0
- package/eject/files/chip-bar.ts +16 -0
- package/eject/files/chip.ts +35 -0
- package/eject/files/count-badge.ts +32 -0
- package/eject/files/date-picker.css +352 -0
- package/eject/files/date-picker.ts +250 -0
- package/eject/files/date-range-picker.ts +323 -0
- package/eject/files/dialog.css +139 -0
- package/eject/files/dialog.ts +15 -0
- package/eject/files/divider.ts +5 -0
- package/eject/files/empty-state.ts +22 -0
- package/eject/files/icon.ts +36 -0
- package/eject/files/list-row.ts +66 -0
- package/eject/files/media-card.ts +66 -0
- package/eject/files/menu.css +176 -0
- package/eject/files/menu.ts +84 -0
- package/eject/files/parts.ts +17 -0
- package/eject/files/progress-bar.ts +23 -0
- package/eject/files/radio-group.css +160 -0
- package/eject/files/radio-group.ts +24 -0
- package/eject/files/section-header.ts +32 -0
- package/eject/files/segmented-control.ts +30 -0
- package/eject/files/select.css +285 -0
- package/eject/files/select.ts +36 -0
- package/eject/files/sidebar.ts +75 -0
- package/eject/files/skeleton.ts +51 -0
- package/eject/files/slider.css +136 -0
- package/eject/files/slider.ts +65 -0
- package/eject/files/spinner.ts +22 -0
- package/eject/files/switch.ts +34 -0
- package/eject/files/tabs.css +112 -0
- package/eject/files/tabs.ts +35 -0
- package/eject/files/text-field.css +229 -0
- package/eject/files/text-field.ts +48 -0
- package/eject/files/text.ts +38 -0
- package/eject/files/thumbnail.ts +51 -0
- package/eject/files/toast.ts +31 -0
- package/eject/files/tooltip.css +104 -0
- package/eject/files/tooltip.ts +21 -0
- package/eject/manifest.json +814 -0
- package/package.json +66 -4
- package/page.css +20 -0
- package/styles.css +3252 -0
- package/tailwind.css +2665 -0
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
// Ejected from `@xds/react` 0.2.0 by `xds eject`. This copy is the app's own: change it
|
|
2
|
+
// as you need. `xds eject --list` says which ejected files differ from what was copied.
|
|
3
|
+
|
|
4
|
+
import type { RootProps } from "@xds/react/base";
|
|
5
|
+
import { useRef } from "react";
|
|
6
|
+
import { Icon } from "./Icon.tsx";
|
|
7
|
+
import { classes, rootPart } from "./parts.ts";
|
|
8
|
+
import type { SearchFieldBaseProps } from "./text-field.ts";
|
|
9
|
+
|
|
10
|
+
export type SearchFieldProps = SearchFieldBaseProps &
|
|
11
|
+
RootProps & {
|
|
12
|
+
onChange: (value: string) => void;
|
|
13
|
+
/** Called with the query on Enter, or on the search key of a software keyboard. */
|
|
14
|
+
onSubmit?: (value: string) => void;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* A text field for a query: TextField's box as a pill, with a search icon in front and, while
|
|
19
|
+
* there is a value, a control that clears it. Escape clears too.
|
|
20
|
+
*
|
|
21
|
+
* Use it to filter or search what is on the screen. For a value that is saved with a form,
|
|
22
|
+
* use a TextField, which has a visible label.
|
|
23
|
+
*/
|
|
24
|
+
export function SearchField({
|
|
25
|
+
value,
|
|
26
|
+
onChange,
|
|
27
|
+
onSubmit,
|
|
28
|
+
label,
|
|
29
|
+
placeholder,
|
|
30
|
+
disabled = false,
|
|
31
|
+
clearLabel = "Clear",
|
|
32
|
+
className,
|
|
33
|
+
style,
|
|
34
|
+
}: SearchFieldProps) {
|
|
35
|
+
const input = useRef<HTMLInputElement>(null);
|
|
36
|
+
return (
|
|
37
|
+
// A TextField's root, drawn by its stylesheet, with a root part of its own.
|
|
38
|
+
<div
|
|
39
|
+
className={classes("{{prefix}}-text-field", rootPart("SearchField"), className)}
|
|
40
|
+
style={style}
|
|
41
|
+
>
|
|
42
|
+
<div className="{{prefix}}-text-field__control {{prefix}}-text-field__control--pill {{prefix}}-text-field__group">
|
|
43
|
+
<span className="{{prefix}}-text-field__slot {{prefix}}-text-field__slot--leading">
|
|
44
|
+
<Icon name="search" size="sm" />
|
|
45
|
+
</span>
|
|
46
|
+
<input
|
|
47
|
+
ref={input}
|
|
48
|
+
type="text"
|
|
49
|
+
className="{{prefix}}-text-field__input"
|
|
50
|
+
aria-label={label}
|
|
51
|
+
enterKeyHint="search"
|
|
52
|
+
placeholder={placeholder}
|
|
53
|
+
value={value}
|
|
54
|
+
disabled={disabled}
|
|
55
|
+
// Escape clears only while there is something to clear; an empty field lets Escape
|
|
56
|
+
// through to whatever it sits in, such as a dialog.
|
|
57
|
+
data-uses-escape={value !== "" ? "" : undefined}
|
|
58
|
+
onChange={(event) => onChange(event.currentTarget.value)}
|
|
59
|
+
onKeyDown={(event) => {
|
|
60
|
+
// While a composition is open, Enter and Escape belong to the input method.
|
|
61
|
+
if (event.nativeEvent.isComposing) return;
|
|
62
|
+
if (event.key === "Enter") onSubmit?.(value);
|
|
63
|
+
if (event.key === "Escape" && value !== "") {
|
|
64
|
+
event.stopPropagation();
|
|
65
|
+
onChange("");
|
|
66
|
+
}
|
|
67
|
+
}}
|
|
68
|
+
/>
|
|
69
|
+
{value !== "" && !disabled && (
|
|
70
|
+
<span className="{{prefix}}-text-field__slot {{prefix}}-text-field__slot--trailing">
|
|
71
|
+
<button
|
|
72
|
+
type="button"
|
|
73
|
+
aria-label={clearLabel}
|
|
74
|
+
onClick={() => {
|
|
75
|
+
onChange("");
|
|
76
|
+
// The control is about to disappear, and focus would be lost with it.
|
|
77
|
+
input.current?.focus();
|
|
78
|
+
}}
|
|
79
|
+
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"
|
|
80
|
+
>
|
|
81
|
+
<Icon name="circle-x" size="sm" />
|
|
82
|
+
</button>
|
|
83
|
+
</span>
|
|
84
|
+
)}
|
|
85
|
+
</div>
|
|
86
|
+
</div>
|
|
87
|
+
);
|
|
88
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
// Ejected from `@xds/react` 0.2.0 by `xds eject`. This copy is the app's own: change it
|
|
2
|
+
// as you need. `xds eject --list` says which ejected files differ from what was copied.
|
|
3
|
+
|
|
4
|
+
import type { RootProps } from "@xds/react/base";
|
|
5
|
+
import { Button } from "./Button.tsx";
|
|
6
|
+
import { Icon } from "./Icon.tsx";
|
|
7
|
+
import { classes, rootPart } from "./parts.ts";
|
|
8
|
+
import { SECTION_HEADER_PARTS, type SectionHeaderBaseProps } from "./section-header.ts";
|
|
9
|
+
|
|
10
|
+
export type SectionHeaderProps = SectionHeaderBaseProps &
|
|
11
|
+
RootProps & {
|
|
12
|
+
/** A link-like action at the end, such as "See all". */
|
|
13
|
+
action?: { label: string; onPress: () => void };
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* The title row of a group of content. The title is a heading at `level`; the action is a quiet
|
|
18
|
+
* button with a chevron at its end edge, which points the other way in a right-to-left layout.
|
|
19
|
+
*/
|
|
20
|
+
export function SectionHeader({
|
|
21
|
+
title,
|
|
22
|
+
description,
|
|
23
|
+
icon,
|
|
24
|
+
action,
|
|
25
|
+
level = 2,
|
|
26
|
+
className,
|
|
27
|
+
style,
|
|
28
|
+
}: SectionHeaderProps) {
|
|
29
|
+
const Heading = `h${level}` as const;
|
|
30
|
+
return (
|
|
31
|
+
<div
|
|
32
|
+
className={classes(rootPart("SectionHeader"), SECTION_HEADER_PARTS.root, className)}
|
|
33
|
+
style={style}
|
|
34
|
+
>
|
|
35
|
+
<div className={SECTION_HEADER_PARTS.lead}>
|
|
36
|
+
{icon && (
|
|
37
|
+
<span className={SECTION_HEADER_PARTS.icon}>
|
|
38
|
+
<Icon name={icon} size="md" />
|
|
39
|
+
</span>
|
|
40
|
+
)}
|
|
41
|
+
<div className={SECTION_HEADER_PARTS.text}>
|
|
42
|
+
<Heading className={SECTION_HEADER_PARTS.title}>{title}</Heading>
|
|
43
|
+
{description && <p className={SECTION_HEADER_PARTS.description}>{description}</p>}
|
|
44
|
+
</div>
|
|
45
|
+
</div>
|
|
46
|
+
{action && (
|
|
47
|
+
<span className={SECTION_HEADER_PARTS.action}>
|
|
48
|
+
<Button variant="ghost" size="sm" onPress={action.onPress}>
|
|
49
|
+
{action.label}
|
|
50
|
+
<Icon name="chevron-right" size="sm" className={SECTION_HEADER_PARTS.chevron} />
|
|
51
|
+
</Button>
|
|
52
|
+
</span>
|
|
53
|
+
)}
|
|
54
|
+
</div>
|
|
55
|
+
);
|
|
56
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
// Ejected from `@xds/react` 0.2.0 by `xds eject`. This copy is the app's own: change it
|
|
2
|
+
// as you need. `xds eject --list` says which ejected files differ from what was copied.
|
|
3
|
+
|
|
4
|
+
import type { RootProps } from "@xds/react/base";
|
|
5
|
+
import { useId } from "react";
|
|
6
|
+
import { classes, rootPart } from "./parts.ts";
|
|
7
|
+
import {
|
|
8
|
+
type SegmentedControlBaseProps,
|
|
9
|
+
segmentedControlClass,
|
|
10
|
+
segmentedControlOptionClass,
|
|
11
|
+
segmentedControlSegmentClass,
|
|
12
|
+
} from "./segmented-control.ts";
|
|
13
|
+
|
|
14
|
+
export type SegmentedControlProps<Value extends string> = SegmentedControlBaseProps<Value> &
|
|
15
|
+
RootProps & {
|
|
16
|
+
onChange: (value: Value) => void;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* A choice between a few views or modes, all visible at once. The selected segment is outlined
|
|
21
|
+
* as well as filled, so the choice does not depend on telling two greys apart.
|
|
22
|
+
*
|
|
23
|
+
* It is a group of native radio buttons, so the arrow keys move between segments.
|
|
24
|
+
*/
|
|
25
|
+
export function SegmentedControl<Value extends string>({
|
|
26
|
+
options,
|
|
27
|
+
value,
|
|
28
|
+
onChange,
|
|
29
|
+
fullWidth = false,
|
|
30
|
+
className,
|
|
31
|
+
style,
|
|
32
|
+
...aria
|
|
33
|
+
}: SegmentedControlProps<Value>) {
|
|
34
|
+
const name = useId();
|
|
35
|
+
return (
|
|
36
|
+
<div
|
|
37
|
+
{...aria}
|
|
38
|
+
role="radiogroup"
|
|
39
|
+
className={classes(rootPart("SegmentedControl"), segmentedControlClass(fullWidth), className)}
|
|
40
|
+
style={style}
|
|
41
|
+
>
|
|
42
|
+
{options.map((option) => (
|
|
43
|
+
<label key={option.value} className={segmentedControlOptionClass(fullWidth)}>
|
|
44
|
+
<input
|
|
45
|
+
type="radio"
|
|
46
|
+
name={name}
|
|
47
|
+
value={option.value}
|
|
48
|
+
className="peer sr-only"
|
|
49
|
+
checked={option.value === value}
|
|
50
|
+
onChange={() => onChange(option.value)}
|
|
51
|
+
/>
|
|
52
|
+
<span className={segmentedControlSegmentClass}>{option.label}</span>
|
|
53
|
+
</label>
|
|
54
|
+
))}
|
|
55
|
+
</div>
|
|
56
|
+
);
|
|
57
|
+
}
|
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
// Ejected from `@xds/react` 0.2.0 by `xds eject`. This copy is the app's own: change it
|
|
2
|
+
// as you need. `xds eject --list` says which ejected files differ from what was copied.
|
|
3
|
+
|
|
4
|
+
import {
|
|
5
|
+
keepListKeys,
|
|
6
|
+
Portal,
|
|
7
|
+
type RootProps,
|
|
8
|
+
space,
|
|
9
|
+
useModalPopover,
|
|
10
|
+
usePresence,
|
|
11
|
+
} from "@xds/react/base";
|
|
12
|
+
import { mergeProps, normalizeProps, useMachine } from "@zag-js/react";
|
|
13
|
+
import * as select from "@zag-js/select";
|
|
14
|
+
import { type KeyboardEvent, useId, useMemo, useRef } from "react";
|
|
15
|
+
import { Icon } from "./Icon.tsx";
|
|
16
|
+
import { classes } from "./parts.ts";
|
|
17
|
+
import { type SelectBaseProps, type SelectOption, selectOptionIds } from "./select.ts";
|
|
18
|
+
|
|
19
|
+
export type { SelectOption } from "./select.ts";
|
|
20
|
+
|
|
21
|
+
/** `className` and `style` are for the field, not for the list that opens from it. */
|
|
22
|
+
export type SelectProps<Value extends string = string> = SelectBaseProps<Value> &
|
|
23
|
+
RootProps & {
|
|
24
|
+
onChange: (value: Value) => void;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
type KeyHandler = (event: KeyboardEvent) => void;
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* A field for choosing one option from a list too long to show at once. Closed, it looks like a
|
|
31
|
+
* TextField; pressed, it opens the list under itself with a Menu's surface, as wide as the
|
|
32
|
+
* field. Choosing an option calls `onChange` and closes the list; a press outside or Escape
|
|
33
|
+
* closes it too.
|
|
34
|
+
*
|
|
35
|
+
* The field is a button that says it opens a list box and whether the list is open. In the list
|
|
36
|
+
* the arrow keys move, typing jumps to an option, and Enter chooses. The chosen option is
|
|
37
|
+
* selected for assistive technology and marked with a check.
|
|
38
|
+
*/
|
|
39
|
+
export function Select<Value extends string = string>({
|
|
40
|
+
label,
|
|
41
|
+
options,
|
|
42
|
+
value,
|
|
43
|
+
onChange,
|
|
44
|
+
placeholder,
|
|
45
|
+
description,
|
|
46
|
+
error,
|
|
47
|
+
name,
|
|
48
|
+
disabled = false,
|
|
49
|
+
className,
|
|
50
|
+
style,
|
|
51
|
+
}: SelectProps<Value>) {
|
|
52
|
+
const id = useId();
|
|
53
|
+
const valueId = `${id}-value`;
|
|
54
|
+
const descriptionId = `${id}-description`;
|
|
55
|
+
const errorId = `${id}-error`;
|
|
56
|
+
const invalid = error !== undefined;
|
|
57
|
+
const collection = useMemo(
|
|
58
|
+
() =>
|
|
59
|
+
select.collection<SelectOption<Value>>({
|
|
60
|
+
items: [...options],
|
|
61
|
+
itemToValue: (option) => option.value,
|
|
62
|
+
itemToString: (option) => option.label,
|
|
63
|
+
}),
|
|
64
|
+
[options],
|
|
65
|
+
);
|
|
66
|
+
const service = useMachine(select.machine, {
|
|
67
|
+
id,
|
|
68
|
+
collection,
|
|
69
|
+
value: value === undefined ? [] : [value],
|
|
70
|
+
onValueChange: (details) => {
|
|
71
|
+
const next = details.value[0];
|
|
72
|
+
if (next !== undefined) onChange(next as Value);
|
|
73
|
+
},
|
|
74
|
+
disabled,
|
|
75
|
+
invalid,
|
|
76
|
+
name,
|
|
77
|
+
positioning: {
|
|
78
|
+
placement: "bottom-start",
|
|
79
|
+
gutter: space[1],
|
|
80
|
+
sameWidth: true,
|
|
81
|
+
// The list keeps this far from the window's edges.
|
|
82
|
+
overflowPadding: space[3],
|
|
83
|
+
},
|
|
84
|
+
});
|
|
85
|
+
const api = select.connect(service, normalizeProps);
|
|
86
|
+
// Zag's key handlers read whether a search by typing is under way when the field renders,
|
|
87
|
+
// and a search ends on a timer, which renders nothing: long after a search, Space would
|
|
88
|
+
// still search for a space instead of opening the list or choosing. A handler taken from
|
|
89
|
+
// the machine when the key comes reads it then.
|
|
90
|
+
const current = () => select.connect(service, normalizeProps);
|
|
91
|
+
// A span: the field is a button, which a <label> cannot point at. A press on it still
|
|
92
|
+
// focuses the field.
|
|
93
|
+
const { htmlFor: _for, ...labelProps } = api.getLabelProps();
|
|
94
|
+
// A button that opens a list box, rather than Zag's combobox: named by the chosen option and
|
|
95
|
+
// then the label, and described by the help or the error. The error is said there, so the
|
|
96
|
+
// button itself does not claim to be invalid or required.
|
|
97
|
+
const {
|
|
98
|
+
role: _role,
|
|
99
|
+
"aria-invalid": _invalid,
|
|
100
|
+
"aria-required": _required,
|
|
101
|
+
onKeyDown: _onTriggerKeyDown,
|
|
102
|
+
...triggerProps
|
|
103
|
+
} = api.getTriggerProps();
|
|
104
|
+
const positioner = useRef<HTMLDivElement>(null);
|
|
105
|
+
const surface = useRef<HTMLDivElement>(null);
|
|
106
|
+
const { onKeyDown: _onContentKeyDown, ...contentProps } = api.getContentProps();
|
|
107
|
+
const content = {
|
|
108
|
+
...contentProps,
|
|
109
|
+
onKeyDown: (event: KeyboardEvent) => {
|
|
110
|
+
// Ahead of Zag's handler, which skips a key that was already handled.
|
|
111
|
+
keepListKeys(event, surface.current, ".{{prefix}}-select__item:not([data-disabled])", (row) =>
|
|
112
|
+
api.setHighlightedValue(row),
|
|
113
|
+
);
|
|
114
|
+
(current().getContentProps().onKeyDown as KeyHandler | undefined)?.(event);
|
|
115
|
+
},
|
|
116
|
+
};
|
|
117
|
+
useModalPopover(api.open, () => positioner.current);
|
|
118
|
+
const present = usePresence(api.open, () => [surface.current]);
|
|
119
|
+
return (
|
|
120
|
+
<div
|
|
121
|
+
{...mergeProps(api.getRootProps(), {
|
|
122
|
+
className: classes("{{prefix}}-select", className),
|
|
123
|
+
style,
|
|
124
|
+
})}
|
|
125
|
+
>
|
|
126
|
+
<span {...labelProps} className="{{prefix}}-select__label">
|
|
127
|
+
{label}
|
|
128
|
+
</span>
|
|
129
|
+
<button
|
|
130
|
+
{...triggerProps}
|
|
131
|
+
aria-labelledby={`${valueId} ${labelProps.id}`}
|
|
132
|
+
aria-describedby={invalid ? errorId : description ? descriptionId : undefined}
|
|
133
|
+
onKeyDown={(event) => {
|
|
134
|
+
const now = current();
|
|
135
|
+
// Home and End leave a closed field to the page; Zag would choose the first or the
|
|
136
|
+
// last option.
|
|
137
|
+
if (!now.open && (event.key === "Home" || event.key === "End")) return;
|
|
138
|
+
(now.getTriggerProps().onKeyDown as KeyHandler | undefined)?.(event);
|
|
139
|
+
}}
|
|
140
|
+
type="button"
|
|
141
|
+
className="{{prefix}}-select__trigger"
|
|
142
|
+
>
|
|
143
|
+
{/* The chosen option's label alone: the list's rows also hold a description and a
|
|
144
|
+
check, which do not belong in the field. */}
|
|
145
|
+
<span {...api.getValueTextProps()} id={valueId} className="{{prefix}}-select__value">
|
|
146
|
+
{api.valueAsString || placeholder}
|
|
147
|
+
</span>
|
|
148
|
+
<Icon name="chevrons-up-down" size="sm" className="text-xds-field-placeholder" />
|
|
149
|
+
</button>
|
|
150
|
+
{/* One line under the box: the help, or the error in its place. */}
|
|
151
|
+
{(invalid || description) && (
|
|
152
|
+
<div className="{{prefix}}-select__footer">
|
|
153
|
+
{invalid ? (
|
|
154
|
+
<span id={errorId} className="{{prefix}}-select__error">
|
|
155
|
+
{error}
|
|
156
|
+
</span>
|
|
157
|
+
) : (
|
|
158
|
+
<span id={descriptionId} className="{{prefix}}-select__description">
|
|
159
|
+
{description}
|
|
160
|
+
</span>
|
|
161
|
+
)}
|
|
162
|
+
</div>
|
|
163
|
+
)}
|
|
164
|
+
{/* What a form submits; the first option stands for no choice. */}
|
|
165
|
+
<select {...api.getHiddenSelectProps()}>
|
|
166
|
+
{/* oxlint-disable-next-line jsx-a11y/control-has-associated-label -- Zag's props hide the select from assistive technology, which uses the trigger */}
|
|
167
|
+
<option value="" />
|
|
168
|
+
{options.map((option) => (
|
|
169
|
+
<option key={option.value} value={option.value}>
|
|
170
|
+
{option.label}
|
|
171
|
+
</option>
|
|
172
|
+
))}
|
|
173
|
+
</select>
|
|
174
|
+
<Portal>
|
|
175
|
+
{api.open && (
|
|
176
|
+
// Takes a press outside, which then only closes the list. The focus stays in the
|
|
177
|
+
// list until the list hands it back to the field.
|
|
178
|
+
// oxlint-disable-next-line jsx-a11y/no-static-element-interactions -- not a control: the handler only keeps the focus where it is
|
|
179
|
+
<div
|
|
180
|
+
className="{{prefix}}-select__underlay"
|
|
181
|
+
onMouseDown={(event) => event.preventDefault()}
|
|
182
|
+
/>
|
|
183
|
+
)}
|
|
184
|
+
<div
|
|
185
|
+
{...api.getPositionerProps()}
|
|
186
|
+
ref={positioner}
|
|
187
|
+
className="{{prefix}}-select__positioner"
|
|
188
|
+
>
|
|
189
|
+
{/* Shown until its exit animation ends; Zag would hide it as it closes. */}
|
|
190
|
+
<div {...content} ref={surface} hidden={!present} className="{{prefix}}-select__content">
|
|
191
|
+
<div {...api.getListProps()} className="{{prefix}}-select__list">
|
|
192
|
+
{collection.items.map((option, index) => {
|
|
193
|
+
const ids = selectOptionIds(id, index);
|
|
194
|
+
return (
|
|
195
|
+
// Named by its label alone, as the field shows it; the help line describes it.
|
|
196
|
+
<div
|
|
197
|
+
key={option.value}
|
|
198
|
+
{...api.getItemProps({ item: option })}
|
|
199
|
+
aria-labelledby={ids.label}
|
|
200
|
+
aria-describedby={option.description ? ids.description : undefined}
|
|
201
|
+
className="{{prefix}}-select__item"
|
|
202
|
+
>
|
|
203
|
+
<span className="{{prefix}}-select__item-words">
|
|
204
|
+
<span
|
|
205
|
+
{...api.getItemTextProps({ item: option })}
|
|
206
|
+
id={ids.label}
|
|
207
|
+
className="{{prefix}}-select__item-label"
|
|
208
|
+
>
|
|
209
|
+
{option.label}
|
|
210
|
+
</span>
|
|
211
|
+
{option.description && (
|
|
212
|
+
<span id={ids.description} className="{{prefix}}-select__item-description">
|
|
213
|
+
{option.description}
|
|
214
|
+
</span>
|
|
215
|
+
)}
|
|
216
|
+
</span>
|
|
217
|
+
{/* Unnamed, unlike a Menu's: the option itself reports that it is selected. */}
|
|
218
|
+
{api.getItemState({ item: option }).selected && <Icon name="check" size="sm" />}
|
|
219
|
+
</div>
|
|
220
|
+
);
|
|
221
|
+
})}
|
|
222
|
+
</div>
|
|
223
|
+
</div>
|
|
224
|
+
</div>
|
|
225
|
+
</Portal>
|
|
226
|
+
</div>
|
|
227
|
+
);
|
|
228
|
+
}
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
// Ejected from `@xds/react` 0.2.0 by `xds eject`. This copy is the app's own: change it
|
|
2
|
+
// as you need. `xds eject --list` says which ejected files differ from what was copied.
|
|
3
|
+
|
|
4
|
+
import { type IconName, type RootProps, useTrigger } from "@xds/react/base";
|
|
5
|
+
import { type ReactNode, useId } from "react";
|
|
6
|
+
import { Icon } from "./Icon.tsx";
|
|
7
|
+
import { PlaceRow } from "./ListRow.tsx";
|
|
8
|
+
import { classes, rootPart } from "./parts.ts";
|
|
9
|
+
import {
|
|
10
|
+
SIDEBAR_PARTS,
|
|
11
|
+
type SidebarBaseProps,
|
|
12
|
+
sidebarClass,
|
|
13
|
+
sidebarCount,
|
|
14
|
+
sidebarIconClass,
|
|
15
|
+
sidebarRailButtonClass,
|
|
16
|
+
sidebarSectionClass,
|
|
17
|
+
sidebarTitleClass,
|
|
18
|
+
} from "./sidebar.ts";
|
|
19
|
+
import { TooltipBeside } from "./Tooltip.tsx";
|
|
20
|
+
|
|
21
|
+
export type { SidebarItem, SidebarSection } from "./sidebar.ts";
|
|
22
|
+
|
|
23
|
+
export type SidebarProps<Value extends string = string> = SidebarBaseProps<Value> &
|
|
24
|
+
RootProps & {
|
|
25
|
+
onChange: (value: Value) => void;
|
|
26
|
+
/** At the top, such as the app's name. It has to fit the rail itself while collapsed. */
|
|
27
|
+
header?: ReactNode;
|
|
28
|
+
/** At the bottom, such as an account row. It has to fit the rail itself while collapsed. */
|
|
29
|
+
footer?: ReactNode;
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* The top-level places of an app used with a pointer: the counterpart of TabBar on touch. Each
|
|
34
|
+
* row is a compact list row; the current one is selected, its title heavier and its icon
|
|
35
|
+
* filled, so the place does not depend on the tint alone.
|
|
36
|
+
*
|
|
37
|
+
* It is navigation named by `label`, and the current row says it is the current page.
|
|
38
|
+
* Collapsed, the rows keep their names, and show them in a Tooltip under a pointer and on
|
|
39
|
+
* keyboard focus.
|
|
40
|
+
*/
|
|
41
|
+
export function Sidebar<Value extends string = string>({
|
|
42
|
+
sections,
|
|
43
|
+
value,
|
|
44
|
+
onChange,
|
|
45
|
+
label,
|
|
46
|
+
collapsed = false,
|
|
47
|
+
header,
|
|
48
|
+
footer,
|
|
49
|
+
className,
|
|
50
|
+
style,
|
|
51
|
+
}: SidebarProps<Value>) {
|
|
52
|
+
const id = useId();
|
|
53
|
+
return (
|
|
54
|
+
<nav
|
|
55
|
+
aria-label={label}
|
|
56
|
+
className={classes(rootPart("Sidebar"), sidebarClass(collapsed), className)}
|
|
57
|
+
style={style}
|
|
58
|
+
>
|
|
59
|
+
{header != null && <div className={SIDEBAR_PARTS.edge}>{header}</div>}
|
|
60
|
+
{/* The places scroll when there are more than fit; the header and footer stay. */}
|
|
61
|
+
<div className={SIDEBAR_PARTS.places}>
|
|
62
|
+
{sections.map((section, index) => {
|
|
63
|
+
const title = `${id}-${index}`;
|
|
64
|
+
return (
|
|
65
|
+
// A section has nothing but its position to tell it apart: titles are optional.
|
|
66
|
+
<div key={index} className={sidebarSectionClass(index, collapsed)}>
|
|
67
|
+
{section.title && (
|
|
68
|
+
<p id={title} className={sidebarTitleClass(collapsed)}>
|
|
69
|
+
{section.title}
|
|
70
|
+
</p>
|
|
71
|
+
)}
|
|
72
|
+
{collapsed && index > 0 && <div aria-hidden="true" className={SIDEBAR_PARTS.rule} />}
|
|
73
|
+
<ul
|
|
74
|
+
{...(section.title ? { "aria-labelledby": title } : {})}
|
|
75
|
+
className={SIDEBAR_PARTS.list}
|
|
76
|
+
>
|
|
77
|
+
{section.items.map((item) => {
|
|
78
|
+
const selected = item.value === value;
|
|
79
|
+
const count = sidebarCount(item.count);
|
|
80
|
+
return (
|
|
81
|
+
<li key={item.value} className={SIDEBAR_PARTS.item}>
|
|
82
|
+
{collapsed ? (
|
|
83
|
+
<TooltipBeside label={item.label}>
|
|
84
|
+
<RailButton
|
|
85
|
+
label={item.label}
|
|
86
|
+
icon={item.icon}
|
|
87
|
+
selected={selected}
|
|
88
|
+
onPress={() => onChange(item.value)}
|
|
89
|
+
/>
|
|
90
|
+
</TooltipBeside>
|
|
91
|
+
) : (
|
|
92
|
+
<PlaceRow
|
|
93
|
+
compact
|
|
94
|
+
current="page"
|
|
95
|
+
selected={selected}
|
|
96
|
+
onPress={() => onChange(item.value)}
|
|
97
|
+
title={item.label}
|
|
98
|
+
leading={
|
|
99
|
+
<Icon
|
|
100
|
+
name={item.icon}
|
|
101
|
+
size="md"
|
|
102
|
+
filled={selected}
|
|
103
|
+
className={sidebarIconClass(selected)}
|
|
104
|
+
/>
|
|
105
|
+
}
|
|
106
|
+
trailing={
|
|
107
|
+
count !== undefined && (
|
|
108
|
+
<span className={SIDEBAR_PARTS.count}>{count}</span>
|
|
109
|
+
)
|
|
110
|
+
}
|
|
111
|
+
/>
|
|
112
|
+
)}
|
|
113
|
+
</li>
|
|
114
|
+
);
|
|
115
|
+
})}
|
|
116
|
+
</ul>
|
|
117
|
+
</div>
|
|
118
|
+
);
|
|
119
|
+
})}
|
|
120
|
+
</div>
|
|
121
|
+
{footer != null && <div className={SIDEBAR_PARTS.edge}>{footer}</div>}
|
|
122
|
+
</nav>
|
|
123
|
+
);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/** A row of the collapsed rail. It is the trigger of the Tooltip that names it. */
|
|
127
|
+
function RailButton({
|
|
128
|
+
label,
|
|
129
|
+
icon,
|
|
130
|
+
selected,
|
|
131
|
+
onPress,
|
|
132
|
+
}: {
|
|
133
|
+
label: string;
|
|
134
|
+
icon: IconName;
|
|
135
|
+
selected: boolean;
|
|
136
|
+
onPress: () => void;
|
|
137
|
+
}) {
|
|
138
|
+
const attributes = useTrigger({
|
|
139
|
+
className: sidebarRailButtonClass(selected),
|
|
140
|
+
"aria-label": label,
|
|
141
|
+
"aria-current": selected ? ("page" as const) : undefined,
|
|
142
|
+
onClick: onPress,
|
|
143
|
+
});
|
|
144
|
+
return (
|
|
145
|
+
<button {...attributes} type="button">
|
|
146
|
+
<Icon name={icon} size="md" filled={selected} />
|
|
147
|
+
</button>
|
|
148
|
+
);
|
|
149
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
// Ejected from `@xds/react` 0.2.0 by `xds eject`. This copy is the app's own: change it
|
|
2
|
+
// as you need. `xds eject --list` says which ejected files differ from what was copied.
|
|
3
|
+
|
|
4
|
+
import { type RootProps, useDefaults } from "@xds/react/base";
|
|
5
|
+
import { classes, rootPart } from "./parts.ts";
|
|
6
|
+
import { type SkeletonBaseProps, skeletonClass, skeletonSize } from "./skeleton.ts";
|
|
7
|
+
|
|
8
|
+
export type SkeletonProps = SkeletonBaseProps & RootProps;
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Holds the place of content that is loading, in the shape the content will have. It pulses,
|
|
12
|
+
* and stands still for people who ask for less motion.
|
|
13
|
+
*
|
|
14
|
+
* It is hidden from assistive technology: the screen that shows skeletons says that it is
|
|
15
|
+
* loading, once, instead of every placeholder saying so.
|
|
16
|
+
*/
|
|
17
|
+
export function Skeleton(props: SkeletonProps) {
|
|
18
|
+
const defaults = useDefaults("Skeleton");
|
|
19
|
+
const { width, height, className, style } = props;
|
|
20
|
+
const shape = props.shape ?? defaults.shape;
|
|
21
|
+
return (
|
|
22
|
+
<span
|
|
23
|
+
aria-hidden="true"
|
|
24
|
+
className={classes(rootPart("Skeleton"), skeletonClass(shape), className)}
|
|
25
|
+
style={{ ...skeletonSize({ shape, width, height }), ...style }}
|
|
26
|
+
/>
|
|
27
|
+
);
|
|
28
|
+
}
|