vueless 0.0.365 → 0.0.367

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.
@@ -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 { base, extend } = keysToExtendConfig[key];
119
+ const keyAttrs = keysAttrs[`${key}Attrs`];
120
+
121
+ keysAttrs[`${key}Attrs`] = computed(() => ({
122
+ ...keyAttrs.value,
123
+ class: cx([
124
+ ...(Array.isArray(base) ? toValue(base) : [toValue(base)]),
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vueless",
3
- "version": "0.0.365",
3
+ "version": "0.0.367",
4
4
  "license": "MIT",
5
5
  "description": "Vue Styleless Component Framework.",
6
6
  "homepage": "https://vueless.com",
@@ -1,43 +1,22 @@
1
- import { computed, useSlots } from "vue";
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
- return setColor(value, props.color);
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
- attrs[`${key}Attrs`] = getAttrs(key, { classes });
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: "group ring-dynamic ring-offset-dynamic ring-{color}-700/15",
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",
@@ -7,8 +7,3 @@ export const UDropdownButton = "UDropdownButton";
7
7
  export const BUTTON_VARIANT = {
8
8
  primary: "primary",
9
9
  };
10
-
11
- export const LIST_POSITION = {
12
- bottom: "bottom",
13
- right: "right",
14
- };
@@ -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, getColor, setColor, getAttrs, hasSlotContent, isSystemKey, isCVA } = useUI(
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
- if (key === "dropdownButton") {
33
- const dropdownButton = attrs[`${key}Attrs`];
12
+ const extendingKeys = ["dropdownButtonActive"];
13
+ const extendingKeysClasses = getExtendingKeysClasses(extendingKeys);
34
14
 
35
- attrs[`${key}Attrs`] = computed(() => ({
36
- ...dropdownButton.value,
37
- class: cx([
38
- dropdownButton.value.class,
39
- isShownOptions.value && setColor(config.value.dropdownButtonActive, props.color),
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
  }
package/web-types.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "framework": "vue",
3
3
  "name": "vueless",
4
- "version": "0.0.365",
4
+ "version": "0.0.367",
5
5
  "contributions": {
6
6
  "html": {
7
7
  "description-markup": "markdown",