vueless 0.0.504 → 0.0.505

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 (32) hide show
  1. package/package.json +1 -1
  2. package/types.ts +6 -0
  3. package/ui.button/UButton.vue +101 -240
  4. package/ui.button/storybook/Docs.mdx +2 -2
  5. package/ui.button/storybook/{stories.js → stories.ts} +25 -12
  6. package/ui.button/types.ts +121 -0
  7. package/ui.button/{useAttrs.js → useAttrs.ts} +6 -3
  8. package/ui.button-link/ULink.vue +72 -223
  9. package/ui.button-link/storybook/Docs.mdx +2 -2
  10. package/ui.button-link/storybook/{stories.js → stories.ts} +30 -17
  11. package/ui.button-link/types.ts +131 -0
  12. package/ui.button-link/{useAttrs.js → useAttrs.ts} +15 -3
  13. package/ui.button-toggle/UToggle.vue +47 -165
  14. package/ui.button-toggle/storybook/Docs.mdx +2 -2
  15. package/ui.button-toggle/storybook/{stories.js → stories.ts} +13 -5
  16. package/ui.button-toggle/types.ts +85 -0
  17. package/ui.button-toggle/useAttrs.ts +18 -0
  18. package/ui.button-toggle-item/UToggleItem.vue +59 -110
  19. package/ui.button-toggle-item/storybook/Docs.mdx +2 -2
  20. package/ui.button-toggle-item/storybook/{stories.js → stories.ts} +10 -3
  21. package/ui.button-toggle-item/types.ts +40 -0
  22. package/ui.button-toggle-item/{useAttrs.js → useAttrs.ts} +16 -4
  23. package/web-types.json +134 -59
  24. package/ui.button-toggle/useAttrs.js +0 -15
  25. /package/ui.button/{config.js → config.ts} +0 -0
  26. /package/ui.button/{constants.js → constants.ts} +0 -0
  27. /package/ui.button-link/{config.js → config.ts} +0 -0
  28. /package/ui.button-link/{constants.js → constants.ts} +0 -0
  29. /package/ui.button-toggle/{config.js → config.ts} +0 -0
  30. /package/ui.button-toggle/{constants.js → constants.ts} +0 -0
  31. /package/ui.button-toggle-item/{config.js → config.ts} +0 -0
  32. /package/ui.button-toggle-item/{constants.js → constants.ts} +0 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vueless",
3
- "version": "0.0.504",
3
+ "version": "0.0.505",
4
4
  "license": "MIT",
5
5
  "description": "Vue Styleless UI Component Library, powered by Tailwind CSS.",
