vueless 0.0.223 → 0.0.225

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.
@@ -92,7 +92,7 @@ export default function useUI(defaultConfig = {}, propsConfigGetter = null, topL
92
92
 
93
93
  watch(config, updateVuelessAttrs, { immediate: true });
94
94
  watch(props, updateVuelessAttrs);
95
- options?.classes && watch(options?.classes, updateVuelessAttrs);
95
+ options?.classes?.value && watch(options?.classes, updateVuelessAttrs);
96
96
 
97
97
  function updateVuelessAttrs() {
98
98
  const configKeyValue = config.value[configKey];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vueless",
3
- "version": "0.0.223",
3
+ "version": "0.0.225",
4
4
  "license": "MIT",
5
5
  "description": "Vue Styleless Component Framework.",
6
6
  "homepage": "https://vueless.com",
@@ -1,4 +1,13 @@
1
1
  export default /*tw*/ {
2
+ label: {
3
+ component: "{ULabel}",
4
+ base: "flex flex-wrap",
5
+ variants: {
6
+ block: {
7
+ true: "w-full",
8
+ },
9
+ },
10
+ },
2
11
  items: {
3
12
  base: "flex flex-wrap",
4
13
  variants: {
@@ -13,8 +22,8 @@ export default /*tw*/ {
13
22
  separated: {
14
23
  false: `
15
24
  flex-nowrap -space-x-px gap-0
16
- [&>:first-child]:rounded-l-lg [&>:last-child]:rounded-r-lg
17
- [&>:first-child>*>*]:rounded-l-lg [&>:last-child>*>*]:rounded-r-lg
25
+ [&>:first-child]:rounded-l-lg [&>:last-child]:rounded-r-lg
26
+ [&>:first-child>*>*]:rounded-l-lg [&>:last-child>*>*]:rounded-r-lg
18
27
  `,
19
28
  },
20
29
  },
@@ -23,14 +32,6 @@ export default /*tw*/ {
23
32
  { separated: false, multiple: true, class: "space-x-px" },
24
33
  ],
25
34
  },
26
- label: {
27
- base: "{ULabel} flex flex-wrap",
28
- variants: {
29
- block: {
30
- true: "w-full",
31
- },
32
- },
33
- },
34
35
  item: "{UToggleItem}",
35
36
  defaultVariants: {
36
37
  variant: "primary",
@@ -148,8 +148,15 @@ Default.args = {
148
148
  name: "Default",
149
149
  };
150
150
 
151
+ export const Disabled = DefaultTemplate.bind({});
152
+ Disabled.args = {
153
+ name: "Disabled",
154
+ disabled: true,
155
+ };
156
+
151
157
  export const label = DefaultTemplate.bind({});
152
158
  label.args = {
159
+ name: "Label",
153
160
  label: "Label",
154
161
  description: "description",
155
162
  };
@@ -5,8 +5,9 @@
5
5
  :description="description"
6
6
  :align="labelAlign"
7
7
  :disabled="disabled"
8
- :data-cy="dataCy"
8
+ centred
9
9
  v-bind="labelAttrs"
10
+ :data-cy="dataCy"
10
11
  >
11
12
  <div v-bind="itemsAttrs">
12
13
  <!-- @slot Use it to add UToggleItem directly. -->
@@ -223,15 +224,15 @@ function updateSelectedValue(value, checked) {
223
224
  }
224
225
  }
225
226
 
226
- provide("toggleType", readonly(type));
227
- provide("togglePill", () => props.pill);
228
- provide("toggleName", () => props.name);
229
- provide("toggleSize", () => props.size);
230
- provide("toggleBlock", () => props.block);
231
- provide("toggleSquare", () => props.square);
232
- provide("toggleVariant", () => props.variant);
233
- provide("toggleDisabled", () => props.disabled);
234
- provide("toggleSeparated", () => props.separated);
227
+ provide("getToggleName", () => props.name);
228
+ provide("getToggleType", () => type.value);
229
+ provide("getToggleSize", () => props.size);
230
+ provide("getTogglePill", () => props.pill);
231
+ provide("getToggleBlock", () => props.block);
232
+ provide("getToggleSquare", () => props.square);
233
+ provide("getToggleVariant", () => props.variant);
234
+ provide("getToggleDisabled", () => props.disabled);
235
+ provide("getToggleSeparated", () => props.separated);
235
236
 
236
237
  provide("toggleSelectedValue", {
237
238
  selectedValue: readonly(selectedValue),
@@ -1,20 +1,18 @@
1
1
  import { computed, toValue } from "vue";
2
2
  import useUI from "../../composable.ui";
3
- import { cx, cva } from "../../service.ui";
3
+ import { cva } from "../../service.ui";
4
4
  import defaultConfig from "../configs/default.config";
5
5
 
6
- export default function useAttrs(props, { selectedValue, separated, variant }) {
6
+ export default function useAttrs(props, { isSelected, separated, variant }) {
7
7
  const { config, getAttrs, isSystemKey, hasSlotContent } = useUI(
8
8
  defaultConfig,
9
9
  () => props.config,
10
10
  );
11
11
 
12
- const skipKeys = ["selected"];
13
-
14
12
  const attrs = {};
15
13
 
16
14
  for (const key in defaultConfig) {
17
- if (isSystemKey(key) || skipKeys.includes(key)) continue;
15
+ if (isSystemKey(key)) continue;
18
16
 
19
17
  const classes = computed(() => {
20
18
  const value = config.value[key];
@@ -24,6 +22,7 @@ export default function useAttrs(props, { selectedValue, separated, variant }) {
24
22
  ...props,
25
23
  variant: toValue(variant),
26
24
  separated: toValue(separated),
25
+ selected: isSelected.value,
27
26
  });
28
27
  }
29
28
 
@@ -31,29 +30,6 @@ export default function useAttrs(props, { selectedValue, separated, variant }) {
31
30
  });
32
31
 
33
32
  attrs[`${key}Attrs`] = getAttrs(key, { classes });
34
-
35
- if (key === "button") {
36
- const selectedClasses = computed(() =>
37
- cva(config.value.selected)({
38
- ...props,
39
- variant: toValue(variant),
40
- separated: toValue(separated),
41
- }),
42
- );
43
-
44
- const buttonAttrs = attrs[`${key}Attrs`];
45
-
46
- attrs[`${key}Attrs`] = computed(() => {
47
- const isSelected = Array.isArray(selectedValue?.value)
48
- ? selectedValue?.value?.includes(props.value)
49
- : selectedValue?.value === props.value;
50
-
51
- return {
52
- ...buttonAttrs.value,
53
- class: cx([buttonAttrs.value.class, isSelected && selectedClasses.value]),
54
- };
55
- });
56
- }
57
33
  }
58
34
 
59
35
  return {
@@ -1,7 +1,8 @@
1
1
  export default /*tw*/ {
2
2
  button: {
3
+ component: "{UButton}",
3
4
  base: `
4
- {UButton} border-gray-300 font-normal
5
+ border-gray-300 font-normal
5
6
  hover:text-brand-600 hover:border-brand-600 hover:relative hover:z-10
6
7
  focus:text-brand-600 focus:border-brand-600 focus:relative focus:z-10 focus:ring-brand-600 focus-within:ring-brand-600
7
8
  active:text-brand-700 active:border-brand-700 active:relative active:z-10
@@ -21,18 +22,29 @@ export default /*tw*/ {
21
22
  `,
22
23
  },
23
24
  },
24
- },
25
- input: "p-0 m-0 size-0 invisible absolute",
26
- selected: {
27
- base: "relative disabled:z-10",
28
- variants: {
29
- variant: {
30
- primary: "!text-white bg-brand-600 border-brand-600 disabled:border-brand-600",
31
- secondary: "text-brand-600 border-brand-600 disabled:border-brand-600 bg-brand-600 bg-opacity-10",
32
- thirdary: " bg-brand-600 bg-opacity-20 hover:bg-opacity-20 focus:bg-opacity-20",
25
+ compoundVariants: [
26
+ {
27
+ selected: true,
28
+ class: "relative disabled:z-10",
33
29
  },
34
- },
30
+ {
31
+ selected: true,
32
+ variant: "primary",
33
+ class: "!text-white bg-brand-600 border-brand-600 disabled:border-brand-600",
34
+ },
35
+ {
36
+ selected: true,
37
+ variant: "secondary",
38
+ class: "text-brand-600 border-brand-600 disabled:border-brand-600 bg-brand-600 bg-opacity-10",
39
+ },
40
+ {
41
+ selected: true,
42
+ variant: "thirdary",
43
+ class: "bg-brand-600 bg-opacity-20 hover:bg-opacity-20 focus:bg-opacity-20",
44
+ },
45
+ ],
35
46
  },
47
+ input: "p-0 m-0 size-0 invisible absolute",
36
48
  defaultVariants: {
37
49
  variant: "primary",
38
50
  type: "radio",
@@ -5,11 +5,11 @@
5
5
  color="grayscale"
6
6
  variant="secondary"
7
7
  :label="label"
8
- :size="toValue(size)"
9
- :pill="toValue(pill)"
10
- :block="toValue(block)"
11
- :square="toValue(square)"
12
- :disabled="toValue(disabled)"
8
+ :size="getToggleSize()"
9
+ :pill="getTogglePill()"
10
+ :block="getToggleBlock()"
11
+ :square="getToggleSquare()"
12
+ :disabled="getToggleDisabled()"
13
13
  v-bind="buttonAttrs"
14
14
  @click="onClickSetValue"
15
15
  >
@@ -22,12 +22,13 @@
22
22
  <input
23
23
  :id="id"
24
24
  v-model="selectedItem"
25
- :name="name"
26
- :type="type"
25
+ :name="getToggleName()"
26
+ :type="getToggleType()"
27
27
  :value="value"
28
- :disabled="toValue(disabled)"
28
+ :disabled="getToggleDisabled()"
29
29
  v-bind="inputAttrs"
30
30
  />
31
+ {{ label }}
31
32
  <!-- @slot Use it to add something instead of the text. -->
32
33
  <slot name="default" />
33
34
  </template>
@@ -40,7 +41,7 @@
40
41
  </template>
41
42
 
42
43
  <script setup>
43
- import { inject, onMounted, ref, toValue } from "vue";
44
+ import { computed, inject, onMounted, ref } from "vue";
44
45
 
45
46
  import UButton from "../ui.button";
46
47
  import UIService, { getRandomId } from "../service.ui";
@@ -121,37 +122,44 @@ const emit = defineEmits([
121
122
  "update:modelValue",
122
123
  ]);
123
124
 
124
- const name = inject("toggleName", () => "toggle");
125
- const type = inject("toggleType", UIService.get(defaultConfig, UToggleItem).default.type);
126
- const size = inject("toggleSize", UIService.get(defaultConfig, UToggleItem).default.size);
127
- const pill = inject("togglePill", UIService.get(defaultConfig, UToggleItem).default.pill);
128
- const block = inject("toggleBlock", UIService.get(defaultConfig, UToggleItem).default.block);
129
- const square = inject("toggleSquare", UIService.get(defaultConfig, UToggleItem).default.square);
130
- const variant = inject("toggleVariant", UIService.get(defaultConfig, UToggleItem).default.variant);
131
- const separated = inject("toggleSeparated", () => true);
132
- // eslint-disable-next-line vue/no-dupe-keys, prettier/prettier
133
- const disabled = inject("toggleDisabled", props.disabled || UIService.get(defaultConfig, UToggleItem).default.disabled);
125
+ /* eslint-disable prettier/prettier, vue/max-len */
126
+ const getToggleName = inject("getToggleName", () => "toggle");
127
+ const getToggleType = inject("getToggleType", () => UIService.get(defaultConfig, UToggleItem).default.type);
128
+ const getToggleSize = inject("getToggleSize", () => UIService.get(defaultConfig, UToggleItem).default.size);
129
+ const getTogglePill = inject("getTogglePill", () => UIService.get(defaultConfig, UToggleItem).default.pill);
130
+ const getToggleBlock = inject("getToggleBlock", () => UIService.get(defaultConfig, UToggleItem).default.block);
131
+ const getToggleSquare = inject("getToggleSquare", () => UIService.get(defaultConfig, UToggleItem).default.square);
132
+ const getToggleVariant = inject("getToggleVariant",() => UIService.get(defaultConfig, UToggleItem).default.variant);
133
+ const getToggleSeparated = inject("getToggleSeparated", () => true);
134
+ const getToggleDisabled = inject("getToggleDisabled", () => props.disabled || UIService.get(defaultConfig, UToggleItem).default.disabled);
135
+ /* eslint-enaable prettier/prettier, vue/max-len */
134
136
 
135
137
  const { selectedValue, updateSelectedValue } = inject("toggleSelectedValue", {});
136
138
 
137
139
  const selectedItem = ref("");
138
140
 
139
- const { buttonAttrs, inputAttrs } = useAttrs(props, { selectedValue, separated, variant });
141
+ const isSelected = computed(() => {
142
+ return Array.isArray(selectedValue?.value)
143
+ ? selectedValue?.value?.includes(props.value)
144
+ : selectedValue?.value === props.value;
145
+ });
146
+
147
+ const { buttonAttrs, inputAttrs } = useAttrs(props, {
148
+ isSelected,
149
+ separated: getToggleSeparated,
150
+ variant: getToggleVariant
151
+ });
140
152
 
141
153
  onMounted(() => {
142
- if (type.value === TYPE_RADIO) {
143
- selectedItem.value = selectedValue ? selectedValue.value : selectedItem.value;
144
- } else {
145
- selectedItem.value = selectedValue
146
- ? selectedValue.value.includes(props.value)
147
- : selectedItem.value;
148
- }
154
+ selectedItem.value = getToggleType() === TYPE_RADIO
155
+ ? selectedValue?.value || selectedItem.value
156
+ : selectedValue?.value?.includes(props.value) || selectedItem.value;
149
157
  });
150
158
 
151
159
  function onClickSetValue() {
152
- if (type.value === TYPE_RADIO) {
153
- selectedItem.value = props.value;
154
- }
160
+ selectedItem.value = getToggleType() === TYPE_RADIO
161
+ ? props.value
162
+ : selectedValue?.value?.includes(props.value) || selectedItem.value;
155
163
 
156
164
  updateSelectedValue && updateSelectedValue(props.value, !selectedItem.value);
157
165
 
@@ -45,6 +45,7 @@ export default function useAttrs(props) {
45
45
  }
46
46
 
47
47
  // TODO: Need to find other solution
48
+ // classes is not reactive here, which may cause problems in styling by `config` prop
48
49
  if (key === "day") {
49
50
  attrs[`${key}Attrs`] = (classes) => {
50
51
  return getAttrs("day", { classes }).value;
@@ -1,5 +1,5 @@
1
1
  import useUI from "../../composable.ui";
2
- import { cva, cx } from "../../service.ui";
2
+ import { cva } from "../../service.ui";
3
3
  import { computed, watchEffect } from "vue";
4
4
 
5
5
  import defaultConfig from "../configs/default.config";
@@ -18,6 +18,8 @@ export default function useAttrs(props, { isShownCalendar, isTop, isRight }) {
18
18
  if (value.variants || value.compoundVariants) {
19
19
  return cva(value)({
20
20
  ...props,
21
+ openDirectionY: isTop.value ? POSITION.top : POSITION.bottom,
22
+ openDirectionX: isRight.value ? POSITION.right : POSITION.left,
21
23
  });
22
24
  }
23
25
 
@@ -31,24 +33,14 @@ export default function useAttrs(props, { isShownCalendar, isTop, isRight }) {
31
33
 
32
34
  attrs[`${key}Attrs`] = computed(() => ({
33
35
  ...inputAttrs.value,
34
- class: cx([inputAttrs.value.class, isShownCalendar.value && config.value.inputFocus]),
36
+ config: {
37
+ ...inputAttrs.value.config,
38
+ ...(isShownCalendar.value ? config.value.inputFocused : {}),
39
+ },
35
40
  }));
36
41
  }
37
42
 
38
43
  if (key === "calendar") {
39
- const calendarAttrs = attrs[`${key}Attrs`];
40
-
41
- attrs[`${key}Attrs`] = computed(() => ({
42
- ...calendarAttrs.value,
43
- class: cx([
44
- cva(config.value.calendar.wrapper)({
45
- openDirectionY: isTop.value ? POSITION.top : POSITION.bottom,
46
- openDirectionX: isRight.value ? POSITION.right : POSITION.left,
47
- }),
48
- calendarAttrs.value.class,
49
- ]),
50
- }));
51
-
52
44
  // This watcher rewrites default calendar locales with datepicker range locales
53
45
  // Watcher will not rewrite custom calendar locales
54
46
  watchEffect(() => {
@@ -1,20 +1,20 @@
1
1
  export default /*tw*/ {
2
2
  wrapper: "relative",
3
- input: "",
4
- inputFocus: {
3
+ input: "{UInput}",
4
+ inputFocused: {
5
+ component: "{UInput}",
5
6
  block: "ring-4 ring-brand-600/[.15] border-brand-500 hover:border-brand-500",
6
7
  },
7
8
  calendar: {
8
- wrapper: {
9
- base: "{UCalendar} absolute z-40 my-2",
10
- variants: {
11
- openDirectionX: {
12
- left: "left-0",
13
- right: "right-0",
14
- },
15
- openDirectionY: {
16
- top: "bottom-full mt-0",
17
- },
9
+ component: "{UCalendar}",
10
+ base: "absolute z-40 my-2",
11
+ variants: {
12
+ openDirectionX: {
13
+ left: "left-0",
14
+ right: "right-0",
15
+ },
16
+ openDirectionY: {
17
+ top: "bottom-full mt-0",
18
18
  },
19
19
  },
20
20
  },
@@ -251,14 +251,8 @@ const calendarWrapperRef = computed(() => calendarRef?.value?.wrapperRef);
251
251
  const { isTop, isRight, adjustPositionY, adjustPositionX } = useAdjustElementPosition(
252
252
  wrapperRef,
253
253
  calendarWrapperRef,
254
- {
255
- x: props.openDirectionX,
256
- y: props.openDirectionY,
257
- },
258
- {
259
- x: "left",
260
- y: "bottom",
261
- },
254
+ { x: props.openDirectionX, y: props.openDirectionY },
255
+ { x: "left", y: "bottom" },
262
256
  );
263
257
 
264
258
  defineExpose({
@@ -1,7 +1,8 @@
1
1
  export default /*tw*/ {
2
2
  input: {
3
+ component: "{UInput}",
3
4
  wrapper: "relative flex items-center justify-between w-full rounded-lg bg-gray-900 bg-opacity-5",
4
- input: "{UInput} w-full",
5
+ input: "w-full",
5
6
  label: "w-full",
6
7
  rightSlot: "pr-0",
7
8
  leftSlot: "pl-0",
package/web-types.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "framework": "vue",
3
3
  "name": "vueless",
4
- "version": "0.0.223",
4
+ "version": "0.0.225",
5
5
  "contributions": {
6
6
  "html": {
7
7
  "description-markup": "markdown",