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
@@ -1,177 +1,29 @@
1
- <template>
2
- <ULabel
3
- :size="labelSize"
4
- :label="label"
5
- :description="description"
6
- :align="labelAlign"
7
- :disabled="disabled"
8
- centred
9
- v-bind="toggleLabelAttrs"
10
- :data-test="dataTest"
11
- >
12
- <div v-bind="itemsAttrs">
13
- <!-- @slot Use it to add UToggleItem directly. -->
14
- <slot>
15
- <UToggleItem
16
- v-for="(item, index) in options"
17
- :key="item.value"
18
- :name="name"
19
- :model-value="item.value"
20
- :value="item.value"
21
- :disabled="disabled"
22
- :label="item.label"
23
- :data-test="`${dataTest}-item-${index}`"
24
- v-bind="itemAttrs"
25
- />
26
- </slot>
27
- </div>
28
- </ULabel>
29
- </template>
30
-
31
- <script setup>
1
+ <script lang="ts" setup>
32
2
  import { computed, provide, readonly } from "vue";
33
3
 
34
4
  import ULabel from "../ui.form-label/ULabel.vue";
35
5
  import UToggleItem from "../ui.button-toggle-item/UToggleItem.vue";
36
6
  import { getDefault } from "../utils/ui.ts";
37
7
 
