vueless 0.0.534 → 0.0.536
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 +31 -0
- package/ui.button/types.ts +3 -22
- package/ui.button-link/types.ts +2 -22
- 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-checkbox/UCheckbox.vue +82 -187
- package/ui.form-checkbox/storybook/Docs.mdx +2 -2
- package/ui.form-checkbox/storybook/{stories.js → stories.ts} +14 -6
- package/ui.form-checkbox/types.ts +106 -0
- package/ui.form-checkbox/useAttrs.ts +35 -0
- package/ui.form-checkbox-group/UCheckboxGroup.vue +63 -137
- package/ui.form-checkbox-group/storybook/Docs.mdx +2 -2
- package/ui.form-checkbox-group/storybook/{stories.js → stories.ts} +19 -6
- package/ui.form-checkbox-group/types.ts +83 -0
- package/ui.form-checkbox-group/useAttrs.ts +18 -0
- package/ui.form-checkbox-multi-state/UCheckboxMultiState.vue +34 -97
- package/ui.form-checkbox-multi-state/storybook/Docs.mdx +2 -2
- package/ui.form-checkbox-multi-state/storybook/{stories.js → stories.ts} +16 -5
- package/ui.form-checkbox-multi-state/types.ts +71 -0
- package/ui.form-checkbox-multi-state/useAttrs.ts +41 -0
- 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 +227 -498
- package/ui.form-checkbox/useAttrs.js +0 -23
- package/ui.form-checkbox-group/useAttrs.js +0 -15
- package/ui.form-checkbox-multi-state/useAttrs.js +0 -28
- /package/ui.form-checkbox/{config.js → config.ts} +0 -0
- /package/ui.form-checkbox/{constants.js → constants.ts} +0 -0
- /package/ui.form-checkbox-group/{config.js → config.ts} +0 -0
- /package/ui.form-checkbox-group/{constants.js → constants.ts} +0 -0
- /package/ui.form-checkbox-multi-state/{config.js → config.ts} +0 -0
- /package/ui.form-checkbox-multi-state/{constants.js → constants.ts} +0 -0
|
@@ -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
|
@@ -41,6 +41,9 @@ import UTabConfig from "./ui.navigation-tab/config.ts";
|
|
|
41
41
|
import UTabsConfig from "./ui.navigation-tabs/config.ts";
|
|
42
42
|
import UAvatarConfig from "./ui.image-avatar/config.ts";
|
|
43
43
|
import UIconConfig from "./ui.image-icon/config.ts";
|
|
44
|
+
import UCheckboxConfig from "./ui.form-checkbox/config.ts";
|
|
45
|
+
import UCheckboxGroupConfig from "./ui.form-checkbox-group/config.ts";
|
|
46
|
+
import UCheckboxMultiStateConfig from "./ui.form-checkbox-multi-state/config.ts";
|
|
44
47
|
|
|
45
48
|
import type { ComputedRef, MaybeRef, Ref } from "vue";
|
|
46
49
|
import type { Props } from "tippy.js";
|
|
@@ -54,6 +57,30 @@ export enum ColorMode {
|
|
|
54
57
|
Auto = "auto",
|
|
55
58
|
}
|
|
56
59
|
|
|
60
|
+
export enum Color {
|
|
61
|
+
Brand = "brand",
|
|
62
|
+
Grayscale = "grayscale",
|
|
63
|
+
Gray = "gray",
|
|
64
|
+
Red = "red",
|
|
65
|
+
Orange = "orange",
|
|
66
|
+
Amber = "amber",
|
|
67
|
+
Yellow = "yellow",
|
|
68
|
+
Lime = "lime",
|
|
69
|
+
Green = "green",
|
|
70
|
+
Emerald = "emerald",
|
|
71
|
+
Teal = "teal",
|
|
72
|
+
Cyan = "cyan",
|
|
73
|
+
Sky = "sky",
|
|
74
|
+
Blue = "blue",
|
|
75
|
+
Indigo = "indigo",
|
|
76
|
+
Violet = "violet",
|
|
77
|
+
Purple = "purple",
|
|
78
|
+
Fuchsia = "fuchsia",
|
|
79
|
+
Pink = "pink",
|
|
80
|
+
Rose = "rose",
|
|
81
|
+
White = "white",
|
|
82
|
+
}
|
|
83
|
+
|
|
57
84
|
export interface ExtendedKeyClasses {
|
|
58
85
|
[key: string]: Ref<string>;
|
|
59
86
|
}
|
|
@@ -128,6 +155,7 @@ export interface Config extends ThemeConfig {
|
|
|
128
155
|
}
|
|
129
156
|
|
|
130
157
|
export type UnknownObject = Record<string, unknown>;
|
|
158
|
+
export type UnknownArray = Array<unknown>;
|
|
131
159
|
export type ComponentNames = keyof Components; // keys union
|
|
132
160
|
export type Strategies = "merge" | "replace" | "override";
|
|
133
161
|
export type Gray = "gray";
|
|
@@ -193,6 +221,9 @@ export interface Components {
|
|
|
193
221
|
UTabs?: Partial<typeof UTabsConfig>;
|
|
194
222
|
UAvatar?: Partial<typeof UAvatarConfig>;
|
|
195
223
|
UIcon?: Partial<typeof UIconConfig>;
|
|
224
|
+
UCheckbox?: Partial<typeof UCheckboxConfig>;
|
|
225
|
+
UCheckboxGroup?: Partial<typeof UCheckboxGroupConfig>;
|
|
226
|
+
UCheckboxMultiState?: Partial<typeof UCheckboxMultiStateConfig>;
|
|
196
227
|
}
|
|
197
228
|
|
|
198
229
|
export interface Directives {
|
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.
|
|
@@ -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: `
|
|
@@ -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 UDropdownButtonProps {
|
|
|
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.
|
|
@@ -33,28 +35,7 @@ export interface UDropdownButtonProps {
|
|
|
33
35
|
/**
|
|
34
36
|
* Button color.
|
|
35
37
|
*/
|
|
36
|
-
color?:
|
|
37
|
-
| "brand"
|
|
38
|
-
| "grayscale"
|
|
39
|
-
| "gray"
|
|
40
|
-
| "red"
|
|
41
|
-
| "orange"
|
|
42
|
-
| "amber"
|
|
43
|
-
| "yellow"
|
|
44
|
-
| "lime"
|
|
45
|
-
| "green"
|
|
46
|
-
| "emerald"
|
|
47
|
-
| "teal"
|
|
48
|
-
| "cyan"
|
|
49
|
-
| "sky"
|
|
50
|
-
| "blue"
|
|
51
|
-
| "indigo"
|
|
52
|
-
| "violet"
|
|
53
|
-
| "purple"
|
|
54
|
-
| "fuchsia"
|
|
55
|
-
| "pink"
|
|
56
|
-
| "rose"
|
|
57
|
-
| "white";
|
|
38
|
+
color?: `${Color}`;
|
|
58
39
|
|
|
59
40
|
/**
|
|
60
41
|
* Button size.
|
|
@@ -72,7 +53,7 @@ export interface UDropdownButtonProps {
|
|
|
72
53
|
square?: boolean;
|
|
73
54
|
|
|
74
55
|
/**
|
|
75
|
-
* Disable the
|
|
56
|
+
* Disable the button.
|
|
76
57
|
*/
|
|
77
58
|
disabled?: boolean;
|
|
78
59
|
|
|
@@ -84,12 +65,12 @@ export interface UDropdownButtonProps {
|
|
|
84
65
|
/**
|
|
85
66
|
* The position of dropdown list on the y-axis.
|
|
86
67
|
*/
|
|
87
|
-
yPosition?:
|
|
68
|
+
yPosition?: Direction.Top | Direction.Bottom;
|
|
88
69
|
|
|
89
70
|
/**
|
|
90
71
|
* The position of dropdown list on the x-axis.
|
|
91
72
|
*/
|
|
92
|
-
xPosition?:
|
|
73
|
+
xPosition?: Direction.Left | Direction.Right;
|
|
93
74
|
|
|
94
75
|
/**
|
|
95
76
|
* Unique element id.
|
|
@@ -99,7 +80,7 @@ export interface UDropdownButtonProps {
|
|
|
99
80
|
/**
|
|
100
81
|
* Component config object.
|
|
101
82
|
*/
|
|
102
|
-
config?:
|
|
83
|
+
config?: Config;
|
|
103
84
|
|
|
104
85
|
/**
|
|
105
86
|
* Data-test attribute for automated testing.
|
|
@@ -4,18 +4,18 @@ 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, UDropdownButtonProps } from "./types.ts";
|
|
8
|
+
import type { UseAttrs } from "src/types.ts";
|
|
9
9
|
|
|
10
|
-
|
|
10
|
+
interface DropdownButtonState {
|
|
11
11
|
isShownOptions: Ref<boolean>;
|
|
12
|
-
}
|
|
12
|
+
}
|
|
13
13
|
|
|
14
14
|
export default function useAttrs(
|
|
15
15
|
props: UDropdownButtonProps,
|
|
16
|
-
{ isShownOptions }:
|
|
16
|
+
{ isShownOptions }: DropdownButtonState,
|
|
17
17
|
): UseAttrs<Config> {
|
|
18
|
-
const { config, getKeysAttrs, hasSlotContent, getExtendingKeysClasses } = useUI
|
|
18
|
+
const { config, getKeysAttrs, hasSlotContent, getExtendingKeysClasses } = useUI(
|
|
19
19
|
defaultConfig,
|
|
20
20
|
() => props.config,
|
|
21
21
|
);
|