vueless 0.0.145 → 0.0.147

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vueless",
3
- "version": "0.0.145",
3
+ "version": "0.0.147",
4
4
  "license": "MIT",
5
5
  "description": "Vue Styleless Component Framework.",
6
6
  "homepage": "https://vueless.com",
@@ -1,16 +1,34 @@
1
+ import { computed } from "vue";
1
2
  import useUI from "../../composable.ui";
3
+ import { cva } from "../../service.ui";
2
4
 
3
5
  import defaultConfig from "../configs/default.config";
4
6
 
5
7
  export function useAttrs(props) {
6
8
  const { config, getAttrs } = useUI(defaultConfig, () => props.config);
9
+ const { items } = config.value;
7
10
 
8
- const wrapperAttrs = getAttrs("wrapper");
9
- const toggleItemAttrs = getAttrs("toggleItem", { isComponent: true });
11
+ const cvaItems = cva({
12
+ base: items.base,
13
+ variants: items.variants,
14
+ compoundVariants: items.compoundVariants,
15
+ });
16
+
17
+ const itemsClasses = computed(() =>
18
+ cvaItems({
19
+ size: props.size,
20
+ separated: props.separated,
21
+ }),
22
+ );
23
+
24
+ const labelAttrs = getAttrs("label", { isComponent: true });
25
+ const itemsAttrs = getAttrs("items", { classes: itemsClasses });
26
+ const itemAttrs = getAttrs("item", { isComponent: true });
10
27
 
11
28
  return {
12
29
  config,
13
- wrapperAttrs,
14
- toggleItemAttrs,
30
+ labelAttrs,
31
+ itemsAttrs,
32
+ itemAttrs,
15
33
  };
16
34
  }
@@ -1,14 +1,37 @@
1
1
  export default /*tw*/ {
2
- wrapper: `
3
- flex gap-px
4
- [&>*:first-child]:rounded-l-lg [&>*:first-child]:rounded-r-none
5
- [&>*:last-child]:rounded-r-lg [&>*:last-child]:rounded-l-none
6
- `,
7
- toggleItem: "",
2
+ label: "",
3
+ items: {
4
+ base: "flex flex-wrap",
5
+ variants: {
6
+ size: {
7
+ "2xs": "gap-2",
8
+ xs: "gap-3",
9
+ sm: "gap-4",
10
+ md: "gap-5",
11
+ lg: "gap-6",
12
+ xl: "gap-7",
13
+ },
14
+ separated: {
15
+ false: `
16
+ gap-px flex-nowrap
17
+ [&>*:first-child]:rounded-l-lg [&>*:first-child]:rounded-r-none
18
+ [&>*:last-child]:rounded-r-lg [&>*:last-child]:rounded-l-none
19
+ `,
20
+ },
21
+ },
22
+ },
23
+ item: "",
8
24
  defaultVariants: {
25
+ color: "brand",
9
26
  variant: "primary",
27
+ labelAlign: "top",
10
28
  size: "md",
11
29
  block: false,
30
+ pill: false,
31
+ square: false,
32
+ filled: false,
33
+ disabled: false,
12
34
  multiple: false,
35
+ separated: false,
13
36
  },
14
37
  };
@@ -1,24 +1,35 @@
1
1
  <template>
2
- <div :data-cy="dataCy" v-bind="wrapperAttrs">
3
- <!-- @slot Use it to add UToggleItem directly. -->
4
- <slot>
5
- <UToggleItem
6
- v-for="(item, index) in options"
7
- :key="item.value"
8
- :name="name"
9
- :model-value="item.value"
10
- :value="item.value"
11
- :label="item.label"
12
- :data-cy="`${dataCy}-item-${index}`"
13
- v-bind="toggleItemAttrs"
14
- />
15
- </slot>
16
- </div>
2
+ <ULabel
3
+ :size="size"
4
+ :label="label"
5
+ :description="description"
6
+ :align="labelAlign"
7
+ :disabled="disabled"
8
+ :data-cy="dataCy"
9
+ v-bind="labelAttrs"
10
+ >
11
+ <div v-bind="itemsAttrs">
12
+ <!-- @slot Use it to add UToggleItem directly. -->
13
+ <slot>
14
+ <UToggleItem
15
+ v-for="(item, index) in options"
16
+ :key="item.value"
17
+ :name="name"
18
+ :model-value="item.value"
19
+ :value="item.value"
20
+ :label="item.label"
21
+ :data-cy="`${dataCy}-item-${index}`"
22
+ v-bind="itemAttrs"
23
+ />
24
+ </slot>
25
+ </div>
26
+ </ULabel>
17
27
  </template>
