@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,157 @@
|
|
|
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 * as accordion from "@zag-js/accordion";
|
|
6
|
+
import { mergeProps, normalizeProps, useMachine } from "@zag-js/react";
|
|
7
|
+
import {
|
|
8
|
+
type HTMLAttributes,
|
|
9
|
+
type ReactNode,
|
|
10
|
+
useId,
|
|
11
|
+
useLayoutEffect,
|
|
12
|
+
useRef,
|
|
13
|
+
useState,
|
|
14
|
+
} from "react";
|
|
15
|
+
import {
|
|
16
|
+
ACCORDION_PARTS,
|
|
17
|
+
type AccordionBaseProps,
|
|
18
|
+
type AccordionItemBase,
|
|
19
|
+
focusTitleOnClick,
|
|
20
|
+
setPanelOpen,
|
|
21
|
+
} from "./accordion.ts";
|
|
22
|
+
import { Icon } from "./Icon.tsx";
|
|
23
|
+
import { classes } from "./parts.ts";
|
|
24
|
+
|
|
25
|
+
export type AccordionItem<Value extends string = string> = AccordionItemBase<Value> & {
|
|
26
|
+
/** The body, shown under the title while the item is open. */
|
|
27
|
+
content: ReactNode;
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
export type AccordionProps<Value extends string = string> = AccordionBaseProps<Value> &
|
|
31
|
+
RootProps & {
|
|
32
|
+
items: readonly AccordionItem<Value>[];
|
|
33
|
+
onChange: (expanded: Value[]) => void;
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Items whose bodies open and close under their titles, separated by hairlines. The chevron
|
|
38
|
+
* turns over when an item is open, so the state does not depend on color. Opening and closing
|
|
39
|
+
* animate the height, and do not for people who ask for less motion.
|
|
40
|
+
*
|
|
41
|
+
* Each title is a heading holding a button that says whether its body is expanded and which
|
|
42
|
+
* body it controls. A closed body is hidden, but the browser's find in page still opens it.
|
|
43
|
+
*/
|
|
44
|
+
export function Accordion<Value extends string = string>({
|
|
45
|
+
items,
|
|
46
|
+
expanded,
|
|
47
|
+
onChange,
|
|
48
|
+
multiple = false,
|
|
49
|
+
className,
|
|
50
|
+
style,
|
|
51
|
+
}: AccordionProps<Value>) {
|
|
52
|
+
const service = useMachine(accordion.machine, {
|
|
53
|
+
id: useId(),
|
|
54
|
+
value: [...expanded],
|
|
55
|
+
onValueChange: (details) => onChange(details.value as Value[]),
|
|
56
|
+
multiple,
|
|
57
|
+
collapsible: true,
|
|
58
|
+
hiddenUntilFound: true,
|
|
59
|
+
});
|
|
60
|
+
const api = accordion.connect(service, normalizeProps);
|
|
61
|
+
return (
|
|
62
|
+
<div
|
|
63
|
+
{...mergeProps(api.getRootProps(), {
|
|
64
|
+
className: classes("{{prefix}}-accordion", className),
|
|
65
|
+
style,
|
|
66
|
+
})}
|
|
67
|
+
>
|
|
68
|
+
{items.map((item) => {
|
|
69
|
+
// The panel hides itself once it has finished closing; see Panel.
|
|
70
|
+
const { hidden: _hidden, ...body } = api.getItemContentProps({ value: item.value });
|
|
71
|
+
return (
|
|
72
|
+
<div
|
|
73
|
+
key={item.value}
|
|
74
|
+
{...api.getItemProps({ value: item.value })}
|
|
75
|
+
className="{{prefix}}-accordion__item"
|
|
76
|
+
>
|
|
77
|
+
<h3
|
|
78
|
+
{...api.getItemHeaderProps({ value: item.value })}
|
|
79
|
+
className="{{prefix}}-accordion__heading"
|
|
80
|
+
>
|
|
81
|
+
<button
|
|
82
|
+
{...mergeProps(api.getItemTriggerProps({ value: item.value }), {
|
|
83
|
+
// Runs before Zag's handler.
|
|
84
|
+
onClick: focusTitleOnClick,
|
|
85
|
+
})}
|
|
86
|
+
type="button"
|
|
87
|
+
className="{{prefix}}-accordion__trigger group"
|
|
88
|
+
>
|
|
89
|
+
<span className={ACCORDION_PARTS.text}>
|
|
90
|
+
<span className={ACCORDION_PARTS.title}>{item.title}</span>
|
|
91
|
+
{item.description && (
|
|
92
|
+
<span className={ACCORDION_PARTS.description}>{item.description}</span>
|
|
93
|
+
)}
|
|
94
|
+
</span>
|
|
95
|
+
<Icon name="chevron-down" size="sm" className={ACCORDION_PARTS.chevron} />
|
|
96
|
+
</button>
|
|
97
|
+
</h3>
|
|
98
|
+
<Panel open={api.value.includes(item.value)} attributes={body}>
|
|
99
|
+
{item.content}
|
|
100
|
+
</Panel>
|
|
101
|
+
</div>
|
|
102
|
+
);
|
|
103
|
+
})}
|
|
104
|
+
</div>
|
|
105
|
+
);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* An item's body. Its height moves between zero and the height of what it holds, and it is
|
|
110
|
+
* hidden only once it has finished closing.
|
|
111
|
+
*/
|
|
112
|
+
function Panel({
|
|
113
|
+
open,
|
|
114
|
+
attributes,
|
|
115
|
+
children,
|
|
116
|
+
}: {
|
|
117
|
+
open: boolean;
|
|
118
|
+
attributes: HTMLAttributes<HTMLDivElement>;
|
|
119
|
+
children: ReactNode;
|
|
120
|
+
}) {
|
|
121
|
+
const panel = useRef<HTMLDivElement>(null);
|
|
122
|
+
// What the panel was last set to. A change animates; the first setting, and the same one
|
|
123
|
+
// again when StrictMode runs the effect twice, do not.
|
|
124
|
+
const shown = useRef<boolean>(undefined);
|
|
125
|
+
// A page rendered on the server shows the panel before the effect below can run, so a
|
|
126
|
+
// closed one starts hidden. The value never changes, so React leaves the attribute to the
|
|
127
|
+
// effect from then on.
|
|
128
|
+
const [closedAtFirst] = useState(!open);
|
|
129
|
+
// Before the browser paints, so a closed panel never shows for a frame.
|
|
130
|
+
useLayoutEffect(() => {
|
|
131
|
+
if (!panel.current) return;
|
|
132
|
+
const stop = setPanelOpen(
|
|
133
|
+
panel.current,
|
|
134
|
+
open,
|
|
135
|
+
shown.current !== undefined && shown.current !== open,
|
|
136
|
+
);
|
|
137
|
+
shown.current = open;
|
|
138
|
+
// The next toggle takes over from this one.
|
|
139
|
+
return stop;
|
|
140
|
+
}, [open]);
|
|
141
|
+
// A group: a region is a landmark, and a page of accordions would fill the list of
|
|
142
|
+
// landmarks. A closed one is left out of the accessibility tree as soon as it starts closing;
|
|
143
|
+
// `hidden="until-found"` alone leaves the empty group in it.
|
|
144
|
+
return (
|
|
145
|
+
// A group, not a fieldset: it is the body of a disclosure, not a set of form fields.
|
|
146
|
+
<div
|
|
147
|
+
{...attributes}
|
|
148
|
+
ref={panel}
|
|
149
|
+
hidden={closedAtFirst || undefined}
|
|
150
|
+
role="group"
|
|
151
|
+
aria-hidden={open ? undefined : true}
|
|
152
|
+
className="{{prefix}}-accordion__panel"
|
|
153
|
+
>
|
|
154
|
+
<div className="{{prefix}}-accordion__body">{children}</div>
|
|
155
|
+
</div>
|
|
156
|
+
);
|
|
157
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
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, usePicture } from "@xds/react/base";
|
|
5
|
+
import { type AvatarBaseProps, avatarClass, avatarInitials, pictureClass } from "./avatar.ts";
|
|
6
|
+
import { classes, rootPart } from "./parts.ts";
|
|
7
|
+
|
|
8
|
+
export type { AvatarSize } from "./avatar.ts";
|
|
9
|
+
|
|
10
|
+
export type AvatarProps = AvatarBaseProps & RootProps;
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Stands for a person or a team by a picture, or by their initials when there is none.
|
|
14
|
+
* Assistive technology gets the full name either way. The small size has room for one letter.
|
|
15
|
+
*/
|
|
16
|
+
export function Avatar(props: AvatarProps) {
|
|
17
|
+
const defaults = useDefaults("Avatar");
|
|
18
|
+
const { name, src, className, style } = props;
|
|
19
|
+
const size = props.size ?? defaults.size;
|
|
20
|
+
const picture = usePicture(src);
|
|
21
|
+
return (
|
|
22
|
+
<span
|
|
23
|
+
role="img"
|
|
24
|
+
aria-label={name}
|
|
25
|
+
className={classes(rootPart("Avatar"), avatarClass(size), className)}
|
|
26
|
+
style={style}
|
|
27
|
+
>
|
|
28
|
+
{avatarInitials(name, size)}
|
|
29
|
+
{src && picture.loaded !== false && (
|
|
30
|
+
<img
|
|
31
|
+
src={src}
|
|
32
|
+
// The name is on the avatar itself; a second one on the picture would be read twice.
|
|
33
|
+
alt=""
|
|
34
|
+
aria-hidden="true"
|
|
35
|
+
className={pictureClass(picture.loaded === true)}
|
|
36
|
+
{...picture.image}
|
|
37
|
+
/>
|
|
38
|
+
)}
|
|
39
|
+
</span>
|
|
40
|
+
);
|
|
41
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
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 {
|
|
6
|
+
type AvatarStackBaseProps,
|
|
7
|
+
avatarStack,
|
|
8
|
+
avatarStackClass,
|
|
9
|
+
avatarStackItemClass,
|
|
10
|
+
avatarStackRestClass,
|
|
11
|
+
} from "./avatar-stack.ts";
|
|
12
|
+
import { Avatar } from "./Avatar.tsx";
|
|
13
|
+
import { classes, rootPart } from "./parts.ts";
|
|
14
|
+
|
|
15
|
+
export type AvatarStackProps = AvatarStackBaseProps & RootProps;
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Several people in the room of one. Assistive technology gets one image named after
|
|
19
|
+
* everyone in it, including those who did not fit.
|
|
20
|
+
*/
|
|
21
|
+
export function AvatarStack(props: AvatarStackProps) {
|
|
22
|
+
const defaults = useDefaults("AvatarStack");
|
|
23
|
+
const { people, max, label, className, style } = props;
|
|
24
|
+
// Settled here, so that the avatars take the stack's size and not an Avatar default.
|
|
25
|
+
const size = props.size ?? defaults.size ?? "md";
|
|
26
|
+
const stack = avatarStack(people, max, label);
|
|
27
|
+
return (
|
|
28
|
+
<span
|
|
29
|
+
role="img"
|
|
30
|
+
aria-label={stack.name}
|
|
31
|
+
className={classes(rootPart("AvatarStack"), avatarStackClass, className)}
|
|
32
|
+
style={style}
|
|
33
|
+
>
|
|
34
|
+
{stack.shown.map((person, index) => (
|
|
35
|
+
// By position, not by name: two people can share a name.
|
|
36
|
+
<span key={index} aria-hidden="true" className={avatarStackItemClass(size)}>
|
|
37
|
+
<Avatar name={person.name} src={person.src} size={size} />
|
|
38
|
+
</span>
|
|
39
|
+
))}
|
|
40
|
+
{stack.rest > 0 && (
|
|
41
|
+
<span aria-hidden="true" className={avatarStackRestClass(size)}>
|
|
42
|
+
+{stack.rest}
|
|
43
|
+
</span>
|
|
44
|
+
)}
|
|
45
|
+
</span>
|
|
46
|
+
);
|
|
47
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
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 type { ReactNode } from "react";
|
|
6
|
+
import { type BadgeBaseProps, badgeClass, badgeDotClass } from "./badge.ts";
|
|
7
|
+
import { Icon } from "./Icon.tsx";
|
|
8
|
+
import { classes, rootPart } from "./parts.ts";
|
|
9
|
+
|
|
10
|
+
export type { BadgeTone } from "./badge.ts";
|
|
11
|
+
|
|
12
|
+
export type BadgeProps = BadgeBaseProps &
|
|
13
|
+
RootProps & {
|
|
14
|
+
children: ReactNode;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* A short status or category. The words carry the meaning; the color only reinforces it, so a
|
|
19
|
+
* badge still reads for someone who cannot tell the tones apart. `dot` adds a small mark for
|
|
20
|
+
* live states such as "connected", and `icon` a drawing in front of the words.
|
|
21
|
+
*/
|
|
22
|
+
export function Badge(props: BadgeProps) {
|
|
23
|
+
const defaults = useDefaults("Badge");
|
|
24
|
+
const { dot = false, icon, className, style, children } = props;
|
|
25
|
+
const tone = props.tone ?? defaults.tone;
|
|
26
|
+
return (
|
|
27
|
+
<span className={classes(rootPart("Badge"), badgeClass(tone), className)} style={style}>
|
|
28
|
+
{dot && <span aria-hidden className={badgeDotClass} />}
|
|
29
|
+
{icon && <Icon name={icon} size="xs" />}
|
|
30
|
+
{children}
|
|
31
|
+
</span>
|
|
32
|
+
);
|
|
33
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
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 type { ReactNode } from "react";
|
|
6
|
+
import {
|
|
7
|
+
BANNER_PARTS,
|
|
8
|
+
type BannerBaseProps,
|
|
9
|
+
bannerClass,
|
|
10
|
+
bannerIconClass,
|
|
11
|
+
bannerIconPath,
|
|
12
|
+
bannerRole,
|
|
13
|
+
} from "./banner.ts";
|
|
14
|
+
import { Button } from "./Button.tsx";
|
|
15
|
+
import { IconButton } from "./IconButton.tsx";
|
|
16
|
+
import { classes, rootPart } from "./parts.ts";
|
|
17
|
+
|
|
18
|
+
export type { BannerTone } from "./banner.ts";
|
|
19
|
+
|
|
20
|
+
export type BannerProps = BannerBaseProps &
|
|
21
|
+
RootProps & {
|
|
22
|
+
/** What the person can do about the message. Drawn under it as a small secondary button. */
|
|
23
|
+
action?: { label: string; onPress: () => void };
|
|
24
|
+
/**
|
|
25
|
+
* Shows a close control. The banner does not hide itself: the handler decides what happens
|
|
26
|
+
* to it.
|
|
27
|
+
*/
|
|
28
|
+
onDismiss?: () => void;
|
|
29
|
+
children: ReactNode;
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* A message about the whole view or a section of it. Each tone has its own icon shape, so the
|
|
34
|
+
* tone does not depend on color. Problems (`warning`, `danger`) interrupt a screen reader;
|
|
35
|
+
* `info` and `success` wait their turn.
|
|
36
|
+
*/
|
|
37
|
+
export function Banner(props: BannerProps) {
|
|
38
|
+
const defaults = useDefaults("Banner");
|
|
39
|
+
const { title, action, onDismiss, dismissLabel = "Dismiss", className, style, children } = props;
|
|
40
|
+
const tone = props.tone ?? defaults.tone;
|
|
41
|
+
return (
|
|
42
|
+
<div
|
|
43
|
+
role={bannerRole(tone)}
|
|
44
|
+
className={classes(rootPart("Banner"), bannerClass(tone), className)}
|
|
45
|
+
style={style}
|
|
46
|
+
>
|
|
47
|
+
<svg viewBox="0 0 24 24" aria-hidden="true" className={bannerIconClass(tone)}>
|
|
48
|
+
<path fill="currentColor" d={bannerIconPath(tone)} />
|
|
49
|
+
</svg>
|
|
50
|
+
<div className={BANNER_PARTS.body}>
|
|
51
|
+
{title && <p className={BANNER_PARTS.title}>{title}</p>}
|
|
52
|
+
<div>{children}</div>
|
|
53
|
+
{/* Its controls name their variant and size: a Button or IconButton default that the
|
|
54
|
+
app sets is for the app's own controls, not for the parts of a banner. */}
|
|
55
|
+
{action && (
|
|
56
|
+
<div className={BANNER_PARTS.action}>
|
|
57
|
+
<Button variant="secondary" size="sm" onPress={action.onPress}>
|
|
58
|
+
{action.label}
|
|
59
|
+
</Button>
|
|
60
|
+
</div>
|
|
61
|
+
)}
|
|
62
|
+
</div>
|
|
63
|
+
{onDismiss && (
|
|
64
|
+
<div className={BANNER_PARTS.dismiss}>
|
|
65
|
+
<IconButton icon="x" label={dismissLabel} variant="ghost" size="sm" onPress={onDismiss} />
|
|
66
|
+
</div>
|
|
67
|
+
)}
|
|
68
|
+
</div>
|
|
69
|
+
);
|
|
70
|
+
}
|
|
@@ -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, useDefaults, useTrigger } from "@xds/react/base";
|
|
5
|
+
import type { ReactNode } from "react";
|
|
6
|
+
import { BUTTON_ICON, type ButtonBaseProps, buttonClass, isHeld } from "./button.ts";
|
|
7
|
+
import { Icon } from "./Icon.tsx";
|
|
8
|
+
import { classes } from "./parts.ts";
|
|
9
|
+
import { Spinner } from "./Spinner.tsx";
|
|
10
|
+
|
|
11
|
+
export type { ButtonVariant, ControlSize } from "./button.ts";
|
|
12
|
+
|
|
13
|
+
export type ButtonProps = ButtonBaseProps &
|
|
14
|
+
RootProps & {
|
|
15
|
+
onPress?: () => void;
|
|
16
|
+
/** Leave it out for a button that holds only an icon, and name that one with `aria-label`. */
|
|
17
|
+
children?: ReactNode;
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* A native button. It also opens a Menu or a Tooltip it is the trigger of: their props reach
|
|
22
|
+
* it through context.
|
|
23
|
+
*/
|
|
24
|
+
export function Button(props: ButtonProps) {
|
|
25
|
+
const defaults = useDefaults("Button");
|
|
26
|
+
const {
|
|
27
|
+
iconStart,
|
|
28
|
+
iconEnd,
|
|
29
|
+
selected,
|
|
30
|
+
disabled = false,
|
|
31
|
+
loading = false,
|
|
32
|
+
fullWidth = false,
|
|
33
|
+
type = "button",
|
|
34
|
+
onPress,
|
|
35
|
+
"aria-label": label,
|
|
36
|
+
className,
|
|
37
|
+
style,
|
|
38
|
+
children,
|
|
39
|
+
} = props;
|
|
40
|
+
const variant = props.variant ?? defaults.variant ?? "secondary";
|
|
41
|
+
const size = props.size ?? defaults.size ?? "md";
|
|
42
|
+
const icon = BUTTON_ICON[size];
|
|
43
|
+
const attributes = useTrigger(
|
|
44
|
+
{
|
|
45
|
+
// The recipe's first class is the root part, `{{prefix}}-button`.
|
|
46
|
+
className: classes(
|
|
47
|
+
buttonClass({
|
|
48
|
+
variant,
|
|
49
|
+
size,
|
|
50
|
+
iconOnly: children == null && (iconStart !== undefined || iconEnd !== undefined),
|
|
51
|
+
fullWidth,
|
|
52
|
+
}),
|
|
53
|
+
className,
|
|
54
|
+
),
|
|
55
|
+
style,
|
|
56
|
+
disabled,
|
|
57
|
+
// Loading keeps the button focusable, so focus is not lost while it waits.
|
|
58
|
+
"aria-disabled": loading || undefined,
|
|
59
|
+
"data-pending": loading ? "" : undefined,
|
|
60
|
+
"aria-pressed": selected,
|
|
61
|
+
"aria-label": label,
|
|
62
|
+
onClick: () => {
|
|
63
|
+
// The press was taken already.
|
|
64
|
+
if (!loading) onPress?.();
|
|
65
|
+
},
|
|
66
|
+
},
|
|
67
|
+
loading,
|
|
68
|
+
);
|
|
69
|
+
return (
|
|
70
|
+
// oxlint-disable-next-line react/button-has-type -- one of the three types, from the props
|
|
71
|
+
<button {...attributes} type={type}>
|
|
72
|
+
{loading &&
|
|
73
|
+
(iconStart ? (
|
|
74
|
+
// Where the icon was, so the button keeps its width.
|
|
75
|
+
<span className={icon.box}>
|
|
76
|
+
<Spinner size="sm" />
|
|
77
|
+
</span>
|
|
78
|
+
) : (
|
|
79
|
+
<Spinner size="sm" />
|
|
80
|
+
))}
|
|
81
|
+
{iconStart && !loading && (
|
|
82
|
+
<Icon name={iconStart} size={icon.size} filled={isHeld({ variant, selected, disabled })} />
|
|
83
|
+
)}
|
|
84
|
+
{children}
|
|
85
|
+
{iconEnd && <Icon name={iconEnd} size={icon.size} />}
|
|
86
|
+
</button>
|
|
87
|
+
);
|
|
88
|
+
}
|
|
@@ -0,0 +1,85 @@
|
|
|
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 type { ReactNode } from "react";
|
|
6
|
+
import { CARD_PARTS, type CardBaseProps, cardClass, cardMediaClass } from "./card.ts";
|
|
7
|
+
import { classes, rootPart } from "./parts.ts";
|
|
8
|
+
|
|
9
|
+
export type CardProps = CardBaseProps &
|
|
10
|
+
RootProps & {
|
|
11
|
+
/** Sit across from the title. A pressable card takes none: it is one button already. */
|
|
12
|
+
actions?: ReactNode;
|
|
13
|
+
/** A picture or a drawing at the top, running edge to edge above the padding. */
|
|
14
|
+
media?: ReactNode;
|
|
15
|
+
/** Makes the whole card one button. Put no other control inside it then. */
|
|
16
|
+
onPress?: () => void;
|
|
17
|
+
children?: ReactNode;
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* A surface that groups related content. A hairline outline and a trace of shadow lift it off
|
|
22
|
+
* the page; in dark mode, where shadows barely show, the lighter fill does that. `title`
|
|
23
|
+
* renders as a heading; `actions` sit across from it.
|
|
24
|
+
*/
|
|
25
|
+
export function Card({
|
|
26
|
+
title,
|
|
27
|
+
description,
|
|
28
|
+
actions,
|
|
29
|
+
media,
|
|
30
|
+
flush = false,
|
|
31
|
+
onPress,
|
|
32
|
+
selected,
|
|
33
|
+
className,
|
|
34
|
+
style,
|
|
35
|
+
children,
|
|
36
|
+
}: CardProps) {
|
|
37
|
+
const surface = classes(
|
|
38
|
+
rootPart("Card"),
|
|
39
|
+
cardClass({ selected, flush, pressable: onPress !== undefined }),
|
|
40
|
+
className,
|
|
41
|
+
);
|
|
42
|
+
// A button may hold only phrasing content, so inside one the parts are spans. Its heading
|
|
43
|
+
// would not be reachable as a heading anyway: a button reads as its text.
|
|
44
|
+
const [Header, Box, Title, Line] = onPress
|
|
45
|
+
? (["span", "span", "span", "span"] as const)
|
|
46
|
+
: (["header", "div", "h2", "p"] as const);
|
|
47
|
+
const parts = (
|
|
48
|
+
<>
|
|
49
|
+
{media != null && <Box className={cardMediaClass(flush)}>{media}</Box>}
|
|
50
|
+
{(title || (actions && !onPress)) && (
|
|
51
|
+
<Header className={CARD_PARTS.header}>
|
|
52
|
+
<Box className={CARD_PARTS.heading}>
|
|
53
|
+
{title && <Title className={CARD_PARTS.title}>{title}</Title>}
|
|
54
|
+
{description && <Line className={CARD_PARTS.description}>{description}</Line>}
|
|
55
|
+
</Box>
|
|
56
|
+
{actions && !onPress && <div className={CARD_PARTS.actions}>{actions}</div>}
|
|
57
|
+
</Header>
|
|
58
|
+
)}
|
|
59
|
+
{children}
|
|
60
|
+
</>
|
|
61
|
+
);
|
|
62
|
+
const content = flush ? <Box className={CARD_PARTS.flush}>{parts}</Box> : parts;
|
|
63
|
+
if (!onPress) {
|
|
64
|
+
return (
|
|
65
|
+
<section
|
|
66
|
+
{...(selected ? { "aria-current": "true" as const } : {})}
|
|
67
|
+
className={surface}
|
|
68
|
+
style={style}
|
|
69
|
+
>
|
|
70
|
+
{content}
|
|
71
|
+
</section>
|
|
72
|
+
);
|
|
73
|
+
}
|
|
74
|
+
return (
|
|
75
|
+
<button
|
|
76
|
+
type="button"
|
|
77
|
+
onClick={onPress}
|
|
78
|
+
{...(selected === undefined ? {} : { "aria-pressed": selected })}
|
|
79
|
+
className={surface}
|
|
80
|
+
style={style}
|
|
81
|
+
>
|
|
82
|
+
{content}
|
|
83
|
+
</button>
|
|
84
|
+
);
|
|
85
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
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 {
|
|
6
|
+
CHECKBOX_MARK,
|
|
7
|
+
type CheckboxBaseProps,
|
|
8
|
+
checkboxBoxClass,
|
|
9
|
+
checkboxClass,
|
|
10
|
+
checkboxLabelClass,
|
|
11
|
+
checkboxMarkClass,
|
|
12
|
+
} from "./checkbox.ts";
|
|
13
|
+
import { classes, rootPart } from "./parts.ts";
|
|
14
|
+
|
|
15
|
+
export type CheckboxProps = CheckboxBaseProps &
|
|
16
|
+
RootProps & {
|
|
17
|
+
onChange: (checked: boolean) => void;
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* A choice that is applied later, with the form it belongs to. A native checkbox: the input is
|
|
22
|
+
* hidden and the box is drawn beside it.
|
|
23
|
+
*/
|
|
24
|
+
export function Checkbox({
|
|
25
|
+
checked,
|
|
26
|
+
onChange,
|
|
27
|
+
label,
|
|
28
|
+
name,
|
|
29
|
+
disabled = false,
|
|
30
|
+
className,
|
|
31
|
+
style,
|
|
32
|
+
...aria
|
|
33
|
+
}: CheckboxProps) {
|
|
34
|
+
return (
|
|
35
|
+
<label className={classes(rootPart("Checkbox"), checkboxClass, className)} style={style}>
|
|
36
|
+
<input
|
|
37
|
+
{...aria}
|
|
38
|
+
type="checkbox"
|
|
39
|
+
className="peer sr-only"
|
|
40
|
+
checked={checked}
|
|
41
|
+
disabled={disabled}
|
|
42
|
+
onChange={(event) => onChange(event.target.checked)}
|
|
43
|
+
{...(name ? { name } : {})}
|
|
44
|
+
/>
|
|
45
|
+
<span className={checkboxBoxClass}>
|
|
46
|
+
<svg viewBox="0 0 16 16" fill="none" aria-hidden="true" className={checkboxMarkClass}>
|
|
47
|
+
<path
|
|
48
|
+
d={CHECKBOX_MARK}
|
|
49
|
+
stroke="currentColor"
|
|
50
|
+
strokeWidth="2"
|
|
51
|
+
strokeLinecap="round"
|
|
52
|
+
strokeLinejoin="round"
|
|
53
|
+
/>
|
|
54
|
+
</svg>
|
|
55
|
+
</span>
|
|
56
|
+
{label && <span className={checkboxLabelClass}>{label}</span>}
|
|
57
|
+
</label>
|
|
58
|
+
);
|
|
59
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
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 { type ChipBaseProps, chipClass, chipIcon } from "./chip.ts";
|
|
6
|
+
import { Icon } from "./Icon.tsx";
|
|
7
|
+
import { classes, rootPart } from "./parts.ts";
|
|
8
|
+
|
|
9
|
+
export type ChipProps = ChipBaseProps &
|
|
10
|
+
RootProps & {
|
|
11
|
+
onPress?: () => void;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* A choice that filters what is shown. Unlike a Badge it is pressed. A selected chip is tinted,
|
|
16
|
+
* outlined and marked with a check, so the state does not depend on color.
|
|
17
|
+
*
|
|
18
|
+
* It is a toggle button: assistive technology hears whether it is pressed.
|
|
19
|
+
*/
|
|
20
|
+
export function Chip({
|
|
21
|
+
label,
|
|
22
|
+
selected = false,
|
|
23
|
+
onPress,
|
|
24
|
+
iconStart,
|
|
25
|
+
disabled = false,
|
|
26
|
+
className,
|
|
27
|
+
style,
|
|
28
|
+
}: ChipProps) {
|
|
29
|
+
const icon = chipIcon({ selected, iconStart });
|
|
30
|
+
return (
|
|
31
|
+
<button
|
|
32
|
+
type="button"
|
|
33
|
+
aria-pressed={selected}
|
|
34
|
+
disabled={disabled}
|
|
35
|
+
onClick={onPress}
|
|
36
|
+
className={classes(rootPart("Chip"), chipClass(selected), className)}
|
|
37
|
+
style={style}
|
|
38
|
+
>
|
|
39
|
+
{icon && <Icon name={icon} size="sm" />}
|
|
40
|
+
{label}
|
|
41
|
+
</button>
|
|
42
|
+
);
|
|
43
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
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 type { ReactNode } from "react";
|
|
6
|
+
import { type ChipBarBaseProps, chipBarClass } from "./chip-bar.ts";
|
|
7
|
+
import { classes, rootPart } from "./parts.ts";
|
|
8
|
+
|
|
9
|
+
export type ChipBarProps = ChipBarBaseProps &
|
|
10
|
+
RootProps & {
|
|
11
|
+
/** The chips. Which of them are selected is the app's business: the bar holds no state. */
|
|
12
|
+
children: ReactNode;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* One row of chips. It scrolls sideways when the chips do not fit and never wraps, so the
|
|
17
|
+
* content under it stays where it is.
|
|
18
|
+
*/
|
|
19
|
+
export function ChipBar({ label, className, style, children }: ChipBarProps) {
|
|
20
|
+
return (
|
|
21
|
+
// A group, not a fieldset: a fieldset cannot be a scrolling flex row in every browser.
|
|
22
|
+
<div
|
|
23
|
+
role="group"
|
|
24
|
+
aria-label={label}
|
|
25
|
+
className={classes(rootPart("ChipBar"), chipBarClass, className)}
|
|
26
|
+
style={style}
|
|
27
|
+
>
|
|
28
|
+
{children}
|
|
29
|
+
</div>
|
|
30
|
+
);
|
|
31
|
+
}
|