@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,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/ListRow.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type ListRowBaseProps } from "@xds/core";
|
|
2
2
|
import { type Element } from "solid-js";
|
|
3
|
-
import type
|
|
3
|
+
import { type RootProps } from "./root.ts";
|
|
4
4
|
export type ListRowProps = ListRowBaseProps & RootProps & {
|
|
5
5
|
/** In front of the title: an avatar or an icon. */
|
|
6
6
|
leading?: Element;
|
package/dist/source/ListRow.jsx
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { classes, LIST_ROW_PARTS, listRowClass, listRowDescriptionClass, listRowTitleClass, rootPart, } from "@xds/core";
|
|
2
2
|
import { Show } from "solid-js";
|
|
3
3
|
import { Icon } from "./Icon.jsx";
|
|
4
|
+
import { rootAttributes } from "./root.js";
|
|
4
5
|
const ROOT = rootPart("ListRow");
|
|
5
6
|
export function ListRow(props) {
|
|
6
7
|
return <PlaceRow {...props} current="true"/>;
|
|
@@ -28,10 +29,10 @@ export function PlaceRow(props) {
|
|
|
28
29
|
<Icon name="chevron-right" size="sm" class={LIST_ROW_PARTS.chevron}/>
|
|
29
30
|
</Show>
|
|
30
31
|
</>);
|
|
31
|
-
return (<Show when={pressable()} fallback={<div aria-current={current()} class={row()} style={props.style}>
|
|
32
|
+
return (<Show when={pressable()} fallback={<div {...rootAttributes(props)} aria-current={current()} class={row()} style={props.style}>
|
|
32
33
|
{content()}
|
|
33
34
|
</div>}>
|
|
34
|
-
<button aria-current={current()} type="button" disabled={props.disabled} onClick={() => props.onPress?.()} class={row()} style={props.style}>
|
|
35
|
+
<button {...rootAttributes(props)} aria-current={current()} type="button" disabled={props.disabled} onClick={() => props.onPress?.()} class={row()} style={props.style}>
|
|
35
36
|
{content()}
|
|
36
37
|
</button>
|
|
37
38
|
</Show>);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type MediaCardBaseProps } from "@xds/core";
|
|
2
2
|
import { type Element } from "solid-js";
|
|
3
|
-
import type
|
|
3
|
+
import { type RootProps } from "./root.ts";
|
|
4
4
|
export type MediaCardProps = MediaCardBaseProps & RootProps & {
|
|
5
5
|
/** Before the text in the vertical layout, such as an Avatar. */
|
|
6
6
|
leading?: Element;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { classes, MEDIA_CARD_PARTS, mediaCardContentClass, mediaCardIds, mediaCardThumbnailClass, rootPart, } from "@xds/core";
|
|
2
2
|
import { createMemo, createUniqueId, For, Show } from "solid-js";
|
|
3
3
|
import { useDefaults } from "./Defaults.jsx";
|
|
4
|
+
import { rootAttributes } from "./root.js";
|
|
4
5
|
import { Thumbnail } from "./Thumbnail.jsx";
|
|
5
6
|
const ROOT = rootPart("MediaCard");
|
|
6
7
|
export function MediaCard(props) {
|
|
@@ -36,10 +37,10 @@ export function MediaCard(props) {
|
|
|
36
37
|
</Show>
|
|
37
38
|
</div>
|
|
38
39
|
</div>);
|
|
39
|
-
return (<Show when={pressable()} fallback={<div role="group" aria-labelledby={ids().names} class={classes(ROOT, MEDIA_CARD_PARTS.group, props.class)} style={props.style}>
|
|
40
|
+
return (<Show when={pressable()} fallback={<div {...rootAttributes(props)} role="group" aria-labelledby={ids().names} class={classes(ROOT, MEDIA_CARD_PARTS.group, props.class)} style={props.style}>
|
|
40
41
|
{content()}
|
|
41
42
|
</div>}>
|
|
42
|
-
<div class={classes(ROOT, MEDIA_CARD_PARTS.pressable, props.class)} style={props.style}>
|
|
43
|
+
<div {...rootAttributes(props)} class={classes(ROOT, MEDIA_CARD_PARTS.pressable, props.class)} style={props.style}>
|
|
43
44
|
<button type="button" onClick={() => props.onPress?.()} aria-labelledby={ids().names} class={MEDIA_CARD_PARTS.button}/>
|
|
44
45
|
{content()}
|
|
45
46
|
</div>
|
package/dist/source/Menu.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type MenuBaseProps } from "@xds/core";
|
|
2
2
|
import { type Element } from "solid-js";
|
|
3
|
-
import type
|
|
3
|
+
import { type RootProps } from "./root.ts";
|
|
4
4
|
export type { MenuItem } from "@xds/core";
|
|
5
5
|
export type MenuProps = MenuBaseProps & RootProps & {
|
|
6
6
|
/** The control that opens the menu: a Button or an IconButton. */
|
package/dist/source/Menu.jsx
CHANGED
|
@@ -7,11 +7,14 @@ import { Icon } from "./Icon.jsx";
|
|
|
7
7
|
import { modalPopover } from "./modal-popover.js";
|
|
8
8
|
import { Portal } from "./portal.jsx";
|
|
9
9
|
import { createPresence } from "./presence.js";
|
|
10
|
+
import { rootAttributes } from "./root.js";
|
|
11
|
+
import { createItemProps } from "./rows.js";
|
|
10
12
|
import { provideTrigger, TriggerContext } from "./trigger.js";
|
|
11
13
|
export function Menu(props) {
|
|
12
14
|
const id = createUniqueId();
|
|
13
15
|
const service = useMachine(menu.machine, () => ({
|
|
14
16
|
id,
|
|
17
|
+
ids: { content: props.id },
|
|
15
18
|
"aria-label": props.label,
|
|
16
19
|
positioning: {
|
|
17
20
|
placement: `bottom-${props.align ?? "start"}`,
|
|
@@ -60,7 +63,7 @@ export function Menu(props) {
|
|
|
60
63
|
let surface;
|
|
61
64
|
modalPopover(() => api().open, () => positioner);
|
|
62
65
|
const present = createPresence(() => api().open, () => [surface]);
|
|
63
|
-
const content = mergeProps(() => api().getContentProps(), {
|
|
66
|
+
const content = mergeProps(() => api().getContentProps(), rootAttributes(props), {
|
|
64
67
|
onKeyDown: (event) => keepListKeys(event, surface, ".xds-menu__item:not([data-disabled])", (value) => api().setHighlightedValue(value)),
|
|
65
68
|
get style() {
|
|
66
69
|
return props.style;
|
|
@@ -80,7 +83,11 @@ export function Menu(props) {
|
|
|
80
83
|
|
|
81
84
|
<div {...content} ref={(element) => (surface = element)} hidden={!present()} class={classes("xds-menu", props.class)}>
|
|
82
85
|
<For each={props.items}>
|
|
83
|
-
{(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)}>
|
|
84
91
|
<Show when={item.icon}>
|
|
85
92
|
{(name) => <Icon name={name()} size="sm" class="xds-menu__item-icon"/>}
|
|
86
93
|
</Show>
|
|
@@ -89,7 +96,8 @@ export function Menu(props) {
|
|
|
89
96
|
<Show when={item.selected}>
|
|
90
97
|
<Icon name="check" size="sm" label="Selected"/>
|
|
91
98
|
</Show>
|
|
92
|
-
</div>)
|
|
99
|
+
</div>);
|
|
100
|
+
}}
|
|
93
101
|
</For>
|
|
94
102
|
</div>
|
|
95
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
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type ProgressBarBaseProps } from "@xds/core";
|
|
2
|
-
import type
|
|
2
|
+
import { type RootProps } from "./root.ts";
|
|
3
3
|
export type ProgressBarProps = ProgressBarBaseProps & RootProps;
|
|
4
4
|
/**
|
|
5
5
|
* How far along something is, from 0 to 1. For work of unknown length use a Spinner.
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { classes, progressBarClass, progressBarFillClass, progressPercent, rootPart, } from "@xds/core";
|
|
2
|
+
import { rootAttributes } from "./root.js";
|
|
2
3
|
const ROOT = rootPart("ProgressBar");
|
|
3
4
|
export function ProgressBar(props) {
|
|
4
5
|
const percent = () => progressPercent(props.value);
|
|
5
|
-
return (<div role="progressbar" aria-label={props.label} aria-valuemin={0} aria-valuemax={100} aria-valuenow={percent()} class={classes(ROOT, progressBarClass, props.class)} style={props.style}>
|
|
6
|
+
return (<div {...rootAttributes(props)} role="progressbar" aria-label={props.label} aria-valuemin={0} aria-valuemax={100} aria-valuenow={percent()} class={classes(ROOT, progressBarClass, props.class)} style={props.style}>
|
|
6
7
|
<div class={progressBarFillClass} style={{ width: `${percent()}%` }}/>
|
|
7
8
|
</div>);
|
|
8
9
|
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { type RadioGroupBaseProps } from "@xds/core";
|
|
2
|
-
import type
|
|
2
|
+
import { type RootProps } from "./root.ts";
|
|
3
3
|
export type { RadioOption } from "@xds/core";
|
|
4
4
|
export type RadioGroupProps<Value extends string = string> = RadioGroupBaseProps<Value> & RootProps & {
|
|
5
|
-
onChange
|
|
5
|
+
onChange?: (value: Value) => void;
|
|
6
6
|
};
|
|
7
7
|
/**
|
|
8
8
|
* One choice among a few, applied later with the form it belongs to. For a choice that takes
|
|
@@ -11,5 +11,8 @@ export type RadioGroupProps<Value extends string = string> = RadioGroupBaseProps
|
|
|
11
11
|
* The chosen option has a dot and a thicker ring, so the choice does not depend on color. The
|
|
12
12
|
* options are native radio buttons, hidden and drawn beside, in a group named by the legend:
|
|
13
13
|
* the arrow keys move between them, and the error is tied to the group and announced.
|
|
14
|
+
*
|
|
15
|
+
* Without `value` it keeps its own choice, from `defaultValue`. Given `value`, even as
|
|
16
|
+
* `undefined`, it shows that.
|
|
14
17
|
*/
|
|
15
18
|
export declare function RadioGroup<Value extends string = string>(props: RadioGroupProps<Value>): import("@solidjs/web").JSX.Element;
|
|
@@ -1,28 +1,41 @@
|
|
|
1
|
-
import { classes } from "@xds/core";
|
|
1
|
+
import { classes, isControlled } from "@xds/core";
|
|
2
2
|
import { createUniqueId, For, Show } from "solid-js";
|
|
3
|
+
import { createControllable, resetWithForm } from "./controllable.js";
|
|
3
4
|
import { keepChecked } from "./controlled.js";
|
|
5
|
+
import { rootAttributes } from "./root.js";
|
|
4
6
|
export function RadioGroup(props) {
|
|
5
7
|
const id = createUniqueId();
|
|
6
8
|
const labelId = `${id}-label`;
|
|
7
9
|
const errorId = `${id}-error`;
|
|
8
10
|
const invalid = () => props.error !== undefined;
|
|
9
11
|
let group;
|
|
10
|
-
|
|
12
|
+
const controlled = () => isControlled(props, "value");
|
|
13
|
+
const value = createControllable({
|
|
14
|
+
controlled,
|
|
15
|
+
value: () => props.value,
|
|
16
|
+
defaultValue: () => props.defaultValue,
|
|
17
|
+
onChange: (next) => {
|
|
18
|
+
if (next !== undefined)
|
|
19
|
+
props.onChange?.(next);
|
|
20
|
+
},
|
|
21
|
+
});
|
|
22
|
+
resetWithForm(() => group, controlled, value.reset);
|
|
23
|
+
return (<div {...rootAttributes(props)} ref={(element) => (group = element)} role="radiogroup" aria-labelledby={labelId} aria-describedby={invalid() ? errorId : undefined} aria-invalid={invalid() ? "true" : undefined} aria-disabled={props.disabled ? "true" : undefined} aria-orientation="vertical" class={classes("xds-radio-group", props.class)} style={props.style}>
|
|
11
24
|
<span id={labelId} class="xds-radio-group__label">
|
|
12
25
|
{props.label}
|
|
13
26
|
</span>
|
|
14
27
|
<div class="xds-radio-group__options">
|
|
15
28
|
<For each={props.options}>
|
|
16
29
|
{(option, index) => (<label class="xds-radio-group__option">
|
|
17
|
-
<input type="radio" class="xds-radio-group__input sr-only" name={props.name ?? id} value={option.value} checked={option.value ===
|
|
30
|
+
<input type="radio" class="xds-radio-group__input sr-only" name={props.name ?? id} value={option.value} checked={option.value === value.value()} defaultChecked={option.value === (controlled() ? value.value() : props.defaultValue)} disabled={props.disabled} aria-labelledby={`${id}-${index()}`} aria-describedby={[
|
|
18
31
|
option.description ? `${id}-${index()}-description` : undefined,
|
|
19
32
|
invalid() ? errorId : undefined,
|
|
20
33
|
]
|
|
21
34
|
.filter(Boolean)
|
|
22
35
|
.join(" ") || undefined} aria-invalid={invalid() ? "true" : undefined} onChange={() => {
|
|
23
|
-
|
|
36
|
+
value.set(option.value);
|
|
24
37
|
for (const input of group.querySelectorAll("input")) {
|
|
25
|
-
keepChecked(input, () => input.value ===
|
|
38
|
+
keepChecked(input, () => input.value === value.value());
|
|
26
39
|
}
|
|
27
40
|
}}/>
|
|
28
41
|
<span class="xds-radio-group__row">
|
|
@@ -1,7 +1,12 @@
|
|
|
1
1
|
import { type SearchFieldBaseProps } from "@xds/core";
|
|
2
|
-
import type {
|
|
2
|
+
import type { JSX } from "@solidjs/web";
|
|
3
|
+
import { type RootProps } from "./root.ts";
|
|
3
4
|
export type SearchFieldProps = SearchFieldBaseProps & RootProps & {
|
|
4
|
-
onChange
|
|
5
|
+
onChange?: (value: string) => void;
|
|
6
|
+
onFocus?: JSX.FocusEventHandler<HTMLInputElement, FocusEvent>;
|
|
7
|
+
onBlur?: JSX.FocusEventHandler<HTMLInputElement, FocusEvent>;
|
|
8
|
+
/** The native input. */
|
|
9
|
+
ref?: JSX.Ref<HTMLInputElement>;
|
|
5
10
|
/** Called with the query on Enter, or on the search key of a software keyboard. */
|
|
6
11
|
onSubmit?: (value: string) => void;
|
|
7
12
|
};
|
|
@@ -11,5 +16,8 @@ export type SearchFieldProps = SearchFieldBaseProps & RootProps & {
|
|
|
11
16
|
*
|
|
12
17
|
* Use it to filter or search what is on the screen. For a value that is saved with a form,
|
|
13
18
|
* use a TextField, which has a visible label.
|
|
19
|
+
*
|
|
20
|
+
* Without `value` it keeps its own query, from `defaultValue`. A read-only one has no control
|
|
21
|
+
* that clears it, and Escape leaves it as it is.
|
|
14
22
|
*/
|
|
15
|
-
export declare function SearchField(props: SearchFieldProps):
|
|
23
|
+
export declare function SearchField(props: SearchFieldProps): JSX.Element;
|
|
@@ -1,35 +1,49 @@
|
|
|
1
|
-
import { classes, rootPart } from "@xds/core";
|
|
1
|
+
import { classes, isControlled, rootPart } from "@xds/core";
|
|
2
2
|
import { Show } from "solid-js";
|
|
3
|
+
import { composeRefs, createControllable, resetWithForm } from "./controllable.js";
|
|
3
4
|
import { keepValue } from "./controlled.js";
|
|
4
5
|
import { Icon } from "./Icon.jsx";
|
|
6
|
+
import { useLabels } from "./Labels.jsx";
|
|
7
|
+
import { rootAttributes } from "./root.js";
|
|
5
8
|
const ROOT = rootPart("SearchField");
|
|
6
9
|
export function SearchField(props) {
|
|
10
|
+
const labels = useLabels();
|
|
7
11
|
let input;
|
|
8
|
-
|
|
12
|
+
const controlled = () => isControlled(props, "value");
|
|
13
|
+
const defaultValue = () => props.defaultValue ?? "";
|
|
14
|
+
const value = createControllable({
|
|
15
|
+
controlled,
|
|
16
|
+
value: () => props.value ?? "",
|
|
17
|
+
defaultValue,
|
|
18
|
+
onChange: (next) => props.onChange?.(next),
|
|
19
|
+
});
|
|
20
|
+
resetWithForm(() => input, controlled, value.reset);
|
|
21
|
+
const clearable = () => value.value() !== "" && !props.disabled && !props.readOnly;
|
|
22
|
+
return (<div {...rootAttributes(props)} class={classes("xds-text-field", ROOT, props.class)} style={props.style}>
|
|
9
23
|
<div class="xds-text-field__control xds-text-field__control--pill xds-text-field__group">
|
|
10
24
|
<span class="xds-text-field__slot xds-text-field__slot--leading">
|
|
11
25
|
<Icon name="search" size="sm"/>
|
|
12
26
|
</span>
|
|
13
|
-
<input ref={(element) => (input = element)} type="text" role="searchbox" class="xds-text-field__input" aria-label={props.label} enterkeyhint="search" placeholder={props.placeholder} value={
|
|
14
|
-
|
|
27
|
+
<input ref={composeRefs((element) => (input = element), () => props.ref)} type="text" role="searchbox" class="xds-text-field__input" aria-label={props.label} enterkeyhint="search" placeholder={props.placeholder} value={value.value()} defaultValue={controlled() ? value.value() : defaultValue()} disabled={props.disabled} readonly={props.readOnly} data-uses-escape={clearable() ? "" : undefined} onInput={(event) => {
|
|
28
|
+
value.set(event.currentTarget.value);
|
|
15
29
|
if (!event.isComposing)
|
|
16
|
-
keepValue(event.currentTarget,
|
|
17
|
-
}} onCompositionEnd={(event) => keepValue(event.currentTarget, () => props.
|
|
30
|
+
keepValue(event.currentTarget, value.value);
|
|
31
|
+
}} onCompositionEnd={(event) => keepValue(event.currentTarget, value.value)} onFocus={(event) => props.onFocus?.(event)} onBlur={(event) => props.onBlur?.(event)} onKeyDown={(event) => {
|
|
18
32
|
if (event.isComposing)
|
|
19
33
|
return;
|
|
20
34
|
if (event.key === "Enter" && props.onSubmit) {
|
|
21
35
|
event.preventDefault();
|
|
22
|
-
props.onSubmit(
|
|
36
|
+
props.onSubmit(value.value());
|
|
23
37
|
}
|
|
24
|
-
if (event.key === "Escape" &&
|
|
38
|
+
if (event.key === "Escape" && clearable()) {
|
|
25
39
|
event.stopPropagation();
|
|
26
|
-
|
|
40
|
+
value.set("");
|
|
27
41
|
}
|
|
28
42
|
}}/>
|
|
29
|
-
<Show when={
|
|
43
|
+
<Show when={clearable()}>
|
|
30
44
|
<span class="xds-text-field__slot xds-text-field__slot--trailing">
|
|
31
|
-
<button type="button" aria-label={props.clearLabel ??
|
|
32
|
-
|
|
45
|
+
<button type="button" aria-label={props.clearLabel ?? labels().clear} onClick={() => {
|
|
46
|
+
value.set("");
|
|
33
47
|
input.focus();
|
|
34
48
|
}} class="-me-1 flex size-xds-target-min cursor-pointer items-center justify-center rounded-xds-full hover:text-xds-field-text focus-visible:outline-(length:--xds-focus-width) focus-visible:outline-xds-border-focus focus-visible:outline-solid">
|
|
35
49
|
<Icon name="circle-x" size="sm"/>
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type SectionHeaderBaseProps } from "@xds/core";
|
|
2
|
-
import type
|
|
2
|
+
import { type RootProps } from "./root.ts";
|
|
3
3
|
export type SectionHeaderProps = SectionHeaderBaseProps & RootProps & {
|
|
4
4
|
/** A link-like action at the end, such as "See all". */
|
|
5
5
|
action?: {
|
|
@@ -3,10 +3,11 @@ import { dynamic } from "@solidjs/web";
|
|
|
3
3
|
import { Show } from "solid-js";
|
|
4
4
|
import { Button } from "./Button.jsx";
|
|
5
5
|
import { Icon } from "./Icon.jsx";
|
|
6
|
+
import { rootAttributes } from "./root.js";
|
|
6
7
|
const ROOT = rootPart("SectionHeader");
|
|
7
8
|
export function SectionHeader(props) {
|
|
8
9
|
const Heading = dynamic(() => `h${props.level ?? 2}`);
|
|
9
|
-
return (<div class={classes(ROOT, SECTION_HEADER_PARTS.root, props.class)} style={props.style}>
|
|
10
|
+
return (<div {...rootAttributes(props)} class={classes(ROOT, SECTION_HEADER_PARTS.root, props.class)} style={props.style}>
|
|
10
11
|
<div class={SECTION_HEADER_PARTS.lead}>
|
|
11
12
|
<Show when={props.icon}>
|
|
12
13
|
{(icon) => (<span class={SECTION_HEADER_PARTS.icon}>
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { type SegmentedControlBaseProps } from "@xds/core";
|
|
2
|
-
import type
|
|
2
|
+
import { type RootProps } from "./root.ts";
|
|
3
3
|
export type SegmentedControlProps<Value extends string> = SegmentedControlBaseProps<Value> & RootProps & {
|
|
4
|
-
onChange
|
|
4
|
+
onChange?: (value: Value) => void;
|
|
5
5
|
};
|
|
6
6
|
/**
|
|
7
7
|
* A choice between a few views or modes, all visible at once. The selected segment is outlined
|
|
8
8
|
* as well as filled, so the choice does not depend on telling two greys apart.
|
|
9
9
|
*
|
|
10
|
-
* It is a group of native radio buttons, so the arrow keys move between segments.
|
|
10
|
+
* It is a group of native radio buttons, so the arrow keys move between segments. Without
|
|
11
|
+
* `value` it keeps its own choice, from `defaultValue`, or the first segment.
|
|
11
12
|
*/
|
|
12
13
|
export declare function SegmentedControl<Value extends string>(props: SegmentedControlProps<Value>): import("@solidjs/web").JSX.Element;
|
|
@@ -1,17 +1,28 @@
|
|
|
1
|
-
import { classes, rootPart, segmentedControlClass, segmentedControlOptionClass, segmentedControlSegmentClass, } from "@xds/core";
|
|
1
|
+
import { classes, isControlled, rootPart, segmentedControlClass, segmentedControlOptionClass, segmentedControlSegmentClass, } from "@xds/core";
|
|
2
2
|
import { createUniqueId, For } from "solid-js";
|
|
3
|
+
import { createControllable } from "./controllable.js";
|
|
3
4
|
import { keepChecked } from "./controlled.js";
|
|
5
|
+
import { rootAttributes } from "./root.js";
|
|
4
6
|
const ROOT = rootPart("SegmentedControl");
|
|
5
7
|
export function SegmentedControl(props) {
|
|
6
8
|
const name = createUniqueId();
|
|
7
9
|
let group;
|
|
8
|
-
|
|
10
|
+
const value = createControllable({
|
|
11
|
+
controlled: () => isControlled(props, "value"),
|
|
12
|
+
value: () => props.value,
|
|
13
|
+
defaultValue: () => props.defaultValue ?? props.options[0]?.value,
|
|
14
|
+
onChange: (next) => {
|
|
15
|
+
if (next !== undefined)
|
|
16
|
+
props.onChange?.(next);
|
|
17
|
+
},
|
|
18
|
+
});
|
|
19
|
+
return (<div {...rootAttributes(props)} ref={(element) => (group = element)} aria-label={props["aria-label"]} role="radiogroup" class={classes(ROOT, segmentedControlClass(props.fullWidth), props.class)} style={props.style}>
|
|
9
20
|
<For each={props.options}>
|
|
10
21
|
{(option) => (<label class={segmentedControlOptionClass(props.fullWidth)}>
|
|
11
|
-
<input type="radio" name={name} value={option.value} class="peer sr-only" checked={option.value ===
|
|
12
|
-
|
|
22
|
+
<input type="radio" name={name} value={option.value} class="peer sr-only" checked={option.value === value.value()} defaultChecked={option.value === value.value()} onChange={() => {
|
|
23
|
+
value.set(option.value);
|
|
13
24
|
for (const input of group.querySelectorAll("input")) {
|
|
14
|
-
keepChecked(input, () => input.value ===
|
|
25
|
+
keepChecked(input, () => input.value === value.value());
|
|
15
26
|
}
|
|
16
27
|
}}/>
|
|
17
28
|
<span class={segmentedControlSegmentClass}>{option.label}</span>
|
package/dist/source/Select.d.ts
CHANGED
|
@@ -3,7 +3,9 @@ import type { JSX } from "@solidjs/web";
|
|
|
3
3
|
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
|
-
onChange
|
|
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
|
|
@@ -14,5 +16,12 @@ export type SelectProps<Value extends string = string> = SelectBaseProps<Value>
|
|
|
14
16
|
* The field is a button that says it opens a list box and whether the list is open. In the list
|
|
15
17
|
* the arrow keys move, typing jumps to an option, and Enter chooses. The chosen option is
|
|
16
18
|
* selected for assistive technology and marked with a check.
|
|
19
|
+
*
|
|
20
|
+
* Without `value` it keeps its own choice, from `defaultValue`. Given `value`, even as
|
|
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.
|
|
17
26
|
*/
|
|
18
27
|
export declare function Select<Value extends string = string>(props: SelectProps<Value>): JSX.Element;
|