@aleph-alpha/ui-library 6.3.3 → 6.4.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/config.js +2 -1
- package/dist/system/components/UiDropdownMenu/UiDropdownMenuSubContent.vue.d.ts +102 -2
- package/dist/system/components/UiDropdownMenu/UiDropdownMenuViewport.vue.d.ts +23 -0
- package/dist/system/components/UiDropdownMenu/menu-metrics.d.ts +4 -0
- package/dist/system/components/UiDropdownMenu/placeMobileSubmenu.d.ts +55 -0
- package/dist/system/components/UiDropdownMenu/types.d.ts +3 -0
- package/dist/system/components/UiDropdownMenu/useMobileSubmenuPlacement.d.ts +18 -0
- package/dist/system/components/UiFileUploadBox/UiFileUploadBox.vue.d.ts +2 -2
- package/dist/system/components/UiFileUploadBox/types.d.ts +8 -5
- package/dist/system/components/UiResizable/UiResizablePanel.vue.d.ts +2 -2
- package/dist/system/components/UiStepper/context.d.ts +8 -0
- package/dist/system/components/UiToggle/UiToggle.vue.d.ts +2 -1
- package/dist/system/components/UiToggle/types.d.ts +10 -2
- package/dist/system/components/UiToggleGroup/UiToggleGroupItem.vue.d.ts +5 -1
- package/dist/system/components/UiToggleGroup/types.d.ts +12 -2
- package/dist/system/components/core/dropdown-menu/DropdownMenuSubContent.vue.d.ts +2 -6
- package/dist/system/components/core/range-calendar/RangeCalendar.vue.d.ts +24 -24
- package/dist/system/components/core/resizable/ResizablePanel.vue.d.ts +2 -2
- package/dist/system/components/core/toggle/Toggle.vue.d.ts +3 -1
- package/dist/system/components/core/toggle/index.d.ts +47 -2
- package/dist/system/components/core/toggle-group/ToggleGroup.vue.d.ts +3 -1
- package/dist/system/components/core/toggle-group/ToggleGroupItem.vue.d.ts +11 -1
- package/dist/system/components/core/toggle-group/context.d.ts +1 -0
- package/dist/system/components/core/toggle-group/index.d.ts +10 -2
- package/dist/system/icons/story-sidebar-icons.json +7 -0
- package/dist/system/lib.js +14114 -13755
- package/dist/system/patterns/UiFileUpload/UiFileUpload.vue.d.ts +2 -2
- package/dist/system/patterns/UiLayout/layout-shell.d.ts +379 -8
- package/dist/system/patterns/UiProfileCard/profile-card.d.ts +51 -1
- package/dist/system/patterns/UiTopBar/accessory-dropdown.d.ts +232 -0
- package/dist/system/story-sidebar-icons.json +7 -0
- package/package.json +2 -2
- package/src/components/UiAccordion/UiAccordion.stories.ts +1079 -0
- package/src/components/UiCalendar/UiCalendar.stories.ts +734 -0
- package/src/components/UiCalendar/__tests__/UiCalendar.test.ts +8 -5
- package/src/components/UiDropdownMenu/UiDropdownMenu.stories.ts +819 -31
- package/src/components/UiDropdownMenu/UiDropdownMenuContent.vue +4 -1
- package/src/components/UiDropdownMenu/UiDropdownMenuSubContent.vue +142 -1
- package/src/components/UiDropdownMenu/UiDropdownMenuSubTrigger.vue +28 -0
- package/src/components/UiDropdownMenu/UiDropdownMenuTrigger.vue +3 -1
- package/src/components/UiDropdownMenu/UiDropdownMenuViewport.vue +171 -0
- package/src/components/UiDropdownMenu/__tests__/UiDropdownMenu.test.ts +326 -0
- package/src/components/UiDropdownMenu/__tests__/placeMobileSubmenu.test.ts +128 -0
- package/src/components/UiDropdownMenu/menu-metrics.ts +5 -0
- package/src/components/UiDropdownMenu/placeMobileSubmenu.ts +96 -0
- package/src/components/UiDropdownMenu/types.ts +3 -0
- package/src/components/UiDropdownMenu/useMobileSubmenuPlacement.ts +163 -0
- package/src/components/UiFileUploadBox/UiFileUploadBox.stories.ts +389 -3
- package/src/components/UiFileUploadBox/UiFileUploadBox.vue +55 -75
- package/src/components/UiFileUploadBox/__tests__/UiFileUploadBox.test.ts +44 -0
- package/src/components/UiFileUploadBox/types.ts +8 -5
- package/src/components/UiNavigationMenu/UiNavigationMenu.stories.ts +723 -0
- package/src/components/UiRangeCalendar/UiRangeCalendar.stories.ts +819 -7
- package/src/components/UiRangeCalendar/__tests__/UiRangeCalendar.test.ts +8 -3
- package/src/components/UiResizable/UiResizable.stories.ts +1215 -5
- package/src/components/UiSnackbar/UiSnackbar.stories.ts +1089 -4
- package/src/components/UiSnackbar/UiSnackbar.vue +3 -2
- package/src/components/UiSnackbar/UiSnackbarContent.vue +1 -1
- package/src/components/UiSnackbar/__tests__/UiSnackbar.test.ts +3 -1
- package/src/components/UiStepper/UiStepper.stories.ts +566 -2
- package/src/components/UiStepper/UiStepper.vue +14 -1
- package/src/components/UiStepper/UiStepperItem.vue +22 -4
- package/src/components/UiStepper/__tests__/UiStepper.test.ts +66 -0
- package/src/components/UiStepper/context.ts +10 -0
- package/src/components/UiToggle/UiToggle.stories.ts +386 -261
- package/src/components/UiToggle/UiToggle.vue +2 -0
- package/src/components/UiToggle/__tests__/UiToggle.test.ts +63 -10
- package/src/components/UiToggle/types.ts +10 -2
- package/src/components/UiToggleGroup/UiToggleGroup.stories.ts +765 -30
- package/src/components/UiToggleGroup/UiToggleGroup.vue +2 -0
- package/src/components/UiToggleGroup/UiToggleGroupItem.vue +10 -1
- package/src/components/UiToggleGroup/__tests__/UiToggleGroup.test.ts +83 -4
- package/src/components/UiToggleGroup/types.ts +12 -2
- package/src/components/core/calendar/Calendar.vue +234 -2
- package/src/components/core/calendar/CalendarCellTrigger.vue +1 -1
- package/src/components/core/dropdown-menu/DropdownMenuContent.vue +1 -1
- package/src/components/core/dropdown-menu/DropdownMenuItem.vue +1 -1
- package/src/components/core/dropdown-menu/DropdownMenuSubContent.vue +31 -20
- package/src/components/core/navigation-menu/NavigationMenuList.vue +1 -1
- package/src/components/core/range-calendar/RangeCalendar.vue +254 -6
- package/src/components/core/range-calendar/RangeCalendarCellTrigger.vue +1 -1
- package/src/components/core/toggle/Toggle.vue +12 -5
- package/src/components/core/toggle/index.ts +47 -19
- package/src/components/core/toggle-group/ToggleGroup.vue +20 -4
- package/src/components/core/toggle-group/ToggleGroupItem.vue +36 -8
- package/src/components/core/toggle-group/context.ts +1 -0
- package/src/components/core/toggle-group/index.ts +10 -24
- package/src/patterns/UiDataTable/UiDataTableColumnFilter.vue +1 -1
- package/src/patterns/UiDataTable/UiDataTableFilterMenu.vue +1 -1
- package/src/patterns/UiDatePicker/UiDatePicker.stories.ts +846 -17
- package/src/patterns/UiDatePicker/UiDatePicker.vue +9 -0
- package/src/patterns/UiDatePicker/__tests__/UiDatePicker.test.ts +13 -8
- package/src/patterns/UiFileUpload/UiFileItem.stories.ts +23 -17
- package/src/patterns/UiFileUpload/UiFileUpload.stories.ts +138 -113
- package/src/patterns/UiFileUpload/UiFileUpload.vue +1 -1
- package/src/patterns/UiFileUpload/__tests__/UiFileUpload.test.ts +2 -2
- package/src/patterns/UiLayout/UiLayout.stories.ts +25 -0
- package/src/patterns/UiLayout/UiLayoutContent.stories.ts +359 -0
- package/src/patterns/UiLayout/UiLayoutContent.vue +45 -23
- package/src/patterns/UiLayout/UiLayoutMobile.stories.ts +13 -0
- package/src/patterns/UiLayout/layout-shell.ts +159 -13
- package/src/patterns/UiProfileCard/UiProfileCard.stories.ts +13 -6
- package/src/patterns/UiTopBar/UiTopBar.stories.ts +245 -36
- package/src/patterns/UiTopBar/UiTopBar.vue +4 -2
- package/src/patterns/UiTopBar/accessory-dropdown.ts +99 -0
|
@@ -1,7 +1,17 @@
|
|
|
1
1
|
<script lang="ts" setup>
|
|
2
|
-
import type {
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
import type {
|
|
3
|
+
DateValue,
|
|
4
|
+
RangeCalendarRootEmits,
|
|
5
|
+
RangeCalendarRootProps,
|
|
6
|
+
} from 'reka-ui';
|
|
7
|
+
import type { HTMLAttributes, Ref } from 'vue';
|
|
8
|
+
import {
|
|
9
|
+
getLocalTimeZone,
|
|
10
|
+
parseDate,
|
|
11
|
+
toCalendar,
|
|
12
|
+
today,
|
|
13
|
+
} from '@internationalized/date';
|
|
14
|
+
import { reactiveOmit, useVModel } from '@vueuse/core';
|
|
5
15
|
import { RangeCalendarRoot, useForwardPropsEmits } from 'reka-ui';
|
|
6
16
|
import { nextTick, onMounted, ref, watch } from 'vue';
|
|
7
17
|
import { cn } from '@/lib/utils';
|
|
@@ -25,7 +35,14 @@ const props = defineProps<
|
|
|
25
35
|
|
|
26
36
|
const emits = defineEmits<RangeCalendarRootEmits>();
|
|
27
37
|
|
|
28
|
-
const delegatedProps = reactiveOmit(props, 'class');
|
|
38
|
+
const delegatedProps = reactiveOmit(props, 'class', 'placeholder');
|
|
39
|
+
|
|
40
|
+
// Managed locally (instead of forwarded) so the grid keydown handler below
|
|
41
|
+
// can move the roving tab stop, which follows the placeholder in reka-ui.
|
|
42
|
+
const placeholder = useVModel(props, 'placeholder', emits, {
|
|
43
|
+
passive: true,
|
|
44
|
+
defaultValue: props.defaultPlaceholder ?? today(getLocalTimeZone()),
|
|
45
|
+
}) as Ref<DateValue>;
|
|
29
46
|
|
|
30
47
|
const forwarded = useForwardPropsEmits(delegatedProps, emits);
|
|
31
48
|
const rangeCalendarRootRef = ref<InstanceType<typeof RangeCalendarRoot> | null>(
|
|
@@ -44,16 +61,247 @@ function removeUnsupportedReadonlyAttributes() {
|
|
|
44
61
|
}
|
|
45
62
|
|
|
46
63
|
onMounted(removeUnsupportedReadonlyAttributes);
|
|
47
|
-
|
|
64
|
+
// Month navigation re-renders the grid table, which re-adds the unsupported
|
|
65
|
+
// attribute, so rerun the cleanup whenever the visible month (placeholder)
|
|
66
|
+
// changes — not only when the readonly prop flips.
|
|
67
|
+
watch([() => props.readonly, placeholder], removeUnsupportedReadonlyAttributes);
|
|
68
|
+
|
|
69
|
+
const GRID_NAV_KEYS = ['Home', 'End', 'PageUp', 'PageDown'];
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Converts a cell's Gregorian ISO `data-value` into the placeholder's
|
|
73
|
+
* calendar system. `data-value` strings are always Gregorian (that is what
|
|
74
|
+
* `DateValue.toString()` emits), but placeholder fields and month arithmetic
|
|
75
|
+
* must be interpreted in the placeholder's own calendar (e.g. Hebrew).
|
|
76
|
+
* @param value ISO date string carried by the cell's `data-value` attribute.
|
|
77
|
+
*/
|
|
78
|
+
function parseCellValue(value: string): DateValue {
|
|
79
|
+
return toCalendar(parseDate(value), placeholder.value.calendar);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Moves the placeholder to the given day while preserving the placeholder's
|
|
84
|
+
* date type, calendar system, and era. reka-ui's roving tabindex follows the
|
|
85
|
+
* placeholder, so this keeps the single tab stop in sync with the day we
|
|
86
|
+
* focus.
|
|
87
|
+
* @param date Target day.
|
|
88
|
+
*/
|
|
89
|
+
function setPlaceholderDay(date: DateValue) {
|
|
90
|
+
const target = toCalendar(date, placeholder.value.calendar);
|
|
91
|
+
placeholder.value = placeholder.value.set({
|
|
92
|
+
era: target.era,
|
|
93
|
+
year: target.year,
|
|
94
|
+
month: target.month,
|
|
95
|
+
day: target.day,
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Focuses a day cell trigger and syncs the placeholder to it.
|
|
101
|
+
* @param cell The day cell trigger element to focus.
|
|
102
|
+
*/
|
|
103
|
+
function focusDay(cell: HTMLElement | null | undefined) {
|
|
104
|
+
const value = cell?.getAttribute('data-value');
|
|
105
|
+
if (!cell || !value) return;
|
|
106
|
+
setPlaceholderDay(parseCellValue(value));
|
|
107
|
+
cell.focus();
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* Finds the in-view (not outside-view) day cell trigger for a date value in
|
|
112
|
+
* the currently rendered view.
|
|
113
|
+
* @param value ISO date string carried by the cell's `data-value` attribute.
|
|
114
|
+
* @returns The matching trigger element, or null when not rendered.
|
|
115
|
+
*/
|
|
116
|
+
function queryInViewDay(value: string): HTMLElement | null {
|
|
117
|
+
const root = rangeCalendarRootRef.value?.$el as HTMLElement | undefined;
|
|
118
|
+
return (
|
|
119
|
+
root?.querySelector<HTMLElement>(
|
|
120
|
+
`[data-value='${value}']:not([data-outside-view])`,
|
|
121
|
+
) ?? null
|
|
122
|
+
);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* Whether a day cannot take keyboard focus — disabled by the `isDateDisabled`
|
|
127
|
+
* matcher or outside the min/max bounds.
|
|
128
|
+
* @param date Candidate day.
|
|
129
|
+
*/
|
|
130
|
+
function isDayDisabled(date: DateValue): boolean {
|
|
131
|
+
return Boolean(
|
|
132
|
+
props.isDateDisabled?.(date) ||
|
|
133
|
+
(props.minValue && date.compare(props.minValue) < 0) ||
|
|
134
|
+
(props.maxValue && date.compare(props.maxValue) > 0),
|
|
135
|
+
);
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* Resolves an enabled landing day within the candidate's month, stepping past
|
|
140
|
+
* disabled dates in the given direction.
|
|
141
|
+
* @param candidate First-choice landing day.
|
|
142
|
+
* @param direction 1 to step forwards, -1 to step backwards.
|
|
143
|
+
* @returns The first enabled day, or null when the whole stretch is disabled
|
|
144
|
+
* (e.g. a fully disabled target month).
|
|
145
|
+
*/
|
|
146
|
+
function resolveEnabledLandingDay(
|
|
147
|
+
candidate: DateValue,
|
|
148
|
+
direction: number,
|
|
149
|
+
): DateValue | null {
|
|
150
|
+
const targetMonth = candidate.month;
|
|
151
|
+
let day = candidate;
|
|
152
|
+
while (day.month === targetMonth && isDayDisabled(day)) {
|
|
153
|
+
day = day.add({ days: direction });
|
|
154
|
+
}
|
|
155
|
+
return day.month === targetMonth ? day : null;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
/**
|
|
159
|
+
* Clamps a landing day into the min/max bounds so paging stays possible when
|
|
160
|
+
* only part of the target month is allowed (e.g. PageUp from June 10 with
|
|
161
|
+
* minValue May 15 lands on May 15 instead of being rejected).
|
|
162
|
+
* @param target Unclamped landing day (same day in the target month/year).
|
|
163
|
+
* @param direction 1 when paging forwards, -1 backwards.
|
|
164
|
+
* @returns The clamped landing day plus the direction to search for an
|
|
165
|
+
* enabled day (away from the clamped bound, into the month), or null when the
|
|
166
|
+
* whole target month lies outside the bounds.
|
|
167
|
+
*/
|
|
168
|
+
function clampLandingDay(
|
|
169
|
+
target: DateValue,
|
|
170
|
+
direction: number,
|
|
171
|
+
): { day: DateValue; searchDirection: number } | null {
|
|
172
|
+
let day = target;
|
|
173
|
+
let searchDirection = direction;
|
|
174
|
+
if (props.minValue && day.compare(props.minValue) < 0) {
|
|
175
|
+
day = toCalendar(props.minValue, placeholder.value.calendar);
|
|
176
|
+
searchDirection = 1;
|
|
177
|
+
} else if (props.maxValue && day.compare(props.maxValue) > 0) {
|
|
178
|
+
day = toCalendar(props.maxValue, placeholder.value.calendar);
|
|
179
|
+
searchDirection = -1;
|
|
180
|
+
}
|
|
181
|
+
const sameMonth =
|
|
182
|
+
day.era === target.era &&
|
|
183
|
+
day.year === target.year &&
|
|
184
|
+
day.month === target.month;
|
|
185
|
+
return sameMonth ? { day, searchDirection } : null;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
/**
|
|
189
|
+
* Home/End move to the first/last enabled day of the focused row.
|
|
190
|
+
* Outside-view days stay included: with the default
|
|
191
|
+
* `disableDaysOutsideCurrentView: false` they are visible and selectable, so
|
|
192
|
+
* row navigation must reach them too. When that prop is true, reka-ui marks
|
|
193
|
+
* them `data-disabled`, and the filter excludes them consistently.
|
|
194
|
+
* @param trigger The focused day cell trigger.
|
|
195
|
+
* @param key The pressed key, 'Home' or 'End'.
|
|
196
|
+
*/
|
|
197
|
+
function handleHomeEndKey(trigger: HTMLElement, key: string) {
|
|
198
|
+
const week = Array.from(
|
|
199
|
+
trigger
|
|
200
|
+
.closest('tr')
|
|
201
|
+
?.querySelectorAll<HTMLElement>(
|
|
202
|
+
'[data-reka-calendar-cell-trigger]:not([data-disabled])',
|
|
203
|
+
) ?? [],
|
|
204
|
+
);
|
|
205
|
+
const target = key === 'Home' ? week[0] : week[week.length - 1];
|
|
206
|
+
const targetValue = target?.getAttribute('data-value');
|
|
207
|
+
if (!target || !targetValue) return;
|
|
208
|
+
|
|
209
|
+
if (!target.hasAttribute('data-outside-view')) {
|
|
210
|
+
focusDay(target);
|
|
211
|
+
return;
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
// The row's first/last day belongs to the adjacent month. Mirror reka-ui's
|
|
215
|
+
// arrow navigation, which never focuses outside-view cells: flip the view
|
|
216
|
+
// to that month, then focus the same date as an in-view cell.
|
|
217
|
+
setPlaceholderDay(parseCellValue(targetValue));
|
|
218
|
+
nextTick(() => focusDay(queryInViewDay(targetValue)));
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
/**
|
|
222
|
+
* PageUp/PageDown move to the same day in the previous/next month;
|
|
223
|
+
* Shift+PageUp/Shift+PageDown move by a year per the WAI-ARIA calendar
|
|
224
|
+
* pattern. The month/year arithmetic runs in the placeholder's calendar
|
|
225
|
+
* system, landing days are clamped into the min/max bounds, and the enabled
|
|
226
|
+
* landing day is resolved *before* flipping the view, so bailing out (e.g. a
|
|
227
|
+
* fully disabled or out-of-bounds target month) keeps the current view and
|
|
228
|
+
* focus intact instead of stranding keyboard focus.
|
|
229
|
+
* @param trigger The focused day cell trigger.
|
|
230
|
+
* @param e The keydown event.
|
|
231
|
+
*/
|
|
232
|
+
function handlePageKey(trigger: HTMLElement, e: KeyboardEvent) {
|
|
233
|
+
const currentValue = trigger.getAttribute('data-value');
|
|
234
|
+
if (!currentValue) return;
|
|
235
|
+
const direction = e.key === 'PageDown' ? 1 : -1;
|
|
236
|
+
const target = parseCellValue(currentValue).add(
|
|
237
|
+
e.shiftKey ? { years: direction } : { months: direction },
|
|
238
|
+
);
|
|
239
|
+
const clamped = clampLandingDay(target, direction);
|
|
240
|
+
if (!clamped) return;
|
|
241
|
+
const candidate = resolveEnabledLandingDay(
|
|
242
|
+
clamped.day,
|
|
243
|
+
clamped.searchDirection,
|
|
244
|
+
);
|
|
245
|
+
if (!candidate) return;
|
|
246
|
+
|
|
247
|
+
setPlaceholderDay(candidate);
|
|
248
|
+
nextTick(() => focusLandingDay(candidate, currentValue));
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
/**
|
|
252
|
+
* Focuses the resolved landing day after the view flipped. Defensive: if the
|
|
253
|
+
* landing cell is unexpectedly missing or disabled in the new view, restores
|
|
254
|
+
* the previous view and focus instead of leaving keyboard focus lost.
|
|
255
|
+
* @param candidate The resolved landing day.
|
|
256
|
+
* @param originValue `data-value` of the day the navigation started from.
|
|
257
|
+
*/
|
|
258
|
+
function focusLandingDay(candidate: DateValue, originValue: string) {
|
|
259
|
+
const cell = queryInViewDay(candidate.toString());
|
|
260
|
+
if (cell && !cell.hasAttribute('data-disabled')) {
|
|
261
|
+
focusDay(cell);
|
|
262
|
+
return;
|
|
263
|
+
}
|
|
264
|
+
setPlaceholderDay(parseCellValue(originValue));
|
|
265
|
+
nextTick(() => focusDay(queryInViewDay(originValue)));
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
/**
|
|
269
|
+
* reka-ui's RangeCalendarCellTrigger only implements arrow-key navigation plus
|
|
270
|
+
* Enter/Space selection. The WAI-ARIA date-grid pattern also expects Home/End
|
|
271
|
+
* (first/last day of the visible week), PageUp/PageDown (same day in the
|
|
272
|
+
* previous/next month), and Shift+PageUp/Shift+PageDown (same day in the
|
|
273
|
+
* previous/next year), so we add those here on the calendar root.
|
|
274
|
+
* @param e The keydown event bubbling up from a day cell trigger.
|
|
275
|
+
*/
|
|
276
|
+
function handleGridKeydown(e: KeyboardEvent) {
|
|
277
|
+
if (!GRID_NAV_KEYS.includes(e.key)) return;
|
|
278
|
+
const trigger = e.target as HTMLElement | null;
|
|
279
|
+
if (
|
|
280
|
+
!trigger?.hasAttribute('data-reka-calendar-cell-trigger') ||
|
|
281
|
+
trigger.hasAttribute('data-disabled')
|
|
282
|
+
) {
|
|
283
|
+
return;
|
|
284
|
+
}
|
|
285
|
+
e.preventDefault();
|
|
286
|
+
e.stopPropagation();
|
|
287
|
+
|
|
288
|
+
if (e.key === 'Home' || e.key === 'End') {
|
|
289
|
+
handleHomeEndKey(trigger, e.key);
|
|
290
|
+
} else {
|
|
291
|
+
handlePageKey(trigger, e);
|
|
292
|
+
}
|
|
293
|
+
}
|
|
48
294
|
</script>
|
|
49
295
|
|
|
50
296
|
<template>
|
|
51
297
|
<RangeCalendarRoot
|
|
52
298
|
ref="rangeCalendarRootRef"
|
|
53
299
|
#default="{ grid, weekDays }"
|
|
300
|
+
v-bind="forwarded"
|
|
301
|
+
v-model:placeholder="placeholder"
|
|
54
302
|
data-slot="range-calendar"
|
|
55
303
|
:class="cn('p-3', props.class)"
|
|
56
|
-
|
|
304
|
+
@keydown="handleGridKeydown"
|
|
57
305
|
>
|
|
58
306
|
<RangeCalendarHeader>
|
|
59
307
|
<RangeCalendarHeading />
|
|
@@ -10,11 +10,13 @@ const props = withDefaults(
|
|
|
10
10
|
ToggleProps & {
|
|
11
11
|
variant?: ToggleVariants['variant'];
|
|
12
12
|
size?: ToggleVariants['size'];
|
|
13
|
+
soft?: ToggleVariants['soft'];
|
|
13
14
|
}
|
|
14
15
|
>(),
|
|
15
16
|
{
|
|
16
17
|
variant: 'default',
|
|
17
18
|
size: 'default',
|
|
19
|
+
soft: false,
|
|
18
20
|
disabled: false,
|
|
19
21
|
},
|
|
20
22
|
);
|
|
@@ -22,15 +24,16 @@ const props = withDefaults(
|
|
|
22
24
|
const emits = defineEmits<ToggleEmits>();
|
|
23
25
|
|
|
24
26
|
/**
|
|
25
|
-
* `variant` and `
|
|
26
|
-
* declare them, so forwarding them would land them on the rendered `button`
|
|
27
|
-
* invalid HTML attributes.
|
|
27
|
+
* `variant`, `size` and `soft` only feed `toggleVariants`. reka's Toggle does
|
|
28
|
+
* not declare them, so forwarding them would land them on the rendered `button`
|
|
29
|
+
* as invalid HTML attributes.
|
|
28
30
|
*/
|
|
29
31
|
const delegatedProps = computed(() => {
|
|
30
32
|
const rest = { ...props } as ToggleProps &
|
|
31
|
-
Partial<Record<'variant' | 'size', unknown>>;
|
|
33
|
+
Partial<Record<'variant' | 'size' | 'soft', unknown>>;
|
|
32
34
|
delete rest.variant;
|
|
33
35
|
delete rest.size;
|
|
36
|
+
delete rest.soft;
|
|
34
37
|
return rest as ToggleProps;
|
|
35
38
|
});
|
|
36
39
|
|
|
@@ -43,7 +46,11 @@ const forwarded = useForwardPropsEmits(delegatedProps, emits);
|
|
|
43
46
|
v-bind="forwarded"
|
|
44
47
|
:class="
|
|
45
48
|
cn(
|
|
46
|
-
toggleVariants({
|
|
49
|
+
toggleVariants({
|
|
50
|
+
variant: props.variant,
|
|
51
|
+
size: props.size,
|
|
52
|
+
soft: props.soft,
|
|
53
|
+
}),
|
|
47
54
|
$attrs.class ?? '',
|
|
48
55
|
)
|
|
49
56
|
"
|
|
@@ -2,28 +2,56 @@ import { cva, type VariantProps } from 'class-variance-authority';
|
|
|
2
2
|
|
|
3
3
|
export { default as Toggle } from './Toggle.vue';
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
5
|
+
/**
|
|
6
|
+
* Everything a toggle looks like apart from its corner radius. The toggle group
|
|
7
|
+
* builds on this so a grouped item is the same control, only with its corners
|
|
8
|
+
* squared off where it meets its neighbours.
|
|
9
|
+
*
|
|
10
|
+
* `hover-layer` carries hover, keyboard focus, press and `data-state=open` as
|
|
11
|
+
* an overlay; it deliberately ignores the pressed state, so that stays a real
|
|
12
|
+
* fill rather than the same wash.
|
|
13
|
+
*/
|
|
14
|
+
export const toggleBaseClasses =
|
|
15
|
+
'inline-flex items-center justify-center gap-2 label-14-medium transition-colors ui-focus-ring hover-layer hover-layer-subtle disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none [&_svg]:size-4 [&_svg]:shrink-0 border bg-transparent text-content-on-surface-primary';
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* The variants themselves, shared with the toggle group so the two cannot drift
|
|
19
|
+
* apart. Only the base differs between them.
|
|
20
|
+
*/
|
|
21
|
+
export const toggleVariantsConfig = {
|
|
22
|
+
variants: {
|
|
23
|
+
variant: {
|
|
24
|
+
default: 'border-transparent',
|
|
25
|
+
ghost: 'border-transparent',
|
|
26
|
+
outline: 'border-input',
|
|
27
|
+
},
|
|
28
|
+
size: {
|
|
29
|
+
default: 'label-m-medium py-2.5 px-2',
|
|
30
|
+
sm: 'label-s-medium py-1 px-1.5',
|
|
31
|
+
lg: 'label-m-medium py-3 px-2.5',
|
|
21
32
|
},
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
33
|
+
/**
|
|
34
|
+
* Pressed fill only: the hover overlay instead of a muted surface.
|
|
35
|
+
*
|
|
36
|
+
* Keyed off `aria-pressed` rather than `data-state`, because a trigger
|
|
37
|
+
* rendered with `as-child` overwrites `data-state` with its own
|
|
38
|
+
* `open`/`closed`, which would drop the fill on every menu trigger.
|
|
39
|
+
*/
|
|
40
|
+
soft: {
|
|
41
|
+
true: 'aria-pressed:bg-overlay-hover-subtle',
|
|
42
|
+
false: 'aria-pressed:bg-background-surface-muted-subtle',
|
|
25
43
|
},
|
|
26
44
|
},
|
|
45
|
+
defaultVariants: {
|
|
46
|
+
variant: 'default',
|
|
47
|
+
size: 'default',
|
|
48
|
+
soft: false,
|
|
49
|
+
},
|
|
50
|
+
} as const;
|
|
51
|
+
|
|
52
|
+
export const toggleVariants = cva(
|
|
53
|
+
`${toggleBaseClasses} rounded-md`,
|
|
54
|
+
toggleVariantsConfig,
|
|
27
55
|
);
|
|
28
56
|
|
|
29
57
|
export type ToggleVariants = VariantProps<typeof toggleVariants>;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
<script setup lang="ts">
|
|
2
2
|
import type { ToggleGroupRootEmits, ToggleGroupRootProps } from 'reka-ui';
|
|
3
3
|
import { ToggleGroupRoot, useForwardPropsEmits } from 'reka-ui';
|
|
4
|
-
import { provide, toRefs } from 'vue';
|
|
4
|
+
import { computed, provide, toRefs } from 'vue';
|
|
5
5
|
import { cn } from '@/lib/utils';
|
|
6
6
|
import type { ToggleGroupVariants } from '.';
|
|
7
7
|
import { toggleGroupContextKey } from './context';
|
|
@@ -11,20 +11,36 @@ const props = withDefaults(
|
|
|
11
11
|
ToggleGroupRootProps & {
|
|
12
12
|
variant?: ToggleGroupVariants['variant'];
|
|
13
13
|
size?: ToggleGroupVariants['size'];
|
|
14
|
+
soft?: ToggleGroupVariants['soft'];
|
|
14
15
|
}
|
|
15
16
|
>(),
|
|
16
17
|
{
|
|
17
18
|
variant: 'default',
|
|
18
19
|
size: 'default',
|
|
20
|
+
soft: false,
|
|
19
21
|
},
|
|
20
22
|
);
|
|
21
23
|
|
|
22
24
|
const emits = defineEmits<ToggleGroupRootEmits>();
|
|
23
25
|
|
|
24
|
-
|
|
26
|
+
/**
|
|
27
|
+
* The styling props reach the items through the context, not through reka.
|
|
28
|
+
* Forwarding them would land them on the rendered root as invalid HTML
|
|
29
|
+
* attributes.
|
|
30
|
+
*/
|
|
31
|
+
const delegatedProps = computed(() => {
|
|
32
|
+
const rest = { ...props } as ToggleGroupRootProps &
|
|
33
|
+
Partial<Record<'variant' | 'size' | 'soft', unknown>>;
|
|
34
|
+
delete rest.variant;
|
|
35
|
+
delete rest.size;
|
|
36
|
+
delete rest.soft;
|
|
37
|
+
return rest as ToggleGroupRootProps;
|
|
38
|
+
});
|
|
25
39
|
|
|
26
|
-
const
|
|
27
|
-
|
|
40
|
+
const forwarded = useForwardPropsEmits(delegatedProps, emits);
|
|
41
|
+
|
|
42
|
+
const { variant, size, soft } = toRefs(props);
|
|
43
|
+
provide(toggleGroupContextKey, { variant, size, soft });
|
|
28
44
|
</script>
|
|
29
45
|
|
|
30
46
|
<template>
|
|
@@ -1,21 +1,48 @@
|
|
|
1
1
|
<script setup lang="ts">
|
|
2
2
|
import type { ToggleGroupItemProps } from 'reka-ui';
|
|
3
3
|
import { ToggleGroupItem, useForwardProps } from 'reka-ui';
|
|
4
|
-
import { inject } from 'vue';
|
|
4
|
+
import { computed, inject } from 'vue';
|
|
5
5
|
import { cn } from '@/lib/utils';
|
|
6
6
|
import { toggleGroupVariants, type ToggleGroupVariants } from '.';
|
|
7
7
|
import { toggleGroupContextKey } from './context';
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
9
|
+
/**
|
|
10
|
+
* `soft` has to stay `undefined` when it is not set, otherwise Vue casts the
|
|
11
|
+
* absent boolean prop to `false` and the item overrides the group instead of
|
|
12
|
+
* inheriting from it.
|
|
13
|
+
*/
|
|
14
|
+
const props = withDefaults(
|
|
15
|
+
defineProps<
|
|
16
|
+
ToggleGroupItemProps & {
|
|
17
|
+
variant?: ToggleGroupVariants['variant'];
|
|
18
|
+
size?: ToggleGroupVariants['size'];
|
|
19
|
+
soft?: ToggleGroupVariants['soft'];
|
|
20
|
+
}
|
|
21
|
+
>(),
|
|
22
|
+
{
|
|
23
|
+
variant: undefined,
|
|
24
|
+
size: undefined,
|
|
25
|
+
soft: undefined,
|
|
26
|
+
},
|
|
27
|
+
);
|
|
15
28
|
|
|
16
29
|
const context = inject(toggleGroupContextKey);
|
|
17
30
|
|
|
18
|
-
|
|
31
|
+
/**
|
|
32
|
+
* The styling props only feed `toggleGroupVariants`. reka's ToggleGroupItem
|
|
33
|
+
* does not declare them, so forwarding them would land them on the rendered
|
|
34
|
+
* `button` as invalid HTML attributes.
|
|
35
|
+
*/
|
|
36
|
+
const delegatedProps = computed(() => {
|
|
37
|
+
const rest = { ...props } as ToggleGroupItemProps &
|
|
38
|
+
Partial<Record<'variant' | 'size' | 'soft', unknown>>;
|
|
39
|
+
delete rest.variant;
|
|
40
|
+
delete rest.size;
|
|
41
|
+
delete rest.soft;
|
|
42
|
+
return rest as ToggleGroupItemProps;
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
const forwarded = useForwardProps(delegatedProps);
|
|
19
46
|
</script>
|
|
20
47
|
|
|
21
48
|
<template>
|
|
@@ -27,6 +54,7 @@ const forwarded = useForwardProps(props);
|
|
|
27
54
|
toggleGroupVariants({
|
|
28
55
|
variant: props.variant ?? context?.variant?.value,
|
|
29
56
|
size: props.size ?? context?.size?.value,
|
|
57
|
+
soft: props.soft ?? context?.soft?.value,
|
|
30
58
|
}),
|
|
31
59
|
$attrs.class ?? '',
|
|
32
60
|
)
|
|
@@ -4,6 +4,7 @@ import type { ToggleGroupVariants } from '.';
|
|
|
4
4
|
export interface ToggleGroupContext {
|
|
5
5
|
variant: Ref<ToggleGroupVariants['variant']>;
|
|
6
6
|
size: Ref<ToggleGroupVariants['size']>;
|
|
7
|
+
soft: Ref<ToggleGroupVariants['soft']>;
|
|
7
8
|
}
|
|
8
9
|
|
|
9
10
|
export const toggleGroupContextKey = Symbol(
|
|
@@ -1,34 +1,20 @@
|
|
|
1
1
|
import { cva, type VariantProps } from 'class-variance-authority';
|
|
2
|
+
import { toggleBaseClasses, toggleVariantsConfig } from '../toggle';
|
|
2
3
|
|
|
3
4
|
export { default as ToggleGroup } from './ToggleGroup.vue';
|
|
4
5
|
export { default as ToggleGroupItem } from './ToggleGroupItem.vue';
|
|
5
6
|
export { toggleGroupContextKey, type ToggleGroupContext } from './context';
|
|
6
7
|
|
|
8
|
+
/**
|
|
9
|
+
* A grouped item is a `Toggle` in group format: the same base, variants and
|
|
10
|
+
* sizes, with only the corner radius changed. Items sit flush against each
|
|
11
|
+
* other, so just the outer edges of the group are rounded — and because the
|
|
12
|
+
* radius lives on the item, the pressed fill, the hover overlay and the focus
|
|
13
|
+
* ring are all clipped to the same shape.
|
|
14
|
+
*/
|
|
7
15
|
export const toggleGroupVariants = cva(
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
// the hover fill and the focus ring are all clipped to the same shape.
|
|
11
|
-
'inline-flex items-center justify-center gap-2 rounded-none first:rounded-l-md last:rounded-r-md label-14-medium transition-colors hover:bg-background-surface-muted-subtle ui-focus-ring disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none [&_svg]:size-4 [&_svg]:shrink-0',
|
|
12
|
-
{
|
|
13
|
-
variants: {
|
|
14
|
-
variant: {
|
|
15
|
-
default:
|
|
16
|
-
'bg-transparent data-[state=on]:bg-accent-default data-[state=on]:text-accent-default-foreground data-[state=on]:hover:bg-accent-default data-[state=on]:hover:text-accent-default-foreground data-[state=open]:bg-accent-default data-[state=open]:text-accent-default-foreground data-[state=open]:hover:bg-accent-default data-[state=open]:hover:text-accent-default-foreground aria-pressed:bg-accent-default aria-pressed:text-accent-default-foreground aria-pressed:hover:bg-accent-default aria-pressed:hover:text-accent-default-foreground',
|
|
17
|
-
outline:
|
|
18
|
-
'border border-input bg-transparent data-[state=on]:bg-accent-default data-[state=on]:text-accent-default-foreground data-[state=on]:hover:bg-accent-default data-[state=on]:hover:text-accent-default-foreground data-[state=open]:bg-accent-default data-[state=open]:text-accent-default-foreground data-[state=open]:hover:bg-accent-default data-[state=open]:hover:text-accent-default-foreground aria-pressed:bg-accent-default aria-pressed:text-accent-default-foreground aria-pressed:hover:bg-accent-default aria-pressed:hover:text-accent-default-foreground',
|
|
19
|
-
soft: 'bg-transparent data-[state=on]:bg-accent data-[state=on]:text-accent-foreground data-[state=on]:border data-[state=on]:border-accent-default data-[state=on]:hover:bg-accent data-[state=on]:hover:text-accent-foreground data-[state=open]:bg-accent data-[state=open]:text-accent-foreground data-[state=open]:border data-[state=open]:border-accent-default data-[state=open]:hover:bg-accent data-[state=open]:hover:text-accent-foreground aria-pressed:bg-accent aria-pressed:text-accent-foreground aria-pressed:border aria-pressed:border-accent-default aria-pressed:hover:bg-accent aria-pressed:hover:text-accent-foreground',
|
|
20
|
-
},
|
|
21
|
-
size: {
|
|
22
|
-
default: 'h-9 px-2 min-w-9',
|
|
23
|
-
sm: 'h-8 px-1.5 min-w-8',
|
|
24
|
-
lg: 'h-10 px-2.5 min-w-10',
|
|
25
|
-
},
|
|
26
|
-
},
|
|
27
|
-
defaultVariants: {
|
|
28
|
-
variant: 'default',
|
|
29
|
-
size: 'default',
|
|
30
|
-
},
|
|
31
|
-
},
|
|
16
|
+
`${toggleBaseClasses} rounded-none first:rounded-l-md last:rounded-r-md`,
|
|
17
|
+
toggleVariantsConfig,
|
|
32
18
|
);
|
|
33
19
|
|
|
34
20
|
export type ToggleGroupVariants = VariantProps<typeof toggleGroupVariants>;
|