@xds/solid 1.1.0 → 1.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/dom/Breadcrumb.js +87 -0
- package/dist/dom/Checkbox.js +12 -6
- package/dist/dom/Combobox.js +295 -0
- package/dist/dom/Link.js +62 -0
- package/dist/dom/Menu.js +15 -14
- package/dist/dom/Pagination.js +132 -0
- package/dist/dom/Popover.js +126 -0
- package/dist/dom/Select.js +75 -48
- package/dist/dom/Table.js +150 -0
- package/dist/dom/TimePicker.js +245 -0
- package/dist/dom/ToastQueue.js +59 -0
- package/dist/dom/base.js +16 -0
- package/dist/dom/index.js +9 -1
- package/dist/dom/modal-popover.js +2 -2
- package/dist/dom/presence.js +3 -2
- package/dist/dom/preview.js +19 -2
- package/dist/dom/rows.js +13 -0
- package/dist/source/Breadcrumb.d.ts +9 -0
- package/dist/source/Breadcrumb.jsx +26 -0
- package/dist/source/Checkbox.d.ts +1 -1
- package/dist/source/Checkbox.jsx +9 -3
- package/dist/source/Combobox.d.ts +16 -0
- package/dist/source/Combobox.jsx +137 -0
- package/dist/source/Link.d.ts +20 -0
- package/dist/source/Link.jsx +21 -0
- package/dist/source/Menu.jsx +8 -2
- package/dist/source/Pagination.d.ts +12 -0
- package/dist/source/Pagination.jsx +51 -0
- package/dist/source/Popover.d.ts +19 -0
- package/dist/source/Popover.jsx +65 -0
- package/dist/source/Select.d.ts +6 -0
- package/dist/source/Select.jsx +32 -8
- package/dist/source/Table.d.ts +17 -0
- package/dist/source/Table.jsx +46 -0
- package/dist/source/TimePicker.d.ts +19 -0
- package/dist/source/TimePicker.jsx +137 -0
- package/dist/source/ToastQueue.d.ts +19 -0
- package/dist/source/ToastQueue.jsx +27 -0
- package/dist/source/base.d.ts +15 -0
- package/dist/source/base.js +15 -0
- package/dist/source/controllable.d.ts +1 -1
- package/dist/source/index.d.ts +9 -1
- package/dist/source/index.js +8 -0
- package/dist/source/modal-popover.js +2 -2
- package/dist/source/presence.js +3 -2
- package/dist/source/preview.d.ts +10 -2
- package/dist/source/preview.jsx +12 -3
- package/dist/source/rows.d.ts +8 -0
- package/dist/source/rows.js +5 -0
- package/eject/files/Accordion.tsx +138 -0
- package/eject/files/Avatar.tsx +48 -0
- package/eject/files/AvatarStack.tsx +51 -0
- package/eject/files/Badge.tsx +39 -0
- package/eject/files/Banner.tsx +80 -0
- package/eject/files/Breadcrumb.tsx +57 -0
- package/eject/files/Button.tsx +90 -0
- package/eject/files/Card.tsx +100 -0
- package/eject/files/Checkbox.tsx +100 -0
- package/eject/files/Chip.tsx +40 -0
- package/eject/files/ChipBar.tsx +34 -0
- package/eject/files/Combobox.tsx +200 -0
- package/eject/files/CountBadge.tsx +55 -0
- package/eject/files/DatePicker.tsx +225 -0
- package/eject/files/DateRangePicker.tsx +319 -0
- package/eject/files/Dialog.tsx +117 -0
- package/eject/files/Divider.tsx +21 -0
- package/eject/files/EmptyState.tsx +39 -0
- package/eject/files/Icon.tsx +37 -0
- package/eject/files/IconButton.tsx +76 -0
- package/eject/files/Link.tsx +61 -0
- package/eject/files/ListRow.tsx +94 -0
- package/eject/files/MediaCard.tsx +116 -0
- package/eject/files/Menu.tsx +190 -0
- package/eject/files/Pagination.tsx +109 -0
- package/eject/files/Popover.tsx +124 -0
- package/eject/files/ProgressBar.tsx +37 -0
- package/eject/files/RadioGroup.tsx +138 -0
- package/eject/files/SearchField.tsx +124 -0
- package/eject/files/SectionHeader.tsx +59 -0
- package/eject/files/SegmentedControl.tsx +79 -0
- package/eject/files/Select.tsx +290 -0
- package/eject/files/Sidebar.tsx +156 -0
- package/eject/files/Skeleton.tsx +33 -0
- package/eject/files/Slider.tsx +131 -0
- package/eject/files/Spinner.tsx +44 -0
- package/eject/files/Switch.tsx +88 -0
- package/eject/files/Table.tsx +98 -0
- package/eject/files/Tabs.tsx +87 -0
- package/eject/files/Text.tsx +38 -0
- package/eject/files/TextField.tsx +171 -0
- package/eject/files/Thumbnail.tsx +84 -0
- package/eject/files/TimePicker.tsx +237 -0
- package/eject/files/Toast.tsx +100 -0
- package/eject/files/ToastQueue.tsx +62 -0
- package/eject/files/Tooltip.tsx +135 -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 +71 -0
- package/eject/files/base.css +38 -0
- package/eject/files/breadcrumb.css +51 -0
- package/eject/files/breadcrumb.ts +42 -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 +52 -0
- package/eject/files/chip-bar.ts +16 -0
- package/eject/files/chip.ts +35 -0
- package/eject/files/combobox.css +269 -0
- package/eject/files/combobox.ts +85 -0
- package/eject/files/count-badge.ts +32 -0
- package/eject/files/date-picker.css +375 -0
- package/eject/files/date-picker.ts +280 -0
- package/eject/files/date-range-picker.ts +338 -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/link.css +64 -0
- package/eject/files/link.ts +63 -0
- package/eject/files/list-row.ts +66 -0
- package/eject/files/media-card.ts +66 -0
- package/eject/files/menu.css +192 -0
- package/eject/files/menu.ts +84 -0
- package/eject/files/overlay.css +40 -0
- package/eject/files/pagination.css +106 -0
- package/eject/files/pagination.ts +68 -0
- package/eject/files/parts.ts +17 -0
- package/eject/files/popover.css +101 -0
- package/eject/files/popover.ts +37 -0
- package/eject/files/progress-bar.ts +26 -0
- package/eject/files/radio-group.css +184 -0
- package/eject/files/radio-group.ts +30 -0
- package/eject/files/section-header.ts +32 -0
- package/eject/files/segmented-control.ts +33 -0
- package/eject/files/select.css +347 -0
- package/eject/files/select.ts +77 -0
- package/eject/files/sidebar.ts +75 -0
- package/eject/files/skeleton.ts +51 -0
- package/eject/files/slider.css +160 -0
- package/eject/files/slider.ts +80 -0
- package/eject/files/spinner.ts +22 -0
- package/eject/files/switch.ts +45 -0
- package/eject/files/table.css +107 -0
- package/eject/files/table.ts +84 -0
- package/eject/files/tabs.css +120 -0
- package/eject/files/tabs.ts +37 -0
- package/eject/files/text-field.css +225 -0
- package/eject/files/text-field.ts +64 -0
- package/eject/files/text.ts +38 -0
- package/eject/files/thumbnail.ts +51 -0
- package/eject/files/time-picker.ts +113 -0
- package/eject/files/toast-queue.ts +64 -0
- package/eject/files/toast.ts +31 -0
- package/eject/files/tooltip.css +111 -0
- package/eject/files/tooltip.ts +21 -0
- package/eject/manifest.json +1027 -0
- package/package.json +12 -4
- package/styles.css +1064 -169
- package/tailwind.css +1295 -218
|
@@ -0,0 +1,319 @@
|
|
|
1
|
+
// Ejected from `@xds/solid` 1.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
|
+
createPresence,
|
|
6
|
+
modalPopover,
|
|
7
|
+
Portal,
|
|
8
|
+
type RootProps,
|
|
9
|
+
readCssPx,
|
|
10
|
+
rootAttributes,
|
|
11
|
+
space,
|
|
12
|
+
underlayLayerStyle,
|
|
13
|
+
useLabels,
|
|
14
|
+
withStyle,
|
|
15
|
+
} from "@xds/solid/base";
|
|
16
|
+
import * as datePicker from "@zag-js/date-picker";
|
|
17
|
+
import { normalizeProps, useMachine } from "@zag-js/solid";
|
|
18
|
+
import { createEffect, createMemo, createSignal, createUniqueId, For, Show } from "solid-js";
|
|
19
|
+
import {
|
|
20
|
+
DATE_PICKER_NAV_CLASS,
|
|
21
|
+
datePickerContentAttrs,
|
|
22
|
+
datePickerIds,
|
|
23
|
+
datePickerLocale,
|
|
24
|
+
datePickerTriggerAttrs,
|
|
25
|
+
focusOpeningDay,
|
|
26
|
+
keepCalendarFocus,
|
|
27
|
+
keepDayFocused,
|
|
28
|
+
} from "./date-picker.ts";
|
|
29
|
+
import {
|
|
30
|
+
type DateRange,
|
|
31
|
+
type DateRangePickerBaseProps,
|
|
32
|
+
dateRangeMachineProps,
|
|
33
|
+
endRangeChoiceOnClose,
|
|
34
|
+
formatRange,
|
|
35
|
+
keepRangePreview,
|
|
36
|
+
type RangeDraft,
|
|
37
|
+
rangeDayClick,
|
|
38
|
+
rangeGridKeyDown,
|
|
39
|
+
rangeMonths,
|
|
40
|
+
rangeMonthViews,
|
|
41
|
+
rangeSummary,
|
|
42
|
+
shownRange,
|
|
43
|
+
} from "./date-range-picker.ts";
|
|
44
|
+
import { Icon } from "./Icon.tsx";
|
|
45
|
+
import { classes } from "./parts.ts";
|
|
46
|
+
|
|
47
|
+
export type { DateRange } from "./date-range-picker.ts";
|
|
48
|
+
|
|
49
|
+
export type DateRangePickerProps = DateRangePickerBaseProps &
|
|
50
|
+
RootProps & {
|
|
51
|
+
onChange: (value: DateRange) => void;
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
type Handler<E> = (event: E) => void;
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* A field for choosing a range of days, a start and an end, as for a stay. Closed, it looks like
|
|
58
|
+
* a DatePicker and shows both days in the locale's medium form ("Mar 10 – 14, 2026"), or the
|
|
59
|
+
* placeholder. Pressed, it opens a calendar under itself, two months side by side where the
|
|
60
|
+
* window has room and one where it does not, on the start's month, or on today's while nothing
|
|
61
|
+
* is chosen.
|
|
62
|
+
*
|
|
63
|
+
* The first day pressed starts the range, and the band previews it to the day under the pointer
|
|
64
|
+
* or the keyboard's focus. The second ends it, if the days between are at least `minLength` and
|
|
65
|
+
* at most `maxLength`, which leave the other days unavailable meanwhile: `onChange` gets the
|
|
66
|
+
* range and the calendar closes. A day before the start starts again from there. Escape or a
|
|
67
|
+
* press outside closes the calendar without a change.
|
|
68
|
+
*
|
|
69
|
+
* The keys are DatePicker's, and Page Up and Page Down move a month whether one or two are
|
|
70
|
+
* shown. Each month is a grid named by its month; every day of the range is selected, and the
|
|
71
|
+
* two ends are named by `startLabel` and `endLabel` before the day.
|
|
72
|
+
*/
|
|
73
|
+
export function DateRangePicker(props: DateRangePickerProps) {
|
|
74
|
+
const id = createUniqueId();
|
|
75
|
+
const ids = datePickerIds(id);
|
|
76
|
+
const locale = () => datePickerLocale(props.locale);
|
|
77
|
+
const labels = useLabels();
|
|
78
|
+
// A start alone while the end is chosen; null while the calendar shows the chosen range.
|
|
79
|
+
const [draft, setDraft] = createSignal<RangeDraft | null>(null);
|
|
80
|
+
const [months, setMonths] = createSignal(1);
|
|
81
|
+
const shown = createMemo(() => shownRange(props.value, draft()));
|
|
82
|
+
const service = useMachine(datePicker.machine, () => ({
|
|
83
|
+
...dateRangeMachineProps(props, shown(), {
|
|
84
|
+
id,
|
|
85
|
+
locale: locale(),
|
|
86
|
+
months: months(),
|
|
87
|
+
onDraft: (next) => setDraft(() => next),
|
|
88
|
+
onChange: (value) => props.onChange(value),
|
|
89
|
+
gutter: readCssPx(null, "--xds-space-1", space[1]),
|
|
90
|
+
labels: labels(),
|
|
91
|
+
}),
|
|
92
|
+
// The app's id goes on the root, where Zag looks for it by this one.
|
|
93
|
+
ids: { root: props.id },
|
|
94
|
+
}));
|
|
95
|
+
const api = createMemo(() => datePicker.connect(service, normalizeProps));
|
|
96
|
+
const root = withStyle(
|
|
97
|
+
() => api().getRootProps(),
|
|
98
|
+
() => props.style,
|
|
99
|
+
rootAttributes(props),
|
|
100
|
+
);
|
|
101
|
+
let positioner: HTMLDivElement | undefined;
|
|
102
|
+
let surface: HTMLDivElement | undefined;
|
|
103
|
+
modalPopover(
|
|
104
|
+
() => api().open,
|
|
105
|
+
() => positioner,
|
|
106
|
+
);
|
|
107
|
+
const present = createPresence(
|
|
108
|
+
() => api().open,
|
|
109
|
+
() => [surface],
|
|
110
|
+
);
|
|
111
|
+
// Memos, so that the effects run only when one of them changes, not on every change of the
|
|
112
|
+
// machine.
|
|
113
|
+
const open = createMemo(() => api().open);
|
|
114
|
+
const focused = createMemo(() => api().focusedValue.toString());
|
|
115
|
+
const month = createMemo(() => api().visibleRange.start.toString());
|
|
116
|
+
createEffect(
|
|
117
|
+
() => [open(), focused(), month()] as const,
|
|
118
|
+
([isOpen]) => keepDayFocused(isOpen, surface),
|
|
119
|
+
);
|
|
120
|
+
createEffect(open, (isOpen) => endRangeChoiceOnClose(service, isOpen));
|
|
121
|
+
createEffect(focused, () => keepRangePreview(service, shown(), open()));
|
|
122
|
+
const summary = createMemo(() => rangeSummary(shown(), props, locale(), labels()));
|
|
123
|
+
const views = createMemo(() => rangeMonthViews(api(), months()));
|
|
124
|
+
const invalid = () => props.error !== undefined;
|
|
125
|
+
return (
|
|
126
|
+
<div
|
|
127
|
+
{...root}
|
|
128
|
+
class={classes("{{prefix}}-date-picker {{prefix}}-date-range-picker", props.class)}
|
|
129
|
+
>
|
|
130
|
+
{/* A span: the field is a button, which a <label> cannot point at. */}
|
|
131
|
+
<span id={ids.label} class="{{prefix}}-date-picker__label">
|
|
132
|
+
{props.label}
|
|
133
|
+
</span>
|
|
134
|
+
{/* What Zag places the calendar against. */}
|
|
135
|
+
<div {...api().getControlProps()} class="{{prefix}}-date-picker__control">
|
|
136
|
+
<button
|
|
137
|
+
{...api().getTriggerProps()}
|
|
138
|
+
{...datePickerTriggerAttrs(props, ids)}
|
|
139
|
+
type="button"
|
|
140
|
+
onClick={(event) => {
|
|
141
|
+
if (!api().open) setMonths(rangeMonths());
|
|
142
|
+
focusOpeningDay(api(), { ...props, value: props.value?.start });
|
|
143
|
+
(api().getTriggerProps().onClick as Handler<MouseEvent> | undefined)?.(event);
|
|
144
|
+
}}
|
|
145
|
+
class="{{prefix}}-date-picker__trigger"
|
|
146
|
+
>
|
|
147
|
+
<span id={ids.value} class="{{prefix}}-date-picker__value">
|
|
148
|
+
{props.value === undefined ? props.placeholder : formatRange(props.value, locale())}
|
|
149
|
+
</span>
|
|
150
|
+
<Icon name="calendar" size="sm" class="text-xds-field-placeholder" />
|
|
151
|
+
</button>
|
|
152
|
+
</div>
|
|
153
|
+
{/* One line under the box: the help, or the error in its place. The error stays mounted as
|
|
154
|
+
a live region so assistive technology announces it when it appears. */}
|
|
155
|
+
<div class="{{prefix}}-date-picker__footer">
|
|
156
|
+
<Show when={!invalid() && props.description}>
|
|
157
|
+
<span id={ids.description} class="{{prefix}}-date-picker__description">
|
|
158
|
+
{props.description}
|
|
159
|
+
</span>
|
|
160
|
+
</Show>
|
|
161
|
+
<span id={ids.error} class="{{prefix}}-date-picker__error" aria-live="polite">
|
|
162
|
+
{props.error}
|
|
163
|
+
</span>
|
|
164
|
+
</div>
|
|
165
|
+
{/* What a form submits. Zag gives the names to its text inputs, which are not drawn. */}
|
|
166
|
+
<Show when={props.startName !== undefined}>
|
|
167
|
+
<input type="hidden" name={props.startName} value={props.value?.start ?? ""} />
|
|
168
|
+
</Show>
|
|
169
|
+
<Show when={props.endName !== undefined}>
|
|
170
|
+
<input type="hidden" name={props.endName} value={props.value?.end ?? ""} />
|
|
171
|
+
</Show>
|
|
172
|
+
<Portal>
|
|
173
|
+
<Show when={api().open}>
|
|
174
|
+
{/* Takes a press outside, which then only closes the calendar. The focus stays in
|
|
175
|
+
the calendar until it hands it back to the field. */}
|
|
176
|
+
{/* oxlint-disable-next-line jsx-a11y/no-static-element-interactions -- not a control: the handler only keeps the focus where it is */}
|
|
177
|
+
<div
|
|
178
|
+
class="{{prefix}}-date-picker__underlay"
|
|
179
|
+
style={underlayLayerStyle(api().getPositionerProps().style)}
|
|
180
|
+
onMouseDown={(event) => event.preventDefault()}
|
|
181
|
+
/>
|
|
182
|
+
</Show>
|
|
183
|
+
<div
|
|
184
|
+
ref={(element) => (positioner = element)}
|
|
185
|
+
{...api().getPositionerProps()}
|
|
186
|
+
class="{{prefix}}-date-picker__positioner"
|
|
187
|
+
>
|
|
188
|
+
{/* Shown until its exit animation ends; Zag would hide it as it closes. */}
|
|
189
|
+
{/* oxlint-disable-next-line jsx-a11y/no-static-element-interactions -- a dialog: datePickerContentAttrs gives it the role */}
|
|
190
|
+
<div
|
|
191
|
+
{...api().getContentProps()}
|
|
192
|
+
{...datePickerContentAttrs(ids)}
|
|
193
|
+
ref={(element) => (surface = element)}
|
|
194
|
+
hidden={!present()}
|
|
195
|
+
onKeyDown={(event) => keepCalendarFocus(event, surface)}
|
|
196
|
+
class="{{prefix}}-date-picker__content {{prefix}}-date-range-picker__content"
|
|
197
|
+
>
|
|
198
|
+
<div class="{{prefix}}-date-range-picker__summary" aria-live="polite">
|
|
199
|
+
<span>{summary().start}</span>
|
|
200
|
+
<span>{summary().end}</span>
|
|
201
|
+
</div>
|
|
202
|
+
<div class="{{prefix}}-date-range-picker__months">
|
|
203
|
+
{/* Kept by position: the months move under the same columns. */}
|
|
204
|
+
<For each={views()} keyed={false}>
|
|
205
|
+
{(view) => (
|
|
206
|
+
<div class="{{prefix}}-date-range-picker__month">
|
|
207
|
+
<div class="{{prefix}}-date-picker__header">
|
|
208
|
+
<Show
|
|
209
|
+
when={view().index === 0}
|
|
210
|
+
fallback={<span class="{{prefix}}-date-range-picker__nav-space" />}
|
|
211
|
+
>
|
|
212
|
+
<button
|
|
213
|
+
{...api().getPreviousTriggerProps()}
|
|
214
|
+
type="button"
|
|
215
|
+
class={DATE_PICKER_NAV_CLASS}
|
|
216
|
+
>
|
|
217
|
+
<Icon name="chevron-left" size="sm" />
|
|
218
|
+
</button>
|
|
219
|
+
</Show>
|
|
220
|
+
<span {...api().getRangeTextProps()} class="{{prefix}}-date-picker__heading">
|
|
221
|
+
{view().name}
|
|
222
|
+
</span>
|
|
223
|
+
<Show
|
|
224
|
+
when={view().index === months() - 1}
|
|
225
|
+
fallback={<span class="{{prefix}}-date-range-picker__nav-space" />}
|
|
226
|
+
>
|
|
227
|
+
<button
|
|
228
|
+
{...api().getNextTriggerProps()}
|
|
229
|
+
type="button"
|
|
230
|
+
class={DATE_PICKER_NAV_CLASS}
|
|
231
|
+
>
|
|
232
|
+
<Icon name="chevron-right" size="sm" />
|
|
233
|
+
</button>
|
|
234
|
+
</Show>
|
|
235
|
+
</div>
|
|
236
|
+
{/* 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 */}
|
|
237
|
+
<table
|
|
238
|
+
{...api().getTableProps({ view: "day", id: view().table.id })}
|
|
239
|
+
{...view().table}
|
|
240
|
+
onKeyDown={(event) =>
|
|
241
|
+
rangeGridKeyDown(
|
|
242
|
+
event,
|
|
243
|
+
api(),
|
|
244
|
+
shown(),
|
|
245
|
+
props,
|
|
246
|
+
api().getTableProps({ view: "day", id: view().table.id }).onKeyDown as
|
|
247
|
+
| Handler<KeyboardEvent>
|
|
248
|
+
| undefined,
|
|
249
|
+
)
|
|
250
|
+
}
|
|
251
|
+
class="{{prefix}}-date-picker__grid"
|
|
252
|
+
>
|
|
253
|
+
<thead {...api().getTableHeadProps({ view: "day" })}>
|
|
254
|
+
<tr {...api().getTableRowProps({ view: "day" })}>
|
|
255
|
+
<For each={api().weekDays} keyed={false}>
|
|
256
|
+
{(weekDay) => (
|
|
257
|
+
<th scope="col" class="{{prefix}}-date-picker__weekday">
|
|
258
|
+
{weekDay().narrow}
|
|
259
|
+
</th>
|
|
260
|
+
)}
|
|
261
|
+
</For>
|
|
262
|
+
</tr>
|
|
263
|
+
</thead>
|
|
264
|
+
<tbody {...api().getTableBodyProps({ view: "day" })}>
|
|
265
|
+
{/* Kept by position, as in DatePicker: a cell made anew would drop the
|
|
266
|
+
focus it holds when a move is held at `min` or `max`. */}
|
|
267
|
+
<For each={view().weeks} keyed={false}>
|
|
268
|
+
{(week) => (
|
|
269
|
+
<tr {...api().getTableRowProps({ view: "day" })}>
|
|
270
|
+
<For each={week()} keyed={false}>
|
|
271
|
+
{(date) => {
|
|
272
|
+
const cell = () => ({
|
|
273
|
+
value: date(),
|
|
274
|
+
visibleRange: view().visibleRange,
|
|
275
|
+
});
|
|
276
|
+
return (
|
|
277
|
+
<td
|
|
278
|
+
{...api().getDayTableCellProps(cell())}
|
|
279
|
+
class="{{prefix}}-date-picker__cell"
|
|
280
|
+
>
|
|
281
|
+
{/* 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 */}
|
|
282
|
+
<div
|
|
283
|
+
{...api().getDayTableCellTriggerProps(cell())}
|
|
284
|
+
onClick={(event) =>
|
|
285
|
+
rangeDayClick(
|
|
286
|
+
event,
|
|
287
|
+
api(),
|
|
288
|
+
shown(),
|
|
289
|
+
props,
|
|
290
|
+
date(),
|
|
291
|
+
view().visibleRange,
|
|
292
|
+
api().getDayTableCellTriggerProps(cell()).onClick as
|
|
293
|
+
| Handler<MouseEvent>
|
|
294
|
+
| undefined,
|
|
295
|
+
)
|
|
296
|
+
}
|
|
297
|
+
class="{{prefix}}-date-picker__day"
|
|
298
|
+
>
|
|
299
|
+
{date().day}
|
|
300
|
+
</div>
|
|
301
|
+
</td>
|
|
302
|
+
);
|
|
303
|
+
}}
|
|
304
|
+
</For>
|
|
305
|
+
</tr>
|
|
306
|
+
)}
|
|
307
|
+
</For>
|
|
308
|
+
</tbody>
|
|
309
|
+
</table>
|
|
310
|
+
</div>
|
|
311
|
+
)}
|
|
312
|
+
</For>
|
|
313
|
+
</div>
|
|
314
|
+
</div>
|
|
315
|
+
</div>
|
|
316
|
+
</Portal>
|
|
317
|
+
</div>
|
|
318
|
+
);
|
|
319
|
+
}
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
// Ejected from `@xds/solid` 1.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
|
+
createPresence,
|
|
6
|
+
leaveEscapeToFields,
|
|
7
|
+
Portal,
|
|
8
|
+
type RootProps,
|
|
9
|
+
rootAttributes,
|
|
10
|
+
TriggerContext,
|
|
11
|
+
withStyle,
|
|
12
|
+
} from "@xds/solid/base";
|
|
13
|
+
import * as dialog from "@zag-js/dialog";
|
|
14
|
+
import { normalizeProps, useMachine } from "@zag-js/solid";
|
|
15
|
+
import { createMemo, createUniqueId, type Element, Show } from "solid-js";
|
|
16
|
+
import type { DialogBaseProps } from "./dialog.ts";
|
|
17
|
+
import { classes } from "./parts.ts";
|
|
18
|
+
|
|
19
|
+
export type DialogProps = DialogBaseProps &
|
|
20
|
+
RootProps & {
|
|
21
|
+
/** Called on Escape and on a press outside the dialog. Set `open` to false in it. */
|
|
22
|
+
onClose: () => void;
|
|
23
|
+
/** The body, between the description and the actions. It scrolls when it is too tall. */
|
|
24
|
+
children?: Element;
|
|
25
|
+
/** Buttons, in a row at the end edge. Put the main action last. */
|
|
26
|
+
actions?: Element;
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* A window that interrupts the screen for a confirmation or a short task. Everything behind it
|
|
31
|
+
* is dimmed and cannot be reached until it closes.
|
|
32
|
+
*
|
|
33
|
+
* It is a modal dialog named by its title and described by its description. Focus moves into
|
|
34
|
+
* it, stays inside it, and returns to where it was when it closes.
|
|
35
|
+
*
|
|
36
|
+
* Its `class` and `style` are the dialog's surface's, not the backdrop's.
|
|
37
|
+
*/
|
|
38
|
+
export function Dialog(props: DialogProps) {
|
|
39
|
+
const id = createUniqueId();
|
|
40
|
+
let backdrop: HTMLDivElement | undefined;
|
|
41
|
+
let positioner: HTMLDivElement | undefined;
|
|
42
|
+
let content: HTMLElement | undefined;
|
|
43
|
+
const service = useMachine(dialog.machine, () => ({
|
|
44
|
+
id,
|
|
45
|
+
// The app's id goes on the surface, where Zag looks for it by this one.
|
|
46
|
+
ids: { content: props.id },
|
|
47
|
+
open: props.open,
|
|
48
|
+
onOpenChange: (details: dialog.OpenChangeDetails) => {
|
|
49
|
+
if (!details.open) props.onClose();
|
|
50
|
+
},
|
|
51
|
+
closeOnEscape: props.dismissible ?? true,
|
|
52
|
+
closeOnInteractOutside: props.dismissible ?? true,
|
|
53
|
+
onEscapeKeyDown: leaveEscapeToFields,
|
|
54
|
+
// The dialog itself rather than its first field or button: a screen reader then reads the
|
|
55
|
+
// title and the description first.
|
|
56
|
+
initialFocusEl: () => content ?? null,
|
|
57
|
+
}));
|
|
58
|
+
const api = createMemo(() => dialog.connect(service, normalizeProps));
|
|
59
|
+
const contentProps = withStyle(
|
|
60
|
+
() => api().getContentProps(),
|
|
61
|
+
() => props.style,
|
|
62
|
+
rootAttributes(props),
|
|
63
|
+
);
|
|
64
|
+
const present = createPresence(
|
|
65
|
+
() => api().open,
|
|
66
|
+
() => [backdrop, positioner],
|
|
67
|
+
);
|
|
68
|
+
return (
|
|
69
|
+
<Show when={present()}>
|
|
70
|
+
<Portal>
|
|
71
|
+
{/* Nothing inside opens an overlay from a control outside it. */}
|
|
72
|
+
<TriggerContext value={null}>
|
|
73
|
+
{/* A press on the scrim keeps the focus in the dialog: a dialog that cannot be
|
|
74
|
+
dismissed stays open, and the focus would go to the page.
|
|
75
|
+
The backdrop and the dialog stay shown until their exit animation ends; Zag
|
|
76
|
+
would hide them as the dialog closes. */}
|
|
77
|
+
{/* oxlint-disable-next-line jsx-a11y/no-static-element-interactions -- not a control: the handler only keeps the focus where it is */}
|
|
78
|
+
<div
|
|
79
|
+
{...api().getBackdropProps()}
|
|
80
|
+
ref={(element) => (backdrop = element)}
|
|
81
|
+
hidden={false}
|
|
82
|
+
onMouseDown={(event) => event.preventDefault()}
|
|
83
|
+
class="{{prefix}}-dialog__backdrop"
|
|
84
|
+
/>
|
|
85
|
+
<div
|
|
86
|
+
{...api().getPositionerProps()}
|
|
87
|
+
ref={(element) => (positioner = element)}
|
|
88
|
+
class="{{prefix}}-dialog__positioner"
|
|
89
|
+
>
|
|
90
|
+
<section
|
|
91
|
+
{...contentProps}
|
|
92
|
+
ref={(element) => (content = element)}
|
|
93
|
+
hidden={false}
|
|
94
|
+
class={classes("{{prefix}}-dialog", props.class)}
|
|
95
|
+
>
|
|
96
|
+
<h2 {...api().getTitleProps()} class="{{prefix}}-dialog__title">
|
|
97
|
+
{props.title}
|
|
98
|
+
</h2>
|
|
99
|
+
<Show when={props.description}>
|
|
100
|
+
<p {...api().getDescriptionProps()} class="{{prefix}}-dialog__description">
|
|
101
|
+
{props.description}
|
|
102
|
+
</p>
|
|
103
|
+
</Show>
|
|
104
|
+
{/* `when` reads each slot once, and the accessor hands back those same nodes. */}
|
|
105
|
+
<Show when={props.children}>
|
|
106
|
+
{(body) => <div class="{{prefix}}-dialog__body">{body()}</div>}
|
|
107
|
+
</Show>
|
|
108
|
+
<Show when={props.actions}>
|
|
109
|
+
{(actions) => <div class="{{prefix}}-dialog__actions">{actions()}</div>}
|
|
110
|
+
</Show>
|
|
111
|
+
</section>
|
|
112
|
+
</div>
|
|
113
|
+
</TriggerContext>
|
|
114
|
+
</Portal>
|
|
115
|
+
</Show>
|
|
116
|
+
);
|
|
117
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
// Ejected from `@xds/solid` 1.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, rootAttributes } from "@xds/solid/base";
|
|
5
|
+
import { dividerClass } from "./divider.ts";
|
|
6
|
+
import { classes, rootPart } from "./parts.ts";
|
|
7
|
+
|
|
8
|
+
export type DividerProps = RootProps;
|
|
9
|
+
|
|
10
|
+
const ROOT = rootPart("Divider");
|
|
11
|
+
|
|
12
|
+
/** A line between groups of content. Decorative lines use the low-contrast border color. */
|
|
13
|
+
export function Divider(props: DividerProps) {
|
|
14
|
+
return (
|
|
15
|
+
<hr
|
|
16
|
+
{...rootAttributes(props)}
|
|
17
|
+
class={classes(ROOT, dividerClass, props.class)}
|
|
18
|
+
style={props.style}
|
|
19
|
+
/>
|
|
20
|
+
);
|
|
21
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
// Ejected from `@xds/solid` 1.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, rootAttributes } from "@xds/solid/base";
|
|
5
|
+
import { type Element, Show } from "solid-js";
|
|
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?: Element;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
const ROOT = rootPart("EmptyState");
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* What a screen or a list says when it has nothing to show. It centers itself in its container,
|
|
20
|
+
* also vertically when the container is a flex box with room to spare.
|
|
21
|
+
*/
|
|
22
|
+
export function EmptyState(props: EmptyStateProps) {
|
|
23
|
+
return (
|
|
24
|
+
<div
|
|
25
|
+
{...rootAttributes(props)}
|
|
26
|
+
class={classes(ROOT, EMPTY_STATE_PARTS.root, props.class)}
|
|
27
|
+
style={props.style}
|
|
28
|
+
>
|
|
29
|
+
<Icon name={props.icon} size="xl" class={EMPTY_STATE_PARTS.icon} />
|
|
30
|
+
<p class={EMPTY_STATE_PARTS.title}>{props.title}</p>
|
|
31
|
+
<Show when={props.description}>
|
|
32
|
+
{(description) => <p class={EMPTY_STATE_PARTS.description}>{description()}</p>}
|
|
33
|
+
</Show>
|
|
34
|
+
<Show when={props.action}>
|
|
35
|
+
{(action) => <div class={EMPTY_STATE_PARTS.action}>{action()}</div>}
|
|
36
|
+
</Show>
|
|
37
|
+
</div>
|
|
38
|
+
);
|
|
39
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
// Ejected from `@xds/solid` 1.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 { icons, type RootProps, rootAttributes, useDefaults } from "@xds/solid/base";
|
|
5
|
+
import { For } from "solid-js";
|
|
6
|
+
import { type IconBaseProps, iconClass } from "./icon.ts";
|
|
7
|
+
import { classes, rootPart } from "./parts.ts";
|
|
8
|
+
|
|
9
|
+
export type IconProps = IconBaseProps & RootProps;
|
|
10
|
+
|
|
11
|
+
const ROOT = rootPart("Icon");
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* An icon from design/icons. It takes the color of the text around it. An arrow or a chevron
|
|
15
|
+
* mirrors itself in a right-to-left layout when given `rtl:-scale-x-100` in `class`.
|
|
16
|
+
*/
|
|
17
|
+
export function Icon(props: IconProps) {
|
|
18
|
+
const defaults = useDefaults("Icon");
|
|
19
|
+
return (
|
|
20
|
+
<svg
|
|
21
|
+
{...rootAttributes(props)}
|
|
22
|
+
viewBox="0 0 24 24"
|
|
23
|
+
fill={props.filled ? "currentColor" : "none"}
|
|
24
|
+
stroke="currentColor"
|
|
25
|
+
stroke-width="2"
|
|
26
|
+
stroke-linecap="round"
|
|
27
|
+
stroke-linejoin="round"
|
|
28
|
+
class={classes(ROOT, iconClass(props.size ?? defaults().size), props.class)}
|
|
29
|
+
style={props.style}
|
|
30
|
+
role={props.label ? "img" : undefined}
|
|
31
|
+
aria-label={props.label || undefined}
|
|
32
|
+
aria-hidden={props.label ? undefined : "true"}
|
|
33
|
+
>
|
|
34
|
+
<For each={icons[props.name]}>{(path) => <path d={path} />}</For>
|
|
35
|
+
</svg>
|
|
36
|
+
);
|
|
37
|
+
}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
// Ejected from `@xds/solid` 1.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, rootAttributes, useDefaults, withTrigger } from "@xds/solid/base";
|
|
5
|
+
import type { JSX } from "@solidjs/web";
|
|
6
|
+
import { createMemo, Show } from "solid-js";
|
|
7
|
+
import { buttonClass, ICON_BUTTON_BOX, type IconButtonBaseProps, isHeld } from "./button.ts";
|
|
8
|
+
import { Icon } from "./Icon.tsx";
|
|
9
|
+
import { classes } from "./parts.ts";
|
|
10
|
+
import { Spinner } from "./Spinner.tsx";
|
|
11
|
+
|
|
12
|
+
export type IconButtonProps = IconButtonBaseProps &
|
|
13
|
+
RootProps & {
|
|
14
|
+
onPress?: () => void;
|
|
15
|
+
onFocus?: JSX.FocusEventHandler<HTMLButtonElement, FocusEvent>;
|
|
16
|
+
onBlur?: JSX.FocusEventHandler<HTMLButtonElement, FocusEvent>;
|
|
17
|
+
/** The native button. */
|
|
18
|
+
ref?: JSX.Ref<HTMLButtonElement>;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* A button that holds only an icon, in Button's variants, sizes and states. It is a square as
|
|
23
|
+
* tall as a Button of its size, and its pressable area is never smaller than the minimum
|
|
24
|
+
* target, even when the square is. Like Button, it opens a Menu or a Tooltip it is the trigger
|
|
25
|
+
* of.
|
|
26
|
+
*/
|
|
27
|
+
export function IconButton(props: IconButtonProps) {
|
|
28
|
+
const defaults = useDefaults("IconButton");
|
|
29
|
+
const variant = () => props.variant ?? defaults().variant ?? "ghost";
|
|
30
|
+
const size = () => props.size ?? defaults().size ?? "md";
|
|
31
|
+
const attributes = withTrigger(
|
|
32
|
+
createMemo((): JSX.ButtonHTMLAttributes<HTMLButtonElement> => ({
|
|
33
|
+
type: "button",
|
|
34
|
+
// Its root part, `{{prefix}}-icon-button`, is in the recipe.
|
|
35
|
+
class: classes(
|
|
36
|
+
buttonClass({ variant: variant(), size: size(), iconButton: true }),
|
|
37
|
+
props.class,
|
|
38
|
+
),
|
|
39
|
+
style: props.style,
|
|
40
|
+
disabled: props.disabled,
|
|
41
|
+
"aria-disabled": props.loading ? "true" : undefined,
|
|
42
|
+
"data-pending": props.loading ? "" : undefined,
|
|
43
|
+
"aria-pressed": props.selected === undefined ? undefined : props.selected ? "true" : "false",
|
|
44
|
+
"aria-label": props.label,
|
|
45
|
+
onClick: () => {
|
|
46
|
+
if (!props.loading) props.onPress?.();
|
|
47
|
+
},
|
|
48
|
+
onFocus: (event) => props.onFocus?.(event),
|
|
49
|
+
onBlur: (event) => props.onBlur?.(event),
|
|
50
|
+
})),
|
|
51
|
+
() => props.loading === true,
|
|
52
|
+
rootAttributes(props),
|
|
53
|
+
);
|
|
54
|
+
return (
|
|
55
|
+
<button ref={props.ref} {...attributes}>
|
|
56
|
+
<Show
|
|
57
|
+
when={!props.loading}
|
|
58
|
+
fallback={
|
|
59
|
+
<span class={ICON_BUTTON_BOX[size()]}>
|
|
60
|
+
<Spinner size="sm" />
|
|
61
|
+
</span>
|
|
62
|
+
}
|
|
63
|
+
>
|
|
64
|
+
<Icon
|
|
65
|
+
name={props.icon}
|
|
66
|
+
size={size()}
|
|
67
|
+
filled={isHeld({
|
|
68
|
+
variant: variant(),
|
|
69
|
+
selected: props.selected,
|
|
70
|
+
disabled: props.disabled,
|
|
71
|
+
})}
|
|
72
|
+
/>
|
|
73
|
+
</Show>
|
|
74
|
+
</button>
|
|
75
|
+
);
|
|
76
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
// Ejected from `@xds/solid` 1.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 { composeRefs, type RootProps, rootAttributes } from "@xds/solid/base";
|
|
5
|
+
import { dynamic, type JSX } from "@solidjs/web";
|
|
6
|
+
import { createMemo, type Element, Show } from "solid-js";
|
|
7
|
+
import { Icon } from "./Icon.tsx";
|
|
8
|
+
import { LINK_ICON, LINK_PARTS, type LinkBaseProps, linkElement } from "./link.ts";
|
|
9
|
+
import { classes, rootPart } from "./parts.ts";
|
|
10
|
+
|
|
11
|
+
export type LinkProps = LinkBaseProps &
|
|
12
|
+
RootProps & {
|
|
13
|
+
/** Called on a press, before the browser follows `href`. A disabled link never calls it. */
|
|
14
|
+
onPress?: () => void;
|
|
15
|
+
onFocus?: JSX.FocusEventHandler<HTMLElement, FocusEvent>;
|
|
16
|
+
onBlur?: JSX.FocusEventHandler<HTMLElement, FocusEvent>;
|
|
17
|
+
/** The native element: an `<a>`, or a `<button>` for a link without `href`. */
|
|
18
|
+
ref?: JSX.Ref<HTMLElement>;
|
|
19
|
+
/** The text, which names the link. */
|
|
20
|
+
children: Element;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
const ROOT = rootPart("Link");
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Text that takes the person somewhere, in the type of the text around it. It is underlined, so
|
|
27
|
+
* it does not depend on color. With `href` it is a native link; without one, a button that
|
|
28
|
+
* assistive technology hears as a link.
|
|
29
|
+
*/
|
|
30
|
+
export function Link(props: LinkProps) {
|
|
31
|
+
const element = createMemo(() =>
|
|
32
|
+
linkElement({ href: props.href, external: props.external, disabled: props.disabled }),
|
|
33
|
+
);
|
|
34
|
+
const Tag = dynamic(() => element().tag);
|
|
35
|
+
// Either element can take it, so it is typed by what both are, which a dynamic tag's own ref
|
|
36
|
+
// prop is not.
|
|
37
|
+
const ref = composeRefs<HTMLElement>(
|
|
38
|
+
() => {},
|
|
39
|
+
() => props.ref,
|
|
40
|
+
);
|
|
41
|
+
type Focus = FocusEvent & { currentTarget: HTMLElement; target: globalThis.Element };
|
|
42
|
+
return (
|
|
43
|
+
<Tag
|
|
44
|
+
ref={ref}
|
|
45
|
+
{...rootAttributes(props)}
|
|
46
|
+
{...element().attributes}
|
|
47
|
+
class={classes(ROOT, props.class)}
|
|
48
|
+
style={props.style}
|
|
49
|
+
onClick={() => {
|
|
50
|
+
if (!props.disabled) props.onPress?.();
|
|
51
|
+
}}
|
|
52
|
+
onFocus={(event: Focus) => props.onFocus?.(event)}
|
|
53
|
+
onBlur={(event: Focus) => props.onBlur?.(event)}
|
|
54
|
+
>
|
|
55
|
+
{props.children}
|
|
56
|
+
<Show when={props.external}>
|
|
57
|
+
<Icon name={LINK_ICON.name} size={LINK_ICON.size} class={LINK_PARTS.icon} />
|
|
58
|
+
</Show>
|
|
59
|
+
</Tag>
|
|
60
|
+
);
|
|
61
|
+
}
|