@xds/solid 1.0.1 → 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/Accordion.js +3 -2
- package/dist/dom/Avatar.js +17 -13
- package/dist/dom/AvatarStack.js +17 -13
- package/dist/dom/Badge.js +12 -10
- package/dist/dom/Banner.js +25 -15
- package/dist/dom/Breadcrumb.js +87 -0
- package/dist/dom/Button.js +10 -3
- package/dist/dom/Card.js +31 -26
- package/dist/dom/Checkbox.js +57 -26
- package/dist/dom/Chip.js +21 -17
- package/dist/dom/ChipBar.js +17 -13
- package/dist/dom/Combobox.js +295 -0
- package/dist/dom/CountBadge.js +28 -23
- package/dist/dom/DatePicker.js +13 -7
- package/dist/dom/DateRangePicker.js +16 -10
- package/dist/dom/Dialog.js +3 -2
- package/dist/dom/Divider.js +12 -10
- package/dist/dom/EmptyState.js +14 -11
- package/dist/dom/Icon.js +30 -19
- package/dist/dom/IconButton.js +10 -3
- package/dist/dom/Labels.js +26 -0
- package/dist/dom/Link.js +62 -0
- package/dist/dom/ListRow.js +34 -28
- package/dist/dom/MediaCard.js +32 -23
- package/dist/dom/Menu.js +18 -15
- package/dist/dom/Pagination.js +132 -0
- package/dist/dom/Popover.js +126 -0
- package/dist/dom/ProgressBar.js +27 -15
- package/dist/dom/RadioGroup.js +44 -23
- package/dist/dom/SearchField.js +58 -32
- package/dist/dom/SectionHeader.js +17 -10
- package/dist/dom/SegmentedControl.js +33 -19
- package/dist/dom/Select.js +91 -51
- package/dist/dom/Sidebar.js +17 -13
- package/dist/dom/Skeleton.js +15 -13
- package/dist/dom/Slider.js +15 -7
- package/dist/dom/Spinner.js +23 -17
- package/dist/dom/Switch.js +49 -24
- package/dist/dom/Table.js +150 -0
- package/dist/dom/Tabs.js +16 -6
- package/dist/dom/Text.js +6 -3
- package/dist/dom/TextField.js +37 -19
- package/dist/dom/Thumbnail.js +21 -14
- package/dist/dom/TimePicker.js +245 -0
- package/dist/dom/Toast.js +19 -20
- package/dist/dom/ToastQueue.js +59 -0
- package/dist/dom/Tooltip.js +10 -6
- package/dist/dom/base.js +16 -0
- package/dist/dom/controllable.js +44 -0
- package/dist/dom/index.js +10 -1
- package/dist/dom/modal-popover.js +2 -2
- package/dist/dom/presence.js +3 -2
- package/dist/dom/preview.js +20 -1
- package/dist/dom/root.js +16 -4
- package/dist/dom/rows.js +13 -0
- package/dist/dom/trigger.js +5 -3
- package/dist/source/Accordion.jsx +3 -2
- package/dist/source/Avatar.d.ts +1 -1
- package/dist/source/Avatar.jsx +2 -1
- package/dist/source/AvatarStack.d.ts +1 -1
- package/dist/source/AvatarStack.jsx +2 -1
- package/dist/source/Badge.d.ts +1 -1
- package/dist/source/Badge.jsx +2 -1
- package/dist/source/Banner.d.ts +1 -1
- package/dist/source/Banner.jsx +5 -2
- package/dist/source/Breadcrumb.d.ts +9 -0
- package/dist/source/Breadcrumb.jsx +26 -0
- package/dist/source/Button.d.ts +5 -1
- package/dist/source/Button.jsx +5 -2
- package/dist/source/Card.d.ts +1 -1
- package/dist/source/Card.jsx +3 -2
- package/dist/source/Checkbox.d.ts +10 -4
- package/dist/source/Checkbox.jsx +26 -8
- package/dist/source/Chip.d.ts +1 -1
- package/dist/source/Chip.jsx +2 -1
- package/dist/source/ChipBar.d.ts +1 -1
- package/dist/source/ChipBar.jsx +2 -1
- package/dist/source/Combobox.d.ts +16 -0
- package/dist/source/Combobox.jsx +137 -0
- package/dist/source/CountBadge.d.ts +1 -1
- package/dist/source/CountBadge.jsx +3 -2
- package/dist/source/DatePicker.jsx +13 -7
- package/dist/source/DateRangePicker.jsx +16 -10
- package/dist/source/Dialog.jsx +3 -2
- package/dist/source/Divider.d.ts +1 -1
- package/dist/source/Divider.jsx +2 -1
- package/dist/source/EmptyState.d.ts +1 -1
- package/dist/source/EmptyState.jsx +2 -1
- package/dist/source/Icon.d.ts +1 -1
- package/dist/source/Icon.jsx +2 -1
- package/dist/source/IconButton.d.ts +5 -1
- package/dist/source/IconButton.jsx +5 -2
- package/dist/source/Labels.d.ts +17 -0
- package/dist/source/Labels.jsx +11 -0
- package/dist/source/Link.d.ts +20 -0
- package/dist/source/Link.jsx +21 -0
- package/dist/source/ListRow.d.ts +1 -1
- package/dist/source/ListRow.jsx +3 -2
- package/dist/source/MediaCard.d.ts +1 -1
- package/dist/source/MediaCard.jsx +3 -2
- package/dist/source/Menu.d.ts +1 -1
- package/dist/source/Menu.jsx +11 -3
- 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/ProgressBar.d.ts +1 -1
- package/dist/source/ProgressBar.jsx +2 -1
- package/dist/source/RadioGroup.d.ts +5 -2
- package/dist/source/RadioGroup.jsx +18 -5
- package/dist/source/SearchField.d.ts +11 -3
- package/dist/source/SearchField.jsx +26 -12
- package/dist/source/SectionHeader.d.ts +1 -1
- package/dist/source/SectionHeader.jsx +2 -1
- package/dist/source/SegmentedControl.d.ts +4 -3
- package/dist/source/SegmentedControl.jsx +16 -5
- package/dist/source/Select.d.ts +10 -1
- package/dist/source/Select.jsx +46 -11
- package/dist/source/Sidebar.d.ts +1 -1
- package/dist/source/Sidebar.jsx +2 -1
- package/dist/source/Skeleton.jsx +2 -2
- package/dist/source/Slider.d.ts +2 -2
- package/dist/source/Slider.jsx +14 -6
- package/dist/source/Spinner.d.ts +1 -1
- package/dist/source/Spinner.jsx +2 -1
- package/dist/source/Switch.d.ts +10 -4
- package/dist/source/Switch.jsx +18 -6
- package/dist/source/Table.d.ts +17 -0
- package/dist/source/Table.jsx +46 -0
- package/dist/source/Tabs.d.ts +2 -2
- package/dist/source/Tabs.jsx +16 -5
- package/dist/source/Text.d.ts +1 -1
- package/dist/source/Text.jsx +2 -1
- package/dist/source/TextField.d.ts +12 -3
- package/dist/source/TextField.jsx +24 -9
- package/dist/source/Thumbnail.d.ts +1 -1
- package/dist/source/Thumbnail.jsx +2 -1
- package/dist/source/TimePicker.d.ts +19 -0
- package/dist/source/TimePicker.jsx +137 -0
- package/dist/source/Toast.d.ts +1 -1
- package/dist/source/Toast.jsx +2 -1
- package/dist/source/ToastQueue.d.ts +19 -0
- package/dist/source/ToastQueue.jsx +27 -0
- package/dist/source/Tooltip.jsx +4 -3
- package/dist/source/base.d.ts +15 -0
- package/dist/source/base.js +15 -0
- package/dist/source/controllable.d.ts +30 -0
- package/dist/source/controllable.js +30 -0
- package/dist/source/index.d.ts +10 -1
- package/dist/source/index.js +9 -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 -2
- package/dist/source/root.d.ts +14 -4
- package/dist/source/root.js +7 -2
- package/dist/source/rows.d.ts +8 -0
- package/dist/source/rows.js +5 -0
- package/dist/source/trigger.d.ts +4 -2
- package/dist/source/trigger.js +2 -2
- 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 +1066 -167
- package/tailwind.css +1295 -218
|
@@ -0,0 +1,88 @@
|
|
|
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
|
+
composeRefs,
|
|
6
|
+
createControllable,
|
|
7
|
+
isControlled,
|
|
8
|
+
keepChecked,
|
|
9
|
+
type RootProps,
|
|
10
|
+
resetWithForm,
|
|
11
|
+
rootAttributes,
|
|
12
|
+
} from "@xds/solid/base";
|
|
13
|
+
import type { JSX } from "@solidjs/web";
|
|
14
|
+
import { Show } from "solid-js";
|
|
15
|
+
import { classes, rootPart } from "./parts.ts";
|
|
16
|
+
import {
|
|
17
|
+
type SwitchBaseProps,
|
|
18
|
+
switchClass,
|
|
19
|
+
switchLabelClass,
|
|
20
|
+
switchThumbClass,
|
|
21
|
+
switchTrackClass,
|
|
22
|
+
} from "./switch.ts";
|
|
23
|
+
|
|
24
|
+
export type SwitchProps = SwitchBaseProps &
|
|
25
|
+
RootProps & {
|
|
26
|
+
onChange?: (checked: boolean) => void;
|
|
27
|
+
onFocus?: JSX.FocusEventHandler<HTMLInputElement, FocusEvent>;
|
|
28
|
+
onBlur?: JSX.FocusEventHandler<HTMLInputElement, FocusEvent>;
|
|
29
|
+
/** The native checkbox, which has the switch role. */
|
|
30
|
+
ref?: JSX.Ref<HTMLInputElement>;
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
const ROOT = rootPart("Switch");
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Turns a setting on or off, and takes effect at once. For a choice that is applied later,
|
|
37
|
+
* with a form, use a Checkbox.
|
|
38
|
+
*
|
|
39
|
+
* It is a native checkbox with the switch role, so the keyboard, forms and screen readers
|
|
40
|
+
* treat it as one. The input is hidden and the track is drawn beside it. Without `checked` it
|
|
41
|
+
* keeps its own state, from `defaultChecked`.
|
|
42
|
+
*/
|
|
43
|
+
export function Switch(props: SwitchProps) {
|
|
44
|
+
const controlled = () => isControlled(props, "checked");
|
|
45
|
+
const defaultChecked = () => props.defaultChecked ?? false;
|
|
46
|
+
const checked = createControllable({
|
|
47
|
+
controlled,
|
|
48
|
+
value: () => props.checked ?? false,
|
|
49
|
+
defaultValue: defaultChecked,
|
|
50
|
+
onChange: (next) => props.onChange?.(next),
|
|
51
|
+
});
|
|
52
|
+
let input: HTMLInputElement | undefined;
|
|
53
|
+
resetWithForm(() => input, controlled, checked.reset);
|
|
54
|
+
return (
|
|
55
|
+
<label
|
|
56
|
+
{...rootAttributes(props)}
|
|
57
|
+
class={classes(ROOT, switchClass, props.class)}
|
|
58
|
+
style={props.style}
|
|
59
|
+
>
|
|
60
|
+
<input
|
|
61
|
+
ref={composeRefs(
|
|
62
|
+
(element) => (input = element),
|
|
63
|
+
() => props.ref,
|
|
64
|
+
)}
|
|
65
|
+
type="checkbox"
|
|
66
|
+
role="switch"
|
|
67
|
+
aria-checked={checked.value() ? "true" : "false"}
|
|
68
|
+
aria-label={props["aria-label"]}
|
|
69
|
+
class="peer sr-only"
|
|
70
|
+
checked={checked.value()}
|
|
71
|
+
defaultChecked={controlled() ? checked.value() : defaultChecked()}
|
|
72
|
+
disabled={props.disabled}
|
|
73
|
+
onChange={(event) => {
|
|
74
|
+
checked.set(event.currentTarget.checked);
|
|
75
|
+
keepChecked(event.currentTarget, checked.value);
|
|
76
|
+
}}
|
|
77
|
+
onFocus={(event) => props.onFocus?.(event)}
|
|
78
|
+
onBlur={(event) => props.onBlur?.(event)}
|
|
79
|
+
/>
|
|
80
|
+
<span class={switchTrackClass}>
|
|
81
|
+
<span class={switchThumbClass} />
|
|
82
|
+
</span>
|
|
83
|
+
<Show when={props.label}>
|
|
84
|
+
<span class={switchLabelClass}>{props.label}</span>
|
|
85
|
+
</Show>
|
|
86
|
+
</label>
|
|
87
|
+
);
|
|
88
|
+
}
|
|
@@ -0,0 +1,98 @@
|
|
|
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 { For, Show } from "solid-js";
|
|
6
|
+
import { Icon } from "./Icon.tsx";
|
|
7
|
+
import { classes, rootPart } from "./parts.ts";
|
|
8
|
+
import {
|
|
9
|
+
columnSort,
|
|
10
|
+
nextSort,
|
|
11
|
+
sortIcon,
|
|
12
|
+
TABLE_PARTS,
|
|
13
|
+
type TableBaseProps,
|
|
14
|
+
type TableSort,
|
|
15
|
+
} from "./table.ts";
|
|
16
|
+
|
|
17
|
+
export type { SortDirection, TableColumn, TableRow, TableSort } from "./table.ts";
|
|
18
|
+
|
|
19
|
+
export type TableProps = TableBaseProps &
|
|
20
|
+
RootProps & {
|
|
21
|
+
/**
|
|
22
|
+
* Called with the sort a press on a sortable column's header asks for. The app sorts the
|
|
23
|
+
* rows and gives the table the new `sort`.
|
|
24
|
+
*/
|
|
25
|
+
onSortChange?: (sort: TableSort) => void;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
const ROOT = rootPart("Table");
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Rows of data under a row of column headers, to read and compare across. The header of a
|
|
32
|
+
* sortable column is a button that asks for the rows sorted by it, ascending first and then the
|
|
33
|
+
* other way, and the header they are sorted by says so with `aria-sort` and an arrow. The rows
|
|
34
|
+
* are shown in the order given. Where the columns do not fit, the table scrolls sideways.
|
|
35
|
+
*/
|
|
36
|
+
export function Table(props: TableProps) {
|
|
37
|
+
const end = (align: string | undefined) => align === "end" && TABLE_PARTS.end;
|
|
38
|
+
return (
|
|
39
|
+
<div {...rootAttributes(props)} class={classes(ROOT, props.class)} style={props.style}>
|
|
40
|
+
<table class={TABLE_PARTS.table} aria-label={props.label}>
|
|
41
|
+
<thead>
|
|
42
|
+
<tr class={TABLE_PARTS.row}>
|
|
43
|
+
<For each={props.columns}>
|
|
44
|
+
{(column) => {
|
|
45
|
+
const direction = () => columnSort(props.sort, column.key);
|
|
46
|
+
return (
|
|
47
|
+
// oxlint-disable-next-line jsx-a11y/control-has-associated-label -- the column's label is its text, or its button's, behind Show
|
|
48
|
+
<th
|
|
49
|
+
scope="col"
|
|
50
|
+
aria-sort={direction()}
|
|
51
|
+
class={classes(TABLE_PARTS.header, end(column.align))}
|
|
52
|
+
>
|
|
53
|
+
<Show when={column.sortable} fallback={column.label}>
|
|
54
|
+
<button
|
|
55
|
+
type="button"
|
|
56
|
+
class={TABLE_PARTS.sort}
|
|
57
|
+
onClick={() => props.onSortChange?.(nextSort(props.sort, column.key))}
|
|
58
|
+
>
|
|
59
|
+
{column.label}
|
|
60
|
+
<Icon name={sortIcon(direction())} size="xs" />
|
|
61
|
+
</button>
|
|
62
|
+
</Show>
|
|
63
|
+
</th>
|
|
64
|
+
);
|
|
65
|
+
}}
|
|
66
|
+
</For>
|
|
67
|
+
</tr>
|
|
68
|
+
</thead>
|
|
69
|
+
<tbody>
|
|
70
|
+
<Show
|
|
71
|
+
when={props.rows.length > 0 || props.empty === undefined}
|
|
72
|
+
fallback={
|
|
73
|
+
<tr class={TABLE_PARTS.row}>
|
|
74
|
+
<td class={TABLE_PARTS.empty} colspan={props.columns.length}>
|
|
75
|
+
{props.empty}
|
|
76
|
+
</td>
|
|
77
|
+
</tr>
|
|
78
|
+
}
|
|
79
|
+
>
|
|
80
|
+
<For each={props.rows}>
|
|
81
|
+
{(row) => (
|
|
82
|
+
<tr class={TABLE_PARTS.row}>
|
|
83
|
+
<For each={props.columns}>
|
|
84
|
+
{(column, index) => (
|
|
85
|
+
<td class={classes(TABLE_PARTS.cell, end(column.align))}>
|
|
86
|
+
{row.cells[index()]}
|
|
87
|
+
</td>
|
|
88
|
+
)}
|
|
89
|
+
</For>
|
|
90
|
+
</tr>
|
|
91
|
+
)}
|
|
92
|
+
</For>
|
|
93
|
+
</Show>
|
|
94
|
+
</tbody>
|
|
95
|
+
</table>
|
|
96
|
+
</div>
|
|
97
|
+
);
|
|
98
|
+
}
|
|
@@ -0,0 +1,87 @@
|
|
|
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
|
+
createControllable,
|
|
6
|
+
isControlled,
|
|
7
|
+
type RootProps,
|
|
8
|
+
rootAttributes,
|
|
9
|
+
withStyle,
|
|
10
|
+
} from "@xds/solid/base";
|
|
11
|
+
import { mergeProps, normalizeProps, useMachine } from "@zag-js/solid";
|
|
12
|
+
import * as tabs from "@zag-js/tabs";
|
|
13
|
+
import { createMemo, createUniqueId, For, Show } from "solid-js";
|
|
14
|
+
import { Icon } from "./Icon.tsx";
|
|
15
|
+
import { classes } from "./parts.ts";
|
|
16
|
+
import { type TabsBaseProps, tabStopIndex, tabsClass } from "./tabs.ts";
|
|
17
|
+
|
|
18
|
+
export type TabsProps<Value extends string> = TabsBaseProps<Value> &
|
|
19
|
+
RootProps & {
|
|
20
|
+
onChange?: (value: Value) => void;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Switches between views inside one screen. For two to four short modes a SegmentedControl is
|
|
25
|
+
* lighter; tabs are for more items, longer labels, or a row that may have to scroll.
|
|
26
|
+
*
|
|
27
|
+
* The selected tab is underlined as well as darker, so the choice does not depend on color.
|
|
28
|
+
* This is only the row: the app shows the view that matches `value`. The arrow keys move
|
|
29
|
+
* between tabs. Without `value` they keep their own, from `defaultValue`, or the first tab.
|
|
30
|
+
*/
|
|
31
|
+
export function Tabs<Value extends string>(props: TabsProps<Value>) {
|
|
32
|
+
const id = createUniqueId();
|
|
33
|
+
const value = createControllable<Value | undefined>({
|
|
34
|
+
controlled: () => isControlled(props, "value"),
|
|
35
|
+
value: () => props.value,
|
|
36
|
+
defaultValue: () => props.defaultValue ?? props.items[0]?.value,
|
|
37
|
+
onChange: (next) => {
|
|
38
|
+
if (next !== undefined) props.onChange?.(next);
|
|
39
|
+
},
|
|
40
|
+
});
|
|
41
|
+
const service = useMachine(tabs.machine, () => ({
|
|
42
|
+
id,
|
|
43
|
+
// The app's id goes on the root, where Zag looks for it by this one.
|
|
44
|
+
ids: { root: props.id },
|
|
45
|
+
// Zag's own while the tabs are empty and nothing is chosen.
|
|
46
|
+
value: value.value() ?? null,
|
|
47
|
+
onValueChange: (details: tabs.ValueChangeDetails) => value.set(details.value as Value),
|
|
48
|
+
}));
|
|
49
|
+
const api = createMemo(() => tabs.connect(service, normalizeProps));
|
|
50
|
+
const root = withStyle(
|
|
51
|
+
() => api().getRootProps(),
|
|
52
|
+
() => props.style,
|
|
53
|
+
rootAttributes(props),
|
|
54
|
+
);
|
|
55
|
+
return (
|
|
56
|
+
// Its root part, `{{prefix}}-tabs`, is in the recipe.
|
|
57
|
+
<div {...root} class={classes(tabsClass(props.fullWidth), props.class)}>
|
|
58
|
+
<div {...api().getListProps()} aria-label={props.label} class="{{prefix}}-tabs__list">
|
|
59
|
+
<For each={props.items}>
|
|
60
|
+
{(item) => {
|
|
61
|
+
const trigger = () => api().getTriggerProps({ value: item.value });
|
|
62
|
+
// Zag's props carry it as `tabIndex`, which Solid's types do not list.
|
|
63
|
+
const tabIndex = () =>
|
|
64
|
+
tabStopIndex(
|
|
65
|
+
api().focusedValue,
|
|
66
|
+
item.value,
|
|
67
|
+
(trigger() as { tabIndex?: number }).tabIndex,
|
|
68
|
+
);
|
|
69
|
+
return (
|
|
70
|
+
<button
|
|
71
|
+
{...mergeProps(trigger, () => ({ tabIndex: tabIndex() }))}
|
|
72
|
+
// Zag points the selected tab at its panel, which this row never renders: the
|
|
73
|
+
// app shows the view. A reference to an element that does not exist is invalid.
|
|
74
|
+
aria-controls={undefined}
|
|
75
|
+
class="{{prefix}}-tabs__tab"
|
|
76
|
+
>
|
|
77
|
+
<Show when={item.icon}>{(name) => <Icon name={name()} size="sm" />}</Show>
|
|
78
|
+
{item.label}
|
|
79
|
+
</button>
|
|
80
|
+
);
|
|
81
|
+
}}
|
|
82
|
+
</For>
|
|
83
|
+
<div {...api().getIndicatorProps()} class="{{prefix}}-tabs__indicator" />
|
|
84
|
+
</div>
|
|
85
|
+
</div>
|
|
86
|
+
);
|
|
87
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
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 } from "@xds/solid/base";
|
|
5
|
+
import { dynamic, type ValidComponent } from "@solidjs/web";
|
|
6
|
+
import type { Element } from "solid-js";
|
|
7
|
+
import { classes, rootPart } from "./parts.ts";
|
|
8
|
+
import { type TextBaseProps, textClass } from "./text.ts";
|
|
9
|
+
|
|
10
|
+
export type TextProps = TextBaseProps &
|
|
11
|
+
RootProps & {
|
|
12
|
+
/** The element to render. Pick it for the document outline (`h1`, `h2`, `p`), not for looks. */
|
|
13
|
+
as?: ValidComponent;
|
|
14
|
+
children: Element;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
const ROOT = rootPart("Text");
|
|
18
|
+
|
|
19
|
+
export function Text(props: TextProps) {
|
|
20
|
+
const Tag = dynamic(() => props.as ?? "p");
|
|
21
|
+
const defaults = useDefaults("Text");
|
|
22
|
+
return (
|
|
23
|
+
<Tag
|
|
24
|
+
{...rootAttributes(props)}
|
|
25
|
+
class={classes(
|
|
26
|
+
ROOT,
|
|
27
|
+
textClass({
|
|
28
|
+
variant: props.variant ?? defaults().variant,
|
|
29
|
+
tone: props.tone ?? defaults().tone,
|
|
30
|
+
}),
|
|
31
|
+
props.class,
|
|
32
|
+
)}
|
|
33
|
+
style={props.style}
|
|
34
|
+
>
|
|
35
|
+
{props.children}
|
|
36
|
+
</Tag>
|
|
37
|
+
);
|
|
38
|
+
}
|
|
@@ -0,0 +1,171 @@
|
|
|
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
|
+
composeRefs,
|
|
6
|
+
createControllable,
|
|
7
|
+
isControlled,
|
|
8
|
+
keepValue,
|
|
9
|
+
type RootProps,
|
|
10
|
+
resetWithForm,
|
|
11
|
+
rootAttributes,
|
|
12
|
+
} from "@xds/solid/base";
|
|
13
|
+
import type { JSX } from "@solidjs/web";
|
|
14
|
+
import { children, createEffect, createUniqueId, type Element, onSettled, Show } from "solid-js";
|
|
15
|
+
import { classes } from "./parts.ts";
|
|
16
|
+
import type { TextFieldBaseProps } from "./text-field.ts";
|
|
17
|
+
|
|
18
|
+
type Field = HTMLInputElement | HTMLTextAreaElement;
|
|
19
|
+
|
|
20
|
+
export type TextFieldProps = TextFieldBaseProps &
|
|
21
|
+
RootProps & {
|
|
22
|
+
onChange?: (value: string) => void;
|
|
23
|
+
onFocus?: JSX.FocusEventHandler<Field, FocusEvent>;
|
|
24
|
+
onBlur?: JSX.FocusEventHandler<Field, FocusEvent>;
|
|
25
|
+
/** The native input, or the text area of a field of several lines. */
|
|
26
|
+
ref?: JSX.Ref<Field>;
|
|
27
|
+
/**
|
|
28
|
+
* Inside the box, in front of the text: an icon, a unit. It takes the placeholder's color
|
|
29
|
+
* unless it sets its own.
|
|
30
|
+
*/
|
|
31
|
+
leading?: Element;
|
|
32
|
+
/** Inside the box, after the text: an icon, a unit, a small button. */
|
|
33
|
+
trailing?: Element;
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* A labelled text field, of one line or several. The label, the description and the error
|
|
38
|
+
* message are tied to the input for assistive technology, and the error is announced when it
|
|
39
|
+
* appears.
|
|
40
|
+
*
|
|
41
|
+
* An invalid field blocks its form from being submitted, so `error` has to be cleared as soon as
|
|
42
|
+
* the person edits the value.
|
|
43
|
+
*
|
|
44
|
+
* Without `value` it keeps its own text, from `defaultValue`.
|
|
45
|
+
*/
|
|
46
|
+
export function TextField(props: TextFieldProps) {
|
|
47
|
+
const id = createUniqueId();
|
|
48
|
+
const descriptionId = `${id}-description`;
|
|
49
|
+
const errorId = `${id}-error`;
|
|
50
|
+
// Read once: each read of a JSX prop creates its nodes again.
|
|
51
|
+
const leading = children(() => props.leading);
|
|
52
|
+
const trailing = children(() => props.trailing);
|
|
53
|
+
const invalid = () => props.error !== undefined;
|
|
54
|
+
let input!: Field;
|
|
55
|
+
const controlled = () => isControlled(props, "value");
|
|
56
|
+
const defaultValue = () => props.defaultValue ?? "";
|
|
57
|
+
const value = createControllable({
|
|
58
|
+
controlled,
|
|
59
|
+
value: () => props.value ?? "",
|
|
60
|
+
defaultValue,
|
|
61
|
+
onChange: (next) => props.onChange?.(next),
|
|
62
|
+
});
|
|
63
|
+
resetWithForm(() => input, controlled, value.reset);
|
|
64
|
+
|
|
65
|
+
onSettled(() => {
|
|
66
|
+
// The value is set as a property, which leaves a text area's caret after the last line,
|
|
67
|
+
// and keyboard focus would then scroll to it. React renders the first value as the text
|
|
68
|
+
// area's own text, with the caret before the first line.
|
|
69
|
+
if (input instanceof HTMLTextAreaElement) input.setSelectionRange(0, 0);
|
|
70
|
+
if (props.autoFocus) input.focus();
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
createEffect(
|
|
74
|
+
() => [props.error, props.multiline] as const,
|
|
75
|
+
([error]) => {
|
|
76
|
+
input?.setCustomValidity(error ?? "");
|
|
77
|
+
},
|
|
78
|
+
);
|
|
79
|
+
|
|
80
|
+
// The attributes the input and the text area share. `box` when the input draws the box
|
|
81
|
+
// itself, which it does until something sits inside the box beside the text.
|
|
82
|
+
const shared = (box: boolean) => ({
|
|
83
|
+
id,
|
|
84
|
+
class: box
|
|
85
|
+
? "{{prefix}}-text-field__input {{prefix}}-text-field__control"
|
|
86
|
+
: "{{prefix}}-text-field__input",
|
|
87
|
+
value: value.value(),
|
|
88
|
+
defaultValue: controlled() ? value.value() : defaultValue(),
|
|
89
|
+
placeholder: props.placeholder,
|
|
90
|
+
name: props.name,
|
|
91
|
+
maxlength: props.maxLength,
|
|
92
|
+
inputmode: props.inputMode,
|
|
93
|
+
autocomplete: props.autoComplete,
|
|
94
|
+
required: props.required,
|
|
95
|
+
disabled: props.disabled,
|
|
96
|
+
readonly: props.readOnly,
|
|
97
|
+
"aria-invalid": invalid() ? ("true" as const) : undefined,
|
|
98
|
+
"aria-errormessage": invalid() ? errorId : undefined,
|
|
99
|
+
"aria-describedby": invalid() ? errorId : props.description ? descriptionId : undefined,
|
|
100
|
+
onInput: (event: InputEvent & { currentTarget: Field }) => {
|
|
101
|
+
value.set(event.currentTarget.value);
|
|
102
|
+
// While a composition is open the text belongs to the input method; it ends with
|
|
103
|
+
// compositionend.
|
|
104
|
+
if (!event.isComposing) keepValue(event.currentTarget, value.value);
|
|
105
|
+
},
|
|
106
|
+
onCompositionEnd: (event: CompositionEvent & { currentTarget: HTMLElement }) =>
|
|
107
|
+
keepValue(event.currentTarget as HTMLInputElement, value.value),
|
|
108
|
+
onFocus: (event: FocusEvent & { currentTarget: Field; target: Field }) =>
|
|
109
|
+
props.onFocus?.(event),
|
|
110
|
+
onBlur: (event: FocusEvent & { currentTarget: Field; target: Field }) => props.onBlur?.(event),
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
const ref = composeRefs<Field>(
|
|
114
|
+
(element) => (input = element),
|
|
115
|
+
() => props.ref,
|
|
116
|
+
);
|
|
117
|
+
const field = (box: boolean) =>
|
|
118
|
+
props.multiline ? (
|
|
119
|
+
<textarea ref={ref} rows={props.rows ?? 3} {...shared(box)} />
|
|
120
|
+
) : (
|
|
121
|
+
<input ref={ref} type={props.type ?? "text"} {...shared(box)} />
|
|
122
|
+
);
|
|
123
|
+
|
|
124
|
+
return (
|
|
125
|
+
<div
|
|
126
|
+
{...rootAttributes(props)}
|
|
127
|
+
class={classes("{{prefix}}-text-field", props.class)}
|
|
128
|
+
style={props.style}
|
|
129
|
+
>
|
|
130
|
+
<label for={id} class="{{prefix}}-text-field__label">
|
|
131
|
+
{props.label}
|
|
132
|
+
</label>
|
|
133
|
+
<Show when={leading() != null || trailing() != null} fallback={field(true)}>
|
|
134
|
+
<div class="{{prefix}}-text-field__control {{prefix}}-text-field__group">
|
|
135
|
+
<Show when={leading()}>
|
|
136
|
+
{(content) => (
|
|
137
|
+
<span class="{{prefix}}-text-field__slot {{prefix}}-text-field__slot--leading">
|
|
138
|
+
{content()}
|
|
139
|
+
</span>
|
|
140
|
+
)}
|
|
141
|
+
</Show>
|
|
142
|
+
{field(false)}
|
|
143
|
+
<Show when={trailing()}>
|
|
144
|
+
{(content) => (
|
|
145
|
+
<span class="{{prefix}}-text-field__slot {{prefix}}-text-field__slot--trailing">
|
|
146
|
+
{content()}
|
|
147
|
+
</span>
|
|
148
|
+
)}
|
|
149
|
+
</Show>
|
|
150
|
+
</div>
|
|
151
|
+
</Show>
|
|
152
|
+
{/* One line under the box: the help or the error at the start edge, the count at the
|
|
153
|
+
end. The error is a live region, so it is announced when it appears. */}
|
|
154
|
+
<div class="{{prefix}}-text-field__footer">
|
|
155
|
+
<Show when={!invalid() && props.description}>
|
|
156
|
+
<span id={descriptionId} class="{{prefix}}-text-field__description">
|
|
157
|
+
{props.description}
|
|
158
|
+
</span>
|
|
159
|
+
</Show>
|
|
160
|
+
<span id={errorId} class="{{prefix}}-text-field__error" aria-live="polite">
|
|
161
|
+
{props.error}
|
|
162
|
+
</span>
|
|
163
|
+
<Show when={props.maxLength !== undefined}>
|
|
164
|
+
<span class="ms-auto shrink-0 text-xds-footnote text-xds-text-secondary tabular-nums">
|
|
165
|
+
{value.value().length}/{props.maxLength}
|
|
166
|
+
</span>
|
|
167
|
+
</Show>
|
|
168
|
+
</div>
|
|
169
|
+
</div>
|
|
170
|
+
);
|
|
171
|
+
}
|
|
@@ -0,0 +1,84 @@
|
|
|
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
|
+
createPicture,
|
|
6
|
+
pictureClass,
|
|
7
|
+
type RootProps,
|
|
8
|
+
rootAttributes,
|
|
9
|
+
useDefaults,
|
|
10
|
+
} from "@xds/solid/base";
|
|
11
|
+
import { Show } from "solid-js";
|
|
12
|
+
import { Badge } from "./Badge.tsx";
|
|
13
|
+
import { Icon } from "./Icon.tsx";
|
|
14
|
+
import { classes, rootPart } from "./parts.ts";
|
|
15
|
+
import {
|
|
16
|
+
THUMBNAIL_PARTS,
|
|
17
|
+
type ThumbnailBaseProps,
|
|
18
|
+
thumbnailBadgeClass,
|
|
19
|
+
thumbnailClass,
|
|
20
|
+
thumbnailWatched,
|
|
21
|
+
} from "./thumbnail.ts";
|
|
22
|
+
|
|
23
|
+
export type { ThumbnailRatio } from "./thumbnail.ts";
|
|
24
|
+
|
|
25
|
+
export type ThumbnailProps = ThumbnailBaseProps & RootProps;
|
|
26
|
+
|
|
27
|
+
const ROOT = rootPart("Thumbnail");
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* A picture in a fixed shape, for a video, an article or a product. It fills the width it is
|
|
31
|
+
* given and takes its height from `ratio`, and crops the picture to fill it.
|
|
32
|
+
*/
|
|
33
|
+
export function Thumbnail(props: ThumbnailProps) {
|
|
34
|
+
const defaults = useDefaults("Thumbnail");
|
|
35
|
+
const picture = createPicture(() => props.src);
|
|
36
|
+
const watched = () => thumbnailWatched(props.progress);
|
|
37
|
+
return (
|
|
38
|
+
<span
|
|
39
|
+
{...rootAttributes(props)}
|
|
40
|
+
class={classes(ROOT, thumbnailClass(props.ratio ?? defaults().ratio), props.class)}
|
|
41
|
+
style={props.style}
|
|
42
|
+
>
|
|
43
|
+
{/* The placeholder is the picture's stand-in for assistive technology too, so the
|
|
44
|
+
description is on the box that always shows, not on the picture that may not. */}
|
|
45
|
+
<span
|
|
46
|
+
class={THUMBNAIL_PARTS.placeholder}
|
|
47
|
+
role={props.alt ? "img" : undefined}
|
|
48
|
+
aria-label={props.alt || undefined}
|
|
49
|
+
aria-hidden={props.alt ? undefined : "true"}
|
|
50
|
+
>
|
|
51
|
+
<Show when={picture.loaded() !== true}>
|
|
52
|
+
<Icon name="image" size="lg" />
|
|
53
|
+
</Show>
|
|
54
|
+
<Show when={picture.loaded() !== false && props.src}>
|
|
55
|
+
{(src) => (
|
|
56
|
+
<img
|
|
57
|
+
ref={(element) => picture.sync(element, src())}
|
|
58
|
+
src={src()}
|
|
59
|
+
alt=""
|
|
60
|
+
aria-hidden="true"
|
|
61
|
+
class={pictureClass(picture.loaded() === true)}
|
|
62
|
+
onLoad={() => picture.onLoad(src())}
|
|
63
|
+
onError={() => picture.onError(src())}
|
|
64
|
+
/>
|
|
65
|
+
)}
|
|
66
|
+
</Show>
|
|
67
|
+
</span>
|
|
68
|
+
<Show when={props.badge}>
|
|
69
|
+
{(badge) => (
|
|
70
|
+
<span class={thumbnailBadgeClass(watched())}>
|
|
71
|
+
<Badge tone="overlay">{badge()}</Badge>
|
|
72
|
+
</span>
|
|
73
|
+
)}
|
|
74
|
+
</Show>
|
|
75
|
+
<Show when={watched() > 0}>
|
|
76
|
+
{/* Decoration: what was watched is for the eye, and a list that needs it said says it
|
|
77
|
+
in words. */}
|
|
78
|
+
<span aria-hidden="true" class={THUMBNAIL_PARTS.track}>
|
|
79
|
+
<span class={THUMBNAIL_PARTS.fill} style={{ width: `${watched() * 100}%` }} />
|
|
80
|
+
</span>
|
|
81
|
+
</Show>
|
|
82
|
+
</span>
|
|
83
|
+
);
|
|
84
|
+
}
|