vueless 0.0.514 → 0.0.515

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.
Files changed (34) hide show
  1. package/package.json +1 -1
  2. package/types.ts +8 -0
  3. package/ui.button-link/useAttrs.ts +2 -2
  4. package/ui.dropdown-badge/UDropdownBadge.vue +70 -167
  5. package/ui.dropdown-badge/storybook/Docs.mdx +2 -2
  6. package/ui.dropdown-badge/storybook/{stories.js → stories.ts} +16 -5
  7. package/ui.dropdown-badge/types.ts +93 -0
  8. package/ui.dropdown-badge/{useAttrs.js → useAttrs.ts} +13 -2
  9. package/ui.dropdown-button/UDropdownButton.vue +85 -203
  10. package/ui.dropdown-button/storybook/Docs.mdx +2 -2
  11. package/ui.dropdown-button/storybook/{stories.js → stories.ts} +25 -11
  12. package/ui.dropdown-button/types.ts +108 -0
  13. package/ui.dropdown-button/{useAttrs.js → useAttrs.ts} +14 -3
  14. package/ui.dropdown-link/UDropdownLink.vue +84 -194
  15. package/ui.dropdown-link/storybook/Docs.mdx +2 -2
  16. package/ui.dropdown-link/storybook/{stories.js → stories.ts} +20 -9
  17. package/ui.dropdown-link/types.ts +103 -0
  18. package/ui.dropdown-link/{useAttrs.js → useAttrs.ts} +14 -3
  19. package/ui.dropdown-list/UDropdownList.vue +112 -177
  20. package/ui.dropdown-list/storybook/Docs.mdx +2 -2
  21. package/ui.dropdown-list/storybook/{stories.js → stories.ts} +23 -7
  22. package/ui.dropdown-list/types.ts +52 -0
  23. package/ui.dropdown-list/{useAttrs.js → useAttrs.ts} +6 -3
  24. package/ui.dropdown-list/usePointer.ts +111 -0
  25. package/web-types.json +117 -55
  26. package/ui.dropdown-list/usePointer.js +0 -86
  27. /package/ui.dropdown-badge/{config.js → config.ts} +0 -0
  28. /package/ui.dropdown-badge/{constants.js → constants.ts} +0 -0
  29. /package/ui.dropdown-button/{config.js → config.ts} +0 -0
  30. /package/ui.dropdown-button/{constants.js → constants.ts} +0 -0
  31. /package/ui.dropdown-link/{config.js → config.ts} +0 -0
  32. /package/ui.dropdown-link/{constants.js → constants.ts} +0 -0
  33. /package/ui.dropdown-list/{config.js → config.ts} +0 -0
  34. /package/ui.dropdown-list/{constants.js → constants.ts} +0 -0
@@ -1,70 +1,4 @@
1
- <template>
2
- <div v-click-outside="hideOptions" v-bind="wrapperAttrs">
3
- <UButton
4
- :id="elementId"
5
- :label="label"
6
- :size="size"
7
- :color="color"
8
- :round="round"
9
- :square="square"
10
- :variant="variant"
11
- :disabled="disabled"
12
- :filled="filled || isShownOptions"
13
- v-bind="dropdownButtonAttrs"
14
- :data-test="dataTest"
15
- @click="onClickButton"
16
- >
17
- <template #left>
18
- <!--
19
- @slot Use it to add something before the label.
20
- @binding {boolean} opened
21
- -->
22
- <slot name="left" :opened="isShownOptions" />
23
- </template>
24
-
25
- <template #default>
26
- <!--
27
- @slot Use it to add something instead of the default label.
28
- @binding {string} label
29
- @binding {boolean} opened
30
- -->
31
- <slot :label="label" :opened="isShownOptions" />
32
- </template>
33
-
34
- <template #right>
35
- <!--
36
- @slot Use it to add something after the label.
37
- @binding {boolean} opened
38
- -->
39
- <slot name="right" :opened="isShownOptions">
40
- <UIcon
41
- v-if="!noIcon"
42
- internal
43
- :size="iconSize"
44
- :color="iconColor"
45
- :name="config.defaults.dropdownIcon"
46
- v-bind="dropdownIconAttrs"
47
- :data-test="`${dataTest}-dropdown`"
48
- />
49
- </slot>
50
- </template>
51
- </UButton>
52
-
53
- <UDropdownList
54
- v-if="isShownOptions"
55
- ref="dropdownListRef"
56
- :size="size"
57
- :options="options"
58
- :label-key="labelKey"
59
- v-bind="dropdownListAttrs"
60
- :data-test="`${dataTest}-list`"
61
- @click="onClickList"
62
- @click-option="onClickOption"
63
- />
64
- </div>
65
- </template>
66
-
67
- <script setup>
1
+ <script lang="ts" setup>
68
2
  import { nextTick, computed, provide, ref, useId } from "vue";
