@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,109 @@
|
|
|
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, useMergedProps } from "@xds/react/base";
|
|
5
|
+
import { mergeProps, normalizeProps, useMachine } from "@zag-js/react";
|
|
6
|
+
import * as slider from "@zag-js/slider";
|
|
7
|
+
import { useId, useRef } from "react";
|
|
8
|
+
import { classes } from "./parts.ts";
|
|
9
|
+
import {
|
|
10
|
+
focusThumbOnPress,
|
|
11
|
+
type SliderBaseProps,
|
|
12
|
+
sliderArrowValue,
|
|
13
|
+
sliderPageSize,
|
|
14
|
+
sliderValueText,
|
|
15
|
+
} from "./slider.ts";
|
|
16
|
+
|
|
17
|
+
export type SliderProps = SliderBaseProps &
|
|
18
|
+
RootProps & {
|
|
19
|
+
onChange: (value: number) => void;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Picks a number in a range by dragging the thumb, or by pressing the track where it should
|
|
24
|
+
* go. The values snap to `step`.
|
|
25
|
+
*
|
|
26
|
+
* It is a slider named by its label with its value, minimum and maximum, and each arrow key
|
|
27
|
+
* moves it one step.
|
|
28
|
+
*/
|
|
29
|
+
export function Slider({
|
|
30
|
+
label,
|
|
31
|
+
value,
|
|
32
|
+
onChange,
|
|
33
|
+
min = 0,
|
|
34
|
+
max = 100,
|
|
35
|
+
step = 1,
|
|
36
|
+
disabled = false,
|
|
37
|
+
showValue = false,
|
|
38
|
+
className,
|
|
39
|
+
style,
|
|
40
|
+
}: SliderProps) {
|
|
41
|
+
const pageSize = sliderPageSize({ min, max, step });
|
|
42
|
+
const service = useMachine(slider.machine, {
|
|
43
|
+
id: useId(),
|
|
44
|
+
value: [value],
|
|
45
|
+
// One thumb, so one number.
|
|
46
|
+
onValueChange: (details) => onChange(details.value[0] ?? min),
|
|
47
|
+
min,
|
|
48
|
+
max,
|
|
49
|
+
step,
|
|
50
|
+
largeStep: pageSize,
|
|
51
|
+
disabled,
|
|
52
|
+
// The thumb's center is on the value, at the ends too; the band is inset to make room.
|
|
53
|
+
thumbAlignment: "center",
|
|
54
|
+
getAriaValueText: (details) => sliderValueText(details.value),
|
|
55
|
+
});
|
|
56
|
+
const api = slider.connect(service, normalizeProps);
|
|
57
|
+
const thumbElement = useRef<HTMLDivElement>(null);
|
|
58
|
+
const thumb = mergeProps(api.getThumbProps({ index: 0 }), {
|
|
59
|
+
// Up and Down move a horizontal slider too, as they move a native range input.
|
|
60
|
+
onKeyDown: (event: { key: string; shiftKey: boolean }) => {
|
|
61
|
+
if (disabled) return;
|
|
62
|
+
const next = sliderArrowValue(event, {
|
|
63
|
+
value: api.value[0] ?? min,
|
|
64
|
+
min,
|
|
65
|
+
max,
|
|
66
|
+
step,
|
|
67
|
+
pageSize,
|
|
68
|
+
});
|
|
69
|
+
if (next !== undefined) api.setThumbValue(0, next);
|
|
70
|
+
},
|
|
71
|
+
});
|
|
72
|
+
const control = useMergedProps(api.getControlProps(), {
|
|
73
|
+
// No focus ring after a press. This handler runs before Zag's.
|
|
74
|
+
onPointerDown: (event: { button: number }) => {
|
|
75
|
+
if (!disabled) focusThumbOnPress(event, thumbElement.current);
|
|
76
|
+
},
|
|
77
|
+
});
|
|
78
|
+
return (
|
|
79
|
+
// A group named by the label, around the label, the value and the slider. Not a fieldset:
|
|
80
|
+
// that is for a set of fields, and this is one slider and its label.
|
|
81
|
+
<div
|
|
82
|
+
{...mergeProps(api.getRootProps(), {
|
|
83
|
+
className: classes("{{prefix}}-slider", className),
|
|
84
|
+
style,
|
|
85
|
+
})}
|
|
86
|
+
role="group"
|
|
87
|
+
aria-labelledby={api.getLabelProps().id}
|
|
88
|
+
>
|
|
89
|
+
{/* Zag's props give it `htmlFor`, the hidden input's id. */}
|
|
90
|
+
<label {...api.getLabelProps()} className="{{prefix}}-slider__label">
|
|
91
|
+
{label}
|
|
92
|
+
</label>
|
|
93
|
+
{showValue && (
|
|
94
|
+
// Read when asked for, not at every step: the slider itself announces its value.
|
|
95
|
+
<output {...api.getValueTextProps()} aria-live="off" className="{{prefix}}-slider__output">
|
|
96
|
+
{sliderValueText(api.value[0] ?? value)}
|
|
97
|
+
</output>
|
|
98
|
+
)}
|
|
99
|
+
<div {...control} className="{{prefix}}-slider__control">
|
|
100
|
+
<div {...api.getTrackProps()} className="{{prefix}}-slider__track">
|
|
101
|
+
<div {...api.getRangeProps()} className="{{prefix}}-slider__range" />
|
|
102
|
+
</div>
|
|
103
|
+
<div {...thumb} ref={thumbElement} className="{{prefix}}-slider__thumb">
|
|
104
|
+
<input {...api.getHiddenInputProps({ index: 0 })} />
|
|
105
|
+
</div>
|
|
106
|
+
</div>
|
|
107
|
+
</div>
|
|
108
|
+
);
|
|
109
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
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 SpinnerBaseProps, spinnerClass } from "./spinner.ts";
|
|
7
|
+
|
|
8
|
+
export type SpinnerProps = SpinnerBaseProps & RootProps;
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Says that something is in progress and how long is unknown. Takes the color of the text around
|
|
12
|
+
* it. With `label` it is announced; without one it is decoration next to text that already says
|
|
13
|
+
* what is happening.
|
|
14
|
+
*/
|
|
15
|
+
export function Spinner(props: SpinnerProps) {
|
|
16
|
+
const defaults = useDefaults("Spinner");
|
|
17
|
+
const { label, className, style } = props;
|
|
18
|
+
const size = props.size ?? defaults.size;
|
|
19
|
+
return (
|
|
20
|
+
<span
|
|
21
|
+
className={classes(rootPart("Spinner"), "inline-flex shrink-0", className)}
|
|
22
|
+
style={style}
|
|
23
|
+
{...(label ? { role: "status", "aria-label": label } : { "aria-hidden": true })}
|
|
24
|
+
>
|
|
25
|
+
<svg viewBox="0 0 24 24" fill="none" aria-hidden="true" className={spinnerClass(size)}>
|
|
26
|
+
<circle cx="12" cy="12" r="9" stroke="currentColor" strokeWidth="3" opacity="0.25" />
|
|
27
|
+
<path
|
|
28
|
+
d="M21 12a9 9 0 0 0-9-9"
|
|
29
|
+
stroke="currentColor"
|
|
30
|
+
strokeWidth="3"
|
|
31
|
+
strokeLinecap="round"
|
|
32
|
+
/>
|
|
33
|
+
</svg>
|
|
34
|
+
</span>
|
|
35
|
+
);
|
|
36
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
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 { classes, rootPart } from "./parts.ts";
|
|
6
|
+
import {
|
|
7
|
+
type SwitchBaseProps,
|
|
8
|
+
switchClass,
|
|
9
|
+
switchLabelClass,
|
|
10
|
+
switchThumbClass,
|
|
11
|
+
switchTrackClass,
|
|
12
|
+
} from "./switch.ts";
|
|
13
|
+
|
|
14
|
+
export type SwitchProps = SwitchBaseProps &
|
|
15
|
+
RootProps & {
|
|
16
|
+
onChange: (checked: boolean) => void;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Turns a setting on or off, and takes effect at once. For a choice that is applied later,
|
|
21
|
+
* with a form, use a Checkbox.
|
|
22
|
+
*
|
|
23
|
+
* It is a native checkbox with the switch role, so the keyboard, forms and screen readers
|
|
24
|
+
* treat it as one. The input is hidden and the track is drawn beside it.
|
|
25
|
+
*/
|
|
26
|
+
export function Switch({
|
|
27
|
+
checked,
|
|
28
|
+
onChange,
|
|
29
|
+
label,
|
|
30
|
+
disabled = false,
|
|
31
|
+
className,
|
|
32
|
+
style,
|
|
33
|
+
...aria
|
|
34
|
+
}: SwitchProps) {
|
|
35
|
+
return (
|
|
36
|
+
<label className={classes(rootPart("Switch"), switchClass, className)} style={style}>
|
|
37
|
+
<input
|
|
38
|
+
{...aria}
|
|
39
|
+
type="checkbox"
|
|
40
|
+
role="switch"
|
|
41
|
+
aria-checked={checked}
|
|
42
|
+
className="peer sr-only"
|
|
43
|
+
checked={checked}
|
|
44
|
+
disabled={disabled}
|
|
45
|
+
onChange={(event) => onChange(event.target.checked)}
|
|
46
|
+
/>
|
|
47
|
+
<span className={switchTrackClass}>
|
|
48
|
+
<span className={switchThumbClass} />
|
|
49
|
+
</span>
|
|
50
|
+
{label && <span className={switchLabelClass}>{label}</span>}
|
|
51
|
+
</label>
|
|
52
|
+
);
|
|
53
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
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 { mergeProps, normalizeProps, useMachine } from "@zag-js/react";
|
|
6
|
+
import * as tabs from "@zag-js/tabs";
|
|
7
|
+
import { useId } from "react";
|
|
8
|
+
import { Icon } from "./Icon.tsx";
|
|
9
|
+
import { classes } from "./parts.ts";
|
|
10
|
+
import { type TabsBaseProps, tabStopIndex, tabsClass } from "./tabs.ts";
|
|
11
|
+
|
|
12
|
+
export type TabsProps<Value extends string> = TabsBaseProps<Value> &
|
|
13
|
+
RootProps & {
|
|
14
|
+
onChange: (value: Value) => void;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Switches between views inside one screen. For two to four short modes a SegmentedControl is
|
|
19
|
+
* lighter; tabs are for more items, longer labels, or a row that may have to scroll.
|
|
20
|
+
*
|
|
21
|
+
* The selected tab is underlined as well as darker, so the choice does not depend on color.
|
|
22
|
+
* This is only the row: the app shows the view that matches `value`. The arrow keys move
|
|
23
|
+
* between tabs.
|
|
24
|
+
*/
|
|
25
|
+
export function Tabs<Value extends string>({
|
|
26
|
+
items,
|
|
27
|
+
value,
|
|
28
|
+
onChange,
|
|
29
|
+
label,
|
|
30
|
+
fullWidth = false,
|
|
31
|
+
className,
|
|
32
|
+
style,
|
|
33
|
+
}: TabsProps<Value>) {
|
|
34
|
+
const service = useMachine(tabs.machine, {
|
|
35
|
+
id: useId(),
|
|
36
|
+
value,
|
|
37
|
+
onValueChange: (details) => onChange(details.value as Value),
|
|
38
|
+
});
|
|
39
|
+
const api = tabs.connect(service, normalizeProps);
|
|
40
|
+
return (
|
|
41
|
+
// The recipe's first class is the root part, `{{prefix}}-tabs`.
|
|
42
|
+
<div
|
|
43
|
+
{...mergeProps(api.getRootProps(), {
|
|
44
|
+
className: classes(tabsClass(fullWidth), className),
|
|
45
|
+
style,
|
|
46
|
+
})}
|
|
47
|
+
>
|
|
48
|
+
<div {...api.getListProps()} aria-label={label} className="{{prefix}}-tabs__list">
|
|
49
|
+
{items.map((item) => {
|
|
50
|
+
const trigger = api.getTriggerProps({ value: item.value });
|
|
51
|
+
return (
|
|
52
|
+
<button
|
|
53
|
+
key={item.value}
|
|
54
|
+
{...trigger}
|
|
55
|
+
tabIndex={tabStopIndex(api.focusedValue, item.value, trigger.tabIndex)}
|
|
56
|
+
// Zag points the selected tab at its panel, which this row never renders: the app
|
|
57
|
+
// shows the view. A reference to an element that does not exist is invalid.
|
|
58
|
+
aria-controls={undefined}
|
|
59
|
+
type="button"
|
|
60
|
+
className="{{prefix}}-tabs__tab"
|
|
61
|
+
>
|
|
62
|
+
{item.icon && <Icon name={item.icon} size="sm" />}
|
|
63
|
+
{item.label}
|
|
64
|
+
</button>
|
|
65
|
+
);
|
|
66
|
+
})}
|
|
67
|
+
<div {...api.getIndicatorProps()} className="{{prefix}}-tabs__indicator" />
|
|
68
|
+
</div>
|
|
69
|
+
</div>
|
|
70
|
+
);
|
|
71
|
+
}
|
|
@@ -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, useDefaults } from "@xds/react/base";
|
|
5
|
+
import type { ElementType, ReactNode } from "react";
|
|
6
|
+
import { classes, rootPart } from "./parts.ts";
|
|
7
|
+
import { type TextBaseProps, textClass } from "./text.ts";
|
|
8
|
+
|
|
9
|
+
export type { TextTone, TextVariant } from "./text.ts";
|
|
10
|
+
|
|
11
|
+
export type TextProps = TextBaseProps &
|
|
12
|
+
RootProps & {
|
|
13
|
+
/** The element to render. Pick it for the document outline (`h1`, `h2`, `p`), not for looks. */
|
|
14
|
+
as?: ElementType;
|
|
15
|
+
children: ReactNode;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export function Text(props: TextProps) {
|
|
19
|
+
const defaults = useDefaults("Text");
|
|
20
|
+
const { as: Element = "p", className, style, children } = props;
|
|
21
|
+
const variant = props.variant ?? defaults.variant;
|
|
22
|
+
const tone = props.tone ?? defaults.tone;
|
|
23
|
+
return (
|
|
24
|
+
<Element
|
|
25
|
+
className={classes(rootPart("Text"), textClass({ variant, tone }), className)}
|
|
26
|
+
style={style}
|
|
27
|
+
>
|
|
28
|
+
{children}
|
|
29
|
+
</Element>
|
|
30
|
+
);
|
|
31
|
+
}
|
|
@@ -0,0 +1,122 @@
|
|
|
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, useId } from "react";
|
|
6
|
+
import { classes } from "./parts.ts";
|
|
7
|
+
import type { TextFieldBaseProps } from "./text-field.ts";
|
|
8
|
+
|
|
9
|
+
export type TextFieldProps = TextFieldBaseProps &
|
|
10
|
+
RootProps & {
|
|
11
|
+
onChange: (value: string) => void;
|
|
12
|
+
/**
|
|
13
|
+
* Inside the box, in front of the text: an icon, a unit. It takes the placeholder's color
|
|
14
|
+
* unless it sets its own.
|
|
15
|
+
*/
|
|
16
|
+
leading?: ReactNode;
|
|
17
|
+
/** Inside the box, after the text: an icon, a unit, a small button. */
|
|
18
|
+
trailing?: ReactNode;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* A labelled text field, of one line or several. The label, the description and the error
|
|
23
|
+
* message are tied to the input for assistive technology, and the error is announced when it
|
|
24
|
+
* appears.
|
|
25
|
+
*
|
|
26
|
+
* An invalid field blocks its form from being submitted, so `error` has to be cleared as soon as
|
|
27
|
+
* the person edits the value.
|
|
28
|
+
*/
|
|
29
|
+
export function TextField({
|
|
30
|
+
label,
|
|
31
|
+
value,
|
|
32
|
+
onChange,
|
|
33
|
+
description,
|
|
34
|
+
error,
|
|
35
|
+
placeholder,
|
|
36
|
+
leading,
|
|
37
|
+
trailing,
|
|
38
|
+
multiline = false,
|
|
39
|
+
rows = 3,
|
|
40
|
+
maxLength,
|
|
41
|
+
name,
|
|
42
|
+
type = "text",
|
|
43
|
+
inputMode,
|
|
44
|
+
autoComplete,
|
|
45
|
+
autoFocus = false,
|
|
46
|
+
required = false,
|
|
47
|
+
disabled = false,
|
|
48
|
+
className,
|
|
49
|
+
style,
|
|
50
|
+
}: TextFieldProps) {
|
|
51
|
+
const id = useId();
|
|
52
|
+
const descriptionId = `${id}-description`;
|
|
53
|
+
const errorId = `${id}-error`;
|
|
54
|
+
const invalid = error !== undefined;
|
|
55
|
+
// The box is drawn by the input itself until something has to sit inside it beside the
|
|
56
|
+
// text; then a group draws the box and the input inside it has none.
|
|
57
|
+
const grouped = leading != null || trailing != null;
|
|
58
|
+
const shared = {
|
|
59
|
+
id,
|
|
60
|
+
className: grouped
|
|
61
|
+
? "{{prefix}}-text-field__input"
|
|
62
|
+
: "{{prefix}}-text-field__input {{prefix}}-text-field__control",
|
|
63
|
+
value,
|
|
64
|
+
placeholder,
|
|
65
|
+
name,
|
|
66
|
+
maxLength,
|
|
67
|
+
inputMode,
|
|
68
|
+
autoComplete,
|
|
69
|
+
autoFocus,
|
|
70
|
+
required,
|
|
71
|
+
disabled,
|
|
72
|
+
"aria-invalid": invalid || undefined,
|
|
73
|
+
"aria-errormessage": invalid ? errorId : undefined,
|
|
74
|
+
"aria-describedby": invalid ? errorId : description ? descriptionId : undefined,
|
|
75
|
+
};
|
|
76
|
+
const field = multiline ? (
|
|
77
|
+
<textarea {...shared} rows={rows} onChange={(event) => onChange(event.currentTarget.value)} />
|
|
78
|
+
) : (
|
|
79
|
+
<input {...shared} type={type} onChange={(event) => onChange(event.currentTarget.value)} />
|
|
80
|
+
);
|
|
81
|
+
return (
|
|
82
|
+
<div className={classes("{{prefix}}-text-field", className)} style={style}>
|
|
83
|
+
<label htmlFor={id} className="{{prefix}}-text-field__label">
|
|
84
|
+
{label}
|
|
85
|
+
</label>
|
|
86
|
+
{grouped ? (
|
|
87
|
+
<div className="{{prefix}}-text-field__control {{prefix}}-text-field__group">
|
|
88
|
+
{leading != null && (
|
|
89
|
+
<span className="{{prefix}}-text-field__slot {{prefix}}-text-field__slot--leading">
|
|
90
|
+
{leading}
|
|
91
|
+
</span>
|
|
92
|
+
)}
|
|
93
|
+
{field}
|
|
94
|
+
{trailing != null && (
|
|
95
|
+
<span className="{{prefix}}-text-field__slot {{prefix}}-text-field__slot--trailing">
|
|
96
|
+
{trailing}
|
|
97
|
+
</span>
|
|
98
|
+
)}
|
|
99
|
+
</div>
|
|
100
|
+
) : (
|
|
101
|
+
field
|
|
102
|
+
)}
|
|
103
|
+
{/* One line under the box: the help or the error at the start edge, the count at the
|
|
104
|
+
end. The error is a live region, so it is announced when it appears. */}
|
|
105
|
+
<div className="{{prefix}}-text-field__footer">
|
|
106
|
+
{!invalid && description && (
|
|
107
|
+
<span id={descriptionId} className="{{prefix}}-text-field__description">
|
|
108
|
+
{description}
|
|
109
|
+
</span>
|
|
110
|
+
)}
|
|
111
|
+
<span id={errorId} className="{{prefix}}-text-field__error" aria-live="polite">
|
|
112
|
+
{error}
|
|
113
|
+
</span>
|
|
114
|
+
{maxLength !== undefined && (
|
|
115
|
+
<span className="ms-auto shrink-0 text-xds-footnote text-xds-text-secondary tabular-nums">
|
|
116
|
+
{value.length}/{maxLength}
|
|
117
|
+
</span>
|
|
118
|
+
)}
|
|
119
|
+
</div>
|
|
120
|
+
</div>
|
|
121
|
+
);
|
|
122
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
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 { pictureClass, type RootProps, useDefaults, usePicture } from "@xds/react/base";
|
|
5
|
+
import { Badge } from "./Badge.tsx";
|
|
6
|
+
import { Icon } from "./Icon.tsx";
|
|
7
|
+
import { classes, rootPart } from "./parts.ts";
|
|
8
|
+
import {
|
|
9
|
+
THUMBNAIL_PARTS,
|
|
10
|
+
type ThumbnailBaseProps,
|
|
11
|
+
thumbnailBadgeClass,
|
|
12
|
+
thumbnailClass,
|
|
13
|
+
thumbnailWatched,
|
|
14
|
+
} from "./thumbnail.ts";
|
|
15
|
+
|
|
16
|
+
export type { ThumbnailRatio } from "./thumbnail.ts";
|
|
17
|
+
|
|
18
|
+
export type ThumbnailProps = ThumbnailBaseProps & RootProps;
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* A picture in a fixed shape, for a video, an article or a product. It fills the width it is
|
|
22
|
+
* given and takes its height from `ratio`, and crops the picture to fill it.
|
|
23
|
+
*/
|
|
24
|
+
export function Thumbnail(props: ThumbnailProps) {
|
|
25
|
+
const defaults = useDefaults("Thumbnail");
|
|
26
|
+
const { src, alt, badge, progress, className, style } = props;
|
|
27
|
+
const ratio = props.ratio ?? defaults.ratio;
|
|
28
|
+
const picture = usePicture(src);
|
|
29
|
+
const watched = thumbnailWatched(progress);
|
|
30
|
+
return (
|
|
31
|
+
<span
|
|
32
|
+
className={classes(rootPart("Thumbnail"), thumbnailClass(ratio), className)}
|
|
33
|
+
style={style}
|
|
34
|
+
>
|
|
35
|
+
{/* The placeholder is the picture's stand-in for assistive technology too, so the
|
|
36
|
+
description is on the box that always shows, not on the picture that may not. */}
|
|
37
|
+
<span
|
|
38
|
+
className={THUMBNAIL_PARTS.placeholder}
|
|
39
|
+
{...(alt ? { role: "img", "aria-label": alt } : { "aria-hidden": true })}
|
|
40
|
+
>
|
|
41
|
+
{picture.loaded !== true && <Icon name="image" size="lg" />}
|
|
42
|
+
{src && picture.loaded !== false && (
|
|
43
|
+
<img
|
|
44
|
+
src={src}
|
|
45
|
+
alt=""
|
|
46
|
+
aria-hidden="true"
|
|
47
|
+
className={pictureClass(picture.loaded === true)}
|
|
48
|
+
{...picture.image}
|
|
49
|
+
/>
|
|
50
|
+
)}
|
|
51
|
+
</span>
|
|
52
|
+
{badge && (
|
|
53
|
+
<span className={thumbnailBadgeClass(watched)}>
|
|
54
|
+
<Badge tone="overlay">{badge}</Badge>
|
|
55
|
+
</span>
|
|
56
|
+
)}
|
|
57
|
+
{watched > 0 && (
|
|
58
|
+
// Decoration: what was watched is for the eye, and a list that needs it said says it
|
|
59
|
+
// in words.
|
|
60
|
+
<span aria-hidden="true" className={THUMBNAIL_PARTS.track}>
|
|
61
|
+
<span className={THUMBNAIL_PARTS.fill} style={{ width: `${watched * 100}%` }} />
|
|
62
|
+
</span>
|
|
63
|
+
)}
|
|
64
|
+
</span>
|
|
65
|
+
);
|
|
66
|
+
}
|
|
@@ -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 { motion, type RootProps } from "@xds/react/base";
|
|
5
|
+
import { useEffect, useEffectEvent, useRef, useState } from "react";
|
|
6
|
+
import { classes, rootPart } from "./parts.ts";
|
|
7
|
+
import { TOAST_PARTS, type ToastBaseProps } from "./toast.ts";
|
|
8
|
+
|
|
9
|
+
export type ToastProps = ToastBaseProps &
|
|
10
|
+
RootProps & {
|
|
11
|
+
/** Called when the time is up and after the action. Set `open` to false in it. */
|
|
12
|
+
onClose: () => void;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* A short message about what just happened, which leaves on its own. It sits at the bottom
|
|
17
|
+
* center of the window, above everything else, and is announced politely without taking
|
|
18
|
+
* focus. The time does not run while the pointer is over it or focus is inside it.
|
|
19
|
+
*
|
|
20
|
+
* Do not put the only way to do something in a toast: it is gone in a few seconds.
|
|
21
|
+
*/
|
|
22
|
+
export function Toast({
|
|
23
|
+
open,
|
|
24
|
+
onClose,
|
|
25
|
+
message,
|
|
26
|
+
action,
|
|
27
|
+
duration = motion.duration.toast,
|
|
28
|
+
className,
|
|
29
|
+
style,
|
|
30
|
+
}: ToastProps) {
|
|
31
|
+
const region = useRef<HTMLDivElement>(null);
|
|
32
|
+
const [hovered, setHovered] = useState(false);
|
|
33
|
+
const [focused, setFocused] = useState(false);
|
|
34
|
+
const held = hovered || focused;
|
|
35
|
+
// The timer must not start over because the app handed over a new function on a render.
|
|
36
|
+
const close = useEffectEvent(onClose);
|
|
37
|
+
|
|
38
|
+
// The region is in the top layer for as long as the component is mounted, empty or not: a
|
|
39
|
+
// screen reader only announces what is added to a region it already knows.
|
|
40
|
+
useEffect(() => {
|
|
41
|
+
const element = region.current;
|
|
42
|
+
if (!element?.showPopover) return;
|
|
43
|
+
element.showPopover();
|
|
44
|
+
return () => element.hidePopover();
|
|
45
|
+
}, []);
|
|
46
|
+
|
|
47
|
+
useEffect(() => {
|
|
48
|
+
// A toast that closed under the pointer gets no event to say that the pointer left.
|
|
49
|
+
if (!open) {
|
|
50
|
+
setHovered(false);
|
|
51
|
+
setFocused(false);
|
|
52
|
+
}
|
|
53
|
+
if (!open || held || duration <= 0) return;
|
|
54
|
+
const timer = setTimeout(() => close(), duration);
|
|
55
|
+
return () => clearTimeout(timer);
|
|
56
|
+
}, [open, held, duration]);
|
|
57
|
+
|
|
58
|
+
return (
|
|
59
|
+
<div ref={region} role="status" popover="manual" className={TOAST_PARTS.region}>
|
|
60
|
+
{open && (
|
|
61
|
+
// No role: hover and focus only pause the timer, and the action inside is a real button.
|
|
62
|
+
// The root: the region around it only places it, and spans the window.
|
|
63
|
+
<div
|
|
64
|
+
onPointerEnter={() => setHovered(true)}
|
|
65
|
+
onPointerLeave={() => setHovered(false)}
|
|
66
|
+
onFocus={() => setFocused(true)}
|
|
67
|
+
onBlur={() => setFocused(false)}
|
|
68
|
+
className={classes(rootPart("Toast"), TOAST_PARTS.toast, className)}
|
|
69
|
+
style={style}
|
|
70
|
+
>
|
|
71
|
+
<span className={TOAST_PARTS.message}>{message}</span>
|
|
72
|
+
{action && (
|
|
73
|
+
<button
|
|
74
|
+
type="button"
|
|
75
|
+
onClick={() => {
|
|
76
|
+
action.onPress();
|
|
77
|
+
onClose();
|
|
78
|
+
}}
|
|
79
|
+
className={TOAST_PARTS.action}
|
|
80
|
+
>
|
|
81
|
+
{action.label}
|
|
82
|
+
</button>
|
|
83
|
+
)}
|
|
84
|
+
</div>
|
|
85
|
+
)}
|
|
86
|
+
</div>
|
|
87
|
+
);
|
|
88
|
+
}
|