@aleph-alpha/ui-library 5.3.0 → 5.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/config.d.ts +29 -3
- package/config.js +91 -3
- package/dist/system/components/UiTooltip/UiTooltip.vue.d.ts +1 -0
- package/dist/system/components/UiTooltip/types.d.ts +8 -0
- package/dist/system/components/core/tooltip/TooltipContent.vue.d.ts +2 -0
- package/dist/system/lib.js +4266 -4161
- package/dist/system/patterns/UiDataTable/UiDataTableFilterMenu.vue.d.ts +24 -0
- package/dist/system/patterns/UiDataTable/constants.d.ts +10 -0
- package/dist/system/patterns/UiDataTable/index.d.ts +1 -0
- package/dist/system/patterns/UiDataTable/types.d.ts +23 -1
- package/dist/system/patterns/UiFloatActions/UiFloatActions.vue.d.ts +3 -1
- package/docs/public-docs/getting-started-designers.md +3 -1
- package/docs/public-docs/quick-start.md +43 -0
- package/package.json +1 -1
- package/src/components/UiAccordion/UiAccordion.stories.ts +2 -2
- package/src/components/UiAutocomplete/UiAutocomplete.stories.ts +2 -2
- package/src/components/UiAutocomplete/UiAutocomplete.vue +6 -6
- package/src/components/UiBadge/UiBadge.stories.ts +9 -9
- package/src/components/UiButton/UiButton.stories.ts +5 -5
- package/src/components/UiCheckbox/UiCheckbox.stories.ts +7 -9
- package/src/components/UiChip/UiChip.vue +1 -1
- package/src/components/UiDrawer/UiDrawer.stories.ts +2 -2
- package/src/components/UiDropdownMenu/UiDropdownMenu.stories.ts +6 -6
- package/src/components/UiEmpty/UiEmpty.vue +2 -2
- package/src/components/UiField/UiField.stories.ts +6 -6
- package/src/components/UiField/UiFieldLabelInfo.vue +1 -1
- package/src/components/UiFileUploadBox/UiFileUploadBox.stories.ts +2 -2
- package/src/components/UiFileUploadBox/UiFileUploadBox.vue +2 -2
- package/src/components/UiInput/UiInput.vue +3 -3
- package/src/components/UiKbd/UiKbd.stories.ts +14 -14
- package/src/components/UiKbd/UiKbd.vue +1 -1
- package/src/components/UiNavigationMenu/UiNavigationMenu.stories.ts +66 -66
- package/src/components/UiPopover/UiPopover.stories.ts +20 -20
- package/src/components/UiRadioGroup/UiRadioGroup.stories.ts +24 -24
- package/src/components/UiResizable/UiResizable.stories.ts +15 -14
- package/src/components/UiSelect/UiSelect.stories.ts +1 -1
- package/src/components/UiSeparator/UiSeparator.stories.ts +6 -6
- package/src/components/UiSheet/UiSheet.stories.ts +14 -14
- package/src/components/UiSlider/UiSlider.stories.ts +8 -8
- package/src/components/UiSpinner/UiSpinner.stories.ts +8 -8
- package/src/components/UiSwitch/UiSwitch.stories.ts +4 -4
- package/src/components/UiTabs/UiTabs.stories.ts +46 -46
- package/src/components/UiToggle/__tests__/UiToggle.test.ts +5 -3
- package/src/components/UiToggleGroup/UiToggleGroup.stories.ts +14 -14
- package/src/components/UiTooltip/UiTooltip.stories.ts +3 -3
- package/src/components/UiTooltip/UiTooltip.vue +2 -0
- package/src/components/UiTooltip/types.ts +9 -0
- package/src/components/core/accordion/AccordionContent.vue +1 -1
- package/src/components/core/accordion/AccordionTrigger.vue +2 -2
- package/src/components/core/alert/AlertDescription.vue +1 -1
- package/src/components/core/alert/index.ts +1 -1
- package/src/components/core/badge/index.ts +1 -1
- package/src/components/core/button/index.ts +2 -2
- package/src/components/core/calendar/Calendar.vue +4 -4
- package/src/components/core/calendar/CalendarCell.vue +1 -1
- package/src/components/core/calendar/CalendarCellTrigger.vue +2 -2
- package/src/components/core/calendar/CalendarHeadCell.vue +1 -1
- package/src/components/core/card/CardDescription.vue +1 -1
- package/src/components/core/checkbox/Checkbox.vue +1 -1
- package/src/components/core/drawer/DrawerDescription.vue +1 -1
- package/src/components/core/dropdown-menu/DropdownMenuCheckboxItem.vue +1 -1
- package/src/components/core/dropdown-menu/DropdownMenuItem.vue +1 -1
- package/src/components/core/dropdown-menu/DropdownMenuLabel.vue +1 -3
- package/src/components/core/dropdown-menu/DropdownMenuRadioItem.vue +1 -1
- package/src/components/core/dropdown-menu/DropdownMenuShortcut.vue +4 -1
- package/src/components/core/dropdown-menu/DropdownMenuSubTrigger.vue +1 -1
- package/src/components/core/field/FieldDescription.vue +1 -1
- package/src/components/core/field/FieldLabel.vue +1 -1
- package/src/components/core/field/FieldLegend.vue +2 -2
- package/src/components/core/field/FieldSeparator.vue +2 -2
- package/src/components/core/input/Input.vue +2 -2
- package/src/components/core/item/index.ts +1 -1
- package/src/components/core/kbd/Kbd.vue +1 -1
- package/src/components/core/label/Label.vue +1 -1
- package/src/components/core/listbox/ListboxFilter.vue +1 -1
- package/src/components/core/listbox/ListboxGroupLabel.vue +4 -1
- package/src/components/core/listbox/ListboxItem.vue +1 -1
- package/src/components/core/native-select/NativeSelect.vue +3 -3
- package/src/components/core/navigation-menu/NavigationMenuLink.vue +1 -1
- package/src/components/core/navigation-menu/index.ts +1 -1
- package/src/components/core/radio-group/RadioGroupItem.vue +1 -1
- package/src/components/core/range-calendar/RangeCalendarCell.vue +1 -1
- package/src/components/core/range-calendar/RangeCalendarCellTrigger.vue +2 -2
- package/src/components/core/range-calendar/RangeCalendarHeadCell.vue +1 -1
- package/src/components/core/select/SelectItem.vue +1 -1
- package/src/components/core/select/SelectLabel.vue +6 -1
- package/src/components/core/select/SelectTrigger.vue +1 -1
- package/src/components/core/sheet/SheetDescription.vue +3 -1
- package/src/components/core/sidebar/SidebarGroupContent.vue +1 -1
- package/src/components/core/sidebar/SidebarGroupLabel.vue +1 -1
- package/src/components/core/sidebar/SidebarMenuBadge.vue +1 -1
- package/src/components/core/sidebar/SidebarMenuSubButton.vue +2 -2
- package/src/components/core/sidebar/index.ts +4 -4
- package/src/components/core/slider/Slider.vue +3 -3
- package/src/components/core/stepper/StepperDescription.vue +1 -1
- package/src/components/core/switch/Switch.vue +1 -1
- package/src/components/core/table/Table.vue +1 -1
- package/src/components/core/table/TableCaption.vue +3 -1
- package/src/components/core/table/TableEmpty.vue +1 -1
- package/src/components/core/tabs/TabsList.vue +1 -1
- package/src/components/core/tabs/TabsTrigger.vue +1 -1
- package/src/components/core/tags-input/TagsInput.vue +1 -1
- package/src/components/core/tags-input/TagsInputInput.vue +1 -1
- package/src/components/core/tags-input/TagsInputItem.vue +1 -1
- package/src/components/core/tags-input/TagsInputItemDelete.vue +1 -1
- package/src/components/core/textarea/Textarea.vue +1 -1
- package/src/components/core/toggle/index.ts +3 -3
- package/src/components/core/toggle-group/index.ts +2 -2
- package/src/components/core/tooltip/TooltipContent.vue +10 -4
- package/src/lib/useDrag.stories.ts +12 -12
- package/src/patterns/UiDataTable/UiDataTable.stories.ts +420 -10
- package/src/patterns/UiDataTable/UiDataTableColumnFilter.vue +1 -1
- package/src/patterns/UiDataTable/UiDataTableFilterMenu.vue +91 -0
- package/src/patterns/UiDataTable/UiDataTablePagination.vue +1 -1
- package/src/patterns/UiDataTable/constants.ts +12 -0
- package/src/patterns/UiDataTable/index.ts +1 -0
- package/src/patterns/UiDataTable/types.ts +24 -0
- package/src/patterns/UiDatePicker/UiDatePicker.stories.ts +8 -8
- package/src/patterns/UiDatePicker/UiDatePicker.vue +1 -1
- package/src/patterns/UiFloatActions/UiFloatActionItems.vue +11 -4
- package/src/patterns/UiFloatActions/UiFloatActions.stories.ts +416 -377
- package/src/patterns/UiFloatActions/UiFloatActions.vue +6 -2
- package/src/patterns/UiSidebar/UiSidebarGroupLabel.stories.ts +2 -2
- package/src/patterns/UiSidebar/UiSidebarMenuButton.stories.ts +5 -5
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import type { Meta, StoryObj } from '@storybook/vue3-vite';
|
|
2
|
-
import type { ColumnDef } from '@aleph-alpha/ui-library';
|
|
3
|
-
import { computed, h, ref } from 'vue';
|
|
2
|
+
import type { ColumnDef, Row } from '@aleph-alpha/ui-library';
|
|
3
|
+
import { computed, h, ref, reactive } from 'vue';
|
|
4
4
|
import {
|
|
5
5
|
UiDataTable,
|
|
6
6
|
UiDataTableColumnFilter,
|
|
7
|
+
UiDataTableFilterMenu,
|
|
7
8
|
UiDataTableColumnHeader,
|
|
8
9
|
UiDataTablePagination,
|
|
9
10
|
UiDataTableToolbar,
|
|
@@ -13,6 +14,14 @@ import { UiCheckbox } from '@/components/UiCheckbox';
|
|
|
13
14
|
import { UiButton } from '@/components/UiButton';
|
|
14
15
|
import { UiIcon } from '@/components/UiIcon';
|
|
15
16
|
import { UiInput } from '@/components/UiInput';
|
|
17
|
+
import {
|
|
18
|
+
UiField,
|
|
19
|
+
UiFieldLabel,
|
|
20
|
+
UiFieldContent,
|
|
21
|
+
UiFieldSet,
|
|
22
|
+
UiFieldLegend,
|
|
23
|
+
UiFieldGroup,
|
|
24
|
+
} from '@/components/UiField';
|
|
16
25
|
import {
|
|
17
26
|
UiDropdownMenu,
|
|
18
27
|
UiDropdownMenuContent,
|
|
@@ -717,7 +726,7 @@ function handleColumnOrderChange(nextOrder: string[]) {
|
|
|
717
726
|
draggable-columns
|
|
718
727
|
:on-column-order-change="handleColumnOrderChange"
|
|
719
728
|
/>
|
|
720
|
-
<p class="body-14-regular text-muted
|
|
729
|
+
<p class="body-14-regular text-content-on-surface-muted">
|
|
721
730
|
Drag a column header to reorder columns.
|
|
722
731
|
<span v-if="columnOrder.length">
|
|
723
732
|
Current order: {{ columnOrder.join(', ') }}
|
|
@@ -1221,7 +1230,7 @@ export const WithDraggableColumns: Story = {
|
|
|
1221
1230
|
v-bind="args"
|
|
1222
1231
|
:on-column-order-change="handleColumnOrderChange"
|
|
1223
1232
|
/>
|
|
1224
|
-
<p class="body-14-regular text-muted
|
|
1233
|
+
<p class="body-14-regular text-content-on-surface-muted">
|
|
1225
1234
|
Drag a column header to reorder columns.
|
|
1226
1235
|
<span v-if="columnOrder.length">
|
|
1227
1236
|
Current order: {{ columnOrder.join(', ') }}
|
|
@@ -1261,7 +1270,7 @@ export const WithExpandableRows: Story = {
|
|
|
1261
1270
|
<template #expanded-row="{ row }">
|
|
1262
1271
|
<div class="body-14-regular rounded-md bg-background-surface-muted p-4">
|
|
1263
1272
|
<p class="font-medium">Payment {{ row.original.id }}</p>
|
|
1264
|
-
<p class="text-muted
|
|
1273
|
+
<p class="text-content-on-surface-muted">
|
|
1265
1274
|
Customer: {{ row.original.email }} - Status: {{ row.original.status }}
|
|
1266
1275
|
</p>
|
|
1267
1276
|
</div>
|
|
@@ -1379,7 +1388,7 @@ const columns: ColumnDef<Payment>[] = [
|
|
|
1379
1388
|
<template>
|
|
1380
1389
|
<UiDataTable :data="data" :columns="columns">
|
|
1381
1390
|
<template #empty>
|
|
1382
|
-
<div class="flex flex-col items-center gap-2 text-muted
|
|
1391
|
+
<div class="flex flex-col items-center gap-2 text-content-on-surface-muted">
|
|
1383
1392
|
<UiIcon name="ban" :size="32" />
|
|
1384
1393
|
<p>No data available for this view.</p>
|
|
1385
1394
|
</div>
|
|
@@ -1414,7 +1423,7 @@ export const WithCustomEmptySlot: Story = {
|
|
|
1414
1423
|
template: `
|
|
1415
1424
|
<UiDataTable v-bind="args">
|
|
1416
1425
|
<template #empty>
|
|
1417
|
-
<div class="flex flex-col items-center gap-2 text-muted
|
|
1426
|
+
<div class="flex flex-col items-center gap-2 text-content-on-surface-muted">
|
|
1418
1427
|
<UiIcon name="ban" :size="32" />
|
|
1419
1428
|
<p>No data available for this view.</p>
|
|
1420
1429
|
</div>
|
|
@@ -1927,7 +1936,7 @@ const cellFormattingColumns: ColumnDef<Payment>[] = [
|
|
|
1927
1936
|
return h(
|
|
1928
1937
|
'div',
|
|
1929
1938
|
{
|
|
1930
|
-
class: `text-right font-medium ${amount > 500 ? 'text-green-800' : 'text-muted
|
|
1939
|
+
class: `text-right font-medium ${amount > 500 ? 'text-green-800' : 'text-content-on-surface-muted'}`,
|
|
1931
1940
|
},
|
|
1932
1941
|
formatted,
|
|
1933
1942
|
);
|
|
@@ -1995,7 +2004,7 @@ const columns: ColumnDef<Payment>[] = [
|
|
|
1995
2004
|
currency: 'EUR',
|
|
1996
2005
|
}).format(amount);
|
|
1997
2006
|
return h('div', {
|
|
1998
|
-
class: \`text-right font-medium \${amount > 500 ? 'text-green-800' : 'text-muted
|
|
2007
|
+
class: \`text-right font-medium \${amount > 500 ? 'text-green-800' : 'text-content-on-surface-muted'}\`,
|
|
1999
2008
|
}, formatted);
|
|
2000
2009
|
},
|
|
2001
2010
|
},
|
|
@@ -2128,7 +2137,408 @@ export const WithRowClick: Story = {
|
|
|
2128
2137
|
<div v-if="clickedRow" class="body-14-regular mt-4 rounded border p-3">
|
|
2129
2138
|
Clicked: <strong>{{ clickedRow.email }}</strong> - {{ clickedRow.status }} - {{ new Intl.NumberFormat('de-DE', { style: 'currency', currency: 'EUR' }).format(clickedRow.amount) }}
|
|
2130
2139
|
</div>
|
|
2131
|
-
<div v-else class="body-14-regular text-muted
|
|
2140
|
+
<div v-else class="body-14-regular text-content-on-surface-muted mt-4">Click a row to see its data</div>
|
|
2141
|
+
</div>
|
|
2142
|
+
`,
|
|
2143
|
+
}),
|
|
2144
|
+
};
|
|
2145
|
+
|
|
2146
|
+
/**
|
|
2147
|
+
* Amount ranges (in EUR) used by the filter menu checkbox group. Ranges are
|
|
2148
|
+
* non-overlapping: the upper bound is inclusive while the lower bound is
|
|
2149
|
+
* exclusive (except the first range), so e.g. 100 falls in "0–100" only.
|
|
2150
|
+
*/
|
|
2151
|
+
const AMOUNT_RANGES: Record<
|
|
2152
|
+
string,
|
|
2153
|
+
{ min: number; max: number; minInclusive: boolean }
|
|
2154
|
+
> = {
|
|
2155
|
+
'amount-0': { min: 0, max: 100, minInclusive: true },
|
|
2156
|
+
'amount-1': { min: 100, max: 400, minInclusive: false },
|
|
2157
|
+
'amount-2': { min: 400, max: 700, minInclusive: false },
|
|
2158
|
+
'amount-3': { min: 700, max: 1000, minInclusive: false },
|
|
2159
|
+
};
|
|
2160
|
+
|
|
2161
|
+
const AMOUNT_OPTIONS = [
|
|
2162
|
+
{ id: 'amount-0', label: 'From 0 to 100,00 €' },
|
|
2163
|
+
{ id: 'amount-1', label: 'From 100,00 € to 400,00 €' },
|
|
2164
|
+
{ id: 'amount-2', label: 'From 400,00 € to 700,00 €' },
|
|
2165
|
+
{ id: 'amount-3', label: 'From 700,00 € to 1.000,00 €' },
|
|
2166
|
+
];
|
|
2167
|
+
|
|
2168
|
+
// UiButton's `end-icon` takes a component, so wrap UiIcon to render the "x".
|
|
2169
|
+
const XIcon = {
|
|
2170
|
+
components: { UiIcon },
|
|
2171
|
+
template: '<UiIcon name="x" :size="16" />',
|
|
2172
|
+
};
|
|
2173
|
+
|
|
2174
|
+
// Reuse the sortable columns but give `amount` a custom range filter so the
|
|
2175
|
+
// checkbox group can match rows falling into any selected range.
|
|
2176
|
+
const filterMenuColumns: ColumnDef<Payment>[] = sortableColumns.map((column) =>
|
|
2177
|
+
'accessorKey' in column && column.accessorKey === 'amount'
|
|
2178
|
+
? {
|
|
2179
|
+
...column,
|
|
2180
|
+
filterFn: (row: Row<Payment>, columnId: string, value: string[]) => {
|
|
2181
|
+
if (!value?.length) return true;
|
|
2182
|
+
const amount = Number(row.getValue(columnId));
|
|
2183
|
+
return value.some((key) => {
|
|
2184
|
+
const range = AMOUNT_RANGES[key];
|
|
2185
|
+
if (!range) return true;
|
|
2186
|
+
const aboveMin = range.minInclusive
|
|
2187
|
+
? amount >= range.min
|
|
2188
|
+
: amount > range.min;
|
|
2189
|
+
return aboveMin && amount <= range.max;
|
|
2190
|
+
});
|
|
2191
|
+
},
|
|
2192
|
+
}
|
|
2193
|
+
: column,
|
|
2194
|
+
);
|
|
2195
|
+
|
|
2196
|
+
const withFilterMenuTemplateSource = `<script setup lang="ts">
|
|
2197
|
+
import { computed, h, reactive, ref } from 'vue';
|
|
2198
|
+
import {
|
|
2199
|
+
UiButton,
|
|
2200
|
+
UiCheckbox,
|
|
2201
|
+
UiDataTable,
|
|
2202
|
+
UiDataTableColumnHeader,
|
|
2203
|
+
UiDataTableFilterMenu,
|
|
2204
|
+
UiDataTableToolbar,
|
|
2205
|
+
UiField,
|
|
2206
|
+
UiFieldContent,
|
|
2207
|
+
UiFieldGroup,
|
|
2208
|
+
UiFieldLabel,
|
|
2209
|
+
UiFieldLegend,
|
|
2210
|
+
UiFieldSet,
|
|
2211
|
+
UiIcon,
|
|
2212
|
+
UiInput,
|
|
2213
|
+
} from '@aleph-alpha/ui-library';
|
|
2214
|
+
import type { ColumnDef, Row } from '@aleph-alpha/ui-library';
|
|
2215
|
+
|
|
2216
|
+
interface Payment {
|
|
2217
|
+
id: string;
|
|
2218
|
+
amount: number;
|
|
2219
|
+
status: string;
|
|
2220
|
+
email: string;
|
|
2221
|
+
}
|
|
2222
|
+
|
|
2223
|
+
const data: Payment[] = [
|
|
2224
|
+
{ id: '1', amount: 316, status: 'success', email: 'ken99@yahoo.com' },
|
|
2225
|
+
{ id: '2', amount: 242, status: 'success', email: 'abe45@gmail.com' },
|
|
2226
|
+
{ id: '3', amount: 837, status: 'processing', email: 'monserrat44@gmail.com' },
|
|
2227
|
+
];
|
|
2228
|
+
|
|
2229
|
+
// Non-overlapping amount ranges (EUR) matched by the checkbox group.
|
|
2230
|
+
const amountRanges: Record<string, { min: number; max: number; minInclusive: boolean }> = {
|
|
2231
|
+
'amount-0': { min: 0, max: 100, minInclusive: true },
|
|
2232
|
+
'amount-1': { min: 100, max: 400, minInclusive: false },
|
|
2233
|
+
'amount-2': { min: 400, max: 700, minInclusive: false },
|
|
2234
|
+
'amount-3': { min: 700, max: 1000, minInclusive: false },
|
|
2235
|
+
};
|
|
2236
|
+
|
|
2237
|
+
const amountOptions = [
|
|
2238
|
+
{ id: 'amount-0', label: 'From 0 to 100,00 €' },
|
|
2239
|
+
{ id: 'amount-1', label: 'From 100,00 € to 400,00 €' },
|
|
2240
|
+
{ id: 'amount-2', label: 'From 400,00 € to 700,00 €' },
|
|
2241
|
+
{ id: 'amount-3', label: 'From 700,00 € to 1.000,00 €' },
|
|
2242
|
+
];
|
|
2243
|
+
|
|
2244
|
+
// UiButton's \`end-icon\` takes a component, so wrap UiIcon to render the "x".
|
|
2245
|
+
const XIcon = {
|
|
2246
|
+
components: { UiIcon },
|
|
2247
|
+
template: '<UiIcon name="x" :size="16" />',
|
|
2248
|
+
};
|
|
2249
|
+
|
|
2250
|
+
const columns: ColumnDef<Payment>[] = [
|
|
2251
|
+
{
|
|
2252
|
+
accessorKey: 'status',
|
|
2253
|
+
header: ({ column }) => h(UiDataTableColumnHeader, { column, title: 'Status' }),
|
|
2254
|
+
},
|
|
2255
|
+
{
|
|
2256
|
+
accessorKey: 'email',
|
|
2257
|
+
header: ({ column }) => h(UiDataTableColumnHeader, { column, title: 'Email' }),
|
|
2258
|
+
},
|
|
2259
|
+
{
|
|
2260
|
+
accessorKey: 'amount',
|
|
2261
|
+
header: ({ column }) => h(UiDataTableColumnHeader, { column, title: 'Amount', class: 'justify-end' }),
|
|
2262
|
+
// Match rows whose amount falls into any selected range.
|
|
2263
|
+
filterFn: (row: Row<Payment>, columnId, value: string[]) => {
|
|
2264
|
+
if (!value?.length) return true;
|
|
2265
|
+
const amount = Number(row.getValue(columnId));
|
|
2266
|
+
return value.some((key) => {
|
|
2267
|
+
const range = amountRanges[key];
|
|
2268
|
+
if (!range) return true;
|
|
2269
|
+
const aboveMin = range.minInclusive ? amount >= range.min : amount > range.min;
|
|
2270
|
+
return aboveMin && amount <= range.max;
|
|
2271
|
+
});
|
|
2272
|
+
},
|
|
2273
|
+
},
|
|
2274
|
+
];
|
|
2275
|
+
|
|
2276
|
+
const tableRef = ref<InstanceType<typeof UiDataTable>>();
|
|
2277
|
+
const table = computed(() => tableRef.value?.table);
|
|
2278
|
+
const filterOpen = ref(false);
|
|
2279
|
+
|
|
2280
|
+
// Draft state edited in the form; committed to the table only on "Apply".
|
|
2281
|
+
const draft = reactive({ email: '', status: '', amount: [] as string[] });
|
|
2282
|
+
|
|
2283
|
+
// Count of applied filters drives the trigger badge and the "Remove filters" button.
|
|
2284
|
+
const activeCount = computed(() => table.value?.getState().columnFilters.length ?? 0);
|
|
2285
|
+
|
|
2286
|
+
// Checkbox group: toggle membership in the array (each checkbox is a boolean).
|
|
2287
|
+
function toggleAmount(id: string, checked: boolean | 'indeterminate') {
|
|
2288
|
+
const next = new Set(draft.amount);
|
|
2289
|
+
checked ? next.add(id) : next.delete(id);
|
|
2290
|
+
draft.amount = [...next];
|
|
2291
|
+
}
|
|
2292
|
+
|
|
2293
|
+
function syncDraftFromTable() {
|
|
2294
|
+
draft.email = (table.value?.getColumn('email')?.getFilterValue() as string) ?? '';
|
|
2295
|
+
draft.status = (table.value?.getColumn('status')?.getFilterValue() as string) ?? '';
|
|
2296
|
+
draft.amount = [...((table.value?.getColumn('amount')?.getFilterValue() as string[]) ?? [])];
|
|
2297
|
+
}
|
|
2298
|
+
|
|
2299
|
+
function applyFilters() {
|
|
2300
|
+
table.value?.getColumn('email')?.setFilterValue(draft.email || undefined);
|
|
2301
|
+
table.value?.getColumn('status')?.setFilterValue(draft.status || undefined);
|
|
2302
|
+
table.value?.getColumn('amount')?.setFilterValue(draft.amount.length ? [...draft.amount] : undefined);
|
|
2303
|
+
filterOpen.value = false;
|
|
2304
|
+
}
|
|
2305
|
+
|
|
2306
|
+
function cancelFilters() {
|
|
2307
|
+
syncDraftFromTable();
|
|
2308
|
+
filterOpen.value = false;
|
|
2309
|
+
}
|
|
2310
|
+
|
|
2311
|
+
// Clear every applied filter and reset the draft form.
|
|
2312
|
+
function removeFilters() {
|
|
2313
|
+
table.value?.resetColumnFilters();
|
|
2314
|
+
draft.email = '';
|
|
2315
|
+
draft.status = '';
|
|
2316
|
+
draft.amount = [];
|
|
2317
|
+
}
|
|
2318
|
+
</script>
|
|
2319
|
+
|
|
2320
|
+
<template>
|
|
2321
|
+
<div class="space-y-4">
|
|
2322
|
+
<UiDataTableToolbar>
|
|
2323
|
+
<UiDataTableFilterMenu v-if="table" v-model:open="filterOpen" :active-count="activeCount">
|
|
2324
|
+
<form class="flex flex-col gap-xl" @submit.prevent="applyFilters">
|
|
2325
|
+
<UiFieldGroup>
|
|
2326
|
+
<UiField>
|
|
2327
|
+
<UiFieldLabel for="filter-email">Email</UiFieldLabel>
|
|
2328
|
+
<UiFieldContent>
|
|
2329
|
+
<UiInput id="filter-email" v-model="draft.email" name="email" placeholder="Placeholder" />
|
|
2330
|
+
</UiFieldContent>
|
|
2331
|
+
</UiField>
|
|
2332
|
+
<UiField>
|
|
2333
|
+
<UiFieldLabel for="filter-status">Status</UiFieldLabel>
|
|
2334
|
+
<UiFieldContent>
|
|
2335
|
+
<UiInput id="filter-status" v-model="draft.status" name="status" placeholder="Placeholder" />
|
|
2336
|
+
</UiFieldContent>
|
|
2337
|
+
</UiField>
|
|
2338
|
+
<UiFieldSet>
|
|
2339
|
+
<UiFieldLegend variant="legend">Amount</UiFieldLegend>
|
|
2340
|
+
<UiFieldGroup data-slot="checkbox-group">
|
|
2341
|
+
<UiField v-for="option in amountOptions" :key="option.id" orientation="responsive">
|
|
2342
|
+
<UiCheckbox
|
|
2343
|
+
:id="option.id"
|
|
2344
|
+
:name="option.id"
|
|
2345
|
+
:model-value="draft.amount.includes(option.id)"
|
|
2346
|
+
@update:model-value="(checked) => toggleAmount(option.id, checked)"
|
|
2347
|
+
/>
|
|
2348
|
+
<UiFieldLabel :for="option.id">{{ option.label }}</UiFieldLabel>
|
|
2349
|
+
</UiField>
|
|
2350
|
+
</UiFieldGroup>
|
|
2351
|
+
</UiFieldSet>
|
|
2352
|
+
<div class="flex items-center gap-2">
|
|
2353
|
+
<UiButton v-if="!!activeCount" variant="outline" :end-icon="XIcon" type="button" @click="removeFilters">
|
|
2354
|
+
Remove filters
|
|
2355
|
+
</UiButton>
|
|
2356
|
+
<div class="ml-auto flex gap-2">
|
|
2357
|
+
<UiButton variant="ghost" type="button" @click="cancelFilters">Cancel</UiButton>
|
|
2358
|
+
<UiButton type="submit">Apply</UiButton>
|
|
2359
|
+
</div>
|
|
2360
|
+
</div>
|
|
2361
|
+
</UiFieldGroup>
|
|
2362
|
+
</form>
|
|
2363
|
+
</UiDataTableFilterMenu>
|
|
2364
|
+
</UiDataTableToolbar>
|
|
2365
|
+
<UiDataTable ref="tableRef" :columns="columns" :data="data" />
|
|
2366
|
+
</div>
|
|
2367
|
+
</template>`;
|
|
2368
|
+
|
|
2369
|
+
/**
|
|
2370
|
+
* Table with a multi-field filter menu popover.
|
|
2371
|
+
*
|
|
2372
|
+
* `UiDataTableFilterMenu` holds a form of filter controls. Edits are kept in a
|
|
2373
|
+
* local `draft` and only committed to the table on **Apply**; **Cancel** reverts
|
|
2374
|
+
* the draft to the applied state. When any filter is active, a **Remove filters**
|
|
2375
|
+
* button clears them all via `table.resetColumnFilters()`. The trigger badge
|
|
2376
|
+
* reflects the number of applied column filters.
|
|
2377
|
+
*/
|
|
2378
|
+
export const WithFilterMenu: Story = {
|
|
2379
|
+
args: {
|
|
2380
|
+
data: payments,
|
|
2381
|
+
columns: filterMenuColumns,
|
|
2382
|
+
},
|
|
2383
|
+
parameters: {
|
|
2384
|
+
docs: {
|
|
2385
|
+
source: {
|
|
2386
|
+
code: withFilterMenuTemplateSource,
|
|
2387
|
+
},
|
|
2388
|
+
},
|
|
2389
|
+
},
|
|
2390
|
+
render: (args) => ({
|
|
2391
|
+
components: {
|
|
2392
|
+
UiDataTable,
|
|
2393
|
+
UiDataTableFilterMenu,
|
|
2394
|
+
UiDataTableToolbar,
|
|
2395
|
+
UiField,
|
|
2396
|
+
UiFieldLabel,
|
|
2397
|
+
UiFieldContent,
|
|
2398
|
+
UiFieldSet,
|
|
2399
|
+
UiFieldLegend,
|
|
2400
|
+
UiFieldGroup,
|
|
2401
|
+
UiButton,
|
|
2402
|
+
UiCheckbox,
|
|
2403
|
+
UiInput,
|
|
2404
|
+
},
|
|
2405
|
+
setup() {
|
|
2406
|
+
const tableRef = ref<InstanceType<typeof UiDataTable>>();
|
|
2407
|
+
const table = computed(() => tableRef.value?.table);
|
|
2408
|
+
const filterOpen = ref(false);
|
|
2409
|
+
|
|
2410
|
+
const draft = reactive({
|
|
2411
|
+
email: '',
|
|
2412
|
+
status: '',
|
|
2413
|
+
amount: [] as string[],
|
|
2414
|
+
});
|
|
2415
|
+
|
|
2416
|
+
const activeCount = computed(
|
|
2417
|
+
() => table.value?.getState().columnFilters.length ?? 0,
|
|
2418
|
+
);
|
|
2419
|
+
|
|
2420
|
+
function toggleAmount(id: string, checked: boolean | 'indeterminate') {
|
|
2421
|
+
const next = new Set(draft.amount);
|
|
2422
|
+
if (checked) {
|
|
2423
|
+
next.add(id);
|
|
2424
|
+
} else {
|
|
2425
|
+
next.delete(id);
|
|
2426
|
+
}
|
|
2427
|
+
draft.amount = [...next];
|
|
2428
|
+
}
|
|
2429
|
+
|
|
2430
|
+
function syncDraftFromTable() {
|
|
2431
|
+
draft.email =
|
|
2432
|
+
(table.value?.getColumn('email')?.getFilterValue() as string) ?? '';
|
|
2433
|
+
draft.status =
|
|
2434
|
+
(table.value?.getColumn('status')?.getFilterValue() as string) ?? '';
|
|
2435
|
+
draft.amount = [
|
|
2436
|
+
...((table.value?.getColumn('amount')?.getFilterValue() as
|
|
2437
|
+
| string[]
|
|
2438
|
+
| undefined) ?? []),
|
|
2439
|
+
];
|
|
2440
|
+
}
|
|
2441
|
+
|
|
2442
|
+
function applyFilters() {
|
|
2443
|
+
table.value
|
|
2444
|
+
?.getColumn('email')
|
|
2445
|
+
?.setFilterValue(draft.email || undefined);
|
|
2446
|
+
table.value
|
|
2447
|
+
?.getColumn('status')
|
|
2448
|
+
?.setFilterValue(draft.status || undefined);
|
|
2449
|
+
table.value
|
|
2450
|
+
?.getColumn('amount')
|
|
2451
|
+
?.setFilterValue(draft.amount.length ? [...draft.amount] : undefined);
|
|
2452
|
+
filterOpen.value = false;
|
|
2453
|
+
}
|
|
2454
|
+
|
|
2455
|
+
function cancelFilters() {
|
|
2456
|
+
syncDraftFromTable();
|
|
2457
|
+
filterOpen.value = false;
|
|
2458
|
+
}
|
|
2459
|
+
|
|
2460
|
+
function removeFilters() {
|
|
2461
|
+
table.value?.resetColumnFilters();
|
|
2462
|
+
draft.email = '';
|
|
2463
|
+
draft.status = '';
|
|
2464
|
+
draft.amount = [];
|
|
2465
|
+
}
|
|
2466
|
+
|
|
2467
|
+
return {
|
|
2468
|
+
args,
|
|
2469
|
+
table,
|
|
2470
|
+
tableRef,
|
|
2471
|
+
filterOpen,
|
|
2472
|
+
draft,
|
|
2473
|
+
activeCount,
|
|
2474
|
+
amountOptions: AMOUNT_OPTIONS,
|
|
2475
|
+
XIcon,
|
|
2476
|
+
toggleAmount,
|
|
2477
|
+
applyFilters,
|
|
2478
|
+
cancelFilters,
|
|
2479
|
+
removeFilters,
|
|
2480
|
+
};
|
|
2481
|
+
},
|
|
2482
|
+
template: `
|
|
2483
|
+
<div class="space-y-4">
|
|
2484
|
+
<UiDataTableToolbar>
|
|
2485
|
+
<UiDataTableFilterMenu
|
|
2486
|
+
v-if="table"
|
|
2487
|
+
v-model:open="filterOpen"
|
|
2488
|
+
:active-count="activeCount"
|
|
2489
|
+
>
|
|
2490
|
+
<form class="flex flex-col gap-xl" @submit.prevent="applyFilters">
|
|
2491
|
+
<UiFieldGroup>
|
|
2492
|
+
<UiField>
|
|
2493
|
+
<UiFieldLabel for="filter-email">Email</UiFieldLabel>
|
|
2494
|
+
<UiFieldContent>
|
|
2495
|
+
<UiInput id="filter-email" v-model="draft.email" name="email" placeholder="Placeholder" />
|
|
2496
|
+
</UiFieldContent>
|
|
2497
|
+
</UiField>
|
|
2498
|
+
<UiField>
|
|
2499
|
+
<UiFieldLabel for="filter-status">Status</UiFieldLabel>
|
|
2500
|
+
<UiFieldContent>
|
|
2501
|
+
<UiInput id="filter-status" v-model="draft.status" name="status" placeholder="Placeholder" />
|
|
2502
|
+
</UiFieldContent>
|
|
2503
|
+
</UiField>
|
|
2504
|
+
<UiFieldSet>
|
|
2505
|
+
<UiFieldLegend variant="legend">Amount</UiFieldLegend>
|
|
2506
|
+
<UiFieldGroup data-slot="checkbox-group">
|
|
2507
|
+
<UiField
|
|
2508
|
+
v-for="option in amountOptions"
|
|
2509
|
+
:key="option.id"
|
|
2510
|
+
orientation="responsive"
|
|
2511
|
+
>
|
|
2512
|
+
<UiCheckbox
|
|
2513
|
+
:id="option.id"
|
|
2514
|
+
:name="option.id"
|
|
2515
|
+
:model-value="draft.amount.includes(option.id)"
|
|
2516
|
+
@update:model-value="(checked) => toggleAmount(option.id, checked)"
|
|
2517
|
+
/>
|
|
2518
|
+
<UiFieldLabel :for="option.id">{{ option.label }}</UiFieldLabel>
|
|
2519
|
+
</UiField>
|
|
2520
|
+
</UiFieldGroup>
|
|
2521
|
+
</UiFieldSet>
|
|
2522
|
+
<div class="flex items-center gap-2">
|
|
2523
|
+
<UiButton
|
|
2524
|
+
v-if="!!activeCount"
|
|
2525
|
+
variant="outline"
|
|
2526
|
+
:end-icon="XIcon"
|
|
2527
|
+
type="button"
|
|
2528
|
+
@click="removeFilters"
|
|
2529
|
+
>
|
|
2530
|
+
Remove filters
|
|
2531
|
+
</UiButton>
|
|
2532
|
+
<div class="ml-auto flex gap-2">
|
|
2533
|
+
<UiButton variant="ghost" type="button" @click="cancelFilters">Cancel</UiButton>
|
|
2534
|
+
<UiButton type="submit">Apply</UiButton>
|
|
2535
|
+
</div>
|
|
2536
|
+
</div>
|
|
2537
|
+
</UiFieldGroup>
|
|
2538
|
+
</form>
|
|
2539
|
+
</UiDataTableFilterMenu>
|
|
2540
|
+
</UiDataTableToolbar>
|
|
2541
|
+
<UiDataTable ref="tableRef" v-bind="args" />
|
|
2132
2542
|
</div>
|
|
2133
2543
|
`,
|
|
2134
2544
|
}),
|
|
@@ -67,7 +67,7 @@ function getColumnLabel(column: (typeof columns.value)[number]) {
|
|
|
67
67
|
</template>
|
|
68
68
|
</UiToggle>
|
|
69
69
|
</UiDropdownMenuTrigger>
|
|
70
|
-
<UiDropdownMenuContent align="
|
|
70
|
+
<UiDropdownMenuContent align="start" class="flex flex-col gap-2 p-2">
|
|
71
71
|
<UiDropdownMenuCheckboxItem
|
|
72
72
|
v-for="column in columns"
|
|
73
73
|
:key="column.id"
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
<script setup lang="ts" generic="TData">
|
|
2
|
+
/**
|
|
3
|
+
* UiDataTableFilterMenu renders a popover of filter controls for a data table.
|
|
4
|
+
*
|
|
5
|
+
* Place filter fields (inputs, checkbox groups, etc.) in the default slot. The
|
|
6
|
+
* trigger is a soft toggle that shows an optional count badge and stays filled
|
|
7
|
+
* while filters are applied.
|
|
8
|
+
* @component UiDataTableFilterMenu
|
|
9
|
+
* @property {number} [activeCount=0] - Number of applied filters. Shows a count
|
|
10
|
+
* badge and keeps the trigger filled when greater than `0`.
|
|
11
|
+
* @property {FilterMenuLabels} [labels] - i18n label overrides.
|
|
12
|
+
* @slot default - Filter controls (usually a form with inputs and checkbox groups).
|
|
13
|
+
*/
|
|
14
|
+
import { UiToggle } from '@/components';
|
|
15
|
+
import { UiBadge } from '@/components/UiBadge';
|
|
16
|
+
import UiIcon from '@/components/UiIcon/UiIcon.vue';
|
|
17
|
+
import UiPopover from '@/components/UiPopover/UiPopover.vue';
|
|
18
|
+
import UiPopoverContent from '@/components/UiPopover/UiPopoverContent.vue';
|
|
19
|
+
import UiPopoverTrigger from '@/components/UiPopover/UiPopoverTrigger.vue';
|
|
20
|
+
import { computed } from 'vue';
|
|
21
|
+
import { DATA_TABLE_LABELS } from './constants';
|
|
22
|
+
import type { UiDataTableFilterMenuProps } from './types';
|
|
23
|
+
|
|
24
|
+
defineOptions({
|
|
25
|
+
name: 'UiDataTableFilterMenu',
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
const props = defineProps<UiDataTableFilterMenuProps<TData>>();
|
|
29
|
+
|
|
30
|
+
defineSlots<{
|
|
31
|
+
/** Filter controls, usually a form with inputs and checkbox groups. */
|
|
32
|
+
default(): unknown;
|
|
33
|
+
}>();
|
|
34
|
+
|
|
35
|
+
const open = defineModel<boolean>('open', { default: false });
|
|
36
|
+
|
|
37
|
+
const labels = computed(() => ({
|
|
38
|
+
filters: props.labels?.filters ?? DATA_TABLE_LABELS.filters,
|
|
39
|
+
toggleFilters: props.labels?.toggleFilters ?? DATA_TABLE_LABELS.toggleFilters,
|
|
40
|
+
}));
|
|
41
|
+
|
|
42
|
+
const activeCount = computed(() => props.activeCount ?? 0);
|
|
43
|
+
const hasActiveFilters = computed(() => activeCount.value > 0);
|
|
44
|
+
|
|
45
|
+
// Keep the accessible name in sync with the visible label (WCAG 2.5.3) and
|
|
46
|
+
// surface the applied count to assistive tech.
|
|
47
|
+
const triggerAriaLabel = computed(() =>
|
|
48
|
+
hasActiveFilters.value
|
|
49
|
+
? `${labels.value.toggleFilters}, ${activeCount.value} applied`
|
|
50
|
+
: labels.value.toggleFilters,
|
|
51
|
+
);
|
|
52
|
+
</script>
|
|
53
|
+
|
|
54
|
+
<template>
|
|
55
|
+
<UiPopover v-model:open="open">
|
|
56
|
+
<UiPopoverTrigger as-child>
|
|
57
|
+
<UiToggle
|
|
58
|
+
:active="open || hasActiveFilters"
|
|
59
|
+
variant="soft"
|
|
60
|
+
size="sm"
|
|
61
|
+
class="label-14-medium h-8"
|
|
62
|
+
left-icon="list-filter"
|
|
63
|
+
:aria-label="triggerAriaLabel"
|
|
64
|
+
>
|
|
65
|
+
<span class="inline-flex items-center gap-xs">
|
|
66
|
+
{{ labels.filters }}
|
|
67
|
+
<UiBadge
|
|
68
|
+
v-if="hasActiveFilters"
|
|
69
|
+
variant="default"
|
|
70
|
+
size="small"
|
|
71
|
+
class="h-5 min-w-5 justify-center px-1 label-12-medium"
|
|
72
|
+
>
|
|
73
|
+
{{ activeCount }}
|
|
74
|
+
</UiBadge>
|
|
75
|
+
</span>
|
|
76
|
+
<template #right-icon>
|
|
77
|
+
<UiIcon
|
|
78
|
+
name="chevron-down"
|
|
79
|
+
:size="16"
|
|
80
|
+
aria-hidden="true"
|
|
81
|
+
class="transition-transform"
|
|
82
|
+
:class="open ? 'rotate-180' : undefined"
|
|
83
|
+
/>
|
|
84
|
+
</template>
|
|
85
|
+
</UiToggle>
|
|
86
|
+
</UiPopoverTrigger>
|
|
87
|
+
<UiPopoverContent align="start" side="bottom" class="min-w-[350px]">
|
|
88
|
+
<slot />
|
|
89
|
+
</UiPopoverContent>
|
|
90
|
+
</UiPopover>
|
|
91
|
+
</template>
|
|
@@ -38,7 +38,7 @@ const labels = computed(() => ({
|
|
|
38
38
|
<div class="flex items-center gap-2 justify-between px-2">
|
|
39
39
|
<div
|
|
40
40
|
v-if="showSelection"
|
|
41
|
-
class="flex-1 body-14-regular text-muted
|
|
41
|
+
class="flex-1 body-14-regular text-content-on-surface-muted"
|
|
42
42
|
>
|
|
43
43
|
{{
|
|
44
44
|
labels.rowsSelected(
|
|
@@ -27,6 +27,10 @@ export const DATA_TABLE_LABELS = {
|
|
|
27
27
|
rowsSelected: (selected: number, total: number) =>
|
|
28
28
|
`${selected} of ${total} row(s) selected.`,
|
|
29
29
|
|
|
30
|
+
/** UiDataTableFilterMenu */
|
|
31
|
+
filters: 'Filters',
|
|
32
|
+
toggleFilters: 'Toggle Filters',
|
|
33
|
+
|
|
30
34
|
/** UiDataTableColumnFilter */
|
|
31
35
|
columns: 'Columns',
|
|
32
36
|
toggleColumns: 'Toggle columns',
|
|
@@ -76,3 +80,11 @@ export interface ColumnFilterLabels {
|
|
|
76
80
|
/** Dropdown section label. */
|
|
77
81
|
columnVisibility?: string;
|
|
78
82
|
}
|
|
83
|
+
|
|
84
|
+
/** Labels for UiDataTableFilterMenu */
|
|
85
|
+
export interface FilterMenuLabels {
|
|
86
|
+
/** Visible label for the trigger button. */
|
|
87
|
+
filters?: string;
|
|
88
|
+
/** Accessible label for the trigger button. */
|
|
89
|
+
toggleFilters?: string;
|
|
90
|
+
}
|
|
@@ -3,6 +3,7 @@ export { default as UiDataTableColumnFilter } from './UiDataTableColumnFilter.vu
|
|
|
3
3
|
export { default as UiDataTableColumnHeader } from './UiDataTableColumnHeader.vue';
|
|
4
4
|
export { default as UiDataTablePagination } from './UiDataTablePagination.vue';
|
|
5
5
|
export { default as UiDataTableToolbar } from './UiDataTableToolbar.vue';
|
|
6
|
+
export { default as UiDataTableFilterMenu } from './UiDataTableFilterMenu.vue';
|
|
6
7
|
export type { Column, ColumnDef, Row, Table } from '@tanstack/vue-table';
|
|
7
8
|
export * from './types';
|
|
8
9
|
export * from './constants';
|
|
@@ -2,6 +2,7 @@ import type { Column, ColumnDef, Row, Table } from '@tanstack/vue-table';
|
|
|
2
2
|
import type {
|
|
3
3
|
ColumnHeaderLabels,
|
|
4
4
|
ColumnFilterLabels,
|
|
5
|
+
FilterMenuLabels,
|
|
5
6
|
PaginationLabels,
|
|
6
7
|
} from './constants';
|
|
7
8
|
|
|
@@ -127,3 +128,26 @@ export type UiDataTableColumnFilterProps<TData> = {
|
|
|
127
128
|
*/
|
|
128
129
|
labels?: ColumnFilterLabels;
|
|
129
130
|
};
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* Props for the UiDataTableFilterMenu component.
|
|
134
|
+
*/
|
|
135
|
+
export type UiDataTableFilterMenuProps<TData> = {
|
|
136
|
+
/**
|
|
137
|
+
* The TanStack Table instance. Optional — the menu only hosts filter controls
|
|
138
|
+
* passed via the default slot and does not read from the table directly.
|
|
139
|
+
* @internal
|
|
140
|
+
*/
|
|
141
|
+
table?: Table<TData>;
|
|
142
|
+
/**
|
|
143
|
+
* Number of filters currently applied. When greater than `0`, a count badge is
|
|
144
|
+
* shown next to the label and the trigger stays visually filled (active).
|
|
145
|
+
* @default 0
|
|
146
|
+
*/
|
|
147
|
+
activeCount?: number;
|
|
148
|
+
/**
|
|
149
|
+
* Custom labels for i18n support.
|
|
150
|
+
* Partial object that merges with defaults.
|
|
151
|
+
*/
|
|
152
|
+
labels?: FilterMenuLabels;
|
|
153
|
+
};
|