@xds/svelte 0.0.0-stage → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +19 -2
- package/dist/Accordion.svelte +89 -0
- package/dist/Accordion.svelte.d.ts +43 -0
- package/dist/AccordionPanel.svelte +40 -0
- package/dist/AccordionPanel.svelte.d.ts +15 -0
- package/dist/Avatar.svelte +45 -0
- package/dist/Avatar.svelte.d.ts +11 -0
- package/dist/AvatarStack.svelte +49 -0
- package/dist/AvatarStack.svelte.d.ts +10 -0
- package/dist/Badge.svelte +36 -0
- package/dist/Badge.svelte.d.ts +15 -0
- package/dist/Banner.svelte +88 -0
- package/dist/Banner.svelte.d.ts +25 -0
- package/dist/Button.svelte +90 -0
- package/dist/Button.svelte.d.ts +16 -0
- package/dist/Card.svelte +99 -0
- package/dist/Card.svelte.d.ts +20 -0
- package/dist/Checkbox.svelte +68 -0
- package/dist/Checkbox.svelte.d.ts +12 -0
- package/dist/Chip.svelte +43 -0
- package/dist/Chip.svelte.d.ts +14 -0
- package/dist/ChipBar.svelte +32 -0
- package/dist/ChipBar.svelte.d.ts +14 -0
- package/dist/CountBadge.svelte +50 -0
- package/dist/CountBadge.svelte.d.ts +14 -0
- package/dist/DatePicker.svelte +178 -0
- package/dist/DatePicker.svelte.d.ts +22 -0
- package/dist/DateRangePicker.svelte +264 -0
- package/dist/DateRangePicker.svelte.d.ts +25 -0
- package/dist/Defaults.svelte +29 -0
- package/dist/Defaults.svelte.d.ts +17 -0
- package/dist/Dialog.svelte +104 -0
- package/dist/Dialog.svelte.d.ts +22 -0
- package/dist/Divider.svelte +17 -0
- package/dist/Divider.svelte.d.ts +6 -0
- package/dist/EmptyState.svelte +34 -0
- package/dist/EmptyState.svelte.d.ts +14 -0
- package/dist/Icon.svelte +38 -0
- package/dist/Icon.svelte.d.ts +10 -0
- package/dist/IconButton.svelte +67 -0
- package/dist/IconButton.svelte.d.ts +13 -0
- package/dist/ListRow.svelte +29 -0
- package/dist/ListRow.svelte.d.ts +15 -0
- package/dist/MediaCard.svelte +112 -0
- package/dist/MediaCard.svelte.d.ts +22 -0
- package/dist/Menu.svelte +156 -0
- package/dist/Menu.svelte.d.ts +19 -0
- package/dist/PlaceRow.svelte +66 -0
- package/dist/PlaceRow.svelte.d.ts +12 -0
- package/dist/Portal.svelte +27 -0
- package/dist/Portal.svelte.d.ts +15 -0
- package/dist/ProgressBar.svelte +37 -0
- package/dist/ProgressBar.svelte.d.ts +10 -0
- package/dist/RadioGroup.svelte +114 -0
- package/dist/RadioGroup.svelte.d.ts +38 -0
- package/dist/SearchField.svelte +93 -0
- package/dist/SearchField.svelte.d.ts +17 -0
- package/dist/SectionHeader.svelte +56 -0
- package/dist/SectionHeader.svelte.d.ts +16 -0
- package/dist/SegmentedControl.svelte +70 -0
- package/dist/SegmentedControl.svelte.d.ts +35 -0
- package/dist/Select.svelte +214 -0
- package/dist/Select.svelte.d.ts +40 -0
- package/dist/Sidebar.svelte +125 -0
- package/dist/Sidebar.svelte.d.ts +43 -0
- package/dist/SidebarRailButton.svelte +29 -0
- package/dist/SidebarRailButton.svelte.d.ts +14 -0
- package/dist/Skeleton.svelte +34 -0
- package/dist/Skeleton.svelte.d.ts +13 -0
- package/dist/Slider.svelte +111 -0
- package/dist/Slider.svelte.d.ts +15 -0
- package/dist/Spinner.svelte +35 -0
- package/dist/Spinner.svelte.d.ts +11 -0
- package/dist/Switch.svelte +60 -0
- package/dist/Switch.svelte.d.ts +15 -0
- package/dist/Tabs.svelte +65 -0
- package/dist/Tabs.svelte.d.ts +36 -0
- package/dist/Text.svelte +36 -0
- package/dist/Text.svelte.d.ts +11 -0
- package/dist/TextField.svelte +163 -0
- package/dist/TextField.svelte.d.ts +23 -0
- package/dist/Thumbnail.svelte +81 -0
- package/dist/Thumbnail.svelte.d.ts +11 -0
- package/dist/Toast.svelte +83 -0
- package/dist/Toast.svelte.d.ts +17 -0
- package/dist/Tooltip.svelte +40 -0
- package/dist/Tooltip.svelte.d.ts +19 -0
- package/dist/TooltipOverlay.svelte +66 -0
- package/dist/TooltipOverlay.svelte.d.ts +17 -0
- package/dist/controlled.d.ts +4 -0
- package/dist/controlled.js +23 -0
- package/dist/defaults.svelte.d.ts +12 -0
- package/dist/defaults.svelte.js +25 -0
- package/dist/index.d.ts +41 -0
- package/dist/index.js +47 -0
- package/dist/modal-popover.svelte.d.ts +8 -0
- package/dist/modal-popover.svelte.js +22 -0
- package/dist/picture.svelte.d.ts +19 -0
- package/dist/picture.svelte.js +18 -0
- package/dist/presence.svelte.d.ts +6 -0
- package/dist/presence.svelte.js +19 -0
- package/dist/preview/Component.svelte +56 -0
- package/dist/preview/Component.svelte.d.ts +15 -0
- package/dist/preview/Draw.svelte +65 -0
- package/dist/preview/Draw.svelte.d.ts +15 -0
- package/dist/preview/Preview.svelte +41 -0
- package/dist/preview/Preview.svelte.d.ts +13 -0
- package/dist/preview/Snippets.svelte +36 -0
- package/dist/preview/Snippets.svelte.d.ts +19 -0
- package/dist/preview/components.js +48 -0
- package/dist/preview/index.d.ts +2 -0
- package/dist/preview/index.js +4 -0
- package/dist/root.d.ts +11 -0
- package/dist/root.js +1 -0
- package/dist/styles/index.css +5 -0
- package/dist/trigger.svelte.d.ts +21 -0
- package/dist/trigger.svelte.js +48 -0
- package/package.json +62 -4
- package/page.css +20 -0
- package/styles.css +3354 -0
- package/tailwind.css +2665 -0
|
@@ -0,0 +1,264 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
@component
|
|
3
|
+
A field for choosing a range of days, a start and an end, as for a stay. Closed, it looks like a
|
|
4
|
+
DatePicker and shows both days in the locale's medium form ("Mar 10 – 14, 2026"), or the
|
|
5
|
+
placeholder. Pressed, it opens a calendar under itself, two months side by side where the window
|
|
6
|
+
has room and one where it does not, on the start's month, or on today's while nothing is chosen.
|
|
7
|
+
|
|
8
|
+
The first day pressed starts the range, and the band previews it to the day under the pointer or
|
|
9
|
+
the keyboard's focus. The second ends it, if the days between are at least `minLength` and at
|
|
10
|
+
most `maxLength`, which leave the other days unavailable meanwhile: `onChange` gets the range and
|
|
11
|
+
the calendar closes. A day before the start starts again from there. Escape or a press outside
|
|
12
|
+
closes the calendar without a change.
|
|
13
|
+
|
|
14
|
+
The keys are DatePicker's, and Page Up and Page Down move a month whether one or two are shown.
|
|
15
|
+
Each month is a grid named by its month; every day of the range is selected, and the two ends
|
|
16
|
+
are named by `startLabel` and `endLabel` before the day.
|
|
17
|
+
-->
|
|
18
|
+
<script module lang="ts">
|
|
19
|
+
import type { DateRange, DateRangePickerBaseProps } from "@xds/core";
|
|
20
|
+
import type { RootProps } from "./root.js";
|
|
21
|
+
|
|
22
|
+
export type { DateRange } from "@xds/core";
|
|
23
|
+
|
|
24
|
+
export type DateRangePickerProps = DateRangePickerBaseProps &
|
|
25
|
+
RootProps & {
|
|
26
|
+
onChange: (value: DateRange) => void;
|
|
27
|
+
};
|
|
28
|
+
</script>
|
|
29
|
+
|
|
30
|
+
<script lang="ts">
|
|
31
|
+
import {
|
|
32
|
+
classes,
|
|
33
|
+
DATE_PICKER_NAV_CLASS,
|
|
34
|
+
dateRangeMachineProps,
|
|
35
|
+
datePickerContentAttrs,
|
|
36
|
+
datePickerIds,
|
|
37
|
+
datePickerLocale,
|
|
38
|
+
datePickerTriggerAttrs,
|
|
39
|
+
endRangeChoiceOnClose,
|
|
40
|
+
focusOpeningDay,
|
|
41
|
+
formatRange,
|
|
42
|
+
keepCalendarFocus,
|
|
43
|
+
keepDayFocused,
|
|
44
|
+
keepRangePreview,
|
|
45
|
+
type RangeDraft,
|
|
46
|
+
rangeDayClick,
|
|
47
|
+
rangeGridKeyDown,
|
|
48
|
+
rangeMonths,
|
|
49
|
+
rangeMonthViews,
|
|
50
|
+
rangeSummary,
|
|
51
|
+
shownRange,
|
|
52
|
+
} from "@xds/core";
|
|
53
|
+
import * as datePicker from "@zag-js/date-picker";
|
|
54
|
+
import { mergeProps, normalizeProps, useMachine } from "@zag-js/svelte";
|
|
55
|
+
import { untrack } from "svelte";
|
|
56
|
+
import Icon from "./Icon.svelte";
|
|
57
|
+
import { modalPopover } from "./modal-popover.svelte.js";
|
|
58
|
+
import Portal from "./Portal.svelte";
|
|
59
|
+
import { createPresence } from "./presence.svelte.js";
|
|
60
|
+
|
|
61
|
+
// The rest stays reactive: the machine's props read it each time it changes.
|
|
62
|
+
let { onChange, class: className, style, ...props }: DateRangePickerProps = $props();
|
|
63
|
+
|
|
64
|
+
const id = $props.id();
|
|
65
|
+
const ids = datePickerIds(id);
|
|
66
|
+
const locale = datePickerLocale();
|
|
67
|
+
// A start alone while the end is chosen; null while the calendar shows the chosen range.
|
|
68
|
+
let draft = $state.raw<RangeDraft | null>(null);
|
|
69
|
+
let months = $state(1);
|
|
70
|
+
const shown = $derived(shownRange(props.value, draft));
|
|
71
|
+
const service = useMachine(datePicker.machine, () =>
|
|
72
|
+
dateRangeMachineProps(props, shown, {
|
|
73
|
+
id,
|
|
74
|
+
locale,
|
|
75
|
+
months,
|
|
76
|
+
onDraft: (next) => (draft = next),
|
|
77
|
+
onChange,
|
|
78
|
+
}),
|
|
79
|
+
);
|
|
80
|
+
const api = $derived(datePicker.connect(service, normalizeProps));
|
|
81
|
+
const trigger = $derived(api.getTriggerProps());
|
|
82
|
+
const invalid = $derived(props.error !== undefined);
|
|
83
|
+
const summary = $derived(rangeSummary(shown, props, locale));
|
|
84
|
+
const views = $derived(rangeMonthViews(api, months));
|
|
85
|
+
let positioner = $state<HTMLDivElement>();
|
|
86
|
+
let surface = $state<HTMLDivElement>();
|
|
87
|
+
modalPopover(
|
|
88
|
+
() => api.open,
|
|
89
|
+
() => positioner,
|
|
90
|
+
);
|
|
91
|
+
const present = createPresence(
|
|
92
|
+
() => api.open,
|
|
93
|
+
() => [surface],
|
|
94
|
+
);
|
|
95
|
+
// Strings, so that the effects below run only when the focused day or the month changes, not
|
|
96
|
+
// on every change of the machine.
|
|
97
|
+
const focused = $derived(api.focusedValue.toString());
|
|
98
|
+
const month = $derived(api.visibleRange.start.toString());
|
|
99
|
+
const open = $derived(api.open);
|
|
100
|
+
$effect(() => {
|
|
101
|
+
const isOpen = open;
|
|
102
|
+
void focused;
|
|
103
|
+
void month;
|
|
104
|
+
untrack(() => keepDayFocused(isOpen, surface));
|
|
105
|
+
});
|
|
106
|
+
$effect(() => {
|
|
107
|
+
const isOpen = open;
|
|
108
|
+
untrack(() => endRangeChoiceOnClose(service, isOpen));
|
|
109
|
+
});
|
|
110
|
+
$effect(() => {
|
|
111
|
+
void focused;
|
|
112
|
+
untrack(() => keepRangePreview(service, shown, open));
|
|
113
|
+
});
|
|
114
|
+
</script>
|
|
115
|
+
|
|
116
|
+
<!-- Merged, so that the app's style joins any the machine writes on the root. -->
|
|
117
|
+
<div
|
|
118
|
+
{...mergeProps(api.getRootProps(), {
|
|
119
|
+
class: classes("xds-date-picker xds-date-range-picker", className),
|
|
120
|
+
style,
|
|
121
|
+
})}
|
|
122
|
+
>
|
|
123
|
+
<!-- A span: the field is a button, which a <label> cannot point at. -->
|
|
124
|
+
<span id={ids.label} class="xds-date-picker__label">{props.label}</span>
|
|
125
|
+
<!-- What Zag places the calendar against. -->
|
|
126
|
+
<div {...api.getControlProps()} class="xds-date-picker__control">
|
|
127
|
+
<button
|
|
128
|
+
{...trigger}
|
|
129
|
+
{...datePickerTriggerAttrs(props, ids)}
|
|
130
|
+
type="button"
|
|
131
|
+
onclick={(event) => {
|
|
132
|
+
if (!api.open) months = rangeMonths();
|
|
133
|
+
focusOpeningDay(api, { ...props, value: props.value?.start });
|
|
134
|
+
trigger.onclick?.(event);
|
|
135
|
+
}}
|
|
136
|
+
class="xds-date-picker__trigger"
|
|
137
|
+
>
|
|
138
|
+
<span id={ids.value} class="xds-date-picker__value"
|
|
139
|
+
>{props.value === undefined ? props.placeholder : formatRange(props.value, locale)}</span
|
|
140
|
+
>
|
|
141
|
+
<Icon name="calendar" size="sm" class="text-xds-field-placeholder" />
|
|
142
|
+
</button>
|
|
143
|
+
</div>
|
|
144
|
+
<!-- One line under the box: the help, or the error in its place. -->
|
|
145
|
+
{#if invalid || props.description}
|
|
146
|
+
<div class="xds-date-picker__footer">
|
|
147
|
+
{#if invalid}
|
|
148
|
+
<span id={ids.error} class="xds-date-picker__error">{props.error}</span>
|
|
149
|
+
{:else}
|
|
150
|
+
<span id={ids.description} class="xds-date-picker__description">{props.description}</span>
|
|
151
|
+
{/if}
|
|
152
|
+
</div>
|
|
153
|
+
{/if}
|
|
154
|
+
<!-- What a form submits. Zag gives the names to its text inputs, which are not drawn. -->
|
|
155
|
+
{#if props.startName !== undefined}
|
|
156
|
+
<input type="hidden" name={props.startName} value={props.value?.start ?? ""} />
|
|
157
|
+
{/if}
|
|
158
|
+
{#if props.endName !== undefined}
|
|
159
|
+
<input type="hidden" name={props.endName} value={props.value?.end ?? ""} />
|
|
160
|
+
{/if}
|
|
161
|
+
<Portal>
|
|
162
|
+
{#if api.open}
|
|
163
|
+
<!-- Takes a press outside, which then only closes the calendar. The focus stays in the
|
|
164
|
+
calendar until it hands it back to the field. -->
|
|
165
|
+
<!-- svelte-ignore a11y_no_static_element_interactions -->
|
|
166
|
+
<div class="xds-date-picker__underlay" onmousedown={(event) => event.preventDefault()}></div>
|
|
167
|
+
{/if}
|
|
168
|
+
<div {...api.getPositionerProps()} bind:this={positioner} class="xds-date-picker__positioner">
|
|
169
|
+
<!-- Shown until its exit animation ends; Zag would hide it as it closes. -->
|
|
170
|
+
<div
|
|
171
|
+
{...api.getContentProps()}
|
|
172
|
+
{...datePickerContentAttrs(ids)}
|
|
173
|
+
bind:this={surface}
|
|
174
|
+
hidden={!present()}
|
|
175
|
+
onkeydown={(event) => keepCalendarFocus(event, surface)}
|
|
176
|
+
class="xds-date-picker__content xds-date-range-picker__content"
|
|
177
|
+
>
|
|
178
|
+
<div class="xds-date-range-picker__summary" aria-live="polite">
|
|
179
|
+
<span>{summary.start}</span>
|
|
180
|
+
<span>{summary.end}</span>
|
|
181
|
+
</div>
|
|
182
|
+
<div class="xds-date-range-picker__months">
|
|
183
|
+
{#each views as view (view.index)}
|
|
184
|
+
{@const table = api.getTableProps({ view: "day", id: view.table.id })}
|
|
185
|
+
<div class="xds-date-range-picker__month">
|
|
186
|
+
<div class="xds-date-picker__header">
|
|
187
|
+
{#if view.index === 0}
|
|
188
|
+
<button
|
|
189
|
+
{...api.getPreviousTriggerProps()}
|
|
190
|
+
type="button"
|
|
191
|
+
class={DATE_PICKER_NAV_CLASS}
|
|
192
|
+
>
|
|
193
|
+
<Icon name="chevron-left" size="sm" />
|
|
194
|
+
</button>
|
|
195
|
+
{:else}
|
|
196
|
+
<span class="xds-date-range-picker__nav-space"></span>
|
|
197
|
+
{/if}
|
|
198
|
+
<span {...api.getRangeTextProps()} class="xds-date-picker__heading"
|
|
199
|
+
>{view.name}</span
|
|
200
|
+
>
|
|
201
|
+
{#if view.index === months - 1}
|
|
202
|
+
<button
|
|
203
|
+
{...api.getNextTriggerProps()}
|
|
204
|
+
type="button"
|
|
205
|
+
class={DATE_PICKER_NAV_CLASS}
|
|
206
|
+
>
|
|
207
|
+
<Icon name="chevron-right" size="sm" />
|
|
208
|
+
</button>
|
|
209
|
+
{:else}
|
|
210
|
+
<span class="xds-date-range-picker__nav-space"></span>
|
|
211
|
+
{/if}
|
|
212
|
+
</div>
|
|
213
|
+
<table
|
|
214
|
+
{...table}
|
|
215
|
+
{...view.table}
|
|
216
|
+
onkeydown={(event) => rangeGridKeyDown(event, api, shown, props, table.onkeydown)}
|
|
217
|
+
class="xds-date-picker__grid"
|
|
218
|
+
>
|
|
219
|
+
<thead {...api.getTableHeadProps({ view: "day" })}>
|
|
220
|
+
<tr {...api.getTableRowProps({ view: "day" })}>
|
|
221
|
+
{#each api.weekDays as weekDay (weekDay.long)}
|
|
222
|
+
<th scope="col" class="xds-date-picker__weekday">{weekDay.narrow}</th>
|
|
223
|
+
{/each}
|
|
224
|
+
</tr>
|
|
225
|
+
</thead>
|
|
226
|
+
<tbody {...api.getTableBodyProps({ view: "day" })}>
|
|
227
|
+
<!-- Keyed by the day, as in DatePicker: a cell made anew would drop the focus it
|
|
228
|
+
holds when a move is held at `min` or `max`. -->
|
|
229
|
+
{#each view.weeks as week (week[0]?.toString())}
|
|
230
|
+
<tr {...api.getTableRowProps({ view: "day" })}>
|
|
231
|
+
{#each week as value (value.toString())}
|
|
232
|
+
{@const cell = { value, visibleRange: view.visibleRange }}
|
|
233
|
+
{@const day = api.getDayTableCellTriggerProps(cell)}
|
|
234
|
+
<td {...api.getDayTableCellProps(cell)} class="xds-date-picker__cell">
|
|
235
|
+
<!-- svelte-ignore a11y_click_events_have_key_events, a11y_no_static_element_interactions -->
|
|
236
|
+
<div
|
|
237
|
+
{...day}
|
|
238
|
+
onclick={(event) =>
|
|
239
|
+
rangeDayClick(
|
|
240
|
+
event,
|
|
241
|
+
api,
|
|
242
|
+
shown,
|
|
243
|
+
props,
|
|
244
|
+
value,
|
|
245
|
+
view.visibleRange,
|
|
246
|
+
day.onclick,
|
|
247
|
+
)}
|
|
248
|
+
class="xds-date-picker__day"
|
|
249
|
+
>
|
|
250
|
+
{value.day}
|
|
251
|
+
</div>
|
|
252
|
+
</td>
|
|
253
|
+
{/each}
|
|
254
|
+
</tr>
|
|
255
|
+
{/each}
|
|
256
|
+
</tbody>
|
|
257
|
+
</table>
|
|
258
|
+
</div>
|
|
259
|
+
{/each}
|
|
260
|
+
</div>
|
|
261
|
+
</div>
|
|
262
|
+
</div>
|
|
263
|
+
</Portal>
|
|
264
|
+
</div>
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { DateRange, DateRangePickerBaseProps } from "@xds/core";
|
|
2
|
+
import type { RootProps } from "./root.js";
|
|
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 a
|
|
9
|
+
* 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 window
|
|
11
|
+
* has room and one where it does not, on the start's month, or on today's while nothing is chosen.
|
|
12
|
+
*
|
|
13
|
+
* The first day pressed starts the range, and the band previews it to the day under the pointer or
|
|
14
|
+
* the keyboard's focus. The second ends it, if the days between are at least `minLength` and at
|
|
15
|
+
* most `maxLength`, which leave the other days unavailable meanwhile: `onChange` gets the range and
|
|
16
|
+
* the calendar closes. A day before the start starts again from there. Escape or a press outside
|
|
17
|
+
* closes the calendar without a change.
|
|
18
|
+
*
|
|
19
|
+
* The keys are DatePicker's, and Page Up and Page Down move a month whether one or two are shown.
|
|
20
|
+
* Each month is a grid named by its month; every day of the range is selected, and the two ends
|
|
21
|
+
* are named by `startLabel` and `endLabel` before the day.
|
|
22
|
+
*/
|
|
23
|
+
declare const DateRangePicker: import("svelte").Component<DateRangePickerProps, {}, "">;
|
|
24
|
+
type DateRangePicker = ReturnType<typeof DateRangePicker>;
|
|
25
|
+
export default DateRangePicker;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
@component
|
|
3
|
+
Layer 6 of the library's customization: the components inside it take `value` for the options
|
|
4
|
+
they are not given, such as a Button's variant or a Text's tone. A component's own props win,
|
|
5
|
+
then the closest Defaults, then the component's built-in default. A Defaults inside another
|
|
6
|
+
keeps the outer one's defaults and replaces only those it names.
|
|
7
|
+
-->
|
|
8
|
+
<script module lang="ts">
|
|
9
|
+
import type { ComponentDefaults } from "@xds/core";
|
|
10
|
+
import type { Snippet } from "svelte";
|
|
11
|
+
|
|
12
|
+
export type { ComponentDefaults } from "@xds/core";
|
|
13
|
+
|
|
14
|
+
export type DefaultsProps = {
|
|
15
|
+
/** The defaults, by component and option. It may change; the components follow it. */
|
|
16
|
+
value: ComponentDefaults;
|
|
17
|
+
children: Snippet;
|
|
18
|
+
};
|
|
19
|
+
</script>
|
|
20
|
+
|
|
21
|
+
<script lang="ts">
|
|
22
|
+
import { provideDefaults } from "./defaults.svelte.js";
|
|
23
|
+
|
|
24
|
+
let { value, children }: DefaultsProps = $props();
|
|
25
|
+
|
|
26
|
+
provideDefaults(() => value);
|
|
27
|
+
</script>
|
|
28
|
+
|
|
29
|
+
{@render children()}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { ComponentDefaults } from "@xds/core";
|
|
2
|
+
import type { Snippet } from "svelte";
|
|
3
|
+
export type { ComponentDefaults } from "@xds/core";
|
|
4
|
+
export type DefaultsProps = {
|
|
5
|
+
/** The defaults, by component and option. It may change; the components follow it. */
|
|
6
|
+
value: ComponentDefaults;
|
|
7
|
+
children: Snippet;
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* Layer 6 of the library's customization: the components inside it take `value` for the options
|
|
11
|
+
* they are not given, such as a Button's variant or a Text's tone. A component's own props win,
|
|
12
|
+
* then the closest Defaults, then the component's built-in default. A Defaults inside another
|
|
13
|
+
* keeps the outer one's defaults and replaces only those it names.
|
|
14
|
+
*/
|
|
15
|
+
declare const Defaults: import("svelte").Component<DefaultsProps, {}, "">;
|
|
16
|
+
type Defaults = ReturnType<typeof Defaults>;
|
|
17
|
+
export default Defaults;
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
@component
|
|
3
|
+
A window that interrupts the screen for a confirmation or a short task. Everything behind it is
|
|
4
|
+
dimmed and cannot be reached until it closes.
|
|
5
|
+
|
|
6
|
+
It is a modal dialog named by its title and described by its description. Focus moves into it,
|
|
7
|
+
stays inside it, and returns to where it was when it closes.
|
|
8
|
+
-->
|
|
9
|
+
<script module lang="ts">
|
|
10
|
+
import type { DialogBaseProps } from "@xds/core";
|
|
11
|
+
import type { Snippet } from "svelte";
|
|
12
|
+
import type { RootProps } from "./root.js";
|
|
13
|
+
|
|
14
|
+
/** Its root is the dialog itself, while it is open, not the scrim around it. */
|
|
15
|
+
export type DialogProps = DialogBaseProps &
|
|
16
|
+
RootProps & {
|
|
17
|
+
/** Called on Escape and on a press outside the dialog. Set `open` to false in it. */
|
|
18
|
+
onClose: () => void;
|
|
19
|
+
/** The body, between the description and the actions. It scrolls when it is too tall. */
|
|
20
|
+
children?: Snippet;
|
|
21
|
+
/** Buttons, in a row at the end edge. Put the main action last. */
|
|
22
|
+
actions?: Snippet;
|
|
23
|
+
};
|
|
24
|
+
</script>
|
|
25
|
+
|
|
26
|
+
<script lang="ts">
|
|
27
|
+
import { classes, leaveEscapeToFields } from "@xds/core";
|
|
28
|
+
import * as dialog from "@zag-js/dialog";
|
|
29
|
+
import { mergeProps, normalizeProps, useMachine } from "@zag-js/svelte";
|
|
30
|
+
import Portal from "./Portal.svelte";
|
|
31
|
+
import { createPresence } from "./presence.svelte.js";
|
|
32
|
+
import { resetTrigger } from "./trigger.svelte.js";
|
|
33
|
+
|
|
34
|
+
let {
|
|
35
|
+
open,
|
|
36
|
+
title,
|
|
37
|
+
description,
|
|
38
|
+
dismissible,
|
|
39
|
+
onClose,
|
|
40
|
+
class: className,
|
|
41
|
+
style,
|
|
42
|
+
children,
|
|
43
|
+
actions,
|
|
44
|
+
}: DialogProps = $props();
|
|
45
|
+
|
|
46
|
+
const id = $props.id();
|
|
47
|
+
let backdrop = $state<HTMLDivElement>();
|
|
48
|
+
let positioner = $state<HTMLDivElement>();
|
|
49
|
+
let content = $state<HTMLElement>();
|
|
50
|
+
const service = useMachine(dialog.machine, () => ({
|
|
51
|
+
id,
|
|
52
|
+
open,
|
|
53
|
+
onOpenChange: (details: dialog.OpenChangeDetails) => {
|
|
54
|
+
if (!details.open) onClose();
|
|
55
|
+
},
|
|
56
|
+
closeOnEscape: dismissible ?? true,
|
|
57
|
+
closeOnInteractOutside: dismissible ?? true,
|
|
58
|
+
onEscapeKeyDown: leaveEscapeToFields,
|
|
59
|
+
// The dialog itself rather than its first field or button: a screen reader then reads the
|
|
60
|
+
// title and the description first.
|
|
61
|
+
initialFocusEl: () => content ?? null,
|
|
62
|
+
}));
|
|
63
|
+
const api = $derived(dialog.connect(service, normalizeProps));
|
|
64
|
+
const present = createPresence(
|
|
65
|
+
() => api.open,
|
|
66
|
+
() => [backdrop, positioner],
|
|
67
|
+
);
|
|
68
|
+
// Nothing inside opens an overlay from a control outside it.
|
|
69
|
+
resetTrigger();
|
|
70
|
+
</script>
|
|
71
|
+
|
|
72
|
+
{#if present()}
|
|
73
|
+
<Portal>
|
|
74
|
+
<!-- A press on the scrim keeps the focus in the dialog: a dialog that cannot be dismissed stays
|
|
75
|
+
open, and the focus would go to the page. The backdrop and the dialog stay shown until
|
|
76
|
+
their exit animation ends; Zag would hide them as the dialog closes. -->
|
|
77
|
+
<!-- svelte-ignore a11y_no_static_element_interactions -->
|
|
78
|
+
<div
|
|
79
|
+
{...api.getBackdropProps()}
|
|
80
|
+
bind:this={backdrop}
|
|
81
|
+
hidden={false}
|
|
82
|
+
onmousedown={(event) => event.preventDefault()}
|
|
83
|
+
class="xds-dialog__backdrop"
|
|
84
|
+
></div>
|
|
85
|
+
<div {...api.getPositionerProps()} bind:this={positioner} class="xds-dialog__positioner">
|
|
86
|
+
<section
|
|
87
|
+
{...mergeProps(api.getContentProps(), { class: classes("xds-dialog", className), style })}
|
|
88
|
+
bind:this={content}
|
|
89
|
+
hidden={false}
|
|
90
|
+
>
|
|
91
|
+
<h2 {...api.getTitleProps()} class="xds-dialog__title">{title}</h2>
|
|
92
|
+
{#if description}
|
|
93
|
+
<p {...api.getDescriptionProps()} class="xds-dialog__description">{description}</p>
|
|
94
|
+
{/if}
|
|
95
|
+
{#if children}
|
|
96
|
+
<div class="xds-dialog__body">{@render children()}</div>
|
|
97
|
+
{/if}
|
|
98
|
+
{#if actions}
|
|
99
|
+
<div class="xds-dialog__actions">{@render actions()}</div>
|
|
100
|
+
{/if}
|
|
101
|
+
</section>
|
|
102
|
+
</div>
|
|
103
|
+
</Portal>
|
|
104
|
+
{/if}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { DialogBaseProps } from "@xds/core";
|
|
2
|
+
import type { Snippet } from "svelte";
|
|
3
|
+
import type { RootProps } from "./root.js";
|
|
4
|
+
/** Its root is the dialog itself, while it is open, not the scrim around it. */
|
|
5
|
+
export type DialogProps = DialogBaseProps & RootProps & {
|
|
6
|
+
/** Called on Escape and on a press outside the dialog. Set `open` to false in it. */
|
|
7
|
+
onClose: () => void;
|
|
8
|
+
/** The body, between the description and the actions. It scrolls when it is too tall. */
|
|
9
|
+
children?: Snippet;
|
|
10
|
+
/** Buttons, in a row at the end edge. Put the main action last. */
|
|
11
|
+
actions?: Snippet;
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* A window that interrupts the screen for a confirmation or a short task. Everything behind it is
|
|
15
|
+
* dimmed and cannot be reached until it closes.
|
|
16
|
+
*
|
|
17
|
+
* It is a modal dialog named by its title and described by its description. Focus moves into it,
|
|
18
|
+
* stays inside it, and returns to where it was when it closes.
|
|
19
|
+
*/
|
|
20
|
+
declare const Dialog: import("svelte").Component<DialogProps, {}, "">;
|
|
21
|
+
type Dialog = ReturnType<typeof Dialog>;
|
|
22
|
+
export default Dialog;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
@component
|
|
3
|
+
A line between groups of content. Decorative lines use the low-contrast border color.
|
|
4
|
+
-->
|
|
5
|
+
<script module lang="ts">
|
|
6
|
+
import type { RootProps } from "./root.js";
|
|
7
|
+
|
|
8
|
+
export type DividerProps = RootProps;
|
|
9
|
+
</script>
|
|
10
|
+
|
|
11
|
+
<script lang="ts">
|
|
12
|
+
import { classes, dividerClass, rootPart } from "@xds/core";
|
|
13
|
+
|
|
14
|
+
let { class: className, style }: DividerProps = $props();
|
|
15
|
+
</script>
|
|
16
|
+
|
|
17
|
+
<hr class={classes(rootPart("Divider"), dividerClass, className)} {style} />
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { RootProps } from "./root.js";
|
|
2
|
+
export type DividerProps = RootProps;
|
|
3
|
+
/** A line between groups of content. Decorative lines use the low-contrast border color. */
|
|
4
|
+
declare const Divider: import("svelte").Component<RootProps, {}, "">;
|
|
5
|
+
type Divider = ReturnType<typeof Divider>;
|
|
6
|
+
export default Divider;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
@component
|
|
3
|
+
What a screen or a list says when it has nothing to show. It centers itself in its container,
|
|
4
|
+
also vertically when the container is a flex box with room to spare.
|
|
5
|
+
-->
|
|
6
|
+
<script module lang="ts">
|
|
7
|
+
import type { EmptyStateBaseProps } from "@xds/core";
|
|
8
|
+
import type { Snippet } from "svelte";
|
|
9
|
+
import type { RootProps } from "./root.js";
|
|
10
|
+
|
|
11
|
+
export type EmptyStateProps = EmptyStateBaseProps &
|
|
12
|
+
RootProps & {
|
|
13
|
+
/** The one thing to do about it, usually a Button. */
|
|
14
|
+
action?: Snippet;
|
|
15
|
+
};
|
|
16
|
+
</script>
|
|
17
|
+
|
|
18
|
+
<script lang="ts">
|
|
19
|
+
import { classes, EMPTY_STATE_PARTS, rootPart } from "@xds/core";
|
|
20
|
+
import Icon from "./Icon.svelte";
|
|
21
|
+
|
|
22
|
+
let { icon, title, description, action, class: className, style }: EmptyStateProps = $props();
|
|
23
|
+
</script>
|
|
24
|
+
|
|
25
|
+
<div class={classes(rootPart("EmptyState"), EMPTY_STATE_PARTS.root, className)} {style}>
|
|
26
|
+
<Icon name={icon} size="xl" class={EMPTY_STATE_PARTS.icon} />
|
|
27
|
+
<p class={EMPTY_STATE_PARTS.title}>{title}</p>
|
|
28
|
+
{#if description}
|
|
29
|
+
<p class={EMPTY_STATE_PARTS.description}>{description}</p>
|
|
30
|
+
{/if}
|
|
31
|
+
{#if action}
|
|
32
|
+
<div class={EMPTY_STATE_PARTS.action}>{@render action()}</div>
|
|
33
|
+
{/if}
|
|
34
|
+
</div>
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { EmptyStateBaseProps } from "@xds/core";
|
|
2
|
+
import type { Snippet } from "svelte";
|
|
3
|
+
import type { RootProps } from "./root.js";
|
|
4
|
+
export type EmptyStateProps = EmptyStateBaseProps & RootProps & {
|
|
5
|
+
/** The one thing to do about it, usually a Button. */
|
|
6
|
+
action?: Snippet;
|
|
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
|
+
declare const EmptyState: import("svelte").Component<EmptyStateProps, {}, "">;
|
|
13
|
+
type EmptyState = ReturnType<typeof EmptyState>;
|
|
14
|
+
export default EmptyState;
|
package/dist/Icon.svelte
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
@component
|
|
3
|
+
An icon from design/icons. It takes the color of the text around it. An arrow or a chevron
|
|
4
|
+
mirrors itself in a right-to-left layout when given `rtl:-scale-x-100` in `class`.
|
|
5
|
+
-->
|
|
6
|
+
<script module lang="ts">
|
|
7
|
+
import type { IconBaseProps } from "@xds/core";
|
|
8
|
+
import type { RootProps } from "./root.js";
|
|
9
|
+
|
|
10
|
+
export type IconProps = IconBaseProps & RootProps;
|
|
11
|
+
</script>
|
|
12
|
+
|
|
13
|
+
<script lang="ts">
|
|
14
|
+
import { icons } from "@xds/tokens";
|
|
15
|
+
import { classes, iconClass, rootPart } from "@xds/core";
|
|
16
|
+
import { useDefaults } from "./defaults.svelte.js";
|
|
17
|
+
|
|
18
|
+
let { name, size: ownSize, filled, label, class: className, style }: IconProps = $props();
|
|
19
|
+
|
|
20
|
+
const defaults = useDefaults("Icon");
|
|
21
|
+
const size = $derived(ownSize ?? defaults().size);
|
|
22
|
+
</script>
|
|
23
|
+
|
|
24
|
+
<svg
|
|
25
|
+
viewBox="0 0 24 24"
|
|
26
|
+
fill={filled ? "currentColor" : "none"}
|
|
27
|
+
stroke="currentColor"
|
|
28
|
+
stroke-width="2"
|
|
29
|
+
stroke-linecap="round"
|
|
30
|
+
stroke-linejoin="round"
|
|
31
|
+
class={classes(rootPart("Icon"), iconClass(size), className)}
|
|
32
|
+
{style}
|
|
33
|
+
role={label ? "img" : undefined}
|
|
34
|
+
aria-label={label || undefined}
|
|
35
|
+
aria-hidden={label ? undefined : "true"}
|
|
36
|
+
>
|
|
37
|
+
{#each icons[name] as path, index (index)}<path d={path} />{/each}
|
|
38
|
+
</svg>
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { IconBaseProps } from "@xds/core";
|
|
2
|
+
import type { RootProps } from "./root.js";
|
|
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
|
+
declare const Icon: import("svelte").Component<IconProps, {}, "">;
|
|
9
|
+
type Icon = ReturnType<typeof Icon>;
|
|
10
|
+
export default Icon;
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
@component
|
|
3
|
+
A button that holds only an icon, in Button's variants, sizes and states. It is a square as
|
|
4
|
+
tall as a Button of its size, and its pressable area is never smaller than the minimum target,
|
|
5
|
+
even when the square is. Like Button, it opens a Menu or a Tooltip it is the trigger of.
|
|
6
|
+
-->
|
|
7
|
+
<script module lang="ts">
|
|
8
|
+
import type { IconButtonBaseProps } from "@xds/core";
|
|
9
|
+
import type { RootProps } from "./root.js";
|
|
10
|
+
|
|
11
|
+
export type IconButtonProps = IconButtonBaseProps &
|
|
12
|
+
RootProps & {
|
|
13
|
+
onPress?: () => void;
|
|
14
|
+
};
|
|
15
|
+
</script>
|
|
16
|
+
|
|
17
|
+
<script lang="ts">
|
|
18
|
+
import { buttonClass, classes, ICON_BUTTON_BOX, isHeld } from "@xds/core";
|
|
19
|
+
import type { HTMLButtonAttributes } from "svelte/elements";
|
|
20
|
+
import { useDefaults } from "./defaults.svelte.js";
|
|
21
|
+
import Icon from "./Icon.svelte";
|
|
22
|
+
import Spinner from "./Spinner.svelte";
|
|
23
|
+
import { withTrigger } from "./trigger.svelte.js";
|
|
24
|
+
|
|
25
|
+
let {
|
|
26
|
+
icon,
|
|
27
|
+
label,
|
|
28
|
+
variant: ownVariant,
|
|
29
|
+
size: ownSize,
|
|
30
|
+
selected,
|
|
31
|
+
disabled,
|
|
32
|
+
loading,
|
|
33
|
+
onPress,
|
|
34
|
+
class: className,
|
|
35
|
+
style,
|
|
36
|
+
}: IconButtonProps = $props();
|
|
37
|
+
|
|
38
|
+
const defaults = useDefaults("IconButton");
|
|
39
|
+
const variant = $derived(ownVariant ?? defaults().variant ?? "ghost");
|
|
40
|
+
const size = $derived(ownSize ?? defaults().size ?? "md");
|
|
41
|
+
|
|
42
|
+
const attributes = withTrigger(
|
|
43
|
+
(): HTMLButtonAttributes => ({
|
|
44
|
+
type: "button",
|
|
45
|
+
// The recipe gives the root part, `xds-icon-button`.
|
|
46
|
+
class: classes(buttonClass({ variant, size, iconButton: true }), className),
|
|
47
|
+
style,
|
|
48
|
+
disabled,
|
|
49
|
+
"aria-disabled": loading ? "true" : undefined,
|
|
50
|
+
"data-pending": loading ? "" : undefined,
|
|
51
|
+
"aria-pressed": selected === undefined ? undefined : selected ? "true" : "false",
|
|
52
|
+
"aria-label": label,
|
|
53
|
+
onclick: () => {
|
|
54
|
+
if (!loading) onPress?.();
|
|
55
|
+
},
|
|
56
|
+
}),
|
|
57
|
+
() => loading === true,
|
|
58
|
+
);
|
|
59
|
+
</script>
|
|
60
|
+
|
|
61
|
+
<button {...attributes()}>
|
|
62
|
+
{#if loading}
|
|
63
|
+
<span class={ICON_BUTTON_BOX[size]}><Spinner size="sm" /></span>
|
|
64
|
+
{:else}
|
|
65
|
+
<Icon name={icon} {size} filled={isHeld({ variant, selected, disabled })} />
|
|
66
|
+
{/if}
|
|
67
|
+
</button>
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { IconButtonBaseProps } from "@xds/core";
|
|
2
|
+
import type { RootProps } from "./root.js";
|
|
3
|
+
export type IconButtonProps = IconButtonBaseProps & RootProps & {
|
|
4
|
+
onPress?: () => void;
|
|
5
|
+
};
|
|
6
|
+
/**
|
|
7
|
+
* A button that holds only an icon, in Button's variants, sizes and states. It is a square as
|
|
8
|
+
* tall as a Button of its size, and its pressable area is never smaller than the minimum target,
|
|
9
|
+
* even when the square is. Like Button, it opens a Menu or a Tooltip it is the trigger of.
|
|
10
|
+
*/
|
|
11
|
+
declare const IconButton: import("svelte").Component<IconButtonProps, {}, "">;
|
|
12
|
+
type IconButton = ReturnType<typeof IconButton>;
|
|
13
|
+
export default IconButton;
|