@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,50 @@
|
|
|
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 {
|
|
7
|
+
type CountBadgeBaseProps,
|
|
8
|
+
countBadgeAnchorClass,
|
|
9
|
+
countBadgeClass,
|
|
10
|
+
countBadgeText,
|
|
11
|
+
} from "./count-badge.ts";
|
|
12
|
+
import { classes, rootPart } from "./parts.ts";
|
|
13
|
+
|
|
14
|
+
export type CountBadgeProps = CountBadgeBaseProps &
|
|
15
|
+
RootProps & {
|
|
16
|
+
/** What the count belongs to: an icon, an avatar, a button. The badge sits on its corner. */
|
|
17
|
+
children?: ReactNode;
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* A count of something waiting: unread messages, items in a cart. On its own it is laid out
|
|
22
|
+
* inline; around a child it sits on the child's top end corner.
|
|
23
|
+
*/
|
|
24
|
+
export function CountBadge({ count, max, label, className, style, children }: CountBadgeProps) {
|
|
25
|
+
// On its own the badge is the root; around a child the anchor is.
|
|
26
|
+
const anchored = children !== undefined;
|
|
27
|
+
const badge = count > 0 && (
|
|
28
|
+
<span
|
|
29
|
+
{...(label ? { role: "img", "aria-label": label } : {})}
|
|
30
|
+
className={
|
|
31
|
+
anchored
|
|
32
|
+
? countBadgeClass(true)
|
|
33
|
+
: classes(rootPart("CountBadge"), countBadgeClass(false), className)
|
|
34
|
+
}
|
|
35
|
+
style={anchored ? undefined : style}
|
|
36
|
+
>
|
|
37
|
+
{countBadgeText(count, max)}
|
|
38
|
+
</span>
|
|
39
|
+
);
|
|
40
|
+
if (!anchored) return badge || null;
|
|
41
|
+
return (
|
|
42
|
+
<span
|
|
43
|
+
className={classes(rootPart("CountBadge"), countBadgeAnchorClass, className)}
|
|
44
|
+
style={style}
|
|
45
|
+
>
|
|
46
|
+
{children}
|
|
47
|
+
{badge}
|
|
48
|
+
</span>
|
|
49
|
+
);
|
|
50
|
+
}
|
|
@@ -0,0 +1,192 @@
|
|
|
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 { Portal, type RootProps, useModalPopover, usePresence } from "@xds/react/base";
|
|
5
|
+
import * as datePicker from "@zag-js/date-picker";
|
|
6
|
+
import { mergeProps, normalizeProps, useMachine } from "@zag-js/react";
|
|
7
|
+
import { type MouseEvent, useEffect, useId, useRef } from "react";
|
|
8
|
+
import {
|
|
9
|
+
DATE_PICKER_NAV_CLASS,
|
|
10
|
+
type DatePickerBaseProps,
|
|
11
|
+
datePickerContentAttrs,
|
|
12
|
+
datePickerIds,
|
|
13
|
+
datePickerLocale,
|
|
14
|
+
datePickerMachineProps,
|
|
15
|
+
datePickerTriggerAttrs,
|
|
16
|
+
focusOpeningDay,
|
|
17
|
+
formatDay,
|
|
18
|
+
type IsoDate,
|
|
19
|
+
keepCalendarFocus,
|
|
20
|
+
keepDayFocused,
|
|
21
|
+
} from "./date-picker.ts";
|
|
22
|
+
import { Icon } from "./Icon.tsx";
|
|
23
|
+
import { classes } from "./parts.ts";
|
|
24
|
+
|
|
25
|
+
export type { IsoDate } from "./date-picker.ts";
|
|
26
|
+
|
|
27
|
+
export type DatePickerProps = DatePickerBaseProps &
|
|
28
|
+
RootProps & {
|
|
29
|
+
onChange: (value: IsoDate) => void;
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* A field for choosing one day. Closed, it looks like a Select: the chosen day in the locale's
|
|
34
|
+
* medium form, or the placeholder. Pressed, it opens a calendar of one month under itself, on
|
|
35
|
+
* the chosen day, or on today while none is. A press on a day, or Enter on the focused one,
|
|
36
|
+
* calls `onChange` with the day as `YYYY-MM-DD` and closes the calendar; Escape or a press
|
|
37
|
+
* outside closes it without a choice.
|
|
38
|
+
*
|
|
39
|
+
* The field is a button that says it opens a dialog and whether it is open. In the calendar the
|
|
40
|
+
* arrow keys move a day or a week, Page Up and Page Down a month (a year with Shift), and Home
|
|
41
|
+
* and End to the first and the last day of the month, never past `min` or `max`. Tab goes round
|
|
42
|
+
* the month buttons and the focused day. The chosen day is selected for assistive technology,
|
|
43
|
+
* and today is the current date.
|
|
44
|
+
*/
|
|
45
|
+
export function DatePicker({ onChange, className, style, ...props }: DatePickerProps) {
|
|
46
|
+
const { label, value, placeholder, description, error, name } = props;
|
|
47
|
+
const id = useId();
|
|
48
|
+
const ids = datePickerIds(id);
|
|
49
|
+
const locale = datePickerLocale();
|
|
50
|
+
const service = useMachine(
|
|
51
|
+
datePicker.machine,
|
|
52
|
+
datePickerMachineProps(props, { id, locale, onChange }),
|
|
53
|
+
);
|
|
54
|
+
const api = datePicker.connect(service, normalizeProps);
|
|
55
|
+
const trigger = api.getTriggerProps();
|
|
56
|
+
const positioner = useRef<HTMLDivElement>(null);
|
|
57
|
+
const surface = useRef<HTMLDivElement>(null);
|
|
58
|
+
useModalPopover(api.open, () => positioner.current);
|
|
59
|
+
const present = usePresence(api.open, () => [surface.current]);
|
|
60
|
+
const focused = api.focusedValue.toString();
|
|
61
|
+
const month = api.visibleRange.start.toString();
|
|
62
|
+
useEffect(() => keepDayFocused(api.open, surface.current), [api.open, focused, month]);
|
|
63
|
+
const invalid = error !== undefined;
|
|
64
|
+
return (
|
|
65
|
+
<div
|
|
66
|
+
{...mergeProps(api.getRootProps(), {
|
|
67
|
+
className: classes("{{prefix}}-date-picker", className),
|
|
68
|
+
style,
|
|
69
|
+
})}
|
|
70
|
+
>
|
|
71
|
+
{/* A span: the field is a button, which a <label> cannot point at. */}
|
|
72
|
+
<span id={ids.label} className="{{prefix}}-date-picker__label">
|
|
73
|
+
{label}
|
|
74
|
+
</span>
|
|
75
|
+
{/* What Zag places the calendar against. */}
|
|
76
|
+
<div {...api.getControlProps()} className="{{prefix}}-date-picker__control">
|
|
77
|
+
<button
|
|
78
|
+
{...trigger}
|
|
79
|
+
{...datePickerTriggerAttrs(props, ids)}
|
|
80
|
+
type="button"
|
|
81
|
+
onClick={(event: MouseEvent<HTMLButtonElement>) => {
|
|
82
|
+
focusOpeningDay(api, props);
|
|
83
|
+
trigger.onClick?.(event);
|
|
84
|
+
}}
|
|
85
|
+
className="{{prefix}}-date-picker__trigger"
|
|
86
|
+
>
|
|
87
|
+
<span id={ids.value} className="{{prefix}}-date-picker__value">
|
|
88
|
+
{value === undefined ? placeholder : formatDay(value, locale)}
|
|
89
|
+
</span>
|
|
90
|
+
<Icon name="calendar" size="sm" className="text-xds-field-placeholder" />
|
|
91
|
+
</button>
|
|
92
|
+
</div>
|
|
93
|
+
{/* One line under the box: the help, or the error in its place. */}
|
|
94
|
+
{(invalid || description) && (
|
|
95
|
+
<div className="{{prefix}}-date-picker__footer">
|
|
96
|
+
{invalid ? (
|
|
97
|
+
<span id={ids.error} className="{{prefix}}-date-picker__error">
|
|
98
|
+
{error}
|
|
99
|
+
</span>
|
|
100
|
+
) : (
|
|
101
|
+
<span id={ids.description} className="{{prefix}}-date-picker__description">
|
|
102
|
+
{description}
|
|
103
|
+
</span>
|
|
104
|
+
)}
|
|
105
|
+
</div>
|
|
106
|
+
)}
|
|
107
|
+
{/* What a form submits. Zag gives the name to its text input, which is not drawn. */}
|
|
108
|
+
{name !== undefined && <input type="hidden" name={name} value={value ?? ""} />}
|
|
109
|
+
<Portal>
|
|
110
|
+
{api.open && (
|
|
111
|
+
// Takes a press outside, which then only closes the calendar. The focus stays in the
|
|
112
|
+
// calendar until it hands it back to the field.
|
|
113
|
+
// oxlint-disable-next-line jsx-a11y/no-static-element-interactions -- not a control: the handler only keeps the focus where it is
|
|
114
|
+
<div
|
|
115
|
+
className="{{prefix}}-date-picker__underlay"
|
|
116
|
+
onMouseDown={(event) => event.preventDefault()}
|
|
117
|
+
/>
|
|
118
|
+
)}
|
|
119
|
+
<div
|
|
120
|
+
{...api.getPositionerProps()}
|
|
121
|
+
ref={positioner}
|
|
122
|
+
className="{{prefix}}-date-picker__positioner"
|
|
123
|
+
>
|
|
124
|
+
{/* Shown until its exit animation ends; Zag would hide it as it closes. */}
|
|
125
|
+
{/* oxlint-disable-next-line jsx-a11y/no-static-element-interactions -- a dialog: datePickerContentAttrs gives it the role */}
|
|
126
|
+
<div
|
|
127
|
+
{...api.getContentProps()}
|
|
128
|
+
{...datePickerContentAttrs(ids)}
|
|
129
|
+
ref={surface}
|
|
130
|
+
hidden={!present}
|
|
131
|
+
onKeyDown={(event) => keepCalendarFocus(event, surface.current)}
|
|
132
|
+
className="{{prefix}}-date-picker__content"
|
|
133
|
+
>
|
|
134
|
+
<div className="{{prefix}}-date-picker__header">
|
|
135
|
+
<button
|
|
136
|
+
{...api.getPreviousTriggerProps()}
|
|
137
|
+
type="button"
|
|
138
|
+
className={DATE_PICKER_NAV_CLASS}
|
|
139
|
+
>
|
|
140
|
+
<Icon name="chevron-left" size="sm" />
|
|
141
|
+
</button>
|
|
142
|
+
<span {...api.getRangeTextProps()} className="{{prefix}}-date-picker__heading">
|
|
143
|
+
{api.visibleRangeText.start}
|
|
144
|
+
</span>
|
|
145
|
+
<button
|
|
146
|
+
{...api.getNextTriggerProps()}
|
|
147
|
+
type="button"
|
|
148
|
+
className={DATE_PICKER_NAV_CLASS}
|
|
149
|
+
>
|
|
150
|
+
<Icon name="chevron-right" size="sm" />
|
|
151
|
+
</button>
|
|
152
|
+
</div>
|
|
153
|
+
<table {...api.getTableProps({ view: "day" })} className="{{prefix}}-date-picker__grid">
|
|
154
|
+
<thead {...api.getTableHeadProps({ view: "day" })}>
|
|
155
|
+
<tr {...api.getTableRowProps({ view: "day" })}>
|
|
156
|
+
{api.weekDays.map((weekDay) => (
|
|
157
|
+
<th key={weekDay.long} scope="col" className="{{prefix}}-date-picker__weekday">
|
|
158
|
+
{weekDay.narrow}
|
|
159
|
+
</th>
|
|
160
|
+
))}
|
|
161
|
+
</tr>
|
|
162
|
+
</thead>
|
|
163
|
+
<tbody {...api.getTableBodyProps({ view: "day" })}>
|
|
164
|
+
{/* Keyed by the day, not by the object: Zag hands out new dates on every
|
|
165
|
+
change, and a cell made anew would drop the focus it holds when a move is
|
|
166
|
+
held at `min` or `max`. */}
|
|
167
|
+
{api.weeks.map((week) => (
|
|
168
|
+
<tr key={week[0]?.toString()} {...api.getTableRowProps({ view: "day" })}>
|
|
169
|
+
{week.map((date) => (
|
|
170
|
+
<td
|
|
171
|
+
key={date.toString()}
|
|
172
|
+
{...api.getDayTableCellProps({ value: date })}
|
|
173
|
+
className="{{prefix}}-date-picker__cell"
|
|
174
|
+
>
|
|
175
|
+
<div
|
|
176
|
+
{...api.getDayTableCellTriggerProps({ value: date })}
|
|
177
|
+
className="{{prefix}}-date-picker__day"
|
|
178
|
+
>
|
|
179
|
+
{date.day}
|
|
180
|
+
</div>
|
|
181
|
+
</td>
|
|
182
|
+
))}
|
|
183
|
+
</tr>
|
|
184
|
+
))}
|
|
185
|
+
</tbody>
|
|
186
|
+
</table>
|
|
187
|
+
</div>
|
|
188
|
+
</div>
|
|
189
|
+
</Portal>
|
|
190
|
+
</div>
|
|
191
|
+
);
|
|
192
|
+
}
|
|
@@ -0,0 +1,271 @@
|
|
|
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 { Portal, type RootProps, useModalPopover, usePresence } from "@xds/react/base";
|
|
5
|
+
import * as datePicker from "@zag-js/date-picker";
|
|
6
|
+
import { mergeProps, normalizeProps, useMachine } from "@zag-js/react";
|
|
7
|
+
import { type MouseEvent, useEffect, useId, useRef, useState } from "react";
|
|
8
|
+
import {
|
|
9
|
+
DATE_PICKER_NAV_CLASS,
|
|
10
|
+
datePickerContentAttrs,
|
|
11
|
+
datePickerIds,
|
|
12
|
+
datePickerLocale,
|
|
13
|
+
datePickerTriggerAttrs,
|
|
14
|
+
focusOpeningDay,
|
|
15
|
+
keepCalendarFocus,
|
|
16
|
+
keepDayFocused,
|
|
17
|
+
} from "./date-picker.ts";
|
|
18
|
+
import {
|
|
19
|
+
type DateRange,
|
|
20
|
+
type DateRangePickerBaseProps,
|
|
21
|
+
dateRangeMachineProps,
|
|
22
|
+
endRangeChoiceOnClose,
|
|
23
|
+
formatRange,
|
|
24
|
+
keepRangePreview,
|
|
25
|
+
type RangeDraft,
|
|
26
|
+
rangeDayClick,
|
|
27
|
+
rangeGridKeyDown,
|
|
28
|
+
rangeMonths,
|
|
29
|
+
rangeMonthViews,
|
|
30
|
+
rangeSummary,
|
|
31
|
+
shownRange,
|
|
32
|
+
} from "./date-range-picker.ts";
|
|
33
|
+
import { Icon } from "./Icon.tsx";
|
|
34
|
+
import { classes } from "./parts.ts";
|
|
35
|
+
|
|
36
|
+
export type { DateRange } from "./date-range-picker.ts";
|
|
37
|
+
|
|
38
|
+
export type DateRangePickerProps = DateRangePickerBaseProps &
|
|
39
|
+
RootProps & {
|
|
40
|
+
onChange: (value: DateRange) => void;
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* A field for choosing a range of days, a start and an end, as for a stay. Closed, it looks like
|
|
45
|
+
* a DatePicker and shows both days in the locale's medium form ("Mar 10 – 14, 2026"), or the
|
|
46
|
+
* placeholder. Pressed, it opens a calendar under itself, two months side by side where the
|
|
47
|
+
* window has room and one where it does not, on the start's month, or on today's while nothing
|
|
48
|
+
* is chosen.
|
|
49
|
+
*
|
|
50
|
+
* The first day pressed starts the range, and the band previews it to the day under the pointer
|
|
51
|
+
* or the keyboard's focus. The second ends it, if the days between are at least `minLength` and
|
|
52
|
+
* at most `maxLength`, which leave the other days unavailable meanwhile: `onChange` gets the
|
|
53
|
+
* range and the calendar closes. A day before the start starts again from there. Escape or a
|
|
54
|
+
* press outside closes the calendar without a change.
|
|
55
|
+
*
|
|
56
|
+
* The keys are DatePicker's, and Page Up and Page Down move a month whether one or two are
|
|
57
|
+
* shown. Each month is a grid named by its month; every day of the range is selected, and the
|
|
58
|
+
* two ends are named by `startLabel` and `endLabel` before the day.
|
|
59
|
+
*/
|
|
60
|
+
export function DateRangePicker({ onChange, className, style, ...props }: DateRangePickerProps) {
|
|
61
|
+
const { label, value, placeholder, description, error, startName, endName } = props;
|
|
62
|
+
const id = useId();
|
|
63
|
+
const ids = datePickerIds(id);
|
|
64
|
+
const locale = datePickerLocale();
|
|
65
|
+
// A start alone while the end is chosen; null while the calendar shows the chosen range.
|
|
66
|
+
const [draft, setDraft] = useState<RangeDraft | null>(null);
|
|
67
|
+
const [months, setMonths] = useState(1);
|
|
68
|
+
const shown = shownRange(value, draft);
|
|
69
|
+
const service = useMachine(
|
|
70
|
+
datePicker.machine,
|
|
71
|
+
dateRangeMachineProps(props, shown, { id, locale, months, onDraft: setDraft, onChange }),
|
|
72
|
+
);
|
|
73
|
+
const api = datePicker.connect(service, normalizeProps);
|
|
74
|
+
const trigger = api.getTriggerProps();
|
|
75
|
+
const positioner = useRef<HTMLDivElement>(null);
|
|
76
|
+
const surface = useRef<HTMLDivElement>(null);
|
|
77
|
+
useModalPopover(api.open, () => positioner.current);
|
|
78
|
+
const present = usePresence(api.open, () => [surface.current]);
|
|
79
|
+
const focused = api.focusedValue.toString();
|
|
80
|
+
const month = api.visibleRange.start.toString();
|
|
81
|
+
useEffect(() => keepDayFocused(api.open, surface.current), [api.open, focused, month]);
|
|
82
|
+
// oxlint-disable-next-line react/exhaustive-deps -- only as the calendar opens or closes
|
|
83
|
+
useEffect(() => endRangeChoiceOnClose(service, api.open), [api.open]);
|
|
84
|
+
// oxlint-disable-next-line react/exhaustive-deps -- only once the focused day has moved
|
|
85
|
+
useEffect(() => keepRangePreview(service, shown, api.open), [focused]);
|
|
86
|
+
const summary = rangeSummary(shown, props, locale);
|
|
87
|
+
const invalid = error !== undefined;
|
|
88
|
+
return (
|
|
89
|
+
<div
|
|
90
|
+
{...mergeProps(api.getRootProps(), {
|
|
91
|
+
className: classes("{{prefix}}-date-picker {{prefix}}-date-range-picker", className),
|
|
92
|
+
style,
|
|
93
|
+
})}
|
|
94
|
+
>
|
|
95
|
+
{/* A span: the field is a button, which a <label> cannot point at. */}
|
|
96
|
+
<span id={ids.label} className="{{prefix}}-date-picker__label">
|
|
97
|
+
{label}
|
|
98
|
+
</span>
|
|
99
|
+
{/* What Zag places the calendar against. */}
|
|
100
|
+
<div {...api.getControlProps()} className="{{prefix}}-date-picker__control">
|
|
101
|
+
<button
|
|
102
|
+
{...trigger}
|
|
103
|
+
{...datePickerTriggerAttrs(props, ids)}
|
|
104
|
+
type="button"
|
|
105
|
+
onClick={(event: MouseEvent<HTMLButtonElement>) => {
|
|
106
|
+
if (!api.open) setMonths(rangeMonths());
|
|
107
|
+
focusOpeningDay(api, { ...props, value: value?.start });
|
|
108
|
+
trigger.onClick?.(event);
|
|
109
|
+
}}
|
|
110
|
+
className="{{prefix}}-date-picker__trigger"
|
|
111
|
+
>
|
|
112
|
+
<span id={ids.value} className="{{prefix}}-date-picker__value">
|
|
113
|
+
{value === undefined ? placeholder : formatRange(value, locale)}
|
|
114
|
+
</span>
|
|
115
|
+
<Icon name="calendar" size="sm" className="text-xds-field-placeholder" />
|
|
116
|
+
</button>
|
|
117
|
+
</div>
|
|
118
|
+
{/* One line under the box: the help, or the error in its place. */}
|
|
119
|
+
{(invalid || description) && (
|
|
120
|
+
<div className="{{prefix}}-date-picker__footer">
|
|
121
|
+
{invalid ? (
|
|
122
|
+
<span id={ids.error} className="{{prefix}}-date-picker__error">
|
|
123
|
+
{error}
|
|
124
|
+
</span>
|
|
125
|
+
) : (
|
|
126
|
+
<span id={ids.description} className="{{prefix}}-date-picker__description">
|
|
127
|
+
{description}
|
|
128
|
+
</span>
|
|
129
|
+
)}
|
|
130
|
+
</div>
|
|
131
|
+
)}
|
|
132
|
+
{/* What a form submits. Zag gives the names to its text inputs, which are not drawn. */}
|
|
133
|
+
{startName !== undefined && (
|
|
134
|
+
<input type="hidden" name={startName} value={value?.start ?? ""} />
|
|
135
|
+
)}
|
|
136
|
+
{endName !== undefined && <input type="hidden" name={endName} value={value?.end ?? ""} />}
|
|
137
|
+
<Portal>
|
|
138
|
+
{api.open && (
|
|
139
|
+
// Takes a press outside, which then only closes the calendar. The focus stays in the
|
|
140
|
+
// calendar until it hands it back to the field.
|
|
141
|
+
// oxlint-disable-next-line jsx-a11y/no-static-element-interactions -- not a control: the handler only keeps the focus where it is
|
|
142
|
+
<div
|
|
143
|
+
className="{{prefix}}-date-picker__underlay"
|
|
144
|
+
onMouseDown={(event) => event.preventDefault()}
|
|
145
|
+
/>
|
|
146
|
+
)}
|
|
147
|
+
<div
|
|
148
|
+
{...api.getPositionerProps()}
|
|
149
|
+
ref={positioner}
|
|
150
|
+
className="{{prefix}}-date-picker__positioner"
|
|
151
|
+
>
|
|
152
|
+
{/* Shown until its exit animation ends; Zag would hide it as it closes. */}
|
|
153
|
+
{/* oxlint-disable-next-line jsx-a11y/no-static-element-interactions -- a dialog: datePickerContentAttrs gives it the role */}
|
|
154
|
+
<div
|
|
155
|
+
{...api.getContentProps()}
|
|
156
|
+
{...datePickerContentAttrs(ids)}
|
|
157
|
+
ref={surface}
|
|
158
|
+
hidden={!present}
|
|
159
|
+
onKeyDown={(event) => keepCalendarFocus(event, surface.current)}
|
|
160
|
+
className="{{prefix}}-date-picker__content {{prefix}}-date-range-picker__content"
|
|
161
|
+
>
|
|
162
|
+
<div className="{{prefix}}-date-range-picker__summary" aria-live="polite">
|
|
163
|
+
<span>{summary.start}</span>
|
|
164
|
+
<span>{summary.end}</span>
|
|
165
|
+
</div>
|
|
166
|
+
<div className="{{prefix}}-date-range-picker__months">
|
|
167
|
+
{rangeMonthViews(api, months).map((view) => {
|
|
168
|
+
const table = api.getTableProps({ view: "day", id: view.table.id });
|
|
169
|
+
return (
|
|
170
|
+
<div key={view.index} className="{{prefix}}-date-range-picker__month">
|
|
171
|
+
<div className="{{prefix}}-date-picker__header">
|
|
172
|
+
{view.index === 0 ? (
|
|
173
|
+
<button
|
|
174
|
+
{...api.getPreviousTriggerProps()}
|
|
175
|
+
type="button"
|
|
176
|
+
className={DATE_PICKER_NAV_CLASS}
|
|
177
|
+
>
|
|
178
|
+
<Icon name="chevron-left" size="sm" />
|
|
179
|
+
</button>
|
|
180
|
+
) : (
|
|
181
|
+
<span className="{{prefix}}-date-range-picker__nav-space" />
|
|
182
|
+
)}
|
|
183
|
+
<span
|
|
184
|
+
{...api.getRangeTextProps()}
|
|
185
|
+
className="{{prefix}}-date-picker__heading"
|
|
186
|
+
>
|
|
187
|
+
{view.name}
|
|
188
|
+
</span>
|
|
189
|
+
{view.index === months - 1 ? (
|
|
190
|
+
<button
|
|
191
|
+
{...api.getNextTriggerProps()}
|
|
192
|
+
type="button"
|
|
193
|
+
className={DATE_PICKER_NAV_CLASS}
|
|
194
|
+
>
|
|
195
|
+
<Icon name="chevron-right" size="sm" />
|
|
196
|
+
</button>
|
|
197
|
+
) : (
|
|
198
|
+
<span className="{{prefix}}-date-range-picker__nav-space" />
|
|
199
|
+
)}
|
|
200
|
+
</div>
|
|
201
|
+
{/* oxlint-disable-next-line jsx-a11y/no-noninteractive-element-interactions -- a grid: Zag's props give it the role, and Enter on a day before the start is handled first */}
|
|
202
|
+
<table
|
|
203
|
+
{...table}
|
|
204
|
+
{...view.table}
|
|
205
|
+
onKeyDown={(event) =>
|
|
206
|
+
rangeGridKeyDown(event, api, shown, props, table.onKeyDown)
|
|
207
|
+
}
|
|
208
|
+
className="{{prefix}}-date-picker__grid"
|
|
209
|
+
>
|
|
210
|
+
<thead {...api.getTableHeadProps({ view: "day" })}>
|
|
211
|
+
<tr {...api.getTableRowProps({ view: "day" })}>
|
|
212
|
+
{api.weekDays.map((weekDay) => (
|
|
213
|
+
<th
|
|
214
|
+
key={weekDay.long}
|
|
215
|
+
scope="col"
|
|
216
|
+
className="{{prefix}}-date-picker__weekday"
|
|
217
|
+
>
|
|
218
|
+
{weekDay.narrow}
|
|
219
|
+
</th>
|
|
220
|
+
))}
|
|
221
|
+
</tr>
|
|
222
|
+
</thead>
|
|
223
|
+
<tbody {...api.getTableBodyProps({ view: "day" })}>
|
|
224
|
+
{/* Keyed by the day, as in DatePicker: a cell made anew would drop the
|
|
225
|
+
focus it holds when a move is held at `min` or `max`. */}
|
|
226
|
+
{view.weeks.map((week) => (
|
|
227
|
+
<tr key={week[0]?.toString()} {...api.getTableRowProps({ view: "day" })}>
|
|
228
|
+
{week.map((date) => {
|
|
229
|
+
const cell = { value: date, visibleRange: view.visibleRange };
|
|
230
|
+
const day = api.getDayTableCellTriggerProps(cell);
|
|
231
|
+
return (
|
|
232
|
+
<td
|
|
233
|
+
key={date.toString()}
|
|
234
|
+
{...api.getDayTableCellProps(cell)}
|
|
235
|
+
className="{{prefix}}-date-picker__cell"
|
|
236
|
+
>
|
|
237
|
+
{/* oxlint-disable-next-line jsx-a11y/click-events-have-key-events, jsx-a11y/no-static-element-interactions -- a button: Zag's props give it the role, and its grid takes the keys */}
|
|
238
|
+
<div
|
|
239
|
+
{...day}
|
|
240
|
+
onClick={(event) =>
|
|
241
|
+
rangeDayClick(
|
|
242
|
+
event,
|
|
243
|
+
api,
|
|
244
|
+
shown,
|
|
245
|
+
props,
|
|
246
|
+
date,
|
|
247
|
+
view.visibleRange,
|
|
248
|
+
day.onClick,
|
|
249
|
+
)
|
|
250
|
+
}
|
|
251
|
+
className="{{prefix}}-date-picker__day"
|
|
252
|
+
>
|
|
253
|
+
{date.day}
|
|
254
|
+
</div>
|
|
255
|
+
</td>
|
|
256
|
+
);
|
|
257
|
+
})}
|
|
258
|
+
</tr>
|
|
259
|
+
))}
|
|
260
|
+
</tbody>
|
|
261
|
+
</table>
|
|
262
|
+
</div>
|
|
263
|
+
);
|
|
264
|
+
})}
|
|
265
|
+
</div>
|
|
266
|
+
</div>
|
|
267
|
+
</div>
|
|
268
|
+
</Portal>
|
|
269
|
+
</div>
|
|
270
|
+
);
|
|
271
|
+
}
|
|
@@ -0,0 +1,108 @@
|
|
|
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
|
+
leaveEscapeToFields,
|
|
6
|
+
Portal,
|
|
7
|
+
type RootProps,
|
|
8
|
+
TriggerContext,
|
|
9
|
+
usePresence,
|
|
10
|
+
} from "@xds/react/base";
|
|
11
|
+
import * as dialog from "@zag-js/dialog";
|
|
12
|
+
import { mergeProps, normalizeProps, useMachine } from "@zag-js/react";
|
|
13
|
+
import { type ReactNode, useId, useRef } from "react";
|
|
14
|
+
import type { DialogBaseProps } from "./dialog.ts";
|
|
15
|
+
import { classes } from "./parts.ts";
|
|
16
|
+
|
|
17
|
+
/** `className` and `style` are for the dialog's panel, not for the backdrop around it. */
|
|
18
|
+
export type DialogProps = DialogBaseProps &
|
|
19
|
+
RootProps & {
|
|
20
|
+
/** Called on Escape and on a press outside the dialog. Set `open` to false in it. */
|
|
21
|
+
onClose: () => void;
|
|
22
|
+
/** The body, between the description and the actions. It scrolls when it is too tall. */
|
|
23
|
+
children?: ReactNode;
|
|
24
|
+
/** Buttons, in a row at the end edge. Put the main action last. */
|
|
25
|
+
actions?: ReactNode;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* A window that interrupts the screen for a confirmation or a short task. Everything behind it
|
|
30
|
+
* is dimmed and cannot be reached until it closes.
|
|
31
|
+
*
|
|
32
|
+
* It is a modal dialog named by its title and described by its description. Focus moves into
|
|
33
|
+
* it, stays inside it, and returns to where it was when it closes.
|
|
34
|
+
*/
|
|
35
|
+
export function Dialog({
|
|
36
|
+
open,
|
|
37
|
+
onClose,
|
|
38
|
+
title,
|
|
39
|
+
description,
|
|
40
|
+
children,
|
|
41
|
+
actions,
|
|
42
|
+
dismissible = true,
|
|
43
|
+
className,
|
|
44
|
+
style,
|
|
45
|
+
}: DialogProps) {
|
|
46
|
+
const backdrop = useRef<HTMLDivElement>(null);
|
|
47
|
+
const positioner = useRef<HTMLDivElement>(null);
|
|
48
|
+
const content = useRef<HTMLElement>(null);
|
|
49
|
+
const service = useMachine(dialog.machine, {
|
|
50
|
+
id: useId(),
|
|
51
|
+
open,
|
|
52
|
+
onOpenChange: (details) => {
|
|
53
|
+
if (!details.open) onClose();
|
|
54
|
+
},
|
|
55
|
+
closeOnEscape: dismissible,
|
|
56
|
+
closeOnInteractOutside: dismissible,
|
|
57
|
+
onEscapeKeyDown: leaveEscapeToFields,
|
|
58
|
+
// The dialog itself rather than its first field or button: a screen reader then reads the
|
|
59
|
+
// title and the description first.
|
|
60
|
+
initialFocusEl: () => content.current,
|
|
61
|
+
});
|
|
62
|
+
const api = dialog.connect(service, normalizeProps);
|
|
63
|
+
const present = usePresence(api.open, () => [backdrop.current, positioner.current]);
|
|
64
|
+
if (!present) return null;
|
|
65
|
+
return (
|
|
66
|
+
<Portal>
|
|
67
|
+
{/* Nothing inside opens an overlay from a control outside it. */}
|
|
68
|
+
<TriggerContext value={null}>
|
|
69
|
+
{/* A press on the scrim keeps the focus in the dialog: a dialog that cannot be dismissed
|
|
70
|
+
stays open, and the focus would go to the page. The backdrop and the dialog stay
|
|
71
|
+
shown until their exit animation ends; Zag would hide them as the dialog closes. */}
|
|
72
|
+
{/* oxlint-disable-next-line jsx-a11y/no-static-element-interactions -- not a control: the handler only keeps the focus where it is */}
|
|
73
|
+
<div
|
|
74
|
+
{...api.getBackdropProps()}
|
|
75
|
+
ref={backdrop}
|
|
76
|
+
hidden={false}
|
|
77
|
+
onMouseDown={(event) => event.preventDefault()}
|
|
78
|
+
className="{{prefix}}-dialog__backdrop"
|
|
79
|
+
/>
|
|
80
|
+
<div
|
|
81
|
+
{...api.getPositionerProps()}
|
|
82
|
+
ref={positioner}
|
|
83
|
+
className="{{prefix}}-dialog__positioner"
|
|
84
|
+
>
|
|
85
|
+
<section
|
|
86
|
+
{...mergeProps(api.getContentProps(), {
|
|
87
|
+
className: classes("{{prefix}}-dialog", className),
|
|
88
|
+
style,
|
|
89
|
+
})}
|
|
90
|
+
ref={content}
|
|
91
|
+
hidden={false}
|
|
92
|
+
>
|
|
93
|
+
<h2 {...api.getTitleProps()} className="{{prefix}}-dialog__title">
|
|
94
|
+
{title}
|
|
95
|
+
</h2>
|
|
96
|
+
{description && (
|
|
97
|
+
<p {...api.getDescriptionProps()} className="{{prefix}}-dialog__description">
|
|
98
|
+
{description}
|
|
99
|
+
</p>
|
|
100
|
+
)}
|
|
101
|
+
{children != null && <div className="{{prefix}}-dialog__body">{children}</div>}
|
|
102
|
+
{actions != null && <div className="{{prefix}}-dialog__actions">{actions}</div>}
|
|
103
|
+
</section>
|
|
104
|
+
</div>
|
|
105
|
+
</TriggerContext>
|
|
106
|
+
</Portal>
|
|
107
|
+
);
|
|
108
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
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 { dividerClass } from "./divider.ts";
|
|
6
|
+
import { classes, rootPart } from "./parts.ts";
|
|
7
|
+
|
|
8
|
+
export type DividerProps = RootProps;
|
|
9
|
+
|
|
10
|
+
/** A line between groups of content. Decorative lines use the low-contrast border color. */
|
|
11
|
+
export function Divider({ className, style }: DividerProps) {
|
|
12
|
+
return <hr className={classes(rootPart("Divider"), dividerClass, className)} style={style} />;
|
|
13
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
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 { EMPTY_STATE_PARTS, type EmptyStateBaseProps } from "./empty-state.ts";
|
|
7
|
+
import { Icon } from "./Icon.tsx";
|
|
8
|
+
import { classes, rootPart } from "./parts.ts";
|
|
9
|
+
|
|
10
|
+
export type EmptyStateProps = EmptyStateBaseProps &
|
|
11
|
+
RootProps & {
|
|
12
|
+
/** The one thing to do about it, usually a Button. */
|
|
13
|
+
action?: ReactNode;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* What a screen or a list says when it has nothing to show. It centers itself in its container,
|
|
18
|
+
* also vertically when the container is a flex box with room to spare.
|
|
19
|
+
*/
|
|
20
|
+
export function EmptyState({
|
|
21
|
+
icon,
|
|
22
|
+
title,
|
|
23
|
+
description,
|
|
24
|
+
action,
|
|
25
|
+
className,
|
|
26
|
+
style,
|
|
27
|
+
}: EmptyStateProps) {
|
|
28
|
+
return (
|
|
29
|
+
<div
|
|
30
|
+
className={classes(rootPart("EmptyState"), EMPTY_STATE_PARTS.root, className)}
|
|
31
|
+
style={style}
|
|
32
|
+
>
|
|
33
|
+
<Icon name={icon} size="xl" className={EMPTY_STATE_PARTS.icon} />
|
|
34
|
+
<p className={EMPTY_STATE_PARTS.title}>{title}</p>
|
|
35
|
+
{description && <p className={EMPTY_STATE_PARTS.description}>{description}</p>}
|
|
36
|
+
{action != null && <div className={EMPTY_STATE_PARTS.action}>{action}</div>}
|
|
37
|
+
</div>
|
|
38
|
+
);
|
|
39
|
+
}
|