@aleph-alpha/ui-library 5.4.0 → 5.6.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 +9 -0
- package/config.js +12 -3
- package/dist/system/components/UiAutocomplete/UiAutocomplete.vue.d.ts +2 -0
- package/dist/system/components/UiButtonGroup/UiButtonGroup.vue.d.ts +20 -0
- package/dist/system/components/UiButtonGroup/index.d.ts +2 -0
- package/dist/system/components/UiButtonGroup/types.d.ts +20 -0
- package/dist/system/components/core/button-group/ButtonGroup.vue.d.ts +23 -0
- package/dist/system/components/core/button-group/ButtonGroupSeparator.vue.d.ts +9 -0
- package/dist/system/components/core/button-group/ButtonGroupText.vue.d.ts +26 -0
- package/dist/system/components/core/button-group/index.d.ts +8 -0
- package/dist/system/components/index.d.ts +1 -0
- package/dist/system/lib.js +8878 -8692
- package/dist/system/patterns/UiFloatActions/UiFloatActionItems.vue.d.ts +173 -2
- package/dist/system/patterns/UiFloatActions/floatActionItemContext.d.ts +15 -1
- package/dist/system/patterns/UiFloatActions/types.d.ts +25 -1
- package/dist/system/story-sidebar-icons.json +8 -1
- package/package.json +5 -3
- package/src/components/UiAutocomplete/UiAutocomplete.stories.ts +620 -0
- package/src/components/UiAutocomplete/UiAutocomplete.vue +28 -3
- package/src/components/UiAutocomplete/__tests__/UiAutocomplete.test.ts +14 -69
- package/src/components/UiButton/UiButton.stories.ts +9 -9
- package/src/components/UiButtonGroup/UiButtonGroup.stories.ts +690 -0
- package/src/components/UiButtonGroup/UiButtonGroup.vue +18 -0
- package/src/components/UiButtonGroup/__tests__/UiButtonGroup.test.ts +68 -0
- package/src/components/UiButtonGroup/index.ts +2 -0
- package/src/components/UiButtonGroup/types.ts +21 -0
- package/src/components/UiCheckbox/UiCheckbox.stories.ts +253 -0
- package/src/components/UiCheckbox/__tests__/UiCheckbox.test.ts +3 -18
- package/src/components/UiField/UiField.stories.ts +608 -1
- package/src/components/UiField/UiFieldDescription.vue +7 -2
- package/src/components/UiInput/UiInput.stories.ts +336 -2
- package/src/components/UiInput/__tests__/UiInput.test.ts +20 -28
- package/src/components/UiItem/UiItem.stories.ts +236 -1
- package/src/components/UiItem/__tests__/UiItem.test.ts +11 -72
- package/src/components/UiSelect/UiSelect.stories.ts +769 -0
- package/src/components/UiSelect/__tests__/UiSelect.test.ts +4 -73
- package/src/components/UiSelect/__tests__/UiSelectItem.test.ts +3 -31
- package/src/components/UiSelect/__tests__/UiSelectTrigger.test.ts +14 -5
- package/src/components/UiSnackbar/UiSnackbar.stories.ts +6 -6
- package/src/components/UiSnackbar/UiSnackbar.vue +4 -4
- package/src/components/UiSnackbar/UiSnackbarContent.vue +4 -4
- package/src/components/core/button-group/ButtonGroup.vue +24 -0
- package/src/components/core/button-group/ButtonGroupSeparator.vue +29 -0
- package/src/components/core/button-group/ButtonGroupText.vue +33 -0
- package/src/components/core/button-group/index.ts +25 -0
- package/src/components/core/checkbox/Checkbox.vue +0 -1
- package/src/components/core/select/SelectTrigger.vue +1 -1
- package/src/components/core/tabs/TabsTrigger.vue +1 -1
- package/src/components/index.ts +1 -0
- package/src/patterns/UiDataTable/UiDataTable.stories.ts +495 -8
- package/src/patterns/UiDataTable/UiDataTableFilterMenu.vue +1 -1
- package/src/patterns/UiDataTable/__tests__/UiDataTable.test.ts +7 -184
- package/src/patterns/UiFloatActions/UiFloatActionItems.vue +138 -11
- package/src/patterns/UiFloatActions/UiFloatActions.stories.ts +890 -3
- package/src/patterns/UiFloatActions/__tests__/UiFloatActionItems.test.ts +46 -24
- package/src/patterns/UiFloatActions/floatActionItemContext.ts +16 -1
- package/src/patterns/UiFloatActions/types.ts +28 -1
- package/src/components/UiField/__tests__/UiFieldError.test.ts +0 -39
- package/src/patterns/UiFloatActions/__tests__/UiFloatActions.a11y.test.ts +0 -152
|
@@ -5,7 +5,6 @@ import { h, ref, nextTick } from 'vue';
|
|
|
5
5
|
import type { ColumnDef } from '@aleph-alpha/ui-library';
|
|
6
6
|
import UiDataTable from '../UiDataTable.vue';
|
|
7
7
|
import UiDataTableColumnFilter from '../UiDataTableColumnFilter.vue';
|
|
8
|
-
import UiDataTableColumnHeader from '../UiDataTableColumnHeader.vue';
|
|
9
8
|
import { UiCheckbox } from '@/components/UiCheckbox';
|
|
10
9
|
|
|
11
10
|
interface TestData {
|
|
@@ -25,19 +24,6 @@ const basicColumns: ColumnDef<TestData>[] = [
|
|
|
25
24
|
{ accessorKey: 'amount', header: 'Amount' },
|
|
26
25
|
];
|
|
27
26
|
|
|
28
|
-
const sortableColumns: ColumnDef<TestData>[] = [
|
|
29
|
-
{
|
|
30
|
-
accessorKey: 'name',
|
|
31
|
-
header: ({ column }) =>
|
|
32
|
-
h(UiDataTableColumnHeader, { column, title: 'Name' }),
|
|
33
|
-
},
|
|
34
|
-
{
|
|
35
|
-
accessorKey: 'amount',
|
|
36
|
-
header: ({ column }) =>
|
|
37
|
-
h(UiDataTableColumnHeader, { column, title: 'Amount' }),
|
|
38
|
-
},
|
|
39
|
-
];
|
|
40
|
-
|
|
41
27
|
const sizedColumns: ColumnDef<TestData>[] = [
|
|
42
28
|
{ accessorKey: 'name', header: 'Name', size: 200 },
|
|
43
29
|
{ accessorKey: 'amount', header: 'Amount' },
|
|
@@ -451,58 +437,10 @@ describe('UiDataTable', () => {
|
|
|
451
437
|
});
|
|
452
438
|
});
|
|
453
439
|
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
props: { columns: sortableColumns, data: testData },
|
|
459
|
-
});
|
|
460
|
-
|
|
461
|
-
// Click the Name column header button to sort ascending
|
|
462
|
-
await user.click(getByRole('button', { name: /Name/i }));
|
|
463
|
-
|
|
464
|
-
const cells = getAllByRole('cell');
|
|
465
|
-
// First data row should be Alice (alphabetically first)
|
|
466
|
-
expect(cells[0]).toHaveTextContent('Alice');
|
|
467
|
-
});
|
|
468
|
-
|
|
469
|
-
test('sorts descending on second click', async () => {
|
|
470
|
-
const user = userEvent.setup();
|
|
471
|
-
const { getByRole, getAllByRole } = render(UiDataTable, {
|
|
472
|
-
props: { columns: sortableColumns, data: testData },
|
|
473
|
-
});
|
|
474
|
-
|
|
475
|
-
// First click: ascending
|
|
476
|
-
await user.click(getByRole('button', { name: /Name/i }));
|
|
477
|
-
// Second click: descending
|
|
478
|
-
await user.click(getByRole('button', { name: /Name/i }));
|
|
479
|
-
|
|
480
|
-
const cells = getAllByRole('cell');
|
|
481
|
-
// First data row should be Charlie (alphabetically last)
|
|
482
|
-
expect(cells[0]).toHaveTextContent('Charlie');
|
|
483
|
-
});
|
|
484
|
-
|
|
485
|
-
test('clears sorting on third click', async () => {
|
|
486
|
-
const user = userEvent.setup();
|
|
487
|
-
const { getByRole, getAllByRole } = render(UiDataTable, {
|
|
488
|
-
props: { columns: sortableColumns, data: testData },
|
|
489
|
-
});
|
|
490
|
-
|
|
491
|
-
const initialCells = getAllByRole('cell');
|
|
492
|
-
const initialFirst = initialCells[0].textContent;
|
|
493
|
-
|
|
494
|
-
const headerButton = getByRole('button', { name: /Name/i });
|
|
495
|
-
// First click: ascending
|
|
496
|
-
await user.click(headerButton);
|
|
497
|
-
// Second click: descending
|
|
498
|
-
await user.click(headerButton);
|
|
499
|
-
// Third click: clear sorting (back to original order)
|
|
500
|
-
await user.click(headerButton);
|
|
501
|
-
|
|
502
|
-
const finalCells = getAllByRole('cell');
|
|
503
|
-
expect(finalCells[0]).toHaveTextContent(initialFirst ?? '');
|
|
504
|
-
});
|
|
505
|
-
});
|
|
440
|
+
// Sorting interactions (click/keyboard to sort ascending, descending, and
|
|
441
|
+
// clear) are covered by the `test - Keyboard Navigation` play function in
|
|
442
|
+
// UiDataTable.stories.ts. The column-header wiring is unit-tested in
|
|
443
|
+
// UiDataTableColumnHeader.test.ts.
|
|
506
444
|
|
|
507
445
|
describe('Row Click', () => {
|
|
508
446
|
test('calls onRowClick with row data when a row is clicked', async () => {
|
|
@@ -657,124 +595,9 @@ describe('UiDataTable', () => {
|
|
|
657
595
|
});
|
|
658
596
|
});
|
|
659
597
|
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
const tableRef = ref<InstanceType<typeof UiDataTable>>();
|
|
664
|
-
|
|
665
|
-
const { getByLabelText } = render({
|
|
666
|
-
components: { UiDataTable },
|
|
667
|
-
template:
|
|
668
|
-
'<UiDataTable ref="tableRef" :columns="columns" :data="data" />',
|
|
669
|
-
setup() {
|
|
670
|
-
return { tableRef, columns: selectableColumns, data: testData };
|
|
671
|
-
},
|
|
672
|
-
});
|
|
673
|
-
|
|
674
|
-
await nextTick();
|
|
675
|
-
|
|
676
|
-
// Select row
|
|
677
|
-
const checkbox = getByLabelText('Select row Alice');
|
|
678
|
-
await user.click(checkbox);
|
|
679
|
-
await nextTick();
|
|
680
|
-
|
|
681
|
-
let selectedRows = tableRef.value?.table.getSelectedRowModel().rows;
|
|
682
|
-
expect(selectedRows).toHaveLength(1);
|
|
683
|
-
expect(selectedRows?.[0].original.name).toBe('Alice');
|
|
684
|
-
|
|
685
|
-
// Deselect row
|
|
686
|
-
await user.click(checkbox);
|
|
687
|
-
await nextTick();
|
|
688
|
-
|
|
689
|
-
selectedRows = tableRef.value?.table.getSelectedRowModel().rows;
|
|
690
|
-
expect(selectedRows).toHaveLength(0);
|
|
691
|
-
});
|
|
692
|
-
|
|
693
|
-
test('selects multiple rows independently', async () => {
|
|
694
|
-
const user = userEvent.setup();
|
|
695
|
-
const tableRef = ref<InstanceType<typeof UiDataTable>>();
|
|
696
|
-
|
|
697
|
-
const { getByLabelText } = render({
|
|
698
|
-
components: { UiDataTable },
|
|
699
|
-
template:
|
|
700
|
-
'<UiDataTable ref="tableRef" :columns="columns" :data="data" />',
|
|
701
|
-
setup() {
|
|
702
|
-
return { tableRef, columns: selectableColumns, data: testData };
|
|
703
|
-
},
|
|
704
|
-
});
|
|
705
|
-
|
|
706
|
-
await nextTick();
|
|
707
|
-
|
|
708
|
-
// Select Alice and Charlie
|
|
709
|
-
await user.click(getByLabelText('Select row Alice'));
|
|
710
|
-
await user.click(getByLabelText('Select row Charlie'));
|
|
711
|
-
await nextTick();
|
|
712
|
-
|
|
713
|
-
const selectedRows = tableRef.value?.table.getSelectedRowModel().rows;
|
|
714
|
-
expect(selectedRows).toHaveLength(2);
|
|
715
|
-
expect(selectedRows?.map((r) => r.original.name)).toEqual([
|
|
716
|
-
'Alice',
|
|
717
|
-
'Charlie',
|
|
718
|
-
]);
|
|
719
|
-
});
|
|
720
|
-
|
|
721
|
-
test('toggles all rows when select all checkbox is clicked', async () => {
|
|
722
|
-
const user = userEvent.setup();
|
|
723
|
-
const tableRef = ref<InstanceType<typeof UiDataTable>>();
|
|
724
|
-
|
|
725
|
-
const { getByLabelText } = render({
|
|
726
|
-
components: { UiDataTable },
|
|
727
|
-
template:
|
|
728
|
-
'<UiDataTable ref="tableRef" :columns="columns" :data="data" />',
|
|
729
|
-
setup() {
|
|
730
|
-
return { tableRef, columns: selectableColumns, data: testData };
|
|
731
|
-
},
|
|
732
|
-
});
|
|
733
|
-
|
|
734
|
-
await nextTick();
|
|
735
|
-
|
|
736
|
-
const selectAll = getByLabelText('Select all');
|
|
737
|
-
|
|
738
|
-
// Select all
|
|
739
|
-
await user.click(selectAll);
|
|
740
|
-
await nextTick();
|
|
741
|
-
|
|
742
|
-
let selectedRows = tableRef.value?.table.getSelectedRowModel().rows;
|
|
743
|
-
expect(selectedRows).toHaveLength(3);
|
|
744
|
-
expect(tableRef.value?.table.getIsAllPageRowsSelected()).toBe(true);
|
|
745
|
-
|
|
746
|
-
// Deselect all
|
|
747
|
-
await user.click(selectAll);
|
|
748
|
-
await nextTick();
|
|
749
|
-
|
|
750
|
-
selectedRows = tableRef.value?.table.getSelectedRowModel().rows;
|
|
751
|
-
expect(selectedRows).toHaveLength(0);
|
|
752
|
-
expect(tableRef.value?.table.getIsAllPageRowsSelected()).toBe(false);
|
|
753
|
-
});
|
|
754
|
-
|
|
755
|
-
test('shows indeterminate state when some rows selected', async () => {
|
|
756
|
-
const user = userEvent.setup();
|
|
757
|
-
const tableRef = ref<InstanceType<typeof UiDataTable>>();
|
|
758
|
-
|
|
759
|
-
const { getByLabelText } = render({
|
|
760
|
-
components: { UiDataTable },
|
|
761
|
-
template:
|
|
762
|
-
'<UiDataTable ref="tableRef" :columns="columns" :data="data" />',
|
|
763
|
-
setup() {
|
|
764
|
-
return { tableRef, columns: selectableColumns, data: testData };
|
|
765
|
-
},
|
|
766
|
-
});
|
|
767
|
-
|
|
768
|
-
await nextTick();
|
|
769
|
-
|
|
770
|
-
// Select only one row
|
|
771
|
-
await user.click(getByLabelText('Select row Alice'));
|
|
772
|
-
await nextTick();
|
|
773
|
-
|
|
774
|
-
expect(tableRef.value?.table.getIsSomePageRowsSelected()).toBe(true);
|
|
775
|
-
expect(tableRef.value?.table.getIsAllPageRowsSelected()).toBe(false);
|
|
776
|
-
});
|
|
777
|
-
});
|
|
598
|
+
// Row selection interactions (individual toggle, multiple independent
|
|
599
|
+
// selection, select-all, and the indeterminate/mixed state) are covered by
|
|
600
|
+
// the `test - Row Selection` play function in UiDataTable.stories.ts.
|
|
778
601
|
|
|
779
602
|
describe('Reactivity', () => {
|
|
780
603
|
test('updates table when data prop changes', async () => {
|
|
@@ -45,7 +45,9 @@ import { cn, omitClass } from '@/lib/utils';
|
|
|
45
45
|
import {
|
|
46
46
|
computed,
|
|
47
47
|
inject,
|
|
48
|
+
nextTick,
|
|
48
49
|
onBeforeUnmount,
|
|
50
|
+
onMounted,
|
|
49
51
|
provide,
|
|
50
52
|
ref,
|
|
51
53
|
useAttrs,
|
|
@@ -55,8 +57,10 @@ import {
|
|
|
55
57
|
FLOAT_ACTION_ITEM_SELECTOR,
|
|
56
58
|
FLOAT_ACTION_ITEM_CONTEXT,
|
|
57
59
|
type FloatActionItemContext,
|
|
60
|
+
type FloatActionItemRegistration,
|
|
58
61
|
} from './floatActionItemContext';
|
|
59
62
|
import type { UiFloatActionItemsEmits, UiFloatActionItemsProps } from './types';
|
|
63
|
+
import UiInput from '@/components/UiInput/UiInput.vue';
|
|
60
64
|
|
|
61
65
|
defineOptions({
|
|
62
66
|
name: 'UiFloatActionItems',
|
|
@@ -69,6 +73,8 @@ const props = withDefaults(defineProps<UiFloatActionItemsProps>(), {
|
|
|
69
73
|
orientation: 'horizontal',
|
|
70
74
|
ariaLabel: undefined,
|
|
71
75
|
placeholder: undefined,
|
|
76
|
+
modelValue: undefined,
|
|
77
|
+
value: undefined,
|
|
72
78
|
});
|
|
73
79
|
|
|
74
80
|
const emit = defineEmits<UiFloatActionItemsEmits>();
|
|
@@ -91,13 +97,25 @@ const isGroup = computed(() => props.type === 'group');
|
|
|
91
97
|
const isSeparator = computed(() => props.type === 'separator');
|
|
92
98
|
|
|
93
99
|
const activeIndex = ref(0);
|
|
94
|
-
|
|
100
|
+
type RegisteredItem = FloatActionItemRegistration & {
|
|
101
|
+
/** Unique id used for roving-tabindex bookkeeping. */
|
|
102
|
+
id: symbol;
|
|
103
|
+
};
|
|
104
|
+
const registeredItems = ref<RegisteredItem[]>([]);
|
|
95
105
|
|
|
96
106
|
const toolbarOrientation = computed(() => props.orientation ?? 'horizontal');
|
|
97
107
|
|
|
108
|
+
// A toolbar becomes a single-select control when `v-model` is bound. We can't
|
|
109
|
+
// distinguish an unbound prop from an explicit `undefined`, so presence of a
|
|
110
|
+
// non-undefined `modelValue` opts into the indicator behaviour.
|
|
111
|
+
const hasModel = computed(
|
|
112
|
+
() => isToolbar.value && props.modelValue !== undefined,
|
|
113
|
+
);
|
|
114
|
+
const modelValueRef = computed(() => props.modelValue);
|
|
115
|
+
|
|
98
116
|
const toolbarContext: FloatActionItemContext = {
|
|
99
|
-
registerItem(id) {
|
|
100
|
-
registeredItems.value.push({ id });
|
|
117
|
+
registerItem(id, registration) {
|
|
118
|
+
registeredItems.value.push({ id, ...registration });
|
|
101
119
|
},
|
|
102
120
|
unregisterItem(id) {
|
|
103
121
|
registeredItems.value = registeredItems.value.filter(
|
|
@@ -114,18 +132,96 @@ const toolbarContext: FloatActionItemContext = {
|
|
|
114
132
|
return index === activeIndex.value ? 0 : -1;
|
|
115
133
|
},
|
|
116
134
|
orientation: toolbarOrientation,
|
|
135
|
+
hasModel,
|
|
136
|
+
modelValue: modelValueRef,
|
|
137
|
+
select(value) {
|
|
138
|
+
emit('update:modelValue', value);
|
|
139
|
+
},
|
|
117
140
|
};
|
|
118
141
|
|
|
142
|
+
const inputName = computed(
|
|
143
|
+
() => (attrs.name as string) ?? `float-action-input-${itemId.toString()}`,
|
|
144
|
+
);
|
|
145
|
+
|
|
119
146
|
if (isToolbar.value) {
|
|
120
147
|
provide(FLOAT_ACTION_ITEM_CONTEXT, toolbarContext);
|
|
121
148
|
}
|
|
122
149
|
|
|
150
|
+
// Sliding background indicator: an absolutely-positioned layer inside the
|
|
151
|
+
// toolbar that tracks the active (selected) item's box so it appears to move
|
|
152
|
+
// between items as the selection changes.
|
|
153
|
+
const indicatorStyle = ref<Record<string, string>>({ opacity: '0' });
|
|
154
|
+
const indicatorReady = ref(false);
|
|
155
|
+
let resizeObserver: ResizeObserver | null = null;
|
|
156
|
+
|
|
157
|
+
function updateIndicator() {
|
|
158
|
+
if (!isToolbar.value || !hasModel.value) {
|
|
159
|
+
indicatorStyle.value = { opacity: '0' };
|
|
160
|
+
return;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
const root = itemRef.value;
|
|
164
|
+
const activeEl = registeredItems.value
|
|
165
|
+
.find(
|
|
166
|
+
(item) => item.value() !== undefined && item.value() === props.modelValue,
|
|
167
|
+
)
|
|
168
|
+
?.el();
|
|
169
|
+
|
|
170
|
+
if (!root || !activeEl) {
|
|
171
|
+
indicatorStyle.value = { opacity: '0' };
|
|
172
|
+
return;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
indicatorStyle.value = {
|
|
176
|
+
opacity: '1',
|
|
177
|
+
width: `${activeEl.offsetWidth}px`,
|
|
178
|
+
height: `${activeEl.offsetHeight}px`,
|
|
179
|
+
transform: `translate(${activeEl.offsetLeft}px, ${activeEl.offsetTop}px)`,
|
|
180
|
+
};
|
|
181
|
+
|
|
182
|
+
if (!indicatorReady.value && typeof requestAnimationFrame === 'function') {
|
|
183
|
+
// Position once without a transition, then enable animation so future
|
|
184
|
+
// selections slide instead of jumping in from the top-left corner.
|
|
185
|
+
requestAnimationFrame(() => {
|
|
186
|
+
indicatorReady.value = true;
|
|
187
|
+
});
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
function scheduleIndicatorUpdate() {
|
|
192
|
+
void nextTick(updateIndicator);
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
if (isToolbar.value) {
|
|
196
|
+
watch(
|
|
197
|
+
[() => props.modelValue, hasModel, registeredItems],
|
|
198
|
+
scheduleIndicatorUpdate,
|
|
199
|
+
{ deep: true },
|
|
200
|
+
);
|
|
201
|
+
|
|
202
|
+
onMounted(() => {
|
|
203
|
+
scheduleIndicatorUpdate();
|
|
204
|
+
if (typeof ResizeObserver !== 'undefined' && itemRef.value) {
|
|
205
|
+
resizeObserver = new ResizeObserver(() => updateIndicator());
|
|
206
|
+
resizeObserver.observe(itemRef.value);
|
|
207
|
+
}
|
|
208
|
+
});
|
|
209
|
+
|
|
210
|
+
onBeforeUnmount(() => {
|
|
211
|
+
resizeObserver?.disconnect();
|
|
212
|
+
resizeObserver = null;
|
|
213
|
+
});
|
|
214
|
+
}
|
|
215
|
+
|
|
123
216
|
watch(
|
|
124
217
|
itemRef,
|
|
125
218
|
(element) => {
|
|
126
219
|
if (!parentContext || (!isButton.value && !isInput.value)) return;
|
|
127
220
|
if (element) {
|
|
128
|
-
parentContext.registerItem(itemId
|
|
221
|
+
parentContext.registerItem(itemId, {
|
|
222
|
+
el: () => itemRef.value,
|
|
223
|
+
value: () => props.value,
|
|
224
|
+
});
|
|
129
225
|
return;
|
|
130
226
|
}
|
|
131
227
|
parentContext.unregisterItem(itemId);
|
|
@@ -133,6 +229,17 @@ watch(
|
|
|
133
229
|
{ immediate: true },
|
|
134
230
|
);
|
|
135
231
|
|
|
232
|
+
// Selectable buttons opt in by declaring a `value` inside a `v-model` toolbar.
|
|
233
|
+
const isSelectable = computed(
|
|
234
|
+
() =>
|
|
235
|
+
isButton.value &&
|
|
236
|
+
parentContext?.hasModel.value === true &&
|
|
237
|
+
props.value !== undefined,
|
|
238
|
+
);
|
|
239
|
+
const isActive = computed(
|
|
240
|
+
() => isSelectable.value && parentContext?.modelValue.value === props.value,
|
|
241
|
+
);
|
|
242
|
+
|
|
136
243
|
onBeforeUnmount(() => {
|
|
137
244
|
parentContext?.unregisterItem(itemId);
|
|
138
245
|
});
|
|
@@ -208,6 +315,9 @@ function onButtonClick(event: MouseEvent) {
|
|
|
208
315
|
event.preventDefault();
|
|
209
316
|
return;
|
|
210
317
|
}
|
|
318
|
+
if (isSelectable.value && props.value !== undefined) {
|
|
319
|
+
parentContext?.select(props.value);
|
|
320
|
+
}
|
|
211
321
|
emit('click', event);
|
|
212
322
|
}
|
|
213
323
|
|
|
@@ -222,26 +332,34 @@ const forwardedAttrs = computed(() => omitClass(attrs));
|
|
|
222
332
|
|
|
223
333
|
const toolbarClass = computed(() =>
|
|
224
334
|
cn(
|
|
225
|
-
'inline-flex items-center gap-0.5 rounded-
|
|
335
|
+
'relative inline-flex items-center gap-0.5 rounded-xl-2xl border border-border-surface-default bg-background-surface-floating p-1 shadow-xs',
|
|
226
336
|
props.orientation === 'vertical' && 'flex-col',
|
|
227
337
|
attrs.class ?? '',
|
|
228
338
|
),
|
|
229
339
|
);
|
|
230
340
|
|
|
231
|
-
|
|
341
|
+
// The active indicator sits behind the items (first child, no z-index) and
|
|
342
|
+
// slides between them; `bg-background-surface-muted` mirrors the previous hover
|
|
343
|
+
// surface so the selected item reads as highlighted.
|
|
344
|
+
const indicatorClass = computed(() =>
|
|
232
345
|
cn(
|
|
233
|
-
'
|
|
234
|
-
|
|
346
|
+
'pointer-events-none absolute left-0 top-0 rounded-full bg-background-surface-muted',
|
|
347
|
+
indicatorReady.value &&
|
|
348
|
+
'transition-[transform,width,height] duration-200 ease-out motion-reduce:transition-none',
|
|
235
349
|
),
|
|
236
350
|
);
|
|
237
351
|
|
|
238
|
-
const
|
|
352
|
+
const buttonClass = computed(() =>
|
|
239
353
|
cn(
|
|
240
|
-
'ui-focus-ring h-8
|
|
354
|
+
'ui-focus-ring relative inline-flex h-8 w-8 shrink-0 cursor-pointer items-center justify-center rounded-full border border-transparent bg-transparent text-content-on-surface-muted focus-visible:text-content-on-surface-primary hover:text-content-on-surface-primary transition-colors disabled:cursor-not-allowed disabled:opacity-50 aria-pressed:text-content-on-surface-primary',
|
|
241
355
|
attrs.class ?? '',
|
|
242
356
|
),
|
|
243
357
|
);
|
|
244
358
|
|
|
359
|
+
const inputClass = computed(() =>
|
|
360
|
+
cn('h-8 min-w-16 label-14-regular', attrs.class ?? ''),
|
|
361
|
+
);
|
|
362
|
+
|
|
245
363
|
const textClass = computed(() =>
|
|
246
364
|
cn(
|
|
247
365
|
'inline-flex h-8 min-w-8 items-center justify-center px-1 label-14-regular text-content-on-surface-muted focus:text-content-on-surface-primary hover:text-content-on-surface-primary',
|
|
@@ -273,6 +391,13 @@ const separatorClass = computed(() =>
|
|
|
273
391
|
:class="toolbarClass"
|
|
274
392
|
@keydown="onToolbarKeydown"
|
|
275
393
|
>
|
|
394
|
+
<span
|
|
395
|
+
v-if="hasModel"
|
|
396
|
+
aria-hidden="true"
|
|
397
|
+
data-slot="float-item-indicator"
|
|
398
|
+
:class="indicatorClass"
|
|
399
|
+
:style="indicatorStyle"
|
|
400
|
+
/>
|
|
276
401
|
<slot />
|
|
277
402
|
</div>
|
|
278
403
|
|
|
@@ -283,6 +408,7 @@ const separatorClass = computed(() =>
|
|
|
283
408
|
type="button"
|
|
284
409
|
data-slot="float-item-action"
|
|
285
410
|
:aria-label="props.ariaLabel"
|
|
411
|
+
:aria-pressed="isSelectable ? isActive : undefined"
|
|
286
412
|
:disabled="props.disabled"
|
|
287
413
|
:tabindex="tabIndex"
|
|
288
414
|
:class="buttonClass"
|
|
@@ -292,7 +418,7 @@ const separatorClass = computed(() =>
|
|
|
292
418
|
<slot />
|
|
293
419
|
</button>
|
|
294
420
|
|
|
295
|
-
<
|
|
421
|
+
<UiInput
|
|
296
422
|
v-else-if="isInput"
|
|
297
423
|
ref="itemRef"
|
|
298
424
|
data-slot="float-item-action"
|
|
@@ -302,6 +428,7 @@ const separatorClass = computed(() =>
|
|
|
302
428
|
:disabled="props.disabled"
|
|
303
429
|
:tabindex="tabIndex"
|
|
304
430
|
:class="inputClass"
|
|
431
|
+
:name="inputName"
|
|
305
432
|
@focus="onItemFocus"
|
|
306
433
|
/>
|
|
307
434
|
|