38
- import defaultConfig from "./config.js";
39
- import { UToggle, TYPE_RADIO, TYPE_CHECKBOX } from "./constants.js";
40
- import useAttrs from "./useAttrs.js";
41
-
42
- defineOptions({ inheritAttrs: false });
43
-
44
- const props = defineProps({
45
- /**
46
- * Selected value.
47
- */
48
- modelValue: {
49
- type: [String, Number, Array],
50
- default: "",
51
- },
52
-
53
- /**
54
- * Toggle item options.
55
- */
56
- options: {
57
- type: Array,
58
- default: () => [],
59
- },
60
-
61
- /**
62
- * Toggle variant.
63
- * @values primary, secondary, thirdary
64
- */
65
- variant: {
66
- type: String,
67
- default: getDefault(defaultConfig, UToggle).variant,
68
- },
69
-
70
- /**
71
- * Toggle size.
72
- * @values 2xs, xs, sm, md, lg, xl
73
- */
74
- size: {
75
- type: String,
76
- default: getDefault(defaultConfig, UToggle).size,
77
- },
78
-
79
- /**
80
- * Label placement.
81
- * @values top, topWithDesc, left, right
82
- */
83
- labelAlign: {
84
- type: String,
85
- default: getDefault(defaultConfig, UToggle).labelAlign,
86
- },
87
-
88
- /**
89
- * Toggle label.
90
- */
91
- label: {
92
- type: String,
93
- default: "",
94
- },
95
-
96
- /**
97
- * Toggle description.
98
- */
99
- description: {
100
- type: String,
101
- default: "",
102
- },
103
-
104
- /**
105
- * Toggle name.
106
- */
107
- name: {
108
- type: String,
109
- required: true,
110
- },
111
-
112
- /**
113
- * Allow selecting a few options and return them as an array.
114
- */
115
- multiple: {
116
- type: Boolean,
117
- default: getDefault(defaultConfig, UToggle).multiple,
118
- },
119
-
120
- /**
121
- * Separate toggle items.
122
- */
123
- separated: {
124
- type: Boolean,
125
- default: getDefault(defaultConfig, UToggle).separated,
126
- },
8
+ import defaultConfig from "./config.ts";
9
+ import { UToggle, TYPE_RADIO, TYPE_CHECKBOX } from "./constants.ts";
10
+ import useAttrs from "./useAttrs.ts";
127
11
 
128
- /**
129
- * Make toggle disabled.
130
- */
131
- disabled: {
132
- type: Boolean,
133
- default: getDefault(defaultConfig, UToggle).disabled,
134
- },
12
+ import type { UToggleProps } from "./types.ts";
135
13
 
136
- /**
137
- * Make the toggle fill the width with its container.
138
- */
139
- block: {
140
- type: Boolean,
141
- default: getDefault(defaultConfig, UToggle).block,
142
- },
143
-
144
- /**
145
- * Set button corners rounded.
146
- */
147
- round: {
148
- type: Boolean,
149
- default: getDefault(defaultConfig, UToggle).round,
150
- },
151
-
152
- /**
153
- * Set the same paddings for the button.
154
- */
155
- square: {
156
- type: Boolean,
157
- default: getDefault(defaultConfig, UToggle).square,
158
- },
159
-
160
- /**
161
- * Component config object.
162
- */
163
- config: {
164
- type: Object,
165
- default: () => ({}),
166
- },
14
+ defineOptions({ inheritAttrs: false });
167
15
 
168
- /**
169
- * Data-test attribute for automated testing.
170
- */
171
- dataTest: {
172
- type: String,
173
- default: "",
174
- },
16
+ const props = withDefaults(defineProps<UToggleProps>(), {
17
+ variant: getDefault<UToggleProps>(defaultConfig, UToggle).variant,
18
+ size: getDefault<UToggleProps>(defaultConfig, UToggle).size,
19
+ labelAlign: getDefault<UToggleProps>(defaultConfig, UToggle).labelAlign,
20
+ multiple: getDefault<UToggleProps>(defaultConfig, UToggle).multiple,
21
+ separated: getDefault<UToggleProps>(defaultConfig, UToggle).separated,
22
+ disabled: getDefault<UToggleProps>(defaultConfig, UToggle).disabled,
23
+ block: getDefault<UToggleProps>(defaultConfig, UToggle).block,
24
+ round: getDefault<UToggleProps>(defaultConfig, UToggle).round,
25
+ square: getDefault<UToggleProps>(defaultConfig, UToggle).square,
26
+ dataTest: "",
175
27
  });
176
28
 
177
29
  const emit = defineEmits([
@@ -238,3 +90,33 @@ provide("toggleSelectedValue", {
238
90
  updateSelectedValue,
239
91
  });
240
92
  </script>
93
+
94
+ <template>
95
+ <ULabel
96
+ :size="labelSize"
97
+ :label="label"
98
+ :description="description"
99
+ :align="labelAlign"
100
+ :disabled="disabled"
101
+ centred
102
+ v-bind="toggleLabelAttrs"
103
+ :data-test="dataTest"
104
+ >
105
+ <div v-bind="itemsAttrs">
106
+ <!-- @slot Use it to add UToggleItem directly. -->
107
+ <slot>
108
+ <UToggleItem
109
+ v-for="(item, index) in options"
110
+ :key="item.value"
111
+ :name="name"
112
+ :model-value="item.value"
113
+ :value="item.value"
114
+ :disabled="disabled"
115
+ :label="item.label"
116
+ :data-test="`${dataTest}-item-${index}`"
117
+ v-bind="itemAttrs"
118
+ />
119
+ </slot>
120
+ </div>
121
+ </ULabel>
122
+ </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} />
@@ -6,6 +6,14 @@ import UIcon from "../../ui.image-icon/UIcon.vue";
6
6
  import UToggleItem from "../../ui.button-toggle-item/UToggleItem.vue";
7
7
  import URow from "../../ui.container-row/URow.vue";
8
8
 
9
+ import type { Meta, StoryFn } from "@storybook/vue3";
10
+ import type { UToggleProps } from "../types.ts";
11
+
12
+ interface UToggleArgs extends UToggleProps {
13
+ slotTemplate?: string;
14
+ enum: "variant" | "size";
15
+ }
16
+
9
17
  /**
10
18
  * The `UToggle` component. | [View on GitHub](https://github.com/vuelessjs/vueless/tree/main/src/ui.button-toggle)
11
19
  */
@@ -25,9 +33,9 @@ export default {
25
33
  ...getArgTypes(UToggle.__name),
26
34
  modelValue: { control: { type: "text" } },
27
35
  },
28
- };
36
+ } as Meta;
29
37
 
30
- const DefaultTemplate = (args) => ({
38
+ const DefaultTemplate: StoryFn<UToggleArgs> = (args: UToggleArgs) => ({
31
39
  components: { UToggle, UIcon, UToggleItem },
32
40
  setup() {
33
41
  const slots = getSlotNames(UToggle.__name);
@@ -36,12 +44,12 @@ const DefaultTemplate = (args) => ({
36
44
  },
37
45
  template: `
38
46
  <UToggle v-bind="args" v-model="args.modelValue">
39
- ${args.slotTemplate || getSlotsFragment()}
47
+ ${args.slotTemplate || getSlotsFragment("")}
40
48
  </UToggle>
41
49
  `,
42
50
  });
43
51
 
44
- const EnumVariantTemplate = (args, { argTypes }) => ({
52
+ const EnumVariantTemplate: StoryFn<UToggleArgs> = (args: UToggleArgs, { argTypes }) => ({
45
53
  components: { UToggle, URow },
46
54
  setup() {
47
55
  const value = ref("");
@@ -49,7 +57,7 @@ const EnumVariantTemplate = (args, { argTypes }) => ({
49
57
  return {
50
58
  args,
51
59
  value,
52
- options: argTypes[args.enum].options,
60
+ options: argTypes?.[args.enum]?.options,
53
61
  };
54
62
  },
55
63
  template: `
@@ -0,0 +1,85 @@
1
+ import defaultConfig from "./config.ts";
2
+
3
+ export type Config = Partial<typeof defaultConfig>;
4
+
5
+ export interface UToggleProps {
6
+ /**
7
+ * Selected value.
8
+ */
9
+ modelValue?: string | number | Array<string | number>;
10
+
11
+ /**
12
+ * Toggle item options.
13
+ */
14
+ options?: Array<string | number>;
15
+
16
+ /**
17
+ * Toggle variant.
18
+ */
19
+ variant?: "primary" | "secondary" | "thirdary";
20
+
21
+ /**
22
+ * Toggle size.
23
+ */
24
+ size?: "2xs" | "xs" | "sm" | "md" | "lg" | "xl";
25
+
26
+ /**
27
+ * Label placement.
28
+ */
29
+ labelAlign?: "top" | "topWithDesc" | "left" | "right";
30
+
31
+ /**
32
+ * Toggle label.
33
+ */
34
+ label?: string;
35
+
36
+ /**
37
+ * Toggle description.
38
+ */
39
+ description?: string;
40
+
41
+ /**
42
+ * Toggle name.
43
+ */
44
+ name: string;
45
+
46
+ /**
47
+ * Allow selecting a few options and return them as an array.
48
+ */
49
+ multiple?: boolean;
50
+
51
+ /**
52
+ * Separate toggle items.
53
+ */
54
+ separated?: boolean;
55
+
56
+ /**
57
+ * Make toggle disabled.
58
+ */
59
+ disabled?: boolean;
60
+
61
+ /**
62
+ * Make the toggle fill the width with its container.
63
+ */
64
+ block?: boolean;
65
+
66
+ /**
67
+ * Set button corners rounded.
68
+ */
69
+ round?: boolean;
70
+
71
+ /**
72
+ * Set the same paddings for the button.
73
+ */
74
+ square?: boolean;
75
+
76
+ /**
77
+ * Component config object.
78
+ */
79
+ config?: Partial<typeof defaultConfig>;
80
+
81
+ /**
82
+ * Data-test attribute for automated testing.
83
+ */
84
+ dataTest?: string;
85
+ }
@@ -0,0 +1,18 @@
1
+ import useUI from "../composables/useUI.ts";
2
+
3
+ import defaultConfig from "./config.ts";
4
+
5
+ import type { UseAttrs } from "../types.ts";
6
+ import type { UToggleProps, Config } from "./types.ts";
7
+
8
+ export default function useAttrs(props: UToggleProps): UseAttrs<Config> {
9
+ const { config, getKeysAttrs, hasSlotContent } = useUI<Config>(defaultConfig, () => props.config);
10
+
11
+ const keysAttrs = getKeysAttrs();
12
+
13
+ return {
14
+ config,
15
+ ...keysAttrs,
16
+ hasSlotContent,
17
+ };
18
+ }
@@ -1,122 +1,22 @@
1
- <template>
2
- <UButton
3
- tabindex="0"
4
- :for="elementId"
5
- :no-ring="!getToggleSeparated()"
6
- color="grayscale"
7
- variant="secondary"
8
- :label="label"
9
- :size="getToggleSize()"
10
- :round="getToggleRound()"
11
- :block="getToggleBlock()"
12
- :square="getToggleSquare()"
13
- :disabled="getToggleDisabled()"
14
- v-bind="toggleButtonAttrs"
15
- @click="onClickSetValue"
16
- >
17
- <template #left>
18
- <!-- @slot Use it to add something before the label. -->
19
- <slot name="left" />
20
- </template>
21
-
22
- <!-- @slot Use it to add something instead of the label. -->
23
- <template #default>
24
- <input
25
- :id="elementId"
26
- v-model="selectedItem"
27
- :name="getToggleName()"
28
- :type="getToggleType()"
29
- :value="value"
30
- :disabled="getToggleDisabled()"
31
- v-bind="toggleInputAttrs"
32
- />
33
-
34
- <!--
35
- @slot Use it to add something instead of the label.
36
- @binding {string} label
37
- -->
38
- <slot name="default" :label="label">
39
- {{ label }}
40
- </slot>
41
- </template>
42
-
43
- <template #right>
44
- <!-- @slot Use it to add something after the label. -->
45
- <slot name="right" />
46
- </template>
47
- </UButton>
48
- </template>
49
-
50
- <script setup>
1
+ <script lang="ts" setup>
51
2
  import { computed, inject, onMounted, ref, useId } from "vue";
52
3
 
53
4
  import UButton from "../ui.button/UButton.vue";
54
5
  import { getDefault } from "../utils/ui.ts";
55
6
 
56
- import { TYPE_RADIO } from "../ui.button-toggle/constants.js";
7
+ import { TYPE_RADIO } from "../ui.button-toggle/constants.ts";
57
8
 
58
- import useAttrs from "./useAttrs.js";
59
- import defaultConfig from "./config.js";
60
- import { UToggleItem } from "./constants.js";
9
+ import useAttrs from "./useAttrs.ts";
10
+ import defaultConfig from "./config.ts";
11
+ import { UToggleItem } from "./constants.ts";
61
12
 
62
- defineOptions({ inheritAttrs: false });
63
-
64
- const props = defineProps({
65
- /**
66
- * Selected value.
67
- */
68
- modelValue: {
69
- type: [String, Number, Array],
70
- default: "",
71
- },
13
+ import type { UToggleItemProps } from "./types.ts";
72
14
 
73
- /**
74
- * Value for checkbox state.
75
- */
76
- value: {
77
- type: [String, Number],
78
- default: "",
79
- },
80
-
81
- /**
82
- * Toggle item label.
83
- */
84
- label: {
85
- type: String,
86
- default: "",
87
- },
88
-
89
- /**
90
- * Make toggle item disabled.
91
- */
92
- disabled: {
93
- type: Boolean,
94
- default: getDefault(defaultConfig, UToggleItem).disabled,
95
- },
96
-
97
- /**
98
- * Unique element id.
99
- */
100
- id: {
101
- type: String,
102
- default: "",
103
- },
104
-
105
- /**
106
- * Component config object.
107
- */
108
- config: {
109
- type: Object,
110
- default: () => ({}),
111
- },
15
+ defineOptions({ inheritAttrs: false });
112
16
 
113
- /**
114
- * Data-test attribute for automated testing.
115
- */
116
- dataTest: {
117
- type: String,
118
- default: "",
119
- },
17
+ const props = withDefaults(defineProps<UToggleItemProps>(), {
18
+ disabled: getDefault<UToggleItemProps>(defaultConfig, UToggleItem).disabled,
19
+ dataTest: "",
120
20
  });
121
21
 
122
22
  const emit = defineEmits([
@@ -175,3 +75,52 @@ function onClickSetValue() {
175
75
  emit("update:modelValue", props.value);
176
76
  }
177
77
  </script>
78
+
79
+ <template>
80
+ <UButton
81
+ tabindex="0"
82
+ :for="elementId"
83
+ :no-ring="!getToggleSeparated()"
84
+ color="grayscale"
85
+ variant="secondary"
86
+ :label="label"
87
+ :size="getToggleSize()"
88
+ :round="getToggleRound()"
89
+ :block="getToggleBlock()"
90
+ :square="getToggleSquare()"
91
+ :disabled="getToggleDisabled()"
92
+ v-bind="toggleButtonAttrs"
93
+ @click="onClickSetValue"
94
+ >
95
+ <template #left>
96
+ <!-- @slot Use it to add something before the label. -->
97
+ <slot name="left" />
98
+ </template>
99
+
100
+ <!-- @slot Use it to add something instead of the label. -->
101
+ <template #default>
102
+ <input
103
+ :id="elementId"
104
+ v-model="selectedItem"
105
+ :name="getToggleName()"
106
+ :type="getToggleType()"
107
+ :value="value"
108
+ :disabled="getToggleDisabled()"
109
+ v-bind="toggleInputAttrs"
110
+ />
111
+
112
+ <!--
113
+ @slot Use it to add something instead of the label.
114
+ @binding {string} label
115
+ -->
116
+ <slot name="default" :label="label">
117
+ {{ label }}
118
+ </slot>
119
+ </template>
120
+
121
+ <template #right>
122
+ <!-- @slot Use it to add something after the label. -->
123
+ <slot name="right" />
124
+ </template>
125
+ </UButton>
126
+ </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} />
@@ -3,6 +3,13 @@ import { getArgTypes, getSlotNames, getSlotsFragment } from "../../utils/storybo
3
3
  import UToggleItem from "../../ui.button-toggle-item/UToggleItem.vue";
4
4
  import UIcon from "../../ui.image-icon/UIcon.vue";
5
5
 
6
+ import type { Meta, StoryFn } from "@storybook/vue3";
7
+ import type { UToggleItemProps } from "../types.ts";
8
+
9
+ interface UToggleItemArgs extends UToggleItemProps {
10
+ slotTemplate?: string;
11
+ }
12
+
6
13
  /**
7
14
  * The `UToggleItem` component. | [View on GitHub](https://github.com/vuelessjs/vueless/tree/main/src/ui.button-toggle-item)
8
15
  */
@@ -18,9 +25,9 @@ export default {
18
25
  ...getArgTypes(UToggleItem.__name),
19
26
  value: { control: { type: "text" } },
20
27
  },
21
- };
28
+ } as Meta;
22
29
 
23
- const DefaultTemplate = (args) => ({
30
+ const DefaultTemplate: StoryFn<UToggleItemArgs> = (args: UToggleItemArgs) => ({
24
31
  components: { UToggleItem, UIcon },
25
32
  setup() {
26
33
  const slots = getSlotNames(UToggleItem.__name);
@@ -33,7 +40,7 @@ const DefaultTemplate = (args) => ({
33
40
  v-model="args.modelValue"
34
41
  name="toggle"
35
42
  >
36
- ${args.slotTemplate || getSlotsFragment()}
43
+ ${args.slotTemplate || getSlotsFragment("")}
37
44
  </UToggleItem>
38
45
  `,
39
46
  });
@@ -0,0 +1,40 @@
1
+ import defaultConfig from "./config.ts";
2
+
3
+ export type Config = Partial<typeof defaultConfig>;
4
+
5
+ export interface UToggleItemProps {
6
+ /**
7
+ * Selected value.
8
+ */
9
+ modelValue?: string | number | Array<string | number>;
10
+
11
+ /**
12
+ * Value for checkbox state.
13
+ */
14
+ value?: string | number;
15
+
16
+ /**
17
+ * Toggle item label.
18
+ */
19
+ label?: string;
20
+
21
+ /**
22
+ * Make toggle item disabled.
23
+ */
24
+ disabled?: boolean;
25
+
26
+ /**
27
+ * Unique element id.
28
+ */
29
+ id?: string;
30
+
31
+ /**
32
+ * Component config object.
33
+ */
34
+ config?: Partial<typeof defaultConfig>;
35
+
36
+ /**
37
+ * Data-test attribute for automated testing.
38
+ */
39
+ dataTest?: string;
40
+ }
@@ -1,10 +1,22 @@
1
- import { computed, toValue } from "vue";
1
+ import { computed, toValue, type Ref } 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, { isSelected, separated, variant }) {
7
- const { config, getKeysAttrs, hasSlotContent, getExtendingKeysClasses } = useUI(
6
+ import type { UseAttrs } from "../types.ts";
7
+ import type { UToggleItemProps, Config } from "./types.ts";
8
+
9
+ type itemState = {
10
+ isSelected: Ref<boolean>;
11
+ separated: Ref<boolean>;
12
+ variant: string;
13
+ };
14
+
15
+ export default function useAttrs(
16
+ props: UToggleItemProps,
17
+ { isSelected, separated, variant }: itemState,
18
+ ): UseAttrs<Config> {
19
+ const { config, getKeysAttrs, hasSlotContent, getExtendingKeysClasses } = useUI<Config>(
8
20
  defaultConfig,
9
21
  () => props.config,
10
22
  );