@volverjs/ui-vue 0.0.6-beta.5 → 0.0.6-beta.7

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 (70) hide show
  1. package/auto-imports.d.ts +9 -0
  2. package/dist/Volver.d.ts +1 -1
  3. package/dist/components/VvAccordion/index.d.ts +1 -1
  4. package/dist/components/VvButton/VvButton.es.js +25 -19
  5. package/dist/components/VvButton/VvButton.umd.js +1 -1
  6. package/dist/components/VvCheckbox/VvCheckbox.es.js +151 -98
  7. package/dist/components/VvCheckbox/VvCheckbox.umd.js +1 -1
  8. package/dist/components/VvCheckbox/VvCheckbox.vue.d.ts +37 -1
  9. package/dist/components/VvCheckbox/index.d.ts +6 -1
  10. package/dist/components/VvCheckboxGroup/VvCheckboxGroup.es.js +187 -101
  11. package/dist/components/VvCheckboxGroup/VvCheckboxGroup.umd.js +1 -1
  12. package/dist/components/VvCheckboxGroup/VvCheckboxGroup.vue.d.ts +36 -0
  13. package/dist/components/VvCheckboxGroup/index.d.ts +5 -0
  14. package/dist/components/VvCombobox/VvCombobox.es.js +236 -140
  15. package/dist/components/VvCombobox/VvCombobox.umd.js +1 -1
  16. package/dist/components/VvCombobox/VvCombobox.vue.d.ts +25 -1
  17. package/dist/components/VvDialog/VvDialog.es.js +25 -19
  18. package/dist/components/VvDialog/VvDialog.umd.js +1 -1
  19. package/dist/components/VvDropdown/VvDropdown.es.js +19 -4
  20. package/dist/components/VvDropdown/VvDropdown.umd.js +1 -1
  21. package/dist/components/VvDropdown/VvDropdown.vue.d.ts +8 -4
  22. package/dist/components/VvDropdown/index.d.ts +1 -1
  23. package/dist/components/VvIcon/VvIcon.es.js +25 -19
  24. package/dist/components/VvIcon/VvIcon.umd.js +1 -1
  25. package/dist/components/VvIcon/VvIcon.vue.d.ts +2 -2
  26. package/dist/components/VvIcon/index.d.ts +2 -2
  27. package/dist/components/VvInputText/VvInputText.es.js +160 -136
  28. package/dist/components/VvInputText/VvInputText.umd.js +1 -1
  29. package/dist/components/VvInputText/VvInputText.vue.d.ts +24 -0
  30. package/dist/components/VvRadio/VvRadio.es.js +151 -98
  31. package/dist/components/VvRadio/VvRadio.umd.js +1 -1
  32. package/dist/components/VvRadio/VvRadio.vue.d.ts +37 -1
  33. package/dist/components/VvRadio/index.d.ts +6 -1
  34. package/dist/components/VvRadioGroup/VvRadioGroup.es.js +187 -101
  35. package/dist/components/VvRadioGroup/VvRadioGroup.umd.js +1 -1
  36. package/dist/components/VvRadioGroup/VvRadioGroup.vue.d.ts +36 -0
  37. package/dist/components/VvRadioGroup/index.d.ts +5 -0
  38. package/dist/components/VvSelect/VvSelect.es.js +163 -137
  39. package/dist/components/VvSelect/VvSelect.umd.js +1 -1
  40. package/dist/components/VvSelect/VvSelect.vue.d.ts +24 -0
  41. package/dist/components/VvTextarea/VvTextarea.es.js +160 -136
  42. package/dist/components/VvTextarea/VvTextarea.umd.js +1 -1
  43. package/dist/components/VvTextarea/VvTextarea.vue.d.ts +24 -0
  44. package/dist/components/common/HintSlot.d.ts +38 -12
  45. package/dist/components/index.es.js +466 -168
  46. package/dist/components/index.umd.js +1 -1
  47. package/dist/composables/group/useInjectedGroupState.d.ts +1 -1
  48. package/dist/composables/useOptions.d.ts +2 -2
  49. package/dist/directives/index.d.ts +2 -2
  50. package/dist/icons.es.js +3 -3
  51. package/dist/icons.umd.js +1 -1
  52. package/dist/props/index.d.ts +22 -0
  53. package/package.json +33 -33
  54. package/src/assets/icons/detailed.json +1 -1
  55. package/src/assets/icons/normal.json +1 -1
  56. package/src/assets/icons/simple.json +1 -1
  57. package/src/components/VvCheckbox/VvCheckbox.vue +23 -2
  58. package/src/components/VvCheckboxGroup/VvCheckboxGroup.vue +15 -2
  59. package/src/components/VvCombobox/VvCombobox.vue +40 -16
  60. package/src/components/VvDropdown/VvDropdown.vue +20 -2
  61. package/src/components/VvIcon/VvIcon.vue +37 -34
  62. package/src/components/VvIcon/index.ts +2 -2
  63. package/src/components/VvInputText/VvInputText.vue +26 -9
  64. package/src/components/VvRadio/VvRadio.vue +23 -2
  65. package/src/components/VvRadioGroup/VvRadioGroup.vue +15 -2
  66. package/src/components/VvSelect/VvSelect.vue +26 -9
  67. package/src/components/VvTextarea/VvTextarea.vue +26 -9
  68. package/src/components/common/HintSlot.ts +129 -170
  69. package/src/composables/useOptions.ts +9 -7
  70. package/src/props/index.ts +2 -0
