@xds/solid 0.0.0-stage → 0.1.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/dom/Accordion.js +139 -0
- package/dist/dom/Avatar.js +59 -0
- package/dist/dom/AvatarStack.js +74 -0
- package/dist/dom/Badge.js +58 -0
- package/dist/dom/Banner.js +102 -0
- package/dist/dom/Button.js +107 -0
- package/dist/dom/Card.js +164 -0
- package/dist/dom/Checkbox.js +64 -0
- package/dist/dom/Chip.js +52 -0
- package/dist/dom/ChipBar.js +28 -0
- package/dist/dom/CountBadge.js +67 -0
- package/dist/dom/DatePicker.js +300 -0
- package/dist/dom/DateRangePicker.js +404 -0
- package/dist/dom/Defaults.js +29 -0
- package/dist/dom/Dialog.js +136 -0
- package/dist/dom/Divider.js +20 -0
- package/dist/dom/EmptyState.js +70 -0
- package/dist/dom/Icon.js +46 -0
- package/dist/dom/IconButton.js +72 -0
- package/dist/dom/ListRow.js +126 -0
- package/dist/dom/MediaCard.js +178 -0
- package/dist/dom/Menu.js +176 -0
- package/dist/dom/ProgressBar.js +33 -0
- package/dist/dom/RadioGroup.js +123 -0
- package/dist/dom/SearchField.js +94 -0
- package/dist/dom/SectionHeader.js +104 -0
- package/dist/dom/SegmentedControl.js +69 -0
- package/dist/dom/Select.js +271 -0
- package/dist/dom/Sidebar.js +233 -0
- package/dist/dom/Skeleton.js +34 -0
- package/dist/dom/Slider.js +115 -0
- package/dist/dom/Spinner.js +35 -0
- package/dist/dom/Switch.js +65 -0
- package/dist/dom/Tabs.js +80 -0
- package/dist/dom/Text.js +24 -0
- package/dist/dom/TextField.js +172 -0
- package/dist/dom/Thumbnail.js +119 -0
- package/dist/dom/Toast.js +99 -0
- package/dist/dom/Tooltip.js +128 -0
- package/dist/dom/controlled.js +13 -0
- package/dist/dom/index.js +40 -0
- package/dist/dom/modal-popover.js +22 -0
- package/dist/dom/picture.js +29 -0
- package/dist/dom/presence.js +20 -0
- package/dist/dom/preview.js +139 -0
- package/dist/dom/root.js +26 -0
- package/dist/dom/trigger.js +31 -0
- package/dist/source/Accordion.d.ts +21 -0
- package/dist/source/Accordion.jsx +57 -0
- package/dist/source/Avatar.d.ts +9 -0
- package/dist/source/Avatar.jsx +16 -0
- package/dist/source/AvatarStack.d.ts +8 -0
- package/dist/source/AvatarStack.jsx +22 -0
- package/dist/source/Badge.d.ts +13 -0
- package/dist/source/Badge.jsx +15 -0
- package/dist/source/Banner.d.ts +23 -0
- package/dist/source/Banner.jsx +32 -0
- package/dist/source/Button.d.ts +15 -0
- package/dist/source/Button.jsx +48 -0
- package/dist/source/Card.d.ts +18 -0
- package/dist/source/Card.jsx +46 -0
- package/dist/source/Checkbox.d.ts +10 -0
- package/dist/source/Checkbox.jsx +20 -0
- package/dist/source/Chip.d.ts +12 -0
- package/dist/source/Chip.jsx +12 -0
- package/dist/source/ChipBar.d.ts +12 -0
- package/dist/source/ChipBar.jsx +7 -0
- package/dist/source/CountBadge.d.ts +12 -0
- package/dist/source/CountBadge.jsx +17 -0
- package/dist/source/DatePicker.d.ts +20 -0
- package/dist/source/DatePicker.jsx +109 -0
- package/dist/source/DateRangePicker.d.ts +24 -0
- package/dist/source/DateRangePicker.jsx +150 -0
- package/dist/source/Defaults.d.ts +23 -0
- package/dist/source/Defaults.jsx +12 -0
- package/dist/source/Dialog.d.ts +21 -0
- package/dist/source/Dialog.jsx +58 -0
- package/dist/source/Divider.d.ts +4 -0
- package/dist/source/Divider.jsx +5 -0
- package/dist/source/EmptyState.d.ts +12 -0
- package/dist/source/EmptyState.jsx +16 -0
- package/dist/source/Icon.d.ts +8 -0
- package/dist/source/Icon.jsx +11 -0
- package/dist/source/IconButton.d.ts +13 -0
- package/dist/source/IconButton.jsx +36 -0
- package/dist/source/ListRow.d.ts +21 -0
- package/dist/source/ListRow.jsx +38 -0
- package/dist/source/MediaCard.d.ts +20 -0
- package/dist/source/MediaCard.jsx +47 -0
- package/dist/source/Menu.d.ts +19 -0
- package/dist/source/Menu.jsx +99 -0
- package/dist/source/ProgressBar.d.ts +8 -0
- package/dist/source/ProgressBar.jsx +8 -0
- package/dist/source/RadioGroup.d.ts +15 -0
- package/dist/source/RadioGroup.jsx +57 -0
- package/dist/source/SearchField.d.ts +15 -0
- package/dist/source/SearchField.jsx +39 -0
- package/dist/source/SectionHeader.d.ts +14 -0
- package/dist/source/SectionHeader.jsx +32 -0
- package/dist/source/SegmentedControl.d.ts +12 -0
- package/dist/source/SegmentedControl.jsx +21 -0
- package/dist/source/Select.d.ts +18 -0
- package/dist/source/Select.jsx +139 -0
- package/dist/source/Sidebar.d.ts +22 -0
- package/dist/source/Sidebar.jsx +65 -0
- package/dist/source/Skeleton.d.ts +11 -0
- package/dist/source/Skeleton.jsx +9 -0
- package/dist/source/Slider.d.ts +13 -0
- package/dist/source/Slider.jsx +69 -0
- package/dist/source/Spinner.d.ts +9 -0
- package/dist/source/Spinner.jsx +12 -0
- package/dist/source/Switch.d.ts +13 -0
- package/dist/source/Switch.jsx +18 -0
- package/dist/source/Tabs.d.ts +14 -0
- package/dist/source/Tabs.jsx +31 -0
- package/dist/source/Text.d.ts +10 -0
- package/dist/source/Text.jsx +14 -0
- package/dist/source/TextField.d.ts +22 -0
- package/dist/source/TextField.jsx +73 -0
- package/dist/source/Thumbnail.d.ts +9 -0
- package/dist/source/Thumbnail.jsx +34 -0
- package/dist/source/Toast.d.ts +16 -0
- package/dist/source/Toast.jsx +42 -0
- package/dist/source/Tooltip.d.ts +28 -0
- package/dist/source/Tooltip.jsx +52 -0
- package/dist/source/controlled.d.ts +4 -0
- package/dist/source/controlled.js +11 -0
- package/dist/source/index.d.ts +40 -0
- package/dist/source/index.js +39 -0
- package/dist/source/modal-popover.d.ts +7 -0
- package/dist/source/modal-popover.js +15 -0
- package/dist/source/picture.d.ts +20 -0
- package/dist/source/picture.js +13 -0
- package/dist/source/presence.d.ts +7 -0
- package/dist/source/presence.js +13 -0
- package/dist/source/preview.d.ts +6 -0
- package/dist/source/preview.jsx +110 -0
- package/dist/source/root.d.ts +25 -0
- package/dist/source/root.js +19 -0
- package/dist/source/trigger.d.ts +18 -0
- package/dist/source/trigger.js +18 -0
- package/package.json +63 -4
- package/page.css +20 -0
- package/styles.css +3353 -0
- package/tailwind.css +2665 -0
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { type CountBadgeBaseProps } from "@xds/core";
|
|
2
|
+
import { type Element } from "solid-js";
|
|
3
|
+
import type { RootProps } from "./root.ts";
|
|
4
|
+
export type CountBadgeProps = CountBadgeBaseProps & RootProps & {
|
|
5
|
+
/** What the count belongs to: an icon, an avatar, a button. The badge sits on its corner. */
|
|
6
|
+
children?: Element;
|
|
7
|
+
};
|
|
8
|
+
/**
|
|
9
|
+
* A count of something waiting: unread messages, items in a cart. On its own it is laid out
|
|
10
|
+
* inline; around a child it sits on the child's top end corner.
|
|
11
|
+
*/
|
|
12
|
+
export declare function CountBadge(props: CountBadgeProps): import("@solidjs/web").JSX.Element;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { countBadgeAnchorClass, countBadgeClass, countBadgeText, classes, rootPart, } from "@xds/core";
|
|
2
|
+
import { children, Show } from "solid-js";
|
|
3
|
+
const ROOT = rootPart("CountBadge");
|
|
4
|
+
export function CountBadge(props) {
|
|
5
|
+
const child = children(() => props.children);
|
|
6
|
+
const badge = (onChild) => (<Show when={props.count > 0}>
|
|
7
|
+
<span role={props.label ? "img" : undefined} aria-label={props.label || undefined} class={classes(!onChild && ROOT, countBadgeClass(onChild), !onChild && props.class)} style={onChild ? undefined : props.style}>
|
|
8
|
+
{countBadgeText(props.count, props.max)}
|
|
9
|
+
</span>
|
|
10
|
+
</Show>);
|
|
11
|
+
return (<Show when={child() != null} fallback={badge(false)}>
|
|
12
|
+
<span class={classes(ROOT, countBadgeAnchorClass, props.class)} style={props.style}>
|
|
13
|
+
{child()}
|
|
14
|
+
{badge(true)}
|
|
15
|
+
</span>
|
|
16
|
+
</Show>);
|
|
17
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { type DatePickerBaseProps, type IsoDate } from "@xds/core";
|
|
2
|
+
import { type RootProps } from "./root.ts";
|
|
3
|
+
export type { IsoDate } from "@xds/core";
|
|
4
|
+
export type DatePickerProps = DatePickerBaseProps & RootProps & {
|
|
5
|
+
onChange: (value: IsoDate) => void;
|
|
6
|
+
};
|
|
7
|
+
/**
|
|
8
|
+
* A field for choosing one day. Closed, it looks like a Select: the chosen day in the locale's
|
|
9
|
+
* medium form, or the placeholder. Pressed, it opens a calendar of one month under itself, on
|
|
10
|
+
* the chosen day, or on today while none is. A press on a day, or Enter on the focused one,
|
|
11
|
+
* calls `onChange` with the day as `YYYY-MM-DD` and closes the calendar; Escape or a press
|
|
12
|
+
* outside closes it without a choice.
|
|
13
|
+
*
|
|
14
|
+
* The field is a button that says it opens a dialog and whether it is open. In the calendar the
|
|
15
|
+
* arrow keys move a day or a week, Page Up and Page Down a month (a year with Shift), and Home
|
|
16
|
+
* and End to the first and the last day of the month, never past `min` or `max`. Tab goes round
|
|
17
|
+
* the month buttons and the focused day. The chosen day is selected for assistive technology,
|
|
18
|
+
* and today is the current date.
|
|
19
|
+
*/
|
|
20
|
+
export declare function DatePicker(props: DatePickerProps): import("@solidjs/web").JSX.Element;
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { classes, DATE_PICKER_NAV_CLASS, datePickerContentAttrs, datePickerIds, datePickerLocale, datePickerMachineProps, datePickerTriggerAttrs, focusOpeningDay, formatDay, keepCalendarFocus, keepDayFocused, } from "@xds/core";
|
|
2
|
+
import { Portal } from "@solidjs/web";
|
|
3
|
+
import * as datePicker from "@zag-js/date-picker";
|
|
4
|
+
import { normalizeProps, useMachine } from "@zag-js/solid";
|
|
5
|
+
import { createEffect, createMemo, createUniqueId, For, Show } from "solid-js";
|
|
6
|
+
import { Icon } from "./Icon.jsx";
|
|
7
|
+
import { modalPopover } from "./modal-popover.js";
|
|
8
|
+
import { createPresence } from "./presence.js";
|
|
9
|
+
import { withStyle } from "./root.js";
|
|
10
|
+
export function DatePicker(props) {
|
|
11
|
+
const id = createUniqueId();
|
|
12
|
+
const ids = datePickerIds(id);
|
|
13
|
+
const locale = datePickerLocale();
|
|
14
|
+
const service = useMachine(datePicker.machine, () => datePickerMachineProps(props, { id, locale, onChange: (value) => props.onChange(value) }));
|
|
15
|
+
const api = createMemo(() => datePicker.connect(service, normalizeProps));
|
|
16
|
+
const root = withStyle(() => api().getRootProps(), () => props.style);
|
|
17
|
+
let positioner;
|
|
18
|
+
let surface;
|
|
19
|
+
modalPopover(() => api().open, () => positioner);
|
|
20
|
+
const present = createPresence(() => api().open, () => [surface]);
|
|
21
|
+
const open = createMemo(() => api().open);
|
|
22
|
+
const focused = createMemo(() => api().focusedValue.toString());
|
|
23
|
+
const month = createMemo(() => api().visibleRange.start.toString());
|
|
24
|
+
createEffect(() => [open(), focused(), month()], ([isOpen]) => keepDayFocused(isOpen, surface));
|
|
25
|
+
const invalid = () => props.error !== undefined;
|
|
26
|
+
return (<div {...root} class={classes("xds-date-picker", props.class)}>
|
|
27
|
+
|
|
28
|
+
<span id={ids.label} class="xds-date-picker__label">
|
|
29
|
+
{props.label}
|
|
30
|
+
</span>
|
|
31
|
+
|
|
32
|
+
<div {...api().getControlProps()} class="xds-date-picker__control">
|
|
33
|
+
<button {...api().getTriggerProps()} {...datePickerTriggerAttrs(props, ids)} type="button" onClick={(event) => {
|
|
34
|
+
focusOpeningDay(api(), props);
|
|
35
|
+
api().getTriggerProps().onClick?.(event);
|
|
36
|
+
}} class="xds-date-picker__trigger">
|
|
37
|
+
<span id={ids.value} class="xds-date-picker__value">
|
|
38
|
+
{props.value === undefined ? props.placeholder : formatDay(props.value, locale)}
|
|
39
|
+
</span>
|
|
40
|
+
<Icon name="calendar" size="sm" class="text-xds-field-placeholder"/>
|
|
41
|
+
</button>
|
|
42
|
+
</div>
|
|
43
|
+
|
|
44
|
+
<Show when={invalid() || props.description}>
|
|
45
|
+
<div class="xds-date-picker__footer">
|
|
46
|
+
<Show when={invalid()} fallback={<span id={ids.description} class="xds-date-picker__description">
|
|
47
|
+
{props.description}
|
|
48
|
+
</span>}>
|
|
49
|
+
<span id={ids.error} class="xds-date-picker__error">
|
|
50
|
+
{props.error}
|
|
51
|
+
</span>
|
|
52
|
+
</Show>
|
|
53
|
+
</div>
|
|
54
|
+
</Show>
|
|
55
|
+
|
|
56
|
+
<Show when={props.name !== undefined}>
|
|
57
|
+
<input type="hidden" name={props.name} value={props.value ?? ""}/>
|
|
58
|
+
</Show>
|
|
59
|
+
<Portal>
|
|
60
|
+
<Show when={api().open}>
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
<div class="xds-date-picker__underlay" onMouseDown={(event) => event.preventDefault()}/>
|
|
64
|
+
</Show>
|
|
65
|
+
<div ref={(element) => (positioner = element)} {...api().getPositionerProps()} class="xds-date-picker__positioner">
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
<div {...api().getContentProps()} {...datePickerContentAttrs(ids)} ref={(element) => (surface = element)} hidden={!present()} onKeyDown={(event) => keepCalendarFocus(event, surface)} class="xds-date-picker__content">
|
|
69
|
+
<div class="xds-date-picker__header">
|
|
70
|
+
<button {...api().getPreviousTriggerProps()} type="button" class={DATE_PICKER_NAV_CLASS}>
|
|
71
|
+
<Icon name="chevron-left" size="sm"/>
|
|
72
|
+
</button>
|
|
73
|
+
<span {...api().getRangeTextProps()} class="xds-date-picker__heading">
|
|
74
|
+
{api().visibleRangeText.start}
|
|
75
|
+
</span>
|
|
76
|
+
<button {...api().getNextTriggerProps()} type="button" class={DATE_PICKER_NAV_CLASS}>
|
|
77
|
+
<Icon name="chevron-right" size="sm"/>
|
|
78
|
+
</button>
|
|
79
|
+
</div>
|
|
80
|
+
<table {...api().getTableProps({ view: "day" })} class="xds-date-picker__grid">
|
|
81
|
+
<thead {...api().getTableHeadProps({ view: "day" })}>
|
|
82
|
+
<tr {...api().getTableRowProps({ view: "day" })}>
|
|
83
|
+
<For each={api().weekDays} keyed={false}>
|
|
84
|
+
{(weekDay) => (<th scope="col" class="xds-date-picker__weekday">
|
|
85
|
+
{weekDay().narrow}
|
|
86
|
+
</th>)}
|
|
87
|
+
</For>
|
|
88
|
+
</tr>
|
|
89
|
+
</thead>
|
|
90
|
+
<tbody {...api().getTableBodyProps({ view: "day" })}>
|
|
91
|
+
|
|
92
|
+
<For each={api().weeks} keyed={false}>
|
|
93
|
+
{(week) => (<tr {...api().getTableRowProps({ view: "day" })}>
|
|
94
|
+
<For each={week()} keyed={false}>
|
|
95
|
+
{(date) => (<td {...api().getDayTableCellProps({ value: date() })} class="xds-date-picker__cell">
|
|
96
|
+
<div {...api().getDayTableCellTriggerProps({ value: date() })} class="xds-date-picker__day">
|
|
97
|
+
{date().day}
|
|
98
|
+
</div>
|
|
99
|
+
</td>)}
|
|
100
|
+
</For>
|
|
101
|
+
</tr>)}
|
|
102
|
+
</For>
|
|
103
|
+
</tbody>
|
|
104
|
+
</table>
|
|
105
|
+
</div>
|
|
106
|
+
</div>
|
|
107
|
+
</Portal>
|
|
108
|
+
</div>);
|
|
109
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { type DateRange, type DateRangePickerBaseProps } from "@xds/core";
|
|
2
|
+
import { type RootProps } from "./root.ts";
|
|
3
|
+
export type { DateRange } from "@xds/core";
|
|
4
|
+
export type DateRangePickerProps = DateRangePickerBaseProps & RootProps & {
|
|
5
|
+
onChange: (value: DateRange) => void;
|
|
6
|
+
};
|
|
7
|
+
/**
|
|
8
|
+
* A field for choosing a range of days, a start and an end, as for a stay. Closed, it looks like
|
|
9
|
+
* a DatePicker and shows both days in the locale's medium form ("Mar 10 – 14, 2026"), or the
|
|
10
|
+
* placeholder. Pressed, it opens a calendar under itself, two months side by side where the
|
|
11
|
+
* window has room and one where it does not, on the start's month, or on today's while nothing
|
|
12
|
+
* is chosen.
|
|
13
|
+
*
|
|
14
|
+
* The first day pressed starts the range, and the band previews it to the day under the pointer
|
|
15
|
+
* or the keyboard's focus. The second ends it, if the days between are at least `minLength` and
|
|
16
|
+
* at most `maxLength`, which leave the other days unavailable meanwhile: `onChange` gets the
|
|
17
|
+
* range and the calendar closes. A day before the start starts again from there. Escape or a
|
|
18
|
+
* press outside closes the calendar without a change.
|
|
19
|
+
*
|
|
20
|
+
* The keys are DatePicker's, and Page Up and Page Down move a month whether one or two are
|
|
21
|
+
* shown. Each month is a grid named by its month; every day of the range is selected, and the
|
|
22
|
+
* two ends are named by `startLabel` and `endLabel` before the day.
|
|
23
|
+
*/
|
|
24
|
+
export declare function DateRangePicker(props: DateRangePickerProps): import("@solidjs/web").JSX.Element;
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
import { classes, DATE_PICKER_NAV_CLASS, dateRangeMachineProps, datePickerContentAttrs, datePickerIds, datePickerLocale, datePickerTriggerAttrs, endRangeChoiceOnClose, focusOpeningDay, formatRange, keepCalendarFocus, keepDayFocused, keepRangePreview, rangeDayClick, rangeGridKeyDown, rangeMonths, rangeMonthViews, rangeSummary, shownRange, } from "@xds/core";
|
|
2
|
+
import { Portal } from "@solidjs/web";
|
|
3
|
+
import * as datePicker from "@zag-js/date-picker";
|
|
4
|
+
import { normalizeProps, useMachine } from "@zag-js/solid";
|
|
5
|
+
import { createEffect, createMemo, createSignal, createUniqueId, For, Show } from "solid-js";
|
|
6
|
+
import { Icon } from "./Icon.jsx";
|
|
7
|
+
import { modalPopover } from "./modal-popover.js";
|
|
8
|
+
import { createPresence } from "./presence.js";
|
|
9
|
+
import { withStyle } from "./root.js";
|
|
10
|
+
export function DateRangePicker(props) {
|
|
11
|
+
const id = createUniqueId();
|
|
12
|
+
const ids = datePickerIds(id);
|
|
13
|
+
const locale = datePickerLocale();
|
|
14
|
+
const [draft, setDraft] = createSignal(null);
|
|
15
|
+
const [months, setMonths] = createSignal(1);
|
|
16
|
+
const shown = createMemo(() => shownRange(props.value, draft()));
|
|
17
|
+
const service = useMachine(datePicker.machine, () => dateRangeMachineProps(props, shown(), {
|
|
18
|
+
id,
|
|
19
|
+
locale,
|
|
20
|
+
months: months(),
|
|
21
|
+
onDraft: (next) => setDraft(() => next),
|
|
22
|
+
onChange: (value) => props.onChange(value),
|
|
23
|
+
}));
|
|
24
|
+
const api = createMemo(() => datePicker.connect(service, normalizeProps));
|
|
25
|
+
const root = withStyle(() => api().getRootProps(), () => props.style);
|
|
26
|
+
let positioner;
|
|
27
|
+
let surface;
|
|
28
|
+
modalPopover(() => api().open, () => positioner);
|
|
29
|
+
const present = createPresence(() => api().open, () => [surface]);
|
|
30
|
+
const open = createMemo(() => api().open);
|
|
31
|
+
const focused = createMemo(() => api().focusedValue.toString());
|
|
32
|
+
const month = createMemo(() => api().visibleRange.start.toString());
|
|
33
|
+
createEffect(() => [open(), focused(), month()], ([isOpen]) => keepDayFocused(isOpen, surface));
|
|
34
|
+
createEffect(open, (isOpen) => endRangeChoiceOnClose(service, isOpen));
|
|
35
|
+
createEffect(focused, () => keepRangePreview(service, shown(), open()));
|
|
36
|
+
const summary = createMemo(() => rangeSummary(shown(), props, locale));
|
|
37
|
+
const views = createMemo(() => rangeMonthViews(api(), months()));
|
|
38
|
+
const invalid = () => props.error !== undefined;
|
|
39
|
+
return (<div {...root} class={classes("xds-date-picker xds-date-range-picker", props.class)}>
|
|
40
|
+
|
|
41
|
+
<span id={ids.label} class="xds-date-picker__label">
|
|
42
|
+
{props.label}
|
|
43
|
+
</span>
|
|
44
|
+
|
|
45
|
+
<div {...api().getControlProps()} class="xds-date-picker__control">
|
|
46
|
+
<button {...api().getTriggerProps()} {...datePickerTriggerAttrs(props, ids)} type="button" onClick={(event) => {
|
|
47
|
+
if (!api().open)
|
|
48
|
+
setMonths(rangeMonths());
|
|
49
|
+
focusOpeningDay(api(), { ...props, value: props.value?.start });
|
|
50
|
+
api().getTriggerProps().onClick?.(event);
|
|
51
|
+
}} class="xds-date-picker__trigger">
|
|
52
|
+
<span id={ids.value} class="xds-date-picker__value">
|
|
53
|
+
{props.value === undefined ? props.placeholder : formatRange(props.value, locale)}
|
|
54
|
+
</span>
|
|
55
|
+
<Icon name="calendar" size="sm" class="text-xds-field-placeholder"/>
|
|
56
|
+
</button>
|
|
57
|
+
</div>
|
|
58
|
+
|
|
59
|
+
<Show when={invalid() || props.description}>
|
|
60
|
+
<div class="xds-date-picker__footer">
|
|
61
|
+
<Show when={invalid()} fallback={<span id={ids.description} class="xds-date-picker__description">
|
|
62
|
+
{props.description}
|
|
63
|
+
</span>}>
|
|
64
|
+
<span id={ids.error} class="xds-date-picker__error">
|
|
65
|
+
{props.error}
|
|
66
|
+
</span>
|
|
67
|
+
</Show>
|
|
68
|
+
</div>
|
|
69
|
+
</Show>
|
|
70
|
+
|
|
71
|
+
<Show when={props.startName !== undefined}>
|
|
72
|
+
<input type="hidden" name={props.startName} value={props.value?.start ?? ""}/>
|
|
73
|
+
</Show>
|
|
74
|
+
<Show when={props.endName !== undefined}>
|
|
75
|
+
<input type="hidden" name={props.endName} value={props.value?.end ?? ""}/>
|
|
76
|
+
</Show>
|
|
77
|
+
<Portal>
|
|
78
|
+
<Show when={api().open}>
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
<div class="xds-date-picker__underlay" onMouseDown={(event) => event.preventDefault()}/>
|
|
82
|
+
</Show>
|
|
83
|
+
<div ref={(element) => (positioner = element)} {...api().getPositionerProps()} class="xds-date-picker__positioner">
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
<div {...api().getContentProps()} {...datePickerContentAttrs(ids)} ref={(element) => (surface = element)} hidden={!present()} onKeyDown={(event) => keepCalendarFocus(event, surface)} class="xds-date-picker__content xds-date-range-picker__content">
|
|
87
|
+
<div class="xds-date-range-picker__summary" aria-live="polite">
|
|
88
|
+
<span>{summary().start}</span>
|
|
89
|
+
<span>{summary().end}</span>
|
|
90
|
+
</div>
|
|
91
|
+
<div class="xds-date-range-picker__months">
|
|
92
|
+
|
|
93
|
+
<For each={views()} keyed={false}>
|
|
94
|
+
{(view) => (<div class="xds-date-range-picker__month">
|
|
95
|
+
<div class="xds-date-picker__header">
|
|
96
|
+
<Show when={view().index === 0} fallback={<span class="xds-date-range-picker__nav-space"/>}>
|
|
97
|
+
<button {...api().getPreviousTriggerProps()} type="button" class={DATE_PICKER_NAV_CLASS}>
|
|
98
|
+
<Icon name="chevron-left" size="sm"/>
|
|
99
|
+
</button>
|
|
100
|
+
</Show>
|
|
101
|
+
<span {...api().getRangeTextProps()} class="xds-date-picker__heading">
|
|
102
|
+
{view().name}
|
|
103
|
+
</span>
|
|
104
|
+
<Show when={view().index === months() - 1} fallback={<span class="xds-date-range-picker__nav-space"/>}>
|
|
105
|
+
<button {...api().getNextTriggerProps()} type="button" class={DATE_PICKER_NAV_CLASS}>
|
|
106
|
+
<Icon name="chevron-right" size="sm"/>
|
|
107
|
+
</button>
|
|
108
|
+
</Show>
|
|
109
|
+
</div>
|
|
110
|
+
|
|
111
|
+
<table {...api().getTableProps({ view: "day", id: view().table.id })} {...view().table} onKeyDown={(event) => rangeGridKeyDown(event, api(), shown(), props, api().getTableProps({ view: "day", id: view().table.id }).onKeyDown)} class="xds-date-picker__grid">
|
|
112
|
+
<thead {...api().getTableHeadProps({ view: "day" })}>
|
|
113
|
+
<tr {...api().getTableRowProps({ view: "day" })}>
|
|
114
|
+
<For each={api().weekDays} keyed={false}>
|
|
115
|
+
{(weekDay) => (<th scope="col" class="xds-date-picker__weekday">
|
|
116
|
+
{weekDay().narrow}
|
|
117
|
+
</th>)}
|
|
118
|
+
</For>
|
|
119
|
+
</tr>
|
|
120
|
+
</thead>
|
|
121
|
+
<tbody {...api().getTableBodyProps({ view: "day" })}>
|
|
122
|
+
|
|
123
|
+
<For each={view().weeks} keyed={false}>
|
|
124
|
+
{(week) => (<tr {...api().getTableRowProps({ view: "day" })}>
|
|
125
|
+
<For each={week()} keyed={false}>
|
|
126
|
+
{(date) => {
|
|
127
|
+
const cell = () => ({
|
|
128
|
+
value: date(),
|
|
129
|
+
visibleRange: view().visibleRange,
|
|
130
|
+
});
|
|
131
|
+
return (<td {...api().getDayTableCellProps(cell())} class="xds-date-picker__cell">
|
|
132
|
+
|
|
133
|
+
<div {...api().getDayTableCellTriggerProps(cell())} onClick={(event) => rangeDayClick(event, api(), shown(), props, date(), view().visibleRange, api().getDayTableCellTriggerProps(cell()).onClick)} class="xds-date-picker__day">
|
|
134
|
+
{date().day}
|
|
135
|
+
</div>
|
|
136
|
+
</td>);
|
|
137
|
+
}}
|
|
138
|
+
</For>
|
|
139
|
+
</tr>)}
|
|
140
|
+
</For>
|
|
141
|
+
</tbody>
|
|
142
|
+
</table>
|
|
143
|
+
</div>)}
|
|
144
|
+
</For>
|
|
145
|
+
</div>
|
|
146
|
+
</div>
|
|
147
|
+
</div>
|
|
148
|
+
</Portal>
|
|
149
|
+
</div>);
|
|
150
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { type ComponentDefaults, type DefaultedComponent } from "@xds/core";
|
|
2
|
+
import { type Accessor, type Element } from "solid-js";
|
|
3
|
+
export type { ComponentDefaults } from "@xds/core";
|
|
4
|
+
export type DefaultsProps = {
|
|
5
|
+
/**
|
|
6
|
+
* What the components inside take for an option they are not given, by component:
|
|
7
|
+
* `{ Button: { variant: "primary" } }`. Inside another Defaults, it replaces only the options
|
|
8
|
+
* it names.
|
|
9
|
+
*/
|
|
10
|
+
value: ComponentDefaults;
|
|
11
|
+
children: Element;
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* Gives the components inside it their defaults: a component takes the option it is given,
|
|
15
|
+
* then the one the closest Defaults names, then its own default. A change of `value` reaches
|
|
16
|
+
* every component inside.
|
|
17
|
+
*/
|
|
18
|
+
export declare function Defaults(props: DefaultsProps): import("@solidjs/web").JSX.Element;
|
|
19
|
+
/**
|
|
20
|
+
* For a component with defaultable options: the defaults the Defaults around it give it, read
|
|
21
|
+
* where the option is read so that a change of them updates it.
|
|
22
|
+
*/
|
|
23
|
+
export declare function useDefaults<N extends DefaultedComponent>(component: N): Accessor<NonNullable<ComponentDefaults[N]>>;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { mergeDefaults } from "@xds/core";
|
|
2
|
+
import { createContext, createMemo, useContext } from "solid-js";
|
|
3
|
+
const DefaultsContext = createContext(() => ({}));
|
|
4
|
+
export function Defaults(props) {
|
|
5
|
+
const outer = useContext(DefaultsContext);
|
|
6
|
+
const merged = createMemo(() => mergeDefaults(outer(), props.value));
|
|
7
|
+
return <DefaultsContext value={merged}>{props.children}</DefaultsContext>;
|
|
8
|
+
}
|
|
9
|
+
export function useDefaults(component) {
|
|
10
|
+
const defaults = useContext(DefaultsContext);
|
|
11
|
+
return () => defaults()[component] ?? {};
|
|
12
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { type DialogBaseProps } from "@xds/core";
|
|
2
|
+
import { type Element } from "solid-js";
|
|
3
|
+
import { type RootProps } from "./root.ts";
|
|
4
|
+
export type DialogProps = DialogBaseProps & RootProps & {
|
|
5
|
+
/** Called on Escape and on a press outside the dialog. Set `open` to false in it. */
|
|
6
|
+
onClose: () => void;
|
|
7
|
+
/** The body, between the description and the actions. It scrolls when it is too tall. */
|
|
8
|
+
children?: Element;
|
|
9
|
+
/** Buttons, in a row at the end edge. Put the main action last. */
|
|
10
|
+
actions?: Element;
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* A window that interrupts the screen for a confirmation or a short task. Everything behind it
|
|
14
|
+
* is dimmed and cannot be reached until it closes.
|
|
15
|
+
*
|
|
16
|
+
* It is a modal dialog named by its title and described by its description. Focus moves into
|
|
17
|
+
* it, stays inside it, and returns to where it was when it closes.
|
|
18
|
+
*
|
|
19
|
+
* Its `class` and `style` are the dialog's surface's, not the backdrop's.
|
|
20
|
+
*/
|
|
21
|
+
export declare function Dialog(props: DialogProps): import("@solidjs/web").JSX.Element;
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { classes, leaveEscapeToFields } from "@xds/core";
|
|
2
|
+
import { Portal } from "@solidjs/web";
|
|
3
|
+
import * as dialog from "@zag-js/dialog";
|
|
4
|
+
import { normalizeProps, useMachine } from "@zag-js/solid";
|
|
5
|
+
import { createMemo, createUniqueId, Show } from "solid-js";
|
|
6
|
+
import { createPresence } from "./presence.js";
|
|
7
|
+
import { withStyle } from "./root.js";
|
|
8
|
+
import { TriggerContext } from "./trigger.js";
|
|
9
|
+
export function Dialog(props) {
|
|
10
|
+
const id = createUniqueId();
|
|
11
|
+
let backdrop;
|
|
12
|
+
let positioner;
|
|
13
|
+
let content;
|
|
14
|
+
const service = useMachine(dialog.machine, () => ({
|
|
15
|
+
id,
|
|
16
|
+
open: props.open,
|
|
17
|
+
onOpenChange: (details) => {
|
|
18
|
+
if (!details.open)
|
|
19
|
+
props.onClose();
|
|
20
|
+
},
|
|
21
|
+
closeOnEscape: props.dismissible ?? true,
|
|
22
|
+
closeOnInteractOutside: props.dismissible ?? true,
|
|
23
|
+
onEscapeKeyDown: leaveEscapeToFields,
|
|
24
|
+
initialFocusEl: () => content ?? null,
|
|
25
|
+
}));
|
|
26
|
+
const api = createMemo(() => dialog.connect(service, normalizeProps));
|
|
27
|
+
const contentProps = withStyle(() => api().getContentProps(), () => props.style);
|
|
28
|
+
const present = createPresence(() => api().open, () => [backdrop, positioner]);
|
|
29
|
+
return (<Show when={present()}>
|
|
30
|
+
<Portal>
|
|
31
|
+
|
|
32
|
+
<TriggerContext value={null}>
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
<div {...api().getBackdropProps()} ref={(element) => (backdrop = element)} hidden={false} onMouseDown={(event) => event.preventDefault()} class="xds-dialog__backdrop"/>
|
|
36
|
+
<div {...api().getPositionerProps()} ref={(element) => (positioner = element)} class="xds-dialog__positioner">
|
|
37
|
+
<section {...contentProps} ref={(element) => (content = element)} hidden={false} class={classes("xds-dialog", props.class)}>
|
|
38
|
+
<h2 {...api().getTitleProps()} class="xds-dialog__title">
|
|
39
|
+
{props.title}
|
|
40
|
+
</h2>
|
|
41
|
+
<Show when={props.description}>
|
|
42
|
+
<p {...api().getDescriptionProps()} class="xds-dialog__description">
|
|
43
|
+
{props.description}
|
|
44
|
+
</p>
|
|
45
|
+
</Show>
|
|
46
|
+
|
|
47
|
+
<Show when={props.children}>
|
|
48
|
+
{(body) => <div class="xds-dialog__body">{body()}</div>}
|
|
49
|
+
</Show>
|
|
50
|
+
<Show when={props.actions}>
|
|
51
|
+
{(actions) => <div class="xds-dialog__actions">{actions()}</div>}
|
|
52
|
+
</Show>
|
|
53
|
+
</section>
|
|
54
|
+
</div>
|
|
55
|
+
</TriggerContext>
|
|
56
|
+
</Portal>
|
|
57
|
+
</Show>);
|
|
58
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { type EmptyStateBaseProps } from "@xds/core";
|
|
2
|
+
import { type Element } from "solid-js";
|
|
3
|
+
import type { RootProps } from "./root.ts";
|
|
4
|
+
export type EmptyStateProps = EmptyStateBaseProps & RootProps & {
|
|
5
|
+
/** The one thing to do about it, usually a Button. */
|
|
6
|
+
action?: Element;
|
|
7
|
+
};
|
|
8
|
+
/**
|
|
9
|
+
* What a screen or a list says when it has nothing to show. It centers itself in its container,
|
|
10
|
+
* also vertically when the container is a flex box with room to spare.
|
|
11
|
+
*/
|
|
12
|
+
export declare function EmptyState(props: EmptyStateProps): import("@solidjs/web").JSX.Element;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { classes, EMPTY_STATE_PARTS, rootPart } from "@xds/core";
|
|
2
|
+
import { Show } from "solid-js";
|
|
3
|
+
import { Icon } from "./Icon.jsx";
|
|
4
|
+
const ROOT = rootPart("EmptyState");
|
|
5
|
+
export function EmptyState(props) {
|
|
6
|
+
return (<div class={classes(ROOT, EMPTY_STATE_PARTS.root, props.class)} style={props.style}>
|
|
7
|
+
<Icon name={props.icon} size="xl" class={EMPTY_STATE_PARTS.icon}/>
|
|
8
|
+
<p class={EMPTY_STATE_PARTS.title}>{props.title}</p>
|
|
9
|
+
<Show when={props.description}>
|
|
10
|
+
{(description) => <p class={EMPTY_STATE_PARTS.description}>{description()}</p>}
|
|
11
|
+
</Show>
|
|
12
|
+
<Show when={props.action}>
|
|
13
|
+
{(action) => <div class={EMPTY_STATE_PARTS.action}>{action()}</div>}
|
|
14
|
+
</Show>
|
|
15
|
+
</div>);
|
|
16
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { type IconBaseProps } from "@xds/core";
|
|
2
|
+
import type { RootProps } from "./root.ts";
|
|
3
|
+
export type IconProps = IconBaseProps & RootProps;
|
|
4
|
+
/**
|
|
5
|
+
* An icon from design/icons. It takes the color of the text around it. An arrow or a chevron
|
|
6
|
+
* mirrors itself in a right-to-left layout when given `rtl:-scale-x-100` in `class`.
|
|
7
|
+
*/
|
|
8
|
+
export declare function Icon(props: IconProps): import("@solidjs/web").JSX.Element;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { icons } from "@xds/tokens";
|
|
2
|
+
import { classes, iconClass, rootPart } from "@xds/core";
|
|
3
|
+
import { For } from "solid-js";
|
|
4
|
+
import { useDefaults } from "./Defaults.jsx";
|
|
5
|
+
const ROOT = rootPart("Icon");
|
|
6
|
+
export function Icon(props) {
|
|
7
|
+
const defaults = useDefaults("Icon");
|
|
8
|
+
return (<svg viewBox="0 0 24 24" fill={props.filled ? "currentColor" : "none"} stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class={classes(ROOT, iconClass(props.size ?? defaults().size), props.class)} style={props.style} role={props.label ? "img" : undefined} aria-label={props.label || undefined} aria-hidden={props.label ? undefined : "true"}>
|
|
9
|
+
<For each={icons[props.name]}>{(path) => <path d={path}/>}</For>
|
|
10
|
+
</svg>);
|
|
11
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { type IconButtonBaseProps } from "@xds/core";
|
|
2
|
+
import type { JSX } from "@solidjs/web";
|
|
3
|
+
import type { RootProps } from "./root.ts";
|
|
4
|
+
export type IconButtonProps = IconButtonBaseProps & RootProps & {
|
|
5
|
+
onPress?: () => void;
|
|
6
|
+
};
|
|
7
|
+
/**
|
|
8
|
+
* A button that holds only an icon, in Button's variants, sizes and states. It is a square as
|
|
9
|
+
* tall as a Button of its size, and its pressable area is never smaller than the minimum
|
|
10
|
+
* target, even when the square is. Like Button, it opens a Menu or a Tooltip it is the trigger
|
|
11
|
+
* of.
|
|
12
|
+
*/
|
|
13
|
+
export declare function IconButton(props: IconButtonProps): JSX.Element;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { buttonClass, classes, ICON_BUTTON_BOX, isHeld, } from "@xds/core";
|
|
2
|
+
import { createMemo, Show } from "solid-js";
|
|
3
|
+
import { useDefaults } from "./Defaults.jsx";
|
|
4
|
+
import { Icon } from "./Icon.jsx";
|
|
5
|
+
import { Spinner } from "./Spinner.jsx";
|
|
6
|
+
import { withTrigger } from "./trigger.js";
|
|
7
|
+
export function IconButton(props) {
|
|
8
|
+
const defaults = useDefaults("IconButton");
|
|
9
|
+
const variant = () => props.variant ?? defaults().variant ?? "ghost";
|
|
10
|
+
const size = () => props.size ?? defaults().size ?? "md";
|
|
11
|
+
const attributes = withTrigger(createMemo(() => ({
|
|
12
|
+
type: "button",
|
|
13
|
+
class: classes(buttonClass({ variant: variant(), size: size(), iconButton: true }), props.class),
|
|
14
|
+
style: props.style,
|
|
15
|
+
disabled: props.disabled,
|
|
16
|
+
"aria-disabled": props.loading ? "true" : undefined,
|
|
17
|
+
"data-pending": props.loading ? "" : undefined,
|
|
18
|
+
"aria-pressed": props.selected === undefined ? undefined : props.selected ? "true" : "false",
|
|
19
|
+
"aria-label": props.label,
|
|
20
|
+
onClick: () => {
|
|
21
|
+
if (!props.loading)
|
|
22
|
+
props.onPress?.();
|
|
23
|
+
},
|
|
24
|
+
})), () => props.loading === true);
|
|
25
|
+
return (<button {...attributes}>
|
|
26
|
+
<Show when={!props.loading} fallback={<span class={ICON_BUTTON_BOX[size()]}>
|
|
27
|
+
<Spinner size="sm"/>
|
|
28
|
+
</span>}>
|
|
29
|
+
<Icon name={props.icon} size={size()} filled={isHeld({
|
|
30
|
+
variant: variant(),
|
|
31
|
+
selected: props.selected,
|
|
32
|
+
disabled: props.disabled,
|
|
33
|
+
})}/>
|
|
34
|
+
</Show>
|
|
35
|
+
</button>);
|
|
36
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { type ListRowBaseProps } from "@xds/core";
|
|
2
|
+
import { type Element } from "solid-js";
|
|
3
|
+
import type { RootProps } from "./root.ts";
|
|
4
|
+
export type ListRowProps = ListRowBaseProps & RootProps & {
|
|
5
|
+
/** In front of the title: an avatar or an icon. */
|
|
6
|
+
leading?: Element;
|
|
7
|
+
/** At the far end: a value, a badge or a switch. */
|
|
8
|
+
trailing?: Element;
|
|
9
|
+
/** Makes the whole row a button. Do not put another control in `trailing` then. */
|
|
10
|
+
onPress?: () => void;
|
|
11
|
+
};
|
|
12
|
+
/** One line of a list or a settings screen. Separate rows with a Divider. */
|
|
13
|
+
export declare function ListRow(props: ListRowProps): import("@solidjs/web").JSX.Element;
|
|
14
|
+
/**
|
|
15
|
+
* A ListRow that says what kind of current item its selected state is. A Sidebar's rows are the
|
|
16
|
+
* places of an app, so its selected row is the current page. Only for this package's own
|
|
17
|
+
* components: the index does not export it.
|
|
18
|
+
*/
|
|
19
|
+
export declare function PlaceRow(props: ListRowProps & {
|
|
20
|
+
current: "true" | "page";
|
|
21
|
+
}): import("@solidjs/web").JSX.Element;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { classes, LIST_ROW_PARTS, listRowClass, listRowDescriptionClass, listRowTitleClass, rootPart, } from "@xds/core";
|
|
2
|
+
import { Show } from "solid-js";
|
|
3
|
+
import { Icon } from "./Icon.jsx";
|
|
4
|
+
const ROOT = rootPart("ListRow");
|
|
5
|
+
export function ListRow(props) {
|
|
6
|
+
return <PlaceRow {...props} current="true"/>;
|
|
7
|
+
}
|
|
8
|
+
export function PlaceRow(props) {
|
|
9
|
+
const pressable = () => props.onPress !== undefined;
|
|
10
|
+
const current = () => (props.selected ? props.current : undefined);
|
|
11
|
+
const row = () => classes(ROOT, listRowClass({ compact: props.compact, selected: props.selected, pressable: pressable() }), props.class);
|
|
12
|
+
const content = () => (<>
|
|
13
|
+
{props.leading}
|
|
14
|
+
<span class={LIST_ROW_PARTS.text}>
|
|
15
|
+
<span class={listRowTitleClass({
|
|
16
|
+
compact: props.compact,
|
|
17
|
+
selected: props.selected,
|
|
18
|
+
disabled: props.disabled,
|
|
19
|
+
})}>
|
|
20
|
+
{props.title}
|
|
21
|
+
</span>
|
|
22
|
+
<Show when={props.description}>
|
|
23
|
+
{(description) => (<span class={listRowDescriptionClass(props.compact)}>{description()}</span>)}
|
|
24
|
+
</Show>
|
|
25
|
+
</span>
|
|
26
|
+
{props.trailing}
|
|
27
|
+
<Show when={props.chevron}>
|
|
28
|
+
<Icon name="chevron-right" size="sm" class={LIST_ROW_PARTS.chevron}/>
|
|
29
|
+
</Show>
|
|
30
|
+
</>);
|
|
31
|
+
return (<Show when={pressable()} fallback={<div aria-current={current()} class={row()} style={props.style}>
|
|
32
|
+
{content()}
|
|
33
|
+
</div>}>
|
|
34
|
+
<button aria-current={current()} type="button" disabled={props.disabled} onClick={() => props.onPress?.()} class={row()} style={props.style}>
|
|
35
|
+
{content()}
|
|
36
|
+
</button>
|
|
37
|
+
</Show>);
|
|
38
|
+
}
|