@aleph-alpha/ui-library 5.8.0 → 5.10.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/README.md +8 -7
- package/config.js +157 -4
- package/dist/system/__tests__/test-utils.d.ts +24 -0
- package/dist/system/components/UiAutocomplete/UiAutocomplete.vue.d.ts +8 -4
- package/dist/system/components/UiAutocomplete/types.d.ts +11 -0
- package/dist/system/components/UiFadeMask/UiFadeMask.vue.d.ts +21 -0
- package/dist/system/components/UiFadeMask/index.d.ts +2 -0
- package/dist/system/components/UiFadeMask/types.d.ts +33 -0
- package/dist/system/components/UiFileItem/UiFileItem.vue.d.ts +3 -1
- package/dist/system/components/UiFileType/types.d.ts +2 -1
- package/dist/system/components/UiListbox/UiListboxVirtualizer.vue.d.ts +21 -0
- package/dist/system/components/UiListbox/index.d.ts +1 -0
- package/dist/system/components/UiListbox/types.d.ts +36 -0
- package/dist/system/components/UiSelect/UiSelectVirtualizer.vue.d.ts +21 -0
- package/dist/system/components/UiSelect/index.d.ts +1 -0
- package/dist/system/components/UiSelect/types.d.ts +36 -0
- package/dist/system/components/UiSwitch/UiSwitch.vue.d.ts +1 -0
- package/dist/system/components/UiSwitch/types.d.ts +12 -0
- package/dist/system/components/core/native-select/NativeSelectOptGroup.vue.d.ts +2 -2
- package/dist/system/components/core/native-select/NativeSelectOption.vue.d.ts +2 -2
- package/dist/system/components/core/switch/Switch.vue.d.ts +2 -0
- package/dist/system/components/core/switch/index.d.ts +8 -0
- package/dist/system/components/index.d.ts +1 -0
- package/dist/system/index.d.ts +1 -0
- package/dist/system/lib/scrollbar.d.ts +37 -0
- package/dist/system/lib/useAnchorFloat.d.ts +0 -2
- package/dist/system/lib/useIsTruncated.d.ts +15 -0
- package/dist/system/lib.js +22660 -21292
- package/dist/system/mobile-device-frame.png +0 -0
- package/dist/system/patterns/UiFloatActions/types.d.ts +2 -2
- package/dist/system/patterns/UiProfileCard/index.d.ts +7 -0
- package/dist/system/patterns/UiTopBar/UiTopBar.vue.d.ts +23 -0
- package/dist/system/patterns/UiTopBar/index.d.ts +2 -0
- package/dist/system/patterns/UiTopBar/types.d.ts +28 -0
- package/dist/system/patterns/index.d.ts +2 -0
- package/dist/system/story-sidebar-icons.json +7 -1
- package/docs/public-docs/foundations.md +17 -15
- package/package.json +4 -3
- package/src/__tests__/test-utils.ts +74 -0
- package/src/components/UiAutocomplete/UiAutocomplete.stories.ts +94 -0
- package/src/components/UiAutocomplete/UiAutocomplete.vue +164 -44
- package/src/components/UiAutocomplete/__tests__/UiAutocompleteVirtualized.test.ts +107 -0
- package/src/components/UiAutocomplete/types.ts +11 -0
- package/src/components/UiCodeBlock/UiCodeBlock.stories.ts +54 -0
- package/src/components/UiCodeBlock/UiCodeBlock.vue +84 -32
- package/src/components/UiCodeBlock/__tests__/UiCodeBlock.test.ts +65 -21
- package/src/components/UiDropdownMenu/UiDropdownMenu.stories.ts +760 -0
- package/src/components/UiFadeMask/UiFadeMask.stories.ts +563 -0
- package/src/components/UiFadeMask/UiFadeMask.vue +86 -0
- package/src/components/UiFadeMask/__tests__/UiFadeMask.test.ts +52 -0
- package/src/components/UiFadeMask/index.ts +6 -0
- package/src/components/UiFadeMask/types.ts +35 -0
- package/src/components/UiFileItem/UiFileItem.vue +17 -4
- package/src/components/UiFileItem/__tests__/UiFileItem.test.ts +49 -90
- package/src/components/UiFileType/UiFileType.stories.ts +13 -2
- package/src/components/UiFileType/UiFileType.vue +8 -0
- package/src/components/UiFileType/__tests__/UiFileType.test.ts +10 -0
- package/src/components/UiFileType/types.ts +3 -1
- package/src/components/UiListbox/UiListbox.stories.ts +121 -0
- package/src/components/UiListbox/UiListboxVirtualizer.vue +42 -0
- package/src/components/UiListbox/__tests__/UiListboxVirtualizer.test.ts +96 -0
- package/src/components/UiListbox/index.ts +1 -0
- package/src/components/UiListbox/types.ts +42 -0
- package/src/components/UiSelect/UiSelect.stories.ts +109 -1
- package/src/components/UiSelect/UiSelectVirtualizer.vue +373 -0
- package/src/components/UiSelect/__tests__/UiSelectVirtualizer.test.ts +185 -0
- package/src/components/UiSelect/index.ts +1 -0
- package/src/components/UiSelect/types.ts +38 -0
- package/src/components/UiSnackbar/UiSnackbar.stories.ts +4 -5
- package/src/components/UiSwitch/UiSwitch.stories.ts +658 -7
- package/src/components/UiSwitch/UiSwitch.vue +1 -0
- package/src/components/UiSwitch/__tests__/UiSwitch.test.ts +48 -0
- package/src/components/UiSwitch/types.ts +13 -0
- package/src/components/UiToggleGroup/UiToggleGroup.vue +1 -1
- package/src/components/core/dropdown-menu/DropdownMenuCheckboxItem.vue +8 -2
- package/src/components/core/dropdown-menu/DropdownMenuItem.vue +1 -1
- package/src/components/core/dropdown-menu/DropdownMenuRadioItem.vue +8 -2
- package/src/components/core/dropdown-menu/DropdownMenuSubTrigger.vue +1 -1
- package/src/components/core/field/FieldLabel.vue +1 -1
- package/src/components/core/label/Label.vue +1 -1
- package/src/components/core/listbox/ListboxItem.vue +1 -1
- package/src/components/core/switch/Switch.vue +23 -17
- package/src/components/core/switch/index.ts +36 -0
- package/src/components/index.ts +1 -0
- package/src/index.ts +3 -0
- package/src/lib/scrollbar.ts +295 -0
- package/src/lib/useAnchorFloat.ts +0 -2
- package/src/lib/useIsTruncated.test.ts +174 -0
- package/src/lib/useIsTruncated.ts +75 -0
- package/src/patterns/UiFileUpload/UiFileItem.stories.ts +1162 -0
- package/src/patterns/UiFileUpload/UiFileUpload.stories.ts +552 -1
- package/src/patterns/UiFileUpload/__tests__/UiFileUpload.test.ts +5 -21
- package/src/patterns/UiFloatActions/UiFloatActionItems.vue +0 -1
- package/src/patterns/UiFloatActions/UiFloatActions.stories.ts +4 -6
- package/src/patterns/UiFloatActions/UiFloatActions.vue +23 -12
- package/src/patterns/UiFloatActions/__tests__/UiFloatActions.test.ts +23 -0
- package/src/patterns/UiFloatActions/types.ts +2 -2
- package/src/patterns/UiProfileCard/UiProfileCard.stories.ts +1079 -0
- package/src/patterns/UiProfileCard/index.ts +7 -0
- package/src/patterns/UiTopBar/UiTopBar.stories.ts +1121 -0
- package/src/patterns/UiTopBar/UiTopBar.vue +166 -0
- package/src/patterns/UiTopBar/__tests__/UiTopBar.test.ts +245 -0
- package/src/patterns/UiTopBar/index.ts +2 -0
- package/src/patterns/UiTopBar/types.ts +29 -0
- package/src/patterns/index.ts +2 -0
- package/src/theme/Background.stories.ts +27 -1
- package/src/theme/BorderRadius.stories.ts +5 -0
- package/src/theme/Overlay.stories.ts +12 -1
- package/src/theme/Scrollbar.stories.ts +260 -0
- package/tokens.json +224 -2
- package/src/components/UiFileItem/UiFileItem.stories.ts +0 -442
|
@@ -47,4 +47,52 @@ describe('UiSwitch', () => {
|
|
|
47
47
|
await userEvent.click(getByRole('switch'));
|
|
48
48
|
expect(emitted('update:modelValue')).toBeUndefined();
|
|
49
49
|
});
|
|
50
|
+
|
|
51
|
+
test('defaults to the roomier track and thumb', () => {
|
|
52
|
+
const { getByRole } = render(UiSwitch, {
|
|
53
|
+
props: { name: 'switch' },
|
|
54
|
+
});
|
|
55
|
+
const track = getByRole('switch');
|
|
56
|
+
|
|
57
|
+
expect(track).toHaveClass('h-5', 'w-9');
|
|
58
|
+
// The size variant wins over the conflicting base dimensions.
|
|
59
|
+
expect(track).not.toHaveClass('w-8');
|
|
60
|
+
expect(track.querySelector('[data-slot="switch-thumb"]')).toHaveClass(
|
|
61
|
+
'size-4',
|
|
62
|
+
);
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
test('small size tightens the track and thumb', () => {
|
|
66
|
+
const { getByRole } = render(UiSwitch, {
|
|
67
|
+
props: { name: 'switch', size: 'sm' },
|
|
68
|
+
});
|
|
69
|
+
const track = getByRole('switch');
|
|
70
|
+
|
|
71
|
+
expect(track).toHaveClass('h-4', 'w-7');
|
|
72
|
+
expect(track.querySelector('[data-slot="switch-thumb"]')).toHaveClass(
|
|
73
|
+
'size-3',
|
|
74
|
+
);
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
test('size only picks the variant and is not rendered as an attribute', () => {
|
|
78
|
+
const { getByRole } = render(UiSwitch, {
|
|
79
|
+
props: { name: 'switch', size: 'sm' },
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
// The switch renders a `button`, which has no `size` attribute.
|
|
83
|
+
expect(getByRole('switch')).not.toHaveAttribute('size');
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
test('small size keeps the switch semantics and stays operable', async () => {
|
|
87
|
+
const { getByRole, emitted } = render(UiSwitch, {
|
|
88
|
+
props: { name: 'switch', size: 'sm' },
|
|
89
|
+
});
|
|
90
|
+
const track = getByRole('switch');
|
|
91
|
+
|
|
92
|
+
expect(track).toHaveAttribute('role', 'switch');
|
|
93
|
+
expect(track).toHaveAttribute('aria-checked', 'false');
|
|
94
|
+
|
|
95
|
+
await userEvent.click(track);
|
|
96
|
+
expect(emitted('update:modelValue')[0][0]).toBe(true);
|
|
97
|
+
});
|
|
50
98
|
});
|
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Size options for the UiSwitch component.
|
|
3
|
+
* - `default`: 36×20px track with a 16px thumb
|
|
4
|
+
* - `sm`: 28×16px track with a 12px thumb, for dense rows and table cells
|
|
5
|
+
*/
|
|
6
|
+
export type UiSwitchSize = 'default' | 'sm';
|
|
7
|
+
|
|
1
8
|
/**
|
|
2
9
|
* A toggle switch for on/off states. Use for settings, preferences,
|
|
3
10
|
* or any binary choice that takes effect immediately.
|
|
@@ -21,4 +28,10 @@ export type UiSwitchProps = {
|
|
|
21
28
|
* @default false
|
|
22
29
|
*/
|
|
23
30
|
required?: boolean;
|
|
31
|
+
/**
|
|
32
|
+
* Track and thumb scale. Neither size reaches the 24px minimum target height,
|
|
33
|
+
* so pair the switch with a label that extends the target (WCAG 2.5.8).
|
|
34
|
+
* @default 'default'
|
|
35
|
+
*/
|
|
36
|
+
size?: UiSwitchSize;
|
|
24
37
|
};
|
|
@@ -18,11 +18,11 @@ const props = withDefaults(
|
|
|
18
18
|
/**
|
|
19
19
|
* The default value when initially rendered (uncontrolled mode).
|
|
20
20
|
*/
|
|
21
|
-
// eslint-disable-next-line vue/require-default-prop
|
|
22
21
|
defaultValue?: UiToggleGroupModelValue<T>;
|
|
23
22
|
}
|
|
24
23
|
>(),
|
|
25
24
|
{
|
|
25
|
+
defaultValue: undefined,
|
|
26
26
|
disabled: false,
|
|
27
27
|
variant: 'default',
|
|
28
28
|
size: 'default',
|
|
@@ -25,7 +25,7 @@ const forwarded = useForwardPropsEmits(delegatedProps, emits);
|
|
|
25
25
|
v-bind="forwarded"
|
|
26
26
|
:class="
|
|
27
27
|
cn(
|
|
28
|
-
'group/dropdown-menu-checkbox-item hover:bg-background-surface-muted-subtle data-[highlighted]:bg-background-surface-muted-subtle focus:text-foreground relative flex cursor-default items-center gap-2 rounded-sm py-1.5 pr-2 pl-8 label-14-regular outline-hidden select-none data-[disabled]:pointer-events-none data-[disabled]:opacity-50',
|
|
28
|
+
'group/dropdown-menu-checkbox-item hover:bg-background-surface-muted-subtle data-[highlighted]:bg-background-surface-muted-subtle focus:text-foreground relative h-9 flex cursor-default items-center gap-2 rounded-sm py-1.5 pr-2 pl-8 label-14-regular outline-hidden select-none data-[disabled]:pointer-events-none data-[disabled]:opacity-50',
|
|
29
29
|
props.class,
|
|
30
30
|
)
|
|
31
31
|
"
|
|
@@ -36,11 +36,17 @@ const forwarded = useForwardPropsEmits(delegatedProps, emits);
|
|
|
36
36
|
class="pointer-events-none absolute left-2 flex size-4 items-center justify-center"
|
|
37
37
|
>
|
|
38
38
|
<slot name="indicator-icon">
|
|
39
|
+
<!--
|
|
40
|
+
The checkbox is decoration: the menu item itself carries the checked
|
|
41
|
+
state. It has to be disabled, not just untabbable, or it is focusable
|
|
42
|
+
content inside an `aria-hidden` element (axe `aria-hidden-focus`).
|
|
43
|
+
-->
|
|
39
44
|
<UiCheckbox
|
|
40
45
|
name="dropdown-menu-checkbox-indicator"
|
|
41
46
|
:model-value="props.modelValue"
|
|
47
|
+
disabled
|
|
42
48
|
tabindex="-1"
|
|
43
|
-
class="pointer-events-none"
|
|
49
|
+
class="pointer-events-none disabled:opacity-100"
|
|
44
50
|
/>
|
|
45
51
|
</slot>
|
|
46
52
|
</span>
|
|
@@ -31,7 +31,7 @@ const forwardedProps = useForwardProps(delegatedProps);
|
|
|
31
31
|
v-bind="forwardedProps"
|
|
32
32
|
:class="
|
|
33
33
|
cn(
|
|
34
|
-
'hover:bg-background-surface-muted-subtle data-[highlighted]:bg-background-surface-muted-subtle focus:text-foreground data-[variant=destructive]:text-destructive data-[variant=destructive]:focus:bg-destructive/10 dark:data-[variant=destructive]:focus:bg-destructive/20 data-[variant=destructive]:focus:text-destructive data-[variant=destructive]:*:[svg]:!text-destructive [&_svg:not([class*=\'text-\'])]:text-content-on-surface-muted relative flex cursor-default items-center gap-2 rounded-sm px-2 py-1.5
|
|
34
|
+
'hover:bg-background-surface-muted-subtle data-[highlighted]:bg-background-surface-muted-subtle focus:text-foreground data-[variant=destructive]:text-destructive data-[variant=destructive]:focus:bg-destructive/10 dark:data-[variant=destructive]:focus:bg-destructive/20 data-[variant=destructive]:focus:text-destructive data-[variant=destructive]:*:[svg]:!text-destructive [&_svg:not([class*=\'text-\'])]:text-content-on-surface-muted relative h-9 flex cursor-default items-center gap-2 rounded-sm px-2 py-1.5 body-14-regular outline-hidden select-none data-[disabled]:pointer-events-none data-[disabled]:opacity-50 data-[inset]:pl-8 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*=\'size-\'])]:size-4',
|
|
35
35
|
props.class,
|
|
36
36
|
)
|
|
37
37
|
"
|
|
@@ -29,7 +29,7 @@ const visualRadioValue = computed(() => String(props.value ?? ''));
|
|
|
29
29
|
v-bind="forwarded"
|
|
30
30
|
:class="
|
|
31
31
|
cn(
|
|
32
|
-
'group/dropdown-menu-radio-item hover:bg-background-surface-muted-subtle data-[highlighted]:bg-background-surface-muted-subtle focus:text-foreground relative flex cursor-default items-center gap-2 rounded-sm py-1.5 pr-2 pl-8 label-14-regular outline-hidden select-none data-[disabled]:pointer-events-none data-[disabled]:opacity-50',
|
|
32
|
+
'group/dropdown-menu-radio-item hover:bg-background-surface-muted-subtle data-[highlighted]:bg-background-surface-muted-subtle focus:text-foreground relative h-9 flex cursor-default items-center gap-2 rounded-sm py-1.5 pr-2 pl-8 label-14-regular outline-hidden select-none data-[disabled]:pointer-events-none data-[disabled]:opacity-50',
|
|
33
33
|
props.class,
|
|
34
34
|
)
|
|
35
35
|
"
|
|
@@ -40,6 +40,11 @@ const visualRadioValue = computed(() => String(props.value ?? ''));
|
|
|
40
40
|
class="pointer-events-none absolute left-2 flex size-4 items-center justify-center"
|
|
41
41
|
>
|
|
42
42
|
<slot name="indicator-icon">
|
|
43
|
+
<!--
|
|
44
|
+
The radio is decoration: the menu item itself carries the checked
|
|
45
|
+
state. It has to be disabled, not just untabbable, or it is focusable
|
|
46
|
+
content inside an `aria-hidden` element (axe `aria-hidden-focus`).
|
|
47
|
+
-->
|
|
43
48
|
<UiRadioGroup
|
|
44
49
|
name="dropdown-menu-radio-indicator"
|
|
45
50
|
:model-value="visualRadioValue"
|
|
@@ -48,8 +53,9 @@ const visualRadioValue = computed(() => String(props.value ?? ''));
|
|
|
48
53
|
<UiRadioGroupItem
|
|
49
54
|
:id="`dropdown-menu-radio-indicator-${visualRadioValue}`"
|
|
50
55
|
:value="visualRadioValue"
|
|
56
|
+
disabled
|
|
51
57
|
tabindex="-1"
|
|
52
|
-
class="pointer-events-none border-input group-data-[state=checked]/dropdown-menu-radio-item:border-accent-default [&_[data-slot=radio-group-indicator]]:opacity-0 group-data-[state=checked]/dropdown-menu-radio-item:[&_[data-slot=radio-group-indicator]]:opacity-100"
|
|
58
|
+
class="pointer-events-none border-input disabled:opacity-100 group-data-[state=checked]/dropdown-menu-radio-item:border-accent-default [&_[data-slot=radio-group-indicator]]:opacity-0 group-data-[state=checked]/dropdown-menu-radio-item:[&_[data-slot=radio-group-indicator]]:opacity-100"
|
|
53
59
|
/>
|
|
54
60
|
</UiRadioGroup>
|
|
55
61
|
</slot>
|
|
@@ -23,7 +23,7 @@ const forwardedProps = useForwardProps(delegatedProps);
|
|
|
23
23
|
v-bind="forwardedProps"
|
|
24
24
|
:class="
|
|
25
25
|
cn(
|
|
26
|
-
'hover:bg-background-surface-muted-subtle data-[highlighted]:bg-background-surface-muted-subtle data-[state=open]:bg-background-surface-muted-subtle focus:text-foreground data-[state=open]:text-foreground flex cursor-default items-center rounded-sm px-2 py-1.5 label-14-regular outline-hidden select-none data-[inset]:pl-8',
|
|
26
|
+
'hover:bg-background-surface-muted-subtle data-[highlighted]:bg-background-surface-muted-subtle data-[state=open]:bg-background-surface-muted-subtle focus:text-foreground data-[state=open]:text-foreground h-9 flex cursor-default items-center rounded-sm px-2 py-1.5 label-14-regular outline-hidden select-none data-[disabled]:pointer-events-none data-[disabled]:opacity-50 data-[inset]:pl-8',
|
|
27
27
|
props.class,
|
|
28
28
|
)
|
|
29
29
|
"
|
|
@@ -10,7 +10,7 @@ const props = defineProps<{
|
|
|
10
10
|
</script>
|
|
11
11
|
|
|
12
12
|
<template>
|
|
13
|
-
<!-- eslint-disable-next-line vuejs-accessibility/label-has-for -->
|
|
13
|
+
<!-- eslint-disable-next-line vuejs-accessibility/label-has-for -- false positive: `for` is forwarded to the underlying Label wrapper, which the rule cannot statically resolve -->
|
|
14
14
|
<Label
|
|
15
15
|
data-slot="field-label"
|
|
16
16
|
:for="props.for"
|
|
@@ -11,7 +11,7 @@ const delegatedProps = reactiveOmit(props, 'class', 'for');
|
|
|
11
11
|
</script>
|
|
12
12
|
|
|
13
13
|
<template>
|
|
14
|
-
<!-- eslint-disable-next-line vuejs-accessibility/label-has-for -->
|
|
14
|
+
<!-- eslint-disable-next-line vuejs-accessibility/label-has-for -- false positive: `for` is forwarded to the underlying reka-ui Label, which the rule cannot statically resolve -->
|
|
15
15
|
<Label
|
|
16
16
|
data-slot="label"
|
|
17
17
|
v-bind="delegatedProps"
|
|
@@ -25,7 +25,7 @@ const isDisabled = computed(() => props.disabled || isListboxDisabled.value);
|
|
|
25
25
|
:aria-disabled="isDisabled ? 'true' : undefined"
|
|
26
26
|
:class="
|
|
27
27
|
cn(
|
|
28
|
-
'hover-layer hover-layer-default data-[highlighted]:text-foreground [&_svg:not([class*=\'text-\'])]:text-content-on-surface-muted ui-focus-ring-inset relative flex cursor-default items-center gap-2 rounded-sm px-2 py-1.5
|
|
28
|
+
'hover-layer hover-layer-default data-[highlighted]:text-foreground [&_svg:not([class*=\'text-\'])]:text-content-on-surface-muted ui-focus-ring-inset relative flex cursor-default items-center gap-2 rounded-sm px-2 py-1.5 body-14-regular select-none data-[disabled]:pointer-events-none data-[disabled]:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*=\'size-\'])]:size-4',
|
|
29
29
|
props.class,
|
|
30
30
|
)
|
|
31
31
|
"
|
|
@@ -1,19 +1,37 @@
|
|
|
1
1
|
<script setup lang="ts">
|
|
2
2
|
import type { SwitchRootEmits, SwitchRootProps } from 'reka-ui';
|
|
3
|
-
import type
|
|
3
|
+
import { computed, type HTMLAttributes } from 'vue';
|
|
4
4
|
import { reactiveOmit } from '@vueuse/core';
|
|
5
5
|
import { SwitchRoot, SwitchThumb, useForwardPropsEmits } from 'reka-ui';
|
|
6
6
|
import { cn } from '@/lib/utils';
|
|
7
|
+
import {
|
|
8
|
+
switchRootVariants,
|
|
9
|
+
switchThumbVariants,
|
|
10
|
+
type SwitchVariants,
|
|
11
|
+
} from '.';
|
|
7
12
|
|
|
8
13
|
const props = defineProps<
|
|
9
|
-
SwitchRootProps & {
|
|
14
|
+
SwitchRootProps & {
|
|
15
|
+
class?: HTMLAttributes['class'];
|
|
16
|
+
size?: SwitchVariants['size'];
|
|
17
|
+
}
|
|
10
18
|
>();
|
|
11
19
|
|
|
12
20
|
const emits = defineEmits<SwitchRootEmits>();
|
|
13
21
|
|
|
14
|
-
|
|
22
|
+
// `size` only picks the cva variants — `SwitchRoot` renders a `button`, which has
|
|
23
|
+
// no `size` attribute, so forwarding it would leak an invalid attribute.
|
|
24
|
+
const delegatedProps = reactiveOmit(props, 'class', 'size');
|
|
15
25
|
|
|
16
26
|
const forwarded = useForwardPropsEmits(delegatedProps, emits);
|
|
27
|
+
|
|
28
|
+
const switchRootClass = computed(() =>
|
|
29
|
+
cn(switchRootVariants({ size: props.size }), props.class),
|
|
30
|
+
);
|
|
31
|
+
|
|
32
|
+
const switchThumbClass = computed(() =>
|
|
33
|
+
cn(switchThumbVariants({ size: props.size })),
|
|
34
|
+
);
|
|
17
35
|
</script>
|
|
18
36
|
|
|
19
37
|
<template>
|
|
@@ -21,21 +39,9 @@ const forwarded = useForwardPropsEmits(delegatedProps, emits);
|
|
|
21
39
|
#default="slotProps"
|
|
22
40
|
data-slot="switch"
|
|
23
41
|
v-bind="forwarded"
|
|
24
|
-
:class="
|
|
25
|
-
cn(
|
|
26
|
-
'peer data-[state=checked]:bg-background-accent-default data-[state=unchecked]:bg-background-surface-muted-strong ui-focus-ring dark:data-[state=unchecked]:bg-input/80 inline-flex h-[1.15rem] w-8 shrink-0 items-center rounded-full border border-transparent shadow-xs transition-all disabled:cursor-not-allowed disabled:opacity-50 p-0.5 h-5 w-9',
|
|
27
|
-
props.class,
|
|
28
|
-
)
|
|
29
|
-
"
|
|
42
|
+
:class="switchRootClass"
|
|
30
43
|
>
|
|
31
|
-
<SwitchThumb
|
|
32
|
-
data-slot="switch-thumb"
|
|
33
|
-
:class="
|
|
34
|
-
cn(
|
|
35
|
-
'data-[state=checked]:bg-background-accent-soft data-[state=unchecked]:bg-background-surface-secondary dark:data-[state=unchecked]:bg-foreground pointer-events-none block size-4 rounded-full ring-0 transition-transform data-[state=checked]:translate-x-[calc(100%-2px)] data-[state=unchecked]:translate-x-0',
|
|
36
|
-
)
|
|
37
|
-
"
|
|
38
|
-
>
|
|
44
|
+
<SwitchThumb data-slot="switch-thumb" :class="switchThumbClass">
|
|
39
45
|
<slot name="thumb" v-bind="slotProps" />
|
|
40
46
|
</SwitchThumb>
|
|
41
47
|
</SwitchRoot>
|
|
@@ -1 +1,37 @@
|
|
|
1
|
+
import { cva, type VariantProps } from 'class-variance-authority';
|
|
2
|
+
|
|
1
3
|
export { default as Switch } from './Switch.vue';
|
|
4
|
+
|
|
5
|
+
export const switchRootVariants = cva(
|
|
6
|
+
'peer data-[state=checked]:bg-background-accent-default data-[state=unchecked]:bg-background-surface-muted-strong ui-focus-ring dark:data-[state=unchecked]:bg-input/80 inline-flex shrink-0 items-center rounded-full border border-transparent shadow-xs transition-all disabled:cursor-not-allowed disabled:opacity-50',
|
|
7
|
+
{
|
|
8
|
+
variants: {
|
|
9
|
+
size: {
|
|
10
|
+
default: 'h-5 w-9 p-0.5',
|
|
11
|
+
sm: 'h-4 w-7 p-0.25',
|
|
12
|
+
},
|
|
13
|
+
},
|
|
14
|
+
defaultVariants: {
|
|
15
|
+
size: 'default',
|
|
16
|
+
},
|
|
17
|
+
},
|
|
18
|
+
);
|
|
19
|
+
|
|
20
|
+
export const switchThumbVariants = cva(
|
|
21
|
+
'data-[state=checked]:bg-background-accent-soft data-[state=unchecked]:bg-background-surface-secondary dark:data-[state=unchecked]:bg-foreground pointer-events-none block rounded-full ring-0 transition-transform data-[state=unchecked]:translate-x-0',
|
|
22
|
+
{
|
|
23
|
+
variants: {
|
|
24
|
+
// The checked offset is the free space inside the padding box, so it has
|
|
25
|
+
// to be declared per size for the thumb to rest against the far edge.
|
|
26
|
+
size: {
|
|
27
|
+
default: 'size-4 data-[state=checked]:translate-x-[calc(100%-2px)]',
|
|
28
|
+
sm: 'size-3 data-[state=checked]:translate-x-full',
|
|
29
|
+
},
|
|
30
|
+
},
|
|
31
|
+
defaultVariants: {
|
|
32
|
+
size: 'default',
|
|
33
|
+
},
|
|
34
|
+
},
|
|
35
|
+
);
|
|
36
|
+
|
|
37
|
+
export type SwitchVariants = VariantProps<typeof switchRootVariants>;
|
package/src/components/index.ts
CHANGED
package/src/index.ts
CHANGED
|
@@ -9,11 +9,13 @@ export * from './patterns';
|
|
|
9
9
|
export * from './templates';
|
|
10
10
|
export * from './lib/useDevice';
|
|
11
11
|
export * from './lib/useAnchorFloat';
|
|
12
|
+
export * from './lib/scrollbar';
|
|
12
13
|
export * from './directives';
|
|
13
14
|
export { Primitive } from 'reka-ui';
|
|
14
15
|
export type PrimitiveProps = RekaPrimitiveProps;
|
|
15
16
|
|
|
16
17
|
import { vHover } from './directives/vHover';
|
|
18
|
+
import { installScrollbarBehavior } from './lib/scrollbar';
|
|
17
19
|
|
|
18
20
|
/**
|
|
19
21
|
* Vue SFC module shape used by the library installer.
|
|
@@ -46,6 +48,7 @@ const components = import.meta.glob<ComponentModule>(
|
|
|
46
48
|
export default {
|
|
47
49
|
install(app: App) {
|
|
48
50
|
app.directive('hover', vHover);
|
|
51
|
+
installScrollbarBehavior();
|
|
49
52
|
Object.values(components).forEach((component) => {
|
|
50
53
|
const componentName = component.default.__name ?? component.default.name;
|
|
51
54
|
if (componentName) {
|
|
@@ -0,0 +1,295 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Auto-hide behavior for the library scrollbar.
|
|
3
|
+
*
|
|
4
|
+
* The look of the scrollbar (4px thumb, invisible track, reserved 16px lane) is
|
|
5
|
+
* pure CSS and ships with the UnoCSS preset. Only the *timing* rules need a
|
|
6
|
+
* runtime, because CSS has no way to express "one second after the last scroll":
|
|
7
|
+
*
|
|
8
|
+
* | Situation | Thumb |
|
|
9
|
+
* | -------------------------- | ------------------------------------------- |
|
|
10
|
+
* | At rest | Hidden |
|
|
11
|
+
* | Scrolling, incl. keyboard | Visible, fades in quickly |
|
|
12
|
+
* | Scrolling stops | Stays ~1s, then fades out |
|
|
13
|
+
* | Pointer hovering the lane | Visible, stays visible |
|
|
14
|
+
* | Being dragged | Visible until released, even off-element |
|
|
15
|
+
* | Content too short | No thumb, lane stays reserved |
|
|
16
|
+
* | Reduced motion | Appears and disappears instantly, no fade |
|
|
17
|
+
*
|
|
18
|
+
* The fades and the reduced-motion rule are CSS; this module only decides when
|
|
19
|
+
* a scroll container counts as active.
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
/** Set on `<html>` to switch the CSS from always-visible to auto-hide. */
|
|
23
|
+
const AUTO_HIDE_CLASS = 'ui-scrollbar-autohide';
|
|
24
|
+
|
|
25
|
+
/** Set on a scroll container while its thumb should be visible. */
|
|
26
|
+
const VISIBLE_ATTRIBUTE = 'data-ui-scrollbar';
|
|
27
|
+
|
|
28
|
+
const DEFAULT_IDLE_DELAY = 1000;
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Not every browser dispatches pointer events over the scrollbar lane, so the
|
|
32
|
+
* lane hit test reaches a couple of pixels into the content. Without it the
|
|
33
|
+
* last known pointer position can stall just short of the lane.
|
|
34
|
+
*/
|
|
35
|
+
const LANE_HIT_TOLERANCE = 2;
|
|
36
|
+
|
|
37
|
+
export type ScrollbarBehaviorOptions = {
|
|
38
|
+
/** Milliseconds the thumb stays visible after the last scroll. Defaults to 1000. */
|
|
39
|
+
idleDelay?: number;
|
|
40
|
+
/** Document to attach the listeners to. Defaults to the ambient `document`. */
|
|
41
|
+
document?: Document;
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
/** Teardown handles, keyed by document, so installing twice is a no-op. */
|
|
45
|
+
const installations = new WeakMap<Document, () => void>();
|
|
46
|
+
|
|
47
|
+
/** Teardown returned when there is nothing to install, e.g. during SSR. */
|
|
48
|
+
const noopTeardown = () => undefined;
|
|
49
|
+
|
|
50
|
+
function isElement(value: unknown): value is Element {
|
|
51
|
+
return (
|
|
52
|
+
typeof value === 'object' &&
|
|
53
|
+
value !== null &&
|
|
54
|
+
(value as Node).nodeType === 1
|
|
55
|
+
);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function readPx(value: string): number {
|
|
59
|
+
const parsed = Number.parseFloat(value);
|
|
60
|
+
return Number.isFinite(parsed) ? parsed : 0;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Installs the scroll, hover, and drag listeners that reveal and hide scrollbar
|
|
65
|
+
* thumbs, and puts the document into auto-hide mode.
|
|
66
|
+
*
|
|
67
|
+
* The library's Vue plugin calls this for you. Call it directly when you
|
|
68
|
+
* register components individually instead of installing the plugin. Safe to
|
|
69
|
+
* call during SSR and safe to call more than once per document.
|
|
70
|
+
* @param options Idle delay and target document overrides.
|
|
71
|
+
* @returns Teardown that removes the listeners and restores always-visible thumbs.
|
|
72
|
+
*/
|
|
73
|
+
export function installScrollbarBehavior(
|
|
74
|
+
options: ScrollbarBehaviorOptions = {},
|
|
75
|
+
): () => void {
|
|
76
|
+
const doc =
|
|
77
|
+
options.document ?? (typeof document === 'undefined' ? null : document);
|
|
78
|
+
const win = doc?.defaultView;
|
|
79
|
+
if (!doc || !win) return noopTeardown;
|
|
80
|
+
|
|
81
|
+
return (
|
|
82
|
+
installations.get(doc) ??
|
|
83
|
+
install(doc, win, options.idleDelay ?? DEFAULT_IDLE_DELAY)
|
|
84
|
+
);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
function install(
|
|
88
|
+
doc: Document,
|
|
89
|
+
win: Window & typeof globalThis,
|
|
90
|
+
idleDelay: number,
|
|
91
|
+
): () => void {
|
|
92
|
+
const root = doc.documentElement;
|
|
93
|
+
|
|
94
|
+
const hideTimers = new WeakMap<Element, number>();
|
|
95
|
+
/** Containers whose lane the pointer is currently over. */
|
|
96
|
+
const hovered = new Set<Element>();
|
|
97
|
+
/** Containers whose thumb is currently being dragged. */
|
|
98
|
+
const dragged = new Set<Element>();
|
|
99
|
+
|
|
100
|
+
let pointerX = Number.NaN;
|
|
101
|
+
let pointerY = Number.NaN;
|
|
102
|
+
let frame = 0;
|
|
103
|
+
|
|
104
|
+
function isHeld(element: Element) {
|
|
105
|
+
return hovered.has(element) || dragged.has(element);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
function clearTimer(element: Element) {
|
|
109
|
+
const timer = hideTimers.get(element);
|
|
110
|
+
if (timer !== undefined) {
|
|
111
|
+
win.clearTimeout(timer);
|
|
112
|
+
hideTimers.delete(element);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
function reveal(element: Element) {
|
|
117
|
+
clearTimer(element);
|
|
118
|
+
element.setAttribute(VISIBLE_ATTRIBUTE, 'visible');
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
function scheduleHide(element: Element) {
|
|
122
|
+
clearTimer(element);
|
|
123
|
+
if (isHeld(element)) return;
|
|
124
|
+
|
|
125
|
+
hideTimers.set(
|
|
126
|
+
element,
|
|
127
|
+
win.setTimeout(() => {
|
|
128
|
+
hideTimers.delete(element);
|
|
129
|
+
if (!isHeld(element)) element.removeAttribute(VISIBLE_ATTRIBUTE);
|
|
130
|
+
}, idleDelay),
|
|
131
|
+
);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* True when the point sits in the strip of layout the scrollbar occupies.
|
|
136
|
+
* `offsetWidth - clientWidth` minus the borders is exactly the lane width, so
|
|
137
|
+
* this stays correct whatever the lane is sized to.
|
|
138
|
+
* @param element Candidate scroll container.
|
|
139
|
+
* @param x Viewport x coordinate.
|
|
140
|
+
* @param y Viewport y coordinate.
|
|
141
|
+
* @returns Whether the point is over the element's vertical or horizontal lane.
|
|
142
|
+
*/
|
|
143
|
+
function isOnLane(element: Element, x: number, y: number): boolean {
|
|
144
|
+
let top: number;
|
|
145
|
+
let right: number;
|
|
146
|
+
let bottom: number;
|
|
147
|
+
let left: number;
|
|
148
|
+
let verticalLane: number;
|
|
149
|
+
let horizontalLane: number;
|
|
150
|
+
|
|
151
|
+
if (element === root) {
|
|
152
|
+
top = 0;
|
|
153
|
+
right = win.innerWidth;
|
|
154
|
+
bottom = win.innerHeight;
|
|
155
|
+
left = 0;
|
|
156
|
+
verticalLane = win.innerWidth - root.clientWidth;
|
|
157
|
+
horizontalLane = win.innerHeight - root.clientHeight;
|
|
158
|
+
} else {
|
|
159
|
+
if (!(element instanceof win.HTMLElement)) return false;
|
|
160
|
+
|
|
161
|
+
const rect = element.getBoundingClientRect();
|
|
162
|
+
const style = win.getComputedStyle(element);
|
|
163
|
+
const borderTop = readPx(style.borderTopWidth);
|
|
164
|
+
const borderRight = readPx(style.borderRightWidth);
|
|
165
|
+
const borderBottom = readPx(style.borderBottomWidth);
|
|
166
|
+
const borderLeft = readPx(style.borderLeftWidth);
|
|
167
|
+
|
|
168
|
+
top = rect.top + borderTop;
|
|
169
|
+
right = rect.right - borderRight;
|
|
170
|
+
bottom = rect.bottom - borderBottom;
|
|
171
|
+
left = rect.left + borderLeft;
|
|
172
|
+
verticalLane =
|
|
173
|
+
element.offsetWidth - element.clientWidth - borderLeft - borderRight;
|
|
174
|
+
horizontalLane =
|
|
175
|
+
element.offsetHeight - element.clientHeight - borderTop - borderBottom;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
const isRtl = win.getComputedStyle(element).direction === 'rtl';
|
|
179
|
+
const onVerticalLane =
|
|
180
|
+
verticalLane > 0 &&
|
|
181
|
+
y >= top &&
|
|
182
|
+
y <= bottom &&
|
|
183
|
+
(isRtl
|
|
184
|
+
? x >= left - LANE_HIT_TOLERANCE && x <= left + verticalLane
|
|
185
|
+
: x >= right - verticalLane - LANE_HIT_TOLERANCE && x <= right);
|
|
186
|
+
const onHorizontalLane =
|
|
187
|
+
horizontalLane > 0 &&
|
|
188
|
+
x >= left &&
|
|
189
|
+
x <= right &&
|
|
190
|
+
y >= bottom - horizontalLane - LANE_HIT_TOLERANCE &&
|
|
191
|
+
y <= bottom;
|
|
192
|
+
|
|
193
|
+
return onVerticalLane || onHorizontalLane;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
function collectLanesAt(x: number, y: number): Set<Element> {
|
|
197
|
+
const found = new Set<Element>();
|
|
198
|
+
if (Number.isNaN(x) || Number.isNaN(y)) return found;
|
|
199
|
+
|
|
200
|
+
for (const element of [...doc.elementsFromPoint(x, y), root]) {
|
|
201
|
+
if (isOnLane(element, x, y)) found.add(element);
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
return found;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
function syncHoveredLanes() {
|
|
208
|
+
frame = 0;
|
|
209
|
+
const next = collectLanesAt(pointerX, pointerY);
|
|
210
|
+
|
|
211
|
+
for (const element of hovered) {
|
|
212
|
+
if (next.has(element)) continue;
|
|
213
|
+
hovered.delete(element);
|
|
214
|
+
scheduleHide(element);
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
for (const element of next) {
|
|
218
|
+
if (hovered.has(element)) continue;
|
|
219
|
+
hovered.add(element);
|
|
220
|
+
reveal(element);
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
function onScroll(event: Event) {
|
|
225
|
+
const target = event.target;
|
|
226
|
+
const scroller = isElement(target) ? target : root;
|
|
227
|
+
reveal(scroller);
|
|
228
|
+
scheduleHide(scroller);
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
function onPointerMove(event: PointerEvent) {
|
|
232
|
+
pointerX = event.clientX;
|
|
233
|
+
pointerY = event.clientY;
|
|
234
|
+
if (frame) return;
|
|
235
|
+
frame = win.requestAnimationFrame(syncHoveredLanes);
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
function onPointerDown(event: PointerEvent) {
|
|
239
|
+
for (const element of collectLanesAt(event.clientX, event.clientY)) {
|
|
240
|
+
dragged.add(element);
|
|
241
|
+
reveal(element);
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
function onPointerUp() {
|
|
246
|
+
for (const element of dragged) scheduleHide(element);
|
|
247
|
+
dragged.clear();
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
function onPointerLeave() {
|
|
251
|
+
pointerX = Number.NaN;
|
|
252
|
+
pointerY = Number.NaN;
|
|
253
|
+
for (const element of hovered) scheduleHide(element);
|
|
254
|
+
hovered.clear();
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
root.classList.add(AUTO_HIDE_CLASS);
|
|
258
|
+
doc.addEventListener('scroll', onScroll, { capture: true, passive: true });
|
|
259
|
+
win.addEventListener('pointermove', onPointerMove, {
|
|
260
|
+
capture: true,
|
|
261
|
+
passive: true,
|
|
262
|
+
});
|
|
263
|
+
win.addEventListener('pointerdown', onPointerDown, {
|
|
264
|
+
capture: true,
|
|
265
|
+
passive: true,
|
|
266
|
+
});
|
|
267
|
+
win.addEventListener('pointerup', onPointerUp, { capture: true });
|
|
268
|
+
win.addEventListener('pointercancel', onPointerUp, { capture: true });
|
|
269
|
+
win.addEventListener('blur', onPointerUp);
|
|
270
|
+
doc.addEventListener('pointerleave', onPointerLeave);
|
|
271
|
+
|
|
272
|
+
const uninstall = () => {
|
|
273
|
+
installations.delete(doc);
|
|
274
|
+
doc.removeEventListener('scroll', onScroll, { capture: true });
|
|
275
|
+
win.removeEventListener('pointermove', onPointerMove, { capture: true });
|
|
276
|
+
win.removeEventListener('pointerdown', onPointerDown, { capture: true });
|
|
277
|
+
win.removeEventListener('pointerup', onPointerUp, { capture: true });
|
|
278
|
+
win.removeEventListener('pointercancel', onPointerUp, { capture: true });
|
|
279
|
+
win.removeEventListener('blur', onPointerUp);
|
|
280
|
+
doc.removeEventListener('pointerleave', onPointerLeave);
|
|
281
|
+
|
|
282
|
+
if (frame) win.cancelAnimationFrame(frame);
|
|
283
|
+
for (const element of [...hovered, ...dragged]) clearTimer(element);
|
|
284
|
+
hovered.clear();
|
|
285
|
+
dragged.clear();
|
|
286
|
+
|
|
287
|
+
for (const element of doc.querySelectorAll(`[${VISIBLE_ATTRIBUTE}]`)) {
|
|
288
|
+
element.removeAttribute(VISIBLE_ATTRIBUTE);
|
|
289
|
+
}
|
|
290
|
+
root.classList.remove(AUTO_HIDE_CLASS);
|
|
291
|
+
};
|
|
292
|
+
|
|
293
|
+
installations.set(doc, uninstall);
|
|
294
|
+
return uninstall;
|
|
295
|
+
}
|
|
@@ -33,7 +33,6 @@ export interface AnchorFloatOffset {
|
|
|
33
33
|
|
|
34
34
|
/**
|
|
35
35
|
* Options for {@link useAnchorFloat}.
|
|
36
|
-
*
|
|
37
36
|
* @category Composables
|
|
38
37
|
* @useCases contextual toolbar positioning, custom floating panels
|
|
39
38
|
* @keywords float, anchor, floating-ui, composable, positioning
|
|
@@ -124,7 +123,6 @@ function resolveOffset(value: number | AnchorFloatOffset | undefined) {
|
|
|
124
123
|
*
|
|
125
124
|
* Prefer {@link UiFloatActions} for the standard component API. Use this composable
|
|
126
125
|
* when you need full control over markup, animation, or teleport targets.
|
|
127
|
-
*
|
|
128
126
|
* @param options - Trigger, placement, offset, and dismiss behaviour.
|
|
129
127
|
* @returns Refs, computed styles, open state, and event handlers to wire up
|
|
130
128
|
* anchor and floating elements manually.
|