@xds/react 0.0.0-stage → 0.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/LICENSE +21 -0
- package/README.md +19 -2
- package/dist/Accordion.d.ts +20 -0
- package/dist/Accordion.js +197 -0
- package/dist/Avatar.d.ts +9 -0
- package/dist/Avatar.js +69 -0
- package/dist/AvatarStack.d.ts +8 -0
- package/dist/AvatarStack.js +105 -0
- package/dist/Badge.d.ts +13 -0
- package/dist/Badge.js +66 -0
- package/dist/Banner.d.ts +23 -0
- package/dist/Banner.js +166 -0
- package/dist/Button.d.ts +14 -0
- package/dist/Button.js +159 -0
- package/dist/Card.d.ts +18 -0
- package/dist/Card.js +173 -0
- package/dist/Checkbox.d.ts +10 -0
- package/dist/Checkbox.js +140 -0
- package/dist/Chip.d.ts +12 -0
- package/dist/Chip.js +74 -0
- package/dist/ChipBar.d.ts +12 -0
- package/dist/ChipBar.js +38 -0
- package/dist/CountBadge.d.ts +12 -0
- package/dist/CountBadge.js +64 -0
- package/dist/DatePicker.d.ts +20 -0
- package/dist/DatePicker.js +429 -0
- package/dist/DateRangePicker.d.ts +24 -0
- package/dist/DateRangePicker.js +370 -0
- package/dist/Defaults.d.ts +17 -0
- package/dist/Defaults.js +48 -0
- package/dist/Dialog.d.ts +20 -0
- package/dist/Dialog.js +137 -0
- package/dist/Divider.d.ts +4 -0
- package/dist/Divider.js +31 -0
- package/dist/EmptyState.d.ts +12 -0
- package/dist/EmptyState.js +86 -0
- package/dist/Icon.d.ts +9 -0
- package/dist/Icon.js +79 -0
- package/dist/IconButton.d.ts +12 -0
- package/dist/IconButton.js +119 -0
- package/dist/ListRow.d.ts +21 -0
- package/dist/ListRow.js +185 -0
- package/dist/MediaCard.d.ts +20 -0
- package/dist/MediaCard.js +279 -0
- package/dist/Menu.d.ts +18 -0
- package/dist/Menu.js +244 -0
- package/dist/ProgressBar.d.ts +8 -0
- package/dist/ProgressBar.js +65 -0
- package/dist/RadioGroup.d.ts +15 -0
- package/dist/RadioGroup.js +176 -0
- package/dist/SearchField.d.ts +15 -0
- package/dist/SearchField.js +152 -0
- package/dist/SectionHeader.d.ts +14 -0
- package/dist/SectionHeader.js +124 -0
- package/dist/SegmentedControl.d.ts +12 -0
- package/dist/SegmentedControl.js +106 -0
- package/dist/Select.d.ts +18 -0
- package/dist/Select.js +318 -0
- package/dist/Sidebar.d.ts +21 -0
- package/dist/Sidebar.js +220 -0
- package/dist/Skeleton.d.ts +11 -0
- package/dist/Skeleton.js +64 -0
- package/dist/Slider.d.ts +13 -0
- package/dist/Slider.js +151 -0
- package/dist/Spinner.d.ts +9 -0
- package/dist/Spinner.js +97 -0
- package/dist/Switch.d.ts +13 -0
- package/dist/Switch.js +116 -0
- package/dist/Tabs.d.ts +14 -0
- package/dist/Tabs.js +137 -0
- package/dist/Text.d.ts +10 -0
- package/dist/Text.js +46 -0
- package/dist/TextField.d.ts +22 -0
- package/dist/TextField.js +213 -0
- package/dist/Thumbnail.d.ts +9 -0
- package/dist/Thumbnail.js +152 -0
- package/dist/Toast.d.ts +14 -0
- package/dist/Toast.js +121 -0
- package/dist/Tooltip.d.ts +26 -0
- package/dist/Tooltip.js +166 -0
- package/dist/base.d.ts +11 -0
- package/dist/base.js +10 -0
- package/dist/index.d.ts +39 -0
- package/dist/index.js +39 -0
- package/dist/modal-popover.d.ts +7 -0
- package/dist/modal-popover.js +37 -0
- package/dist/picture.d.ts +13 -0
- package/dist/picture.js +76 -0
- package/dist/portal.d.ts +9 -0
- package/dist/portal.js +27 -0
- package/dist/presence.d.ts +6 -0
- package/dist/presence.js +34 -0
- package/dist/preview.d.ts +17 -0
- package/dist/preview.js +126 -0
- package/dist/root.d.ts +12 -0
- package/dist/root.js +1 -0
- package/dist/trigger.d.ts +24 -0
- package/dist/trigger.js +47 -0
- package/eject/files/Accordion.tsx +157 -0
- package/eject/files/Avatar.tsx +41 -0
- package/eject/files/AvatarStack.tsx +47 -0
- package/eject/files/Badge.tsx +33 -0
- package/eject/files/Banner.tsx +70 -0
- package/eject/files/Button.tsx +88 -0
- package/eject/files/Card.tsx +85 -0
- package/eject/files/Checkbox.tsx +59 -0
- package/eject/files/Chip.tsx +43 -0
- package/eject/files/ChipBar.tsx +31 -0
- package/eject/files/CountBadge.tsx +50 -0
- package/eject/files/DatePicker.tsx +192 -0
- package/eject/files/DateRangePicker.tsx +271 -0
- package/eject/files/Dialog.tsx +108 -0
- package/eject/files/Divider.tsx +13 -0
- package/eject/files/EmptyState.tsx +39 -0
- package/eject/files/Icon.tsx +38 -0
- package/eject/files/IconButton.tsx +62 -0
- package/eject/files/ListRow.tsx +86 -0
- package/eject/files/MediaCard.tsx +111 -0
- package/eject/files/Menu.tsx +168 -0
- package/eject/files/ProgressBar.tsx +34 -0
- package/eject/files/RadioGroup.tsx +112 -0
- package/eject/files/SearchField.tsx +88 -0
- package/eject/files/SectionHeader.tsx +56 -0
- package/eject/files/SegmentedControl.tsx +57 -0
- package/eject/files/Select.tsx +228 -0
- package/eject/files/Sidebar.tsx +149 -0
- package/eject/files/Skeleton.tsx +28 -0
- package/eject/files/Slider.tsx +109 -0
- package/eject/files/Spinner.tsx +36 -0
- package/eject/files/Switch.tsx +53 -0
- package/eject/files/Tabs.tsx +71 -0
- package/eject/files/Text.tsx +31 -0
- package/eject/files/TextField.tsx +122 -0
- package/eject/files/Thumbnail.tsx +66 -0
- package/eject/files/Toast.tsx +88 -0
- package/eject/files/Tooltip.tsx +120 -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 +68 -0
- package/eject/files/base.css +38 -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 +32 -0
- package/eject/files/chip-bar.ts +16 -0
- package/eject/files/chip.ts +35 -0
- package/eject/files/count-badge.ts +32 -0
- package/eject/files/date-picker.css +352 -0
- package/eject/files/date-picker.ts +250 -0
- package/eject/files/date-range-picker.ts +323 -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/list-row.ts +66 -0
- package/eject/files/media-card.ts +66 -0
- package/eject/files/menu.css +176 -0
- package/eject/files/menu.ts +84 -0
- package/eject/files/parts.ts +17 -0
- package/eject/files/progress-bar.ts +23 -0
- package/eject/files/radio-group.css +160 -0
- package/eject/files/radio-group.ts +24 -0
- package/eject/files/section-header.ts +32 -0
- package/eject/files/segmented-control.ts +30 -0
- package/eject/files/select.css +285 -0
- package/eject/files/select.ts +36 -0
- package/eject/files/sidebar.ts +75 -0
- package/eject/files/skeleton.ts +51 -0
- package/eject/files/slider.css +136 -0
- package/eject/files/slider.ts +65 -0
- package/eject/files/spinner.ts +22 -0
- package/eject/files/switch.ts +34 -0
- package/eject/files/tabs.css +112 -0
- package/eject/files/tabs.ts +35 -0
- package/eject/files/text-field.css +229 -0
- package/eject/files/text-field.ts +48 -0
- package/eject/files/text.ts +38 -0
- package/eject/files/thumbnail.ts +51 -0
- package/eject/files/toast.ts +31 -0
- package/eject/files/tooltip.css +104 -0
- package/eject/files/tooltip.ts +21 -0
- package/eject/manifest.json +814 -0
- package/package.json +66 -4
- package/page.css +20 -0
- package/styles.css +3252 -0
- package/tailwind.css +2665 -0
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
// Ejected from `@xds/react` 0.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
|
+
motion,
|
|
6
|
+
Portal,
|
|
7
|
+
type RootProps,
|
|
8
|
+
space,
|
|
9
|
+
TriggerContext,
|
|
10
|
+
usePresence,
|
|
11
|
+
useProvideTrigger,
|
|
12
|
+
} from "@xds/react/base";
|
|
13
|
+
import { mergeProps, normalizeProps, useMachine } from "@zag-js/react";
|
|
14
|
+
import * as tooltip from "@zag-js/tooltip";
|
|
15
|
+
import { type ReactNode, useId, useRef } from "react";
|
|
16
|
+
import { classes } from "./parts.ts";
|
|
17
|
+
import { type TooltipBaseProps, tooltipEndSide } from "./tooltip.ts";
|
|
18
|
+
|
|
19
|
+
/** `className` and `style` are for the tooltip, not for the control it describes. */
|
|
20
|
+
export type TooltipProps = TooltipBaseProps &
|
|
21
|
+
RootProps & {
|
|
22
|
+
/** The control it describes: a Button or an IconButton. */
|
|
23
|
+
children: ReactNode;
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Names a control when the pointer rests on it or the keyboard focuses it. It appears after a
|
|
28
|
+
* short wait under a pointer and at once on keyboard focus, and goes when the pointer leaves,
|
|
29
|
+
* focus leaves, or Escape is pressed.
|
|
30
|
+
*
|
|
31
|
+
* It describes the control and is not its name: an IconButton still needs its `label`. It
|
|
32
|
+
* never holds anything pressable, and touch input has no hover, so nothing may depend on it.
|
|
33
|
+
*/
|
|
34
|
+
export function Tooltip({
|
|
35
|
+
label,
|
|
36
|
+
shortcut,
|
|
37
|
+
placement = "top",
|
|
38
|
+
className,
|
|
39
|
+
style,
|
|
40
|
+
children,
|
|
41
|
+
}: TooltipProps) {
|
|
42
|
+
return (
|
|
43
|
+
<Overlay
|
|
44
|
+
label={label}
|
|
45
|
+
shortcut={shortcut}
|
|
46
|
+
placement={placement}
|
|
47
|
+
className={className}
|
|
48
|
+
style={style}
|
|
49
|
+
>
|
|
50
|
+
{children}
|
|
51
|
+
</Overlay>
|
|
52
|
+
);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* A Tooltip at the end edge of its control instead of above or below it: a collapsed Sidebar
|
|
57
|
+
* names its icons on the side of the content, where they do not cover their neighbours. Only
|
|
58
|
+
* for this package's own components: the index does not export it.
|
|
59
|
+
*/
|
|
60
|
+
export function TooltipBeside({ label, children }: { label: string; children: ReactNode }) {
|
|
61
|
+
return (
|
|
62
|
+
<Overlay label={label} placement={tooltipEndSide()}>
|
|
63
|
+
{children}
|
|
64
|
+
</Overlay>
|
|
65
|
+
);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
function Overlay({
|
|
69
|
+
label,
|
|
70
|
+
shortcut,
|
|
71
|
+
placement,
|
|
72
|
+
className,
|
|
73
|
+
style,
|
|
74
|
+
children,
|
|
75
|
+
}: RootProps & {
|
|
76
|
+
label: string;
|
|
77
|
+
shortcut?: string | undefined;
|
|
78
|
+
placement: tooltip.Placement;
|
|
79
|
+
children: ReactNode;
|
|
80
|
+
}) {
|
|
81
|
+
const service = useMachine(tooltip.machine, {
|
|
82
|
+
id: useId(),
|
|
83
|
+
openDelay: motion.duration.tooltipDelay,
|
|
84
|
+
closeDelay: 0,
|
|
85
|
+
// It stays and follows its control when the page scrolls, for as long as the control keeps
|
|
86
|
+
// focus or the pointer. Tabbing to a control out of view scrolls the page, and a tooltip
|
|
87
|
+
// closed by that scroll would never show for it.
|
|
88
|
+
closeOnScroll: false,
|
|
89
|
+
positioning: { placement, gutter: space[1] },
|
|
90
|
+
});
|
|
91
|
+
const api = tooltip.connect(service, normalizeProps);
|
|
92
|
+
const trigger = useProvideTrigger(api.getTriggerProps());
|
|
93
|
+
const content = useRef<HTMLDivElement>(null);
|
|
94
|
+
const present = usePresence(api.open, () => [content.current]);
|
|
95
|
+
return (
|
|
96
|
+
<>
|
|
97
|
+
<TriggerContext value={trigger}>{children}</TriggerContext>
|
|
98
|
+
{present && (
|
|
99
|
+
<Portal>
|
|
100
|
+
<TriggerContext value={null}>
|
|
101
|
+
<div {...api.getPositionerProps()} className="{{prefix}}-tooltip__positioner">
|
|
102
|
+
{/* Shown until its exit animation ends; Zag would hide it as it closes. */}
|
|
103
|
+
<div
|
|
104
|
+
{...mergeProps(api.getContentProps(), {
|
|
105
|
+
className: classes("{{prefix}}-tooltip", className),
|
|
106
|
+
style,
|
|
107
|
+
})}
|
|
108
|
+
ref={content}
|
|
109
|
+
hidden={false}
|
|
110
|
+
>
|
|
111
|
+
{label}
|
|
112
|
+
{shortcut && <kbd className="{{prefix}}-tooltip__shortcut">{shortcut}</kbd>}
|
|
113
|
+
</div>
|
|
114
|
+
</div>
|
|
115
|
+
</TriggerContext>
|
|
116
|
+
</Portal>
|
|
117
|
+
)}
|
|
118
|
+
</>
|
|
119
|
+
);
|
|
120
|
+
}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Ejected from `@xds/react` 0.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
|
+
* Accordion: Zag's accordion machine.
|
|
7
|
+
*
|
|
8
|
+
* Parts: `.{{prefix}}-accordion`, `.{{prefix}}-accordion__item`, `.{{prefix}}-accordion__heading` (the h3),
|
|
9
|
+
* `.{{prefix}}-accordion__trigger` (the button; also a Tailwind `group` for the chevron),
|
|
10
|
+
* `.{{prefix}}-accordion__panel` (the body's box, whose height moves) and `.{{prefix}}-accordion__body`.
|
|
11
|
+
* States: `:hover`, `:active`, `:focus-visible` and `[aria-expanded]` on the trigger. The
|
|
12
|
+
* panel's height is `--accordion-panel-height`, which the component sets: a length while it
|
|
13
|
+
* moves, `auto` while open and `0px` while closed.
|
|
14
|
+
*/
|
|
15
|
+
@layer components {
|
|
16
|
+
/* A hairline above the first item and one under every item, the last included. */
|
|
17
|
+
.{{prefix}}-accordion {
|
|
18
|
+
width: 100%;
|
|
19
|
+
border-top: var(--xds-border-width-thin) solid var(--xds-color-accordion-border);
|
|
20
|
+
contain: layout style;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
.{{prefix}}-accordion__item {
|
|
24
|
+
position: relative;
|
|
25
|
+
border-style: none;
|
|
26
|
+
border-bottom: var(--xds-border-width-thin) solid var(--xds-color-accordion-border);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
.{{prefix}}-accordion__heading {
|
|
30
|
+
display: flex;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
.{{prefix}}-accordion__trigger {
|
|
34
|
+
display: flex;
|
|
35
|
+
flex: 1;
|
|
36
|
+
align-items: center;
|
|
37
|
+
justify-content: space-between;
|
|
38
|
+
gap: var(--xds-space-3);
|
|
39
|
+
min-height: var(--xds-size-list-row);
|
|
40
|
+
padding: var(--xds-space-2) var(--xds-space-4);
|
|
41
|
+
font-size: var(--xds-typography-label-size);
|
|
42
|
+
font-weight: var(--xds-typography-label-weight);
|
|
43
|
+
line-height: var(--xds-typography-label-line-height);
|
|
44
|
+
text-align: start;
|
|
45
|
+
cursor: pointer;
|
|
46
|
+
touch-action: manipulation;
|
|
47
|
+
-webkit-tap-highlight-color: transparent;
|
|
48
|
+
transition: background-color var(--xds-motion-duration-fast) var(--xds-motion-easing-standard);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/* Open or closed, the row takes its own fills under the pointer and while pressed. */
|
|
52
|
+
@media (hover: hover) {
|
|
53
|
+
.{{prefix}}-accordion__trigger:hover {
|
|
54
|
+
background: var(--xds-color-accordion-header-background-hover);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/* A press that drags does not select the title. */
|
|
59
|
+
.{{prefix}}-accordion__trigger:active {
|
|
60
|
+
background: var(--xds-color-accordion-header-background-pressed);
|
|
61
|
+
user-select: none;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/* Inside the row, so the hairlines next to it do not cut through the ring. */
|
|
65
|
+
.{{prefix}}-accordion__trigger:focus-visible {
|
|
66
|
+
outline: var(--xds-focus-width) solid var(--xds-color-border-focus);
|
|
67
|
+
outline-offset: calc(-1 * var(--xds-focus-offset));
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/* Only the height moves. */
|
|
71
|
+
.{{prefix}}-accordion__panel {
|
|
72
|
+
height: var(--accordion-panel-height, auto);
|
|
73
|
+
overflow: clip;
|
|
74
|
+
transition: height var(--xds-motion-duration-normal) var(--xds-motion-easing-standard);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
@media (prefers-reduced-motion: reduce) {
|
|
78
|
+
.{{prefix}}-accordion__panel {
|
|
79
|
+
transition: none;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
.{{prefix}}-accordion__body {
|
|
84
|
+
padding: 0 var(--xds-space-4) var(--xds-space-4);
|
|
85
|
+
font-size: var(--xds-typography-body-size);
|
|
86
|
+
line-height: var(--xds-typography-body-line-height);
|
|
87
|
+
color: var(--xds-color-text-secondary);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
// Ejected from `@xds/react` 0.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 { afterAnimations, focusWithoutRing } from "@xds/react/base";
|
|
5
|
+
|
|
6
|
+
/** An item of an Accordion in every framework, short of its body. */
|
|
7
|
+
export type AccordionItemBase<Value extends string = string> = {
|
|
8
|
+
value: Value;
|
|
9
|
+
title: string;
|
|
10
|
+
/** A line under the title, shown whether the item is open or not. */
|
|
11
|
+
description?: string;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
/** Accordion's props in every framework, short of its items and `onChange`. */
|
|
15
|
+
export type AccordionBaseProps<Value extends string = string> = {
|
|
16
|
+
/** The values of the open items. */
|
|
17
|
+
expanded: readonly Value[];
|
|
18
|
+
/** Lets several items be open at once. Without it, opening one closes the others. */
|
|
19
|
+
multiple?: boolean;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
export const ACCORDION_PARTS = {
|
|
23
|
+
/** The title and the description, beside the chevron. */
|
|
24
|
+
text: "flex min-w-0 flex-1 flex-col gap-0.5",
|
|
25
|
+
title: "text-xds-body-strong text-xds-text-primary",
|
|
26
|
+
description: "text-xds-detail text-xds-text-secondary",
|
|
27
|
+
// The trigger is a `group`; the chevron turns over while it is expanded.
|
|
28
|
+
chevron:
|
|
29
|
+
"text-xds-accordion-icon transition-transform duration-(--xds-motion-duration-normal) ease-(--xds-motion-easing-standard) group-aria-expanded:rotate-180 motion-reduce:transition-none",
|
|
30
|
+
} as const;
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Opens or closes an item's panel (`.{{prefix}}-accordion__panel`): its height moves between zero and the
|
|
34
|
+
* height of what it holds, and it is hidden only once it has finished closing, with
|
|
35
|
+
* `hidden="until-found"`, so the browser's find in page still opens it. Call it on every change
|
|
36
|
+
* of `open`, with `animate` false the first time, when there is nothing to move from. Returns
|
|
37
|
+
* the function that stops the change from settling: call it before the next change, which
|
|
38
|
+
* takes over.
|
|
39
|
+
*/
|
|
40
|
+
export function setPanelOpen(panel: HTMLElement, open: boolean, animate: boolean): () => void {
|
|
41
|
+
const height = (value: string) => panel.style.setProperty("--accordion-panel-height", value);
|
|
42
|
+
if (!animate) {
|
|
43
|
+
if (open) panel.removeAttribute("hidden");
|
|
44
|
+
else panel.setAttribute("hidden", "until-found");
|
|
45
|
+
height(open ? "auto" : "0px");
|
|
46
|
+
return () => {};
|
|
47
|
+
}
|
|
48
|
+
if (open) {
|
|
49
|
+
panel.removeAttribute("hidden");
|
|
50
|
+
height(`${panel.scrollHeight}px`);
|
|
51
|
+
return afterAnimations([panel], () => height("auto"));
|
|
52
|
+
}
|
|
53
|
+
height(`${panel.scrollHeight}px`);
|
|
54
|
+
// Computes the style now, so the change to zero starts a transition.
|
|
55
|
+
void getComputedStyle(panel).height;
|
|
56
|
+
height("0px");
|
|
57
|
+
return afterAnimations([panel], () => panel.setAttribute("hidden", "until-found"));
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* For a click on an item's title, ahead of Zag's handler. Zag toggles the item only while its
|
|
62
|
+
* title has the focus, which a press gives it but a click from a script or from assistive
|
|
63
|
+
* technology does not. Focused here first, the title takes those clicks too.
|
|
64
|
+
*/
|
|
65
|
+
export function focusTitleOnClick(event: { currentTarget: EventTarget | null }): void {
|
|
66
|
+
if (event.currentTarget instanceof HTMLElement) focusWithoutRing(event.currentTarget);
|
|
67
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
// Ejected from `@xds/react` 0.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/react/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/react` 0.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/react/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/react` 0.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/react/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,68 @@
|
|
|
1
|
+
// Ejected from `@xds/react` 0.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
|
+
/** Names the close control for assistive technology. */
|
|
38
|
+
dismissLabel?: string;
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
export function bannerClass(tone: BannerTone = "info"): string {
|
|
42
|
+
return `flex items-start gap-3 rounded-xds-md p-3 text-xds-banner-text ${TONE[tone].surface}`;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/** The class of the tone's icon, a 24 by 24 drawing of `bannerIconPath(tone)`. */
|
|
46
|
+
export function bannerIconClass(tone: BannerTone = "info"): string {
|
|
47
|
+
return `mt-0.5 size-xds-icon-md shrink-0 ${TONE[tone].accent}`;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/** Each tone has its own icon shape, so the tone does not depend on color. */
|
|
51
|
+
export function bannerIconPath(tone: BannerTone = "info"): string {
|
|
52
|
+
return TONE[tone].icon;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/** Problems interrupt a screen reader; `info` and `success` wait their turn. */
|
|
56
|
+
export function bannerRole(tone: BannerTone = "info"): "alert" | "status" {
|
|
57
|
+
return tone === "danger" || tone === "warning" ? "alert" : "status";
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export const BANNER_PARTS = {
|
|
61
|
+
/** The title, the message and the action, beside the icon. */
|
|
62
|
+
body: "flex min-w-0 flex-1 flex-col gap-0.5 text-xds-detail",
|
|
63
|
+
title: "text-xds-label",
|
|
64
|
+
action: "mt-2",
|
|
65
|
+
// Pulled into the padding, so the cross lines up with the first line of text and a
|
|
66
|
+
// pointer-sized close control does not make a one-line banner taller.
|
|
67
|
+
dismiss: "-m-1 flex shrink-0",
|
|
68
|
+
} as const;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Ejected from `@xds/react` 0.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
|
+
}
|