69
3
 
70
4
  import UIcon from "../ui.image-icon/UIcon.vue";
@@ -75,145 +9,27 @@ import { getDefault } from "../utils/ui.ts";
75
9
 
76
10
  import { vClickOutside } from "../directives";
77
11
 
78
- import defaultConfig from "./config.js";
79
- import useAttrs from "./useAttrs.js";
80
- import { UDropdownButton, BUTTON_VARIANT } from "./constants.js";
81
-
82
- defineOptions({ inheritAttrs: false });
83
-
84
- const props = defineProps({
85
- /**
86
- * Button label.
87
- */
88
- label: {
89
- type: String,
90
- default: "",
91
- },
92
-
93
- /**
94
- * Options list.
95
- */
96
- options: {
97
- type: Array,
98
- default: () => [],
99
- },
100
-
101
- /**
102
- * Label key in the item object of options.
103
- */
104
- labelKey: {
105
- type: String,
106
- default: getDefault(defaultConfig, UDropdownButton).labelKey,
107
- },
108
-
109
- /**
110
- * Button variant.
111
- * @values primary, secondary, thirdary
112
- */
113
- variant: {
114
- type: String,
115
- default: getDefault(defaultConfig, UDropdownButton).variant,
116
- },
117
-
118
- /**
119
- * Fill the background for thirdary variant.
120
- */
121
- filled: {
122
- type: Boolean,
123
- default: getDefault(defaultConfig, UDropdownButton).filled,
124
- },
125
-
126
- /**
127
- * Button color.
128
- * @values brand, grayscale, gray, red, orange, amber, yellow, lime, green, emerald, teal, cyan, sky, blue, indigo, violet, purple, fuchsia, pink, rose, white
129
- */
130
- color: {
131
- type: String,
132
- default: getDefault(defaultConfig, UDropdownButton).color,
133
- },
134
-
135
- /**
136
- * Button size.
137
- * @values 2xs, xs, sm, md, lg, xl
138
- */
139
- size: {
140
- type: String,
141
- default: getDefault(defaultConfig, UDropdownButton).size,
142
- },
143
-
144
- /**
145
- * Set button corners rounded.
146
- */
147
- round: {
148
- type: Boolean,
149
- default: getDefault(defaultConfig, UDropdownButton).round,
150
- },
151
-
152
- /**
153
- * Set the same paddings for the button.
154
- */
155
- square: {
156
- type: Boolean,
157
- default: getDefault(defaultConfig, UDropdownButton).square,
158
- },
159
-
160
- /**
161
- * Disable the link.
162
- */
163
- disabled: {
164
- type: Boolean,
165
- default: getDefault(defaultConfig, UDropdownButton).disabled,
166
- },
12
+ import defaultConfig from "./config.ts";
13
+ import useAttrs from "./useAttrs.ts";
14
+ import { UDropdownButton, BUTTON_VARIANT } from "./constants.ts";
167
15
 
168
- /**
169
- * Hide dropdown icon.
170
- */
171
- noIcon: {
172
- type: Boolean,
173
- default: getDefault(defaultConfig, UDropdownButton).noIcon,
174
- },
16
+ import type { UDropdownButtonProps } from "./types.ts";
175
17
 
176
- /**
177
- * The position of dropdown list on the y-axis.
178
- * @values top, bottom
179
- */
180
- yPosition: {
181
- type: String,
182
- default: getDefault(defaultConfig, UDropdownButton).yPosition,
183
- },
184
-
185
- /**
186
- * The position of dropdown list on the x-axis.
187
- * @values left, right
188
- */
189
- xPosition: {
190
- type: String,
191
- default: getDefault(defaultConfig, UDropdownButton).xPosition,
192
- },
193
-
194
- /**
195
- * Unique element id.
196
- */
197
- id: {
198
- type: String,
199
- default: "",
200
- },
201
-
202
- /**
203
- * Component config object.
204
- */
205
- config: {
206
- type: Object,
207
- default: () => ({}),
208
- },
18
+ defineOptions({ inheritAttrs: false });
209
19
 
210
- /**
211
- * Data-test attribute for automated testing.
212
- */
213
- dataTest: {
214
- type: String,
215
- default: "",
216
- },
20
+ const props = withDefaults(defineProps<UDropdownButtonProps>(), {
21
+ labelKey: getDefault<UDropdownButtonProps>(defaultConfig, UDropdownButton).labelKey,
22
+ variant: getDefault<UDropdownButtonProps>(defaultConfig, UDropdownButton).variant,
23
+ filled: getDefault<UDropdownButtonProps>(defaultConfig, UDropdownButton).filled,
24
+ color: getDefault<UDropdownButtonProps>(defaultConfig, UDropdownButton).color,
25
+ size: getDefault<UDropdownButtonProps>(defaultConfig, UDropdownButton).size,
26
+ round: getDefault<UDropdownButtonProps>(defaultConfig, UDropdownButton).round,
27
+ square: getDefault<UDropdownButtonProps>(defaultConfig, UDropdownButton).square,
28
+ disabled: getDefault<UDropdownButtonProps>(defaultConfig, UDropdownButton).disabled,
29
+ noIcon: getDefault<UDropdownButtonProps>(defaultConfig, UDropdownButton).noIcon,
30
+ yPosition: getDefault<UDropdownButtonProps>(defaultConfig, UDropdownButton).yPosition,
31
+ xPosition: getDefault<UDropdownButtonProps>(defaultConfig, UDropdownButton).xPosition,
32
+ dataTest: "",
217
33
  });
218
34
 
219
35
  const emit = defineEmits([
@@ -271,3 +87,69 @@ function onClickList() {
271
87
  hideOptions();
272
88
  }
273
89
  </script>
90
+
91
+ <template>
92
+ <div v-click-outside="hideOptions" v-bind="wrapperAttrs">
93
+ <UButton
94
+ :id="elementId"
95
+ :label="label"
96
+ :size="size"
97
+ :color="color"
98
+ :round="round"
99
+ :square="square"
100
+ :variant="variant"
101
+ :disabled="disabled"
102
+ :filled="filled || isShownOptions"
103
+ v-bind="dropdownButtonAttrs"
104
+ :data-test="dataTest"
105
+ @click="onClickButton"
106
+ >
107
+ <template #left>
108
+ <!--
109
+ @slot Use it to add something before the label.
110
+ @binding {boolean} opened
111
+ -->
112
+ <slot name="left" :opened="isShownOptions" />
113
+ </template>
114
+
115
+ <template #default>
116
+ <!--
117
+ @slot Use it to add something instead of the default label.
118
+ @binding {string} label
119
+ @binding {boolean} opened
120
+ -->
121
+ <slot :label="label" :opened="isShownOptions" />
122
+ </template>
123
+
124
+ <template #right>
125
+ <!--
126
+ @slot Use it to add something after the label.
127
+ @binding {boolean} opened
128
+ -->
129
+ <slot name="right" :opened="isShownOptions">
130
+ <UIcon
131
+ v-if="!noIcon"
132
+ internal
133
+ :size="iconSize"
134
+ :color="iconColor"
135
+ :name="config.defaults.dropdownIcon"
136
+ v-bind="dropdownIconAttrs"
137
+ :data-test="`${dataTest}-dropdown`"
138
+ />
139
+ </slot>
140
+ </template>
141
+ </UButton>
142
+
143
+ <UDropdownList
144
+ v-if="isShownOptions"
145
+ ref="dropdownListRef"
146
+ :size="size"
147
+ :options="options"
148
+ :label-key="labelKey"
149
+ v-bind="dropdownListAttrs"
150
+ :data-test="`${dataTest}-list`"
151
+ @click="onClickList"
152
+ @click-option="onClickOption"
153
+ />
154
+ </div>
155
+ </template>
@@ -1,8 +1,8 @@
1
1
  import { Meta, Title, Subtitle, Description, Primary, Controls, Stories, Source } from "@storybook/blocks";
2
2
  import { getSource } from "../../utils/storybook.ts";
3
3
 
4
- import * as stories from "./stories.js";
5
- import defaultConfig from "../config.js?raw"
4
+ import * as stories from "./stories.ts";
5
+ import defaultConfig from "../config.ts?raw"
6
6
 
7
7
  <Meta of={stories} />
8
8
  <Title of={stories} />
@@ -5,6 +5,14 @@ import URow from "../../ui.container-row/URow.vue";
5
5
  import UCol from "../../ui.container-col/UCol.vue";
6
6
  import UIcon from "../../ui.image-icon/UIcon.vue";
7
7
 
8
+ import type { Meta, StoryFn } from "@storybook/vue3";
9
+ import type { UDropdownButtonProps } from "../types.ts";
10
+
11
+ interface UDropdownButtonArgs extends UDropdownButtonProps {
12
+ slotTemplate?: string;
13
+ enum: "variant" | "size";
14
+ }
15
+
8
16
  /**
9
17
  * The `UDropdownButton` component. | [View on GitHub](https://github.com/vuelessjs/vueless/tree/main/src/ui.dropdown-button)
10
18
  */
@@ -26,9 +34,9 @@ export default {
26
34
  },
27
35
  },
28
36
  },
29
- };
37
+ } as Meta;
30
38
 
