vueless 0.0.364 → 0.0.366
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/composables/useUI.js +90 -3
- package/package.json +1 -1
- package/ui.button/useAttrs.js +8 -29
- package/ui.dropdown-button/config.js +9 -1
- package/ui.dropdown-button/constants.js +0 -5
- package/ui.dropdown-button/useAttrs.js +12 -34
- package/ui.dropdown-list/UDropdownList.vue +10 -2
- package/web-types.json +1 -1
package/composables/useUI.js
CHANGED
|
@@ -8,9 +8,10 @@ import {
|
|
|
8
8
|
Comment,
|
|
9
9
|
Text,
|
|
10
10
|
Fragment,
|
|
11
|
+
computed,
|
|
11
12
|
} from "vue";
|
|
12
13
|
|
|
13
|
-
import { cx, setColor, getColor, vuelessConfig } from "../utils/utilUI.js";
|
|
14
|
+
import { cx, cva, setColor, getColor, vuelessConfig } from "../utils/utilUI.js";
|
|
14
15
|
|
|
15
16
|
import { cloneDeep, isCSR } from "../utils/utilHelper.js";
|
|
16
17
|
import {
|
|
@@ -53,6 +54,90 @@ export default function useUI(defaultConfig = {}, propsConfigGetter = null, topL
|
|
|
53
54
|
config.value = mergeClassesIntoConfig(mergedConfig, topLevelClassKey || firstClassKey, attrs);
|
|
54
55
|
});
|
|
55
56
|
|
|
57
|
+
/**
|
|
58
|
+
* Get classes by given key (including CVA if config set).
|
|
59
|
+
* @param {string} key
|
|
60
|
+
* @param {Object} mutatedProps
|
|
61
|
+
* @returns {ComputedRef | String}
|
|
62
|
+
*/
|
|
63
|
+
function getClasses(key, mutatedProps = {}) {
|
|
64
|
+
return computed(() => {
|
|
65
|
+
let value = config.value[key];
|
|
66
|
+
|
|
67
|
+
if (isCVA(value)) {
|
|
68
|
+
value = cva(value)({
|
|
69
|
+
...props,
|
|
70
|
+
...toValue(mutatedProps),
|
|
71
|
+
color: props.color ? getColor(props.color) : null,
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
return props.color ? setColor(value, props.color) : value;
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Get an object where:
|
|
81
|
+
* – key: extendingKey
|
|
82
|
+
* – value: reactive string of extendingKey classes.
|
|
83
|
+
* @param {Array} extendingKeys
|
|
84
|
+
* @param {Object} mutatedProps
|
|
85
|
+
* @returns {Object}
|
|
86
|
+
*/
|
|
87
|
+
function getExtendingKeysClasses(extendingKeys, mutatedProps = {}) {
|
|
88
|
+
const extendingClasses = {};
|
|
89
|
+
|
|
90
|
+
for (const key of extendingKeys) {
|
|
91
|
+
extendingClasses[key] = getClasses(key, mutatedProps);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
return extendingClasses;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Get an object where:
|
|
99
|
+
* – key: elementKey
|
|
100
|
+
* – value: reactive object of string element attributes (with classes).
|
|
101
|
+
* @param mutatedProps
|
|
102
|
+
* @param extendingKeys
|
|
103
|
+
* @param keysToExtendConfig
|
|
104
|
+
* @returns {Object}
|
|
105
|
+
*/
|
|
106
|
+
function getKeysAttrs(mutatedProps, extendingKeys = [], keysToExtendConfig = {}) {
|
|
107
|
+
const keysToExtend = Object.keys(keysToExtendConfig);
|
|
108
|
+
const keysAttrs = {};
|
|
109
|
+
|
|
110
|
+
for (const key in defaultConfig) {
|
|
111
|
+
if (isSystemKey(key) || extendingKeys.includes(key)) continue;
|
|
112
|
+
|
|
113
|
+
keysAttrs[`${key}Attrs`] = getAttrs(key, {
|
|
114
|
+
classes: getClasses(key, mutatedProps),
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
if (keysToExtend.includes(key)) {
|
|
118
|
+
const { general, extend } = keysToExtendConfig[key];
|
|
119
|
+
const keyAttrs = keysAttrs[`${key}Attrs`];
|
|
120
|
+
|
|
121
|
+
keysAttrs[`${key}Attrs`] = computed(() => ({
|
|
122
|
+
...keyAttrs.value,
|
|
123
|
+
class: cx([
|
|
124
|
+
...(Array.isArray(general) ? toValue(general) : [toValue(general)]),
|
|
125
|
+
keyAttrs.value.class,
|
|
126
|
+
...(Array.isArray(extend) ? toValue(extend) : [toValue(extend)]),
|
|
127
|
+
]),
|
|
128
|
+
}));
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
return keysAttrs;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* Get an element attributes for a given key.
|
|
137
|
+
* @param {String} configKey
|
|
138
|
+
* @param {Object} options with classes
|
|
139
|
+
* @returns {Object} element attributes
|
|
140
|
+
*/
|
|
56
141
|
function getAttrs(configKey, options) {
|
|
57
142
|
const nestedComponent = getNestedComponent(defaultConfig[configKey]);
|
|
58
143
|
|
|
@@ -105,9 +190,11 @@ export default function useUI(defaultConfig = {}, propsConfigGetter = null, topL
|
|
|
105
190
|
|
|
106
191
|
return {
|
|
107
192
|
config,
|
|
108
|
-
getAttrs,
|
|
109
|
-
getColor,
|
|
110
193
|
setColor,
|
|
194
|
+
getColor,
|
|
195
|
+
getAttrs,
|
|
196
|
+
getKeysAttrs,
|
|
197
|
+
getExtendingKeysClasses,
|
|
111
198
|
isCVA,
|
|
112
199
|
isSystemKey,
|
|
113
200
|
hasSlotContent,
|
package/package.json
CHANGED
package/ui.button/useAttrs.js
CHANGED
|
@@ -1,43 +1,22 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import { useSlots, computed } from "vue";
|
|
3
2
|
import useUI from "../composables/useUI.js";
|
|
4
|
-
import { cva } from "../utils/utilUI.js";
|
|
5
3
|
|
|
6
4
|
import defaultConfig from "./config.js";
|
|
7
5
|
|
|
8
6
|
export default function useAttrs(props) {
|
|
7
|
+
const { config, getKeysAttrs, hasSlotContent } = useUI(defaultConfig, () => props.config);
|
|
9
8
|
const slots = useSlots();
|
|
10
|
-
const { config, getAttrs, getColor, setColor, hasSlotContent, isSystemKey, isCVA } = useUI(
|
|
11
|
-
defaultConfig,
|
|
12
|
-
() => props.config,
|
|
13
|
-
);
|
|
14
|
-
const attrs = {};
|
|
15
|
-
|
|
16
|
-
for (const key in defaultConfig) {
|
|
17
|
-
if (isSystemKey(key)) continue;
|
|
18
|
-
|
|
19
|
-
const classes = computed(() => {
|
|
20
|
-
let value = config.value[key];
|
|
21
|
-
|
|
22
|
-
if (isCVA(value)) {
|
|
23
|
-
value = cva(value)({
|
|
24
|
-
...props,
|
|
25
|
-
color: getColor(props.color),
|
|
26
|
-
square: props.loading || props.square,
|
|
27
|
-
leftIcon: Boolean(props.leftIcon) || hasSlotContent(slots["left"]),
|
|
28
|
-
rightIcon: Boolean(props.rightIcon) || hasSlotContent(slots["right"]),
|
|
29
|
-
});
|
|
30
|
-
}
|
|
31
9
|
|
|
32
|
-
|
|
33
|
-
|
|
10
|
+
const mutatedProps = computed(() => ({
|
|
11
|
+
leftIcon: Boolean(props.leftIcon) || hasSlotContent(slots["left"]),
|
|
12
|
+
rightIcon: Boolean(props.rightIcon) || hasSlotContent(slots["right"]),
|
|
13
|
+
}));
|
|
34
14
|
|
|
35
|
-
|
|
36
|
-
}
|
|
15
|
+
const keysAttrs = getKeysAttrs(mutatedProps);
|
|
37
16
|
|
|
38
17
|
return {
|
|
39
|
-
...attrs,
|
|
40
18
|
config,
|
|
19
|
+
...keysAttrs,
|
|
41
20
|
hasSlotContent,
|
|
42
21
|
};
|
|
43
22
|
}
|
|
@@ -1,7 +1,15 @@
|
|
|
1
1
|
export default /*tw*/ {
|
|
2
2
|
wrapper: "relative inline-block",
|
|
3
3
|
dropdownButton: "{UButton}",
|
|
4
|
-
dropdownButtonActive:
|
|
4
|
+
dropdownButtonActive: {
|
|
5
|
+
base: "group ring-dynamic ring-offset-dynamic ring-{color}-700/15",
|
|
6
|
+
variants: {
|
|
7
|
+
color: {
|
|
8
|
+
grayscale: "ring-gray-700/15",
|
|
9
|
+
white: "ring-gray-700/15",
|
|
10
|
+
},
|
|
11
|
+
},
|
|
12
|
+
},
|
|
5
13
|
dropdownIcon: "{UIcon} transition duration-300 group-[]:rotate-180",
|
|
6
14
|
dropdownList: {
|
|
7
15
|
base: "{UDropdownList} w-fit",
|
|
@@ -1,50 +1,28 @@
|
|
|
1
|
+
import { computed } from "vue";
|
|
1
2
|
import useUI from "../composables/useUI.js";
|
|
2
|
-
import { cva, cx } from "../utils/utilUI.js";
|
|
3
3
|
|
|
4
4
|
import defaultConfig from "./config.js";
|
|
5
|
-
import { computed } from "vue";
|
|
6
5
|
|
|
7
6
|
export default function useAttrs(props, { isShownOptions }) {
|
|
8
|
-
const { config,
|
|
7
|
+
const { config, getKeysAttrs, hasSlotContent, getExtendingKeysClasses } = useUI(
|
|
9
8
|
defaultConfig,
|
|
10
9
|
() => props.config,
|
|
11
10
|
);
|
|
12
|
-
const attrs = {};
|
|
13
|
-
|
|
14
|
-
for (const key in defaultConfig) {
|
|
15
|
-
if (isSystemKey(key)) continue;
|
|
16
|
-
|
|
17
|
-
const classes = computed(() => {
|
|
18
|
-
let value = config.value[key];
|
|
19
|
-
|
|
20
|
-
if (isCVA(value)) {
|
|
21
|
-
value = cva(value)({
|
|
22
|
-
...props,
|
|
23
|
-
color: getColor(props.color),
|
|
24
|
-
});
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
return setColor(value, props.color);
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
attrs[`${key}Attrs`] = getAttrs(key, { classes });
|
|
31
11
|
|
|
32
|
-
|
|
33
|
-
|
|
12
|
+
const extendingKeys = ["dropdownButtonActive"];
|
|
13
|
+
const extendingKeysClasses = getExtendingKeysClasses(extendingKeys);
|
|
34
14
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
}
|
|
43
|
-
}
|
|
15
|
+
const keysAttrs = getKeysAttrs({}, extendingKeys, {
|
|
16
|
+
dropdownButton: {
|
|
17
|
+
extend: computed(() => [
|
|
18
|
+
isShownOptions.value && extendingKeysClasses.dropdownButtonActive.value,
|
|
19
|
+
]),
|
|
20
|
+
},
|
|
21
|
+
});
|
|
44
22
|
|
|
45
23
|
return {
|
|
46
|
-
...attrs,
|
|
47
24
|
config,
|
|
25
|
+
...keysAttrs,
|
|
48
26
|
hasSlotContent,
|
|
49
27
|
};
|
|
50
28
|
}
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
v-if="!(option && (option.groupLabel || option.isSubGroup)) && !option.isHidden"
|
|
24
24
|
v-bind="optionAttrs"
|
|
25
25
|
:class="optionHighlight(index, option)"
|
|
26
|
-
@click="select(option), onClickOption(option)
|
|
26
|
+
@click="select(option), onClickOption(option)"
|
|
27
27
|
@mouseenter.self="pointerSet(index)"
|
|
28
28
|
>
|
|
29
29
|
<!--
|
|
@@ -307,7 +307,15 @@ function addPointerElement({ key } = "Enter") {
|
|
|
307
307
|
pointerReset();
|
|
308
308
|
}
|
|
309
309
|
|
|
310
|
-
function onClickOption(
|
|
310
|
+
function onClickOption(rawOption) {
|
|
311
|
+
const option = { ...rawOption };
|
|
312
|
+
|
|
313
|
+
delete option.onClick;
|
|
314
|
+
|
|
315
|
+
if (typeof rawOption.onClick === "function") {
|
|
316
|
+
rawOption.onClick(option);
|
|
317
|
+
}
|
|
318
|
+
|
|
311
319
|
emit("clickOption", option);
|
|
312
320
|
}
|
|
313
321
|
</script>
|