vueless 0.0.192 → 0.0.194

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.
@@ -1,43 +1,52 @@
1
1
  <template>
2
- <div :data-cy="dataCy" v-bind="ratingAttrs">
3
- <ULabel
4
- :label="label"
5
- :error="error"
6
- :size="size"
7
- :description="description"
8
- :align="labelAlign"
9
- v-bind="labelAttrs"
10
- >
11
- <div v-bind="wrapperAttrs">
12
- <div v-if="!noCounter" v-bind="counterAttrs">
13
- <!-- @slot Use it to add counter. -->
14
- <slot name="counter">
15
- {{ ratingCounter }}
16
- </slot>
17
- </div>
18
-
19
- <div v-bind="iconWrapperAttrs">
20
- <UIcon
21
- v-for="star in starsNumber"
22
- :key="star"
23
- internal
24
- color="yellow"
25
- :size="iconSize"
26
- :interactive="selectable"
27
- :data-cy="`${dataCy}-rating-star-${star}`"
28
- :name="star <= ratingCounter ? config.selectedIconName : config.unselectedIconName"
29
- v-bind="iconAttrs"
30
- @mouseover="onMouseHover(star)"
31
- @mouseleave="onMouseHover()"
32
- @click="onClickStar(star)"
33
- />
34
- </div>
35
-
36
- <!-- @slot Use it to add something right. -->
37
- <slot name="right" />
2
+ <ULabel
3
+ :label="label"
4
+ :error="error"
5
+ :size="size"
6
+ :align="labelAlign"
7
+ :description="description"
8
+ v-bind="labelAttrs"
9
+ :data-cy="dataCy"
10
+ >
11
+ <div v-bind="wrapperAttrs">
12
+ <div v-if="counter || hasSlotContent($slots['counter'])" v-bind="counterAttrs">
13
+ <!--
14
+ @slot Use it to customise counter.
15
+ @binding {number} counter
16
+ @binding {number} total
17
+ -->
18
+ <slot name="counter" :counter="counterValue" :total="total">
19
+ {{ counterValue }}
20
+ </slot>
38
21
  </div>
39
- </ULabel>
40
- </div>
22
+
23
+ <div v-bind="starsAttrs">
24
+ <UIcon
25
+ v-for="star in stars"
26
+ :key="star"
27
+ internal
28
+ color="yellow"
29
+ :size="iconSize"
30
+ :interactive="selectable"
31
+ :name="star <= counterValue ? config.selectedIconName : config.unselectedIconName"
32
+ v-bind="starAttrs"
33
+ :data-cy="`${dataCy}-rating-star-${star}`"
34
+ @click="onClickStar(star)"
35
+ @mouseleave="onMouseHover()"
36
+ @mouseover="onMouseHover(star)"
37
+ />
38
+ </div>
39
+
40
+ <div v-if="total || hasSlotContent($slots['total'])" v-bind="totalAttrs">
41
+ <!--
42
+ @slot Use it to customise total.
43
+ @binding {number} counter
44
+ @binding {number} total
45
+ -->
46
+ <slot name="total" :counter="counter" :total="total">({{ total }})</slot>
47
+ </div>
48
+ </div>
49
+ </ULabel>
41
50
  </template>
42
51
 
43
52
  <script setup>
@@ -56,31 +65,23 @@ defineOptions({ name: "UInputRating", inheritAttrs: false });
56
65
 
