@xds/svelte 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.
- .diffend-unextracted-0 +2 -1
- package/dist/Accordion.svelte +7 -2
- package/dist/Avatar.svelte +10 -2
- package/dist/AvatarStack.svelte +11 -1
- package/dist/Badge.svelte +14 -3
- package/dist/Banner.svelte +6 -1
- package/dist/Breadcrumb.svelte +53 -0
- package/dist/Breadcrumb.svelte.d.ts +11 -0
- package/dist/Button.svelte +30 -2
- package/dist/Button.svelte.d.ts +10 -1
- package/dist/Card.svelte +16 -2
- package/dist/Checkbox.svelte +62 -10
- package/dist/Checkbox.svelte.d.ts +14 -3
- package/dist/Chip.svelte +3 -1
- package/dist/ChipBar.svelte +3 -2
- package/dist/Combobox.svelte +194 -0
- package/dist/Combobox.svelte.d.ts +37 -0
- package/dist/CountBadge.svelte +4 -2
- package/dist/DatePicker.svelte +16 -5
- package/dist/DateRangePicker.svelte +6 -1
- package/dist/Dialog.svelte +9 -2
- package/dist/Divider.svelte +7 -3
- package/dist/EmptyState.svelte +15 -3
- package/dist/Icon.svelte +11 -2
- package/dist/IconButton.svelte +30 -2
- package/dist/IconButton.svelte.d.ts +10 -1
- package/dist/Labels.svelte +29 -0
- package/dist/Labels.svelte.d.ts +17 -0
- package/dist/Link.svelte +86 -0
- package/dist/Link.svelte.d.ts +26 -0
- package/dist/MediaCard.svelte +4 -1
- package/dist/Menu.svelte +21 -2
- package/dist/Pagination.svelte +108 -0
- package/dist/Pagination.svelte.d.ts +14 -0
- package/dist/PlaceRow.svelte +6 -1
- package/dist/Popover.svelte +91 -0
- package/dist/Popover.svelte.d.ts +21 -0
- package/dist/PopoverSurface.svelte +77 -0
- package/dist/PopoverSurface.svelte.d.ts +21 -0
- package/dist/ProgressBar.svelte +3 -1
- package/dist/RadioGroup.svelte +23 -8
- package/dist/RadioGroup.svelte.d.ts +4 -2
- package/dist/SearchField.svelte +65 -18
- package/dist/SearchField.svelte.d.ts +14 -4
- package/dist/SectionHeader.svelte +7 -2
- package/dist/SegmentedControl.svelte +21 -7
- package/dist/SegmentedControl.svelte.d.ts +3 -2
- package/dist/Select.svelte +64 -12
- package/dist/Select.svelte.d.ts +9 -2
- package/dist/Sidebar.svelte +3 -0
- package/dist/Skeleton.svelte +10 -2
- package/dist/Slider.svelte +23 -7
- package/dist/Slider.svelte.d.ts +2 -2
- package/dist/Spinner.svelte +3 -2
- package/dist/Switch.svelte +53 -9
- package/dist/Switch.svelte.d.ts +13 -3
- package/dist/Table.svelte +92 -0
- package/dist/Table.svelte.d.ts +17 -0
- package/dist/Tabs.svelte +21 -6
- package/dist/Tabs.svelte.d.ts +2 -1
- package/dist/Text.svelte +3 -1
- package/dist/TextField.svelte +59 -14
- package/dist/TextField.svelte.d.ts +13 -3
- package/dist/Thumbnail.svelte +7 -1
- package/dist/TimePicker.svelte +222 -0
- package/dist/TimePicker.svelte.d.ts +20 -0
- package/dist/Toast.svelte +12 -2
- package/dist/ToastQueue.svelte +57 -0
- package/dist/ToastQueue.svelte.d.ts +20 -0
- package/dist/Tooltip.svelte +9 -2
- package/dist/TooltipOverlay.svelte +9 -2
- package/dist/base.d.ts +14 -0
- package/dist/base.js +27 -0
- package/dist/controllable.svelte.d.ts +28 -0
- package/dist/controllable.svelte.js +41 -0
- package/dist/index.d.ts +12 -2
- package/dist/index.js +12 -0
- package/dist/labels.svelte.d.ts +13 -0
- package/dist/labels.svelte.js +24 -0
- package/dist/modal-popover.svelte.js +5 -1
- package/dist/presence.svelte.js +5 -2
- package/dist/preview/Component.svelte +8 -3
- package/dist/preview/Preview.svelte +8 -2
- package/dist/preview/Preview.svelte.d.ts +2 -0
- package/dist/preview/components.d.ts +9 -2
- package/dist/preview/components.js +18 -1
- package/dist/preview/index.d.ts +1 -0
- package/dist/root.d.ts +4 -2
- package/eject/files/Accordion.svelte +100 -0
- package/eject/files/AccordionPanel.svelte +48 -0
- package/eject/files/Avatar.svelte +51 -0
- package/eject/files/AvatarStack.svelte +61 -0
- package/eject/files/Badge.svelte +52 -0
- package/eject/files/Banner.svelte +94 -0
- package/eject/files/Breadcrumb.svelte +52 -0
- package/eject/files/Button.svelte +126 -0
- package/eject/files/Card.svelte +112 -0
- package/eject/files/Checkbox.svelte +121 -0
- package/eject/files/Chip.svelte +51 -0
- package/eject/files/ChipBar.svelte +39 -0
- package/eject/files/Combobox.svelte +198 -0
- package/eject/files/CountBadge.svelte +51 -0
- package/eject/files/DatePicker.svelte +213 -0
- package/eject/files/DateRangePicker.svelte +294 -0
- package/eject/files/Dialog.svelte +119 -0
- package/eject/files/Divider.svelte +27 -0
- package/eject/files/EmptyState.svelte +52 -0
- package/eject/files/Icon.svelte +51 -0
- package/eject/files/IconButton.svelte +99 -0
- package/eject/files/Link.svelte +85 -0
- package/eject/files/ListRow.svelte +33 -0
- package/eject/files/MediaCard.svelte +117 -0
- package/eject/files/Menu.svelte +183 -0
- package/eject/files/Pagination.svelte +109 -0
- package/eject/files/PlaceRow.svelte +75 -0
- package/eject/files/Popover.svelte +100 -0
- package/eject/files/PopoverSurface.svelte +85 -0
- package/eject/files/ProgressBar.svelte +38 -0
- package/eject/files/RadioGroup.svelte +133 -0
- package/eject/files/SearchField.svelte +154 -0
- package/eject/files/SectionHeader.svelte +67 -0
- package/eject/files/SegmentedControl.svelte +85 -0
- package/eject/files/Select.svelte +276 -0
- package/eject/files/Sidebar.svelte +130 -0
- package/eject/files/SidebarRailButton.svelte +32 -0
- package/eject/files/Skeleton.svelte +55 -0
- package/eject/files/Slider.svelte +136 -0
- package/eject/files/Spinner.svelte +41 -0
- package/eject/files/Switch.svelte +105 -0
- package/eject/files/Table.svelte +90 -0
- package/eject/files/Tabs.svelte +85 -0
- package/eject/files/Text.svelte +43 -0
- package/eject/files/TextField.svelte +222 -0
- package/eject/files/Thumbnail.svelte +88 -0
- package/eject/files/TimePicker.svelte +237 -0
- package/eject/files/Toast.svelte +98 -0
- package/eject/files/ToastQueue.svelte +61 -0
- package/eject/files/Tooltip.svelte +51 -0
- package/eject/files/TooltipOverlay.svelte +88 -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 +1053 -0
- package/package.json +12 -4
- package/styles.css +1064 -169
- package/tailwind.css +1295 -218
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
// Ejected from `@xds/svelte` 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 { AVATAR_SIZE, type AvatarSize } from "@xds/svelte/base";
|
|
5
|
+
|
|
6
|
+
// Each avatar covers a quarter of the one before it. Written out in full: Tailwind only
|
|
7
|
+
// generates the classes it can find as whole strings.
|
|
8
|
+
const OVERLAP = {
|
|
9
|
+
sm: "not-first:ms-[calc(var(--xds-size-avatar-sm)/-4)]",
|
|
10
|
+
md: "not-first:ms-[calc(var(--xds-size-avatar-md)/-4)]",
|
|
11
|
+
lg: "not-first:ms-[calc(var(--xds-size-avatar-lg)/-4)]",
|
|
12
|
+
xl: "not-first:ms-[calc(var(--xds-size-avatar-xl)/-4)]",
|
|
13
|
+
} as const;
|
|
14
|
+
|
|
15
|
+
// The ring is in the color of the surface behind the stack, so it reads as a gap between two
|
|
16
|
+
// avatars. It is an outline, which takes no room: the stack is as wide as its avatars.
|
|
17
|
+
const RING =
|
|
18
|
+
"rounded-full outline-solid outline-(length:--xds-border-width-thick) outline-xds-avatar-ring";
|
|
19
|
+
|
|
20
|
+
/** AvatarStack's props in every framework. */
|
|
21
|
+
export type AvatarStackBaseProps = {
|
|
22
|
+
people: readonly { name: string; src?: string | undefined }[];
|
|
23
|
+
/** How many avatars to draw. The rest are counted in a "+3" at the end. */
|
|
24
|
+
max?: number;
|
|
25
|
+
size?: AvatarSize;
|
|
26
|
+
/** Replaces the list of names that assistive technology reads. */
|
|
27
|
+
label?: string;
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
export const avatarStackClass = "inline-flex shrink-0 items-center";
|
|
31
|
+
|
|
32
|
+
/** The ring around each avatar of the stack. */
|
|
33
|
+
export function avatarStackItemClass(size: AvatarSize = "md"): string {
|
|
34
|
+
return `inline-flex ${RING} ${OVERLAP[size]}`;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/** The "+3" after the avatars, in an avatar's box. */
|
|
38
|
+
export function avatarStackRestClass(size: AvatarSize = "md"): string {
|
|
39
|
+
return `inline-flex select-none items-center justify-center bg-xds-avatar-overflow-background text-xds-avatar-overflow-text ${AVATAR_SIZE[size]} ${RING} ${OVERLAP[size]}`;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* The avatars drawn, how many people the "+3" counts, and the name of the whole stack, which
|
|
44
|
+
* includes those who did not fit.
|
|
45
|
+
*/
|
|
46
|
+
export function avatarStack<Person extends { name: string }>(
|
|
47
|
+
people: readonly Person[],
|
|
48
|
+
max = 4,
|
|
49
|
+
label?: string,
|
|
50
|
+
): { shown: readonly Person[]; rest: number; name: string } {
|
|
51
|
+
const shown = people.slice(0, max);
|
|
52
|
+
return {
|
|
53
|
+
shown,
|
|
54
|
+
rest: people.length - shown.length,
|
|
55
|
+
name: label ?? people.map((person) => person.name).join(", "),
|
|
56
|
+
};
|
|
57
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
// Ejected from `@xds/svelte` 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 { initials } from "@xds/svelte/base";
|
|
5
|
+
|
|
6
|
+
// The box and the type role of the initials. AvatarStack draws its "+3" with the same pair.
|
|
7
|
+
export const AVATAR_SIZE = {
|
|
8
|
+
sm: "size-xds-avatar-sm text-xds-footnote",
|
|
9
|
+
md: "size-xds-avatar-md text-xds-label",
|
|
10
|
+
lg: "size-xds-avatar-lg text-xds-body-strong",
|
|
11
|
+
xl: "size-xds-avatar-xl text-xds-title",
|
|
12
|
+
} as const;
|
|
13
|
+
|
|
14
|
+
export type AvatarSize = keyof typeof AVATAR_SIZE;
|
|
15
|
+
|
|
16
|
+
/** Avatar's props in every framework. */
|
|
17
|
+
export type AvatarBaseProps = {
|
|
18
|
+
name: string;
|
|
19
|
+
/** The URL of a picture. The initials show while it loads, and stay if it fails. */
|
|
20
|
+
src?: string | undefined;
|
|
21
|
+
size?: AvatarSize;
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
export function avatarClass(size: AvatarSize = "md"): string {
|
|
25
|
+
return `relative inline-flex shrink-0 select-none items-center justify-center overflow-hidden rounded-full bg-xds-avatar-background text-xds-avatar-text ${AVATAR_SIZE[size]}`;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/** The letters an avatar of `size` shows: the small size has room for one. */
|
|
29
|
+
export function avatarInitials(name: string, size: AvatarSize = "md"): string {
|
|
30
|
+
return initials(name, size === "sm" ? 1 : 2);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* The class of a picture over a placeholder: Avatar's initials, Thumbnail's icon. It is not
|
|
35
|
+
* shown until it has loaded: a picture that is half there, or broken, would cover the
|
|
36
|
+
* placeholder with nothing.
|
|
37
|
+
*/
|
|
38
|
+
export function pictureClass(loaded: boolean): string {
|
|
39
|
+
return loaded
|
|
40
|
+
? "absolute inset-0 size-full object-cover"
|
|
41
|
+
: "invisible absolute inset-0 size-full object-cover";
|
|
42
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
// Ejected from `@xds/svelte` 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/svelte/base";
|
|
5
|
+
|
|
6
|
+
const TONE = {
|
|
7
|
+
neutral: "bg-xds-badge-neutral-background text-xds-badge-neutral-text",
|
|
8
|
+
accent: "bg-xds-badge-accent-background text-xds-badge-accent-text",
|
|
9
|
+
success: "bg-xds-badge-success-background text-xds-badge-success-text",
|
|
10
|
+
warning: "bg-xds-badge-warning-background text-xds-badge-warning-text",
|
|
11
|
+
danger: "bg-xds-badge-danger-background text-xds-badge-danger-text",
|
|
12
|
+
/** For a badge that sits on a picture: the same in both color modes. */
|
|
13
|
+
overlay: "bg-xds-badge-overlay-background text-xds-badge-overlay-text",
|
|
14
|
+
} as const;
|
|
15
|
+
|
|
16
|
+
export type BadgeTone = keyof typeof TONE;
|
|
17
|
+
|
|
18
|
+
/** Badge's props in every framework, short of its words. */
|
|
19
|
+
export type BadgeBaseProps = {
|
|
20
|
+
tone?: BadgeTone;
|
|
21
|
+
dot?: boolean;
|
|
22
|
+
icon?: IconName;
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
export function badgeClass(tone: BadgeTone = "neutral"): string {
|
|
26
|
+
return `inline-flex h-xds-badge w-fit shrink-0 items-center gap-1.5 whitespace-nowrap rounded-full px-2.5 text-xds-footnote ${TONE[tone]}`;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/** The mark of a badge with `dot`, in the color of its words. */
|
|
30
|
+
export const badgeDotClass = "size-1.5 rounded-full bg-current";
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
// Ejected from `@xds/svelte` 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
|
+
const TONE = {
|
|
5
|
+
info: {
|
|
6
|
+
surface: "bg-xds-banner-info-background",
|
|
7
|
+
accent: "text-xds-banner-info-accent",
|
|
8
|
+
// A circled "i".
|
|
9
|
+
icon: "M12 2a10 10 0 1 0 0 20 10 10 0 0 0 0-20Zm0 5.2a1.3 1.3 0 1 1 0 2.6 1.3 1.3 0 0 1 0-2.6ZM10.9 11h2.2v6h-2.2v-6Z",
|
|
10
|
+
},
|
|
11
|
+
success: {
|
|
12
|
+
surface: "bg-xds-banner-success-background",
|
|
13
|
+
accent: "text-xds-banner-success-accent",
|
|
14
|
+
// A circled check mark.
|
|
15
|
+
icon: "M12 2a10 10 0 1 0 0 20 10 10 0 0 0 0-20Zm4.7 7.7-5.5 6a1 1 0 0 1-1.5 0l-2.4-2.6 1.5-1.4 1.6 1.8 4.8-5.2 1.5 1.4Z",
|
|
16
|
+
},
|
|
17
|
+
warning: {
|
|
18
|
+
surface: "bg-xds-banner-warning-background",
|
|
19
|
+
accent: "text-xds-banner-warning-accent",
|
|
20
|
+
// A triangle with "!".
|
|
21
|
+
icon: "M12 2.5 1.5 20.5h21L12 2.5Zm-1.1 6.5h2.2v6h-2.2V9Zm1.1 7.3a1.3 1.3 0 1 1 0 2.6 1.3 1.3 0 0 1 0-2.6Z",
|
|
22
|
+
},
|
|
23
|
+
danger: {
|
|
24
|
+
surface: "bg-xds-banner-danger-background",
|
|
25
|
+
accent: "text-xds-banner-danger-accent",
|
|
26
|
+
// A circled "!".
|
|
27
|
+
icon: "M12 2a10 10 0 1 0 0 20 10 10 0 0 0 0-20Zm-1.1 5h2.2v7h-2.2V7Zm1.1 8.2a1.3 1.3 0 1 1 0 2.6 1.3 1.3 0 0 1 0-2.6Z",
|
|
28
|
+
},
|
|
29
|
+
} as const;
|
|
30
|
+
|
|
31
|
+
export type BannerTone = keyof typeof TONE;
|
|
32
|
+
|
|
33
|
+
/** Banner's props in every framework, short of its message, its action and `onDismiss`. */
|
|
34
|
+
export type BannerBaseProps = {
|
|
35
|
+
tone?: BannerTone;
|
|
36
|
+
title?: string;
|
|
37
|
+
/**
|
|
38
|
+
* Names the close control for assistive technology. The `dismiss` label of a `Labels` provider
|
|
39
|
+
* unless set.
|
|
40
|
+
*/
|
|
41
|
+
dismissLabel?: string;
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
export function bannerClass(tone: BannerTone = "info"): string {
|
|
45
|
+
return `flex items-start gap-3 rounded-xds-md p-3 text-xds-banner-text ${TONE[tone].surface}`;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/** The class of the tone's icon, a 24 by 24 drawing of `bannerIconPath(tone)`. */
|
|
49
|
+
export function bannerIconClass(tone: BannerTone = "info"): string {
|
|
50
|
+
return `mt-0.5 size-xds-icon-md shrink-0 ${TONE[tone].accent}`;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/** Each tone has its own icon shape, so the tone does not depend on color. */
|
|
54
|
+
export function bannerIconPath(tone: BannerTone = "info"): string {
|
|
55
|
+
return TONE[tone].icon;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/** Problems interrupt a screen reader; `info` and `success` wait their turn. */
|
|
59
|
+
export function bannerRole(tone: BannerTone = "info"): "alert" | "status" {
|
|
60
|
+
return tone === "danger" || tone === "warning" ? "alert" : "status";
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export const BANNER_PARTS = {
|
|
64
|
+
/** The title, the message and the action, beside the icon. */
|
|
65
|
+
body: "flex min-w-0 flex-1 flex-col gap-0.5 text-xds-detail",
|
|
66
|
+
title: "text-xds-label",
|
|
67
|
+
action: "mt-2",
|
|
68
|
+
// Pulled into the padding, so the cross lines up with the first line of text and a
|
|
69
|
+
// pointer-sized close control does not make a one-line banner taller.
|
|
70
|
+
dismiss: "-m-1 flex shrink-0",
|
|
71
|
+
} as const;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Ejected from `@xds/svelte` 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
|
+
* The base of the ejected components: what the library's stylesheet gives its own elements,
|
|
7
|
+
* given to the elements whose class starts with `{{prefix}}-`, and what is inside one.
|
|
8
|
+
*/
|
|
9
|
+
@layer base {
|
|
10
|
+
/* The outermost component takes the page font of a scaffolded app, so it looks the same in any
|
|
11
|
+
page. The components inside it inherit it as they do there. */
|
|
12
|
+
:where([class^="{{prefix}}-"], [class*=" {{prefix}}-"]):not(:where([class^="{{prefix}}-"], [class*=" {{prefix}}-"]) *) {
|
|
13
|
+
font-family: var(--xds-font-family-sans);
|
|
14
|
+
/* Korean breaks between words, not between syllables. */
|
|
15
|
+
word-break: keep-all;
|
|
16
|
+
/* Long unbroken strings (URLs, email addresses) still wrap instead of overflowing. */
|
|
17
|
+
overflow-wrap: anywhere;
|
|
18
|
+
-webkit-text-size-adjust: 100%;
|
|
19
|
+
tab-size: 4;
|
|
20
|
+
font-feature-settings: normal;
|
|
21
|
+
font-variation-settings: normal;
|
|
22
|
+
-webkit-tap-highlight-color: transparent;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/* A border without a color of its own is a divider, not text-colored. */
|
|
26
|
+
:where([class^="{{prefix}}-"], [class*=" {{prefix}}-"]),
|
|
27
|
+
:where([class^="{{prefix}}-"], [class*=" {{prefix}}-"]) *,
|
|
28
|
+
:where([class^="{{prefix}}-"], [class*=" {{prefix}}-"])::after,
|
|
29
|
+
:where([class^="{{prefix}}-"], [class*=" {{prefix}}-"]) ::after,
|
|
30
|
+
:where([class^="{{prefix}}-"], [class*=" {{prefix}}-"])::before,
|
|
31
|
+
:where([class^="{{prefix}}-"], [class*=" {{prefix}}-"]) ::before,
|
|
32
|
+
:where([class^="{{prefix}}-"], [class*=" {{prefix}}-"])::backdrop,
|
|
33
|
+
:where([class^="{{prefix}}-"], [class*=" {{prefix}}-"]) ::backdrop,
|
|
34
|
+
:where([class^="{{prefix}}-"], [class*=" {{prefix}}-"])::file-selector-button,
|
|
35
|
+
:where([class^="{{prefix}}-"], [class*=" {{prefix}}-"]) ::file-selector-button {
|
|
36
|
+
border-color: var(--xds-color-border-default);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Ejected from `@xds/svelte` 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
|
+
* Breadcrumb: a `<nav>` holding an ordered list of the places above the current one, each a
|
|
7
|
+
* Link, and the current place, which is not a link.
|
|
8
|
+
*
|
|
9
|
+
* Parts: `.{{prefix}}-breadcrumb` (the root), `__list`, `__item`, `__separator` (the chevron after
|
|
10
|
+
* every place but the last) and `__current` (the last place, with `aria-current="page"`).
|
|
11
|
+
*/
|
|
12
|
+
@layer components {
|
|
13
|
+
.{{prefix}}-breadcrumb {
|
|
14
|
+
font-size: var(--xds-typography-detail-size);
|
|
15
|
+
line-height: var(--xds-typography-detail-line-height);
|
|
16
|
+
font-weight: var(--xds-typography-detail-weight);
|
|
17
|
+
letter-spacing: var(--xds-typography-detail-letter-spacing);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/* A long trail wraps between places, never inside a chevron and the place before it. */
|
|
21
|
+
.{{prefix}}-breadcrumb__list {
|
|
22
|
+
display: flex;
|
|
23
|
+
flex-wrap: wrap;
|
|
24
|
+
align-items: center;
|
|
25
|
+
column-gap: var(--xds-space-1);
|
|
26
|
+
margin: 0;
|
|
27
|
+
padding: 0;
|
|
28
|
+
list-style: none;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
.{{prefix}}-breadcrumb__item {
|
|
32
|
+
display: inline-flex;
|
|
33
|
+
align-items: center;
|
|
34
|
+
gap: var(--xds-space-1);
|
|
35
|
+
min-width: 0;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
.{{prefix}}-breadcrumb__separator {
|
|
39
|
+
color: var(--xds-color-breadcrumb-separator);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/* It points onward, so it turns with the reading direction. */
|
|
43
|
+
.{{prefix}}-breadcrumb__separator:dir(rtl) {
|
|
44
|
+
transform: scaleX(-1);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/* Told from the places above it by not being a link: no underline, not in the link color. */
|
|
48
|
+
.{{prefix}}-breadcrumb__current {
|
|
49
|
+
color: var(--xds-color-breadcrumb-current);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
// Ejected from `@xds/svelte` 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
|
+
/** One place of a Breadcrumb's trail. */
|
|
5
|
+
export type BreadcrumbItem = {
|
|
6
|
+
label: string;
|
|
7
|
+
/** The address the place's link opens. Leave it out for one that only calls `onPress`. */
|
|
8
|
+
href?: string;
|
|
9
|
+
/** Called when the place's link is pressed, before the browser follows `href`. */
|
|
10
|
+
onPress?: () => void;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
/** Breadcrumb's props in every framework. */
|
|
14
|
+
export type BreadcrumbBaseProps = {
|
|
15
|
+
/**
|
|
16
|
+
* The places from the top of the app down to the current one, which is the last. Every place
|
|
17
|
+
* but the last is a link; the last is where the person is, and is not.
|
|
18
|
+
*/
|
|
19
|
+
items: readonly BreadcrumbItem[];
|
|
20
|
+
/**
|
|
21
|
+
* Names the trail's navigation landmark for assistive technology: `breadcrumb` from the
|
|
22
|
+
* closest `Labels`, "Breadcrumb" in English, unless it is given.
|
|
23
|
+
*/
|
|
24
|
+
label?: string;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* The classes of a Breadcrumb's parts beside its root, `{{prefix}}-breadcrumb`, a `<nav>`: the list,
|
|
29
|
+
* one item per place, the chevron between two places, and the current place.
|
|
30
|
+
*/
|
|
31
|
+
export const BREADCRUMB_PARTS = {
|
|
32
|
+
list: "{{prefix}}-breadcrumb__list",
|
|
33
|
+
item: "{{prefix}}-breadcrumb__item",
|
|
34
|
+
separator: "{{prefix}}-breadcrumb__separator",
|
|
35
|
+
current: "{{prefix}}-breadcrumb__current",
|
|
36
|
+
} as const;
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* The chevron between two places. `xs` sits on the line of detail text, the trail's type, and
|
|
40
|
+
* the chevron points onward, so it mirrors in a right-to-left layout.
|
|
41
|
+
*/
|
|
42
|
+
export const BREADCRUMB_SEPARATOR = { name: "chevron-right", size: "xs" } as const;
|
|
@@ -0,0 +1,241 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Ejected from `@xds/svelte` 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
|
+
* Button and IconButton: a native <button>.
|
|
7
|
+
*
|
|
8
|
+
* Classes: `.{{prefix}}-button`, `.{{prefix}}-button--<variant>`, `.{{prefix}}-button--<size>`, `.{{prefix}}-button--icon-only` (a Button
|
|
9
|
+
* with icons and no label), `.{{prefix}}-button--full-width`, and `.{{prefix}}-icon-button` (IconButton).
|
|
10
|
+
* States: `:hover`, `:active`, `:focus-visible`, `:disabled`, `[aria-pressed]` for a toggle, and
|
|
11
|
+
* `[aria-disabled="true"][data-pending]` while loading.
|
|
12
|
+
*/
|
|
13
|
+
@layer components {
|
|
14
|
+
.{{prefix}}-button {
|
|
15
|
+
/* The fill and the text color of the current state. Variants and states set these. */
|
|
16
|
+
--button-bg: transparent;
|
|
17
|
+
--button-bg-hover: var(--button-bg);
|
|
18
|
+
--button-bg-pressed: var(--button-bg-hover);
|
|
19
|
+
--button-fg: currentColor;
|
|
20
|
+
|
|
21
|
+
position: relative;
|
|
22
|
+
isolation: isolate;
|
|
23
|
+
display: inline-flex;
|
|
24
|
+
align-items: center;
|
|
25
|
+
justify-content: center;
|
|
26
|
+
gap: var(--xds-space-2);
|
|
27
|
+
width: fit-content;
|
|
28
|
+
height: var(--xds-size-control-md);
|
|
29
|
+
/* Never narrower than it is tall, and never smaller than the smallest pressable area. */
|
|
30
|
+
min-width: max(var(--xds-size-control-md), var(--xds-size-target-min));
|
|
31
|
+
padding-inline: var(--xds-space-4);
|
|
32
|
+
/* A rounded rectangle for a pointer, a capsule for fingers. */
|
|
33
|
+
border-radius: var(--xds-size-button-radius);
|
|
34
|
+
background-color: var(--button-bg);
|
|
35
|
+
color: var(--button-fg);
|
|
36
|
+
font-size: var(--xds-typography-label-size);
|
|
37
|
+
font-weight: var(--xds-typography-label-weight);
|
|
38
|
+
line-height: var(--xds-typography-label-line-height);
|
|
39
|
+
white-space: nowrap;
|
|
40
|
+
outline: none;
|
|
41
|
+
cursor: pointer;
|
|
42
|
+
user-select: none;
|
|
43
|
+
-webkit-tap-highlight-color: transparent;
|
|
44
|
+
transform-origin: center;
|
|
45
|
+
transition-property: background-color, border-color, color, transform;
|
|
46
|
+
transition-duration: var(--xds-motion-duration-fast);
|
|
47
|
+
transition-timing-function: var(--xds-motion-easing-standard);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/* Icons, and the spinner that stands in for one, are sized by their own classes. */
|
|
51
|
+
.{{prefix}}-button svg {
|
|
52
|
+
flex-shrink: 0;
|
|
53
|
+
align-self: center;
|
|
54
|
+
pointer-events: none;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
.{{prefix}}-button:active {
|
|
58
|
+
background-color: var(--button-bg-pressed);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/* A press shrinks the button a little: feedback that does not depend on color. */
|
|
62
|
+
.{{prefix}}-button:active:not(:disabled):not([data-pending]) {
|
|
63
|
+
transform: scale(var(--xds-motion-press-scale));
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
@media (prefers-reduced-motion: reduce) {
|
|
67
|
+
.{{prefix}}-button:active:not(:disabled):not([data-pending]) {
|
|
68
|
+
transform: none;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/* After the press and as specific: under a pointer a pressed button keeps its hover fill and
|
|
73
|
+
only shrinks; a finger, which does not hover, gets the pressed fill. */
|
|
74
|
+
@media (hover: hover) {
|
|
75
|
+
.{{prefix}}-button:hover {
|
|
76
|
+
background-color: var(--button-bg-hover);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/* ------------------------------------------------------------ sizes */
|
|
81
|
+
|
|
82
|
+
.{{prefix}}-button--sm {
|
|
83
|
+
height: var(--xds-size-control-sm);
|
|
84
|
+
min-width: max(var(--xds-size-control-sm), var(--xds-size-target-min));
|
|
85
|
+
padding-inline: var(--xds-space-3);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
.{{prefix}}-button--lg {
|
|
89
|
+
height: var(--xds-size-control-lg);
|
|
90
|
+
min-width: var(--xds-size-control-lg);
|
|
91
|
+
padding-inline: var(--xds-space-6);
|
|
92
|
+
font-size: var(--xds-typography-body-strong-size);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
.{{prefix}}-button--full-width {
|
|
96
|
+
width: 100%;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/* ------------------------------------------------------------ variants */
|
|
100
|
+
|
|
101
|
+
.{{prefix}}-button--primary {
|
|
102
|
+
--button-bg: var(--xds-color-button-primary-background);
|
|
103
|
+
--button-bg-hover: var(--xds-color-button-primary-background-hover);
|
|
104
|
+
--button-bg-pressed: var(--xds-color-button-primary-background-pressed);
|
|
105
|
+
--button-fg: var(--xds-color-button-primary-text);
|
|
106
|
+
/* The same trace of shadow as a secondary button, so the primary one never looks flatter. */
|
|
107
|
+
box-shadow: var(--xds-shadow-subtle);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
.{{prefix}}-button--secondary {
|
|
111
|
+
--button-bg: var(--xds-color-button-secondary-background);
|
|
112
|
+
--button-bg-hover: var(--xds-color-button-secondary-background-hover);
|
|
113
|
+
--button-bg-pressed: var(--xds-color-button-secondary-background-pressed);
|
|
114
|
+
--button-fg: var(--xds-color-button-secondary-text);
|
|
115
|
+
/* Outlined, with a trace of shadow, so it sits quietly beside a primary button. */
|
|
116
|
+
border: var(--xds-border-width-thin) solid var(--xds-color-button-secondary-border);
|
|
117
|
+
box-shadow: var(--xds-shadow-subtle);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
.{{prefix}}-button--ghost {
|
|
121
|
+
--button-bg: transparent;
|
|
122
|
+
--button-bg-hover: var(--xds-color-button-ghost-background-hover);
|
|
123
|
+
--button-bg-pressed: var(--xds-color-button-ghost-background-pressed);
|
|
124
|
+
--button-fg: var(--xds-color-button-ghost-text);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
.{{prefix}}-button--danger {
|
|
128
|
+
--button-bg: var(--xds-color-button-danger-background);
|
|
129
|
+
--button-bg-hover: var(--xds-color-button-danger-background-hover);
|
|
130
|
+
--button-bg-pressed: var(--xds-color-button-danger-background-pressed);
|
|
131
|
+
--button-fg: var(--xds-color-button-danger-text);
|
|
132
|
+
box-shadow: var(--xds-shadow-subtle);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/* ------------------------------------------------------------ toggles */
|
|
136
|
+
|
|
137
|
+
/* A ghost toggle has its outline before it is selected, transparent, so that selecting it
|
|
138
|
+
does not change its width. */
|
|
139
|
+
.{{prefix}}-button--ghost[aria-pressed] {
|
|
140
|
+
border: var(--xds-border-width-thin) solid transparent;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/* A toggle that is on. The outline, not only the tint, says so; primary and danger buttons
|
|
144
|
+
keep their look and only report the state. */
|
|
145
|
+
.{{prefix}}-button--secondary[aria-pressed="true"],
|
|
146
|
+
.{{prefix}}-button--ghost[aria-pressed="true"] {
|
|
147
|
+
--button-bg: var(--xds-color-button-selected-background);
|
|
148
|
+
--button-bg-hover: var(--xds-color-button-selected-background-hover);
|
|
149
|
+
--button-bg-pressed: var(--xds-color-button-selected-background-pressed);
|
|
150
|
+
--button-fg: var(--xds-color-button-selected-text);
|
|
151
|
+
border-color: var(--xds-color-button-selected-border);
|
|
152
|
+
/* Held down, so nothing lifts it off the page. */
|
|
153
|
+
box-shadow: none;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
/* ------------------------------------------------------------ disabled and loading */
|
|
157
|
+
|
|
158
|
+
/* Neither takes the pointer: a disabled button is not there to press, and a loading one has
|
|
159
|
+
already been pressed. */
|
|
160
|
+
.{{prefix}}-button:disabled,
|
|
161
|
+
.{{prefix}}-button[aria-disabled="true"] {
|
|
162
|
+
cursor: not-allowed;
|
|
163
|
+
pointer-events: none;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
/* A disabled button is recolored, not faded: fading a colored fill leaves a pale version of
|
|
167
|
+
the same color that still looks pressable. */
|
|
168
|
+
.{{prefix}}-button:disabled:not([data-pending]),
|
|
169
|
+
.{{prefix}}-button[aria-disabled="true"]:not([data-pending]) {
|
|
170
|
+
--button-bg: var(--xds-color-button-disabled-background);
|
|
171
|
+
--button-fg: var(--xds-color-button-disabled-text);
|
|
172
|
+
box-shadow: none;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
.{{prefix}}-button--secondary:disabled:not([data-pending]),
|
|
176
|
+
.{{prefix}}-button--secondary[aria-disabled="true"]:not([data-pending]) {
|
|
177
|
+
border-color: transparent;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
.{{prefix}}-button--ghost:disabled:not([data-pending]),
|
|
181
|
+
.{{prefix}}-button--ghost[aria-disabled="true"]:not([data-pending]) {
|
|
182
|
+
--button-bg: transparent;
|
|
183
|
+
border-color: transparent;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
/* While loading the label stays, so the button keeps its width, and so do the colors: the
|
|
187
|
+
action was accepted, which is the opposite of unavailable. */
|
|
188
|
+
.{{prefix}}-button[data-pending] {
|
|
189
|
+
cursor: progress;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
/* ------------------------------------------------------------ icon only */
|
|
193
|
+
|
|
194
|
+
/* A Button that holds only an icon is as wide as it is tall, which `min-width` already
|
|
195
|
+
ensures once the padding is gone. A small one is shorter than a finger needs, so its
|
|
196
|
+
height has the same floor as its width. */
|
|
197
|
+
.{{prefix}}-button.{{prefix}}-button--icon-only {
|
|
198
|
+
padding-inline: 0;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
.{{prefix}}-button.{{prefix}}-button--icon-only.{{prefix}}-button--sm {
|
|
202
|
+
height: max(var(--xds-size-control-sm), var(--xds-size-target-min));
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
/* IconButton: a square exactly as tall as a button of its size. Where that is smaller than
|
|
206
|
+
a finger needs, the pressable area grows around it and the square stays what it is. */
|
|
207
|
+
.{{prefix}}-button.{{prefix}}-icon-button {
|
|
208
|
+
width: var(--xds-size-control-md);
|
|
209
|
+
min-width: 0;
|
|
210
|
+
padding-inline: 0;
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
.{{prefix}}-button.{{prefix}}-icon-button.{{prefix}}-button--sm {
|
|
214
|
+
width: var(--xds-size-control-sm);
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
.{{prefix}}-button.{{prefix}}-icon-button.{{prefix}}-button--lg {
|
|
218
|
+
width: var(--xds-size-control-lg);
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
/* Centered with physical offsets, which need no mirroring in a right-to-left layout. */
|
|
222
|
+
.{{prefix}}-button.{{prefix}}-icon-button::after {
|
|
223
|
+
content: "";
|
|
224
|
+
position: absolute;
|
|
225
|
+
top: 50%;
|
|
226
|
+
left: 50%;
|
|
227
|
+
width: max(100%, var(--xds-size-target-min));
|
|
228
|
+
height: max(100%, var(--xds-size-target-min));
|
|
229
|
+
translate: -50% -50%;
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
/* ------------------------------------------------------------ focus */
|
|
233
|
+
|
|
234
|
+
/* A ring a gap away from the button, in the page's color, so it shows on any fill. It
|
|
235
|
+
replaces the shadow of the variant and of a selected toggle, so it comes last. */
|
|
236
|
+
.{{prefix}}-button:focus-visible {
|
|
237
|
+
box-shadow:
|
|
238
|
+
0 0 0 var(--xds-focus-offset) var(--xds-color-background-base),
|
|
239
|
+
0 0 0 calc(var(--xds-focus-width) + var(--xds-focus-offset)) var(--xds-color-border-focus);
|
|
240
|
+
}
|
|
241
|
+
}
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
// Ejected from `@xds/svelte` 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, IconSize } from "@xds/svelte/base";
|
|
5
|
+
|
|
6
|
+
export type ButtonVariant = "primary" | "secondary" | "ghost" | "danger";
|
|
7
|
+
export type ControlSize = "sm" | "md" | "lg";
|
|
8
|
+
|
|
9
|
+
/** Button's props in every framework, short of its label and its press handler. */
|
|
10
|
+
export type ButtonBaseProps = {
|
|
11
|
+
/**
|
|
12
|
+
* `primary` is the one action a view is for; use it once per view. `secondary` is any other
|
|
13
|
+
* action, `ghost` an action that should stay out of the way, `danger` one that destroys.
|
|
14
|
+
*/
|
|
15
|
+
variant?: ButtonVariant;
|
|
16
|
+
size?: ControlSize;
|
|
17
|
+
/** An icon in front of the label. */
|
|
18
|
+
iconStart?: IconName;
|
|
19
|
+
/** An icon after the label. */
|
|
20
|
+
iconEnd?: IconName;
|
|
21
|
+
/**
|
|
22
|
+
* Makes the button a toggle: given at all, its state is reported to assistive technology.
|
|
23
|
+
* While `true`, a `secondary` or a `ghost` button is drawn held down and its `iconStart` is
|
|
24
|
+
* filled. `primary` and `danger` keep their look and only report the state.
|
|
25
|
+
*/
|
|
26
|
+
selected?: boolean;
|
|
27
|
+
disabled?: boolean;
|
|
28
|
+
/**
|
|
29
|
+
* Shows a spinner and ignores presses. The label stays, and the spinner stands where
|
|
30
|
+
* `iconStart` was, so the button keeps its width.
|
|
31
|
+
*/
|
|
32
|
+
loading?: boolean;
|
|
33
|
+
fullWidth?: boolean;
|
|
34
|
+
type?: "button" | "submit" | "reset";
|
|
35
|
+
/** Names the button for assistive technology when it has no text, such as an icon button. */
|
|
36
|
+
"aria-label"?: string;
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
/** IconButton's props in every framework, short of its press handler. */
|
|
40
|
+
export type IconButtonBaseProps = {
|
|
41
|
+
icon: IconName;
|
|
42
|
+
/** The accessible name: there is no visible text. Say what pressing it does. */
|
|
43
|
+
label: string;
|
|
44
|
+
/** As Button's. Defaults to `ghost`, since an icon button usually stays out of the way. */
|
|
45
|
+
variant?: ButtonVariant;
|
|
46
|
+
size?: ControlSize;
|
|
47
|
+
/**
|
|
48
|
+
* Makes the button a toggle: given at all, its state is reported to assistive technology.
|
|
49
|
+
* While `true`, a `secondary` or a `ghost` button is drawn held down and its icon is filled.
|
|
50
|
+
*/
|
|
51
|
+
selected?: boolean;
|
|
52
|
+
disabled?: boolean;
|
|
53
|
+
/** Shows a spinner in the icon's place and ignores presses. */
|
|
54
|
+
loading?: boolean;
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* The classes of a Button, or of an IconButton with `iconButton`. Part of the look comes from
|
|
59
|
+
* attributes the button carries: `disabled`, `aria-pressed`, and `aria-disabled` with
|
|
60
|
+
* `data-pending` while loading.
|
|
61
|
+
*/
|
|
62
|
+
export function buttonClass(options: {
|
|
63
|
+
variant: ButtonVariant;
|
|
64
|
+
size: ControlSize;
|
|
65
|
+
/** A Button with icons and no label: as wide as it is tall. */
|
|
66
|
+
iconOnly?: boolean;
|
|
67
|
+
iconButton?: boolean;
|
|
68
|
+
fullWidth?: boolean;
|
|
69
|
+
}): string {
|
|
70
|
+
const { variant, size, iconOnly = false, iconButton = false, fullWidth = false } = options;
|
|
71
|
+
let classes = `{{prefix}}-button {{prefix}}-button--${variant} {{prefix}}-button--${size}`;
|
|
72
|
+
if (iconButton) classes += " {{prefix}}-icon-button";
|
|
73
|
+
else if (iconOnly) classes += " {{prefix}}-button--icon-only";
|
|
74
|
+
if (fullWidth) classes += " {{prefix}}-button--full-width";
|
|
75
|
+
return classes;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Only the two quiet variants change their look when selected, and a disabled button looks
|
|
80
|
+
* disabled whatever its state, so the filled icon follows the same conditions.
|
|
81
|
+
*/
|
|
82
|
+
export function isHeld(options: {
|
|
83
|
+
variant: ButtonVariant;
|
|
84
|
+
selected?: boolean | undefined;
|
|
85
|
+
disabled?: boolean | undefined;
|
|
86
|
+
}): boolean {
|
|
87
|
+
const { variant, selected, disabled } = options;
|
|
88
|
+
return selected === true && !disabled && (variant === "secondary" || variant === "ghost");
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* The icons of a Button. A large button has larger text, so its icons are a step larger too.
|
|
93
|
+
* The box is what a spinner is centered in while it stands in for an icon.
|
|
94
|
+
*/
|
|
95
|
+
export const BUTTON_ICON = {
|
|
96
|
+
sm: { size: "sm", box: "inline-flex shrink-0 items-center justify-center size-xds-icon-sm" },
|
|
97
|
+
md: { size: "sm", box: "inline-flex shrink-0 items-center justify-center size-xds-icon-sm" },
|
|
98
|
+
lg: { size: "md", box: "inline-flex shrink-0 items-center justify-center size-xds-icon-md" },
|
|
99
|
+
} as const satisfies Record<ControlSize, { size: IconSize; box: string }>;
|
|
100
|
+
|
|
101
|
+
/** The box a spinner is centered in while it stands in for an IconButton's icon. */
|
|
102
|
+
export const ICON_BUTTON_BOX = {
|
|
103
|
+
sm: "inline-flex shrink-0 items-center justify-center size-xds-icon-sm",
|
|
104
|
+
md: "inline-flex shrink-0 items-center justify-center size-xds-icon-md",
|
|
105
|
+
lg: "inline-flex shrink-0 items-center justify-center size-xds-icon-lg",
|
|
106
|
+
} as const satisfies Record<ControlSize, string>;
|