@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,66 @@
|
|
|
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
|
+
/** ListRow's props in every framework, short of `leading`, `trailing` and `onPress`. */
|
|
5
|
+
export type ListRowBaseProps = {
|
|
6
|
+
title: string;
|
|
7
|
+
description?: string;
|
|
8
|
+
/** Draws a chevron at the far end, for a row that leads somewhere else. */
|
|
9
|
+
chevron?: boolean;
|
|
10
|
+
/** The row that is the current choice, such as the open page in a sidebar. */
|
|
11
|
+
selected?: boolean;
|
|
12
|
+
/** A shorter row with smaller text, for dense lists such as a sidebar or a menu. */
|
|
13
|
+
compact?: boolean;
|
|
14
|
+
disabled?: boolean;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
// The selected title is heavier, so the choice does not depend on the tint alone.
|
|
18
|
+
const TITLE = {
|
|
19
|
+
regular: { rest: "text-xds-body", selected: "text-xds-body-strong" },
|
|
20
|
+
compact: { rest: "text-xds-detail", selected: "text-xds-label" },
|
|
21
|
+
} as const;
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* The fills and the focus ring of a pressable row, at rest and selected. A collapsed Sidebar
|
|
25
|
+
* draws its icon-only rows with them too. The ring is inside the row, where a list that clips
|
|
26
|
+
* its rows still shows it.
|
|
27
|
+
*/
|
|
28
|
+
export const PRESSABLE_ROW = {
|
|
29
|
+
rest: "hover:bg-xds-list-row-background-hover active:bg-xds-list-row-background-pressed disabled:hover:bg-transparent",
|
|
30
|
+
selected:
|
|
31
|
+
"hover:bg-xds-list-row-background-selected-hover active:bg-xds-list-row-background-selected-hover disabled:hover:bg-xds-list-row-background-selected",
|
|
32
|
+
focus:
|
|
33
|
+
"focus-visible:outline-solid focus-visible:outline-(length:--xds-focus-width) focus-visible:-outline-offset-(--xds-focus-offset) focus-visible:outline-xds-border-focus",
|
|
34
|
+
} as const;
|
|
35
|
+
|
|
36
|
+
/** The row: a `div`, or a `button` with `pressable`. */
|
|
37
|
+
export function listRowClass(options: {
|
|
38
|
+
compact?: boolean | undefined;
|
|
39
|
+
selected?: boolean | undefined;
|
|
40
|
+
pressable?: boolean | undefined;
|
|
41
|
+
}): string {
|
|
42
|
+
const { compact = false, selected = false, pressable = false } = options;
|
|
43
|
+
const row = `flex w-full items-center gap-3 px-4 text-start ${compact ? "min-h-xds-list-row-compact py-1" : "min-h-xds-list-row py-2"}${selected ? " bg-xds-list-row-background-selected" : ""}`;
|
|
44
|
+
if (!pressable) return row;
|
|
45
|
+
return `${row} cursor-pointer transition-colors duration-(--xds-motion-duration-fast) ${selected ? PRESSABLE_ROW.selected : PRESSABLE_ROW.rest} ${PRESSABLE_ROW.focus} disabled:cursor-not-allowed`;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export function listRowTitleClass(options: {
|
|
49
|
+
compact?: boolean | undefined;
|
|
50
|
+
selected?: boolean | undefined;
|
|
51
|
+
disabled?: boolean | undefined;
|
|
52
|
+
}): string {
|
|
53
|
+
const { compact = false, selected = false, disabled = false } = options;
|
|
54
|
+
return `${TITLE[compact ? "compact" : "regular"][selected ? "selected" : "rest"]} ${disabled ? "text-xds-text-secondary" : "text-xds-text-primary"}`;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export function listRowDescriptionClass(compact = false): string {
|
|
58
|
+
return `text-xds-text-secondary ${compact ? "text-xds-footnote" : "text-xds-detail"}`;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export const LIST_ROW_PARTS = {
|
|
62
|
+
/** The title and the description, between `leading` and `trailing`. */
|
|
63
|
+
text: "flex min-w-0 flex-1 flex-col gap-0.5",
|
|
64
|
+
/** It points onward, so it mirrors in a right-to-left layout. */
|
|
65
|
+
chevron: "text-xds-text-tertiary rtl:-scale-x-100",
|
|
66
|
+
} as const;
|
|
@@ -0,0 +1,66 @@
|
|
|
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 { ThumbnailRatio } from "@xds/solid/base";
|
|
5
|
+
|
|
6
|
+
export type MediaCardLayout = "vertical" | "horizontal";
|
|
7
|
+
|
|
8
|
+
/** MediaCard's props in every framework, short of `leading`, `action` and `onPress`. */
|
|
9
|
+
export type MediaCardBaseProps = {
|
|
10
|
+
/** `vertical` puts the thumbnail on top; `horizontal` at the start, at 40% of the width. */
|
|
11
|
+
layout?: MediaCardLayout;
|
|
12
|
+
/** The picture, as a Thumbnail's. */
|
|
13
|
+
src?: string | undefined;
|
|
14
|
+
/** Describes the picture. Defaults to an empty string: the title already says what it is. */
|
|
15
|
+
alt?: string;
|
|
16
|
+
ratio?: ThumbnailRatio;
|
|
17
|
+
/** Short text on the picture's bottom end corner, such as a duration. */
|
|
18
|
+
badge?: string;
|
|
19
|
+
/** How much was watched, from 0 to 1. */
|
|
20
|
+
progress?: number;
|
|
21
|
+
/** At most two lines, then an ellipsis. */
|
|
22
|
+
title: string;
|
|
23
|
+
/** Short details, one line each, such as a channel name and "3 days ago". */
|
|
24
|
+
meta?: readonly string[];
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
/** The ids of the title and of each detail, which together name the card. */
|
|
28
|
+
export function mediaCardIds(id: string, meta: readonly string[] = []) {
|
|
29
|
+
const title = `${id}-title`;
|
|
30
|
+
const details = meta.map((_, index) => `${id}-meta-${index}`);
|
|
31
|
+
return { title, details, names: [title, ...details].join(" ") };
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* The thumbnail and the text. On a pressable card it sits above the button, which draws the
|
|
36
|
+
* fills under it, and is see-through to the pointer, so a press anywhere but on the action
|
|
37
|
+
* lands on the button.
|
|
38
|
+
*/
|
|
39
|
+
export function mediaCardContentClass(options: {
|
|
40
|
+
horizontal: boolean;
|
|
41
|
+
pressable: boolean;
|
|
42
|
+
}): string {
|
|
43
|
+
const { horizontal, pressable } = options;
|
|
44
|
+
return `relative flex gap-3 ${horizontal ? "items-start" : "flex-col"}${pressable ? " pointer-events-none" : ""}`;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export function mediaCardThumbnailClass(horizontal: boolean): string {
|
|
48
|
+
return horizontal ? "w-2/5 shrink-0" : "block";
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export const MEDIA_CARD_PARTS = {
|
|
52
|
+
/** A card that is not pressable: a group named by its text. */
|
|
53
|
+
group: "flex flex-col",
|
|
54
|
+
/** A pressable card: the box around the button and the content. */
|
|
55
|
+
pressable: "relative flex flex-col rounded-xds-lg p-2",
|
|
56
|
+
/** Covers the whole pressable card, under the content. */
|
|
57
|
+
button:
|
|
58
|
+
"absolute inset-0 cursor-pointer rounded-xds-lg transition-colors duration-(--xds-motion-duration-fast) hover:bg-xds-card-background-hover focus-visible:outline-solid focus-visible:outline-(length:--xds-focus-width) focus-visible:outline-offset-(--xds-focus-offset) focus-visible:outline-xds-border-focus active:bg-xds-card-background-pressed",
|
|
59
|
+
/** Beside the thumbnail, or under it: `leading`, the text and the action. */
|
|
60
|
+
body: "flex min-w-0 flex-1 items-start gap-3",
|
|
61
|
+
leading: "flex shrink-0",
|
|
62
|
+
text: "flex min-w-0 flex-1 flex-col gap-0.5",
|
|
63
|
+
title: "line-clamp-2 text-xds-body-strong text-xds-text-primary",
|
|
64
|
+
meta: "truncate text-xds-detail text-xds-text-secondary",
|
|
65
|
+
action: "pointer-events-auto flex shrink-0",
|
|
66
|
+
} as const;
|
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Ejected from `@xds/solid` 1.2.0 by `xds eject`. This copy is the app's own: change it
|
|
3
|
+
* as you need. `xds eject --list` says which ejected files differ from what was copied.
|
|
4
|
+
*/
|
|
5
|
+
/*
|
|
6
|
+
* Menu: Zag's menu machine. The list stays in the body, hidden while closed once it has
|
|
7
|
+
* animated out.
|
|
8
|
+
*
|
|
9
|
+
* Parts: `.{{prefix}}-menu__trigger` (added to the Button or IconButton that opens it),
|
|
10
|
+
* `.{{prefix}}-menu__underlay` (over the page while the menu is open), `.{{prefix}}-menu__positioner` (placed by
|
|
11
|
+
* Zag), `.{{prefix}}-menu` (the surface, role="menu"), `.{{prefix}}-menu__item` with `.{{prefix}}-menu__item--danger`,
|
|
12
|
+
* `.{{prefix}}-menu__item-icon`, `.{{prefix}}-menu__separator`.
|
|
13
|
+
* States: `[aria-expanded="true"]` on the trigger while open, `[data-highlighted]` on the row
|
|
14
|
+
* the arrow keys or the pointer are on (focus stays on the menu, so it is the only sign of it),
|
|
15
|
+
* `:active` while pressed, `[data-disabled]`, `[data-side]` on the surface for the side it
|
|
16
|
+
* opened on, and `[data-state="closed"]` on it while it animates out.
|
|
17
|
+
*/
|
|
18
|
+
@layer components {
|
|
19
|
+
/* The trigger stays pressed while its menu is open, which ties the menu to the control it
|
|
20
|
+
came from. The underlay is over it, so the pointer does not turn it back to its hover
|
|
21
|
+
fill. */
|
|
22
|
+
.{{prefix}}-menu__trigger[aria-expanded="true"] {
|
|
23
|
+
background-color: var(--button-bg-pressed);
|
|
24
|
+
transform: scale(var(--xds-motion-press-scale));
|
|
25
|
+
will-change: transform;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
@media (prefers-reduced-motion: reduce) {
|
|
29
|
+
.{{prefix}}-menu__trigger[aria-expanded="true"] {
|
|
30
|
+
transform: none;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/* Over the page and under the open menu: a press outside lands here and only closes the
|
|
35
|
+
menu, and nothing on the page reacts to the pointer meanwhile. Rendered before the
|
|
36
|
+
positioner, it is under it at the same level. Inside a dialog it is above the dialog,
|
|
37
|
+
which was rendered earlier. */
|
|
38
|
+
.{{prefix}}-menu__underlay {
|
|
39
|
+
position: fixed;
|
|
40
|
+
inset: 0;
|
|
41
|
+
z-index: calc(var(--{{prefix}}-layer-overlay) + var(--layer-index, 0));
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
.{{prefix}}-menu__positioner {
|
|
45
|
+
z-index: calc(var(--{{prefix}}-layer-overlay) + var(--layer-index, 0));
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
.{{prefix}}-menu {
|
|
49
|
+
display: flex;
|
|
50
|
+
flex-direction: column;
|
|
51
|
+
/* Four times `space.12`: wide enough that a menu of short words does not look like a
|
|
52
|
+
stack of chips. Beyond that it is as wide as its longest row. */
|
|
53
|
+
min-width: calc(4 * var(--xds-space-12));
|
|
54
|
+
max-width: calc(100svw - 2 * var(--xds-space-4));
|
|
55
|
+
max-height: var(--available-height);
|
|
56
|
+
padding: var(--xds-space-1);
|
|
57
|
+
overflow-y: auto;
|
|
58
|
+
overscroll-behavior: contain;
|
|
59
|
+
scroll-padding-block: var(--xds-space-1);
|
|
60
|
+
scrollbar-width: thin;
|
|
61
|
+
border: var(--xds-border-width-thin) solid var(--xds-color-menu-border);
|
|
62
|
+
border-radius: var(--xds-radius-md);
|
|
63
|
+
background: var(--xds-color-menu-background);
|
|
64
|
+
box-shadow: var(--xds-shadow-raised);
|
|
65
|
+
outline: none;
|
|
66
|
+
transform-origin: var(--transform-origin);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/* It grows in from the trigger's side. */
|
|
70
|
+
.{{prefix}}-menu[data-side="bottom"] {
|
|
71
|
+
animation: {{prefix}}-menu-enter-down var(--xds-motion-duration-fast) var(--xds-motion-easing-enter);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
.{{prefix}}-menu[data-side="top"] {
|
|
75
|
+
animation: {{prefix}}-menu-enter-up var(--xds-motion-duration-fast) var(--xds-motion-easing-enter);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/* After the rules above, which it replaces. A closing menu takes no more presses. */
|
|
79
|
+
.{{prefix}}-menu[data-state="closed"] {
|
|
80
|
+
animation: {{prefix}}-overlay-exit var(--xds-motion-duration-fast) var(--xds-motion-easing-exit)
|
|
81
|
+
forwards;
|
|
82
|
+
pointer-events: none;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
@media (prefers-reduced-motion: reduce) {
|
|
86
|
+
.{{prefix}}-menu[data-side],
|
|
87
|
+
.{{prefix}}-menu[data-state="closed"] {
|
|
88
|
+
animation: none;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/* A row of a menu looks like a compact list row. A compact row is shorter than a finger
|
|
93
|
+
needs, so on a touch screen it grows to the smallest pressable size. The padding above and
|
|
94
|
+
below only shows on a row of two lines. */
|
|
95
|
+
.{{prefix}}-menu__item {
|
|
96
|
+
position: relative;
|
|
97
|
+
display: flex;
|
|
98
|
+
align-items: center;
|
|
99
|
+
justify-content: flex-start;
|
|
100
|
+
gap: var(--xds-space-2);
|
|
101
|
+
width: 100%;
|
|
102
|
+
min-height: max(var(--xds-size-list-row-compact), var(--xds-size-target-min));
|
|
103
|
+
padding: var(--xds-space-1) var(--xds-space-2);
|
|
104
|
+
border-radius: var(--xds-radius-sm);
|
|
105
|
+
white-space: nowrap;
|
|
106
|
+
font-size: var(--xds-typography-detail-size);
|
|
107
|
+
font-weight: var(--xds-typography-detail-weight);
|
|
108
|
+
line-height: var(--xds-typography-detail-line-height);
|
|
109
|
+
color: var(--xds-color-menu-text);
|
|
110
|
+
outline: none;
|
|
111
|
+
cursor: pointer;
|
|
112
|
+
touch-action: manipulation;
|
|
113
|
+
-webkit-tap-highlight-color: transparent;
|
|
114
|
+
transition: background-color var(--xds-motion-duration-fast) var(--xds-motion-easing-standard);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
.{{prefix}}-menu__item-icon {
|
|
118
|
+
color: var(--xds-color-menu-icon);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/* The pointer moves the same highlight as the arrow keys, so one rule draws both. The
|
|
122
|
+
highlight is a fill, which shows inside the menu where a focus ring would be clipped. */
|
|
123
|
+
.{{prefix}}-menu__item[data-highlighted] {
|
|
124
|
+
background: var(--xds-color-menu-item-background-hover);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/* A press that drags does not select the row's text. */
|
|
128
|
+
.{{prefix}}-menu__item:active {
|
|
129
|
+
background: var(--xds-color-menu-item-background-pressed);
|
|
130
|
+
user-select: none;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
.{{prefix}}-menu__item--danger,
|
|
134
|
+
.{{prefix}}-menu__item--danger .{{prefix}}-menu__item-icon {
|
|
135
|
+
color: var(--xds-color-menu-danger-text);
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
.{{prefix}}-menu__item--danger[data-highlighted],
|
|
139
|
+
.{{prefix}}-menu__item--danger:active {
|
|
140
|
+
background: var(--xds-color-menu-danger-background-hover);
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/* Recolored, not faded, like a disabled button. */
|
|
144
|
+
.{{prefix}}-menu__item[data-disabled],
|
|
145
|
+
.{{prefix}}-menu__item[data-disabled] .{{prefix}}-menu__item-icon {
|
|
146
|
+
color: var(--xds-color-menu-text-disabled);
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
.{{prefix}}-menu__item[data-disabled] {
|
|
150
|
+
cursor: not-allowed;
|
|
151
|
+
pointer-events: none;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
.{{prefix}}-menu__separator {
|
|
155
|
+
flex-shrink: 0;
|
|
156
|
+
height: var(--xds-border-width-thin);
|
|
157
|
+
margin-block: var(--xds-space-1);
|
|
158
|
+
background: var(--xds-color-menu-border);
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
/* Forced colors draw every fill in the page's color, so the row under the pointer or the
|
|
162
|
+
keyboard takes the system's highlight. The browser draws a backplate in the page's color behind text in forced colors,
|
|
163
|
+
which would hide the highlight's text, so these keep their colors, which are the system's. */
|
|
164
|
+
@media (forced-colors: active) {
|
|
165
|
+
.{{prefix}}-menu__item[data-highlighted],
|
|
166
|
+
.{{prefix}}-menu__item--danger[data-highlighted] {
|
|
167
|
+
forced-color-adjust: none;
|
|
168
|
+
background-color: Highlight;
|
|
169
|
+
color: HighlightText;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
.{{prefix}}-menu__item[data-highlighted] * {
|
|
173
|
+
color: inherit;
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
/* Literal offsets and scales: a custom property inside a keyframe keeps WebKit from running the
|
|
179
|
+
animation on the compositor. */
|
|
180
|
+
@keyframes {{prefix}}-menu-enter-down {
|
|
181
|
+
from {
|
|
182
|
+
opacity: 0;
|
|
183
|
+
transform: translate3d(0, -0.25rem, 0) scale(0.9);
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
@keyframes {{prefix}}-menu-enter-up {
|
|
188
|
+
from {
|
|
189
|
+
opacity: 0;
|
|
190
|
+
transform: translate3d(0, 0.25rem, 0) scale(0.9);
|
|
191
|
+
}
|
|
192
|
+
}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
// Ejected from `@xds/solid` 1.2.0 by `xds eject`. This copy is the app's own: change it
|
|
2
|
+
// as you need. `xds eject --list` says which ejected files differ from what was copied.
|
|
3
|
+
|
|
4
|
+
import type { IconName } from "@xds/solid/base";
|
|
5
|
+
|
|
6
|
+
export type MenuItem =
|
|
7
|
+
| "separator"
|
|
8
|
+
| {
|
|
9
|
+
label: string;
|
|
10
|
+
icon?: IconName;
|
|
11
|
+
onSelect: () => void;
|
|
12
|
+
/** An action that destroys something. Drawn in the danger color. */
|
|
13
|
+
danger?: boolean;
|
|
14
|
+
disabled?: boolean;
|
|
15
|
+
/** The current choice among its neighbours. Marked with a check at the end of the row. */
|
|
16
|
+
selected?: boolean;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
/** Menu's props in every framework, short of its trigger. */
|
|
20
|
+
export type MenuBaseProps = {
|
|
21
|
+
/** Names the menu for assistive technology. */
|
|
22
|
+
label: string;
|
|
23
|
+
items: readonly MenuItem[];
|
|
24
|
+
/** The edge of the trigger the menu lines up with. */
|
|
25
|
+
align?: "start" | "end";
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
/** The class of a row of the menu. The highlight and the disabled look come from attributes. */
|
|
29
|
+
export function menuItemClass(danger = false): string {
|
|
30
|
+
return danger ? "{{prefix}}-menu__item {{prefix}}-menu__item--danger" : "{{prefix}}-menu__item";
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* The box to place a menu against: its trigger's box before the transform that scales the
|
|
35
|
+
* trigger about its center while the menu is open, so the menu stays where it opened.
|
|
36
|
+
*/
|
|
37
|
+
export function layoutRect(element: HTMLElement): {
|
|
38
|
+
x: number;
|
|
39
|
+
y: number;
|
|
40
|
+
width: number;
|
|
41
|
+
height: number;
|
|
42
|
+
} {
|
|
43
|
+
const box = element.getBoundingClientRect();
|
|
44
|
+
const style = getComputedStyle(element);
|
|
45
|
+
const width = Number.parseFloat(style.width);
|
|
46
|
+
const height = Number.parseFloat(style.height);
|
|
47
|
+
return {
|
|
48
|
+
x: box.x + (box.width - width) / 2,
|
|
49
|
+
y: box.y + (box.height - height) / 2,
|
|
50
|
+
width,
|
|
51
|
+
height,
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Whether a press on a menu's trigger opens the menu as the button goes down rather than on
|
|
57
|
+
* the click: the main button of a mouse, without Control (which asks for the context menu on a
|
|
58
|
+
* Mac), on an enabled trigger. The pressed trigger then takes the focus, so the focus that
|
|
59
|
+
* comes back to it when the menu closes shows no keyboard ring. Touch and pen open it on the
|
|
60
|
+
* click, as Zag does.
|
|
61
|
+
*/
|
|
62
|
+
export function opensOnPress(event: {
|
|
63
|
+
pointerType: string;
|
|
64
|
+
button: number;
|
|
65
|
+
ctrlKey: boolean;
|
|
66
|
+
currentTarget: EventTarget | null;
|
|
67
|
+
}): boolean {
|
|
68
|
+
return (
|
|
69
|
+
event.pointerType === "mouse" &&
|
|
70
|
+
event.button === 0 &&
|
|
71
|
+
!event.ctrlKey &&
|
|
72
|
+
!(event.currentTarget instanceof Element && event.currentTarget.matches(":disabled"))
|
|
73
|
+
);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* The value of the first item that can be chosen, by position as the rows are: where the
|
|
78
|
+
* highlight goes when a screen reader or a script opens the menu with a click, as the keyboard
|
|
79
|
+
* puts it there, so the next key works the list at once.
|
|
80
|
+
*/
|
|
81
|
+
export function firstMenuValue(items: readonly MenuItem[]): string | undefined {
|
|
82
|
+
const first = items.findIndex((item) => item !== "separator" && !item.disabled);
|
|
83
|
+
return first >= 0 ? String(first) : undefined;
|
|
84
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Ejected from `@xds/solid` 1.2.0 by `xds eject`. This copy is the app's own: change it
|
|
3
|
+
* as you need. `xds eject --list` says which ejected files differ from what was copied.
|
|
4
|
+
*/
|
|
5
|
+
/*
|
|
6
|
+
* What every overlay shares: the level it is drawn on and how it leaves.
|
|
7
|
+
*
|
|
8
|
+
* The level: a dialog's scrim and the dialog, a menu, a select's list, a tooltip. Zag puts
|
|
9
|
+
* `--layer-index` on each layer it opens (0 for the first, 1 for one opened from it), and an
|
|
10
|
+
* overlay adds it, so the later one is on top. The design tokens have no z-index: only the web
|
|
11
|
+
* needs one. A toast needs none, as it is in the top layer.
|
|
12
|
+
*/
|
|
13
|
+
:root {
|
|
14
|
+
--{{prefix}}-layer-overlay: 100000;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/* How every overlay leaves: a menu, a select's list, a tooltip and a dialog fade and shrink a
|
|
18
|
+
little, a dialog's scrim fades. Each starts it on `[data-state="closed"]`, and its component
|
|
19
|
+
keeps it on the page until it ends. Each holds the last frame (`forwards`): a framework may
|
|
20
|
+
paint once more before it removes the overlay, which would otherwise show again for that
|
|
21
|
+
frame. Both ends are set: WebKit does not run a transform animation that starts from an
|
|
22
|
+
implicit `none`.
|
|
23
|
+
The scale is a literal because a custom property inside a keyframe keeps WebKit from running
|
|
24
|
+
the animation on the compositor. */
|
|
25
|
+
@keyframes {{prefix}}-overlay-exit {
|
|
26
|
+
from {
|
|
27
|
+
opacity: 1;
|
|
28
|
+
transform: scale(1);
|
|
29
|
+
}
|
|
30
|
+
to {
|
|
31
|
+
opacity: 0;
|
|
32
|
+
transform: scale(0.95);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
@keyframes {{prefix}}-fade-out {
|
|
37
|
+
to {
|
|
38
|
+
opacity: 0;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Ejected from `@xds/solid` 1.2.0 by `xds eject`. This copy is the app's own: change it
|
|
3
|
+
* as you need. `xds eject --list` says which ejected files differ from what was copied.
|
|
4
|
+
*/
|
|
5
|
+
/*
|
|
6
|
+
* Pagination: a `<nav>` holding a row of native buttons, the step back, the pages and the step
|
|
7
|
+
* on, with an ellipsis where pages are left out.
|
|
8
|
+
*
|
|
9
|
+
* Parts: `.{{prefix}}-pagination` (the root), `__list`, `__page` (`aria-current="page"` on the page
|
|
10
|
+
* shown), `__gap` and `__step`. A step with no page to go to has `aria-disabled="true"`, which
|
|
11
|
+
* keeps it in the tab order, so the focus stays on it once it reaches the end.
|
|
12
|
+
*/
|
|
13
|
+
@layer components {
|
|
14
|
+
.{{prefix}}-pagination__list {
|
|
15
|
+
display: flex;
|
|
16
|
+
align-items: center;
|
|
17
|
+
gap: var(--xds-space-1);
|
|
18
|
+
margin: 0;
|
|
19
|
+
padding: 0;
|
|
20
|
+
list-style: none;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
.{{prefix}}-pagination__list > li {
|
|
24
|
+
display: flex;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
.{{prefix}}-pagination__page,
|
|
28
|
+
.{{prefix}}-pagination__step,
|
|
29
|
+
.{{prefix}}-pagination__gap {
|
|
30
|
+
display: inline-flex;
|
|
31
|
+
align-items: center;
|
|
32
|
+
justify-content: center;
|
|
33
|
+
min-width: var(--xds-size-control-sm);
|
|
34
|
+
height: var(--xds-size-control-sm);
|
|
35
|
+
font-size: var(--xds-typography-label-size);
|
|
36
|
+
font-weight: var(--xds-typography-label-weight);
|
|
37
|
+
line-height: var(--xds-typography-label-line-height);
|
|
38
|
+
font-variant-numeric: tabular-nums;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
.{{prefix}}-pagination__page,
|
|
42
|
+
.{{prefix}}-pagination__step {
|
|
43
|
+
padding-inline: var(--xds-space-2);
|
|
44
|
+
/* Transparent until it is the page shown, so the outline never changes its size. */
|
|
45
|
+
border: var(--xds-border-width-thin) solid transparent;
|
|
46
|
+
border-radius: var(--xds-radius-md);
|
|
47
|
+
background-color: transparent;
|
|
48
|
+
color: var(--xds-color-pagination-text);
|
|
49
|
+
outline: none;
|
|
50
|
+
cursor: pointer;
|
|
51
|
+
user-select: none;
|
|
52
|
+
-webkit-tap-highlight-color: transparent;
|
|
53
|
+
transition-property: background-color, border-color;
|
|
54
|
+
transition-duration: var(--xds-motion-duration-fast);
|
|
55
|
+
transition-timing-function: var(--xds-motion-easing-standard);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
.{{prefix}}-pagination__step {
|
|
59
|
+
padding-inline: 0;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
.{{prefix}}-pagination__step svg {
|
|
63
|
+
pointer-events: none;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/* They point back and on, so they turn with the reading direction. */
|
|
67
|
+
.{{prefix}}-pagination__step svg:dir(rtl) {
|
|
68
|
+
transform: scaleX(-1);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
@media (hover: hover) {
|
|
72
|
+
.{{prefix}}-pagination__page:not([aria-current]):hover,
|
|
73
|
+
.{{prefix}}-pagination__step:not([aria-disabled="true"]):hover {
|
|
74
|
+
background-color: var(--xds-color-pagination-background-hover);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
.{{prefix}}-pagination__page:not([aria-current]):active,
|
|
79
|
+
.{{prefix}}-pagination__step:not([aria-disabled="true"]):active {
|
|
80
|
+
background-color: var(--xds-color-pagination-background-pressed);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/* The page shown: an outline as well as a tint, so it does not depend on color. */
|
|
84
|
+
.{{prefix}}-pagination__page[aria-current="page"] {
|
|
85
|
+
border-color: var(--xds-color-pagination-border-current);
|
|
86
|
+
background-color: var(--xds-color-pagination-background-current);
|
|
87
|
+
color: var(--xds-color-pagination-text-current);
|
|
88
|
+
cursor: default;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
.{{prefix}}-pagination__step[aria-disabled="true"] {
|
|
92
|
+
color: var(--xds-color-pagination-text-disabled);
|
|
93
|
+
cursor: not-allowed;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
.{{prefix}}-pagination__gap {
|
|
97
|
+
color: var(--xds-color-pagination-gap);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
.{{prefix}}-pagination__page:focus-visible,
|
|
101
|
+
.{{prefix}}-pagination__step:focus-visible {
|
|
102
|
+
box-shadow:
|
|
103
|
+
0 0 0 var(--xds-focus-offset) var(--xds-color-background-base),
|
|
104
|
+
0 0 0 calc(var(--xds-focus-width) + var(--xds-focus-offset)) var(--xds-color-border-focus);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
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
|
+
/** Pagination's props in every framework, short of its change handler. */
|
|
5
|
+
export type PaginationBaseProps = {
|
|
6
|
+
/** How many pages there are. */
|
|
7
|
+
count: number;
|
|
8
|
+
/**
|
|
9
|
+
* The page shown, from 1. Given at all, even as `undefined`, the app keeps it and changes it
|
|
10
|
+
* in `onChange`; otherwise the pagination keeps its own, from `defaultValue`.
|
|
11
|
+
*/
|
|
12
|
+
value?: number;
|
|
13
|
+
/** The page shown first when the pagination keeps its own. Defaults to 1. */
|
|
14
|
+
defaultValue?: number;
|
|
15
|
+
/**
|
|
16
|
+
* Names the pagination's navigation landmark for assistive technology: `pagination` from the
|
|
17
|
+
* closest `Labels`, "Pagination" in English, unless it is given.
|
|
18
|
+
*/
|
|
19
|
+
label?: string;
|
|
20
|
+
/** Names the step back a page: `previousPage` from the closest `Labels` unless it is given. */
|
|
21
|
+
previousLabel?: string;
|
|
22
|
+
/** Names the step on a page: `nextPage` from the closest `Labels` unless it is given. */
|
|
23
|
+
nextLabel?: string;
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
/** A page, by its number from 1, or a gap that stands for the pages left out. */
|
|
27
|
+
export type PaginationEntry = number | "gap";
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* The pages a Pagination shows between its steps: the first, the last, and the one shown, with
|
|
31
|
+
* a gap for each run of pages left out. Never more than five, so the row keeps its width from
|
|
32
|
+
* page to page and fits a phone held upright with the steps beside it. Near either end the
|
|
33
|
+
* three pages there are shown, so a gap never stands for a single page beside the one shown.
|
|
34
|
+
*/
|
|
35
|
+
export function paginationEntries(value: number, count: number): PaginationEntry[] {
|
|
36
|
+
const last = Math.max(0, Math.floor(count));
|
|
37
|
+
if (last <= 5) return Array.from({ length: last }, (_, index) => index + 1);
|
|
38
|
+
const page = clampPage(value, last);
|
|
39
|
+
if (page <= 3) return [1, 2, 3, "gap", last];
|
|
40
|
+
if (page >= last - 2) return [1, "gap", last - 2, last - 1, last];
|
|
41
|
+
return [1, "gap", page, "gap", last];
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/** The page shown, kept between the first and the last: an app may give one past the end. */
|
|
45
|
+
export function clampPage(value: number, count: number): number {
|
|
46
|
+
return Math.min(Math.max(1, Math.floor(value)), Math.max(1, Math.floor(count)));
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* The classes of a Pagination's parts beside its root, `{{prefix}}-pagination`, a `<nav>`: the row,
|
|
51
|
+
* a page, a gap, and the steps back and on.
|
|
52
|
+
*/
|
|
53
|
+
export const PAGINATION_PARTS = {
|
|
54
|
+
list: "{{prefix}}-pagination__list",
|
|
55
|
+
page: "{{prefix}}-pagination__page",
|
|
56
|
+
gap: "{{prefix}}-pagination__gap",
|
|
57
|
+
step: "{{prefix}}-pagination__step",
|
|
58
|
+
} as const;
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* The steps' chevrons, which point back and on, so they mirror in a right-to-left layout. `sm`
|
|
62
|
+
* is the icon of a small control.
|
|
63
|
+
*/
|
|
64
|
+
export const PAGINATION_STEPS = {
|
|
65
|
+
previous: "chevron-left",
|
|
66
|
+
next: "chevron-right",
|
|
67
|
+
size: "sm",
|
|
68
|
+
} as const;
|
|
@@ -0,0 +1,17 @@
|
|
|
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
|
+
/**
|
|
5
|
+
* The class on the root element of every web component, `{{prefix}}-` and its name in kebab case
|
|
6
|
+
* (`{{prefix}}-icon-button`). It is the component's stable handle for an app's own styles, beside the
|
|
7
|
+
* part classes of the components drawn with a stylesheet (`{{prefix}}-dialog__title`) and the state
|
|
8
|
+
* attributes (`aria-*`, `data-state`). A published library names it after itself.
|
|
9
|
+
*/
|
|
10
|
+
export function rootPart(component: string): string {
|
|
11
|
+
return `{{prefix}}-${component.replace(/[A-Z]/g, (letter, index: number) => `${index ? "-" : ""}${letter.toLowerCase()}`)}`;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/** Joins the classes that are given, skipping those that are not. */
|
|
15
|
+
export function classes(...names: (string | false | null | undefined)[]): string {
|
|
16
|
+
return names.filter(Boolean).join(" ");
|
|
17
|
+
}
|