@xds/react 0.1.0 → 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/dist/Accordion.js +191 -33
- package/dist/Avatar.js +65 -6
- package/dist/AvatarStack.js +101 -6
- package/dist/Badge.js +61 -4
- package/dist/Banner.js +161 -5
- package/dist/Button.js +152 -24
- package/dist/Card.js +171 -12
- package/dist/Checkbox.js +138 -3
- package/dist/Chip.js +71 -4
- package/dist/ChipBar.js +36 -3
- package/dist/CountBadge.js +62 -9
- package/dist/DatePicker.js +421 -25
- package/dist/DateRangePicker.js +362 -40
- package/dist/Defaults.js +42 -7
- package/dist/Dialog.js +128 -24
- package/dist/Divider.js +29 -3
- package/dist/EmptyState.js +83 -3
- package/dist/Icon.js +74 -4
- package/dist/IconButton.js +113 -18
- package/dist/ListRow.js +180 -10
- package/dist/MediaCard.js +273 -11
- package/dist/Menu.js +234 -58
- package/dist/ProgressBar.js +63 -4
- package/dist/RadioGroup.js +173 -12
- package/dist/SearchField.js +148 -16
- package/dist/SectionHeader.js +121 -5
- package/dist/SegmentedControl.js +104 -5
- package/dist/Select.js +307 -55
- package/dist/Sidebar.js +212 -19
- package/dist/Skeleton.js +61 -5
- package/dist/Slider.js +142 -35
- package/dist/Spinner.js +93 -4
- package/dist/Switch.js +114 -3
- package/dist/Tabs.js +130 -14
- package/dist/Text.js +42 -4
- package/dist/TextField.js +209 -26
- package/dist/Thumbnail.js +146 -7
- package/dist/Toast.js +118 -30
- package/dist/Tooltip.js +154 -20
- package/dist/base.d.ts +11 -0
- package/dist/base.js +10 -0
- package/dist/modal-popover.js +32 -10
- package/dist/picture.d.ts +6 -4
- package/dist/picture.js +72 -17
- package/dist/portal.js +24 -4
- package/dist/presence.js +30 -9
- package/dist/preview.d.ts +14 -3
- package/dist/preview.js +118 -74
- package/dist/root.js +1 -0
- package/dist/trigger.d.ts +7 -0
- package/dist/trigger.js +41 -8
- 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 +9 -4
|
@@ -0,0 +1,241 @@
|
|
|
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
|
+
* 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) {
|
|
63
|
+
transform: scale(var(--xds-motion-press-scale));
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
@media (prefers-reduced-motion: reduce) {
|
|
67
|
+
.{{prefix}}-button:active:not(:disabled) {
|
|
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/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, IconSize } from "@xds/react/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>;
|
|
@@ -0,0 +1,58 @@
|
|
|
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
|
+
/** Card's props in every framework, short of `onPress`, its content, `actions` and `media`. */
|
|
5
|
+
export type CardBaseProps = {
|
|
6
|
+
title?: string;
|
|
7
|
+
description?: string;
|
|
8
|
+
/** No padding and no gaps: for a card that holds a list, whose rows run edge to edge. */
|
|
9
|
+
flush?: boolean;
|
|
10
|
+
/**
|
|
11
|
+
* Outlines the card as the current choice. Given at all on a pressable card, it also makes
|
|
12
|
+
* the card a toggle that reports its state to assistive technology.
|
|
13
|
+
*/
|
|
14
|
+
selected?: boolean;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
// The selected outline is thicker than the hairline, so the state does not depend on its
|
|
18
|
+
// color. It is a layer over the hairline and over the content: a thicker border would move the
|
|
19
|
+
// content, an outline is what the focus ring uses, and anything under the content would be
|
|
20
|
+
// covered by `media`.
|
|
21
|
+
const SELECTED =
|
|
22
|
+
"border-xds-card-border-selected after:pointer-events-none after:absolute after:-inset-(--xds-border-width-thin) after:rounded-xds-lg after:border-(length:--xds-border-width-thick) after:border-xds-card-border-selected";
|
|
23
|
+
|
|
24
|
+
// What runs to the edges is clipped to the inside of the hairline. The card itself clips
|
|
25
|
+
// nothing, or it would cut off the selected outline and the focus rings of what it holds.
|
|
26
|
+
const CLIP = "overflow-hidden rounded-[calc(var(--xds-radius-lg)-var(--xds-border-width-thin))]";
|
|
27
|
+
const CLIP_TOP =
|
|
28
|
+
"overflow-hidden rounded-t-[calc(var(--xds-radius-lg)-var(--xds-border-width-thin))]";
|
|
29
|
+
|
|
30
|
+
// A button is only as wide as its content unless told otherwise; a card fills its place.
|
|
31
|
+
const PRESSABLE =
|
|
32
|
+
"w-full cursor-pointer text-start transition-colors duration-(--xds-motion-duration-fast) hover:bg-xds-card-background-hover active:bg-xds-card-background-pressed focus-visible:outline-solid focus-visible:outline-(length:--xds-focus-width) focus-visible:outline-offset-(--xds-focus-offset) focus-visible:outline-xds-border-focus";
|
|
33
|
+
|
|
34
|
+
/** The surface: a `section`, or a `button` with `pressable`. */
|
|
35
|
+
export function cardClass(options: {
|
|
36
|
+
selected?: boolean | undefined;
|
|
37
|
+
flush?: boolean | undefined;
|
|
38
|
+
pressable?: boolean | undefined;
|
|
39
|
+
}): string {
|
|
40
|
+
const { selected = false, flush = false, pressable = false } = options;
|
|
41
|
+
const surface = `relative flex flex-col rounded-xds-lg border bg-xds-background-surface shadow-xds-subtle ${selected ? SELECTED : "border-xds-border-default"}${flush ? "" : " gap-4 p-4"}`;
|
|
42
|
+
return pressable ? `${PRESSABLE} ${surface}` : surface;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/** The box of `media`, pulled out through the padding to the edges. */
|
|
46
|
+
export function cardMediaClass(flush = false): string {
|
|
47
|
+
return flush ? `flex flex-col ${CLIP_TOP}` : `flex flex-col ${CLIP_TOP} -mx-4 -mt-4`;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export const CARD_PARTS = {
|
|
51
|
+
/** Around everything in a `flush` card. */
|
|
52
|
+
flush: `flex flex-1 flex-col ${CLIP}`,
|
|
53
|
+
header: "flex items-start justify-between gap-3",
|
|
54
|
+
heading: "flex min-w-0 flex-col gap-0.5",
|
|
55
|
+
title: "text-xds-heading text-xds-text-primary",
|
|
56
|
+
description: "text-xds-detail text-xds-text-secondary",
|
|
57
|
+
actions: "flex shrink-0 items-center gap-2",
|
|
58
|
+
} as const;
|
|
@@ -0,0 +1,32 @@
|
|
|
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 { PEER_FOCUS } from "@xds/react/base";
|
|
5
|
+
|
|
6
|
+
export {
|
|
7
|
+
switchClass as checkboxClass,
|
|
8
|
+
switchLabelClass as checkboxLabelClass,
|
|
9
|
+
} from "@xds/react/base";
|
|
10
|
+
|
|
11
|
+
/** Checkbox's props in every framework, short of `onChange`. */
|
|
12
|
+
export type CheckboxBaseProps = {
|
|
13
|
+
checked: boolean;
|
|
14
|
+
/** Shown beside the box. Pressing it toggles too. */
|
|
15
|
+
label?: string;
|
|
16
|
+
/** Names the checkbox for assistive technology when there is no visible label. */
|
|
17
|
+
"aria-label"?: string;
|
|
18
|
+
name?: string;
|
|
19
|
+
disabled?: boolean;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* The box, drawn beside the hidden input. The outline is what makes an empty box visible; a
|
|
24
|
+
* filled one does not need it.
|
|
25
|
+
*/
|
|
26
|
+
export const checkboxBoxClass = `flex size-xds-checkbox shrink-0 items-center justify-center rounded-xds-sm border-2 border-xds-checkbox-border text-xds-checkbox-mark peer-checked:border-0 peer-checked:bg-xds-checkbox-background-checked peer-disabled:border-0 peer-disabled:bg-xds-checkbox-disabled-background peer-disabled:text-xds-checkbox-disabled-mark *:opacity-0 peer-checked:*:opacity-100 ${PEER_FOCUS}`;
|
|
27
|
+
|
|
28
|
+
/** The check mark inside the box: a 16 by 16 path, `CHECKBOX_MARK`. */
|
|
29
|
+
export const checkboxMarkClass = "size-3/4";
|
|
30
|
+
|
|
31
|
+
/** The path of the check mark, in a `0 0 16 16` view box. */
|
|
32
|
+
export const CHECKBOX_MARK = "m3.5 8.5 3 3 6-7";
|
|
@@ -0,0 +1,16 @@
|
|
|
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
|
+
/** ChipBar's props in every framework, short of the chips. */
|
|
5
|
+
export type ChipBarBaseProps = {
|
|
6
|
+
/** Says what the chips filter, for assistive technology. */
|
|
7
|
+
label: string;
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* The scrolling row. It is as tall as the chips' pressable area, which would otherwise be cut
|
|
12
|
+
* off by the scrolling box. The padding leaves room for a focus ring for the same reason, and
|
|
13
|
+
* the margin takes that room back so the first chip lines up with the content around the bar.
|
|
14
|
+
*/
|
|
15
|
+
export const chipBarClass =
|
|
16
|
+
"-m-1 flex min-h-[calc(var(--xds-size-target-min)+var(--xds-space-2))] items-center gap-2 overflow-x-auto p-1 [scrollbar-width:none] [&::-webkit-scrollbar]:hidden";
|
|
@@ -0,0 +1,35 @@
|
|
|
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
|
+
/** Chip's props in every framework, short of `onPress`. */
|
|
7
|
+
export type ChipBaseProps = {
|
|
8
|
+
label: string;
|
|
9
|
+
/** Whether the chip's filter is on. The app holds this state. */
|
|
10
|
+
selected?: boolean;
|
|
11
|
+
/** An icon in front of the label. A selected chip shows a check mark in its place. */
|
|
12
|
+
iconStart?: IconName;
|
|
13
|
+
disabled?: boolean;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* The classes of a Chip, a native toggle button. The border is there on every chip,
|
|
18
|
+
* transparent until selected, so selecting does not change the size. The `before` box is the
|
|
19
|
+
* pressable area, which is taller than the chip where fingers need it to be.
|
|
20
|
+
*/
|
|
21
|
+
export function chipClass(selected = false): string {
|
|
22
|
+
return `relative inline-flex h-xds-chip shrink-0 cursor-pointer items-center gap-1.5 whitespace-nowrap rounded-xds-full border px-3 text-xds-label transition-colors duration-(--xds-motion-duration-fast) before:absolute before:inset-x-0 before:top-1/2 before:h-[max(100%,var(--xds-size-target-min))] before:-translate-y-1/2 focus-visible:outline-solid focus-visible:outline-(length:--xds-focus-width) focus-visible:outline-offset-(--xds-focus-offset) focus-visible:outline-xds-border-focus disabled:cursor-not-allowed disabled:border-transparent disabled:bg-xds-chip-disabled-background disabled:text-xds-chip-disabled-text ${
|
|
23
|
+
selected
|
|
24
|
+
? "border-xds-chip-selected-border bg-xds-chip-selected-background text-xds-chip-selected-text enabled:hover:bg-xds-chip-selected-background-hover enabled:active:bg-xds-chip-selected-background-pressed"
|
|
25
|
+
: "border-transparent bg-xds-chip-background text-xds-chip-text enabled:hover:bg-xds-chip-background-hover enabled:active:bg-xds-chip-background-pressed"
|
|
26
|
+
}`;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/** The icon in front of the label: a check while selected, so the state is not color alone. */
|
|
30
|
+
export function chipIcon(options: {
|
|
31
|
+
selected?: boolean | undefined;
|
|
32
|
+
iconStart?: IconName | undefined;
|
|
33
|
+
}): IconName | undefined {
|
|
34
|
+
return options.selected ? "check" : options.iconStart;
|
|
35
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
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
|
+
/** CountBadge's props in every framework, short of the child it sits on. */
|
|
5
|
+
export type CountBadgeBaseProps = {
|
|
6
|
+
/** Zero or less draws no badge. */
|
|
7
|
+
count: number;
|
|
8
|
+
/** The largest number shown. A larger count reads "99+". */
|
|
9
|
+
max?: number;
|
|
10
|
+
/**
|
|
11
|
+
* Says what is counted, such as "3 unread notifications". Without it assistive technology
|
|
12
|
+
* reads the number alone.
|
|
13
|
+
*/
|
|
14
|
+
label?: string;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
/** The badge, laid out inline or, with `onChild`, on the top end corner of a child. */
|
|
18
|
+
export function countBadgeClass(onChild: boolean): string {
|
|
19
|
+
// Pushed out from the corner by a quarter of its own height, so it overlaps the corner
|
|
20
|
+
// instead of covering the child. `end` follows the layout direction.
|
|
21
|
+
return onChild
|
|
22
|
+
? "absolute end-[calc(var(--xds-size-count-badge)/-4)] top-[calc(var(--xds-size-count-badge)/-4)] inline-flex h-xds-count-badge min-w-xds-count-badge shrink-0 select-none items-center justify-center whitespace-nowrap rounded-full bg-xds-badge-count-background px-1 text-xds-badge-count-text text-xds-footnote"
|
|
23
|
+
: "inline-flex h-xds-count-badge min-w-xds-count-badge shrink-0 select-none items-center justify-center whitespace-nowrap rounded-full bg-xds-badge-count-background px-1 text-xds-badge-count-text text-xds-footnote";
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/** The box around a child that a badge sits on. */
|
|
27
|
+
export const countBadgeAnchorClass = "relative inline-flex w-fit shrink-0";
|
|
28
|
+
|
|
29
|
+
/** What the badge reads: the count, or "99+" past `max`. */
|
|
30
|
+
export function countBadgeText(count: number, max = 99): string {
|
|
31
|
+
return count > max ? `${max}+` : String(count);
|
|
32
|
+
}
|