@@ -1,202 +1,161 @@
1
- import type { Component, ExtractPropTypes, Slots, Ref } from 'vue'
1
+ import type { ExtractPropTypes, Slots } from 'vue'
2
2
 
3
3
  /**
4
- * Merge errors from string[] to string errors separated from new line (\n)
5
- * @param {string[] | string} errors
4
+ * Merge array of string
5
+ * @param {string[] | string} items
6
6
  * @returns {string}
7
7
  */
8
- function joinLines(errors: string[] | string | unknown[] | undefined) {
9
- if (Array.isArray(errors)) {
10
- return errors.filter((e) => isString(e)).join(' ')
8
+ function joinLines(items: string[] | string | unknown[] | undefined) {
9
+ if (Array.isArray(items)) {
10
+ return items.filter((item) => isString(item)).join(' ')
11
11
  }
12
- return errors
12
+ return items
13
13
  }
14
14
 
15
- interface HintSlotProps {
16
- hintLabel: {
17
- type: StringConstructor
18
- default: ''
19
- required: true
20
- }
21
- modelValue: null
22
- valid: BooleanConstructor
23
- validLabel: (StringConstructor | ArrayConstructor)[]
24
- invalid: BooleanConstructor
25
- invalidLabel: (StringConstructor | ArrayConstructor)[]
26
- }
27
-
28
- interface HintSlotPropsWithLoading extends HintSlotProps {
29
- loading: BooleanConstructor
30
- loadingLabel: StringConstructor
31
- }
15
+ export type HintSlotProps = Readonly<
16
+ ExtractPropTypes<{
17
+ hintLabel: {
18
+ type: StringConstructor
19
+ default: ''
20
+ required: true
21
+ }
22
+ modelValue: null
23
+ valid: BooleanConstructor
24
+ validLabel: (StringConstructor | ArrayConstructor)[]
25
+ invalid: BooleanConstructor
26
+ invalidLabel: (StringConstructor | ArrayConstructor)[]
27
+ loading: BooleanConstructor
28
+ loadingLabel: StringConstructor
29
+ }>
30
+ >
32
31
 
33
32
  /**
34
33
  * Return a vue component (HintSlot) to render and manage hint, errors, valid, loading state and messages
35
- * @param {Readonly<ExtractPropTypes<HintSlotProps | HintSlotPropsWithLoading>>} parentProps vue props
34
+ * @param {HintSlotProps} parentProps vue props
36
35
  * @param {Slots} parentSlots vue slots
37
36
  * @returns {Component} vue component
38
37
  */
39
- export function HintSlotFactory(
40
- parentProps: Readonly<
41
- ExtractPropTypes<HintSlotProps | HintSlotPropsWithLoading>
42
- >,
43
- parentSlots: Slots,
44
- ): {
45
- HintSlot: Component
46
- hasHint: Ref<boolean>
47
- hasInvalid: Ref<boolean>
48
- hasValid: Ref<boolean>
49
- hasLoading: Ref<boolean>
50
- } {
51
- // slots
52
- const {
53
- invalid: invalidSlot,
54
- valid: validSlot,
55
- hint: hintSlot,
56
- loading: loadingSlot,
57
- } = parentSlots
58
-
59
- // props
60
- const {
61
- hintLabel,
62
- modelValue,
63
- valid,
64
- validLabel,
65
- invalid,
66
- invalidLabel,
67
- ...otherProps
68
- } = toRefs(parentProps)
69
-
70
- const loading = resolveFieldData(otherProps, 'loading') as
71
- | Ref<boolean>
72
- | undefined
73
- const loadingLabel = resolveFieldData(otherProps, 'loadingLabel') as
74
- | Ref<string>
75
- | undefined
76
-
77
- const hasInvalid = computed(() => {
78
- if (!invalid.value) {
79
- return false
80
- }
81
- if (invalid.value && invalidSlot) {
82
- return true
83
- }
84
- if (
85
- invalidLabel?.value &&
86
- Array.isArray(invalidLabel.value) &&
87
- invalidLabel.value.length > 0
88
- ) {
89
- return true
90
- }
91
- if (invalidLabel?.value && !isEmpty(invalidLabel)) {
92
- return true
93
- }
94
- return false
95
- })
96
-
97
- const hasHint = computed(
98
- () => !!((hintLabel && hintLabel.value) || hintSlot),
38
+ export function HintSlotFactory(props: HintSlotProps, slots: Slots) {
39
+ // label
40
+ const invalidLabel = computed(() => joinLines(props.invalidLabel))
41
+ const validLabel = computed(() => joinLines(props.validLabel))
42
+ const loadingLabel = computed(() => props.loadingLabel)
43
+ const hintLabel = computed(() => props.hintLabel)
44
+
45
+ // type
46
+ const hasLoadingLabelOrSlot = computed(() =>
47
+ Boolean(props.loading && (slots.loading || loadingLabel.value)),
99
48
  )
100
-
101
- const hasValid = computed(
102
- () => !!((validLabel && validLabel.value) || validSlot),
49
+ const hasInvalidLabelOrSlot = computed(
50
+ () =>
51
+ !hasLoadingLabelOrSlot.value &&
52
+ Boolean(props.invalid && (slots.invalid || invalidLabel.value)),
103
53
  )
104
-
105
- const hasLoading = computed(
54
+ const hasValidLabelOrSlot = computed(
106
55
  () =>
107
- !!(
108
- (loading?.value && loadingSlot) ||
109
- (loading?.value && loadingLabel?.value)
110
- ),
56
+ !hasLoadingLabelOrSlot.value &&
57
+ !hasInvalidLabelOrSlot.value &&
58
+ Boolean(props.valid && (slots.valid || validLabel.value)),
59
+ )
60
+ const hasHintLabelOrSlot = computed(
61
+ () =>
62
+ !hasLoadingLabelOrSlot.value &&
63
+ !hasInvalidLabelOrSlot.value &&
64
+ !hasValidLabelOrSlot.value &&
65
+ Boolean(slots.hint || hintLabel.value),
111
66
  )
112
-
113
67
  const isVisible = computed(
114
68
  () =>
115
- hasHint.value ||
116
- hasValid.value ||
117
- hasInvalid.value ||
118
- hasLoading.value,
69
+ hasInvalidLabelOrSlot.value ||
70
+ hasValidLabelOrSlot.value ||
71
+ hasLoadingLabelOrSlot.value ||
72
+ hasHintLabelOrSlot.value,
119
73
  )
120
-
121
- return {
122
- hasInvalid,
123
- hasHint,
124
- hasValid,
125
- hasLoading,
126
- HintSlot: {
127
- name: 'HintSlot',
128
- props: {
129
- params: {
130
- type: Object,
131
- default: () => ({}),
132
- },
74
+ const hintSlotScope = computed(() => ({
75
+ modelValue: props.modelValue,
76
+ valid: props.valid,
77
+ invalid: props.invalid,
78
+ loading: props.loading,
79
+ }))
80
+ // component
81
+ const HintSlot = defineComponent({
82
+ name: 'HintSlot',
83
+ props: {
84
+ tag: {
85
+ type: String,
86
+ default: 'small',
133
87
  },
134
- setup(props) {
135
- const hintContent = computed(() => {
136
- const slotProps = toReactive({
137
- hintLabel,
138
- modelValue,
139
- valid,
140
- validLabel,
141
- invalid,
142
- invalidLabel,
143
- loading,
144
- loadingLabel,
145
- ...props.params,
146
- })
147
-
148
- if (invalid?.value) {
149
- return (
150
- invalidSlot?.(slotProps) ||
151
- joinLines(invalidLabel?.value) ||
152
- hintLabel?.value
153
- )
154
- }
155
-
156
- if (valid?.value)
157
- return (
158
- validSlot?.(slotProps) ||
159
- joinLines(validLabel?.value) ||
160
- hintLabel?.value
161
- )
162
-
163
- if (loading?.value)
164
- return (
165
- loadingSlot?.(slotProps) ||
166
- joinLines(loadingLabel?.value) ||
167
- hintLabel?.value
168
- )
169
-
170
- return (
171
- hintSlot?.(slotProps) ||
172
- joinLines(hintLabel?.value) ||
173
- hintLabel?.value
88
+ },
89
+ setup() {
90
+ return {
91
+ isVisible,
92
+ invalidLabel,
93
+ validLabel,
94
+ loadingLabel,
95
+ hintLabel,
96
+ hasInvalidLabelOrSlot,
97
+ hasValidLabelOrSlot,
98
+ hasLoadingLabelOrSlot,
99
+ hasHintLabelOrSlot,
100
+ }
101
+ },
102
+ render() {
103
+ if (this.isVisible) {
104
+ let role
105
+ if (this.hasInvalidLabelOrSlot) {
106
+ role = 'alert'
107
+ }
108
+ if (this.hasValidLabelOrSlot) {
109
+ role = 'status'
110
+ }
111
+ if (this.hasLoadingLabelOrSlot) {
112
+ return h(
113
+ this.tag,
114
+ {
115
+ role,
116
+ },
117
+ this.$slots.loading?.() ?? this.loadingLabel,
174
118
  )
175
- })
176
-
177
- return {
178
- isVisible,
179
- hasInvalid,
180
- hasValid,
181
- hintContent,
182
119
  }
183
- },
184
- render() {
185
- if (this.isVisible) {
120
+ if (this.hasInvalidLabelOrSlot) {
186
121
  return h(
187
- 'small',
122
+ this.tag,
188
123
  {
189
- role: this.hasInvalid
190
- ? 'alert'
191
- : this.hasValid
192
- ? 'status'
193
- : undefined,
124
+ role,
194
125
  },
195
- this.hintContent,
126
+ this.$slots.invalid?.() ??
127
+ this.$slots.invalid ??
128
+ this.invalidLabel,
196
129
  )
197
130
  }
198
- },
131
+ if (this.hasValidLabelOrSlot) {
132
+ return h(
133
+ this.tag,
134
+ {
135
+ role,
136
+ },
137
+ this.$slots.valid?.() ?? this.validLabel,
138
+ )
139
+ }
140
+ return h(
141
+ this.tag,
142
+ {
143
+ role,
144
+ },
145
+ this.$slots.hint?.() ?? this.$slots.hint ?? this.hintLabel,
146
+ )
147
+ }
148
+ return null
199
149
  },
150
+ })
151
+
152
+ return {
153
+ hasInvalidLabelOrSlot,
154
+ hasHintLabelOrSlot,
155
+ hasValidLabelOrSlot,
156
+ hasLoadingLabelOrSlot,
157
+ hintSlotScope,
158
+ HintSlot,
200
159
  }
201
160
  }
202
161
 
@@ -5,12 +5,14 @@ export function useOptions(props: any) {
5
5
  const { options, labelKey, valueKey, disabledKey } = toRefs(props)
6
6
 
7
7
  // eslint-disable-next-line
8
- const getOptionLabel = (option: string | Option) => {
8
+ const getOptionLabel = (option: string | Option): string => {
9
9
  if (typeof option !== 'object' && option !== null) return option
10
10
 
11
- return typeof labelKey.value === 'function'
12
- ? labelKey.value(option)
13
- : option[labelKey.value]
11
+ return String(
12
+ typeof labelKey.value === 'function'
13
+ ? labelKey.value(option)
14
+ : option[labelKey.value],
15
+ )
14
16
  }
15
17
 
16
18
  const getOptionValue = (option: string | Option) => {
@@ -21,7 +23,7 @@ export function useOptions(props: any) {
21
23
  : option[valueKey.value]
22
24
  }
23
25
 
24
- const getOptionDisabled = (option: string | Option) => {
26
+ const getOptionDisabled = (option: string | Option): boolean => {
25
27
  if (typeof option !== 'object' && option !== null) return false
26
28
 
27
29
  return typeof disabledKey.value === 'function'
@@ -30,7 +32,7 @@ export function useOptions(props: any) {
30
32
  }
31
33
 
32
34
  const getOptionGrouped = (option: string | Option) => {
33
- if (typeof option !== 'object' && option !== null) return []
35
+ if (typeof option !== 'object' && option !== null) return []
34
36
  return option.options || []
35
37
  }
36
38
 
@@ -39,6 +41,6 @@ export function useOptions(props: any) {
39
41
  getOptionLabel,
40
42
  getOptionValue,
41
43
  getOptionDisabled,
42
- getOptionGrouped
44
+ getOptionGrouped,
43
45
  }
44
46
  }
@@ -406,6 +406,7 @@ export const CheckboxRadioProps = {
406
406
  ...ReadonlyProps,
407
407
  ...ModifiersProps,
408
408
  ...LabelProps,
409
+ ...LoadingProps,
409
410
  /**
410
411
  * Input value
411
412
  * @see https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#value
@@ -426,6 +427,7 @@ export const CheckboxRadioGroupProps = {
426
427
  ...ReadonlyProps,
427
428
  ...ModifiersProps,
428
429
  ...LabelProps,
430
+ ...LoadingProps,
429
431
  /**
430
432
  * Input value
431
433
  */