@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,94 @@
|
|
|
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 { type Element, Show } from "solid-js";
|
|
6
|
+
import { Icon } from "./Icon.tsx";
|
|
7
|
+
import {
|
|
8
|
+
LIST_ROW_PARTS,
|
|
9
|
+
type ListRowBaseProps,
|
|
10
|
+
listRowClass,
|
|
11
|
+
listRowDescriptionClass,
|
|
12
|
+
listRowTitleClass,
|
|
13
|
+
} from "./list-row.ts";
|
|
14
|
+
import { classes, rootPart } from "./parts.ts";
|
|
15
|
+
|
|
16
|
+
export type ListRowProps = ListRowBaseProps &
|
|
17
|
+
RootProps & {
|
|
18
|
+
/** In front of the title: an avatar or an icon. */
|
|
19
|
+
leading?: Element;
|
|
20
|
+
/** At the far end: a value, a badge or a switch. */
|
|
21
|
+
trailing?: Element;
|
|
22
|
+
/** Makes the whole row a button. Do not put another control in `trailing` then. */
|
|
23
|
+
onPress?: () => void;
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
const ROOT = rootPart("ListRow");
|
|
27
|
+
|
|
28
|
+
/** One line of a list or a settings screen. Separate rows with a Divider. */
|
|
29
|
+
export function ListRow(props: ListRowProps) {
|
|
30
|
+
return <PlaceRow {...props} current="true" />;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* A ListRow that says what kind of current item its selected state is. A Sidebar's rows are the
|
|
35
|
+
* places of an app, so its selected row is the current page. Only for this package's own
|
|
36
|
+
* components: the index does not export it.
|
|
37
|
+
*/
|
|
38
|
+
export function PlaceRow(props: ListRowProps & { current: "true" | "page" }) {
|
|
39
|
+
const pressable = () => props.onPress !== undefined;
|
|
40
|
+
const current = () => (props.selected ? props.current : undefined);
|
|
41
|
+
const row = () =>
|
|
42
|
+
classes(
|
|
43
|
+
ROOT,
|
|
44
|
+
listRowClass({ compact: props.compact, selected: props.selected, pressable: pressable() }),
|
|
45
|
+
props.class,
|
|
46
|
+
);
|
|
47
|
+
const content = () => (
|
|
48
|
+
<>
|
|
49
|
+
{props.leading}
|
|
50
|
+
<span class={LIST_ROW_PARTS.text}>
|
|
51
|
+
<span
|
|
52
|
+
class={listRowTitleClass({
|
|
53
|
+
compact: props.compact,
|
|
54
|
+
selected: props.selected,
|
|
55
|
+
disabled: props.disabled,
|
|
56
|
+
})}
|
|
57
|
+
>
|
|
58
|
+
{props.title}
|
|
59
|
+
</span>
|
|
60
|
+
<Show when={props.description}>
|
|
61
|
+
{(description) => (
|
|
62
|
+
<span class={listRowDescriptionClass(props.compact)}>{description()}</span>
|
|
63
|
+
)}
|
|
64
|
+
</Show>
|
|
65
|
+
</span>
|
|
66
|
+
{props.trailing}
|
|
67
|
+
<Show when={props.chevron}>
|
|
68
|
+
<Icon name="chevron-right" size="sm" class={LIST_ROW_PARTS.chevron} />
|
|
69
|
+
</Show>
|
|
70
|
+
</>
|
|
71
|
+
);
|
|
72
|
+
return (
|
|
73
|
+
<Show
|
|
74
|
+
when={pressable()}
|
|
75
|
+
fallback={
|
|
76
|
+
<div {...rootAttributes(props)} aria-current={current()} class={row()} style={props.style}>
|
|
77
|
+
{content()}
|
|
78
|
+
</div>
|
|
79
|
+
}
|
|
80
|
+
>
|
|
81
|
+
<button
|
|
82
|
+
{...rootAttributes(props)}
|
|
83
|
+
aria-current={current()}
|
|
84
|
+
type="button"
|
|
85
|
+
disabled={props.disabled}
|
|
86
|
+
onClick={() => props.onPress?.()}
|
|
87
|
+
class={row()}
|
|
88
|
+
style={props.style}
|
|
89
|
+
>
|
|
90
|
+
{content()}
|
|
91
|
+
</button>
|
|
92
|
+
</Show>
|
|
93
|
+
);
|
|
94
|
+
}
|
|
@@ -0,0 +1,116 @@
|
|
|
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 { createMemo, createUniqueId, type Element, For, Show } from "solid-js";
|
|
6
|
+
import {
|
|
7
|
+
MEDIA_CARD_PARTS,
|
|
8
|
+
type MediaCardBaseProps,
|
|
9
|
+
mediaCardContentClass,
|
|
10
|
+
mediaCardIds,
|
|
11
|
+
mediaCardThumbnailClass,
|
|
12
|
+
} from "./media-card.ts";
|
|
13
|
+
import { classes, rootPart } from "./parts.ts";
|
|
14
|
+
import { Thumbnail } from "./Thumbnail.tsx";
|
|
15
|
+
|
|
16
|
+
export type MediaCardProps = MediaCardBaseProps &
|
|
17
|
+
RootProps & {
|
|
18
|
+
/** Before the text in the vertical layout, such as an Avatar. */
|
|
19
|
+
leading?: Element;
|
|
20
|
+
/** At the end of the text: an IconButton or a Menu. It stays a control of its own. */
|
|
21
|
+
action?: Element;
|
|
22
|
+
/** Makes the whole card one button. */
|
|
23
|
+
onPress?: () => void;
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
const ROOT = rootPart("MediaCard");
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* A thumbnail with its title and details: a video in a feed, an article in a list.
|
|
30
|
+
*
|
|
31
|
+
* With `onPress` the whole card is one button with no surface at rest: under a pointer and
|
|
32
|
+
* while pressed it takes the card's fills, and it has a focus ring. The button is named by the
|
|
33
|
+
* title followed by the details. `action` is a separate control beside it, so pressing it does
|
|
34
|
+
* not press the card.
|
|
35
|
+
*/
|
|
36
|
+
export function MediaCard(props: MediaCardProps) {
|
|
37
|
+
const id = createUniqueId();
|
|
38
|
+
const ids = createMemo(() => mediaCardIds(id, props.meta));
|
|
39
|
+
const defaults = useDefaults("MediaCard");
|
|
40
|
+
const horizontal = () => (props.layout ?? defaults().layout) === "horizontal";
|
|
41
|
+
const pressable = () => props.onPress !== undefined;
|
|
42
|
+
// On a pressable card the button says all of this, so the parts are hidden from assistive
|
|
43
|
+
// technology and only the action is left beside it.
|
|
44
|
+
const hidden = () => (pressable() ? "true" : undefined);
|
|
45
|
+
const content = () => (
|
|
46
|
+
<div class={mediaCardContentClass({ horizontal: horizontal(), pressable: pressable() })}>
|
|
47
|
+
<span aria-hidden={hidden()} class={mediaCardThumbnailClass(horizontal())}>
|
|
48
|
+
<Thumbnail
|
|
49
|
+
src={props.src}
|
|
50
|
+
alt={props.alt ?? ""}
|
|
51
|
+
// The card's own ratio, not one the app gives its other thumbnails.
|
|
52
|
+
ratio={props.ratio ?? "16:9"}
|
|
53
|
+
badge={props.badge}
|
|
54
|
+
progress={props.progress}
|
|
55
|
+
/>
|
|
56
|
+
</span>
|
|
57
|
+
<div class={MEDIA_CARD_PARTS.body}>
|
|
58
|
+
<Show when={!horizontal() && props.leading}>
|
|
59
|
+
{(leading) => (
|
|
60
|
+
<span aria-hidden={hidden()} class={MEDIA_CARD_PARTS.leading}>
|
|
61
|
+
{leading()}
|
|
62
|
+
</span>
|
|
63
|
+
)}
|
|
64
|
+
</Show>
|
|
65
|
+
<span aria-hidden={hidden()} class={MEDIA_CARD_PARTS.text}>
|
|
66
|
+
<span id={ids().title} class={MEDIA_CARD_PARTS.title}>
|
|
67
|
+
{props.title}
|
|
68
|
+
</span>
|
|
69
|
+
{/* Two details may read the same, so they are told apart by their position. */}
|
|
70
|
+
<For each={props.meta ?? []} keyed={false}>
|
|
71
|
+
{(line, index) => (
|
|
72
|
+
<span id={ids().details[index]} class={MEDIA_CARD_PARTS.meta}>
|
|
73
|
+
{line()}
|
|
74
|
+
</span>
|
|
75
|
+
)}
|
|
76
|
+
</For>
|
|
77
|
+
</span>
|
|
78
|
+
<Show when={props.action}>
|
|
79
|
+
{(action) => <div class={MEDIA_CARD_PARTS.action}>{action()}</div>}
|
|
80
|
+
</Show>
|
|
81
|
+
</div>
|
|
82
|
+
</div>
|
|
83
|
+
);
|
|
84
|
+
return (
|
|
85
|
+
<Show
|
|
86
|
+
when={pressable()}
|
|
87
|
+
fallback={
|
|
88
|
+
// A group, not a fieldset: a fieldset groups form controls, and sizes itself to its
|
|
89
|
+
// content, which would undo the ellipses.
|
|
90
|
+
<div
|
|
91
|
+
{...rootAttributes(props)}
|
|
92
|
+
role="group"
|
|
93
|
+
aria-labelledby={ids().names}
|
|
94
|
+
class={classes(ROOT, MEDIA_CARD_PARTS.group, props.class)}
|
|
95
|
+
style={props.style}
|
|
96
|
+
>
|
|
97
|
+
{content()}
|
|
98
|
+
</div>
|
|
99
|
+
}
|
|
100
|
+
>
|
|
101
|
+
<div
|
|
102
|
+
{...rootAttributes(props)}
|
|
103
|
+
class={classes(ROOT, MEDIA_CARD_PARTS.pressable, props.class)}
|
|
104
|
+
style={props.style}
|
|
105
|
+
>
|
|
106
|
+
<button
|
|
107
|
+
type="button"
|
|
108
|
+
onClick={() => props.onPress?.()}
|
|
109
|
+
aria-labelledby={ids().names}
|
|
110
|
+
class={MEDIA_CARD_PARTS.button}
|
|
111
|
+
/>
|
|
112
|
+
{content()}
|
|
113
|
+
</div>
|
|
114
|
+
</Show>
|
|
115
|
+
);
|
|
116
|
+
}
|
|
@@ -0,0 +1,190 @@
|
|
|
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
|
+
createItemProps,
|
|
6
|
+
createPresence,
|
|
7
|
+
keepListKeys,
|
|
8
|
+
leaveEscapeToFields,
|
|
9
|
+
modalPopover,
|
|
10
|
+
Portal,
|
|
11
|
+
provideTrigger,
|
|
12
|
+
type RootProps,
|
|
13
|
+
readCssPx,
|
|
14
|
+
rootAttributes,
|
|
15
|
+
space,
|
|
16
|
+
TriggerContext,
|
|
17
|
+
type TriggerProps,
|
|
18
|
+
underlayLayerStyle,
|
|
19
|
+
} from "@xds/solid/base";
|
|
20
|
+
import * as menu from "@zag-js/menu";
|
|
21
|
+
import { mergeProps, normalizeProps, useMachine } from "@zag-js/solid";
|
|
22
|
+
import { createMemo, createUniqueId, type Element, For, Show } from "solid-js";
|
|
23
|
+
import { Icon } from "./Icon.tsx";
|
|
24
|
+
import {
|
|
25
|
+
firstMenuValue,
|
|
26
|
+
layoutRect,
|
|
27
|
+
type MenuBaseProps,
|
|
28
|
+
menuItemClass,
|
|
29
|
+
opensOnPress,
|
|
30
|
+
} from "./menu.ts";
|
|
31
|
+
import { classes } from "./parts.ts";
|
|
32
|
+
|
|
33
|
+
export type { MenuItem } from "./menu.ts";
|
|
34
|
+
|
|
35
|
+
export type MenuProps = MenuBaseProps &
|
|
36
|
+
RootProps & {
|
|
37
|
+
/** The control that opens the menu: a Button or an IconButton. */
|
|
38
|
+
trigger: Element;
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* A list of actions that opens from a control. Choosing an item calls its `onSelect` and
|
|
43
|
+
* closes the menu; a press outside or Escape closes it too, and focus goes back to the
|
|
44
|
+
* trigger.
|
|
45
|
+
*
|
|
46
|
+
* The trigger reports that it opens a menu and whether the menu is open. The arrow keys move
|
|
47
|
+
* the highlight and Enter chooses.
|
|
48
|
+
*
|
|
49
|
+
* Its `class` and `style` are the menu's surface's, which is in the page only while it is open.
|
|
50
|
+
*/
|
|
51
|
+
export function Menu(props: MenuProps) {
|
|
52
|
+
const id = createUniqueId();
|
|
53
|
+
const service = useMachine(menu.machine, () => ({
|
|
54
|
+
id,
|
|
55
|
+
// The app's id goes on the surface, where Zag looks for it by this one.
|
|
56
|
+
ids: { content: props.id },
|
|
57
|
+
"aria-label": props.label,
|
|
58
|
+
positioning: {
|
|
59
|
+
placement: `bottom-${props.align ?? "start"}` as const,
|
|
60
|
+
gutter: readCssPx(null, "--xds-space-1", space[1]),
|
|
61
|
+
getAnchorRect: (anchor) => (anchor instanceof HTMLElement ? layoutRect(anchor) : null),
|
|
62
|
+
},
|
|
63
|
+
onSelect: (details: menu.SelectionDetails) => {
|
|
64
|
+
// The values are positions, because two items may have the same label.
|
|
65
|
+
const item = props.items[Number(details.value)];
|
|
66
|
+
if (item && item !== "separator") item.onSelect();
|
|
67
|
+
},
|
|
68
|
+
onEscapeKeyDown: leaveEscapeToFields,
|
|
69
|
+
// The arrow keys go round from the last item to the first, as in a native menu.
|
|
70
|
+
loopFocus: true,
|
|
71
|
+
}));
|
|
72
|
+
const api = createMemo(() => menu.connect(service, normalizeProps));
|
|
73
|
+
// Whether the last press on the trigger opened the menu, which its click must then not do.
|
|
74
|
+
let pressOpened = false;
|
|
75
|
+
const trigger = provideTrigger(() => {
|
|
76
|
+
// Zag's handler for a press is left out: it keeps the press from focusing the trigger, so
|
|
77
|
+
// the focus would reach the menu, and come back to the trigger as the menu closes, only
|
|
78
|
+
// from a script, which the browser marks with the keyboard ring.
|
|
79
|
+
const { onPointerDown: _onPointerDown, ...rest } = api().getTriggerProps() as TriggerProps;
|
|
80
|
+
return mergeProps(rest, {
|
|
81
|
+
// Added to the control's own class; the trigger looks pressed while its menu is open.
|
|
82
|
+
class: "{{prefix}}-menu__trigger",
|
|
83
|
+
// A mouse opens the menu as its button goes down; touch and pen open it on the click,
|
|
84
|
+
// as Zag does.
|
|
85
|
+
onPointerDown: (event: PointerEvent & { currentTarget: HTMLElement }) => {
|
|
86
|
+
pressOpened = opensOnPress(event) && !api().open;
|
|
87
|
+
if (pressOpened) api().setOpen(true);
|
|
88
|
+
},
|
|
89
|
+
onClick: (event: MouseEvent) => {
|
|
90
|
+
// A click with no pointer behind it comes from a screen reader or a script.
|
|
91
|
+
const pointer = event.detail !== 0;
|
|
92
|
+
// The press opened the menu already. This handler runs before Zag's, which skips a
|
|
93
|
+
// handled click. Not told by the click's pointer type: a browser may send the click
|
|
94
|
+
// as a plain mouse event.
|
|
95
|
+
if (pressOpened && pointer) {
|
|
96
|
+
pressOpened = false;
|
|
97
|
+
event.preventDefault();
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
if (pointer) return;
|
|
101
|
+
// After the machine has opened the menu.
|
|
102
|
+
requestAnimationFrame(() => {
|
|
103
|
+
if (!api().open) return;
|
|
104
|
+
const first = firstMenuValue(props.items);
|
|
105
|
+
if (first !== undefined) api().setHighlightedValue(first);
|
|
106
|
+
});
|
|
107
|
+
},
|
|
108
|
+
});
|
|
109
|
+
});
|
|
110
|
+
let positioner: HTMLDivElement | undefined;
|
|
111
|
+
let surface: HTMLDivElement | undefined;
|
|
112
|
+
modalPopover(
|
|
113
|
+
() => api().open,
|
|
114
|
+
() => positioner,
|
|
115
|
+
);
|
|
116
|
+
const present = createPresence(
|
|
117
|
+
() => api().open,
|
|
118
|
+
() => [surface],
|
|
119
|
+
);
|
|
120
|
+
const content = mergeProps(() => api().getContentProps(), rootAttributes(props), {
|
|
121
|
+
// This handler runs before Zag's.
|
|
122
|
+
onKeyDown: (event: KeyboardEvent) =>
|
|
123
|
+
keepListKeys(event, surface, ".{{prefix}}-menu__item:not([data-disabled])", (value) =>
|
|
124
|
+
api().setHighlightedValue(value),
|
|
125
|
+
),
|
|
126
|
+
// The app's, laid over Zag's.
|
|
127
|
+
get style() {
|
|
128
|
+
return props.style;
|
|
129
|
+
},
|
|
130
|
+
});
|
|
131
|
+
return (
|
|
132
|
+
<>
|
|
133
|
+
<TriggerContext value={trigger}>{props.trigger}</TriggerContext>
|
|
134
|
+
<Portal>
|
|
135
|
+
{/* Nothing inside opens an overlay from a control outside it. */}
|
|
136
|
+
<TriggerContext value={null}>
|
|
137
|
+
<Show when={api().open}>
|
|
138
|
+
{/* Takes a press outside, which then only closes the menu. The focus stays in the
|
|
139
|
+
menu until the menu hands it back to the trigger. */}
|
|
140
|
+
{/* oxlint-disable-next-line jsx-a11y/no-static-element-interactions -- not a control: the handler only keeps the focus where it is */}
|
|
141
|
+
<div
|
|
142
|
+
class="{{prefix}}-menu__underlay"
|
|
143
|
+
style={underlayLayerStyle(api().getPositionerProps().style)}
|
|
144
|
+
onMouseDown={(event) => event.preventDefault()}
|
|
145
|
+
/>
|
|
146
|
+
</Show>
|
|
147
|
+
<div
|
|
148
|
+
ref={(element) => (positioner = element)}
|
|
149
|
+
{...api().getPositionerProps()}
|
|
150
|
+
class="{{prefix}}-menu__positioner"
|
|
151
|
+
>
|
|
152
|
+
{/* Shown until its exit animation ends; Zag would hide it as it closes. */}
|
|
153
|
+
<div
|
|
154
|
+
{...content}
|
|
155
|
+
ref={(element) => (surface = element)}
|
|
156
|
+
hidden={!present()}
|
|
157
|
+
class={classes("{{prefix}}-menu", props.class)}
|
|
158
|
+
>
|
|
159
|
+
<For each={props.items}>
|
|
160
|
+
{(item, index) => {
|
|
161
|
+
if (item === "separator")
|
|
162
|
+
return (
|
|
163
|
+
<div {...api().getSeparatorProps()} class="{{prefix}}-menu__separator" />
|
|
164
|
+
);
|
|
165
|
+
const itemProps = createItemProps(() =>
|
|
166
|
+
api().getItemProps({ value: String(index()), disabled: item.disabled }),
|
|
167
|
+
);
|
|
168
|
+
return (
|
|
169
|
+
<div {...itemProps()} class={menuItemClass(item.danger)}>
|
|
170
|
+
<Show when={item.icon}>
|
|
171
|
+
{(name) => (
|
|
172
|
+
<Icon name={name()} size="sm" class="{{prefix}}-menu__item-icon" />
|
|
173
|
+
)}
|
|
174
|
+
</Show>
|
|
175
|
+
<span class="flex-1">{item.label}</span>
|
|
176
|
+
{/* Named, so a screen reader hears the state that the check shows. */}
|
|
177
|
+
<Show when={item.selected}>
|
|
178
|
+
<Icon name="check" size="sm" label="Selected" />
|
|
179
|
+
</Show>
|
|
180
|
+
</div>
|
|
181
|
+
);
|
|
182
|
+
}}
|
|
183
|
+
</For>
|
|
184
|
+
</div>
|
|
185
|
+
</div>
|
|
186
|
+
</TriggerContext>
|
|
187
|
+
</Portal>
|
|
188
|
+
</>
|
|
189
|
+
);
|
|
190
|
+
}
|
|
@@ -0,0 +1,109 @@
|
|
|
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
|
+
useLabels,
|
|
10
|
+
} from "@xds/solid/base";
|
|
11
|
+
import { For, Show } from "solid-js";
|
|
12
|
+
import { Icon } from "./Icon.tsx";
|
|
13
|
+
import {
|
|
14
|
+
clampPage,
|
|
15
|
+
PAGINATION_PARTS,
|
|
16
|
+
PAGINATION_STEPS,
|
|
17
|
+
type PaginationBaseProps,
|
|
18
|
+
paginationEntries,
|
|
19
|
+
} from "./pagination.ts";
|
|
20
|
+
import { classes, rootPart } from "./parts.ts";
|
|
21
|
+
|
|
22
|
+
export type PaginationProps = PaginationBaseProps &
|
|
23
|
+
RootProps & {
|
|
24
|
+
/** Called with the page to show, from 1. */
|
|
25
|
+
onChange?: (value: number) => void;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
const ROOT = rootPart("Pagination");
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Moves through a list split into pages: a step back, the first and the last pages, the page
|
|
32
|
+
* shown with an ellipsis for those left out, and a step on. A navigation landmark; the page
|
|
33
|
+
* shown is marked as the current page. Without `value` it keeps its own, from `defaultValue`.
|
|
34
|
+
*/
|
|
35
|
+
export function Pagination(props: PaginationProps) {
|
|
36
|
+
const labels = useLabels();
|
|
37
|
+
const value = createControllable<number | undefined>({
|
|
38
|
+
controlled: () => isControlled(props, "value"),
|
|
39
|
+
value: () => props.value,
|
|
40
|
+
defaultValue: () => props.defaultValue ?? 1,
|
|
41
|
+
onChange: (next) => {
|
|
42
|
+
if (next !== undefined) props.onChange?.(next);
|
|
43
|
+
},
|
|
44
|
+
});
|
|
45
|
+
const page = () => clampPage(value.value() ?? 1, props.count);
|
|
46
|
+
const last = () => Math.max(1, Math.floor(props.count));
|
|
47
|
+
const go = (next: number) => {
|
|
48
|
+
if (next !== page() && next >= 1 && next <= last()) value.set(next);
|
|
49
|
+
};
|
|
50
|
+
return (
|
|
51
|
+
<nav
|
|
52
|
+
{...rootAttributes(props)}
|
|
53
|
+
aria-label={props.label ?? labels().pagination}
|
|
54
|
+
class={classes(ROOT, props.class)}
|
|
55
|
+
style={props.style}
|
|
56
|
+
>
|
|
57
|
+
<ul class={PAGINATION_PARTS.list}>
|
|
58
|
+
<li>
|
|
59
|
+
<button
|
|
60
|
+
type="button"
|
|
61
|
+
class={PAGINATION_PARTS.step}
|
|
62
|
+
aria-label={props.previousLabel ?? labels().previousPage}
|
|
63
|
+
aria-disabled={page() <= 1 ? "true" : undefined}
|
|
64
|
+
onClick={() => go(page() - 1)}
|
|
65
|
+
>
|
|
66
|
+
<Icon name={PAGINATION_STEPS.previous} size={PAGINATION_STEPS.size} />
|
|
67
|
+
</button>
|
|
68
|
+
</li>
|
|
69
|
+
{/* By place: the two gaps are equal, and a page moves from place to place. */}
|
|
70
|
+
<For each={paginationEntries(page(), props.count)} keyed={false}>
|
|
71
|
+
{(entry) => (
|
|
72
|
+
<li>
|
|
73
|
+
<Show
|
|
74
|
+
when={entry() !== "gap" && (entry() as number)}
|
|
75
|
+
fallback={
|
|
76
|
+
<span class={PAGINATION_PARTS.gap} aria-hidden="true">
|
|
77
|
+
…
|
|
78
|
+
</span>
|
|
79
|
+
}
|
|
80
|
+
>
|
|
81
|
+
{(number) => (
|
|
82
|
+
<button
|
|
83
|
+
type="button"
|
|
84
|
+
class={PAGINATION_PARTS.page}
|
|
85
|
+
aria-current={number() === page() ? "page" : undefined}
|
|
86
|
+
onClick={() => go(number())}
|
|
87
|
+
>
|
|
88
|
+
{number()}
|
|
89
|
+
</button>
|
|
90
|
+
)}
|
|
91
|
+
</Show>
|
|
92
|
+
</li>
|
|
93
|
+
)}
|
|
94
|
+
</For>
|
|
95
|
+
<li>
|
|
96
|
+
<button
|
|
97
|
+
type="button"
|
|
98
|
+
class={PAGINATION_PARTS.step}
|
|
99
|
+
aria-label={props.nextLabel ?? labels().nextPage}
|
|
100
|
+
aria-disabled={page() >= last() ? "true" : undefined}
|
|
101
|
+
onClick={() => go(page() + 1)}
|
|
102
|
+
>
|
|
103
|
+
<Icon name={PAGINATION_STEPS.next} size={PAGINATION_STEPS.size} />
|
|
104
|
+
</button>
|
|
105
|
+
</li>
|
|
106
|
+
</ul>
|
|
107
|
+
</nav>
|
|
108
|
+
);
|
|
109
|
+
}
|
|
@@ -0,0 +1,124 @@
|
|
|
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
|
+
createPresence,
|
|
7
|
+
isControlled,
|
|
8
|
+
leaveEscapeToFields,
|
|
9
|
+
Portal,
|
|
10
|
+
provideTrigger,
|
|
11
|
+
type RootProps,
|
|
12
|
+
readCssPx,
|
|
13
|
+
rootAttributes,
|
|
14
|
+
space,
|
|
15
|
+
TriggerContext,
|
|
16
|
+
type TriggerProps,
|
|
17
|
+
useLabels,
|
|
18
|
+
withStyle,
|
|
19
|
+
} from "@xds/solid/base";
|
|
20
|
+
import * as popover from "@zag-js/popover";
|
|
21
|
+
import { mergeProps, normalizeProps, useMachine } from "@zag-js/solid";
|
|
22
|
+
import { createMemo, createUniqueId, type Element, Show } from "solid-js";
|
|
23
|
+
import { IconButton } from "./IconButton.tsx";
|
|
24
|
+
import { classes } from "./parts.ts";
|
|
25
|
+
import { POPOVER_PARTS, type PopoverBaseProps } from "./popover.ts";
|
|
26
|
+
|
|
27
|
+
/** `class` and `style` are for the popover's surface, not for its trigger. */
|
|
28
|
+
export type PopoverProps = PopoverBaseProps &
|
|
29
|
+
RootProps & {
|
|
30
|
+
/** The control that opens it: a Button or an IconButton. */
|
|
31
|
+
trigger: Element;
|
|
32
|
+
/** Called with whether it is open, as it opens and closes. */
|
|
33
|
+
onOpenChange?: (open: boolean) => void;
|
|
34
|
+
/** What it holds: a few lines of text, a short form, actions. */
|
|
35
|
+
children?: Element;
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* A surface that opens beside the control that opens it, for details or a short task that do
|
|
40
|
+
* not need the whole screen: a press outside, Escape or its close button closes it, and the
|
|
41
|
+
* focus goes back to the trigger. It is a dialog named by its title, and not modal: the page
|
|
42
|
+
* stays as it is behind it. Without `open` it keeps its own, from `defaultOpen`.
|
|
43
|
+
*/
|
|
44
|
+
export function Popover(props: PopoverProps) {
|
|
45
|
+
const id = createUniqueId();
|
|
46
|
+
const labels = useLabels();
|
|
47
|
+
const open = createControllable<boolean | undefined>({
|
|
48
|
+
controlled: () => isControlled(props, "open"),
|
|
49
|
+
value: () => props.open,
|
|
50
|
+
defaultValue: () => props.defaultOpen ?? false,
|
|
51
|
+
onChange: (next) => props.onOpenChange?.(next ?? false),
|
|
52
|
+
});
|
|
53
|
+
let content: HTMLElement | undefined;
|
|
54
|
+
const service = useMachine(popover.machine, () => ({
|
|
55
|
+
id,
|
|
56
|
+
// The app's id goes on the surface, where Zag looks for it by this one.
|
|
57
|
+
ids: { content: props.id },
|
|
58
|
+
open: open.value() ?? false,
|
|
59
|
+
onOpenChange: (details: popover.OpenChangeDetails) => open.set(details.open),
|
|
60
|
+
positioning: {
|
|
61
|
+
placement: props.placement ?? "bottom",
|
|
62
|
+
gutter: readCssPx(null, "--xds-space-1", space[1]),
|
|
63
|
+
},
|
|
64
|
+
onEscapeKeyDown: leaveEscapeToFields,
|
|
65
|
+
// The surface itself rather than its first control: a screen reader then reads the title
|
|
66
|
+
// first, and the close button is the next stop.
|
|
67
|
+
initialFocusEl: () => content ?? null,
|
|
68
|
+
}));
|
|
69
|
+
const api = createMemo(() => popover.connect(service, normalizeProps));
|
|
70
|
+
const trigger = provideTrigger(
|
|
71
|
+
// Added to the control's own class; the trigger looks pressed while it is open.
|
|
72
|
+
() =>
|
|
73
|
+
mergeProps(api().getTriggerProps() as TriggerProps, {
|
|
74
|
+
class: POPOVER_PARTS.trigger,
|
|
75
|
+
}) as TriggerProps,
|
|
76
|
+
);
|
|
77
|
+
const contentProps = withStyle(
|
|
78
|
+
() => api().getContentProps(),
|
|
79
|
+
() => props.style,
|
|
80
|
+
rootAttributes(props),
|
|
81
|
+
);
|
|
82
|
+
const present = createPresence(
|
|
83
|
+
() => api().open,
|
|
84
|
+
() => [content],
|
|
85
|
+
);
|
|
86
|
+
return (
|
|
87
|
+
<>
|
|
88
|
+
<TriggerContext value={trigger}>{props.trigger}</TriggerContext>
|
|
89
|
+
<Show when={present()}>
|
|
90
|
+
<Portal>
|
|
91
|
+
{/* Nothing inside opens an overlay from a control outside it. */}
|
|
92
|
+
<TriggerContext value={null}>
|
|
93
|
+
<div {...api().getPositionerProps()} class={POPOVER_PARTS.positioner}>
|
|
94
|
+
{/* Shown until its exit animation ends; Zag would hide it as it closes. */}
|
|
95
|
+
<section
|
|
96
|
+
{...contentProps}
|
|
97
|
+
ref={(element) => (content = element)}
|
|
98
|
+
hidden={false}
|
|
99
|
+
class={classes("{{prefix}}-popover", props.class)}
|
|
100
|
+
>
|
|
101
|
+
<div class={POPOVER_PARTS.header}>
|
|
102
|
+
<h2 {...api().getTitleProps()} class={POPOVER_PARTS.title}>
|
|
103
|
+
{props.title}
|
|
104
|
+
</h2>
|
|
105
|
+
<IconButton
|
|
106
|
+
icon="x"
|
|
107
|
+
label={props.closeLabel ?? labels().close}
|
|
108
|
+
variant="ghost"
|
|
109
|
+
size="sm"
|
|
110
|
+
class={POPOVER_PARTS.close}
|
|
111
|
+
onPress={() => api().setOpen(false)}
|
|
112
|
+
/>
|
|
113
|
+
</div>
|
|
114
|
+
<Show when={props.children != null}>
|
|
115
|
+
<div class={POPOVER_PARTS.body}>{props.children}</div>
|
|
116
|
+
</Show>
|
|
117
|
+
</section>
|
|
118
|
+
</div>
|
|
119
|
+
</TriggerContext>
|
|
120
|
+
</Portal>
|
|
121
|
+
</Show>
|
|
122
|
+
</>
|
|
123
|
+
);
|
|
124
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
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 { classes, rootPart } from "./parts.ts";
|
|
6
|
+
import {
|
|
7
|
+
type ProgressBarBaseProps,
|
|
8
|
+
progressBarClass,
|
|
9
|
+
progressBarFillClass,
|
|
10
|
+
progressPercent,
|
|
11
|
+
} from "./progress-bar.ts";
|
|
12
|
+
|
|
13
|
+
export type ProgressBarProps = ProgressBarBaseProps & RootProps;
|
|
14
|
+
|
|
15
|
+
const ROOT = rootPart("ProgressBar");
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* How far along something is, from 0 to 1. For work of unknown length use a Spinner.
|
|
19
|
+
* `label` says what is progressing; a screen reader reads it with the percentage.
|
|
20
|
+
*/
|
|
21
|
+
export function ProgressBar(props: ProgressBarProps) {
|
|
22
|
+
const percent = () => progressPercent(props.value);
|
|
23
|
+
return (
|
|
24
|
+
<div
|
|
25
|
+
{...rootAttributes(props)}
|
|
26
|
+
role="progressbar"
|
|
27
|
+
aria-label={props.label}
|
|
28
|
+
aria-valuemin={0}
|
|
29
|
+
aria-valuemax={100}
|
|
30
|
+
aria-valuenow={percent()}
|
|
31
|
+
class={classes(ROOT, progressBarClass, props.class)}
|
|
32
|
+
style={props.style}
|
|
33
|
+
>
|
|
34
|
+
<div class={progressBarFillClass} style={{ width: `${percent()}%` }} />
|
|
35
|
+
</div>
|
|
36
|
+
);
|
|
37
|
+
}
|