@xds/solid 1.1.0 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/dom/Breadcrumb.js +87 -0
- package/dist/dom/Checkbox.js +12 -6
- package/dist/dom/Combobox.js +295 -0
- package/dist/dom/Link.js +62 -0
- package/dist/dom/Menu.js +15 -14
- package/dist/dom/Pagination.js +132 -0
- package/dist/dom/Popover.js +126 -0
- package/dist/dom/Select.js +75 -48
- package/dist/dom/Table.js +150 -0
- package/dist/dom/TimePicker.js +245 -0
- package/dist/dom/ToastQueue.js +59 -0
- package/dist/dom/base.js +16 -0
- package/dist/dom/index.js +9 -1
- package/dist/dom/modal-popover.js +2 -2
- package/dist/dom/presence.js +3 -2
- package/dist/dom/preview.js +19 -2
- package/dist/dom/rows.js +13 -0
- package/dist/source/Breadcrumb.d.ts +9 -0
- package/dist/source/Breadcrumb.jsx +26 -0
- package/dist/source/Checkbox.d.ts +1 -1
- package/dist/source/Checkbox.jsx +9 -3
- package/dist/source/Combobox.d.ts +16 -0
- package/dist/source/Combobox.jsx +137 -0
- package/dist/source/Link.d.ts +20 -0
- package/dist/source/Link.jsx +21 -0
- package/dist/source/Menu.jsx +8 -2
- package/dist/source/Pagination.d.ts +12 -0
- package/dist/source/Pagination.jsx +51 -0
- package/dist/source/Popover.d.ts +19 -0
- package/dist/source/Popover.jsx +65 -0
- package/dist/source/Select.d.ts +6 -0
- package/dist/source/Select.jsx +32 -8
- package/dist/source/Table.d.ts +17 -0
- package/dist/source/Table.jsx +46 -0
- package/dist/source/TimePicker.d.ts +19 -0
- package/dist/source/TimePicker.jsx +137 -0
- package/dist/source/ToastQueue.d.ts +19 -0
- package/dist/source/ToastQueue.jsx +27 -0
- package/dist/source/base.d.ts +15 -0
- package/dist/source/base.js +15 -0
- package/dist/source/controllable.d.ts +1 -1
- package/dist/source/index.d.ts +9 -1
- package/dist/source/index.js +8 -0
- package/dist/source/modal-popover.js +2 -2
- package/dist/source/presence.js +3 -2
- package/dist/source/preview.d.ts +10 -2
- package/dist/source/preview.jsx +12 -3
- package/dist/source/rows.d.ts +8 -0
- package/dist/source/rows.js +5 -0
- package/eject/files/Accordion.tsx +138 -0
- package/eject/files/Avatar.tsx +48 -0
- package/eject/files/AvatarStack.tsx +51 -0
- package/eject/files/Badge.tsx +39 -0
- package/eject/files/Banner.tsx +80 -0
- package/eject/files/Breadcrumb.tsx +57 -0
- package/eject/files/Button.tsx +90 -0
- package/eject/files/Card.tsx +100 -0
- package/eject/files/Checkbox.tsx +100 -0
- package/eject/files/Chip.tsx +40 -0
- package/eject/files/ChipBar.tsx +34 -0
- package/eject/files/Combobox.tsx +200 -0
- package/eject/files/CountBadge.tsx +55 -0
- package/eject/files/DatePicker.tsx +225 -0
- package/eject/files/DateRangePicker.tsx +319 -0
- package/eject/files/Dialog.tsx +117 -0
- package/eject/files/Divider.tsx +21 -0
- package/eject/files/EmptyState.tsx +39 -0
- package/eject/files/Icon.tsx +37 -0
- package/eject/files/IconButton.tsx +76 -0
- package/eject/files/Link.tsx +61 -0
- package/eject/files/ListRow.tsx +94 -0
- package/eject/files/MediaCard.tsx +116 -0
- package/eject/files/Menu.tsx +190 -0
- package/eject/files/Pagination.tsx +109 -0
- package/eject/files/Popover.tsx +124 -0
- package/eject/files/ProgressBar.tsx +37 -0
- package/eject/files/RadioGroup.tsx +138 -0
- package/eject/files/SearchField.tsx +124 -0
- package/eject/files/SectionHeader.tsx +59 -0
- package/eject/files/SegmentedControl.tsx +79 -0
- package/eject/files/Select.tsx +290 -0
- package/eject/files/Sidebar.tsx +156 -0
- package/eject/files/Skeleton.tsx +33 -0
- package/eject/files/Slider.tsx +131 -0
- package/eject/files/Spinner.tsx +44 -0
- package/eject/files/Switch.tsx +88 -0
- package/eject/files/Table.tsx +98 -0
- package/eject/files/Tabs.tsx +87 -0
- package/eject/files/Text.tsx +38 -0
- package/eject/files/TextField.tsx +171 -0
- package/eject/files/Thumbnail.tsx +84 -0
- package/eject/files/TimePicker.tsx +237 -0
- package/eject/files/Toast.tsx +100 -0
- package/eject/files/ToastQueue.tsx +62 -0
- package/eject/files/Tooltip.tsx +135 -0
- package/eject/files/accordion.css +89 -0
- package/eject/files/accordion.ts +67 -0
- package/eject/files/avatar-stack.ts +57 -0
- package/eject/files/avatar.ts +42 -0
- package/eject/files/badge.ts +30 -0
- package/eject/files/banner.ts +71 -0
- package/eject/files/base.css +38 -0
- package/eject/files/breadcrumb.css +51 -0
- package/eject/files/breadcrumb.ts +42 -0
- package/eject/files/button.css +241 -0
- package/eject/files/button.ts +106 -0
- package/eject/files/card.ts +58 -0
- package/eject/files/checkbox.ts +52 -0
- package/eject/files/chip-bar.ts +16 -0
- package/eject/files/chip.ts +35 -0
- package/eject/files/combobox.css +269 -0
- package/eject/files/combobox.ts +85 -0
- package/eject/files/count-badge.ts +32 -0
- package/eject/files/date-picker.css +375 -0
- package/eject/files/date-picker.ts +280 -0
- package/eject/files/date-range-picker.ts +338 -0
- package/eject/files/dialog.css +139 -0
- package/eject/files/dialog.ts +15 -0
- package/eject/files/divider.ts +5 -0
- package/eject/files/empty-state.ts +22 -0
- package/eject/files/icon.ts +36 -0
- package/eject/files/link.css +64 -0
- package/eject/files/link.ts +63 -0
- package/eject/files/list-row.ts +66 -0
- package/eject/files/media-card.ts +66 -0
- package/eject/files/menu.css +192 -0
- package/eject/files/menu.ts +84 -0
- package/eject/files/overlay.css +40 -0
- package/eject/files/pagination.css +106 -0
- package/eject/files/pagination.ts +68 -0
- package/eject/files/parts.ts +17 -0
- package/eject/files/popover.css +101 -0
- package/eject/files/popover.ts +37 -0
- package/eject/files/progress-bar.ts +26 -0
- package/eject/files/radio-group.css +184 -0
- package/eject/files/radio-group.ts +30 -0
- package/eject/files/section-header.ts +32 -0
- package/eject/files/segmented-control.ts +33 -0
- package/eject/files/select.css +347 -0
- package/eject/files/select.ts +77 -0
- package/eject/files/sidebar.ts +75 -0
- package/eject/files/skeleton.ts +51 -0
- package/eject/files/slider.css +160 -0
- package/eject/files/slider.ts +80 -0
- package/eject/files/spinner.ts +22 -0
- package/eject/files/switch.ts +45 -0
- package/eject/files/table.css +107 -0
- package/eject/files/table.ts +84 -0
- package/eject/files/tabs.css +120 -0
- package/eject/files/tabs.ts +37 -0
- package/eject/files/text-field.css +225 -0
- package/eject/files/text-field.ts +64 -0
- package/eject/files/text.ts +38 -0
- package/eject/files/thumbnail.ts +51 -0
- package/eject/files/time-picker.ts +113 -0
- package/eject/files/toast-queue.ts +64 -0
- package/eject/files/toast.ts +31 -0
- package/eject/files/tooltip.css +111 -0
- package/eject/files/tooltip.ts +21 -0
- package/eject/manifest.json +1027 -0
- package/package.json +12 -4
- package/styles.css +1064 -169
- package/tailwind.css +1295 -218
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
import { space } from "@xds/tokens";
|
|
2
|
+
import { COMBOBOX_PARTS as PARTS, classes, isControlled, matchOptions, readCssPx, selectOptionIds, } from "@xds/core";
|
|
3
|
+
import * as combobox from "@zag-js/combobox";
|
|
4
|
+
import { mergeProps, normalizeProps, useMachine } from "@zag-js/solid";
|
|
5
|
+
import { createMemo, createSignal, createUniqueId, For, Show } from "solid-js";
|
|
6
|
+
import { createControllable, resetWithForm } from "./controllable.js";
|
|
7
|
+
import { Icon } from "./Icon.jsx";
|
|
8
|
+
import { useLabels } from "./Labels.jsx";
|
|
9
|
+
import { Portal } from "./portal.jsx";
|
|
10
|
+
import { rootAttributes, withStyle } from "./root.js";
|
|
11
|
+
import { createItemProps } from "./rows.js";
|
|
12
|
+
export function Combobox(props) {
|
|
13
|
+
const id = createUniqueId();
|
|
14
|
+
const descriptionId = `${id}-description`;
|
|
15
|
+
const errorId = `${id}-error`;
|
|
16
|
+
const labels = useLabels();
|
|
17
|
+
const invalid = () => props.error !== undefined;
|
|
18
|
+
const controlled = () => isControlled(props, "value");
|
|
19
|
+
const value = createControllable({
|
|
20
|
+
controlled,
|
|
21
|
+
value: () => props.value,
|
|
22
|
+
defaultValue: () => props.defaultValue,
|
|
23
|
+
onChange: (next) => {
|
|
24
|
+
if (next !== undefined)
|
|
25
|
+
props.onChange?.(next);
|
|
26
|
+
},
|
|
27
|
+
});
|
|
28
|
+
let element;
|
|
29
|
+
resetWithForm(() => element, controlled, value.reset);
|
|
30
|
+
const [query, setQuery] = createSignal("");
|
|
31
|
+
const shown = createMemo(() => matchOptions(props.options, query()));
|
|
32
|
+
const collection = createMemo(() => combobox.collection({
|
|
33
|
+
items: shown(),
|
|
34
|
+
itemToValue: (option) => option.value,
|
|
35
|
+
itemToString: (option) => option.label,
|
|
36
|
+
}));
|
|
37
|
+
const service = useMachine(combobox.machine, () => ({
|
|
38
|
+
id,
|
|
39
|
+
ids: { root: props.id },
|
|
40
|
+
collection: collection(),
|
|
41
|
+
value: value.value() === undefined ? [] : [value.value()],
|
|
42
|
+
onValueChange: (details) => {
|
|
43
|
+
const next = details.value[0];
|
|
44
|
+
if (next !== undefined)
|
|
45
|
+
value.set(next);
|
|
46
|
+
},
|
|
47
|
+
onInputValueChange: (details) => {
|
|
48
|
+
if (details.reason === "input-change")
|
|
49
|
+
setQuery(details.inputValue);
|
|
50
|
+
},
|
|
51
|
+
onOpenChange: (details) => {
|
|
52
|
+
if (!details.open)
|
|
53
|
+
setQuery("");
|
|
54
|
+
},
|
|
55
|
+
inputBehavior: "autohighlight",
|
|
56
|
+
selectionBehavior: "replace",
|
|
57
|
+
openOnClick: true,
|
|
58
|
+
disabled: props.disabled,
|
|
59
|
+
invalid: invalid(),
|
|
60
|
+
placeholder: props.placeholder,
|
|
61
|
+
positioning: {
|
|
62
|
+
placement: "bottom-start",
|
|
63
|
+
gutter: readCssPx(null, "--xds-space-1", space[1]),
|
|
64
|
+
sameWidth: true,
|
|
65
|
+
overflowPadding: readCssPx(null, "--xds-space-3", space[3]),
|
|
66
|
+
},
|
|
67
|
+
}));
|
|
68
|
+
const api = createMemo(() => combobox.connect(service, normalizeProps));
|
|
69
|
+
const input = mergeProps(() => api().getInputProps(), {
|
|
70
|
+
onBlur: () => {
|
|
71
|
+
const chosen = props.options.find((option) => option.value === value.value())?.label ?? "";
|
|
72
|
+
const now = combobox.connect(service, normalizeProps);
|
|
73
|
+
if (now.inputValue !== chosen)
|
|
74
|
+
now.setInputValue(chosen, "script");
|
|
75
|
+
},
|
|
76
|
+
});
|
|
77
|
+
const root = withStyle(() => api().getRootProps(), () => props.style, rootAttributes(props));
|
|
78
|
+
return (<div {...root} ref={(node) => (element = node)} class={classes("xds-combobox", props.class)}>
|
|
79
|
+
<label {...api().getLabelProps()} class={PARTS.label}>
|
|
80
|
+
{props.label}
|
|
81
|
+
</label>
|
|
82
|
+
<div {...api().getControlProps()} class={PARTS.control}>
|
|
83
|
+
<input {...input} aria-describedby={invalid() ? errorId : props.description ? descriptionId : undefined} class={PARTS.input}/>
|
|
84
|
+
<Icon name="chevrons-up-down" size="sm" class={PARTS.icon}/>
|
|
85
|
+
</div>
|
|
86
|
+
<div class={PARTS.footer}>
|
|
87
|
+
<Show when={!invalid() && props.description}>
|
|
88
|
+
<span id={descriptionId} class={PARTS.description}>
|
|
89
|
+
{props.description}
|
|
90
|
+
</span>
|
|
91
|
+
</Show>
|
|
92
|
+
<span id={errorId} class={PARTS.error} aria-live="polite">
|
|
93
|
+
{props.error}
|
|
94
|
+
</span>
|
|
95
|
+
</div>
|
|
96
|
+
|
|
97
|
+
<Show when={props.name !== undefined}>
|
|
98
|
+
<input type="hidden" name={props.name} value={value.value() ?? ""}/>
|
|
99
|
+
</Show>
|
|
100
|
+
<Portal>
|
|
101
|
+
<div {...api().getPositionerProps()} class={PARTS.positioner}>
|
|
102
|
+
|
|
103
|
+
<div {...api().getContentProps()} class={PARTS.content}>
|
|
104
|
+
<Show when={shown().length > 0} fallback={<div {...api().getEmptyProps()} class={PARTS.empty}>
|
|
105
|
+
{props.emptyLabel ?? labels().noMatches}
|
|
106
|
+
</div>}>
|
|
107
|
+
<div {...api().getListProps()} class={PARTS.list}>
|
|
108
|
+
<For each={shown()}>
|
|
109
|
+
{(option, index) => {
|
|
110
|
+
const ids = () => selectOptionIds(id, index());
|
|
111
|
+
const itemProps = createItemProps(() => api().getItemProps({ item: option }));
|
|
112
|
+
const textProps = createItemProps(() => api().getItemTextProps({ item: option }));
|
|
113
|
+
const selected = createMemo(() => api().getItemState({ item: option }).selected);
|
|
114
|
+
return (<div {...itemProps()} aria-labelledby={ids().label} aria-describedby={option.description ? ids().description : undefined} class={PARTS.item}>
|
|
115
|
+
<span class={PARTS.itemWords}>
|
|
116
|
+
<span {...textProps()} id={ids().label} class={PARTS.itemLabel}>
|
|
117
|
+
{option.label}
|
|
118
|
+
</span>
|
|
119
|
+
<Show when={option.description}>
|
|
120
|
+
<span id={ids().description} class={PARTS.itemDescription}>
|
|
121
|
+
{option.description}
|
|
122
|
+
</span>
|
|
123
|
+
</Show>
|
|
124
|
+
</span>
|
|
125
|
+
<Show when={selected()}>
|
|
126
|
+
<Icon name="check" size="sm"/>
|
|
127
|
+
</Show>
|
|
128
|
+
</div>);
|
|
129
|
+
}}
|
|
130
|
+
</For>
|
|
131
|
+
</div>
|
|
132
|
+
</Show>
|
|
133
|
+
</div>
|
|
134
|
+
</div>
|
|
135
|
+
</Portal>
|
|
136
|
+
</div>);
|
|
137
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { type LinkBaseProps } from "@xds/core";
|
|
2
|
+
import { type JSX } from "@solidjs/web";
|
|
3
|
+
import { type Element } from "solid-js";
|
|
4
|
+
import { type RootProps } from "./root.ts";
|
|
5
|
+
export type LinkProps = LinkBaseProps & RootProps & {
|
|
6
|
+
/** Called on a press, before the browser follows `href`. A disabled link never calls it. */
|
|
7
|
+
onPress?: () => void;
|
|
8
|
+
onFocus?: JSX.FocusEventHandler<HTMLElement, FocusEvent>;
|
|
9
|
+
onBlur?: JSX.FocusEventHandler<HTMLElement, FocusEvent>;
|
|
10
|
+
/** The native element: an `<a>`, or a `<button>` for a link without `href`. */
|
|
11
|
+
ref?: JSX.Ref<HTMLElement>;
|
|
12
|
+
/** The text, which names the link. */
|
|
13
|
+
children: Element;
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* Text that takes the person somewhere, in the type of the text around it. It is underlined, so
|
|
17
|
+
* it does not depend on color. With `href` it is a native link; without one, a button that
|
|
18
|
+
* assistive technology hears as a link.
|
|
19
|
+
*/
|
|
20
|
+
export declare function Link(props: LinkProps): JSX.Element;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { classes, LINK_ICON, LINK_PARTS, linkElement, rootPart, } from "@xds/core";
|
|
2
|
+
import { dynamic } from "@solidjs/web";
|
|
3
|
+
import { createMemo, Show } from "solid-js";
|
|
4
|
+
import { composeRefs } from "./controllable.js";
|
|
5
|
+
import { Icon } from "./Icon.jsx";
|
|
6
|
+
import { rootAttributes } from "./root.js";
|
|
7
|
+
const ROOT = rootPart("Link");
|
|
8
|
+
export function Link(props) {
|
|
9
|
+
const element = createMemo(() => linkElement({ href: props.href, external: props.external, disabled: props.disabled }));
|
|
10
|
+
const Tag = dynamic(() => element().tag);
|
|
11
|
+
const ref = composeRefs(() => { }, () => props.ref);
|
|
12
|
+
return (<Tag ref={ref} {...rootAttributes(props)} {...element().attributes} class={classes(ROOT, props.class)} style={props.style} onClick={() => {
|
|
13
|
+
if (!props.disabled)
|
|
14
|
+
props.onPress?.();
|
|
15
|
+
}} onFocus={(event) => props.onFocus?.(event)} onBlur={(event) => props.onBlur?.(event)}>
|
|
16
|
+
{props.children}
|
|
17
|
+
<Show when={props.external}>
|
|
18
|
+
<Icon name={LINK_ICON.name} size={LINK_ICON.size} class={LINK_PARTS.icon}/>
|
|
19
|
+
</Show>
|
|
20
|
+
</Tag>);
|
|
21
|
+
}
|
package/dist/source/Menu.jsx
CHANGED
|
@@ -8,6 +8,7 @@ import { modalPopover } from "./modal-popover.js";
|
|
|
8
8
|
import { Portal } from "./portal.jsx";
|
|
9
9
|
import { createPresence } from "./presence.js";
|
|
10
10
|
import { rootAttributes } from "./root.js";
|
|
11
|
+
import { createItemProps } from "./rows.js";
|
|
11
12
|
import { provideTrigger, TriggerContext } from "./trigger.js";
|
|
12
13
|
export function Menu(props) {
|
|
13
14
|
const id = createUniqueId();
|
|
@@ -82,7 +83,11 @@ export function Menu(props) {
|
|
|
82
83
|
|
|
83
84
|
<div {...content} ref={(element) => (surface = element)} hidden={!present()} class={classes("xds-menu", props.class)}>
|
|
84
85
|
<For each={props.items}>
|
|
85
|
-
{(item, index) =>
|
|
86
|
+
{(item, index) => {
|
|
87
|
+
if (item === "separator")
|
|
88
|
+
return <div {...api().getSeparatorProps()} class="xds-menu__separator"/>;
|
|
89
|
+
const itemProps = createItemProps(() => api().getItemProps({ value: String(index()), disabled: item.disabled }));
|
|
90
|
+
return (<div {...itemProps()} class={menuItemClass(item.danger)}>
|
|
86
91
|
<Show when={item.icon}>
|
|
87
92
|
{(name) => <Icon name={name()} size="sm" class="xds-menu__item-icon"/>}
|
|
88
93
|
</Show>
|
|
@@ -91,7 +96,8 @@ export function Menu(props) {
|
|
|
91
96
|
<Show when={item.selected}>
|
|
92
97
|
<Icon name="check" size="sm" label="Selected"/>
|
|
93
98
|
</Show>
|
|
94
|
-
</div>)
|
|
99
|
+
</div>);
|
|
100
|
+
}}
|
|
95
101
|
</For>
|
|
96
102
|
</div>
|
|
97
103
|
</div>
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { type PaginationBaseProps } from "@xds/core";
|
|
2
|
+
import { type RootProps } from "./root.ts";
|
|
3
|
+
export type PaginationProps = PaginationBaseProps & RootProps & {
|
|
4
|
+
/** Called with the page to show, from 1. */
|
|
5
|
+
onChange?: (value: number) => void;
|
|
6
|
+
};
|
|
7
|
+
/**
|
|
8
|
+
* Moves through a list split into pages: a step back, the first and the last pages, the page
|
|
9
|
+
* shown with an ellipsis for those left out, and a step on. A navigation landmark; the page
|
|
10
|
+
* shown is marked as the current page. Without `value` it keeps its own, from `defaultValue`.
|
|
11
|
+
*/
|
|
12
|
+
export declare function Pagination(props: PaginationProps): import("@solidjs/web").JSX.Element;
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { clampPage, classes, isControlled, PAGINATION_PARTS, PAGINATION_STEPS, paginationEntries, rootPart, } from "@xds/core";
|
|
2
|
+
import { For, Show } from "solid-js";
|
|
3
|
+
import { createControllable } from "./controllable.js";
|
|
4
|
+
import { Icon } from "./Icon.jsx";
|
|
5
|
+
import { useLabels } from "./Labels.jsx";
|
|
6
|
+
import { rootAttributes } from "./root.js";
|
|
7
|
+
const ROOT = rootPart("Pagination");
|
|
8
|
+
export function Pagination(props) {
|
|
9
|
+
const labels = useLabels();
|
|
10
|
+
const value = createControllable({
|
|
11
|
+
controlled: () => isControlled(props, "value"),
|
|
12
|
+
value: () => props.value,
|
|
13
|
+
defaultValue: () => props.defaultValue ?? 1,
|
|
14
|
+
onChange: (next) => {
|
|
15
|
+
if (next !== undefined)
|
|
16
|
+
props.onChange?.(next);
|
|
17
|
+
},
|
|
18
|
+
});
|
|
19
|
+
const page = () => clampPage(value.value() ?? 1, props.count);
|
|
20
|
+
const last = () => Math.max(1, Math.floor(props.count));
|
|
21
|
+
const go = (next) => {
|
|
22
|
+
if (next !== page() && next >= 1 && next <= last())
|
|
23
|
+
value.set(next);
|
|
24
|
+
};
|
|
25
|
+
return (<nav {...rootAttributes(props)} aria-label={props.label ?? labels().pagination} class={classes(ROOT, props.class)} style={props.style}>
|
|
26
|
+
<ul class={PAGINATION_PARTS.list}>
|
|
27
|
+
<li>
|
|
28
|
+
<button type="button" class={PAGINATION_PARTS.step} aria-label={props.previousLabel ?? labels().previousPage} aria-disabled={page() <= 1 ? "true" : undefined} onClick={() => go(page() - 1)}>
|
|
29
|
+
<Icon name={PAGINATION_STEPS.previous} size={PAGINATION_STEPS.size}/>
|
|
30
|
+
</button>
|
|
31
|
+
</li>
|
|
32
|
+
|
|
33
|
+
<For each={paginationEntries(page(), props.count)} keyed={false}>
|
|
34
|
+
{(entry) => (<li>
|
|
35
|
+
<Show when={entry() !== "gap" && entry()} fallback={<span class={PAGINATION_PARTS.gap} aria-hidden="true">
|
|
36
|
+
…
|
|
37
|
+
</span>}>
|
|
38
|
+
{(number) => (<button type="button" class={PAGINATION_PARTS.page} aria-current={number() === page() ? "page" : undefined} onClick={() => go(number())}>
|
|
39
|
+
{number()}
|
|
40
|
+
</button>)}
|
|
41
|
+
</Show>
|
|
42
|
+
</li>)}
|
|
43
|
+
</For>
|
|
44
|
+
<li>
|
|
45
|
+
<button type="button" class={PAGINATION_PARTS.step} aria-label={props.nextLabel ?? labels().nextPage} aria-disabled={page() >= last() ? "true" : undefined} onClick={() => go(page() + 1)}>
|
|
46
|
+
<Icon name={PAGINATION_STEPS.next} size={PAGINATION_STEPS.size}/>
|
|
47
|
+
</button>
|
|
48
|
+
</li>
|
|
49
|
+
</ul>
|
|
50
|
+
</nav>);
|
|
51
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { type PopoverBaseProps } from "@xds/core";
|
|
2
|
+
import { type Element } from "solid-js";
|
|
3
|
+
import { type RootProps } from "./root.ts";
|
|
4
|
+
/** `class` and `style` are for the popover's surface, not for its trigger. */
|
|
5
|
+
export type PopoverProps = PopoverBaseProps & RootProps & {
|
|
6
|
+
/** The control that opens it: a Button or an IconButton. */
|
|
7
|
+
trigger: Element;
|
|
8
|
+
/** Called with whether it is open, as it opens and closes. */
|
|
9
|
+
onOpenChange?: (open: boolean) => void;
|
|
10
|
+
/** What it holds: a few lines of text, a short form, actions. */
|
|
11
|
+
children?: Element;
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* A surface that opens beside the control that opens it, for details or a short task that do
|
|
15
|
+
* not need the whole screen: a press outside, Escape or its close button closes it, and the
|
|
16
|
+
* focus goes back to the trigger. It is a dialog named by its title, and not modal: the page
|
|
17
|
+
* stays as it is behind it. Without `open` it keeps its own, from `defaultOpen`.
|
|
18
|
+
*/
|
|
19
|
+
export declare function Popover(props: PopoverProps): import("@solidjs/web").JSX.Element;
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { space } from "@xds/tokens";
|
|
2
|
+
import { classes, isControlled, leaveEscapeToFields, POPOVER_PARTS, readCssPx, } from "@xds/core";
|
|
3
|
+
import * as popover from "@zag-js/popover";
|
|
4
|
+
import { mergeProps, normalizeProps, useMachine } from "@zag-js/solid";
|
|
5
|
+
import { createMemo, createUniqueId, Show } from "solid-js";
|
|
6
|
+
import { createControllable } from "./controllable.js";
|
|
7
|
+
import { IconButton } from "./IconButton.jsx";
|
|
8
|
+
import { useLabels } from "./Labels.jsx";
|
|
9
|
+
import { Portal } from "./portal.jsx";
|
|
10
|
+
import { createPresence } from "./presence.js";
|
|
11
|
+
import { rootAttributes, withStyle } from "./root.js";
|
|
12
|
+
import { provideTrigger, TriggerContext } from "./trigger.js";
|
|
13
|
+
export function Popover(props) {
|
|
14
|
+
const id = createUniqueId();
|
|
15
|
+
const labels = useLabels();
|
|
16
|
+
const open = createControllable({
|
|
17
|
+
controlled: () => isControlled(props, "open"),
|
|
18
|
+
value: () => props.open,
|
|
19
|
+
defaultValue: () => props.defaultOpen ?? false,
|
|
20
|
+
onChange: (next) => props.onOpenChange?.(next ?? false),
|
|
21
|
+
});
|
|
22
|
+
let content;
|
|
23
|
+
const service = useMachine(popover.machine, () => ({
|
|
24
|
+
id,
|
|
25
|
+
ids: { content: props.id },
|
|
26
|
+
open: open.value() ?? false,
|
|
27
|
+
onOpenChange: (details) => open.set(details.open),
|
|
28
|
+
positioning: {
|
|
29
|
+
placement: props.placement ?? "bottom",
|
|
30
|
+
gutter: readCssPx(null, "--xds-space-1", space[1]),
|
|
31
|
+
},
|
|
32
|
+
onEscapeKeyDown: leaveEscapeToFields,
|
|
33
|
+
initialFocusEl: () => content ?? null,
|
|
34
|
+
}));
|
|
35
|
+
const api = createMemo(() => popover.connect(service, normalizeProps));
|
|
36
|
+
const trigger = provideTrigger(() => mergeProps(api().getTriggerProps(), {
|
|
37
|
+
class: POPOVER_PARTS.trigger,
|
|
38
|
+
}));
|
|
39
|
+
const contentProps = withStyle(() => api().getContentProps(), () => props.style, rootAttributes(props));
|
|
40
|
+
const present = createPresence(() => api().open, () => [content]);
|
|
41
|
+
return (<>
|
|
42
|
+
<TriggerContext value={trigger}>{props.trigger}</TriggerContext>
|
|
43
|
+
<Show when={present()}>
|
|
44
|
+
<Portal>
|
|
45
|
+
|
|
46
|
+
<TriggerContext value={null}>
|
|
47
|
+
<div {...api().getPositionerProps()} class={POPOVER_PARTS.positioner}>
|
|
48
|
+
|
|
49
|
+
<section {...contentProps} ref={(element) => (content = element)} hidden={false} class={classes("xds-popover", props.class)}>
|
|
50
|
+
<div class={POPOVER_PARTS.header}>
|
|
51
|
+
<h2 {...api().getTitleProps()} class={POPOVER_PARTS.title}>
|
|
52
|
+
{props.title}
|
|
53
|
+
</h2>
|
|
54
|
+
<IconButton icon="x" label={props.closeLabel ?? labels().close} variant="ghost" size="sm" class={POPOVER_PARTS.close} onPress={() => api().setOpen(false)}/>
|
|
55
|
+
</div>
|
|
56
|
+
<Show when={props.children != null}>
|
|
57
|
+
<div class={POPOVER_PARTS.body}>{props.children}</div>
|
|
58
|
+
</Show>
|
|
59
|
+
</section>
|
|
60
|
+
</div>
|
|
61
|
+
</TriggerContext>
|
|
62
|
+
</Portal>
|
|
63
|
+
</Show>
|
|
64
|
+
</>);
|
|
65
|
+
}
|
package/dist/source/Select.d.ts
CHANGED
|
@@ -4,6 +4,8 @@ import { type RootProps } from "./root.ts";
|
|
|
4
4
|
export type { SelectOption } from "@xds/core";
|
|
5
5
|
export type SelectProps<Value extends string = string> = SelectBaseProps<Value> & RootProps & {
|
|
6
6
|
onChange?: (value: Value) => void;
|
|
7
|
+
/** Called with the chosen options of a select with `multiple`, in the options' order. */
|
|
8
|
+
onValuesChange?: (values: Value[]) => void;
|
|
7
9
|
};
|
|
8
10
|
/**
|
|
9
11
|
* A field for choosing one option from a list too long to show at once. Closed, it looks like a
|
|
@@ -17,5 +19,9 @@ export type SelectProps<Value extends string = string> = SelectBaseProps<Value>
|
|
|
17
19
|
*
|
|
18
20
|
* Without `value` it keeps its own choice, from `defaultValue`. Given `value`, even as
|
|
19
21
|
* `undefined`, it shows that.
|
|
22
|
+
*
|
|
23
|
+
* With `multiple`, any number of options can be chosen: choosing one adds it or takes it away,
|
|
24
|
+
* the list stays open, and `onValuesChange` gets them all. The list box says that several can
|
|
25
|
+
* be chosen.
|
|
20
26
|
*/
|
|
21
27
|
export declare function Select<Value extends string = string>(props: SelectProps<Value>): JSX.Element;
|
package/dist/source/Select.jsx
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { space } from "@xds/tokens";
|
|
2
|
-
import { classes, isControlled, keepListKeys, readCssPx, selectOptionIds, underlayLayerStyle, } from "@xds/core";
|
|
2
|
+
import { classes, isControlled, keepListKeys, orderedValues, readCssPx, selectedLabels, selectOptionIds, underlayLayerStyle, } from "@xds/core";
|
|
3
3
|
import * as select from "@zag-js/select";
|
|
4
4
|
import { mergeProps, normalizeProps, useMachine } from "@zag-js/solid";
|
|
5
5
|
import { createMemo, createUniqueId, For, Show } from "solid-js";
|
|
@@ -9,6 +9,7 @@ import { modalPopover } from "./modal-popover.js";
|
|
|
9
9
|
import { Portal } from "./portal.jsx";
|
|
10
10
|
import { createPresence } from "./presence.js";
|
|
11
11
|
import { rootAttributes, withStyle } from "./root.js";
|
|
12
|
+
import { createItemProps } from "./rows.js";
|
|
12
13
|
export function Select(props) {
|
|
13
14
|
const id = createUniqueId();
|
|
14
15
|
const valueId = `${id}-value`;
|
|
@@ -24,6 +25,13 @@ export function Select(props) {
|
|
|
24
25
|
props.onChange?.(next);
|
|
25
26
|
},
|
|
26
27
|
});
|
|
28
|
+
const values = createControllable({
|
|
29
|
+
controlled: () => isControlled(props, "values"),
|
|
30
|
+
value: () => props.values ?? [],
|
|
31
|
+
defaultValue: () => props.defaultValues ?? [],
|
|
32
|
+
onChange: (next) => props.onValuesChange?.([...next]),
|
|
33
|
+
});
|
|
34
|
+
const multiple = () => props.multiple ?? false;
|
|
27
35
|
const collection = createMemo(() => select.collection({
|
|
28
36
|
items: [...props.options],
|
|
29
37
|
itemToValue: (option) => option.value,
|
|
@@ -33,12 +41,22 @@ export function Select(props) {
|
|
|
33
41
|
id,
|
|
34
42
|
ids: { root: props.id },
|
|
35
43
|
collection: collection(),
|
|
36
|
-
value:
|
|
44
|
+
value: multiple()
|
|
45
|
+
? [...values.value()]
|
|
46
|
+
: value.value() === undefined
|
|
47
|
+
? []
|
|
48
|
+
: [value.value()],
|
|
37
49
|
onValueChange: (details) => {
|
|
50
|
+
if (multiple()) {
|
|
51
|
+
values.set(orderedValues(props.options, details.value));
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
38
54
|
const next = details.value[0];
|
|
39
55
|
if (next !== undefined)
|
|
40
56
|
value.set(next);
|
|
41
57
|
},
|
|
58
|
+
multiple: multiple(),
|
|
59
|
+
closeOnSelect: !multiple(),
|
|
42
60
|
disabled: props.disabled,
|
|
43
61
|
invalid: invalid(),
|
|
44
62
|
name: props.name,
|
|
@@ -87,7 +105,8 @@ export function Select(props) {
|
|
|
87
105
|
<button {...triggerProps()} aria-labelledby={`${valueId} ${labelProps().id}`} aria-describedby={invalid() ? errorId : props.description ? descriptionId : undefined} class="xds-select__trigger">
|
|
88
106
|
|
|
89
107
|
<span {...api().getValueTextProps()} id={valueId} class="xds-select__value">
|
|
90
|
-
{api().valueAsString ||
|
|
108
|
+
{(multiple() ? selectedLabels(props.options, values.value()) : api().valueAsString) ||
|
|
109
|
+
props.placeholder}
|
|
91
110
|
</span>
|
|
92
111
|
<Icon name="chevrons-up-down" size="sm" class="text-xds-field-placeholder"/>
|
|
93
112
|
</button>
|
|
@@ -104,8 +123,10 @@ export function Select(props) {
|
|
|
104
123
|
</div>
|
|
105
124
|
|
|
106
125
|
<select {...api().getHiddenSelectProps()}>
|
|
107
|
-
|
|
108
|
-
|
|
126
|
+
<Show when={!multiple()}>
|
|
127
|
+
|
|
128
|
+
<option value=""/>
|
|
129
|
+
</Show>
|
|
109
130
|
<For each={props.options}>
|
|
110
131
|
{(option) => <option value={option.value}>{option.label}</option>}
|
|
111
132
|
</For>
|
|
@@ -123,9 +144,12 @@ export function Select(props) {
|
|
|
123
144
|
<For each={collection().items}>
|
|
124
145
|
{(option, index) => {
|
|
125
146
|
const ids = () => selectOptionIds(id, index());
|
|
126
|
-
|
|
147
|
+
const itemProps = createItemProps(() => api().getItemProps({ item: option }));
|
|
148
|
+
const textProps = createItemProps(() => api().getItemTextProps({ item: option }));
|
|
149
|
+
const selected = createMemo(() => api().getItemState({ item: option }).selected);
|
|
150
|
+
return (<div {...itemProps()} aria-labelledby={ids().label} aria-describedby={option.description ? ids().description : undefined} class="xds-select__item">
|
|
127
151
|
<span class="xds-select__item-words">
|
|
128
|
-
<span {...
|
|
152
|
+
<span {...textProps()} id={ids().label} class="xds-select__item-label">
|
|
129
153
|
{option.label}
|
|
130
154
|
</span>
|
|
131
155
|
<Show when={option.description}>
|
|
@@ -135,7 +159,7 @@ export function Select(props) {
|
|
|
135
159
|
</Show>
|
|
136
160
|
</span>
|
|
137
161
|
|
|
138
|
-
<Show when={
|
|
162
|
+
<Show when={selected()}>
|
|
139
163
|
<Icon name="check" size="sm"/>
|
|
140
164
|
</Show>
|
|
141
165
|
</div>);
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { type TableBaseProps, type TableSort } from "@xds/core";
|
|
2
|
+
import { type RootProps } from "./root.ts";
|
|
3
|
+
export type { SortDirection, TableColumn, TableRow, TableSort } from "@xds/core";
|
|
4
|
+
export type TableProps = TableBaseProps & RootProps & {
|
|
5
|
+
/**
|
|
6
|
+
* Called with the sort a press on a sortable column's header asks for. The app sorts the
|
|
7
|
+
* rows and gives the table the new `sort`.
|
|
8
|
+
*/
|
|
9
|
+
onSortChange?: (sort: TableSort) => void;
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* Rows of data under a row of column headers, to read and compare across. The header of a
|
|
13
|
+
* sortable column is a button that asks for the rows sorted by it, ascending first and then the
|
|
14
|
+
* other way, and the header they are sorted by says so with `aria-sort` and an arrow. The rows
|
|
15
|
+
* are shown in the order given. Where the columns do not fit, the table scrolls sideways.
|
|
16
|
+
*/
|
|
17
|
+
export declare function Table(props: TableProps): import("@solidjs/web").JSX.Element;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { classes, columnSort, nextSort, rootPart, sortIcon, TABLE_PARTS, } from "@xds/core";
|
|
2
|
+
import { For, Show } from "solid-js";
|
|
3
|
+
import { Icon } from "./Icon.jsx";
|
|
4
|
+
import { rootAttributes } from "./root.js";
|
|
5
|
+
const ROOT = rootPart("Table");
|
|
6
|
+
export function Table(props) {
|
|
7
|
+
const end = (align) => align === "end" && TABLE_PARTS.end;
|
|
8
|
+
return (<div {...rootAttributes(props)} class={classes(ROOT, props.class)} style={props.style}>
|
|
9
|
+
<table class={TABLE_PARTS.table} aria-label={props.label}>
|
|
10
|
+
<thead>
|
|
11
|
+
<tr class={TABLE_PARTS.row}>
|
|
12
|
+
<For each={props.columns}>
|
|
13
|
+
{(column) => {
|
|
14
|
+
const direction = () => columnSort(props.sort, column.key);
|
|
15
|
+
return (<th scope="col" aria-sort={direction()} class={classes(TABLE_PARTS.header, end(column.align))}>
|
|
16
|
+
<Show when={column.sortable} fallback={column.label}>
|
|
17
|
+
<button type="button" class={TABLE_PARTS.sort} onClick={() => props.onSortChange?.(nextSort(props.sort, column.key))}>
|
|
18
|
+
{column.label}
|
|
19
|
+
<Icon name={sortIcon(direction())} size="xs"/>
|
|
20
|
+
</button>
|
|
21
|
+
</Show>
|
|
22
|
+
</th>);
|
|
23
|
+
}}
|
|
24
|
+
</For>
|
|
25
|
+
</tr>
|
|
26
|
+
</thead>
|
|
27
|
+
<tbody>
|
|
28
|
+
<Show when={props.rows.length > 0 || props.empty === undefined} fallback={<tr class={TABLE_PARTS.row}>
|
|
29
|
+
<td class={TABLE_PARTS.empty} colspan={props.columns.length}>
|
|
30
|
+
{props.empty}
|
|
31
|
+
</td>
|
|
32
|
+
</tr>}>
|
|
33
|
+
<For each={props.rows}>
|
|
34
|
+
{(row) => (<tr class={TABLE_PARTS.row}>
|
|
35
|
+
<For each={props.columns}>
|
|
36
|
+
{(column, index) => (<td class={classes(TABLE_PARTS.cell, end(column.align))}>
|
|
37
|
+
{row.cells[index()]}
|
|
38
|
+
</td>)}
|
|
39
|
+
</For>
|
|
40
|
+
</tr>)}
|
|
41
|
+
</For>
|
|
42
|
+
</Show>
|
|
43
|
+
</tbody>
|
|
44
|
+
</table>
|
|
45
|
+
</div>);
|
|
46
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { type IsoTime, type TimePickerBaseProps } from "@xds/core";
|
|
2
|
+
import type { JSX } from "@solidjs/web";
|
|
3
|
+
import { type RootProps } from "./root.ts";
|
|
4
|
+
export type { IsoTime } from "@xds/core";
|
|
5
|
+
export type TimePickerProps = TimePickerBaseProps & RootProps & {
|
|
6
|
+
/** Called with the chosen time, as `HH:MM` on a 24-hour clock. */
|
|
7
|
+
onChange?: (value: IsoTime) => void;
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* A field for choosing a time of day. Closed, it looks like a Select with a clock: the chosen
|
|
11
|
+
* time on the locale's own clock ("9:30 AM", "09:30"). Pressed, it opens the times from `min` to
|
|
12
|
+
* `max`, `step` minutes apart, under itself, with the chosen one in view; choosing one calls
|
|
13
|
+
* `onChange` with it as `HH:MM` and closes the list.
|
|
14
|
+
*
|
|
15
|
+
* The field is a button that says it opens a list box, as a Select's does: the arrow keys move,
|
|
16
|
+
* typing the hour jumps to it, and Enter chooses. Without `value` it keeps its own choice, from
|
|
17
|
+
* `defaultValue`.
|
|
18
|
+
*/
|
|
19
|
+
export declare function TimePicker(props: TimePickerProps): JSX.Element;
|