@xds/react 0.1.0 → 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/dist/Accordion.js +191 -33
- package/dist/Avatar.js +65 -6
- package/dist/AvatarStack.js +101 -6
- package/dist/Badge.js +61 -4
- package/dist/Banner.js +161 -5
- package/dist/Button.js +152 -24
- package/dist/Card.js +171 -12
- package/dist/Checkbox.js +138 -3
- package/dist/Chip.js +71 -4
- package/dist/ChipBar.js +36 -3
- package/dist/CountBadge.js +62 -9
- package/dist/DatePicker.js +421 -25
- package/dist/DateRangePicker.js +362 -40
- package/dist/Defaults.js +42 -7
- package/dist/Dialog.js +128 -24
- package/dist/Divider.js +29 -3
- package/dist/EmptyState.js +83 -3
- package/dist/Icon.js +74 -4
- package/dist/IconButton.js +113 -18
- package/dist/ListRow.js +180 -10
- package/dist/MediaCard.js +273 -11
- package/dist/Menu.js +234 -58
- package/dist/ProgressBar.js +63 -4
- package/dist/RadioGroup.js +173 -12
- package/dist/SearchField.js +148 -16
- package/dist/SectionHeader.js +121 -5
- package/dist/SegmentedControl.js +104 -5
- package/dist/Select.js +307 -55
- package/dist/Sidebar.js +212 -19
- package/dist/Skeleton.js +61 -5
- package/dist/Slider.js +142 -35
- package/dist/Spinner.js +93 -4
- package/dist/Switch.js +114 -3
- package/dist/Tabs.js +130 -14
- package/dist/Text.js +42 -4
- package/dist/TextField.js +209 -26
- package/dist/Thumbnail.js +146 -7
- package/dist/Toast.js +118 -30
- package/dist/Tooltip.js +154 -20
- package/dist/base.d.ts +11 -0
- package/dist/base.js +10 -0
- package/dist/modal-popover.js +32 -10
- package/dist/picture.d.ts +6 -4
- package/dist/picture.js +72 -17
- package/dist/portal.js +24 -4
- package/dist/presence.js +30 -9
- package/dist/preview.d.ts +14 -3
- package/dist/preview.js +118 -74
- package/dist/root.js +1 -0
- package/dist/trigger.d.ts +7 -0
- package/dist/trigger.js +41 -8
- 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 +9 -4
|
@@ -0,0 +1,323 @@
|
|
|
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 { space } from "@xds/react/base";
|
|
5
|
+
import { type DateValue, getLocalTimeZone, parseDate } from "@internationalized/date";
|
|
6
|
+
import type * as datePicker from "@zag-js/date-picker";
|
|
7
|
+
import {
|
|
8
|
+
type DatePickerBaseProps,
|
|
9
|
+
datePickerTranslations,
|
|
10
|
+
formatDay,
|
|
11
|
+
type IsoDate,
|
|
12
|
+
openingDay,
|
|
13
|
+
} from "./date-picker.ts";
|
|
14
|
+
|
|
15
|
+
/** The first and the last day of a range, both chosen, `start` no later than `end`. */
|
|
16
|
+
export type DateRange = { start: IsoDate; end: IsoDate };
|
|
17
|
+
|
|
18
|
+
/** DateRangePicker's props in every framework, short of `onChange`. */
|
|
19
|
+
export type DateRangePickerBaseProps = Omit<DatePickerBaseProps, "value" | "name"> & {
|
|
20
|
+
/** The chosen range. Leave it out while none is chosen. */
|
|
21
|
+
value?: DateRange | undefined;
|
|
22
|
+
/**
|
|
23
|
+
* The fewest days the end can be after the start: the nights of a stay. 0, the default, lets
|
|
24
|
+
* the start be the end too, a range of one day.
|
|
25
|
+
*/
|
|
26
|
+
minLength?: number | undefined;
|
|
27
|
+
/** The most days the end can be after the start. No limit unless it is given. */
|
|
28
|
+
maxLength?: number | undefined;
|
|
29
|
+
/** The name the first day is submitted under with a form, as `YYYY-MM-DD`. */
|
|
30
|
+
startName?: string;
|
|
31
|
+
/** The name the last day is submitted under with a form, as `YYYY-MM-DD`. */
|
|
32
|
+
endName?: string;
|
|
33
|
+
/** Names the first day in the calendar's summary and for assistive technology. */
|
|
34
|
+
startLabel?: string;
|
|
35
|
+
/** Names the last day, as `startLabel` does the first. */
|
|
36
|
+
endLabel?: string;
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* What the calendar shows while it is open: the chosen range as its two days, or the start
|
|
41
|
+
* alone while the end is being chosen, or nothing.
|
|
42
|
+
*/
|
|
43
|
+
export type RangeDraft = readonly IsoDate[];
|
|
44
|
+
|
|
45
|
+
/** Whole days from `from` to `to`, negative when `to` is earlier: the nights between them. */
|
|
46
|
+
export function daysBetween(from: IsoDate, to: IsoDate): number {
|
|
47
|
+
return Math.round((Date.parse(`${to}T00:00:00Z`) - Date.parse(`${from}T00:00:00Z`)) / 86_400_000);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* What a press on `day` does to `draft`. With nothing, or with a whole range, it starts a new
|
|
52
|
+
* range. With a start alone, a day before it starts again from there, as Material's and the
|
|
53
|
+
* booking sites' calendars do, where a library would swap the two; a day the length allows ends
|
|
54
|
+
* the range; any other day does nothing.
|
|
55
|
+
*/
|
|
56
|
+
export function rangeDayChoice(
|
|
57
|
+
draft: RangeDraft,
|
|
58
|
+
day: IsoDate,
|
|
59
|
+
props: Pick<DateRangePickerBaseProps, "minLength" | "maxLength">,
|
|
60
|
+
): "start" | "end" | "none" {
|
|
61
|
+
const [start] = draft;
|
|
62
|
+
if (draft.length !== 1 || start === undefined) return "start";
|
|
63
|
+
const length = daysBetween(start, day);
|
|
64
|
+
if (length < 0) return "start";
|
|
65
|
+
if (length < (props.minLength ?? 0)) return "none";
|
|
66
|
+
if (props.maxLength !== undefined && length > props.maxLength) return "none";
|
|
67
|
+
return "end";
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* The range as the field shows it, in the locale's medium form, with what the two days share
|
|
72
|
+
* said once: "Mar 10 – 14, 2026", "2026. 3. 10. ~ 14.". Read at noon UTC and formatted in UTC,
|
|
73
|
+
* as `formatDay` does.
|
|
74
|
+
*/
|
|
75
|
+
export function formatRange(value: DateRange, locale: string): string {
|
|
76
|
+
return new Intl.DateTimeFormat(locale, { dateStyle: "medium", timeZone: "UTC" }).formatRange(
|
|
77
|
+
new Date(`${value.start}T12:00:00Z`),
|
|
78
|
+
new Date(`${value.end}T12:00:00Z`),
|
|
79
|
+
);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/** The days the calendar shows: the draft while there is one, otherwise the chosen range. */
|
|
83
|
+
export function shownRange(value: DateRange | undefined, draft: RangeDraft | null): RangeDraft {
|
|
84
|
+
return draft ?? (value === undefined ? [] : [value.start, value.end]);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* How many months the calendar shows side by side, read as it opens: two where the window has
|
|
89
|
+
* room for them (40rem, about 640 px), one where it does not.
|
|
90
|
+
*/
|
|
91
|
+
export function rangeMonths(): 1 | 2 {
|
|
92
|
+
return typeof matchMedia === "function" && matchMedia("(min-width: 40rem)").matches ? 2 : 1;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* The props of Zag's date-picker machine in range mode for a DateRangePicker. Zag's value is
|
|
97
|
+
* `shown`, not the chosen range: Zag reports the first press as a value of one day, which an
|
|
98
|
+
* owner that keeps the chosen range would put back, so the start would never show. `onDraft`
|
|
99
|
+
* keeps the start alone, and `onChange` gets the range once the end is chosen. While the start
|
|
100
|
+
* is alone, the days the length does not allow as its end are unavailable; the days before it
|
|
101
|
+
* stay available, since a press on one starts again (see `restartRange`).
|
|
102
|
+
*/
|
|
103
|
+
export function dateRangeMachineProps(
|
|
104
|
+
props: DateRangePickerBaseProps,
|
|
105
|
+
shown: RangeDraft,
|
|
106
|
+
options: {
|
|
107
|
+
id: string;
|
|
108
|
+
locale: string;
|
|
109
|
+
months: number;
|
|
110
|
+
onDraft: (draft: RangeDraft | null) => void;
|
|
111
|
+
onChange: (value: DateRange) => void;
|
|
112
|
+
},
|
|
113
|
+
): datePicker.Props {
|
|
114
|
+
const day = (value: IsoDate | undefined) => (value === undefined ? undefined : parseDate(value));
|
|
115
|
+
const [first] = shown;
|
|
116
|
+
return {
|
|
117
|
+
id: options.id,
|
|
118
|
+
locale: options.locale,
|
|
119
|
+
timeZone: getLocalTimeZone(),
|
|
120
|
+
selectionMode: "range",
|
|
121
|
+
numOfMonths: options.months,
|
|
122
|
+
value: shown.map((value) => parseDate(value)),
|
|
123
|
+
min: day(props.min),
|
|
124
|
+
max: day(props.max),
|
|
125
|
+
defaultFocusedValue: parseDate(openingDay({ ...props, value: props.value?.start })),
|
|
126
|
+
isDateUnavailable: (date: DateValue) =>
|
|
127
|
+
shown.length === 1 &&
|
|
128
|
+
first !== undefined &&
|
|
129
|
+
daysBetween(first, date.toString()) >= 0 &&
|
|
130
|
+
rangeDayChoice(shown, date.toString(), props) === "none",
|
|
131
|
+
onValueChange: (details) => {
|
|
132
|
+
const [start, end] = details.value.map((date) => date.toString());
|
|
133
|
+
if (start !== undefined && end !== undefined) {
|
|
134
|
+
options.onDraft(null);
|
|
135
|
+
options.onChange({ start, end });
|
|
136
|
+
} else if (start !== undefined) options.onDraft([start]);
|
|
137
|
+
},
|
|
138
|
+
// A start alone is dropped with the calendar: the field still shows the chosen range.
|
|
139
|
+
onOpenChange: (details) => {
|
|
140
|
+
if (!details.open) options.onDraft(null);
|
|
141
|
+
},
|
|
142
|
+
disabled: props.disabled,
|
|
143
|
+
invalid: props.error !== undefined,
|
|
144
|
+
outsideDaySelectable: false,
|
|
145
|
+
minView: "day",
|
|
146
|
+
maxView: "day",
|
|
147
|
+
positioning: { placement: "bottom-start", gutter: space[1] },
|
|
148
|
+
translations: dateRangeTranslations(props),
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* DatePicker's strings, with the two ends named by `startLabel` and `endLabel` ahead of the
|
|
154
|
+
* day: "Check-in, Tuesday, March 10, 2026". A range of one day is both.
|
|
155
|
+
*/
|
|
156
|
+
export function dateRangeTranslations(
|
|
157
|
+
props: Pick<DateRangePickerBaseProps, "previousLabel" | "nextLabel" | "startLabel" | "endLabel">,
|
|
158
|
+
): datePicker.IntlTranslations {
|
|
159
|
+
const start = props.startLabel ?? "Start";
|
|
160
|
+
const end = props.endLabel ?? "End";
|
|
161
|
+
return {
|
|
162
|
+
...datePickerTranslations(props),
|
|
163
|
+
dayCell: (state) =>
|
|
164
|
+
[state.firstInRange && start, state.lastInRange && end, state.valueText]
|
|
165
|
+
.filter(Boolean)
|
|
166
|
+
.join(", "),
|
|
167
|
+
};
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
/**
|
|
171
|
+
* The summary above the months: each end after its label, or a dash until it is chosen.
|
|
172
|
+
* "Check-in: Mar 20, 2026", "Check-out: –".
|
|
173
|
+
*/
|
|
174
|
+
export function rangeSummary(
|
|
175
|
+
shown: RangeDraft,
|
|
176
|
+
props: Pick<DateRangePickerBaseProps, "startLabel" | "endLabel">,
|
|
177
|
+
locale: string,
|
|
178
|
+
): { start: string; end: string } {
|
|
179
|
+
const [start, end] = shown;
|
|
180
|
+
const day = (value: IsoDate | undefined) =>
|
|
181
|
+
value === undefined ? "–" : formatDay(value, locale);
|
|
182
|
+
return {
|
|
183
|
+
start: `${props.startLabel ?? "Start"}: ${day(start)}`,
|
|
184
|
+
end: `${props.endLabel ?? "End"}: ${day(end)}`,
|
|
185
|
+
};
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
/** One month of the calendar: its grid's name, its weeks, and the days that are its own. */
|
|
189
|
+
export type RangeMonth = {
|
|
190
|
+
index: number;
|
|
191
|
+
name: string;
|
|
192
|
+
weeks: DateValue[][];
|
|
193
|
+
/** Passed to the props of its cells: Zag counts every month shown as visible. */
|
|
194
|
+
visibleRange: { start: DateValue; end: DateValue };
|
|
195
|
+
/** The props of its grid, after Zag's. */
|
|
196
|
+
table: { id: string; "aria-label": string };
|
|
197
|
+
};
|
|
198
|
+
|
|
199
|
+
/**
|
|
200
|
+
* The months the calendar shows, side by side. Each is a grid of its own, named by its month,
|
|
201
|
+
* where Zag names every grid by all the months shown ("March – April 2026"). Its cells take its
|
|
202
|
+
* own month as the visible range, so that the days of the next month in its last row are drawn
|
|
203
|
+
* as outside, and hidden, rather than as days of the next month shown.
|
|
204
|
+
*/
|
|
205
|
+
export function rangeMonthViews(
|
|
206
|
+
api: Pick<datePicker.Api, "getOffset">,
|
|
207
|
+
months: number,
|
|
208
|
+
): RangeMonth[] {
|
|
209
|
+
return Array.from({ length: months }, (_, index) => {
|
|
210
|
+
const offset = api.getOffset({ months: index });
|
|
211
|
+
const start = offset.visibleRange.start;
|
|
212
|
+
return {
|
|
213
|
+
index,
|
|
214
|
+
name: offset.visibleRangeText.start,
|
|
215
|
+
weeks: offset.weeks,
|
|
216
|
+
visibleRange: { start, end: start.add({ months: 1 }).subtract({ days: 1 }) },
|
|
217
|
+
table: { id: `month-${index}`, "aria-label": offset.visibleRangeText.start },
|
|
218
|
+
};
|
|
219
|
+
});
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
type RangeApi = Pick<datePicker.Api, "focusedValue" | "getDayTableCellState" | "setValue">;
|
|
223
|
+
|
|
224
|
+
/**
|
|
225
|
+
* A press on a day before the start, while the end is being chosen, starts again from there:
|
|
226
|
+
* it becomes the start alone. Zag would make it the start and the old start the end, and close.
|
|
227
|
+
* Returns whether it did, in which case Zag's own handler must not run.
|
|
228
|
+
*/
|
|
229
|
+
export function restartRange(
|
|
230
|
+
api: RangeApi,
|
|
231
|
+
shown: RangeDraft,
|
|
232
|
+
props: Pick<DateRangePickerBaseProps, "minLength" | "maxLength">,
|
|
233
|
+
day: DateValue,
|
|
234
|
+
visibleRange?: { start: DateValue; end: DateValue },
|
|
235
|
+
): boolean {
|
|
236
|
+
if (shown.length !== 1 || rangeDayChoice(shown, day.toString(), props) !== "start") return false;
|
|
237
|
+
if (!api.getDayTableCellState({ value: day, visibleRange }).selectable) return false;
|
|
238
|
+
api.setValue([day]);
|
|
239
|
+
return true;
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
/**
|
|
243
|
+
* For the click handler of a day, in place of Zag's: see `restartRange`. Zag's handler runs
|
|
244
|
+
* for every other press.
|
|
245
|
+
*/
|
|
246
|
+
export function rangeDayClick<E>(
|
|
247
|
+
event: E,
|
|
248
|
+
api: RangeApi,
|
|
249
|
+
shown: RangeDraft,
|
|
250
|
+
props: Pick<DateRangePickerBaseProps, "minLength" | "maxLength">,
|
|
251
|
+
day: DateValue,
|
|
252
|
+
visibleRange: { start: DateValue; end: DateValue },
|
|
253
|
+
zag: ((event: E) => void) | null | undefined,
|
|
254
|
+
): void {
|
|
255
|
+
if (!restartRange(api, shown, props, day, visibleRange)) zag?.(event);
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
/**
|
|
259
|
+
* For the keydown handler of a month's grid, in place of Zag's: Enter or Space on a day before
|
|
260
|
+
* the start starts again from there, as a press does (see `restartRange`). Zag's handler runs
|
|
261
|
+
* for every other key.
|
|
262
|
+
*/
|
|
263
|
+
export function rangeGridKeyDown<E extends { key: string; preventDefault(): void }>(
|
|
264
|
+
event: E,
|
|
265
|
+
api: RangeApi,
|
|
266
|
+
shown: RangeDraft,
|
|
267
|
+
props: Pick<DateRangePickerBaseProps, "minLength" | "maxLength">,
|
|
268
|
+
zag: ((event: E) => void) | null | undefined,
|
|
269
|
+
): void {
|
|
270
|
+
if (
|
|
271
|
+
(event.key === "Enter" || event.key === " ") &&
|
|
272
|
+
restartRange(api, shown, props, api.focusedValue)
|
|
273
|
+
) {
|
|
274
|
+
event.preventDefault();
|
|
275
|
+
return;
|
|
276
|
+
}
|
|
277
|
+
zag?.(event);
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
/**
|
|
281
|
+
* After a render in which the focused day changed while the start is alone: the preview runs
|
|
282
|
+
* from the start to the focused day, or there is none while the focused day is before the
|
|
283
|
+
* start, since a press there starts again rather than ending the range.
|
|
284
|
+
*
|
|
285
|
+
* Zag previews to the day a key moves the focus to, except after ArrowRight (ArrowLeft right to
|
|
286
|
+
* left), whose action clears the preview it has just set (`["focusNextDay", "setHoveredDate"]`,
|
|
287
|
+
* with no day in a key's event): under React, which draws the move before that action runs, the
|
|
288
|
+
* keyboard check of the range fails without this. Zag would also preview a day before the start,
|
|
289
|
+
* from it to the start: the pointer check fails without this in every library.
|
|
290
|
+
*
|
|
291
|
+
* It looks once the event that moved the focus is over, at what the machine holds then.
|
|
292
|
+
*/
|
|
293
|
+
export function keepRangePreview(service: datePicker.Service, shown: RangeDraft, open: boolean) {
|
|
294
|
+
const [start] = shown;
|
|
295
|
+
if (!open || shown.length !== 1 || start === undefined) return;
|
|
296
|
+
queueMicrotask(() => {
|
|
297
|
+
if (!service.state.matches("open")) return;
|
|
298
|
+
const focused = service.context.get("focusedValue");
|
|
299
|
+
const hovered = service.context.get("hoveredValue");
|
|
300
|
+
if (focused.toString() < start) {
|
|
301
|
+
if (hovered) service.send({ type: "TABLE.POINTER_LEAVE" });
|
|
302
|
+
} else if (!hovered || hovered.compare(focused) !== 0) {
|
|
303
|
+
service.send({
|
|
304
|
+
type: "CELL.POINTER_MOVE",
|
|
305
|
+
cell: "day",
|
|
306
|
+
value: focused,
|
|
307
|
+
focus: false,
|
|
308
|
+
outsideRange: false,
|
|
309
|
+
});
|
|
310
|
+
}
|
|
311
|
+
});
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
/**
|
|
315
|
+
* When the calendar closes. Closed with a start alone, Zag stays on choosing an end (Escape does
|
|
316
|
+
* not reset it, the other ways of closing do): reopened over the chosen range, a hover or a key
|
|
317
|
+
* would preview from the range's start. `INPUT.BLUR` is the event Zag's text inputs send, whose
|
|
318
|
+
* only action without one is going back to choosing a start; Zag has no other way to it. The
|
|
319
|
+
* Escape check of the range fails without it.
|
|
320
|
+
*/
|
|
321
|
+
export function endRangeChoiceOnClose(service: datePicker.Service, open: boolean): void {
|
|
322
|
+
if (!open) service.send({ type: "INPUT.BLUR", index: 0, value: "" });
|
|
323
|
+
}
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Ejected from `@xds/react` 0.2.0 by `xds eject`. This copy is the app's own: change it
|
|
3
|
+
* as you need. `xds eject --list` says which ejected files differ from what was copied.
|
|
4
|
+
*/
|
|
5
|
+
/*
|
|
6
|
+
* Dialog: Zag's dialog machine, rendered into the body only while open or animating out.
|
|
7
|
+
*
|
|
8
|
+
* Parts: `.{{prefix}}-dialog__backdrop` (the scrim), `.{{prefix}}-dialog__positioner` (fills the window and centers
|
|
9
|
+
* the dialog), `.{{prefix}}-dialog` (the dialog itself), `__title`, `__description`, `__body`, `__actions`.
|
|
10
|
+
* States: `[data-state="closed"]` on the backdrop and the dialog while they animate out.
|
|
11
|
+
* The backdrop and the positioner stack by `--xds-layer-overlay` and Zag's `--layer-index`.
|
|
12
|
+
*/
|
|
13
|
+
@layer components {
|
|
14
|
+
.{{prefix}}-dialog__backdrop {
|
|
15
|
+
position: fixed;
|
|
16
|
+
inset: 0;
|
|
17
|
+
z-index: calc(var(--xds-layer-overlay) + var(--layer-index, 0));
|
|
18
|
+
background: var(--xds-color-scrim);
|
|
19
|
+
/* Zag turns pointer events off on the body while the dialog is open, and the backdrop would
|
|
20
|
+
inherit that. It takes a press beside the dialog itself, so the component can keep the
|
|
21
|
+
focus in the dialog. */
|
|
22
|
+
pointer-events: auto;
|
|
23
|
+
animation: {{prefix}}-fade-in var(--xds-motion-duration-normal) var(--xds-motion-easing-enter);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/* As wide as the window, so the dialog inside can be `size.dialog` wide whatever it holds,
|
|
27
|
+
and never closer to an edge than the padding. */
|
|
28
|
+
.{{prefix}}-dialog__positioner {
|
|
29
|
+
position: fixed;
|
|
30
|
+
inset: 0;
|
|
31
|
+
z-index: calc(var(--xds-layer-overlay) + var(--layer-index, 0));
|
|
32
|
+
display: flex;
|
|
33
|
+
flex-direction: column;
|
|
34
|
+
align-items: center;
|
|
35
|
+
padding: var(--xds-space-4);
|
|
36
|
+
/* A press beside the dialog reaches the backdrop, which is outside the dialog. */
|
|
37
|
+
pointer-events: none;
|
|
38
|
+
animation: {{prefix}}-dialog-enter var(--xds-motion-duration-normal) var(--xds-motion-easing-enter);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/* After the rules above, which they replace. The positioner follows the dialog's state, as
|
|
42
|
+
Zag gives the positioner none; a closing dialog takes no more presses. */
|
|
43
|
+
.{{prefix}}-dialog__backdrop[data-state="closed"] {
|
|
44
|
+
animation: xds-fade-out var(--xds-motion-duration-fast) var(--xds-motion-easing-exit)
|
|
45
|
+
forwards;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
.{{prefix}}-dialog__positioner:has(> .{{prefix}}-dialog[data-state="closed"]) {
|
|
49
|
+
animation: xds-overlay-exit var(--xds-motion-duration-fast) var(--xds-motion-easing-exit)
|
|
50
|
+
forwards;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
.{{prefix}}-dialog[data-state="closed"] {
|
|
54
|
+
pointer-events: none;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
@media (prefers-reduced-motion: reduce) {
|
|
58
|
+
.{{prefix}}-dialog__backdrop,
|
|
59
|
+
.{{prefix}}-dialog__positioner,
|
|
60
|
+
.{{prefix}}-dialog__backdrop[data-state="closed"],
|
|
61
|
+
.{{prefix}}-dialog__positioner:has(> .{{prefix}}-dialog[data-state="closed"]) {
|
|
62
|
+
animation: none;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
.{{prefix}}-dialog {
|
|
67
|
+
position: relative;
|
|
68
|
+
display: flex;
|
|
69
|
+
flex-direction: column;
|
|
70
|
+
gap: var(--xds-space-4);
|
|
71
|
+
width: 100%;
|
|
72
|
+
max-width: var(--xds-size-dialog);
|
|
73
|
+
max-height: 100%;
|
|
74
|
+
min-height: 0;
|
|
75
|
+
margin-block: auto;
|
|
76
|
+
padding: var(--xds-space-6);
|
|
77
|
+
overflow: clip;
|
|
78
|
+
border: var(--xds-border-width-thin) solid var(--xds-color-dialog-border);
|
|
79
|
+
border-radius: var(--xds-radius-lg);
|
|
80
|
+
background: var(--xds-color-dialog-background);
|
|
81
|
+
box-shadow: var(--xds-shadow-overlay);
|
|
82
|
+
outline: none;
|
|
83
|
+
pointer-events: auto;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
.{{prefix}}-dialog__title {
|
|
87
|
+
font-size: var(--xds-typography-title-size);
|
|
88
|
+
font-weight: var(--xds-typography-title-weight);
|
|
89
|
+
line-height: var(--xds-typography-title-line-height);
|
|
90
|
+
letter-spacing: var(--xds-typography-title-letter-spacing);
|
|
91
|
+
color: var(--xds-color-dialog-title);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
.{{prefix}}-dialog__description {
|
|
95
|
+
font-size: var(--xds-typography-body-size);
|
|
96
|
+
font-weight: var(--xds-typography-body-weight);
|
|
97
|
+
line-height: var(--xds-typography-body-line-height);
|
|
98
|
+
letter-spacing: var(--xds-typography-body-letter-spacing);
|
|
99
|
+
color: var(--xds-color-dialog-text);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/* The body scrolls, which clips whatever is drawn outside it. The inset leaves room for
|
|
103
|
+
the focus ring of a field inside, and the negative margin takes it back, so the text
|
|
104
|
+
still lines up with the title. */
|
|
105
|
+
.{{prefix}}-dialog__body {
|
|
106
|
+
flex: 1;
|
|
107
|
+
min-height: 0;
|
|
108
|
+
margin: calc(-1 * (var(--xds-focus-width) + var(--xds-focus-offset)));
|
|
109
|
+
padding: calc(var(--xds-focus-width) + var(--xds-focus-offset));
|
|
110
|
+
overflow-y: auto;
|
|
111
|
+
overscroll-behavior: contain;
|
|
112
|
+
font-size: var(--xds-typography-body-size);
|
|
113
|
+
line-height: var(--xds-typography-body-line-height);
|
|
114
|
+
color: var(--xds-color-dialog-text);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/* Buttons, in a row at the end edge. */
|
|
118
|
+
.{{prefix}}-dialog__actions {
|
|
119
|
+
display: flex;
|
|
120
|
+
align-items: center;
|
|
121
|
+
justify-content: flex-end;
|
|
122
|
+
gap: var(--xds-space-2);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
@keyframes {{prefix}}-fade-in {
|
|
127
|
+
from {
|
|
128
|
+
opacity: 0;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/* A dialog grows a little as it fades in. The scale is a literal because a custom property
|
|
133
|
+
inside a keyframe keeps WebKit from running the animation on the compositor. */
|
|
134
|
+
@keyframes {{prefix}}-dialog-enter {
|
|
135
|
+
from {
|
|
136
|
+
opacity: 0;
|
|
137
|
+
transform: scale(0.96);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
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
|
+
/** Dialog's props in every framework, short of `onClose`, its body and its actions. */
|
|
5
|
+
export type DialogBaseProps = {
|
|
6
|
+
/** Whether the dialog is shown. It never closes itself: this decides. */
|
|
7
|
+
open: boolean;
|
|
8
|
+
title: string;
|
|
9
|
+
description?: string;
|
|
10
|
+
/**
|
|
11
|
+
* Set it to false for a question that must be answered: Escape and a press outside then do
|
|
12
|
+
* nothing, and only an action closes the dialog.
|
|
13
|
+
*/
|
|
14
|
+
dismissible?: boolean;
|
|
15
|
+
};
|
|
@@ -0,0 +1,5 @@
|
|
|
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
|
+
/** A line between groups of content. Decorative lines use the low-contrast border color. */
|
|
5
|
+
export const dividerClass = "h-px w-full shrink-0 border-0 bg-xds-border-default";
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
// Ejected from `@xds/react` 0.2.0 by `xds eject`. This copy is the app's own: change it
|
|
2
|
+
// as you need. `xds eject --list` says which ejected files differ from what was copied.
|
|
3
|
+
|
|
4
|
+
import type { IconName } from "@xds/react/base";
|
|
5
|
+
|
|
6
|
+
/** EmptyState's props in every framework, short of its action. */
|
|
7
|
+
export type EmptyStateBaseProps = {
|
|
8
|
+
/** Illustrates what is missing. It is decoration. */
|
|
9
|
+
icon: IconName;
|
|
10
|
+
/** Says what is missing, such as "No messages yet". */
|
|
11
|
+
title: string;
|
|
12
|
+
/** Why it is empty, or what will appear here. */
|
|
13
|
+
description?: string;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export const EMPTY_STATE_PARTS = {
|
|
17
|
+
root: "m-auto flex w-full max-w-xds-dialog flex-col items-center py-8 text-center",
|
|
18
|
+
icon: "mb-4 text-xds-empty-state-icon",
|
|
19
|
+
title: "text-xds-heading text-xds-text-primary",
|
|
20
|
+
description: "mt-2 text-xds-body text-xds-text-secondary",
|
|
21
|
+
action: "mt-6 flex justify-center",
|
|
22
|
+
} as const;
|
|
@@ -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 { IconName } from "@xds/react/base";
|
|
5
|
+
|
|
6
|
+
// Written out in full: Tailwind only generates the classes it can find as whole strings.
|
|
7
|
+
const SIZE = {
|
|
8
|
+
xs: "size-xds-icon-xs",
|
|
9
|
+
sm: "size-xds-icon-sm",
|
|
10
|
+
md: "size-xds-icon-md",
|
|
11
|
+
lg: "size-xds-icon-lg",
|
|
12
|
+
xl: "size-xds-icon-xl",
|
|
13
|
+
} as const;
|
|
14
|
+
|
|
15
|
+
export type { IconName };
|
|
16
|
+
export type IconSize = keyof typeof SIZE;
|
|
17
|
+
|
|
18
|
+
export type IconBaseProps = {
|
|
19
|
+
name: IconName;
|
|
20
|
+
/**
|
|
21
|
+
* `xs` fits inside a badge, `sm` and `md` sit beside text, `lg` stands alone, as in a tab
|
|
22
|
+
* bar, and `xl` illustrates, as in an empty state.
|
|
23
|
+
*/
|
|
24
|
+
size?: IconSize;
|
|
25
|
+
/**
|
|
26
|
+
* Fills the shapes, so that a selected state shows in the form and not in the color alone:
|
|
27
|
+
* a heart that was pressed, a bookmark that is saved. Only for icons made of closed shapes.
|
|
28
|
+
*/
|
|
29
|
+
filled?: boolean;
|
|
30
|
+
/** Names the icon for assistive technology. Without it the icon is decoration and is skipped. */
|
|
31
|
+
label?: string;
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
export function iconClass(size: IconSize = "md"): string {
|
|
35
|
+
return `shrink-0 ${SIZE[size]}`;
|
|
36
|
+
}
|
|
@@ -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
|
+
/** ListRow's props in every framework, short of `leading`, `trailing` and `onPress`. */
|
|
5
|
+
export type ListRowBaseProps = {
|
|
6
|
+
title: string;
|
|
7
|
+
description?: string;
|
|
8
|
+
/** Draws a chevron at the far end, for a row that leads somewhere else. */
|
|
9
|
+
chevron?: boolean;
|
|
10
|
+
/** The row that is the current choice, such as the open page in a sidebar. */
|
|
11
|
+
selected?: boolean;
|
|
12
|
+
/** A shorter row with smaller text, for dense lists such as a sidebar or a menu. */
|
|
13
|
+
compact?: boolean;
|
|
14
|
+
disabled?: boolean;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
// The selected title is heavier, so the choice does not depend on the tint alone.
|
|
18
|
+
const TITLE = {
|
|
19
|
+
regular: { rest: "text-xds-body", selected: "text-xds-body-strong" },
|
|
20
|
+
compact: { rest: "text-xds-detail", selected: "text-xds-label" },
|
|
21
|
+
} as const;
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* The fills and the focus ring of a pressable row, at rest and selected. A collapsed Sidebar
|
|
25
|
+
* draws its icon-only rows with them too. The ring is inside the row, where a list that clips
|
|
26
|
+
* its rows still shows it.
|
|
27
|
+
*/
|
|
28
|
+
export const PRESSABLE_ROW = {
|
|
29
|
+
rest: "hover:bg-xds-list-row-background-hover active:bg-xds-list-row-background-pressed disabled:hover:bg-transparent",
|
|
30
|
+
selected:
|
|
31
|
+
"hover:bg-xds-list-row-background-selected-hover active:bg-xds-list-row-background-selected-hover disabled:hover:bg-xds-list-row-background-selected",
|
|
32
|
+
focus:
|
|
33
|
+
"focus-visible:outline-solid focus-visible:outline-(length:--xds-focus-width) focus-visible:-outline-offset-(--xds-focus-offset) focus-visible:outline-xds-border-focus",
|
|
34
|
+
} as const;
|
|
35
|
+
|
|
36
|
+
/** The row: a `div`, or a `button` with `pressable`. */
|
|
37
|
+
export function listRowClass(options: {
|
|
38
|
+
compact?: boolean | undefined;
|
|
39
|
+
selected?: boolean | undefined;
|
|
40
|
+
pressable?: boolean | undefined;
|
|
41
|
+
}): string {
|
|
42
|
+
const { compact = false, selected = false, pressable = false } = options;
|
|
43
|
+
const row = `flex w-full items-center gap-3 px-4 text-start ${compact ? "min-h-xds-list-row-compact py-1" : "min-h-xds-list-row py-2"}${selected ? " bg-xds-list-row-background-selected" : ""}`;
|
|
44
|
+
if (!pressable) return row;
|
|
45
|
+
return `${row} cursor-pointer transition-colors duration-(--xds-motion-duration-fast) ${selected ? PRESSABLE_ROW.selected : PRESSABLE_ROW.rest} ${PRESSABLE_ROW.focus} disabled:cursor-not-allowed`;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export function listRowTitleClass(options: {
|
|
49
|
+
compact?: boolean | undefined;
|
|
50
|
+
selected?: boolean | undefined;
|
|
51
|
+
disabled?: boolean | undefined;
|
|
52
|
+
}): string {
|
|
53
|
+
const { compact = false, selected = false, disabled = false } = options;
|
|
54
|
+
return `${TITLE[compact ? "compact" : "regular"][selected ? "selected" : "rest"]} ${disabled ? "text-xds-text-secondary" : "text-xds-text-primary"}`;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export function listRowDescriptionClass(compact = false): string {
|
|
58
|
+
return `text-xds-text-secondary ${compact ? "text-xds-footnote" : "text-xds-detail"}`;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export const LIST_ROW_PARTS = {
|
|
62
|
+
/** The title and the description, between `leading` and `trailing`. */
|
|
63
|
+
text: "flex min-w-0 flex-1 flex-col gap-0.5",
|
|
64
|
+
/** It points onward, so it mirrors in a right-to-left layout. */
|
|
65
|
+
chevron: "text-xds-text-tertiary rtl:-scale-x-100",
|
|
66
|
+
} as const;
|
|
@@ -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 type { ThumbnailRatio } from "@xds/react/base";
|
|
5
|
+
|
|
6
|
+
export type MediaCardLayout = "vertical" | "horizontal";
|
|
7
|
+
|
|
8
|
+
/** MediaCard's props in every framework, short of `leading`, `action` and `onPress`. */
|
|
9
|
+
export type MediaCardBaseProps = {
|
|
10
|
+
/** `vertical` puts the thumbnail on top; `horizontal` at the start, at 40% of the width. */
|
|
11
|
+
layout?: MediaCardLayout;
|
|
12
|
+
/** The picture, as a Thumbnail's. */
|
|
13
|
+
src?: string | undefined;
|
|
14
|
+
/** Describes the picture. Defaults to an empty string: the title already says what it is. */
|
|
15
|
+
alt?: string;
|
|
16
|
+
ratio?: ThumbnailRatio;
|
|
17
|
+
/** Short text on the picture's bottom end corner, such as a duration. */
|
|
18
|
+
badge?: string;
|
|
19
|
+
/** How much was watched, from 0 to 1. */
|
|
20
|
+
progress?: number;
|
|
21
|
+
/** At most two lines, then an ellipsis. */
|
|
22
|
+
title: string;
|
|
23
|
+
/** Short details, one line each, such as a channel name and "3 days ago". */
|
|
24
|
+
meta?: readonly string[];
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
/** The ids of the title and of each detail, which together name the card. */
|
|
28
|
+
export function mediaCardIds(id: string, meta: readonly string[] = []) {
|
|
29
|
+
const title = `${id}-title`;
|
|
30
|
+
const details = meta.map((_, index) => `${id}-meta-${index}`);
|
|
31
|
+
return { title, details, names: [title, ...details].join(" ") };
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* The thumbnail and the text. On a pressable card it sits above the button, which draws the
|
|
36
|
+
* fills under it, and is see-through to the pointer, so a press anywhere but on the action
|
|
37
|
+
* lands on the button.
|
|
38
|
+
*/
|
|
39
|
+
export function mediaCardContentClass(options: {
|
|
40
|
+
horizontal: boolean;
|
|
41
|
+
pressable: boolean;
|
|
42
|
+
}): string {
|
|
43
|
+
const { horizontal, pressable } = options;
|
|
44
|
+
return `relative flex gap-3 ${horizontal ? "items-start" : "flex-col"}${pressable ? " pointer-events-none" : ""}`;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export function mediaCardThumbnailClass(horizontal: boolean): string {
|
|
48
|
+
return horizontal ? "w-2/5 shrink-0" : "block";
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export const MEDIA_CARD_PARTS = {
|
|
52
|
+
/** A card that is not pressable: a group named by its text. */
|
|
53
|
+
group: "flex flex-col",
|
|
54
|
+
/** A pressable card: the box around the button and the content. */
|
|
55
|
+
pressable: "relative flex flex-col rounded-xds-lg p-2",
|
|
56
|
+
/** Covers the whole pressable card, under the content. */
|
|
57
|
+
button:
|
|
58
|
+
"absolute inset-0 cursor-pointer rounded-xds-lg transition-colors duration-(--xds-motion-duration-fast) hover:bg-xds-card-background-hover focus-visible:outline-solid focus-visible:outline-(length:--xds-focus-width) focus-visible:outline-offset-(--xds-focus-offset) focus-visible:outline-xds-border-focus active:bg-xds-card-background-pressed",
|
|
59
|
+
/** Beside the thumbnail, or under it: `leading`, the text and the action. */
|
|
60
|
+
body: "flex min-w-0 flex-1 items-start gap-3",
|
|
61
|
+
leading: "flex shrink-0",
|
|
62
|
+
text: "flex min-w-0 flex-1 flex-col gap-0.5",
|
|
63
|
+
title: "line-clamp-2 text-xds-body-strong text-xds-text-primary",
|
|
64
|
+
meta: "truncate text-xds-detail text-xds-text-secondary",
|
|
65
|
+
action: "pointer-events-auto flex shrink-0",
|
|
66
|
+
} as const;
|