@xds/react 0.1.0 → 1.0.0-rc.1
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,352 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Ejected from `@xds/react` 1.0.0-rc.1 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
|
+
* DatePicker: Zag's date-picker machine. Its field is a Select's, drawn by select.css; this
|
|
7
|
+
* draws the calendar, which is rendered into the body, always, hidden while closed once it has
|
|
8
|
+
* animated out.
|
|
9
|
+
*
|
|
10
|
+
* Parts: `.{{prefix}}-date-picker__underlay` (over the page while the calendar is open),
|
|
11
|
+
* `__positioner`, `__content` (the surface, a dialog), `__header`, `__nav` (the two month
|
|
12
|
+
* buttons, which button.css draws as small ghost IconButtons: DATE_PICKER_NAV_CLASS gives them
|
|
13
|
+
* both classes), `__heading` (the month and year), `__grid` (a table), `__weekday` (a column
|
|
14
|
+
* header), `__cell` (a grid cell), `__day` (the day in it, a button).
|
|
15
|
+
* States on a day: `:hover`, `:active`, `:focus-visible`, `[data-selected]`, `[data-today]`,
|
|
16
|
+
* `[data-disabled]` (outside `min`..`max`), `[data-outside-range]` (a day of the month before
|
|
17
|
+
* or after). On the content: `[data-side]`, and `[data-state="closed"]` while it animates out.
|
|
18
|
+
* The positioner stacks by `--xds-layer-overlay` and Zag's `--layer-index`.
|
|
19
|
+
*
|
|
20
|
+
* DateRangePicker draws the same calendar under `.{{prefix}}-date-range-picker` (its root, beside
|
|
21
|
+
* `.{{prefix}}-date-picker`) and `.{{prefix}}-date-range-picker__content`, with more parts: `__summary` (the two ends
|
|
22
|
+
* named), `__months` (the months side by side), `__month` (one month: its header and its grid),
|
|
23
|
+
* and `__nav-space` (where the other month has a month button). States on a day, from Zag's
|
|
24
|
+
* range mode: `[data-in-range]` (in the range, or in the preview of one), `[data-range-start]`
|
|
25
|
+
* and `[data-range-end]` (the ends, which are `[data-selected]` too), and
|
|
26
|
+
* `[data-hover-range-start]` and `[data-hover-range-end]` (the ends of the preview to the day
|
|
27
|
+
* under the pointer or the keyboard's focus while the end is chosen), and `[data-unavailable]`
|
|
28
|
+
* (a day the length rules out as the end, which is `[data-disabled]` too).
|
|
29
|
+
*/
|
|
30
|
+
@layer components {
|
|
31
|
+
/* Over the page and under the open calendar, as under a Select's list: a press outside only
|
|
32
|
+
closes the calendar, and the field under the pointer keeps its own border meanwhile. */
|
|
33
|
+
.{{prefix}}-date-picker__underlay {
|
|
34
|
+
position: fixed;
|
|
35
|
+
inset: 0;
|
|
36
|
+
z-index: var(--xds-layer-overlay);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
.{{prefix}}-date-picker__positioner {
|
|
40
|
+
z-index: calc(var(--xds-layer-overlay) + var(--layer-index, 0));
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/* A raised surface, as wide as seven days and its inset. */
|
|
44
|
+
.{{prefix}}-date-picker__content {
|
|
45
|
+
display: flex;
|
|
46
|
+
flex-direction: column;
|
|
47
|
+
gap: var(--xds-space-2);
|
|
48
|
+
width: max-content;
|
|
49
|
+
padding: var(--xds-space-3);
|
|
50
|
+
border: var(--xds-border-width-thin) solid var(--xds-color-border-default);
|
|
51
|
+
border-radius: var(--xds-radius-lg);
|
|
52
|
+
background: var(--xds-color-date-picker-background);
|
|
53
|
+
box-shadow: var(--xds-shadow-raised);
|
|
54
|
+
outline: none;
|
|
55
|
+
transform-origin: var(--transform-origin);
|
|
56
|
+
/* A Select's list's entrance, from select.css. */
|
|
57
|
+
animation: {{prefix}}-select-enter var(--xds-motion-duration-fast) var(--xds-motion-easing-enter);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
.{{prefix}}-date-picker__content[data-side="top"] {
|
|
61
|
+
animation-name: {{prefix}}-select-enter-above;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/* After the rules above, which it replaces. A closing calendar takes no more presses. */
|
|
65
|
+
.{{prefix}}-date-picker__content[data-state="closed"] {
|
|
66
|
+
animation: xds-overlay-exit var(--xds-motion-duration-fast) var(--xds-motion-easing-exit)
|
|
67
|
+
forwards;
|
|
68
|
+
pointer-events: none;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
@media (prefers-reduced-motion: reduce) {
|
|
72
|
+
.{{prefix}}-date-picker__content,
|
|
73
|
+
.{{prefix}}-date-picker__content[data-state="closed"] {
|
|
74
|
+
animation: none;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/* The month between its two buttons. */
|
|
79
|
+
.{{prefix}}-date-picker__header {
|
|
80
|
+
display: flex;
|
|
81
|
+
align-items: center;
|
|
82
|
+
gap: var(--xds-space-2);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
.{{prefix}}-date-picker__heading {
|
|
86
|
+
flex: 1 1 0%;
|
|
87
|
+
min-width: 0;
|
|
88
|
+
text-align: center;
|
|
89
|
+
font-size: var(--xds-typography-body-strong-size);
|
|
90
|
+
font-weight: var(--xds-typography-body-strong-weight);
|
|
91
|
+
line-height: var(--xds-typography-body-strong-line-height);
|
|
92
|
+
letter-spacing: var(--xds-typography-body-strong-letter-spacing);
|
|
93
|
+
color: var(--xds-color-date-picker-heading);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/* Seven columns of one day's side; the rows of days are as tall. */
|
|
97
|
+
.{{prefix}}-date-picker__grid {
|
|
98
|
+
border-collapse: collapse;
|
|
99
|
+
border-spacing: 0;
|
|
100
|
+
table-layout: fixed;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
.{{prefix}}-date-picker__weekday,
|
|
104
|
+
.{{prefix}}-date-picker__cell {
|
|
105
|
+
width: var(--xds-size-calendar-day);
|
|
106
|
+
height: var(--xds-size-calendar-day);
|
|
107
|
+
padding: 0;
|
|
108
|
+
text-align: center;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
.{{prefix}}-date-picker__weekday {
|
|
112
|
+
font-size: var(--xds-typography-footnote-size);
|
|
113
|
+
font-weight: var(--xds-typography-footnote-weight);
|
|
114
|
+
line-height: var(--xds-typography-footnote-line-height);
|
|
115
|
+
color: var(--xds-color-date-picker-weekday);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/* A circle inset a little into its cell, so that two marked days side by side stay apart. */
|
|
119
|
+
.{{prefix}}-date-picker__day {
|
|
120
|
+
display: flex;
|
|
121
|
+
align-items: center;
|
|
122
|
+
justify-content: center;
|
|
123
|
+
width: calc(var(--xds-size-calendar-day) - 2 * var(--xds-space-0-5));
|
|
124
|
+
height: calc(var(--xds-size-calendar-day) - 2 * var(--xds-space-0-5));
|
|
125
|
+
margin: var(--xds-space-0-5);
|
|
126
|
+
border-radius: var(--xds-radius-full);
|
|
127
|
+
font-size: var(--xds-typography-body-size);
|
|
128
|
+
font-weight: var(--xds-typography-body-weight);
|
|
129
|
+
line-height: var(--xds-typography-body-line-height);
|
|
130
|
+
font-variant-numeric: tabular-nums;
|
|
131
|
+
color: var(--xds-color-date-picker-day-text);
|
|
132
|
+
outline: none;
|
|
133
|
+
cursor: pointer;
|
|
134
|
+
user-select: none;
|
|
135
|
+
touch-action: manipulation;
|
|
136
|
+
-webkit-tap-highlight-color: transparent;
|
|
137
|
+
transition-property: background-color, color, box-shadow;
|
|
138
|
+
transition-duration: var(--xds-motion-duration-fast);
|
|
139
|
+
transition-timing-function: var(--xds-motion-easing-standard);
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/* The days of the months around this one are not drawn; their cells keep the grid's shape. */
|
|
143
|
+
.{{prefix}}-date-picker__day[data-outside-range] {
|
|
144
|
+
visibility: hidden;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/* Bolder as well as in the accent, so that today does not depend on telling colors apart,
|
|
148
|
+
and ringed, as a phone's calendar marks it. */
|
|
149
|
+
.{{prefix}}-date-picker__day[data-today] {
|
|
150
|
+
font-weight: var(--xds-typography-body-strong-weight);
|
|
151
|
+
color: var(--xds-color-date-picker-today-text);
|
|
152
|
+
box-shadow: inset 0 0 0 var(--xds-border-width-thin) var(--xds-color-date-picker-today-border);
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
@media (hover: hover) {
|
|
156
|
+
.{{prefix}}-date-picker__day:hover {
|
|
157
|
+
background-color: var(--xds-color-date-picker-day-background-hover);
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
/* The keyboard's day: the pointer's fill, and the ring a gap away from the circle, in the
|
|
162
|
+
surface's color, as around a Button. */
|
|
163
|
+
.{{prefix}}-date-picker__day:focus-visible {
|
|
164
|
+
background-color: var(--xds-color-date-picker-day-background-hover);
|
|
165
|
+
box-shadow:
|
|
166
|
+
0 0 0 var(--xds-focus-offset) var(--xds-color-date-picker-background),
|
|
167
|
+
0 0 0 calc(var(--xds-focus-width) + var(--xds-focus-offset)) var(--xds-color-border-focus);
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
.{{prefix}}-date-picker__day[data-today]:focus-visible {
|
|
171
|
+
box-shadow:
|
|
172
|
+
inset 0 0 0 var(--xds-border-width-thin) var(--xds-color-date-picker-today-border),
|
|
173
|
+
0 0 0 var(--xds-focus-offset) var(--xds-color-date-picker-background),
|
|
174
|
+
0 0 0 calc(var(--xds-focus-width) + var(--xds-focus-offset)) var(--xds-color-border-focus);
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
.{{prefix}}-date-picker__day:active {
|
|
178
|
+
background-color: var(--xds-color-date-picker-day-background-pressed);
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
/* The chosen day: a filled circle, which today's ring would only repeat. */
|
|
182
|
+
.{{prefix}}-date-picker__day[data-selected] {
|
|
183
|
+
background-color: var(--xds-color-date-picker-selected-background);
|
|
184
|
+
color: var(--xds-color-date-picker-selected-text);
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
.{{prefix}}-date-picker__day[data-selected][data-today]:not(:focus-visible) {
|
|
188
|
+
box-shadow: none;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
@media (hover: hover) {
|
|
192
|
+
.{{prefix}}-date-picker__day[data-selected]:hover {
|
|
193
|
+
background-color: var(--xds-color-date-picker-selected-background-hover);
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
.{{prefix}}-date-picker__day[data-selected]:active {
|
|
198
|
+
background-color: var(--xds-color-date-picker-selected-background-pressed);
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
/* DateRangePicker. A day in the band: its number in the band's text color, and the band's own
|
|
202
|
+
fills under the pointer and the keyboard. The ends keep the chosen day's circle. */
|
|
203
|
+
.{{prefix}}-date-picker__day[data-in-range]:not(
|
|
204
|
+
[data-selected],
|
|
205
|
+
[data-hover-range-end],
|
|
206
|
+
[data-disabled],
|
|
207
|
+
[data-today]
|
|
208
|
+
) {
|
|
209
|
+
color: var(--xds-color-date-picker-range-text);
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
@media (hover: hover) {
|
|
213
|
+
.{{prefix}}-date-picker__day[data-in-range]:not(
|
|
214
|
+
[data-selected],
|
|
215
|
+
[data-hover-range-end],
|
|
216
|
+
[data-disabled]
|
|
217
|
+
):hover {
|
|
218
|
+
background-color: var(--xds-color-date-picker-range-background-hover);
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
.{{prefix}}-date-picker__day[data-in-range]:not(
|
|
223
|
+
[data-selected],
|
|
224
|
+
[data-hover-range-end],
|
|
225
|
+
[data-disabled]
|
|
226
|
+
):focus-visible {
|
|
227
|
+
background-color: var(--xds-color-date-picker-range-background-hover);
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
.{{prefix}}-date-picker__day[data-in-range]:not(
|
|
231
|
+
[data-selected],
|
|
232
|
+
[data-hover-range-end],
|
|
233
|
+
[data-disabled]
|
|
234
|
+
):active {
|
|
235
|
+
background-color: var(--xds-color-date-picker-range-background-pressed);
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
/* The day a preview runs to is drawn as the end it would be. */
|
|
239
|
+
.{{prefix}}-date-picker__day[data-hover-range-end] {
|
|
240
|
+
background-color: var(--xds-color-date-picker-selected-background);
|
|
241
|
+
color: var(--xds-color-date-picker-selected-text);
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
.{{prefix}}-date-picker__day[data-hover-range-end][data-today]:not(:focus-visible) {
|
|
245
|
+
box-shadow: none;
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
@media (hover: hover) {
|
|
249
|
+
.{{prefix}}-date-picker__day[data-hover-range-end]:hover {
|
|
250
|
+
background-color: var(--xds-color-date-picker-selected-background-hover);
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
.{{prefix}}-date-picker__day[data-hover-range-end]:active {
|
|
255
|
+
background-color: var(--xds-color-date-picker-selected-background-pressed);
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
/* Outside `min`..`max`: dimmed, and nothing under the pointer. Last, so it outranks the
|
|
259
|
+
states above. A range's start alone is unavailable as its own end while the length rules
|
|
260
|
+
it out, and stays the start's circle. */
|
|
261
|
+
.{{prefix}}-date-picker__day[data-disabled]:not([data-selected][data-unavailable]) {
|
|
262
|
+
background-color: transparent;
|
|
263
|
+
color: var(--xds-color-date-picker-disabled-text);
|
|
264
|
+
cursor: default;
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
.{{prefix}}-date-picker__day[data-selected][data-unavailable] {
|
|
268
|
+
background-color: var(--xds-color-date-picker-selected-background);
|
|
269
|
+
cursor: default;
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
/*
|
|
274
|
+
* DateRangePicker's surface and its band. The band is drawn under the days of each cell in the
|
|
275
|
+
* range, as tall as a day's circle, and runs from the middle of the start's cell to the middle
|
|
276
|
+
* of the end's: the ends are circles on it. It is rounded at the ends of each week, and runs to
|
|
277
|
+
* the edge of a cell elsewhere, so that a range into the next month runs on across its grid.
|
|
278
|
+
* The days of the months around are hidden, and so is the band under them. Logical insets and
|
|
279
|
+
* corners, so that a right-to-left calendar mirrors it.
|
|
280
|
+
*/
|
|
281
|
+
@layer components {
|
|
282
|
+
/* As wide as the months, which it does not widen: the two ends go on two lines over one. */
|
|
283
|
+
.{{prefix}}-date-range-picker__summary {
|
|
284
|
+
display: flex;
|
|
285
|
+
flex-wrap: wrap;
|
|
286
|
+
justify-content: space-between;
|
|
287
|
+
column-gap: var(--xds-space-3);
|
|
288
|
+
contain: inline-size;
|
|
289
|
+
font-size: var(--xds-typography-footnote-size);
|
|
290
|
+
font-weight: var(--xds-typography-footnote-weight);
|
|
291
|
+
line-height: var(--xds-typography-footnote-line-height);
|
|
292
|
+
letter-spacing: var(--xds-typography-footnote-letter-spacing);
|
|
293
|
+
color: var(--xds-color-date-picker-weekday);
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
.{{prefix}}-date-range-picker__months {
|
|
297
|
+
display: flex;
|
|
298
|
+
gap: var(--xds-space-4);
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
.{{prefix}}-date-range-picker__month {
|
|
302
|
+
display: flex;
|
|
303
|
+
flex-direction: column;
|
|
304
|
+
gap: var(--xds-space-2);
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
/* As wide as a month button, so that each heading is centered over its grid. */
|
|
308
|
+
.{{prefix}}-date-range-picker__nav-space {
|
|
309
|
+
flex: none;
|
|
310
|
+
width: var(--xds-size-control-sm);
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
/* Above the band, which is positioned. */
|
|
314
|
+
.{{prefix}}-date-range-picker__content .{{prefix}}-date-picker__day {
|
|
315
|
+
position: relative;
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
.{{prefix}}-date-range-picker__content .{{prefix}}-date-picker__cell {
|
|
319
|
+
position: relative;
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
.{{prefix}}-date-picker__cell:has(> [data-in-range]:not([data-outside-range]))::before {
|
|
323
|
+
content: "";
|
|
324
|
+
position: absolute;
|
|
325
|
+
inset-block: var(--xds-space-0-5);
|
|
326
|
+
inset-inline: 0;
|
|
327
|
+
background: var(--xds-color-date-picker-range-background);
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
/* A range of one day has both, and no band. */
|
|
331
|
+
.{{prefix}}-date-picker__cell:has(
|
|
332
|
+
> [data-in-range]:is([data-range-start], [data-hover-range-start])
|
|
333
|
+
)::before {
|
|
334
|
+
inset-inline-start: 50%;
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
.{{prefix}}-date-picker__cell:has(
|
|
338
|
+
> [data-in-range]:is([data-range-end], [data-hover-range-end])
|
|
339
|
+
)::before {
|
|
340
|
+
inset-inline-end: 50%;
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
.{{prefix}}-date-picker__cell:first-child::before {
|
|
344
|
+
border-start-start-radius: var(--xds-radius-full);
|
|
345
|
+
border-end-start-radius: var(--xds-radius-full);
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
.{{prefix}}-date-picker__cell:last-child::before {
|
|
349
|
+
border-start-end-radius: var(--xds-radius-full);
|
|
350
|
+
border-end-end-radius: var(--xds-radius-full);
|
|
351
|
+
}
|
|
352
|
+
}
|
|
@@ -0,0 +1,250 @@
|
|
|
1
|
+
// Ejected from `@xds/react` 1.0.0-rc.1 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 { buttonClass, space } from "@xds/react/base";
|
|
5
|
+
import { type DateValue, getLocalTimeZone, parseDate, today } from "@internationalized/date";
|
|
6
|
+
import type * as datePicker from "@zag-js/date-picker";
|
|
7
|
+
|
|
8
|
+
/** A day of the calendar without a time or a time zone, as `YYYY-MM-DD`. */
|
|
9
|
+
export type IsoDate = string;
|
|
10
|
+
|
|
11
|
+
/** DatePicker's props in every framework, short of `onChange`. */
|
|
12
|
+
export type DatePickerBaseProps = {
|
|
13
|
+
/** Always visible, like a TextField's. */
|
|
14
|
+
label: string;
|
|
15
|
+
/** The chosen day. Leave it out while none is chosen. */
|
|
16
|
+
value?: IsoDate | undefined;
|
|
17
|
+
/** The first day that can be chosen. */
|
|
18
|
+
min?: IsoDate | undefined;
|
|
19
|
+
/** The last day that can be chosen. */
|
|
20
|
+
max?: IsoDate | undefined;
|
|
21
|
+
/** Shown in the field while no day is chosen. */
|
|
22
|
+
placeholder?: string;
|
|
23
|
+
/** Help shown under the field. Replaced by `error` while there is one. */
|
|
24
|
+
description?: string;
|
|
25
|
+
/** What is wrong and how to fix it. Clear it when the value changes. */
|
|
26
|
+
error?: string | undefined;
|
|
27
|
+
/** The name the day is submitted under with a form, as `YYYY-MM-DD`. */
|
|
28
|
+
name?: string;
|
|
29
|
+
disabled?: boolean;
|
|
30
|
+
/** Names the calendar's button to the month before, for assistive technology. */
|
|
31
|
+
previousLabel?: string;
|
|
32
|
+
/** Names the calendar's button to the month after, for assistive technology. */
|
|
33
|
+
nextLabel?: string;
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* The day as the field shows it: the locale's medium form ("Mar 10, 2026", "2026. 3. 10.").
|
|
38
|
+
* Read at noon UTC and formatted in UTC, so no time zone can move it to another day.
|
|
39
|
+
*/
|
|
40
|
+
export function formatDay(value: IsoDate, locale: string): string {
|
|
41
|
+
return new Intl.DateTimeFormat(locale, { dateStyle: "medium", timeZone: "UTC" }).format(
|
|
42
|
+
new Date(`${value}T12:00:00Z`),
|
|
43
|
+
);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/** Today where the page runs. */
|
|
47
|
+
export function todayIso(): IsoDate {
|
|
48
|
+
return today(getLocalTimeZone()).toString();
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/** `day`, or the nearer of `min` and `max` when it is outside them. */
|
|
52
|
+
export function clampDay(day: IsoDate, min?: IsoDate, max?: IsoDate): IsoDate {
|
|
53
|
+
// Strings of the same form sort as the days they name.
|
|
54
|
+
if (min !== undefined && day < min) return min;
|
|
55
|
+
if (max !== undefined && day > max) return max;
|
|
56
|
+
return day;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* The day that has the focus when the calendar opens, whose month it shows: the chosen day, or
|
|
61
|
+
* today while none is, held between `min` and `max`.
|
|
62
|
+
*/
|
|
63
|
+
export function openingDay(
|
|
64
|
+
props: Pick<DatePickerBaseProps, "value" | "min" | "max">,
|
|
65
|
+
now: IsoDate = todayIso(),
|
|
66
|
+
): IsoDate {
|
|
67
|
+
return clampDay(props.value ?? now, props.min, props.max);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* The language of the names of the days and months, and of the field's form of a day: the
|
|
72
|
+
* page's, as a native date input takes it. Zag's own default is English.
|
|
73
|
+
*/
|
|
74
|
+
export function datePickerLocale(): string {
|
|
75
|
+
return typeof navigator === "undefined" ? "en-US" : navigator.language;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/** The ids of the parts the library names itself, under the DatePicker's own id. */
|
|
79
|
+
export function datePickerIds(id: string) {
|
|
80
|
+
return {
|
|
81
|
+
label: `${id}-label`,
|
|
82
|
+
value: `${id}-value`,
|
|
83
|
+
description: `${id}-description`,
|
|
84
|
+
error: `${id}-error`,
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
type Ids = ReturnType<typeof datePickerIds>;
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* The props of Zag's date-picker machine for a DatePicker. `onChange` gets the chosen day as
|
|
92
|
+
* `YYYY-MM-DD`. One month of days and nothing else: no text input (the field is a button), no
|
|
93
|
+
* month or year views, and no days of the months around it.
|
|
94
|
+
*/
|
|
95
|
+
export function datePickerMachineProps(
|
|
96
|
+
props: DatePickerBaseProps,
|
|
97
|
+
options: { id: string; locale: string; onChange: (value: IsoDate) => void },
|
|
98
|
+
): datePicker.Props {
|
|
99
|
+
const day = (value: IsoDate | undefined) => (value === undefined ? undefined : parseDate(value));
|
|
100
|
+
return {
|
|
101
|
+
id: options.id,
|
|
102
|
+
locale: options.locale,
|
|
103
|
+
// Today is the day where the page runs; Zag's own is the day in UTC.
|
|
104
|
+
timeZone: getLocalTimeZone(),
|
|
105
|
+
value: props.value === undefined ? [] : [parseDate(props.value)],
|
|
106
|
+
min: day(props.min),
|
|
107
|
+
max: day(props.max),
|
|
108
|
+
defaultFocusedValue: parseDate(openingDay(props)),
|
|
109
|
+
onValueChange: (details) => {
|
|
110
|
+
const next = details.value[0];
|
|
111
|
+
if (next !== undefined) options.onChange(next.toString());
|
|
112
|
+
},
|
|
113
|
+
disabled: props.disabled,
|
|
114
|
+
invalid: props.error !== undefined,
|
|
115
|
+
// Zag gives `name` to its text input, which is not drawn: each library draws a hidden input
|
|
116
|
+
// of its own for a form.
|
|
117
|
+
outsideDaySelectable: false,
|
|
118
|
+
minView: "day",
|
|
119
|
+
maxView: "day",
|
|
120
|
+
positioning: { placement: "bottom-start", gutter: space[1] },
|
|
121
|
+
translations: datePickerTranslations(props),
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* Zag's strings that the calendar shows assistive technology. A day is named by its long
|
|
127
|
+
* localized name alone ("Tuesday, March 10, 2026"): its grid cell says whether it is selected
|
|
128
|
+
* and whether it is today, where Zag would add English words for both. The month buttons take
|
|
129
|
+
* `previousLabel` and `nextLabel`. Zag's other strings name parts that are not drawn, or whose
|
|
130
|
+
* names `datePickerTriggerAttrs` and `datePickerContentAttrs` replace.
|
|
131
|
+
*/
|
|
132
|
+
export function datePickerTranslations(
|
|
133
|
+
props: Pick<DatePickerBaseProps, "previousLabel" | "nextLabel">,
|
|
134
|
+
): datePicker.IntlTranslations {
|
|
135
|
+
return {
|
|
136
|
+
dayCell: (state) => state.valueText,
|
|
137
|
+
previousTrigger: () => props.previousLabel ?? "Previous month",
|
|
138
|
+
nextTrigger: () => props.nextLabel ?? "Next month",
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* Spread over Zag's props of the field, the trigger, after them: a button that says it opens a
|
|
144
|
+
* dialog, the calendar, named by the chosen day (or the placeholder) and then the label, as a
|
|
145
|
+
* Select's field is, and described by the help or the error. Zag's English name ("Open
|
|
146
|
+
* calendar") goes. The error is said in the description, so the button does not
|
|
147
|
+
* claim to be invalid; `data-invalid` draws the field's error border.
|
|
148
|
+
*/
|
|
149
|
+
export function datePickerTriggerAttrs(
|
|
150
|
+
props: Pick<DatePickerBaseProps, "error" | "description">,
|
|
151
|
+
ids: Ids,
|
|
152
|
+
) {
|
|
153
|
+
const invalid = props.error !== undefined;
|
|
154
|
+
return {
|
|
155
|
+
"aria-label": undefined,
|
|
156
|
+
"aria-haspopup": "dialog",
|
|
157
|
+
"aria-labelledby": `${ids.value} ${ids.label}`,
|
|
158
|
+
"aria-describedby": invalid ? ids.error : props.description ? ids.description : undefined,
|
|
159
|
+
"data-invalid": invalid ? "" : undefined,
|
|
160
|
+
} as const;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
/**
|
|
164
|
+
* Spread over Zag's props of the calendar's surface, the content, after them: a dialog named
|
|
165
|
+
* by the field's label, in place of Zag's `application` role and its English name.
|
|
166
|
+
*/
|
|
167
|
+
export function datePickerContentAttrs(ids: Ids) {
|
|
168
|
+
return {
|
|
169
|
+
role: "dialog",
|
|
170
|
+
"aria-label": undefined,
|
|
171
|
+
"aria-labelledby": ids.label,
|
|
172
|
+
} as const;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
/**
|
|
176
|
+
* For the click handler of the field, ahead of Zag's: the calendar opens on the day
|
|
177
|
+
* `openingDay` names. Zag goes back to the chosen day itself, but with none chosen it would open
|
|
178
|
+
* on whatever day the focus was on when the calendar last closed.
|
|
179
|
+
*/
|
|
180
|
+
export function focusOpeningDay(
|
|
181
|
+
api: { open: boolean; setFocusedValue(value: DateValue): void },
|
|
182
|
+
props: Pick<DatePickerBaseProps, "value" | "min" | "max">,
|
|
183
|
+
): void {
|
|
184
|
+
if (!api.open) api.setFocusedValue(parseDate(openingDay(props)));
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
/**
|
|
188
|
+
* For the keydown handler of the calendar's surface: Tab and Shift+Tab go round the month
|
|
189
|
+
* buttons that can be pressed and the focused day, as in a modal dialog. Zag would let the focus
|
|
190
|
+
* leave, which closes the calendar without a choice.
|
|
191
|
+
*/
|
|
192
|
+
export function keepCalendarFocus(
|
|
193
|
+
event: { key: string; shiftKey: boolean; preventDefault(): void },
|
|
194
|
+
content: HTMLElement | null | undefined,
|
|
195
|
+
): void {
|
|
196
|
+
if (event.key !== "Tab" || !content) return;
|
|
197
|
+
event.preventDefault();
|
|
198
|
+
const stops = [
|
|
199
|
+
...content.querySelectorAll<HTMLElement>('button:not(:disabled), [role="grid"] [tabindex="0"]'),
|
|
200
|
+
];
|
|
201
|
+
const at = stops.indexOf(document.activeElement as HTMLElement);
|
|
202
|
+
const next =
|
|
203
|
+
at === -1
|
|
204
|
+
? event.shiftKey
|
|
205
|
+
? stops.length - 1
|
|
206
|
+
: 0
|
|
207
|
+
: (at + (event.shiftKey ? -1 : 1) + stops.length) % stops.length;
|
|
208
|
+
stops[next]?.focus();
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
/**
|
|
212
|
+
* After a render in which the focused day or the month changed, while the calendar is open:
|
|
213
|
+
* puts the focus back on the focused day if the change took it off, as React Aria's calendar
|
|
214
|
+
* does. Two changes take it off:
|
|
215
|
+
*
|
|
216
|
+
* - Zag focuses the day a key moves to a frame after the move, but a move held at `min` or
|
|
217
|
+
* `max` into another month shows that month a render later, which a framework that renders
|
|
218
|
+
* after the frame has not drawn yet: the day the focus was on is gone, and the focus with it.
|
|
219
|
+
* - A month button pressed into the month of `min` or `max` is disabled with the focus on it,
|
|
220
|
+
* which the browser then drops to the page, where Tab is no longer held in the calendar.
|
|
221
|
+
*
|
|
222
|
+
* A focus elsewhere in the calendar, such as on a month button that can still be pressed, stays
|
|
223
|
+
* where it is.
|
|
224
|
+
*/
|
|
225
|
+
export function keepDayFocused(open: boolean, content: HTMLElement | null | undefined): void {
|
|
226
|
+
// A DateRangePicker shows a grid for each month.
|
|
227
|
+
const grids = open && content ? [...content.querySelectorAll('[role="grid"]')] : [];
|
|
228
|
+
if (!content || grids.length === 0) return;
|
|
229
|
+
const active = document.activeElement;
|
|
230
|
+
const lost =
|
|
231
|
+
active === null ||
|
|
232
|
+
active === document.body ||
|
|
233
|
+
grids.some((grid) => grid.contains(active)) ||
|
|
234
|
+
(active instanceof HTMLButtonElement && active.disabled && content.contains(active));
|
|
235
|
+
if (!lost) return;
|
|
236
|
+
const day = content.querySelector<HTMLElement>(
|
|
237
|
+
'[role="grid"] [data-focus]:not([data-outside-range])',
|
|
238
|
+
);
|
|
239
|
+
if (day && day !== active) day.focus({ preventScroll: true });
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
/**
|
|
243
|
+
* The classes of the calendar's month buttons: the `__nav` part, which button.css draws as a
|
|
244
|
+
* small ghost IconButton.
|
|
245
|
+
*/
|
|
246
|
+
export const DATE_PICKER_NAV_CLASS = `{{prefix}}-date-picker__nav ${buttonClass({
|
|
247
|
+
variant: "ghost",
|
|
248
|
+
size: "sm",
|
|
249
|
+
iconButton: true,
|
|
250
|
+
})}`;
|