vueless 0.0.533 → 0.0.535
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/composables/useAutoPosition.ts +0 -9
- package/package.json +1 -1
- package/types.ts +24 -0
- package/ui.button/types.ts +3 -22
- package/ui.button-link/types.ts +2 -22
- package/ui.data-table/UTable.vue +16 -7
- package/ui.data-table/UTableRow.vue +0 -2
- package/ui.data-table/utilTable.ts +5 -1
- package/ui.dropdown-badge/UDropdownBadge.vue +16 -9
- package/ui.dropdown-badge/storybook/stories.ts +9 -6
- package/ui.dropdown-badge/types.ts +8 -27
- package/ui.dropdown-badge/useAttrs.ts +5 -5
- package/ui.dropdown-button/UDropdownButton.vue +32 -10
- package/ui.dropdown-button/storybook/stories.ts +15 -10
- package/ui.dropdown-button/types.ts +9 -28
- package/ui.dropdown-button/useAttrs.ts +6 -6
- package/ui.dropdown-link/UDropdownLink.vue +16 -9
- package/ui.dropdown-link/storybook/stories.ts +13 -10
- package/ui.dropdown-link/types.ts +8 -27
- package/ui.dropdown-link/useAttrs.ts +6 -7
- package/ui.dropdown-list/UDropdownList.vue +38 -26
- package/ui.dropdown-list/storybook/stories.ts +12 -10
- package/ui.dropdown-list/types.ts +28 -11
- package/ui.dropdown-list/useAttrs.ts +2 -2
- package/ui.dropdown-list/usePointer.ts +43 -46
- package/ui.form-date-picker-range/useAttrs.ts +3 -3
- package/ui.form-select/storybook/stories.js +1 -0
- package/ui.image-avatar/types.ts +3 -22
- package/ui.image-icon/types.ts +2 -23
- package/ui.loader/types.ts +3 -23
- package/ui.loader-overlay/types.ts +3 -23
- package/ui.loader-progress/types.ts +3 -22
- package/ui.navigation-progress/types.ts +3 -22
- package/ui.other-dot/types.ts +3 -22
- package/ui.text-alert/types.ts +3 -22
- package/ui.text-badge/types.ts +3 -22
- package/ui.text-header/types.ts +3 -22
- package/ui.text-money/types.ts +3 -22
- package/web-types.json +97 -439
|
@@ -14,15 +14,6 @@ export enum Direction {
|
|
|
14
14
|
export type Align = `${Direction}`;
|
|
15
15
|
export type Position = { x: Align; y: Align };
|
|
16
16
|
|
|
17
|
-
// TODO: Remove it after ui.form-date-picker-range and ui.form-date-picker ts migration (use enum there instead).
|
|
18
|
-
export const POSITION = {
|
|
19
|
-
left: "left",
|
|
20
|
-
right: "right",
|
|
21
|
-
top: "top",
|
|
22
|
-
bottom: "bottom",
|
|
23
|
-
auto: "auto",
|
|
24
|
-
};
|
|
25
|
-
|
|
26
17
|
export function useAutoPosition(
|
|
27
18
|
anchorElement: MaybeRef<HTMLElement | null>,
|
|
28
19
|
targetElement: MaybeRef<HTMLElement | null>,
|
package/package.json
CHANGED
package/types.ts
CHANGED
|
@@ -54,6 +54,30 @@ export enum ColorMode {
|
|
|
54
54
|
Auto = "auto",
|
|
55
55
|
}
|
|
56
56
|
|
|
57
|
+
export enum Color {
|
|
58
|
+
Brand = "brand",
|
|
59
|
+
Grayscale = "grayscale",
|
|
60
|
+
Gray = "gray",
|
|
61
|
+
Red = "red",
|
|
62
|
+
Orange = "orange",
|
|
63
|
+
Amber = "amber",
|
|
64
|
+
Yellow = "yellow",
|
|
65
|
+
Lime = "lime",
|
|
66
|
+
Green = "green",
|
|
67
|
+
Emerald = "emerald",
|
|
68
|
+
Teal = "teal",
|
|
69
|
+
Cyan = "cyan",
|
|
70
|
+
Sky = "sky",
|
|
71
|
+
Blue = "blue",
|
|
72
|
+
Indigo = "indigo",
|
|
73
|
+
Violet = "violet",
|
|
74
|
+
Purple = "purple",
|
|
75
|
+
Fuchsia = "fuchsia",
|
|
76
|
+
Pink = "pink",
|
|
77
|
+
Rose = "rose",
|
|
78
|
+
White = "white",
|
|
79
|
+
}
|
|
80
|
+
|
|
57
81
|
export interface ExtendedKeyClasses {
|
|
58
82
|
[key: string]: Ref<string>;
|
|
59
83
|
}
|
package/ui.button/types.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import defaultConfig from "./config.ts";
|
|
2
2
|
|
|
3
|
+
import type { Color } from "../types.ts";
|
|
4
|
+
|
|
3
5
|
export type Config = Partial<typeof defaultConfig>;
|
|
4
6
|
|
|
5
7
|
export interface UButtonProps {
|
|
@@ -11,28 +13,7 @@ export interface UButtonProps {
|
|
|
11
13
|
/**
|
|
12
14
|
* Button color.
|
|
13
15
|
*/
|
|
14
|
-
color?:
|
|
15
|
-
| "brand"
|
|
16
|
-
| "grayscale"
|
|
17
|
-
| "gray"
|
|
18
|
-
| "red"
|
|
19
|
-
| "orange"
|
|
20
|
-
| "amber"
|
|
21
|
-
| "yellow"
|
|
22
|
-
| "lime"
|
|
23
|
-
| "green"
|
|
24
|
-
| "emerald"
|
|
25
|
-
| "teal"
|
|
26
|
-
| "cyan"
|
|
27
|
-
| "sky"
|
|
28
|
-
| "blue"
|
|
29
|
-
| "indigo"
|
|
30
|
-
| "violet"
|
|
31
|
-
| "purple"
|
|
32
|
-
| "fuchsia"
|
|
33
|
-
| "pink"
|
|
34
|
-
| "rose"
|
|
35
|
-
| "white";
|
|
16
|
+
color?: `${Color}`;
|
|
36
17
|
|
|
37
18
|
/**
|
|
38
19
|
* Button size.
|
package/ui.button-link/types.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import defaultConfig from "./config.ts";
|
|
2
2
|
|
|
3
3
|
import type { RouteLocationRaw } from "vue-router";
|
|
4
|
+
import type { Color } from "src/types.ts";
|
|
4
5
|
|
|
5
6
|
export type Config = Partial<typeof defaultConfig>;
|
|
6
7
|
|
|
@@ -28,28 +29,7 @@ export interface ULinkProps {
|
|
|
28
29
|
/**
|
|
29
30
|
* Link color.
|
|
30
31
|
*/
|
|
31
|
-
color?:
|
|
32
|
-
| "brand"
|
|
33
|
-
| "grayscale"
|
|
34
|
-
| "gray"
|
|
35
|
-
| "red"
|
|
36
|
-
| "orange"
|
|
37
|
-
| "amber"
|
|
38
|
-
| "yellow"
|
|
39
|
-
| "lime"
|
|
40
|
-
| "green"
|
|
41
|
-
| "emerald"
|
|
42
|
-
| "teal"
|
|
43
|
-
| "cyan"
|
|
44
|
-
| "sky"
|
|
45
|
-
| "blue"
|
|
46
|
-
| "indigo"
|
|
47
|
-
| "violet"
|
|
48
|
-
| "purple"
|
|
49
|
-
| "fuchsia"
|
|
50
|
-
| "pink"
|
|
51
|
-
| "rose"
|
|
52
|
-
| "white";
|
|
32
|
+
color?: `${Color}`;
|
|
53
33
|
|
|
54
34
|
/**
|
|
55
35
|
* Link open type behaviour.
|
package/ui.data-table/UTable.vue
CHANGED
|
@@ -3,7 +3,6 @@ import {
|
|
|
3
3
|
ref,
|
|
4
4
|
computed,
|
|
5
5
|
watch,
|
|
6
|
-
toValue,
|
|
7
6
|
useSlots,
|
|
8
7
|
nextTick,
|
|
9
8
|
onMounted,
|
|
@@ -39,6 +38,7 @@ import { useLocale } from "../composables/useLocale.ts";
|
|
|
39
38
|
|
|
40
39
|
import type { Cell, Row, RowId, UTableProps, UTableRowAttrs } from "./types.ts";
|
|
41
40
|
import type { Ref, RendererElement, ComputedRef } from "vue";
|
|
41
|
+
import { isEqual } from "lodash-es";
|
|
42
42
|
|
|
43
43
|
defineOptions({ inheritAttrs: false });
|
|
44
44
|
|
|
@@ -254,7 +254,15 @@ const tableRowAttrs = computed(() => ({
|
|
|
254
254
|
|
|
255
255
|
watch(selectAll, onChangeSelectAll, { deep: true });
|
|
256
256
|
watch(selectedRows, onChangeSelectedRows, { deep: true });
|
|
257
|
-
watch(
|
|
257
|
+
watch(
|
|
258
|
+
tableRows,
|
|
259
|
+
() => {
|
|
260
|
+
if (!isEqual(tableRows.value, props.rows)) {
|
|
261
|
+
emit("update:rows", tableRows.value);
|
|
262
|
+
}
|
|
263
|
+
},
|
|
264
|
+
{ deep: true },
|
|
265
|
+
);
|
|
258
266
|
watch(() => tableRows.value.length, updateSelectedRows);
|
|
259
267
|
watch(() => props.rows, synchronizeTableItemsWithProps, { deep: true });
|
|
260
268
|
watch(isHeaderSticky, setHeaderCellWidth);
|
|
@@ -337,7 +345,9 @@ function synchronizeTableItemsWithProps() {
|
|
|
337
345
|
selectedRows.value = [];
|
|
338
346
|
}
|
|
339
347
|
|
|
340
|
-
tableRows.value
|
|
348
|
+
if (!isEqual(tableRows.value, props.rows)) {
|
|
349
|
+
tableRows.value = props.rows;
|
|
350
|
+
}
|
|
341
351
|
}
|
|
342
352
|
|
|
343
353
|
function updateSelectedRows() {
|
|
@@ -379,11 +389,11 @@ function onChangeSelectAll(selectAll: boolean) {
|
|
|
379
389
|
if (selectAll && canSelectAll.value) {
|
|
380
390
|
selectedRows.value = getFlatRows(tableRows.value).map((row) => row.id);
|
|
381
391
|
|
|
382
|
-
tableRows.value.
|
|
392
|
+
tableRows.value = tableRows.value.map((row) => switchRowCheck({ ...row }, true));
|
|
383
393
|
} else if (!selectAll) {
|
|
384
394
|
selectedRows.value = [];
|
|
385
395
|
|
|
386
|
-
tableRows.value.
|
|
396
|
+
tableRows.value = tableRows.value.map((row) => switchRowCheck({ ...row }, false));
|
|
387
397
|
}
|
|
388
398
|
|
|
389
399
|
canSelectAll.value = true;
|
|
@@ -406,8 +416,7 @@ function clearSelectedItems() {
|
|
|
406
416
|
}
|
|
407
417
|
|
|
408
418
|
function onToggleRowVisibility(rowId: string | number) {
|
|
409
|
-
|
|
410
|
-
tableRows.value.forEach((row) => toggleRowVisibility(row, rowId));
|
|
419
|
+
tableRows.value = tableRows.value.map((row) => toggleRowVisibility({ ...row }, rowId));
|
|
411
420
|
}
|
|
412
421
|
|
|
413
422
|
defineExpose({
|
|
@@ -50,7 +50,7 @@ export function toggleRowVisibility(row: Row, targetRowId: string | number) {
|
|
|
50
50
|
row.nestedData.isHidden = !row.nestedData.isHidden;
|
|
51
51
|
}
|
|
52
52
|
|
|
53
|
-
return;
|
|
53
|
+
return row;
|
|
54
54
|
}
|
|
55
55
|
|
|
56
56
|
if (row.row && !Array.isArray(row.row)) {
|
|
@@ -64,6 +64,8 @@ export function toggleRowVisibility(row: Row, targetRowId: string | number) {
|
|
|
64
64
|
if (row.nestedData) {
|
|
65
65
|
toggleRowVisibility(row.nestedData, targetRowId);
|
|
66
66
|
}
|
|
67
|
+
|
|
68
|
+
return row;
|
|
67
69
|
}
|
|
68
70
|
|
|
69
71
|
export function switchRowCheck(row: Row, isChecked: boolean) {
|
|
@@ -76,6 +78,8 @@ export function switchRowCheck(row: Row, isChecked: boolean) {
|
|
|
76
78
|
if (row.row && Array.isArray(row.row)) {
|
|
77
79
|
row.row.map((currentRow) => switchRowCheck(currentRow, isChecked));
|
|
78
80
|
}
|
|
81
|
+
|
|
82
|
+
return row;
|
|
79
83
|
}
|
|
80
84
|
|
|
81
85
|
export function getFlatRows(tableRows: Row[]) {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
<script lang="ts"
|
|
2
|
-
import { nextTick, ref, useId } from "vue";
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import { nextTick, ref, useId, useTemplateRef } from "vue";
|
|
3
3
|
|
|
4
4
|
import UIcon from "../ui.image-icon/UIcon.vue";
|
|
5
5
|
import UBadge from "../ui.text-badge/UBadge.vue";
|
|
@@ -14,10 +14,13 @@ import { UDropdownBadge } from "./constants.ts";
|
|
|
14
14
|
import useAttrs from "./useAttrs.ts";
|
|
15
15
|
|
|
16
16
|
import type { UDropdownBadgeProps } from "./types.ts";
|
|
17
|
+
import type { Option } from "../ui.dropdown-list/types.ts";
|
|
17
18
|
|
|
18
19
|
defineOptions({ inheritAttrs: false });
|
|
19
20
|
|
|
20
21
|
const props = withDefaults(defineProps<UDropdownBadgeProps>(), {
|
|
22
|
+
label: getDefault<UDropdownBadgeProps>(defaultConfig, UDropdownBadge).label,
|
|
23
|
+
options: () => [],
|
|
21
24
|
labelKey: getDefault<UDropdownBadgeProps>(defaultConfig, UDropdownBadge).labelKey,
|
|
22
25
|
variant: getDefault<UDropdownBadgeProps>(defaultConfig, UDropdownBadge).variant,
|
|
23
26
|
color: getDefault<UDropdownBadgeProps>(defaultConfig, UDropdownBadge).color,
|
|
@@ -26,7 +29,9 @@ const props = withDefaults(defineProps<UDropdownBadgeProps>(), {
|
|
|
26
29
|
noIcon: getDefault<UDropdownBadgeProps>(defaultConfig, UDropdownBadge).noIcon,
|
|
27
30
|
yPosition: getDefault<UDropdownBadgeProps>(defaultConfig, UDropdownBadge).yPosition,
|
|
28
31
|
xPosition: getDefault<UDropdownBadgeProps>(defaultConfig, UDropdownBadge).xPosition,
|
|
32
|
+
id: "",
|
|
29
33
|
dataTest: "",
|
|
34
|
+
config: () => ({}),
|
|
30
35
|
});
|
|
31
36
|
|
|
32
37
|
const emit = defineEmits([
|
|
@@ -37,8 +42,10 @@ const emit = defineEmits([
|
|
|
37
42
|
"clickOption",
|
|
38
43
|
]);
|
|
39
44
|
|
|
45
|
+
type UDropdownListRef = InstanceType<typeof UDropdownList>;
|
|
46
|
+
|
|
40
47
|
const isShownOptions = ref(false);
|
|
41
|
-
const dropdownListRef =
|
|
48
|
+
const dropdownListRef = useTemplateRef<UDropdownListRef>("dropdown-list");
|
|
42
49
|
|
|
43
50
|
const elementId = props.id || useId();
|
|
44
51
|
|
|
@@ -53,7 +60,7 @@ function onClickBadge() {
|
|
|
53
60
|
isShownOptions.value = !isShownOptions.value;
|
|
54
61
|
|
|
55
62
|
if (isShownOptions.value) {
|
|
56
|
-
nextTick(() => dropdownListRef.value
|
|
63
|
+
nextTick(() => dropdownListRef.value?.wrapperRef?.focus());
|
|
57
64
|
}
|
|
58
65
|
}
|
|
59
66
|
|
|
@@ -61,7 +68,7 @@ function hideOptions() {
|
|
|
61
68
|
isShownOptions.value = false;
|
|
62
69
|
}
|
|
63
70
|
|
|
64
|
-
function onClickOption(option) {
|
|
71
|
+
function onClickOption(option: Option) {
|
|
65
72
|
emit("clickOption", option);
|
|
66
73
|
|
|
67
74
|
hideOptions();
|
|
@@ -100,7 +107,7 @@ function onClickOption(option) {
|
|
|
100
107
|
<slot :label="label" :opened="isShownOptions" />
|
|
101
108
|
</template>
|
|
102
109
|
|
|
103
|
-
<template #right="{ iconColor
|
|
110
|
+
<template #right="{ iconColor }">
|
|
104
111
|
<!--
|
|
105
112
|
@slot Use it to add something after the label.
|
|
106
113
|
@binding {boolean} opened
|
|
@@ -110,8 +117,8 @@ function onClickOption(option) {
|
|
|
110
117
|
v-if="!noIcon"
|
|
111
118
|
internal
|
|
112
119
|
:color="iconColor"
|
|
113
|
-
:size="
|
|
114
|
-
:name="config.defaults
|
|
120
|
+
:size="size"
|
|
121
|
+
:name="config.defaults?.dropdownIcon"
|
|
115
122
|
v-bind="dropdownIconAttrs"
|
|
116
123
|
:data-test="`${dataTest}-dropdown`"
|
|
117
124
|
/>
|
|
@@ -121,7 +128,7 @@ function onClickOption(option) {
|
|
|
121
128
|
|
|
122
129
|
<UDropdownList
|
|
123
130
|
v-if="isShownOptions"
|
|
124
|
-
ref="
|
|
131
|
+
ref="dropdown-list"
|
|
125
132
|
:size="size"
|
|
126
133
|
:options="options"
|
|
127
134
|
:label-key="labelKey"
|
|
@@ -7,9 +7,12 @@ import UIcon from "../../ui.image-icon/UIcon.vue";
|
|
|
7
7
|
import type { Meta, StoryFn } from "@storybook/vue3";
|
|
8
8
|
import type { UDropdownBadgeProps } from "../types.ts";
|
|
9
9
|
|
|
10
|
-
interface
|
|
10
|
+
interface DefaultUDropdownBadgeArgs extends UDropdownBadgeProps {
|
|
11
11
|
slotTemplate?: string;
|
|
12
|
-
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
interface EnumUDropdownBadgeArgs extends DefaultUDropdownBadgeArgs {
|
|
15
|
+
enum: keyof Pick<UDropdownBadgeProps, "color" | "size">;
|
|
13
16
|
}
|
|
14
17
|
|
|
15
18
|
/**
|
|
@@ -35,7 +38,7 @@ export default {
|
|
|
35
38
|
},
|
|
36
39
|
} as Meta;
|
|
37
40
|
|
|
38
|
-
const DefaultTemplate: StoryFn<
|
|
41
|
+
const DefaultTemplate: StoryFn<DefaultUDropdownBadgeArgs> = (args: DefaultUDropdownBadgeArgs) => ({
|
|
39
42
|
components: { UDropdownBadge, UIcon },
|
|
40
43
|
setup() {
|
|
41
44
|
const slots = getSlotNames(UDropdownBadge.__name);
|
|
@@ -51,15 +54,15 @@ const DefaultTemplate: StoryFn<UDropdownBadgeArgs> = (args: UDropdownBadgeArgs)
|
|
|
51
54
|
`,
|
|
52
55
|
});
|
|
53
56
|
|
|
54
|
-
const EnumVariantTemplate: StoryFn<
|
|
55
|
-
args:
|
|
57
|
+
const EnumVariantTemplate: StoryFn<EnumUDropdownBadgeArgs> = (
|
|
58
|
+
args: EnumUDropdownBadgeArgs,
|
|
56
59
|
{ argTypes },
|
|
57
60
|
) => ({
|
|
58
61
|
components: { UDropdownBadge, URow },
|
|
59
62
|
setup() {
|
|
60
63
|
return {
|
|
61
64
|
args,
|
|
62
|
-
options: argTypes
|
|
65
|
+
options: argTypes[args.enum]?.options,
|
|
63
66
|
};
|
|
64
67
|
},
|
|
65
68
|
template: `
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import defaultConfig from "./config.ts";
|
|
2
2
|
|
|
3
|
-
import type {
|
|
3
|
+
import type { Option } from "../ui.dropdown-list/types";
|
|
4
|
+
import type { Direction } from "../composables/useAutoPosition";
|
|
5
|
+
import type { Color } from "../types";
|
|
4
6
|
|
|
5
7
|
export type Config = Partial<typeof defaultConfig>;
|
|
6
8
|
|
|
@@ -13,7 +15,7 @@ export interface UDropdownBadgeProps {
|
|
|
13
15
|
/**
|
|
14
16
|
* Options list.
|
|
15
17
|
*/
|
|
16
|
-
options?:
|
|
18
|
+
options?: Option[];
|
|
17
19
|
|
|
18
20
|
/**
|
|
19
21
|
* Label key in the item object of options.
|
|
@@ -28,28 +30,7 @@ export interface UDropdownBadgeProps {
|
|
|
28
30
|
/**
|
|
29
31
|
* Badge color.
|
|
30
32
|
*/
|
|
31
|
-
color?:
|
|
32
|
-
| "brand"
|
|
33
|
-
| "grayscale"
|
|
34
|
-
| "gray"
|
|
35
|
-
| "red"
|
|
36
|
-
| "orange"
|
|
37
|
-
| "amber"
|
|
38
|
-
| "yellow"
|
|
39
|
-
| "lime"
|
|
40
|
-
| "green"
|
|
41
|
-
| "emerald"
|
|
42
|
-
| "teal"
|
|
43
|
-
| "cyan"
|
|
44
|
-
| "sky"
|
|
45
|
-
| "blue"
|
|
46
|
-
| "indigo"
|
|
47
|
-
| "violet"
|
|
48
|
-
| "purple"
|
|
49
|
-
| "fuchsia"
|
|
50
|
-
| "pink"
|
|
51
|
-
| "rose"
|
|
52
|
-
| "white";
|
|
33
|
+
color?: `${Color}`;
|
|
53
34
|
|
|
54
35
|
/**
|
|
55
36
|
* Badge size.
|
|
@@ -69,12 +50,12 @@ export interface UDropdownBadgeProps {
|
|
|
69
50
|
/**
|
|
70
51
|
* The position of dropdown list on the y-axis.
|
|
71
52
|
*/
|
|
72
|
-
yPosition?:
|
|
53
|
+
yPosition?: Direction.Top | Direction.Bottom;
|
|
73
54
|
|
|
74
55
|
/**
|
|
75
56
|
* The position of dropdown list on the x-axis.
|
|
76
57
|
*/
|
|
77
|
-
xPosition?:
|
|
58
|
+
xPosition?: Direction.Left | Direction.Right;
|
|
78
59
|
|
|
79
60
|
/**
|
|
80
61
|
* Unique element id.
|
|
@@ -84,7 +65,7 @@ export interface UDropdownBadgeProps {
|
|
|
84
65
|
/**
|
|
85
66
|
* Component config object.
|
|
86
67
|
*/
|
|
87
|
-
config?:
|
|
68
|
+
config?: Config;
|
|
88
69
|
|
|
89
70
|
/**
|
|
90
71
|
* Data-test attribute for automated testing.
|
|
@@ -4,16 +4,16 @@ import useUI from "../composables/useUI.ts";
|
|
|
4
4
|
import defaultConfig from "./config.ts";
|
|
5
5
|
|
|
6
6
|
import type { Ref } from "vue";
|
|
7
|
-
import type {
|
|
8
|
-
import type {
|
|
7
|
+
import type { Config, UDropdownBadgeProps } from "./types.ts";
|
|
8
|
+
import type { UseAttrs } from "src/types.ts";
|
|
9
9
|
|
|
10
|
-
|
|
10
|
+
interface DropdownBadgeState {
|
|
11
11
|
isShownOptions: Ref<boolean>;
|
|
12
|
-
}
|
|
12
|
+
}
|
|
13
13
|
|
|
14
14
|
export default function useAttrs(
|
|
15
15
|
props: UDropdownBadgeProps,
|
|
16
|
-
{ isShownOptions }:
|
|
16
|
+
{ isShownOptions }: DropdownBadgeState,
|
|
17
17
|
): UseAttrs<Config> {
|
|
18
18
|
const { config, getKeysAttrs, hasSlotContent, getExtendingKeysClasses } = useUI(
|
|
19
19
|
defaultConfig,
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
<script lang="ts"
|
|
2
|
-
import { nextTick, computed, provide, ref, useId } from "vue";
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import { nextTick, computed, provide, ref, useId, useTemplateRef } from "vue";
|
|
3
3
|
|
|
4
4
|
import UIcon from "../ui.image-icon/UIcon.vue";
|
|
5
5
|
import UButton from "../ui.button/UButton.vue";
|
|
@@ -14,14 +14,17 @@ import useAttrs from "./useAttrs.ts";
|
|
|
14
14
|
import { UDropdownButton, BUTTON_VARIANT } from "./constants.ts";
|
|
15
15
|
|
|
16
16
|
import type { UDropdownButtonProps } from "./types.ts";
|
|
17
|
+
import type { Option } from "../ui.dropdown-list/types.ts";
|
|
17
18
|
|
|
18
19
|
defineOptions({ inheritAttrs: false });
|
|
19
20
|
|
|
20
21
|
const props = withDefaults(defineProps<UDropdownButtonProps>(), {
|
|
22
|
+
label: getDefault<UDropdownButtonProps>(defaultConfig, UDropdownButton).label,
|
|
23
|
+
options: () => [],
|
|
21
24
|
labelKey: getDefault<UDropdownButtonProps>(defaultConfig, UDropdownButton).labelKey,
|
|
22
25
|
variant: getDefault<UDropdownButtonProps>(defaultConfig, UDropdownButton).variant,
|
|
23
|
-
filled: getDefault<UDropdownButtonProps>(defaultConfig, UDropdownButton).filled,
|
|
24
26
|
color: getDefault<UDropdownButtonProps>(defaultConfig, UDropdownButton).color,
|
|
27
|
+
filled: getDefault<UDropdownButtonProps>(defaultConfig, UDropdownButton).filled,
|
|
25
28
|
size: getDefault<UDropdownButtonProps>(defaultConfig, UDropdownButton).size,
|
|
26
29
|
round: getDefault<UDropdownButtonProps>(defaultConfig, UDropdownButton).round,
|
|
27
30
|
square: getDefault<UDropdownButtonProps>(defaultConfig, UDropdownButton).square,
|
|
@@ -29,7 +32,9 @@ const props = withDefaults(defineProps<UDropdownButtonProps>(), {
|
|
|
29
32
|
noIcon: getDefault<UDropdownButtonProps>(defaultConfig, UDropdownButton).noIcon,
|
|
30
33
|
yPosition: getDefault<UDropdownButtonProps>(defaultConfig, UDropdownButton).yPosition,
|
|
31
34
|
xPosition: getDefault<UDropdownButtonProps>(defaultConfig, UDropdownButton).xPosition,
|
|
35
|
+
id: "",
|
|
32
36
|
dataTest: "",
|
|
37
|
+
config: () => ({}),
|
|
33
38
|
});
|
|
34
39
|
|
|
35
40
|
const emit = defineEmits([
|
|
@@ -42,8 +47,10 @@ const emit = defineEmits([
|
|
|
42
47
|
|
|
43
48
|
provide("hideDropdownOptions", hideOptions);
|
|
44
49
|
|
|
50
|
+
type UDropdownListRef = InstanceType<typeof UDropdownList>;
|
|
51
|
+
|
|
45
52
|
const isShownOptions = ref(false);
|
|
46
|
-
const dropdownListRef =
|
|
53
|
+
const dropdownListRef = useTemplateRef<UDropdownListRef>("dropdown-list");
|
|
47
54
|
|
|
48
55
|
const elementId = props.id || useId();
|
|
49
56
|
|
|
@@ -54,6 +61,7 @@ const iconColor = computed(() => {
|
|
|
54
61
|
return props.variant === BUTTON_VARIANT.primary ? "white" : props.color;
|
|
55
62
|
});
|
|
56
63
|
|
|
64
|
+
type IconSize = "2xs" | "xs" | "sm" | "md" | "lg" | "xl";
|
|
57
65
|
const iconSize = computed(() => {
|
|
58
66
|
const sizes = {
|
|
59
67
|
"2xs": "xs",
|
|
@@ -64,10 +72,24 @@ const iconSize = computed(() => {
|
|
|
64
72
|
xl: "md",
|
|
65
73
|
};
|
|
66
74
|
|
|
67
|
-
return sizes[props.size];
|
|
75
|
+
return sizes[props.size] as IconSize;
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
type DropdownSize = "sm" | "md" | "lg";
|
|
79
|
+
const dropdownSize = computed(() => {
|
|
80
|
+
const sizes = {
|
|
81
|
+
"2xs": "sm",
|
|
82
|
+
xs: "sm",
|
|
83
|
+
sm: "sm",
|
|
84
|
+
md: "md",
|
|
85
|
+
lg: "lg",
|
|
86
|
+
xl: "lg",
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
return sizes[props.size] as DropdownSize;
|
|
68
90
|
});
|
|
69
91
|
|
|
70
|
-
function onClickOption(option) {
|
|
92
|
+
function onClickOption(option: Option) {
|
|
71
93
|
emit("clickOption", option);
|
|
72
94
|
}
|
|
73
95
|
|
|
@@ -75,7 +97,7 @@ function onClickButton() {
|
|
|
75
97
|
isShownOptions.value = !isShownOptions.value;
|
|
76
98
|
|
|
77
99
|
if (isShownOptions.value) {
|
|
78
|
-
nextTick(() => dropdownListRef.value
|
|
100
|
+
nextTick(() => dropdownListRef.value?.wrapperRef?.focus());
|
|
79
101
|
}
|
|
80
102
|
}
|
|
81
103
|
|
|
@@ -132,7 +154,7 @@ function onClickList() {
|
|
|
132
154
|
internal
|
|
133
155
|
:size="iconSize"
|
|
134
156
|
:color="iconColor"
|
|
135
|
-
:name="config.defaults
|
|
157
|
+
:name="config.defaults?.dropdownIcon"
|
|
136
158
|
v-bind="dropdownIconAttrs"
|
|
137
159
|
:data-test="`${dataTest}-dropdown`"
|
|
138
160
|
/>
|
|
@@ -142,8 +164,8 @@ function onClickList() {
|
|
|
142
164
|
|
|
143
165
|
<UDropdownList
|
|
144
166
|
v-if="isShownOptions"
|
|
145
|
-
ref="
|
|
146
|
-
:size="
|
|
167
|
+
ref="dropdown-list"
|
|
168
|
+
:size="dropdownSize"
|
|
147
169
|
:options="options"
|
|
148
170
|
:label-key="labelKey"
|
|
149
171
|
v-bind="dropdownListAttrs"
|
|
@@ -8,9 +8,12 @@ import UIcon from "../../ui.image-icon/UIcon.vue";
|
|
|
8
8
|
import type { Meta, StoryFn } from "@storybook/vue3";
|
|
9
9
|
import type { UDropdownButtonProps } from "../types.ts";
|
|
10
10
|
|
|
11
|
-
interface
|
|
11
|
+
interface DefaultUDropdownButtonArgs extends UDropdownButtonProps {
|
|
12
12
|
slotTemplate?: string;
|
|
13
|
-
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
interface EnumUDropdownButtonArgs extends DefaultUDropdownButtonArgs {
|
|
16
|
+
enum: keyof Pick<UDropdownButtonProps, "size" | "variant">;
|
|
14
17
|
}
|
|
15
18
|
|
|
16
19
|
/**
|
|
@@ -36,7 +39,9 @@ export default {
|
|
|
36
39
|
},
|
|
37
40
|
} as Meta;
|
|
38
41
|
|
|
39
|
-
const DefaultTemplate: StoryFn<
|
|
42
|
+
const DefaultTemplate: StoryFn<DefaultUDropdownButtonArgs> = (
|
|
43
|
+
args: DefaultUDropdownButtonArgs,
|
|
44
|
+
) => ({
|
|
40
45
|
components: { UDropdownButton, UIcon },
|
|
41
46
|
setup() {
|
|
42
47
|
const slots = getSlotNames(UDropdownButton.__name);
|
|
@@ -50,15 +55,15 @@ const DefaultTemplate: StoryFn<UDropdownButtonArgs> = (args: UDropdownButtonArgs
|
|
|
50
55
|
`,
|
|
51
56
|
});
|
|
52
57
|
|
|
53
|
-
const EnumVariantTemplate: StoryFn<
|
|
54
|
-
args:
|
|
58
|
+
const EnumVariantTemplate: StoryFn<EnumUDropdownButtonArgs> = (
|
|
59
|
+
args: EnumUDropdownButtonArgs,
|
|
55
60
|
{ argTypes },
|
|
56
61
|
) => ({
|
|
57
62
|
components: { UDropdownButton, URow },
|
|
58
63
|
setup() {
|
|
59
64
|
return {
|
|
60
65
|
args,
|
|
61
|
-
options: argTypes
|
|
66
|
+
options: argTypes[args.enum]?.options,
|
|
62
67
|
};
|
|
63
68
|
},
|
|
64
69
|
template: `
|
|
@@ -74,16 +79,16 @@ const EnumVariantTemplate: StoryFn<UDropdownButtonArgs> = (
|
|
|
74
79
|
`,
|
|
75
80
|
});
|
|
76
81
|
|
|
77
|
-
const VariantColorsTemplate: StoryFn<
|
|
78
|
-
args:
|
|
82
|
+
const VariantColorsTemplate: StoryFn<EnumUDropdownButtonArgs> = (
|
|
83
|
+
args: EnumUDropdownButtonArgs,
|
|
79
84
|
{ argTypes },
|
|
80
85
|
) => ({
|
|
81
86
|
components: { UDropdownButton, URow, UCol },
|
|
82
87
|
setup() {
|
|
83
88
|
return {
|
|
84
89
|
args,
|
|
85
|
-
variants: argTypes
|
|
86
|
-
colors: argTypes
|
|
90
|
+
variants: argTypes.variant?.options,
|
|
91
|
+
colors: argTypes.color?.options,
|
|
87
92
|
};
|
|
88
93
|
},
|
|
89
94
|
template: `
|