57
66
  const props = defineProps({
58
67
  /**
59
- * Set input rating label.
60
- */
61
- label: {
62
- type: String,
63
- default: "",
64
- },
65
-
66
- /**
67
- * Set input rating value.
68
+ * Rating value.
68
69
  */
69
70
  modelValue: {
70
71
  type: Number,
71
- default: UIService.get(defaultConfig, UInputRating).default.modelValue,
72
+ default: 0,
72
73
  },
73
74
 
74
75
  /**
75
- * Set the number of stars.
76
+ * Rating number of stars.
76
77
  */
77
- starsNumber: {
78
+ stars: {
78
79
  type: Number,
79
- default: UIService.get(defaultConfig, UInputRating).default.starsNumber,
80
+ default: UIService.get(defaultConfig, UInputRating).default.stars,
80
81
  },
81
82
 
82
83
  /**
83
- * Set component size.
84
+ * Rating size.
84
85
  * @values sm, md, lg
85
86
  */
86
87
  size: {
@@ -89,15 +90,15 @@ const props = defineProps({
89
90
  },
90
91
 
91
92
  /**
92
- * Make stars selectable.
93
+ * Rating label.
93
94
  */
94
- selectable: {
95
- type: Boolean,
96
- default: UIService.get(defaultConfig, UInputRating).default.selectable,
95
+ label: {
96
+ type: String,
97
+ default: "",
97
98
  },
98
99
 
99
100
  /**
100
- * Set label placement related from the default slot.
101
+ * Rating label placement.
101
102
  * @values top, topInside, topWithDesc, bottom, left, right
102
103
  */
103
104
  labelAlign: {
@@ -106,7 +107,7 @@ const props = defineProps({
106
107
  },
107
108
 
108
109
  /**
109
- * Set error message.
110
+ * Rating error message.
110
111
  */
111
112
  error: {
112
113
  type: String,
@@ -114,7 +115,7 @@ const props = defineProps({
114
115
  },
115
116
 
116
117
  /**
117
- * Set description text.
118
+ * Rating description.
118
119
  */
119
120
  description: {
120
121
  type: String,
@@ -122,15 +123,31 @@ const props = defineProps({
122
123
  },
123
124
 
124
125
  /**
125
- * Hide / show counter.
126
+ * Rating total.
127
+ */
128
+ total: {
129
+ type: Number,
130
+ default: 0,
131
+ },
132
+
133
+ /**
134
+ * Show rating counter.
126
135
  */
127
- noCounter: {
136
+ counter: {
128
137
  type: Boolean,
129
- default: UIService.get(defaultConfig, UInputRating).default.noCounter,
138
+ default: UIService.get(defaultConfig, UInputRating).default.counter,
130
139
  },
131
140
 
132
141
  /**
133
- * Sets component ui config object.
142
+ * Make rating selectable.
143
+ */
144
+ selectable: {
145
+ type: Boolean,
146
+ default: UIService.get(defaultConfig, UInputRating).default.selectable,
147
+ },
148
+
149
+ /**
150
+ * Component ui config object.
134
151
  */
135
152
  config: {
136
153
  type: Object,
@@ -138,7 +155,7 @@ const props = defineProps({
138
155
  },
139
156
 
140
157
  /**
141
- * Sets data-cy attribute for automated testing.
158
+ * Data-cy attribute for automated testing.
142
159
  */
143
160
  dataCy: {
144
161
  type: String,
@@ -146,12 +163,26 @@ const props = defineProps({
146
163
  },
147
164
  });
148
165
 
149
- const emit = defineEmits(["update:modelValue"]);
166
+ const emit = defineEmits([
167
+ /**
168
+ * Triggers when the rating is changes.
169
+ * @property {number} modelValue
170
+ */
171
+ "update:modelValue",
172
+ ]);
150
173
 
151
174
  const hovered = ref(null);
152
175
 
153
- const { config, counterAttrs, ratingAttrs, wrapperAttrs, iconAttrs, iconWrapperAttrs, labelAttrs } =
154
- useAttrs(props);
176
+ const {
177
+ config,
178
+ labelAttrs,
179
+ wrapperAttrs,
180
+ counterAttrs,
181
+ totalAttrs,
182
+ starsAttrs,
183
+ starAttrs,
184
+ hasSlotContent,
185
+ } = useAttrs(props);
155
186
 
156
187
  const iconSize = computed(() => {
157
188
  const sizes = {
@@ -163,7 +194,7 @@ const iconSize = computed(() => {
163
194
  return sizes[props.size];
164
195
  });
165
196
 
166
- const ratingCounter = computed(() => {
197
+ const counterValue = computed(() => {
167
198
  return hovered.value || props.modelValue;
168
199
  });
169
200
 
@@ -30,7 +30,7 @@
30
30
  </template>
31
31
 
32
32
  <script setup>
33
- import { computed, inject, onMounted, ref, watchEffect } from "vue";
33
+ import { computed, inject, onMounted, ref, watchEffect, toValue } from "vue";
34
34
 
35
35
  import ULabel from "../ui.form-label";
36
36
  import UIService, { getRandomId } from "../service.ui";
@@ -162,8 +162,8 @@ const emit = defineEmits(["update:modelValue"]);
162
162
 
163
163
  const localValue = ref("");
164
164
  const radioName = ref(null);
165
- const radioColor = ref(getRadioGroupColor ? getRadioGroupColor() : props.color);
166
- const radioSize = ref(getRadioGroupSize ? getRadioGroupSize() : props.size);
165
+ const radioColor = ref(toValue(getRadioGroupColor) || props.color);
166
+ const radioSize = ref(toValue(getRadioGroupSize) || props.size);
167
167
 
168
168
  const isChecked = computed(() => {
169
169
  const currentValue = props.modelValue ?? localValue.value;
@@ -182,14 +182,13 @@ const radioValue = computed(() => {
182
182
  });
183
183
 
184
184
  onMounted(() => {
185
- radioName.value = props.name || getRadioGroupName();
185
+ radioName.value = props.name || toValue(getRadioGroupName);
186
186
  });
187
187
 
188
- watchEffect(() => (radioColor.value = getRadioGroupColor ? getRadioGroupColor() : props.color));
189
- watchEffect(() => (radioSize.value = getRadioGroupSize ? getRadioGroupSize() : props.size));
188
+ watchEffect(() => (radioColor.value = toValue(getRadioGroupColor) || props.color));
189
+ watchEffect(() => (radioSize.value = toValue(getRadioGroupSize) || props.size));
190
190
  watchEffect(() => {
191
- localValue.value = getRadioGroupSelectedItem ? getRadioGroupSelectedItem() : null;
192
-
191
+ localValue.value = toValue(getRadioGroupSelectedItem) || null;
193
192
  emit("update:modelValue", props.value);
194
193
  });
195
194
 
@@ -21,20 +21,19 @@ export default function useAttrs(props, { isTop, isOpen, selectedLabel: selected
21
21
  for (const key in defaultConfig) {
22
22
  if (isSystemKey(key)) continue;
23
23
 
24
- let classes = "";
25
- let value = config.value[key];
24
+ const classes = computed(() => {
25
+ const value = config.value[key];
26
26
 
27
- if (value.variants || value.compoundVariants) {
28
- const getCVA = cva(value);
29
-
30
- classes = computed(() =>
31
- getCVA({
27
+ if (value.variants || value.compoundVariants) {
28
+ return cva(value)({
32
29
  ...props,
33
30
  error: Boolean(props.error),
34
31
  label: Boolean(props.label),
35
- }),
36
- );
37
- }
32
+ });
33
+ }
34
+
35
+ return "";
36
+ });
38
37
 
39
38
  attrs[`${key}Attrs`] = getAttrs(key, { classes });
40
39
 
@@ -8,7 +8,7 @@
8
8
  </template>
9
9
 
10
10
  <script setup>
11
- import { computed, inject } from "vue";
11
+ import { computed, inject, toValue } from "vue";
12
12
 
13
13
  import UIService from "../service.ui";
14
14
 
@@ -68,11 +68,11 @@ const props = defineProps({
68
68
  });
69
69
 
70
70
  const selected = computed(() => {
71
- return getUTabsSelectedItem && getUTabsSelectedItem() === props.value && !props.disabled;
71
+ return toValue(getUTabsSelectedItem) === props.value && !props.disabled;
72
72
  });
73
73
 
74
74
  const size = computed(() => {
75
- return getUTabsSize ? getUTabsSize() : UIService.get(defaultConfig, UTab).default.size;
75
+ return toValue(getUTabsSize) || UIService.get(defaultConfig, UTab).default.size;
76
76
  });
77
77
 
78
78
  const { wrapperAttrs } = useAttrs(props, { selected, size });