18
28
 
19
29
  <script setup>
20
30
  import { computed, provide, readonly } from "vue";
21
31
 
32
+ import ULabel from "../ui.form-label";
22
33
  import UToggleItem from "../ui.button-toggle-item";
23
34
  import UIService from "../service.ui";
24
35
 
@@ -39,7 +50,7 @@ const props = defineProps({
39
50
  },
40
51
 
41
52
  /**
42
- * Toggle variants.
53
+ * Toggle variant.
43
54
  * @values primary, secondary, thirdary
44
55
  */
45
56
  variant: {
@@ -65,13 +76,38 @@ const props = defineProps({
65
76
 
66
77
  /**
67
78
  * Toggle size.
68
- * @values xs, sm, md, lg
79
+ * @values 2xs, xs, sm, md, lg, xl
69
80
  */
70
81
  size: {
71
82
  type: String,
72
83
  default: UIService.get(defaultConfig, UToggle).default.size,
73
84
  },
74
85
 
86
+ /**
87
+ * Toggle label.
88
+ */
89
+ label: {
90
+ type: String,
91
+ default: "",
92
+ },
93
+
94
+ /**
95
+ * Toggle description.
96
+ */
97
+ description: {
98
+ type: String,
99
+ default: "",
100
+ },
101
+
102
+ /**
103
+ * Label placement.
104
+ * @values top, topInside, topWithDesc, bottom, left, right
105
+ */
106
+ labelAlign: {
107
+ type: String,
108
+ default: UIService.get(defaultConfig, UToggle).default.labelAlign,
109
+ },
110
+
75
111
  /**
76
112
  * Make the toggle fill the width with its container.
77
113
  */
@@ -88,6 +124,55 @@ const props = defineProps({
88
124
  default: UIService.get(defaultConfig, UToggle).default.multiple,
89
125
  },
90
126
 
127
+ /**
128
+ * Button color.
129
+ * @values brand, grayscale, gray, red, orange, amber, yellow, lime, green, emerald, teal, cyan, sky, blue, indigo, violet, purple, fuchsia, pink, rose, white
130
+ */
131
+ color: {
132
+ type: String,
133
+ default: UIService.get(defaultConfig, UToggle).default.color,
134
+ },
135
+
136
+ /**
137
+ * Separate toggle items.
138
+ */
139
+ separated: {
140
+ type: Boolean,
141
+ default: UIService.get(defaultConfig, UToggle).default.separated,
142
+ },
143
+
144
+ /**
145
+ * Make toggle disabled.
146
+ */
147
+ disabled: {
148
+ type: Boolean,
149
+ default: UIService.get(defaultConfig, UToggle).default.disabled,
150
+ },
151
+
152
+ /**
153
+ * Fill the background for thirdary variant.
154
+ */
155
+ filled: {
156
+ type: Boolean,
157
+ default: UIService.get(defaultConfig, UToggle).default.filled,
158
+ },
159
+
160
+ /**
161
+ * Set button corners rounded.
162
+ */
163
+ pill: {
164
+ type: Boolean,
165
+ default: UIService.get(defaultConfig, UToggle).default.pill,
166
+ },
167
+
168
+ /**
169
+ * Set the same paddings for the button.
170
+ */
171
+ square: {
172
+ type: Boolean,
173
+ default: UIService.get(defaultConfig, UToggle).default.square,
174
+ },
175
+
91
176
  /**
92
177
  * Sets data-cy attribute for automated testing.
93
178
  */
@@ -99,7 +184,7 @@ const props = defineProps({
99
184
 
100
185
  const emit = defineEmits(["update:modelValue"]);
101
186
 
102
- const { wrapperAttrs, toggleItemAttrs } = useAttrs(props);
187
+ const { labelAttrs, itemsAttrs, itemAttrs } = useAttrs(props);
103
188
 
104
189
  const selectedValue = computed({
105
190
  get: () => props.modelValue,
@@ -117,10 +202,10 @@ function updateSelectedValue(value, checked) {
117
202
  return;
118
203
  }
119
204
 
120
- if (!checked) {
121
- selectedValue.value = selectedValue.value.filter((item) => item !== value);
122
- } else {
205
+ if (checked) {
123
206
  selectedValue.value.push(value);
207
+ } else {
208
+ selectedValue.value = selectedValue.value.filter((item) => String(item) !== String(value));
124
209
  }
125
210
  }
126
211
 
@@ -129,6 +214,13 @@ provide("toggleName", () => props.name);
129
214
  provide("toggleSize", () => props.size);
130
215
  provide("toggleBlock", () => props.block);
131
216
  provide("toggleVariant", () => props.variant);
217
+ provide("toggleColor", () => props.color);
218
+ provide("toggleFilled", () => props.filled);
219
+ provide("toggleDisabled", () => props.disabled);
220
+ provide("toggleSeparated", () => props.separated);
221
+ provide("togglePill", () => props.pill);
222
+ provide("toggleSquare", () => props.square);
223
+
132
224
  provide("toggleSelectedValue", {
133
225
  selectedValue: readonly(selectedValue),
134
226
  updateSelectedValue,
@@ -1,13 +1,55 @@
1
+ import { computed, toValue } from "vue";
2
+ import { cx, cva } from "../../service.ui";
1
3
  import useUI from "../../composable.ui";
2
4
 
3
5
  import defaultConfig from "../configs/default.config";
4
6
 
5
- export function useAttrs(props) {
6
- const { getAttrs } = useUI(defaultConfig, () => props.config);
7
+ export function useAttrs(props, { selectedValue, separated, variant, color }) {
8
+ const { config, getAttrs, setColor } = useUI(defaultConfig, () => props.config);
9
+ const { button, selected } = config.value;
7
10
 
8
- const buttonAttrs = getAttrs("button");
11
+ const cvaButton = cva({
12
+ base: button.base,
13
+ variants: button.variants,
14
+ compoundVariants: button.compoundVariants,
15
+ });
16
+
17
+ const buttonClasses = computed(() =>
18
+ cvaButton({
19
+ separated: toValue(separated),
20
+ }),
21
+ );
22
+
23
+ const cvaSelected = cva({
24
+ base: selected.base,
25
+ variants: selected.variants,
26
+ compoundVariants: selected.compoundVariants,
27
+ });
28
+
29
+ const selectedClasses = computed(() =>
30
+ setColor(
31
+ cvaSelected({
32
+ color: toValue(color),
33
+ variant: toValue(variant),
34
+ }),
35
+ toValue(color),
36
+ ),
37
+ );
38
+
39
+ const buttonAttrsRaw = getAttrs("button", { isComponent: true, classes: buttonClasses });
9
40
  const inputAttrs = getAttrs("input");
10
41
 
42
+ const buttonAttrs = computed(() => {
43
+ const isSelected = Array.isArray(selectedValue.value)
44
+ ? selectedValue.value?.includes(props.value)
45
+ : selectedValue.value === props.value;
46
+
47
+ return {
48
+ ...buttonAttrsRaw.value,
49
+ class: cx([buttonAttrsRaw.value.class, isSelected && selectedClasses.value]),
50
+ };
51
+ });
52
+
11
53
  return {
12
54
  buttonAttrs,
13
55
  inputAttrs,
@@ -1,11 +1,40 @@
1
1
  export default /*tw*/ {
2
- button: "rounded-none",
3
- input: "p-0 m-0 size-0 invisible peer absolute",
2
+ button: {
3
+ base: "",
4
+ variants: {
5
+ separated: {
6
+ false: "rounded-none",
7
+ },
8
+ },
9
+ },
10
+ input: "p-0 m-0 size-0 invisible absolute",
11
+ selected: {
12
+ base: "",
13
+ variants: {
14
+ variant: {
15
+ primary: "!bg-{color}-800 !border-{color}-800",
16
+ secondary: "!text-{color}-800 !border-{color}-800 bg-{color}-800 bg-opacity-10",
17
+ thirdary: "!text-{color}-800 !bg-{color}-800 !bg-opacity-10",
18
+ },
19
+ },
20
+ compoundVariants: [
21
+ { color: "grayscale", variant: "primary", class: "!bg-gray-700 !border-gray-700" },
22
+ { color: "grayscale", variant: "secondary", class: "!text-gray-700 !border-gray-700 !bg-gray-700 !bg-opacity-15" },
23
+ { color: "grayscale", variant: "thirdary", class: "!text-gray-700 !bg-gray-700" },
24
+ { color: "white", variant: "primary", class: "!text-gray-700 !border-gray-100 !bg-gray-100" },
25
+ { color: "white", variant: "secondary", class: "!text-gray-700 !border-gray-400" },
26
+ { color: "white", variant: "thirdary", class: "!text-gray-700 !bg-white" },
27
+ ],
28
+ },
4
29
  defaultVariants: {
30
+ color: "brand",
5
31
  variant: "primary",
6
32
  type: "radio",
7
33
  size: "md",
8
34
  block: false,
35
+ pill: false,
36
+ square: false,
37
+ filled: false,
9
38
  disabled: false,
10
39
  },
11
40
  };
@@ -7,8 +7,12 @@
7
7
  :size="toValue(size)"
8
8
  :block="toValue(block)"
9
9
  :variant="toValue(variant)"
10
+ :color="toValue(color)"
11
+ :pill="toValue(pill)"
12
+ :filled="toValue(filled)"
13
+ :square="toValue(square)"
10
14
  v-bind="buttonAttrs"
11
- @click="onClickSetValue"
15
+ @click.stop="onClickSetValue"
12
16
  >
13
17
  <template #left>
14
18
  <slot name="left" />
@@ -21,8 +25,9 @@
21
25
  :name="name"
22
26
  :type="type"
23
27
  :value="value"
24
- :disabled="disabled"
28
+ :disabled="toValue(disabled)"
25
29
  v-bind="inputAttrs"
30
+ @click.stop
26
31
  />
27
32
 
28
33
  <slot name="default" />
@@ -115,12 +120,20 @@ const type = inject("toggleType", UIService.get(defaultConfig, UToggleItem).defa
115
120
  const size = inject("toggleSize", UIService.get(defaultConfig, UToggleItem).default.size);
116
121
  const block = inject("toggleBlock", UIService.get(defaultConfig, UToggleItem).default.block);
117
122
  const variant = inject("toggleVariant", UIService.get(defaultConfig, UToggleItem).default.variant);
118
- const { selectedValue, updateSelectedValue } = inject("toggleSelectedValue", {});
123
+ const color = inject("toggleColor", UIService.get(defaultConfig, UToggleItem).default.color);
124
+ const filled = inject("toggleFilled", UIService.get(defaultConfig, UToggleItem).default.filled);
125
+ const pill = inject("togglePill", UIService.get(defaultConfig, UToggleItem).default.pill);
126
+ const square = inject("toggleSquare", UIService.get(defaultConfig, UToggleItem).default.square);
127
+ const separated = inject("toggleSeparated", false);
128
+ // eslint-disable-next-line vue/no-dupe-keys, prettier/prettier
129
+ const disabled = inject("toggleDisabled", UIService.get(defaultConfig, UToggleItem).default.disabled);
119
130
 
120
- const { buttonAttrs, inputAttrs } = useAttrs(props);
131
+ const { selectedValue, updateSelectedValue } = inject("toggleSelectedValue", {});
121
132
 
122
133
  const selectedItem = ref("");
123
134
 
135
+ const { buttonAttrs, inputAttrs } = useAttrs(props, { selectedValue, separated, variant, color });
136
+
124
137
  onMounted(() => {
125
138
  if (type.value === TYPE_RADIO) {
126
139
  selectedItem.value = selectedValue ? selectedValue.value : selectedItem.value;
@@ -1,8 +1,8 @@
1
+ import { computed } from "vue";
1
2
  import useUI from "../../composable.ui";
2
3
  import { cva } from "../../service.ui";
3
4
 
4
5
  import defaultConfig from "../configs/default.config";
5
- import { computed } from "vue";
6
6
 
7
7
  export function useAttrs(props) {
8
8
  const { config, getAttrs, setColor } = useUI(defaultConfig, () => props.config);
package/web-types.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "framework": "vue",
3
3
  "name": "vueless",
4
- "version": "0.0.145",
4
+ "version": "0.0.147",
5
5
  "contributions": {
6
6
  "html": {
7
7
  "description-markup": "markdown",
@@ -7004,7 +7004,7 @@
7004
7004
  },
7005
7005
  {
7006
7006
  "name": "variant",
7007
- "description": "Toggle variants.",
7007
+ "description": "Toggle variant.",
7008
7008
  "value": {
7009
7009
  "kind": "expression",
7010
7010
  "type": "'primary' | 'secondary' | 'thirdary'"
@@ -7034,10 +7034,37 @@
7034
7034
  "description": "Toggle size.",
7035
7035
  "value": {
7036
7036
  "kind": "expression",
7037
- "type": "'xs' | 'sm' | 'md' | 'lg'"
7037
+ "type": "'2xs' | 'xs' | 'sm' | 'md' | 'lg' | 'xl'"
7038
7038
  },
7039
7039
  "default": "md"
7040
7040
  },
7041
+ {
7042
+ "name": "label",
7043
+ "description": "Toggle label.",
7044
+ "value": {
7045
+ "kind": "expression",
7046
+ "type": "string"
7047
+ },
7048
+ "default": "\"\""
7049
+ },
7050
+ {
7051
+ "name": "description",
7052
+ "description": "Toggle description.",
7053
+ "value": {
7054
+ "kind": "expression",
7055
+ "type": "string"
7056
+ },
7057
+ "default": "\"\""
7058
+ },
7059
+ {
7060
+ "name": "labelAlign",
7061
+ "description": "Label placement.",
7062
+ "value": {
7063
+ "kind": "expression",
7064
+ "type": "'top' | 'topInside' | 'topWithDesc' | 'bottom' | 'left' | 'right'"
7065
+ },
7066
+ "default": "top"
7067
+ },
7041
7068
  {
7042
7069
  "name": "block",
7043
7070
  "description": "Make the toggle fill the width with its container.",
@@ -7056,6 +7083,60 @@
7056
7083
  },
7057
7084
  "default": "false"
7058
7085
  },
7086
+ {
7087
+ "name": "color",
7088
+ "description": "Button color.",
7089
+ "value": {
7090
+ "kind": "expression",
7091
+ "type": "'brand' | 'grayscale' | 'gray' | 'red' | 'orange' | 'amber' | 'yellow' | 'lime' | 'green' | 'emerald' | 'teal' | 'cyan' | 'sky' | 'blue' | 'indigo' | 'violet' | 'purple' | 'fuchsia' | 'pink' | 'rose' | 'white'"
7092
+ },
7093
+ "default": "brand"
7094
+ },
7095
+ {
7096
+ "name": "separated",
7097
+ "description": "Separate toggle items.",
7098
+ "value": {
7099
+ "kind": "expression",
7100
+ "type": "boolean"
7101
+ },
7102
+ "default": "false"
7103
+ },
7104
+ {
7105
+ "name": "disabled",
7106
+ "description": "Make toggle disabled.",
7107
+ "value": {
7108
+ "kind": "expression",
7109
+ "type": "boolean"
7110
+ },
7111
+ "default": "false"
7112
+ },
7113
+ {
7114
+ "name": "filled",
7115
+ "description": "Fill the background for thirdary variant.",
7116
+ "value": {
7117
+ "kind": "expression",
7118
+ "type": "boolean"
7119
+ },
7120
+ "default": "false"
7121
+ },
7122
+ {
7123
+ "name": "pill",
7124
+ "description": "Set button corners rounded.",
7125
+ "value": {
7126
+ "kind": "expression",
7127
+ "type": "boolean"
7128
+ },
7129
+ "default": "false"
7130
+ },
7131
+ {
7132
+ "name": "square",
7133
+ "description": "Set the same paddings for the button.",
7134
+ "value": {
7135
+ "kind": "expression",
7136
+ "type": "boolean"
7137
+ },
7138
+ "default": "false"
7139
+ },
7059
7140
  {
7060
7141
  "name": "dataCy",
7061
7142
  "description": "Sets data-cy attribute for automated testing.",