6
6
  "keywords": [
package/types.ts CHANGED
@@ -11,6 +11,9 @@ import UHeaderDefaultConfig from "./ui.text-header/config.ts";
11
11
  import UNotifyDefaultConfig from "./ui.text-notify/config.ts";
12
12
  import UDotDefaultConfig from "./ui.other-dot/config.ts";
13
13
  import UButtonDefaultConfig from "./ui.button/config.ts";
14
+ import ULinkDefaultConfig from "./ui.button-link/config.ts";
15
+ import UToggleDefaultConfig from "./ui.button-toggle/config.ts";
16
+ import UToggleItemDefaultConfig from "./ui.button-toggle-item/config.ts";
14
17
  import UBadgeDefaultConfig from "./ui.text-badge/config.ts";
15
18
  import UCalendarDefaultConfig from "./ui.form-calendar/config.ts";
16
19
  import UDatePickerConfig from "./ui.form-date-picker/config.ts";
@@ -132,6 +135,9 @@ export interface Components {
132
135
  UNotify?: Partial<typeof UNotifyDefaultConfig>;
133
136
  UDot?: Partial<typeof UDotDefaultConfig>;
134
137
  UButton?: Partial<typeof UButtonDefaultConfig>;
138
+ ULink?: Partial<typeof ULinkDefaultConfig>;
139
+ UToggle?: Partial<typeof UToggleDefaultConfig>;
140
+ UToggleItem?: Partial<typeof UToggleItemDefaultConfig>;
135
141
  UBadge?: Partial<typeof UBadgeDefaultConfig>;
136
142
  UCalendar?: Partial<typeof UCalendarDefaultConfig>;
137
143
  UDatePicker?: Partial<typeof UDatePickerConfig>;
@@ -1,3 +1,104 @@
1
+ <script lang="ts" setup>
2
+ import { computed, ref, watchEffect, useId, watch } from "vue";
3
+
4
+ import { getDefault } from "../utils/ui.ts";
5
+ import ULoader from "../ui.loader/ULoader.vue";
6
+ import UIcon from "../ui.image-icon/UIcon.vue";
7
+
8
+ import defaultConfig from "./config.ts";
9
+ import useAttrs from "./useAttrs.ts";
10
+ import { UButton } from "./constants.ts";
11
+
12
+ import type { UButtonProps } from "./types.ts";
13
+
14
+ defineOptions({ inheritAttrs: false });
15
+
16
+ const props = withDefaults(defineProps<UButtonProps>(), {
17
+ variant: getDefault<UButtonProps>(defaultConfig, UButton).variant,
18
+ color: getDefault<UButtonProps>(defaultConfig, UButton).color,
19
+ size: getDefault<UButtonProps>(defaultConfig, UButton).size,
20
+ tag: getDefault<UButtonProps>(defaultConfig, UButton).tag,
21
+ tabindex: getDefault<UButtonProps>(defaultConfig, UButton).tabindex,
22
+ filled: getDefault<UButtonProps>(defaultConfig, UButton).filled,
23
+ disabled: getDefault<UButtonProps>(defaultConfig, UButton).disabled,
24
+ block: getDefault<UButtonProps>(defaultConfig, UButton).block,
25
+ round: getDefault<UButtonProps>(defaultConfig, UButton).round,
26
+ square: getDefault<UButtonProps>(defaultConfig, UButton).square,
27
+ loading: getDefault<UButtonProps>(defaultConfig, UButton).loading,
28
+ noRing: getDefault<UButtonProps>(defaultConfig, UButton).noRing,
29
+ dataTest: "",
30
+ });
31
+
32
+ const elementId = props.id || useId();
33
+
34
+ const { buttonAttrs, loaderAttrs, leftIconAttrs, rightIconAttrs, centerIconAttrs } =
35
+ useAttrs(props);
36
+
37
+ const buttonRef = ref(null);
38
+ const buttonStyle = ref(null);
39
+ const buttonWidth = ref(0);
40
+
41
+ const loaderSize = computed(() => {
42
+ const sizes = {
43
+ "2xs": "sm",
44
+ xs: "sm",
45
+ sm: "md",
46
+ md: "md",
47
+ lg: "lg",
48
+ xl: "lg",
49
+ };
50
+
51
+ return sizes[props.size];
52
+ });
53
+
54
+ const iconSize = computed(() => {
55
+ const sizes = {
56
+ "2xs": "2xs",
57
+ xs: "xs",
58
+ sm: "sm",
59
+ md: "sm",
60
+ lg: "md",
61
+ xl: "md",
62
+ };
63
+
64
+ return sizes[props.size];
65
+ });
66
+
67
+ const iconColor = computed(() => {
68
+ return props.variant === "primary" ? "white" : props.color;
69
+ });
70
+
71
+ watch(
72
+ () => props.loading,
73
+ (newValue, oldValue) => {
74
+ const isLoaderOn = newValue && oldValue !== undefined;
75
+
76
+ if (isLoaderOn && buttonRef.value) {
77
+ buttonWidth.value = buttonRef.value.offsetWidth;
78
+ }
79
+
80
+ buttonStyle.value = {
81
+ width: isLoaderOn ? `${buttonWidth.value}px` : null,
82
+ paddingLeft: isLoaderOn ? "0px" : null,
83
+ paddingRight: isLoaderOn ? "0px" : null,
84
+ };
85
+ },
86
+ { immediate: true },
87
+ );
88
+
89
+ watchEffect(() => {
90
+ props.loading && buttonRef.value.blur();
91
+ });
92
+
93
+ defineExpose({
94
+ /**
95
+ * A reference to the button element for direct DOM manipulation.
96
+ * @property {HTMLElement}
97
+ */
98
+ buttonRef,
99
+ });
100
+ </script>
101
+
1
102
  <template>
2
103
  <component
3
104
  :is="tag"
@@ -79,243 +180,3 @@
79
180
  </template>
80
181
  </component>
81
182
  </template>
82
-
83
- <script setup>
84
- import { computed, ref, watchEffect, useId, watch } from "vue";
85
-
86
- import { getDefault } from "../utils/ui.ts";
87
- import ULoader from "../ui.loader/ULoader.vue";
88
- import UIcon from "../ui.image-icon/UIcon.vue";
89
-
90
- import defaultConfig from "./config.js";
91
- import useAttrs from "./useAttrs.js";
92
- import { UButton } from "./constants.js";
93
-
94
- defineOptions({ inheritAttrs: false });
95
-
96
- const props = defineProps({
97
- /**
98
- * Button variant.
99
- * @values primary, secondary, thirdary
100
- */
101
- variant: {
102
- type: String,
103
- default: getDefault(defaultConfig, UButton).variant,
104
- },
105
-
106
- /**
107
- * Button color.
108
- * @values brand, grayscale, gray, red, orange, amber, yellow, lime, green, emerald, teal, cyan, sky, blue, indigo, violet, purple, fuchsia, pink, rose, white
109
- */
110
- color: {
111
- type: String,
112
- default: getDefault(defaultConfig, UButton).color,
113
- },
114
-
115
- /**
116
- * Button size.
117
- * @values 2xs, xs, sm, md, lg, xl
118
- */
119
- size: {
120
- type: String,
121
- default: getDefault(defaultConfig, UButton).size,
122
- },
123
-
124
- /**
125
- * Button label.
126
- */
127
- label: {
128
- type: String,
129
- default: "",
130
- },
131
-
132
- /**
133
- * Allows changing button html tag.
134
- */
135
- tag: {
136
- type: String,
137
- default: getDefault(defaultConfig, UButton).tag,
138
- },
139
-
140
- /**
141
- * Icon name (appears instead of label).
142
- */
143
- icon: {
144
- type: String,
145
- default: "",
146
- },
147
-
148
- /**
149
- * Left icon name.
150
- */
151
- leftIcon: {
152
- type: String,
153
- default: "",
154
- },
155
-
156
- /**
157
- * Right icon name.
158
- */
159
- rightIcon: {
160
- type: String,
161
- default: "",
162
- },
163
-
164
- /**
165
- * Controls the keyboard “Tab” focus order of elements.
166
- */
167
- tabindex: {
168
- type: [String, Number],
169
- default: getDefault(defaultConfig, UButton).tabindex,
170
- },
171
-
172
- /**
173
- * Fill the background for thirdary variant.
174
- */
175
- filled: {
176
- type: Boolean,
177
- default: getDefault(defaultConfig, UButton).filled,
178
- },
179
-
180
- /**
181
- * Disable the button.
182
- */
183
- disabled: {
184
- type: Boolean,
185
- default: getDefault(defaultConfig, UButton).disabled,
186
- },
187
-
188
- /**
189
- * Make the Button fill the width with its container.
190
- */
191
- block: {
192
- type: Boolean,
193
- default: getDefault(defaultConfig, UButton).block,
194
- },
195
-
196
- /**
197
- * Set button corners rounded.
198
- */
199
- round: {
200
- type: Boolean,
201
- default: getDefault(defaultConfig, UButton).round,
202
- },
203
-
204
- /**
205
- * Set the same paddings for the button.
206
- */
207
- square: {
208
- type: Boolean,
209
- default: getDefault(defaultConfig, UButton).square,
210
- },
211
-
212
- /**
213
- * Enable loader.
214
- */
215
- loading: {
216
- type: Boolean,
217
- default: getDefault(defaultConfig, UButton).loading,
218
- },
219
-
220
- /**
221
- * Remove button ring on focus.
222
- */
223
- noRing: {
224
- type: Boolean,
225
- default: getDefault(defaultConfig, UButton).noRing,
226
- },
227
-
228
- /**
229
- * Unique element id.
230
- */
231
- id: {
232
- type: String,
233
- default: "",
234
- },
235
-
236
- /**
237
- * Component config object.
238
- */
239
- config: {
240
- type: Object,
241
- default: () => ({}),
242
- },
243
-
244
- /**
245
- * Data-test attribute for automated testing.
246
- */
247
- dataTest: {
248
- type: String,
249
- default: "",
250
- },
251
- });
252
-
253
- const elementId = props.id || useId();
254
-
255
- const { buttonAttrs, loaderAttrs, leftIconAttrs, rightIconAttrs, centerIconAttrs } =
256
- useAttrs(props);
257
-
258
- const buttonRef = ref(null);
259
- const buttonStyle = ref(null);
260
- const buttonWidth = ref(0);
261
-
262
- const loaderSize = computed(() => {
263
- const sizes = {
264
- "2xs": "sm",
265
- xs: "sm",
266
- sm: "md",
267
- md: "md",
268
- lg: "lg",
269
- xl: "lg",
270
- };
271
-
272
- return sizes[props.size];
273
- });
274
-
275
- const iconSize = computed(() => {
276
- const sizes = {
277
- "2xs": "2xs",
278
- xs: "xs",
279
- sm: "sm",
280
- md: "sm",
281
- lg: "md",
282
- xl: "md",
283
- };
284
-
285
- return sizes[props.size];
286
- });
287
-
288
- const iconColor = computed(() => {
289
- return props.variant === "primary" ? "white" : props.color;
290
- });
291
-
292
- watch(
293
- () => props.loading,
294
- (newValue, oldValue) => {
295
- const isLoaderOn = newValue && oldValue !== undefined;
296
-
297
- if (isLoaderOn && buttonRef.value) {
298
- buttonWidth.value = buttonRef.value.offsetWidth;
299
- }
300
-
301
- buttonStyle.value = {
302
- width: isLoaderOn ? `${buttonWidth.value}px` : null,
303
- paddingLeft: isLoaderOn ? "0px" : null,
304
- paddingRight: isLoaderOn ? "0px" : null,
305
- };
306
- },
307
- { immediate: true },
308
- );
309
-
310
- watchEffect(() => {
311
- props.loading && buttonRef.value.blur();
312
- });
313
-
314
- defineExpose({
315
- /**
316
- * A reference to the button element for direct DOM manipulation.
317
- * @property {HTMLElement}
318
- */
319
- buttonRef,
320
- });
321
- </script>
@@ -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} />
@@ -12,6 +12,18 @@ import UIcon from "../../ui.image-icon/UIcon.vue";
12
12
  import URow from "../../ui.container-row/URow.vue";
13
13
  import UCol from "../../ui.container-col/UCol.vue";
14
14
 
15
+ import type { Meta, StoryFn } from "@storybook/vue3";
16
+ import type { UButtonProps } from "../types.ts";
17
+
18
+ interface UButtonArgs extends UButtonProps {
19
+ slotTemplate?: string;
20
+ enum: "variant" | "size";
21
+ }
22
+
23
+ interface StoryArgType {
24
+ options?: string[];
25
+ }
26
+
15
27
  export default {
16
28
  id: "1010",
17
29
  title: "Buttons & Links / Button",
@@ -25,9 +37,9 @@ export default {
25
37
  parameters: {
26
38
  ...getDocsDescription(UButton.__name),
27
39
  },
28
- };
40
+ } as Meta;
29
41
 
30
- const DefaultTemplate = (args) => ({
42
+ const DefaultTemplate: StoryFn<UButtonArgs> = (args: UButtonArgs) => ({
31
43
  components: { UButton, UIcon },
32
44
  setup() {
33
45
  const slots = getSlotNames(UButton.__name);
@@ -36,15 +48,15 @@ const DefaultTemplate = (args) => ({
36
48
  },
37
49
  template: `
38
50
  <UButton v-bind="args">
39
- ${args.slotTemplate || getSlotsFragment()}
51
+ ${args.slotTemplate || getSlotsFragment("")}
40
52
  </UButton>
41
53
  `,
42
54
  });
43
55
 
44
- const EnumVariantTemplate = (args, { argTypes }) => ({
56
+ const EnumVariantTemplate: StoryFn<UButtonArgs> = (args: UButtonArgs, { argTypes }) => ({
45
57
  components: { UButton, URow, UCol },
46
58
  setup() {
47
- return { args, options: argTypes[args.enum].options };
59
+ return { args, options: argTypes?.[args.enum]?.options };
48
60
  },
49
61
  template: `
50
62
  <UCol>
@@ -61,16 +73,17 @@ const EnumVariantTemplate = (args, { argTypes }) => ({
61
73
  `,
62
74
  });
63
75
 
64
- const ColorTemplate = (args, { argTypes }) => ({
76
+ const ColorTemplate: StoryFn<UButtonArgs> = (args, { argTypes }) => ({
65
77
  components: { UButton, URow, UCol },
66
78
  setup() {
67
- const variants = [...argTypes.variant.options, "thirdary"];
79
+ const variantOptions = (argTypes.variant as StoryArgType)?.options ?? [];
80
+ const variants = [...Array.from(variantOptions), "thirdary"];
68
81
 
69
82
  return {
70
83
  args,
71
84
  variants,
72
- colors: argTypes.color.options,
73
- shouldBeFilled: (variant, index) => {
85
+ colors: argTypes?.color?.options,
86
+ shouldBeFilled: (variant: string, index: number) => {
74
87
  return variant === "thirdary" && index === variants.length - 2;
75
88
  },
76
89
  };
@@ -104,7 +117,7 @@ Sizes.args = { enum: "size" };
104
117
  export const Round = EnumVariantTemplate.bind({});
105
118
  Round.args = { enum: "variant", round: true };
106
119
 
107
- export const Loading = (args) => ({
120
+ export const Loading: StoryFn<UButtonArgs> = (args) => ({
108
121
  components: { UButton, URow },
109
122
  setup() {
110
123
  const loading = ref(false);
@@ -147,7 +160,7 @@ Colors.args = {};
147
160
  export const Square = DefaultTemplate.bind({});
148
161
  Square.args = { square: true, icon: "filter_list" };
149
162
 
150
- export const IconProps = (args) => ({
163
+ export const IconProps: StoryFn<UButtonArgs> = (args) => ({
151
164
  components: { UButton, URow },
152
165
  setup() {
153
166
  return { args };
@@ -166,7 +179,7 @@ export const IconProps = (args) => ({
166
179
  `,
167
180
  });
168
181
 
169
- export const Slots = (args) => ({
182
+ export const Slots: StoryFn<UButtonArgs> = (args) => ({
170
183
  components: { UButton, UIcon, URow },
171
184
  setup() {
172
185
  return { args };
@@ -0,0 +1,121 @@
1
+ import defaultConfig from "./config.ts";
2
+
3
+ export type Config = Partial<typeof defaultConfig>;
4
+
5
+ export interface UButtonProps {
6
+ /**
7
+ * Button variant.
8
+ */
9
+ variant?: "primary" | "secondary" | "thirdary";
10
+
11
+ /**
12
+ * Button color.
13
+ */
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";
36
+
37
+ /**
38
+ * Button size.
39
+ */
40
+ size?: "2xs" | "xs" | "sm" | "md" | "lg" | "xl";
41
+
42
+ /**
43
+ * Button label.
44
+ */
45
+ label?: string;
46
+
47
+ /**
48
+ * Allows changing button html tag.
49
+ */
50
+ tag?: string;
51
+
52
+ /**
53
+ * Icon name (appears instead of label).
54
+ */
55
+ icon?: string;
56
+
57
+ /**
58
+ * Left icon name.
59
+ */
60
+ leftIcon?: string;
61
+
62
+ /**
63
+ * Right icon name.
64
+ */
65
+ rightIcon?: string;
66
+
67
+ /**
68
+ * Controls the keyboard “Tab” focus order of elements.
69
+ */
70
+ tabindex?: string | number;
71
+
72
+ /**
73
+ * Fill the background for thirdary variant.
74
+ */
75
+ filled?: boolean;
76
+
77
+ /**
78
+ * Disable the button.
79
+ */
80
+ disabled?: boolean;
81
+
82
+ /**
83
+ * Make the Button fill the width with its container.
84
+ */
85
+ block?: boolean;
86
+
87
+ /**
88
+ * Set button corners rounded.
89
+ */
90
+ round?: boolean;
91
+
92
+ /**
93
+ * Set the same paddings for the button.
94
+ */
95
+ square?: boolean;
96
+
97
+ /**
98
+ * Enable loader.
99
+ */
100
+ loading?: boolean;
101
+
102
+ /**
103
+ * Remove button ring on focus.
104
+ */
105
+ noRing?: boolean;
106
+
107
+ /**
108
+ * Unique element id.
109
+ */
110
+ id?: string;
111
+
112
+ /**
113
+ * Component config object.
114
+ */
115
+ config?: Partial<typeof defaultConfig>;
116
+
117
+ /**
118
+ * Data-test attribute for automated testing.
119
+ */
120
+ dataTest?: string;
121
+ }
@@ -1,10 +1,13 @@
1
1
  import { useSlots, 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) {
7
- const { config, getKeysAttrs, hasSlotContent } = useUI(defaultConfig, () => props.config);
6
+ import type { UseAttrs } from "../types.ts";
7
+ import type { UButtonProps, Config } from "./types.ts";
8
+
9
+ export default function useAttrs(props: UButtonProps): UseAttrs<Config> {
10
+ const { config, getKeysAttrs, hasSlotContent } = useUI<Config>(defaultConfig, () => props.config);
8
11
  const slots = useSlots();
9
12
 
10
13
  const mutatedProps = computed(() => ({