31
- const DefaultTemplate = (args) => ({
39
+ const DefaultTemplate: StoryFn<UDropdownButtonArgs> = (args: UDropdownButtonArgs) => ({
32
40
  components: { UDropdownButton, UIcon },
33
41
  setup() {
34
42
  const slots = getSlotNames(UDropdownButton.__name);
@@ -37,17 +45,20 @@ const DefaultTemplate = (args) => ({
37
45
  },
38
46
  template: `
39
47
  <UDropdownButton v-bind="args">
40
- ${args.slotTemplate || getSlotsFragment()}
48
+ ${args.slotTemplate || getSlotsFragment("")}
41
49
  </UDropdownButton>
42
50
  `,
43
51
  });
44
52
 
45
- const EnumVariantTemplate = (args, { argTypes }) => ({
53
+ const EnumVariantTemplate: StoryFn<UDropdownButtonArgs> = (
54
+ args: UDropdownButtonArgs,
55
+ { argTypes },
56
+ ) => ({
46
57
  components: { UDropdownButton, URow },
47
58
  setup() {
48
59
  return {
49
60
  args,
50
- options: argTypes[args.enum].options,
61
+ options: argTypes?.[args.enum]?.options,
51
62
  };
52
63
  },
53
64
  template: `
@@ -63,13 +74,16 @@ const EnumVariantTemplate = (args, { argTypes }) => ({
63
74
  `,
64
75
  });
65
76
 
66
- const VariantColorsTemplate = (args, { argTypes }) => ({
77
+ const VariantColorsTemplate: StoryFn<UDropdownButtonArgs> = (
78
+ args: UDropdownButtonArgs,
79
+ { argTypes },
80
+ ) => ({
67
81
  components: { UDropdownButton, URow, UCol },
68
82
  setup() {
69
83
  return {
70
84
  args,
71
- variants: argTypes.variant.options,
72
- colors: argTypes.color.options,
85
+ variants: argTypes?.variant?.options,
86
+ colors: argTypes?.color?.options,
73
87
  };
74
88
  },
75
89
  template: `
@@ -95,13 +109,13 @@ export const Filled = DefaultTemplate.bind({});
95
109
  Filled.args = { variant: "thirdary", filled: true };
96
110
 
97
111
  export const Variants = EnumVariantTemplate.bind({});
98
- Variants.args = { enum: "variant", text: "" };
112
+ Variants.args = { enum: "variant" };
99
113
 
100
114
  export const Sizes = EnumVariantTemplate.bind({});
101
- Sizes.args = { enum: "size", text: "" };
115
+ Sizes.args = { enum: "size" };
102
116
 
103
117
  export const VariantColors = VariantColorsTemplate.bind({});
104
- VariantColors.args = { text: "" };
118
+ VariantColors.args = {};
105
119
 
106
120
  export const WithoutDropdownIcon = EnumVariantTemplate.bind({});
107
121
  WithoutDropdownIcon.args = { enum: "variant", noIcon: true };
@@ -0,0 +1,108 @@
1
+ import defaultConfig from "./config.ts";
2
+
3
+ import type { UnknownObject } from "../types.ts";
4
+
5
+ export type Config = Partial<typeof defaultConfig>;
6
+
7
+ export interface UDropdownButtonProps {
8
+ /**
9
+ * Button label.
10
+ */
11
+ label?: string;
12
+
13
+ /**
14
+ * Options list.
15
+ */
16
+ options?: UnknownObject[];
17
+
18
+ /**
19
+ * Label key in the item object of options.
20
+ */
21
+ labelKey?: string;
22
+
23
+ /**
24
+ * Button variant.
25
+ */
26
+ variant?: "primary" | "secondary" | "thirdary";
27
+
28
+ /**
29
+ * Fill the background for thirdary variant.
30
+ */
31
+ filled?: boolean;
32
+
33
+ /**
34
+ * Button color.
35
+ */
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";
58
+
59
+ /**
60
+ * Button size.
61
+ */
62
+ size?: "2xs" | "xs" | "sm" | "md" | "lg" | "xl";
63
+
64
+ /**
65
+ * Set button corners rounded.
66
+ */
67
+ round?: boolean;
68
+
69
+ /**
70
+ * Set the same paddings for the button.
71
+ */
72
+ square?: boolean;
73
+
74
+ /**
75
+ * Disable the link.
76
+ */
77
+ disabled?: boolean;
78
+
79
+ /**
80
+ * Hide dropdown icon.
81
+ */
82
+ noIcon?: boolean;
83
+
84
+ /**
85
+ * The position of dropdown list on the y-axis.
86
+ */
87
+ yPosition?: "top" | "bottom";
88
+
89
+ /**
90
+ * The position of dropdown list on the x-axis.
91
+ */
92
+ xPosition?: "left" | "right";
93
+
94
+ /**
95
+ * Unique element id.
96
+ */
97
+ id?: string;
98
+
99
+ /**
100
+ * Component config object.
101
+ */
102
+ config?: Partial<typeof defaultConfig>;
103
+
104
+ /**
105
+ * Data-test attribute for automated testing.
106
+ */
107
+ dataTest?: string;
108
+ }
@@ -1,10 +1,21 @@
1
1
  import { computed } from "vue";
2
2
  import useUI from "../composables/useUI.ts";
3
3
 
4
- import defaultConfig from "./config.js";
4
+ import defaultConfig from "./config.ts";
5
5
 
6
- export default function useAttrs(props, { isShownOptions }) {
7
- const { config, getKeysAttrs, hasSlotContent, getExtendingKeysClasses } = useUI(
6
+ import type { Ref } from "vue";
7
+ import type { UseAttrs } from "../types.ts";
8
+ import type { UDropdownButtonProps, Config } from "./types.ts";
9
+
10
+ type ComponentState = {
11
+ isShownOptions: Ref<boolean>;
12
+ };
13
+
14
+ export default function useAttrs(
15
+ props: UDropdownButtonProps,
16
+ { isShownOptions }: ComponentState,
17
+ ): UseAttrs<Config> {
18
+ const { config, getKeysAttrs, hasSlotContent, getExtendingKeysClasses } = useUI<Config>(
8
19
  defaultConfig,
9
20
  () => props.config,
10
21
  );