@aleph-alpha/ui-library 6.0.0 → 6.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/config.d.ts +28 -4
- package/config.js +141 -23
- package/dist/system/components/UiTagsInput/UiTagsInput.vue.d.ts +2 -0
- package/dist/system/components/UiTagsInput/UiTagsInputItemDelete.vue.d.ts +2 -1
- package/dist/system/components/UiTagsInput/types.d.ts +21 -2
- package/dist/system/components/core/sidebar/utils.d.ts +9 -0
- package/dist/system/components/core/tags-input/TagsInputItemDelete.vue.d.ts +5 -0
- package/dist/system/icons/story-sidebar-icons.json +8 -0
- package/dist/system/lib.js +6106 -5997
- package/dist/system/patterns/UiLayout/UiLayoutContent.vue.d.ts +39 -0
- package/dist/system/patterns/UiLayout/index.d.ts +2 -0
- package/dist/system/patterns/UiLayout/layout-shell.d.ts +944 -0
- package/dist/system/patterns/UiLayout/types.d.ts +43 -0
- package/dist/system/patterns/index.d.ts +1 -0
- package/dist/system/story-sidebar-icons.json +8 -0
- package/docs/public-docs/migration-guide.md +402 -0
- package/docs/public-docs/quick-start.md +19 -10
- package/package.json +7 -4
- package/src/components/UiAlert/UiAlert.stories.ts +732 -0
- package/src/components/UiAlert/__tests__/UiAlert.test.ts +57 -11
- package/src/components/UiChip/UiChip.stories.ts +756 -2
- package/src/components/UiChip/UiChip.vue +7 -6
- package/src/components/UiChip/__tests__/UiChip.test.ts +38 -61
- package/src/components/UiDrawer/UiDrawer.stories.ts +665 -0
- package/src/components/UiDrawer/__tests__/UiDrawer.test.ts +6 -190
- package/src/components/UiLabel/UiLabel.stories.ts +691 -16
- package/src/components/UiLabel/__tests__/UiLabel.test.ts +18 -26
- package/src/components/UiSheet/UiSheet.stories.ts +751 -0
- package/src/components/UiSheet/__tests__/UiSheet.test.ts +6 -190
- package/src/components/UiSlider/UiSlider.stories.ts +716 -0
- package/src/components/UiSlider/__tests__/UiSlider.test.ts +8 -45
- package/src/components/UiSwitch/UiSwitch.stories.ts +11 -5
- package/src/components/UiTagsInput/UiTagsInput.stories.ts +850 -4
- package/src/components/UiTagsInput/UiTagsInput.vue +34 -0
- package/src/components/UiTagsInput/UiTagsInputItemDelete.vue +4 -1
- package/src/components/UiTagsInput/__tests__/UiTagsInput.test.ts +113 -29
- package/src/components/UiTagsInput/types.ts +24 -2
- package/src/components/core/sheet/SheetContent.vue +6 -1
- package/src/components/core/sidebar/Sidebar.vue +21 -5
- package/src/components/core/sidebar/utils.ts +10 -0
- package/src/components/core/switch/index.ts +8 -7
- package/src/components/core/tags-input/TagsInput.vue +4 -1
- package/src/components/core/tags-input/TagsInputItem.vue +13 -1
- package/src/components/core/tags-input/TagsInputItemDelete.vue +40 -7
- package/src/patterns/UiLayout/UiLayoutContent.stories.ts +1234 -0
- package/src/patterns/UiLayout/UiLayoutContent.vue +98 -0
- package/src/patterns/UiLayout/__tests__/UiLayoutContent.test.ts +97 -0
- package/src/patterns/UiLayout/index.ts +2 -0
- package/src/patterns/UiLayout/layout-shell.ts +64 -15
- package/src/patterns/UiLayout/types.ts +44 -0
- package/src/patterns/index.ts +1 -0
- package/src/theme/Typography.stories.ts +125 -133
- package/tokens.json +8132 -2475
- package/dist/system/icons/mobile-device-frame.png +0 -0
- package/dist/system/mobile-device-frame.png +0 -0
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
<script setup lang="ts">
|
|
2
2
|
import { TagsInput as ShadcnTagsInput } from '@/components/core/tags-input';
|
|
3
|
+
import { ref, watch } from 'vue';
|
|
3
4
|
import { type UiTagsInputProps } from './types';
|
|
4
5
|
|
|
5
6
|
defineOptions({
|
|
@@ -8,13 +9,46 @@ defineOptions({
|
|
|
8
9
|
|
|
9
10
|
const props = withDefaults(defineProps<UiTagsInputProps>(), {
|
|
10
11
|
disabled: false,
|
|
12
|
+
addedLabel: 'added',
|
|
13
|
+
removedLabel: 'removed',
|
|
11
14
|
});
|
|
12
15
|
|
|
13
16
|
const model = defineModel<string[]>({ default: [] });
|
|
17
|
+
|
|
18
|
+
/*
|
|
19
|
+
* Adding or removing a tag only changes the DOM — nothing moves focus and the
|
|
20
|
+
* input is cleared silently, so a screen reader user gets no confirmation that
|
|
21
|
+
* their entry was accepted. This polite live region announces the change.
|
|
22
|
+
* It is `sr-only` (absolutely positioned), so it adds no gap to the flex row.
|
|
23
|
+
*/
|
|
24
|
+
const announcement = ref('');
|
|
25
|
+
|
|
26
|
+
watch(
|
|
27
|
+
() => model.value.slice(),
|
|
28
|
+
(next, previous = []) => {
|
|
29
|
+
const removed = [...previous];
|
|
30
|
+
const added: string[] = [];
|
|
31
|
+
for (const value of next) {
|
|
32
|
+
const index = removed.indexOf(value);
|
|
33
|
+
if (index >= 0) removed.splice(index, 1);
|
|
34
|
+
else added.push(value);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const changes = [
|
|
38
|
+
...added.map((value) => `${value} ${props.addedLabel}`),
|
|
39
|
+
...removed.map((value) => `${value} ${props.removedLabel}`),
|
|
40
|
+
];
|
|
41
|
+
|
|
42
|
+
if (changes.length > 0) announcement.value = changes.join(', ');
|
|
43
|
+
},
|
|
44
|
+
);
|
|
14
45
|
</script>
|
|
15
46
|
|
|
16
47
|
<template>
|
|
17
48
|
<ShadcnTagsInput #default="slotProps" v-model="model" v-bind="props">
|
|
18
49
|
<slot v-bind="slotProps" />
|
|
50
|
+
<span class="sr-only" role="status" aria-live="polite" aria-atomic="true">
|
|
51
|
+
{{ announcement }}
|
|
52
|
+
</span>
|
|
19
53
|
</ShadcnTagsInput>
|
|
20
54
|
</template>
|
|
@@ -1,13 +1,16 @@
|
|
|
1
1
|
<script setup lang="ts">
|
|
2
2
|
import { TagsInputItemDelete as ShadcnTagsInputItemDelete } from '@/components/core/tags-input';
|
|
3
|
+
import { type UiTagsInputItemDeleteProps } from './types';
|
|
3
4
|
|
|
4
5
|
defineOptions({
|
|
5
6
|
name: 'UiTagsInputItemDelete',
|
|
6
7
|
});
|
|
8
|
+
|
|
9
|
+
const props = defineProps<UiTagsInputItemDeleteProps>();
|
|
7
10
|
</script>
|
|
8
11
|
|
|
9
12
|
<template>
|
|
10
|
-
<ShadcnTagsInputItemDelete>
|
|
13
|
+
<ShadcnTagsInputItemDelete v-bind="props">
|
|
11
14
|
<slot />
|
|
12
15
|
</ShadcnTagsInputItemDelete>
|
|
13
16
|
</template>
|
|
@@ -1,48 +1,132 @@
|
|
|
1
1
|
import { render } from '@testing-library/vue';
|
|
2
2
|
import { describe, expect, test } from 'vitest';
|
|
3
|
+
import { nextTick } from 'vue';
|
|
3
4
|
import UiTagsInput from '../UiTagsInput.vue';
|
|
4
5
|
import UiTagsInputInput from '../UiTagsInputInput.vue';
|
|
5
6
|
import UiTagsInputItem from '../UiTagsInputItem.vue';
|
|
6
|
-
import UiTagsInputItemText from '../UiTagsInputItemText.vue';
|
|
7
7
|
import UiTagsInputItemDelete from '../UiTagsInputItemDelete.vue';
|
|
8
|
+
import UiTagsInputItemText from '../UiTagsInputItemText.vue';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Renders the full composition the way consumers do, with the tag list driven
|
|
12
|
+
* by the model.
|
|
13
|
+
* @param modelValue Initial tags.
|
|
14
|
+
* @param disabled Whether the whole field is disabled.
|
|
15
|
+
* @returns The testing-library render result.
|
|
16
|
+
*/
|
|
17
|
+
function renderTagsInput(modelValue: string[], disabled = false) {
|
|
18
|
+
return render({
|
|
19
|
+
components: {
|
|
20
|
+
UiTagsInput,
|
|
21
|
+
UiTagsInputInput,
|
|
22
|
+
UiTagsInputItem,
|
|
23
|
+
UiTagsInputItemText,
|
|
24
|
+
UiTagsInputItemDelete,
|
|
25
|
+
},
|
|
26
|
+
setup: () => ({ modelValue, disabled }),
|
|
27
|
+
template: `
|
|
28
|
+
<UiTagsInput :model-value="modelValue" :disabled="disabled">
|
|
29
|
+
<UiTagsInputItem v-for="item in modelValue" :key="item" :value="item">
|
|
30
|
+
<UiTagsInputItemText />
|
|
31
|
+
<UiTagsInputItemDelete />
|
|
32
|
+
</UiTagsInputItem>
|
|
33
|
+
<UiTagsInputInput placeholder="Add..." />
|
|
34
|
+
</UiTagsInput>
|
|
35
|
+
`,
|
|
36
|
+
});
|
|
37
|
+
}
|
|
8
38
|
|
|
39
|
+
// Adding, removing, keyboard operation, target sizes, and the live-region
|
|
40
|
+
// announcements are covered by the play functions in `UiTagsInput.stories.ts`,
|
|
41
|
+
// where a real browser drives reka's keyboard model. What stays here is the
|
|
42
|
+
// naming and announcement wiring, which is pure output of our wrappers.
|
|
9
43
|
describe('UiTagsInput', () => {
|
|
10
|
-
test('
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
},
|
|
44
|
+
test('names each remove control after the tag it removes', () => {
|
|
45
|
+
const { getByRole } = renderTagsInput(['Apple', 'Banana']);
|
|
46
|
+
|
|
47
|
+
// reka names this button with `aria-labelledby` pointing at the tag's own
|
|
48
|
+
// text, so both controls would be announced exactly like the tags beside
|
|
49
|
+
// them. The wrapper has to replace that name, not just add to it.
|
|
50
|
+
expect(getByRole('button', { name: 'Remove Apple' })).toBeInTheDocument();
|
|
51
|
+
expect(getByRole('button', { name: 'Remove Banana' })).toBeInTheDocument();
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
test('allows the remove control name to be overridden', () => {
|
|
55
|
+
const { getByRole, queryByRole } = render({
|
|
56
|
+
components: {
|
|
57
|
+
UiTagsInput,
|
|
58
|
+
UiTagsInputItem,
|
|
59
|
+
UiTagsInputItemText,
|
|
60
|
+
UiTagsInputItemDelete,
|
|
28
61
|
},
|
|
62
|
+
template: `
|
|
63
|
+
<UiTagsInput :model-value="['Apple']">
|
|
64
|
+
<UiTagsInputItem value="Apple">
|
|
65
|
+
<UiTagsInputItemText />
|
|
66
|
+
<UiTagsInputItemDelete label="Entferne Apple" />
|
|
67
|
+
</UiTagsInputItem>
|
|
68
|
+
</UiTagsInput>
|
|
69
|
+
`,
|
|
29
70
|
});
|
|
30
71
|
|
|
31
|
-
expect(
|
|
32
|
-
|
|
33
|
-
|
|
72
|
+
expect(getByRole('button', { name: 'Entferne Apple' })).toBeInTheDocument();
|
|
73
|
+
expect(queryByRole('button', { name: 'Remove Apple' })).toBeNull();
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
test('leaves the tag wrapper generic so its text is what is exposed', () => {
|
|
77
|
+
const { container, getByText } = renderTagsInput(['Apple']);
|
|
78
|
+
|
|
79
|
+
// The tag carries no role on purpose: the roles that would let it be
|
|
80
|
+
// named are worse (`listitem` needs a `list` parent that cannot wrap the
|
|
81
|
+
// text input), so the value reaches assistive tech as plain text.
|
|
82
|
+
const tag = container.querySelector('[data-slot="tags-input-item"]');
|
|
83
|
+
expect(tag).not.toHaveAttribute('role');
|
|
84
|
+
expect(getByText('Apple')).toBeInTheDocument();
|
|
34
85
|
});
|
|
35
86
|
|
|
36
|
-
test('
|
|
37
|
-
const {
|
|
87
|
+
test('starts with a silent live region', () => {
|
|
88
|
+
const { getByRole } = renderTagsInput(['Apple']);
|
|
89
|
+
|
|
90
|
+
// Content on mount would be announced on page load, before the user has
|
|
91
|
+
// done anything.
|
|
92
|
+
expect(getByRole('status')).toHaveTextContent('');
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
test('announces added and removed tags', async () => {
|
|
96
|
+
const { getByRole, rerender } = render(UiTagsInput, {
|
|
97
|
+
props: { modelValue: ['Apple'] },
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
await rerender({ modelValue: ['Apple', 'Banana'] });
|
|
101
|
+
await nextTick();
|
|
102
|
+
expect(getByRole('status')).toHaveTextContent('Banana added');
|
|
103
|
+
|
|
104
|
+
await rerender({ modelValue: ['Banana'] });
|
|
105
|
+
await nextTick();
|
|
106
|
+
expect(getByRole('status')).toHaveTextContent('Apple removed');
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
test('allows the announcement wording to be translated', async () => {
|
|
110
|
+
const { getByRole, rerender } = render(UiTagsInput, {
|
|
38
111
|
props: {
|
|
39
|
-
modelValue: ['
|
|
40
|
-
|
|
112
|
+
modelValue: ['Apple'],
|
|
113
|
+
addedLabel: 'hinzugefügt',
|
|
114
|
+
removedLabel: 'entfernt',
|
|
41
115
|
},
|
|
42
116
|
});
|
|
43
117
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
).
|
|
118
|
+
await rerender({ modelValue: ['Apple', 'Banana'] });
|
|
119
|
+
await nextTick();
|
|
120
|
+
expect(getByRole('status')).toHaveTextContent('Banana hinzugefügt');
|
|
121
|
+
|
|
122
|
+
await rerender({ modelValue: ['Banana'] });
|
|
123
|
+
await nextTick();
|
|
124
|
+
expect(getByRole('status')).toHaveTextContent('Apple entfernt');
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
test('marks the field as disabled', () => {
|
|
128
|
+
const { getByRole } = renderTagsInput(['Apple'], true);
|
|
129
|
+
|
|
130
|
+
expect(getByRole('textbox')).toBeDisabled();
|
|
47
131
|
});
|
|
48
132
|
});
|
|
@@ -9,7 +9,23 @@ import type { TagsInputRootProps } from 'reka-ui';
|
|
|
9
9
|
* @related UiInput, UiBadge
|
|
10
10
|
* @augments TagsInputRootProps
|
|
11
11
|
*/
|
|
12
|
-
export type UiTagsInputProps = Omit<
|
|
12
|
+
export type UiTagsInputProps = Omit<
|
|
13
|
+
TagsInputRootProps,
|
|
14
|
+
'class' | 'modelValue'
|
|
15
|
+
> & {
|
|
16
|
+
/**
|
|
17
|
+
* Word appended to a tag value when it is added, announced by the
|
|
18
|
+
* component's live region. Override it to translate the announcement.
|
|
19
|
+
* @default 'added'
|
|
20
|
+
*/
|
|
21
|
+
addedLabel?: string;
|
|
22
|
+
/**
|
|
23
|
+
* Word appended to a tag value when it is removed, announced by the
|
|
24
|
+
* component's live region. Override it to translate the announcement.
|
|
25
|
+
* @default 'removed'
|
|
26
|
+
*/
|
|
27
|
+
removedLabel?: string;
|
|
28
|
+
};
|
|
13
29
|
|
|
14
30
|
/**
|
|
15
31
|
* Props for the UiTagsInputInput component.
|
|
@@ -48,4 +64,10 @@ export type UiTagsInputItemTextProps = Record<string, never>;
|
|
|
48
64
|
* Props for the UiTagsInputItemDelete component.
|
|
49
65
|
* The delete button for removing a tag.
|
|
50
66
|
*/
|
|
51
|
-
export
|
|
67
|
+
export interface UiTagsInputItemDeleteProps {
|
|
68
|
+
/**
|
|
69
|
+
* Accessible name for the delete control. Defaults to `Remove <tag value>`,
|
|
70
|
+
* so the control is not announced with the same name as the tag itself.
|
|
71
|
+
*/
|
|
72
|
+
label?: string;
|
|
73
|
+
}
|
|
@@ -50,8 +50,13 @@ const forwarded = useForwardPropsEmits(props, emits);
|
|
|
50
50
|
>
|
|
51
51
|
<slot />
|
|
52
52
|
|
|
53
|
+
<!--
|
|
54
|
+
`size-6` with centred content gives the 16px icon a 24px hit area
|
|
55
|
+
(WCAG 2.5.8 Target Size); `-m-1` cancels the extra 4px so the icon
|
|
56
|
+
still sits exactly at `top-4 right-4`.
|
|
57
|
+
-->
|
|
53
58
|
<DialogClose
|
|
54
|
-
class="ring-offset-background focus:ring-ring data-[state=open]:bg-secondary absolute top-4 right-4 rounded-xs opacity-70 transition-opacity hover:opacity-100 focus:ring-2 focus:ring-offset-2 focus:outline-hidden disabled:pointer-events-none"
|
|
59
|
+
class="ring-offset-background focus:ring-ring data-[state=open]:bg-secondary absolute top-4 right-4 -m-1 flex size-6 items-center justify-center rounded-xs opacity-70 transition-opacity hover:opacity-100 focus:ring-2 focus:ring-offset-2 focus:outline-hidden disabled:pointer-events-none"
|
|
55
60
|
>
|
|
56
61
|
<X class="size-4" />
|
|
57
62
|
<span class="sr-only">{{ props.closeLabel }}</span>
|
|
@@ -17,12 +17,14 @@ import {
|
|
|
17
17
|
SIDEBAR_COOKIE_MAX_AGE,
|
|
18
18
|
SIDEBAR_COOKIE_NAME,
|
|
19
19
|
SIDEBAR_KEYBOARD_SHORTCUT,
|
|
20
|
+
SIDEBAR_MIN_DESKTOP_MEDIA_QUERY,
|
|
20
21
|
SIDEBAR_OFFSET_TOP_CLASS,
|
|
21
22
|
SIDEBAR_WIDTH,
|
|
22
23
|
SIDEBAR_WIDTH_DEFAULT,
|
|
23
24
|
SIDEBAR_WIDTH_ICON,
|
|
24
25
|
SIDEBAR_WIDTH_MAX,
|
|
25
26
|
SIDEBAR_WIDTH_MIN,
|
|
27
|
+
SIDEBAR_WIDTH_MIN_DESKTOP,
|
|
26
28
|
SIDEBAR_WIDTH_MOBILE,
|
|
27
29
|
SIDEBAR_WIDTH_STORAGE_KEY,
|
|
28
30
|
} from './utils';
|
|
@@ -153,10 +155,18 @@ const isResizing = ref(false);
|
|
|
153
155
|
let resizeStartX = 0;
|
|
154
156
|
let resizeStartWidth = 0;
|
|
155
157
|
|
|
158
|
+
// Toward the minimum desktop size (1024px) the sidebar narrows to a fixed
|
|
159
|
+
// 162px and its content truncates. The clamp lives on the width variable, so
|
|
160
|
+
// everything reading `--sidebar-width` — the column, the offcanvas collapse
|
|
161
|
+
// margin, a top bar aligning its gutter — follows along.
|
|
162
|
+
const isMinDesktop = useMediaQuery(SIDEBAR_MIN_DESKTOP_MEDIA_QUERY);
|
|
163
|
+
|
|
156
164
|
const canResize = computed(
|
|
157
165
|
() =>
|
|
158
166
|
resolvedResizable.value &&
|
|
159
167
|
!isMobile.value &&
|
|
168
|
+
// The compact-desktop clamp fixes the width, so a drag would not move it.
|
|
169
|
+
!isMinDesktop.value &&
|
|
160
170
|
(props.collapsible === 'none' || state.value === 'expanded'),
|
|
161
171
|
);
|
|
162
172
|
// The provider used to own these. The sidebar sets them on itself so it can be
|
|
@@ -169,12 +179,18 @@ const widthVars = computed(() => ({
|
|
|
169
179
|
'--sidebar-mobile-transition-duration': props.mobileTransitionDuration,
|
|
170
180
|
}));
|
|
171
181
|
|
|
172
|
-
const sidebarStyle = computed(() =>
|
|
173
|
-
|
|
174
|
-
'--sidebar-width': resolvedResizable.value
|
|
182
|
+
const sidebarStyle = computed(() => {
|
|
183
|
+
let width = resolvedResizable.value
|
|
175
184
|
? `${sidebarWidth.value}px`
|
|
176
|
-
: SIDEBAR_WIDTH
|
|
177
|
-
|
|
185
|
+
: SIDEBAR_WIDTH;
|
|
186
|
+
// The compact-desktop clamp overrides both the constant and a stored drag.
|
|
187
|
+
if (isMinDesktop.value) width = SIDEBAR_WIDTH_MIN_DESKTOP;
|
|
188
|
+
|
|
189
|
+
return {
|
|
190
|
+
...widthVars.value,
|
|
191
|
+
'--sidebar-width': width,
|
|
192
|
+
};
|
|
193
|
+
});
|
|
178
194
|
|
|
179
195
|
const mobileStyle = computed(() => ({
|
|
180
196
|
...widthVars.value,
|
|
@@ -7,6 +7,16 @@ export const SIDEBAR_WIDTH = '16rem';
|
|
|
7
7
|
export const SIDEBAR_WIDTH_DEFAULT = 256;
|
|
8
8
|
export const SIDEBAR_WIDTH_MIN = 240;
|
|
9
9
|
export const SIDEBAR_WIDTH_MAX = 480;
|
|
10
|
+
/**
|
|
11
|
+
* Width on compact desktop viewports (from `md` up to below the `desktop`
|
|
12
|
+
* breakpoint, 1200px): toward the minimum desktop size of 1024px the sidebar
|
|
13
|
+
* narrows to 162px and its content truncates, leaving the room to the content
|
|
14
|
+
* area's grid.
|
|
15
|
+
*/
|
|
16
|
+
export const SIDEBAR_WIDTH_MIN_DESKTOP = '162px';
|
|
17
|
+
/** Matches compact desktop viewports — at or above `md`, below `desktop`. */
|
|
18
|
+
export const SIDEBAR_MIN_DESKTOP_MEDIA_QUERY =
|
|
19
|
+
'(min-width: 768px) and (max-width: 1199.9px)';
|
|
10
20
|
export const SIDEBAR_WIDTH_MOBILE = '16rem';
|
|
11
21
|
export const SIDEBAR_WIDTH_ICON = '3rem';
|
|
12
22
|
export const SIDEBAR_KEYBOARD_SHORTCUT = 'b';
|
|
@@ -2,13 +2,16 @@ import { cva, type VariantProps } from 'class-variance-authority';
|
|
|
2
2
|
|
|
3
3
|
export { default as Switch } from './Switch.vue';
|
|
4
4
|
|
|
5
|
+
// The track uses the outline flavor of the focus ring: `ui-focus-ring` colors a
|
|
6
|
+
// border, and a border on the track eats into the padding box the thumb is
|
|
7
|
+
// sized against, leaving the thumb bigger than the lane it sits in.
|
|
5
8
|
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
|
|
9
|
+
'peer data-[state=checked]:bg-background-accent-default data-[state=unchecked]:bg-background-surface-muted-strong ui-focus-ring-outline dark:data-[state=unchecked]:bg-input/80 inline-flex shrink-0 items-center rounded-full shadow-xs transition-all disabled:cursor-not-allowed disabled:opacity-50',
|
|
7
10
|
{
|
|
8
11
|
variants: {
|
|
9
12
|
size: {
|
|
10
13
|
default: 'h-5 w-9 p-0.5',
|
|
11
|
-
sm: 'h-4 w-7 p-0.
|
|
14
|
+
sm: 'h-4 w-7 p-0.5',
|
|
12
15
|
},
|
|
13
16
|
},
|
|
14
17
|
defaultVariants: {
|
|
@@ -18,14 +21,12 @@ export const switchRootVariants = cva(
|
|
|
18
21
|
);
|
|
19
22
|
|
|
20
23
|
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',
|
|
24
|
+
'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 data-[state=checked]:translate-x-full',
|
|
22
25
|
{
|
|
23
26
|
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
27
|
size: {
|
|
27
|
-
default: 'size-4
|
|
28
|
-
sm: 'size-3
|
|
28
|
+
default: 'size-4',
|
|
29
|
+
sm: 'size-3',
|
|
29
30
|
},
|
|
30
31
|
},
|
|
31
32
|
defaultVariants: {
|
|
@@ -21,7 +21,10 @@ const forwarded = useForwardPropsEmits(delegatedProps, emits);
|
|
|
21
21
|
data-slot="tags-input"
|
|
22
22
|
:class="
|
|
23
23
|
cn(
|
|
24
|
-
|
|
24
|
+
// The root is a `div`, so `disabled:` variants can never match it —
|
|
25
|
+
// reka marks the disabled state with `data-disabled` instead. Dimming
|
|
26
|
+
// stays on the tags themselves so the opacity does not compound.
|
|
27
|
+
'border-input ui-focus-ring-within flex min-h-9 w-full flex-wrap items-center gap-1.5 rounded-md border bg-background-input-default px-3 py-1 label-14-regular shadow-xs transition-[color,box-shadow] data-[disabled]:cursor-not-allowed',
|
|
25
28
|
props.class,
|
|
26
29
|
)
|
|
27
30
|
"
|
|
@@ -15,11 +15,23 @@ const forwardedProps = useForwardProps(delegatedProps);
|
|
|
15
15
|
</script>
|
|
16
16
|
|
|
17
17
|
<template>
|
|
18
|
+
<!--
|
|
19
|
+
reka puts `aria-labelledby` on this wrapper, which is a `div` with no role.
|
|
20
|
+
ARIA prohibits naming a generic element, so axe reports it as needs-review
|
|
21
|
+
(`aria-prohibited-attr`) and browsers ignore the name outright — the tag is
|
|
22
|
+
exposed as its text either way. It cannot be overridden from here (reka
|
|
23
|
+
binds it on an inner element, below our fallthrough attrs), and the roles
|
|
24
|
+
that would permit a name are all worse: `listitem` needs a `list` parent,
|
|
25
|
+
which cannot wrap the text input, and `group` only adds verbosity. Left as
|
|
26
|
+
is deliberately; see the Accessibility story.
|
|
27
|
+
-->
|
|
18
28
|
<TagsInputItem
|
|
19
29
|
data-slot="tags-input-item"
|
|
20
30
|
:class="
|
|
21
31
|
cn(
|
|
22
|
-
|
|
32
|
+
// `h-7` (28px) rather than 24px so the delete control inside can reach
|
|
33
|
+
// its own 24px minimum touch target (WCAG 2.5.8) without overflowing.
|
|
34
|
+
'bg-secondary text-secondary-foreground data-[state=active]:border-ring data-[state=active]:ring-ring/50 inline-flex h-7 shrink-0 items-center gap-1 rounded-sm border px-1 label-12-medium transition-[color,box-shadow] data-[state=active]:ring-[3px] [&[data-disabled]]:opacity-50 [&>button]:shrink-0',
|
|
23
35
|
props.class,
|
|
24
36
|
)
|
|
25
37
|
"
|
|
@@ -1,29 +1,61 @@
|
|
|
1
1
|
<script setup lang="ts">
|
|
2
2
|
import type { TagsInputItemDeleteProps } from 'reka-ui';
|
|
3
3
|
import type { HTMLAttributes } from 'vue';
|
|
4
|
-
import { TagsInputItemDelete,
|
|
4
|
+
import { TagsInputItemDelete, injectTagsInputItemContext } from 'reka-ui';
|
|
5
5
|
import { computed } from 'vue';
|
|
6
|
-
import { cn
|
|
6
|
+
import { cn } from '@/lib/utils';
|
|
7
7
|
|
|
8
8
|
const props = defineProps<
|
|
9
|
-
TagsInputItemDeleteProps & {
|
|
9
|
+
TagsInputItemDeleteProps & {
|
|
10
|
+
class?: HTMLAttributes['class'];
|
|
11
|
+
/**
|
|
12
|
+
* Accessible name for the delete control.
|
|
13
|
+
* Defaults to `Remove <tag value>`.
|
|
14
|
+
*/
|
|
15
|
+
label?: string;
|
|
16
|
+
}
|
|
10
17
|
>();
|
|
11
18
|
|
|
12
|
-
|
|
19
|
+
/*
|
|
20
|
+
* Only reka's own props are forwarded. `label` is consumed here to build the
|
|
21
|
+
* accessible name, and reka has no such prop, so forwarding it would land a
|
|
22
|
+
* meaningless `label` attribute on the button.
|
|
23
|
+
*/
|
|
24
|
+
const delegatedProps = computed<TagsInputItemDeleteProps>(() => ({
|
|
25
|
+
as: props.as,
|
|
26
|
+
asChild: props.asChild,
|
|
27
|
+
}));
|
|
13
28
|
|
|
14
|
-
const
|
|
29
|
+
const itemContext = injectTagsInputItemContext();
|
|
30
|
+
|
|
31
|
+
/*
|
|
32
|
+
* reka names this button with `aria-labelledby` pointing at the tag's own text,
|
|
33
|
+
* so a screen reader reads "Apple, button" — identical to the tag beside it and
|
|
34
|
+
* with no hint that activating it deletes anything. We override that with an
|
|
35
|
+
* explicit name. `aria-labelledby` has to be cleared rather than just adding an
|
|
36
|
+
* `aria-label`, because it wins over `aria-label` in the accessible-name
|
|
37
|
+
* calculation.
|
|
38
|
+
*/
|
|
39
|
+
const deleteLabel = computed(
|
|
40
|
+
() => props.label ?? `Remove ${String(itemContext.value.value)}`,
|
|
41
|
+
);
|
|
15
42
|
</script>
|
|
16
43
|
|
|
17
44
|
<template>
|
|
18
45
|
<TagsInputItemDelete
|
|
19
46
|
data-slot="tags-input-item-delete"
|
|
47
|
+
:aria-label="deleteLabel"
|
|
48
|
+
:aria-labelledby="undefined"
|
|
20
49
|
:class="
|
|
21
50
|
cn(
|
|
22
|
-
|
|
51
|
+
// `size-6` is the 24px minimum touch-target size (WCAG 2.5.8). The
|
|
52
|
+
// button sits flush against the tag text and the input, so the
|
|
53
|
+
// spacing exception does not apply. 24px fits inside the `h-7` tag.
|
|
54
|
+
'hover:bg-secondary-foreground/20 ui-focus-ring -mr-0.5 flex size-6 items-center justify-center rounded-sm transition-[color,box-shadow]',
|
|
23
55
|
props.class,
|
|
24
56
|
)
|
|
25
57
|
"
|
|
26
|
-
v-bind="
|
|
58
|
+
v-bind="delegatedProps"
|
|
27
59
|
>
|
|
28
60
|
<slot>
|
|
29
61
|
<svg
|
|
@@ -36,6 +68,7 @@ const forwardedProps = useForwardProps(delegatedProps);
|
|
|
36
68
|
stroke-width="2"
|
|
37
69
|
stroke-linecap="round"
|
|
38
70
|
stroke-linejoin="round"
|
|
71
|
+
aria-hidden="true"
|
|
39
72
|
>
|
|
40
73
|
<path d="M18 6 6 18" />
|
|
41
74
|
<path d="m6 6 12 12" />
|