@aleph-alpha/ui-library 5.7.0 → 5.8.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 +4 -0
- package/config.d.ts +5 -1
- package/config.js +18 -1
- package/dist/system/components/UiBreadcrumb/UiBreadcrumb.vue.d.ts +17 -0
- package/dist/system/components/UiBreadcrumb/UiBreadcrumbEllipsis.vue.d.ts +17 -0
- package/dist/system/components/UiBreadcrumb/UiBreadcrumbItem.vue.d.ts +17 -0
- package/dist/system/components/UiBreadcrumb/UiBreadcrumbLink.vue.d.ts +18 -0
- package/dist/system/components/UiBreadcrumb/UiBreadcrumbList.vue.d.ts +17 -0
- package/dist/system/components/UiBreadcrumb/UiBreadcrumbPage.vue.d.ts +17 -0
- package/dist/system/components/UiBreadcrumb/UiBreadcrumbSeparator.vue.d.ts +17 -0
- package/dist/system/components/UiBreadcrumb/index.d.ts +8 -0
- package/dist/system/components/UiBreadcrumb/types.d.ts +22 -0
- package/dist/system/components/UiToggleGroup/types.d.ts +0 -5
- package/dist/system/components/core/breadcrumb/Breadcrumb.vue.d.ts +21 -0
- package/dist/system/components/core/breadcrumb/BreadcrumbEllipsis.vue.d.ts +21 -0
- package/dist/system/components/core/breadcrumb/BreadcrumbItem.vue.d.ts +21 -0
- package/dist/system/components/core/breadcrumb/BreadcrumbLink.vue.d.ts +24 -0
- package/dist/system/components/core/breadcrumb/BreadcrumbList.vue.d.ts +21 -0
- package/dist/system/components/core/breadcrumb/BreadcrumbPage.vue.d.ts +21 -0
- package/dist/system/components/core/breadcrumb/BreadcrumbSeparator.vue.d.ts +21 -0
- package/dist/system/components/core/breadcrumb/index.d.ts +7 -0
- package/dist/system/components/core/listbox/Listbox.vue.d.ts +28 -2
- package/dist/system/components/core/listbox/context.d.ts +21 -0
- package/dist/system/components/index.d.ts +1 -0
- package/dist/system/lib.js +10057 -9707
- package/dist/system/patterns/UiDatePicker/UiDatePicker.vue.d.ts +1 -1
- package/dist/system/story-sidebar-icons.json +6 -0
- package/package.json +2 -2
- package/src/components/UiBreadcrumb/UiBreadcrumb.stories.ts +1419 -0
- package/src/components/UiBreadcrumb/UiBreadcrumb.vue +19 -0
- package/src/components/UiBreadcrumb/UiBreadcrumbEllipsis.vue +22 -0
- package/src/components/UiBreadcrumb/UiBreadcrumbItem.vue +19 -0
- package/src/components/UiBreadcrumb/UiBreadcrumbLink.vue +26 -0
- package/src/components/UiBreadcrumb/UiBreadcrumbList.vue +19 -0
- package/src/components/UiBreadcrumb/UiBreadcrumbPage.vue +19 -0
- package/src/components/UiBreadcrumb/UiBreadcrumbSeparator.vue +22 -0
- package/src/components/UiBreadcrumb/index.ts +8 -0
- package/src/components/UiBreadcrumb/types.ts +28 -0
- package/src/components/UiDropdownMenu/UiDropdownMenuTrigger.vue +2 -0
- package/src/components/UiListbox/UiListbox.stories.ts +1283 -30
- package/src/components/UiListbox/__tests__/UiListbox.test.ts +70 -35
- package/src/components/UiSwitch/UiSwitch.stories.ts +706 -9
- package/src/components/UiSwitch/__tests__/UiSwitch.test.ts +2 -6
- package/src/components/UiToggle/UiToggle.stories.ts +961 -130
- package/src/components/UiToggle/UiToggle.vue +8 -1
- package/src/components/UiToggle/__tests__/UiToggle.test.ts +55 -65
- package/src/components/UiToggleGroup/UiToggleGroup.stories.ts +1060 -173
- package/src/components/UiToggleGroup/UiToggleGroup.vue +4 -2
- package/src/components/UiToggleGroup/__tests__/UiToggleGroup.test.ts +117 -325
- package/src/components/UiToggleGroup/types.ts +0 -5
- package/src/components/core/breadcrumb/Breadcrumb.vue +13 -0
- package/src/components/core/breadcrumb/BreadcrumbEllipsis.vue +23 -0
- package/src/components/core/breadcrumb/BreadcrumbItem.vue +17 -0
- package/src/components/core/breadcrumb/BreadcrumbLink.vue +29 -0
- package/src/components/core/breadcrumb/BreadcrumbList.vue +22 -0
- package/src/components/core/breadcrumb/BreadcrumbPage.vue +20 -0
- package/src/components/core/breadcrumb/BreadcrumbSeparator.vue +22 -0
- package/src/components/core/breadcrumb/index.ts +7 -0
- package/src/components/core/listbox/Listbox.vue +14 -2
- package/src/components/core/listbox/ListboxContent.vue +61 -3
- package/src/components/core/listbox/ListboxItem.vue +6 -1
- package/src/components/core/listbox/context.ts +34 -0
- package/src/components/core/toggle/Toggle.vue +15 -1
- package/src/components/core/toggle/index.ts +2 -2
- package/src/components/core/toggle-group/ToggleGroup.vue +1 -1
- package/src/components/core/toggle-group/index.ts +5 -2
- package/src/components/index.ts +1 -0
|
@@ -16,7 +16,14 @@ const props = withDefaults(defineProps<UiToggleProps>(), {
|
|
|
16
16
|
rightIcon: undefined,
|
|
17
17
|
});
|
|
18
18
|
|
|
19
|
-
|
|
19
|
+
/**
|
|
20
|
+
* Vue casts an absent prop whose declared type is Boolean to `false`, so a bare
|
|
21
|
+
* `defineModel<boolean>()` would hand reka a defined `model-value` even when no
|
|
22
|
+
* `v-model` is bound. That pins the toggle into controlled mode and makes it
|
|
23
|
+
* ignore `defaultValue`. An explicit default keeps the prop `undefined` when it
|
|
24
|
+
* is not bound, so the uncontrolled path stays available.
|
|
25
|
+
*/
|
|
26
|
+
const modelValue = defineModel<boolean>({ default: undefined });
|
|
20
27
|
|
|
21
28
|
function handleUpdateModelValue(value: boolean) {
|
|
22
29
|
if (props.active !== undefined) return;
|
|
@@ -1,111 +1,101 @@
|
|
|
1
1
|
import { render } from '@testing-library/vue';
|
|
2
|
+
import userEvent from '@testing-library/user-event';
|
|
2
3
|
import { describe, expect, test } from 'vitest';
|
|
3
4
|
import UiToggle from '../UiToggle.vue';
|
|
4
5
|
|
|
5
6
|
describe('UiToggle', () => {
|
|
6
|
-
test('
|
|
7
|
+
test('exposes its unpressed state to assistive technology', () => {
|
|
7
8
|
const { getByRole } = render(UiToggle, {
|
|
8
9
|
slots: { default: 'Toggle' },
|
|
9
10
|
});
|
|
10
|
-
expect(getByRole('button')).
|
|
11
|
+
expect(getByRole('button')).toHaveAttribute('aria-pressed', 'false');
|
|
11
12
|
});
|
|
12
13
|
|
|
13
|
-
test('
|
|
14
|
-
const
|
|
14
|
+
test('toggles the pressed state and emits the new value', async () => {
|
|
15
|
+
const user = userEvent.setup();
|
|
16
|
+
const { getByRole, emitted } = render(UiToggle, {
|
|
15
17
|
slots: { default: 'Toggle' },
|
|
16
18
|
});
|
|
17
|
-
const toggle =
|
|
18
|
-
expect(toggle).toBeInTheDocument();
|
|
19
|
-
});
|
|
19
|
+
const toggle = getByRole('button');
|
|
20
20
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
});
|
|
25
|
-
expect(getByRole('button')).toHaveAttribute('data-state', 'off');
|
|
26
|
-
});
|
|
21
|
+
await user.click(toggle);
|
|
22
|
+
expect(toggle).toHaveAttribute('aria-pressed', 'true');
|
|
23
|
+
expect(emitted('update:modelValue')).toEqual([[true]]);
|
|
27
24
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
slots: { default: 'Toggle' },
|
|
32
|
-
});
|
|
33
|
-
expect(getByRole('button')).toHaveAttribute('data-state', 'on');
|
|
25
|
+
await user.click(toggle);
|
|
26
|
+
expect(toggle).toHaveAttribute('aria-pressed', 'false');
|
|
27
|
+
expect(emitted('update:modelValue')).toEqual([[true], [false]]);
|
|
34
28
|
});
|
|
35
29
|
|
|
36
|
-
|
|
30
|
+
// `defineModel<boolean>()` alone leaves Vue casting the absent prop to
|
|
31
|
+
// `false`, which pins the toggle to controlled mode and silently drops
|
|
32
|
+
// `defaultValue`.
|
|
33
|
+
test('starts pressed when defaultValue is set', () => {
|
|
37
34
|
const { getByRole } = render(UiToggle, {
|
|
35
|
+
props: { defaultValue: true },
|
|
38
36
|
slots: { default: 'Toggle' },
|
|
39
37
|
});
|
|
40
|
-
expect(getByRole('button')).
|
|
41
|
-
'hover:bg-background-surface-muted-subtle',
|
|
42
|
-
);
|
|
38
|
+
expect(getByRole('button')).toHaveAttribute('aria-pressed', 'true');
|
|
43
39
|
});
|
|
44
40
|
|
|
45
|
-
test('
|
|
46
|
-
const
|
|
41
|
+
test('lets active override the pressed state without self-updating', async () => {
|
|
42
|
+
const user = userEvent.setup();
|
|
43
|
+
const { getByRole, emitted } = render(UiToggle, {
|
|
44
|
+
props: { active: true },
|
|
47
45
|
slots: { default: 'Toggle' },
|
|
48
46
|
});
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
47
|
+
const toggle = getByRole('button');
|
|
48
|
+
expect(toggle).toHaveAttribute('aria-pressed', 'true');
|
|
49
|
+
|
|
50
|
+
// The owner of `active` decides the next state, so the click must not
|
|
51
|
+
// move the toggle on its own.
|
|
52
|
+
await user.click(toggle);
|
|
53
|
+
expect(toggle).toHaveAttribute('aria-pressed', 'true');
|
|
54
|
+
expect(emitted('update:modelValue')).toBeUndefined();
|
|
53
55
|
});
|
|
54
56
|
|
|
55
|
-
test('
|
|
56
|
-
const
|
|
57
|
+
test('does not change state when disabled', async () => {
|
|
58
|
+
const user = userEvent.setup();
|
|
59
|
+
const { getByRole, emitted } = render(UiToggle, {
|
|
57
60
|
props: { disabled: true },
|
|
58
61
|
slots: { default: 'Toggle' },
|
|
59
62
|
});
|
|
60
|
-
|
|
61
|
-
|
|
63
|
+
const toggle = getByRole('button');
|
|
64
|
+
expect(toggle).toBeDisabled();
|
|
62
65
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
slots: { default: 'Toggle' },
|
|
67
|
-
});
|
|
68
|
-
const toggle = container.querySelector('button');
|
|
69
|
-
expect(toggle).toHaveClass('border');
|
|
66
|
+
await user.click(toggle);
|
|
67
|
+
expect(toggle).toHaveAttribute('aria-pressed', 'false');
|
|
68
|
+
expect(emitted('update:modelValue')).toBeUndefined();
|
|
70
69
|
});
|
|
71
70
|
|
|
72
|
-
test('
|
|
73
|
-
const {
|
|
71
|
+
test('maps the variant prop to its fill', () => {
|
|
72
|
+
const { getByRole } = render(UiToggle, {
|
|
74
73
|
props: { variant: 'soft' },
|
|
75
74
|
slots: { default: 'Toggle' },
|
|
76
75
|
});
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
expect(toggle).toHaveClass('border-border-button-outlined');
|
|
80
|
-
expect(toggle).toHaveClass('data-[state=on]:bg-background-accent-soft');
|
|
81
|
-
expect(toggle).toHaveClass('data-[state=on]:text-content-on-accent-soft');
|
|
82
|
-
expect(toggle).toHaveClass('data-[state=on]:border-background-accent-soft');
|
|
83
|
-
expect(toggle).toHaveClass('data-[state=open]:bg-background-accent-soft');
|
|
84
|
-
expect(toggle).toHaveClass('data-[state=open]:text-content-on-accent-soft');
|
|
85
|
-
expect(toggle).toHaveClass(
|
|
86
|
-
'data-[state=open]:border-background-accent-soft',
|
|
76
|
+
expect(getByRole('button')).toHaveClass(
|
|
77
|
+
'data-[state=on]:bg-background-accent-soft',
|
|
87
78
|
);
|
|
88
|
-
expect(toggle).toHaveClass('aria-pressed:bg-background-accent-soft');
|
|
89
|
-
expect(toggle).toHaveClass('aria-pressed:text-content-on-accent-soft');
|
|
90
|
-
expect(toggle).toHaveClass('aria-pressed:border-background-accent-soft');
|
|
91
79
|
});
|
|
92
80
|
|
|
93
|
-
test('
|
|
94
|
-
const {
|
|
95
|
-
props: { size: '
|
|
81
|
+
test('maps the size prop to its height', () => {
|
|
82
|
+
const { getByRole } = render(UiToggle, {
|
|
83
|
+
props: { size: 'lg' },
|
|
96
84
|
slots: { default: 'Toggle' },
|
|
97
85
|
});
|
|
98
|
-
|
|
99
|
-
expect(toggle).toHaveClass('h-8');
|
|
86
|
+
expect(getByRole('button')).toHaveClass('h-10');
|
|
100
87
|
});
|
|
101
88
|
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
89
|
+
// `variant` and `size` are styling-only, so forwarding them to reka would
|
|
90
|
+
// land them on the button as invalid HTML attributes.
|
|
91
|
+
test('keeps styling props off the rendered button', () => {
|
|
92
|
+
const { getByRole } = render(UiToggle, {
|
|
93
|
+
props: { variant: 'outline', size: 'sm' },
|
|
105
94
|
slots: { default: 'Toggle' },
|
|
106
95
|
});
|
|
107
|
-
const toggle =
|
|
108
|
-
expect(toggle).
|
|
96
|
+
const toggle = getByRole('button');
|
|
97
|
+
expect(toggle).not.toHaveAttribute('variant');
|
|
98
|
+
expect(toggle).not.toHaveAttribute('size');
|
|
109
99
|
});
|
|
110
100
|
|
|
111
101
|
test('renders left and right icons', () => {
|