vueless 0.0.549 → 0.0.550

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 (49) hide show
  1. package/package.json +1 -1
  2. package/types.ts +4 -0
  3. package/ui.button/UButton.vue +5 -5
  4. package/ui.button/types.ts +3 -0
  5. package/ui.button-link/ULink.vue +19 -11
  6. package/ui.button-toggle/UToggle.vue +6 -7
  7. package/ui.button-toggle/types.ts +6 -1
  8. package/ui.button-toggle-item/UToggleItem.vue +44 -21
  9. package/ui.button-toggle-item/types.ts +19 -0
  10. package/ui.button-toggle-item/useAttrs.ts +1 -1
  11. package/ui.container-modal-confirm/types.ts +3 -3
  12. package/ui.dropdown-button/UDropdownButton.vue +1 -3
  13. package/ui.dropdown-button/types.ts +3 -0
  14. package/ui.dropdown-link/UDropdownLink.vue +1 -2
  15. package/ui.dropdown-link/types.ts +2 -0
  16. package/ui.form-checkbox/UCheckbox.vue +2 -2
  17. package/ui.form-checkbox/types.ts +5 -2
  18. package/ui.form-checkbox-group/types.ts +3 -3
  19. package/ui.form-checkbox-multi-state/types.ts +3 -2
  20. package/ui.form-radio/URadio.vue +59 -157
  21. package/ui.form-radio/storybook/Docs.mdx +2 -2
  22. package/ui.form-radio/storybook/{stories.js → stories.ts} +11 -3
  23. package/ui.form-radio/types.ts +99 -0
  24. package/ui.form-radio/useAttrs.ts +35 -0
  25. package/ui.form-radio-group/URadioGroup.vue +45 -125
  26. package/ui.form-radio-group/storybook/Docs.mdx +2 -2
  27. package/ui.form-radio-group/storybook/{stories.js → stories.ts} +13 -5
  28. package/ui.form-radio-group/types.ts +92 -0
  29. package/ui.form-radio-group/useAttrs.ts +18 -0
  30. package/ui.image-avatar/UAvatar.vue +1 -1
  31. package/ui.image-icon/UIcon.vue +1 -1
  32. package/ui.navigation-tab/UTab.vue +5 -4
  33. package/ui.navigation-tab/types.ts +4 -0
  34. package/ui.navigation-tabs/types.ts +12 -2
  35. package/ui.text-alert/UAlert.vue +17 -5
  36. package/ui.text-alert/types.ts +3 -0
  37. package/ui.text-badge/UBadge.vue +2 -2
  38. package/ui.text-badge/types.ts +2 -0
  39. package/ui.text-empty/UEmpty.vue +5 -4
  40. package/ui.text-empty/types.ts +3 -0
  41. package/ui.text-file/UFile.vue +6 -5
  42. package/ui.text-file/types.ts +3 -0
  43. package/web-types.json +100 -60
  44. package/ui.form-radio/useAttrs.js +0 -23
  45. package/ui.form-radio-group/useAttrs.js +0 -15
  46. /package/ui.form-radio/{config.js → config.ts} +0 -0
  47. /package/ui.form-radio/{constants.js → constants.ts} +0 -0
  48. /package/ui.form-radio-group/{config.js → config.ts} +0 -0
  49. /package/ui.form-radio-group/{constants.js → constants.ts} +0 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vueless",
3
- "version": "0.0.549",
3
+ "version": "0.0.550",
4
4
  "license": "MIT",
5
5
  "description": "Vue Styleless UI Component Library, powered by Tailwind CSS.",
6
6
  "keywords": [
package/types.ts CHANGED
@@ -43,6 +43,8 @@ import UIconConfig from "./ui.image-icon/config.ts";
43
43
  import UCheckboxConfig from "./ui.form-checkbox/config.ts";
44
44
  import UCheckboxGroupConfig from "./ui.form-checkbox-group/config.ts";
45
45
  import UCheckboxMultiStateConfig from "./ui.form-checkbox-multi-state/config.ts";
46
+ import URadioConfig from "./ui.form-radio/config.ts";
47
+ import URadioGroupConfig from "./ui.form-radio-group/config.ts";
46
48
 
47
49
  import type { ComputedRef, MaybeRef, Ref } from "vue";
48
50
  import type { Props } from "tippy.js";
@@ -199,6 +201,8 @@ export interface Components {
199
201
  UCheckbox?: Partial<typeof UCheckboxConfig>;
200
202
  UCheckboxGroup?: Partial<typeof UCheckboxGroupConfig>;
201
203
  UCheckboxMultiState?: Partial<typeof UCheckboxMultiStateConfig>;
204
+ URadio?: Partial<typeof URadioConfig>;
205
+ URadioGroup?: Partial<typeof URadioGroupConfig>;
202
206
  }
203
207
 
204
208
  export interface Directives {
@@ -10,7 +10,7 @@ import defaultConfig from "./config.ts";
10
10
  import useAttrs from "./useAttrs.ts";
11
11
  import { UButton } from "./constants.ts";
12
12
 
13
- import type { UButtonProps } from "./types.ts";
13
+ import type { UButtonProps, LoaderSize, IconSize } from "./types.ts";
14
14
 
15
15
  defineOptions({ inheritAttrs: false });
16
16
 
@@ -37,7 +37,7 @@ const { isDarkMode } = useDarkMode();
37
37
  const { buttonAttrs, loaderAttrs, leftIconAttrs, rightIconAttrs, centerIconAttrs } =
38
38
  useAttrs(props);
39
39
 
40
- const buttonRef = ref(null);
40
+ const buttonRef = ref<HTMLElement | null>(null);
41
41
  const buttonStyle = ref({});
42
42
  const buttonWidth = ref(0);
43
43
 
@@ -51,7 +51,7 @@ const loaderSize = computed(() => {
51
51
  xl: "lg",
52
52
  };
53
53
 
54
- return sizes[props.size];
54
+ return sizes[props.size] as LoaderSize;
55
55
  });
56
56
 
57
57
  const iconSize = computed(() => {
@@ -64,7 +64,7 @@ const iconSize = computed(() => {
64
64
  xl: "sm",
65
65
  };
66
66
 
67
- return sizes[props.size];
67
+ return sizes[props.size] as IconSize;
68
68
  });
69
69
 
70
70
  const iconColor = computed(() => {
@@ -92,7 +92,7 @@ watch(
92
92
  );
93
93
 
94
94
  watchEffect(() => {
95
- props.loading && buttonRef.value.blur();
95
+ props.loading && buttonRef?.value?.blur();
96
96
  });
97
97
 
98
98
  defineExpose({
@@ -2,6 +2,9 @@ import defaultConfig from "./config.ts";
2
2
 
3
3
  export type Config = Partial<typeof defaultConfig>;
4
4
 
5
+ export type LoaderSize = "sm" | "md" | "lg";
6
+ export type IconSize = "2xs" | "xs" | "sm" | "md";
7
+
5
8
  export interface UButtonProps {
6
9
  /**
7
10
  * Button variant.
@@ -59,19 +59,27 @@ const emit = defineEmits([
59
59
  ]);
60
60
 
61
61
  const isPresentRoute = computed(() => {
62
- for (const key in props.to) return true;
62
+ return typeof props.to === "string" || typeof props.to === "object";
63
+ });
64
+
65
+ const safeTo = computed(() => {
66
+ if (!props.to) {
67
+ return "/";
68
+ }
63
69
 
64
- return false;
70
+ return props.to;
65
71
  });
66
72
 
67
- const { route, isActive, isExactActive } = useLink({
73
+ const useLinkOptions = {
68
74
  activeClass: props.activeClass,
69
75
  ariaCurrentValue: props.ariaCurrentValue,
70
76
  exactActiveClass: props.exactActiveClass,
71
77
  custom: props.custom,
72
78
  replace: props.replace,
73
- to: isPresentRoute.value ? props.to : "/",
74
- });
79
+ to: safeTo.value,
80
+ };
81
+
82
+ const { route, isActive, isExactActive } = useLink(useLinkOptions);
75
83
 
76
84
  const wrapperRef = ref(null);
77
85
 
@@ -88,26 +96,26 @@ const prefixedHref = computed(() => {
88
96
  link: "",
89
97
  };
90
98
 
91
- return props.href ? `${types[props.type]}${props.href}` : null;
99
+ return props.href ? `${types[props.type]}${props.href}` : undefined;
92
100
  });
93
101
 
94
- function onClick(event) {
102
+ function onClick(event: MouseEvent) {
95
103
  emit("click", event);
96
104
  }
97
105
 
98
- function onMouseover(event) {
106
+ function onMouseover(event: MouseEvent) {
99
107
  emit("mouseover", event);
100
108
  }
101
109
 
102
- function onFocus(event) {
110
+ function onFocus(event: FocusEvent) {
103
111
  emit("focus", event);
104
112
  }
105
113
 
106
- function onKeydown(event) {
114
+ function onKeydown(event: KeyboardEvent) {
107
115
  emit("keydown", event);
108
116
  }
109
117
 
110
- function onBlur(event) {
118
+ function onBlur(event: FocusEvent) {
111
119
  emit("blur", event);
112
120
  }
113
121
 
@@ -58,20 +58,19 @@ const type = computed(() => {
58
58
  return props.multiple ? TYPE_CHECKBOX : TYPE_RADIO;
59
59
  });
60
60
 
61
- function updateSelectedValue(value, checked) {
61
+ function updateSelectedValue(value: string | number, checked: boolean) {
62
62
  if (type.value === TYPE_RADIO) {
63
63
  selectedValue.value = value;
64
64
 
65
65
  return;
66
66
  }
67
67
 
68
- if (checked) {
69
- const items = selectedValue.value || [];
70
-
71
- items.push(value);
72
- selectedValue.value = items;
68
+ if (Array.isArray(selectedValue.value)) {
69
+ selectedValue.value = checked
70
+ ? [...selectedValue.value, value]
71
+ : selectedValue.value.filter((item) => String(item) !== String(value));
73
72
  } else {
74
- selectedValue.value = selectedValue.value.filter((item) => String(item) !== String(value));
73
+ selectedValue.value = [value];
75
74
  }
76
75
  }
77
76
 
@@ -2,6 +2,11 @@ import defaultConfig from "./config.ts";
2
2
 
3
3
  export type Config = Partial<typeof defaultConfig>;
4
4
 
5
+ export interface UToggleOption {
6
+ value: string | number;
7
+ label: string;
8
+ }
9
+
5
10
  export interface UToggleProps {
6
11
  /**
7
12
  * Selected value.
@@ -11,7 +16,7 @@ export interface UToggleProps {
11
16
  /**
12
17
  * Toggle item options.
13
18
  */
14
- options?: Array<string | number>;
19
+ options?: UToggleOption[];
15
20
 
16
21
  /**
17
22
  * Toggle variant.
@@ -10,7 +10,9 @@ import useAttrs from "./useAttrs.ts";
10
10
  import defaultConfig from "./config.ts";
11
11
  import { UToggleItem } from "./constants.ts";
12
12
 
13
- import type { UToggleItemProps } from "./types.ts";
13
+ import type { UToggleItemProps, ToggleInjectValues, ToggleContextType } from "./types.ts";
14
+
15
+ type ButtonSize = "2xs" | "xs" | "sm" | "md" | "lg" | "xl";
14
16
 
15
17
  defineOptions({ inheritAttrs: false });
16
18
 
@@ -27,23 +29,40 @@ const emit = defineEmits([
27
29
  "update:modelValue",
28
30
  ]);
29
31
 
30
- /* eslint-disable prettier/prettier, vue/max-len */
31
- const getToggleName = inject("getToggleName", () => "toggle");
32
- const getToggleType = inject("getToggleType", () => getDefault(defaultConfig, UToggleItem).type);
33
- const getToggleSize = inject("getToggleSize", () => getDefault(defaultConfig, UToggleItem).size);
34
- const getToggleRound = inject("getToggleRound", () => getDefault(defaultConfig, UToggleItem).round);
35
- const getToggleBlock = inject("getToggleBlock", () => getDefault(defaultConfig, UToggleItem).block);
36
- const getToggleSquare = inject("getToggleSquare", () => getDefault(defaultConfig, UToggleItem).square);
37
- const getToggleVariant = inject("getToggleVariant", () => getDefault(defaultConfig, UToggleItem).variant);
38
- const getToggleSeparated = inject("getToggleSeparated", () => true);
39
- const getToggleDisabled = inject("getToggleDisabled", () => props.disabled || getDefault(defaultConfig, UToggleItem).disabled);
40
- /* eslint-enable prettier/prettier, vue/max-len */
41
-
42
- const { selectedValue, updateSelectedValue } = inject("toggleSelectedValue", {});
32
+ /* eslint-disable prettier/prettier */
33
+ const getToggleName = inject<() => string>("getToggleName", () => "toggle");
34
+ const getToggleType = inject<() => string>("getToggleType", () =>
35
+ getDefault<ToggleInjectValues>(defaultConfig, UToggleItem).type || TYPE_RADIO
36
+ );
37
+ const getToggleSize = inject<() => ButtonSize>("getToggleSize", () =>
38
+ (getDefault<ToggleInjectValues>(defaultConfig, UToggleItem).size || "md") as ButtonSize
39
+ );
40
+ const getToggleRound = inject<() => boolean>("getToggleRound", () =>
41
+ getDefault<ToggleInjectValues>(defaultConfig, UToggleItem).round || false
42
+ );
43
+ const getToggleBlock = inject<() => boolean>("getToggleBlock", () =>
44
+ getDefault<ToggleInjectValues>(defaultConfig, UToggleItem).block || false
45
+ );
46
+ const getToggleSquare = inject<() => boolean>("getToggleSquare", () =>
47
+ getDefault<ToggleInjectValues>(defaultConfig, UToggleItem).square || false
48
+ );
49
+ const getToggleVariant = inject<string>("getToggleVariant",
50
+ getDefault<ToggleInjectValues>(defaultConfig, UToggleItem).variant || "secondary"
51
+ );
52
+ const getToggleSeparated = inject<boolean>("getToggleSeparated", true);
53
+ const getToggleDisabled = inject<() => boolean>("getToggleDisabled", () =>
54
+ props.disabled || getDefault<ToggleInjectValues>(defaultConfig, UToggleItem).disabled || false
55
+ );
56
+ /* eslint-enable prettier/prettier */
57
+
58
+ const { selectedValue, updateSelectedValue } = inject<ToggleContextType>("toggleSelectedValue", {
59
+ selectedValue: ref(""),
60
+ updateSelectedValue: () => {},
61
+ });
43
62
 
44
63
  const elementId = props.id || useId();
45
64
 
46
- const selectedItem = ref("");
65
+ const selectedItem = ref<string | boolean>("");
47
66
 
48
67
  const isSelected = computed(() => {
49
68
  return Array.isArray(selectedValue?.value)
@@ -58,19 +77,23 @@ const { toggleButtonAttrs, toggleInputAttrs } = useAttrs(props, {
58
77
  });
59
78
 
60
79
  onMounted(() => {
80
+ const propValueString = props.value?.toString() ?? "";
81
+
61
82
  selectedItem.value =
62
83
  getToggleType() === TYPE_RADIO
63
- ? selectedValue?.value || selectedItem.value
64
- : selectedValue?.value?.includes(props.value) || "";
84
+ ? (selectedValue?.value ?? "")
85
+ : Boolean(selectedValue?.value?.includes(propValueString));
65
86
  });
66
87
 
67
88
  function onClickSetValue() {
89
+ const propValueString = props.value?.toString() ?? "";
90
+
68
91
  selectedItem.value =
69
92
  getToggleType() === TYPE_RADIO
70
- ? props.value
71
- : selectedValue?.value?.includes(props.value) || "";
93
+ ? propValueString
94
+ : Boolean(selectedValue?.value?.includes(propValueString));
72
95
 
73
- updateSelectedValue && updateSelectedValue(props.value, !selectedItem.value);
96
+ updateSelectedValue && updateSelectedValue(propValueString, !selectedItem.value);
74
97
 
75
98
  emit("update:modelValue", props.value);
76
99
  }
@@ -80,7 +103,7 @@ function onClickSetValue() {
80
103
  <UButton
81
104
  tabindex="0"
82
105
  :for="elementId"
83
- :no-ring="!getToggleSeparated()"
106
+ :no-ring="!getToggleSeparated"
84
107
  color="grayscale"
85
108
  variant="secondary"
86
109
  :label="label"
@@ -1,7 +1,26 @@
1
1
  import defaultConfig from "./config.ts";
2
2
 
3
+ import type { Ref } from "vue";
4
+
5
+ type UpdateSelectedValue = (value: string | number, checked: boolean) => void;
6
+
3
7
  export type Config = Partial<typeof defaultConfig>;
4
8
 
9
+ export interface ToggleInjectValues {
10
+ type?: string;
11
+ size?: string;
12
+ round?: boolean;
13
+ block?: boolean;
14
+ square?: boolean;
15
+ variant?: string;
16
+ disabled?: boolean;
17
+ }
18
+
19
+ export interface ToggleContextType {
20
+ selectedValue: Ref<string>;
21
+ updateSelectedValue: UpdateSelectedValue;
22
+ }
23
+
5
24
  export interface UToggleItemProps {
6
25
  /**
7
26
  * Selected value.
@@ -8,7 +8,7 @@ import type { UToggleItemProps, Config } from "./types.ts";
8
8
 
9
9
  type itemState = {
10
10
  isSelected: Ref<boolean>;
11
- separated: Ref<boolean>;
11
+ separated: boolean;
12
12
  variant: string;
13
13
  };
14
14
 
@@ -27,9 +27,7 @@ export interface UModalConfirmProps {
27
27
  * Confirm button color.
28
28
  */
29
29
  confirmColor?:
30
- | "brand"
31
30
  | "grayscale"
32
- | "gray"
33
31
  | "red"
34
32
  | "orange"
35
33
  | "amber"
@@ -47,7 +45,9 @@ export interface UModalConfirmProps {
47
45
  | "fuchsia"
48
46
  | "pink"
49
47
  | "rose"
50
- | "white";
48
+ | "gray"
49
+ | "white"
50
+ | "brand";
51
51
 
52
52
  /**
53
53
  * Set the disabled accept-button.
@@ -13,7 +13,7 @@ import defaultConfig from "./config.ts";
13
13
  import useAttrs from "./useAttrs.ts";
14
14
  import { UDropdownButton, BUTTON_VARIANT } from "./constants.ts";
15
15
 
16
- import type { UDropdownButtonProps } from "./types.ts";
16
+ import type { UDropdownButtonProps, IconSize, DropdownSize } from "./types.ts";
17
17
  import type { Option } from "../ui.dropdown-list/types.ts";
18
18
 
19
19
  defineOptions({ inheritAttrs: false });
@@ -60,7 +60,6 @@ const iconColor = computed(() => {
60
60
  return props.variant === BUTTON_VARIANT.primary ? "white" : props.color;
61
61
  });
62
62
 
63
- type IconSize = "2xs" | "xs" | "sm" | "md" | "lg" | "xl";
64
63
  const iconSize = computed(() => {
65
64
  const sizes = {
66
65
  "2xs": "xs",
@@ -74,7 +73,6 @@ const iconSize = computed(() => {
74
73
  return sizes[props.size] as IconSize;
75
74
  });
76
75
 
77
- type DropdownSize = "sm" | "md" | "lg";
78
76
  const dropdownSize = computed(() => {
79
77
  const sizes = {
80
78
  "2xs": "sm",
@@ -4,6 +4,9 @@ import type { Option } from "../ui.dropdown-list/types.ts";
4
4
 
5
5
  export type Config = Partial<typeof defaultConfig>;
6
6
 
7
+ export type IconSize = "2xs" | "xs" | "sm" | "md" | "lg" | "xl";
8
+ export type DropdownSize = "sm" | "md" | "lg";
9
+
7
10
  export interface UDropdownButtonProps {
8
11
  /**
9
12
  * Button label.
@@ -13,7 +13,7 @@ import { UDropdownLink } from "./constants.ts";
13
13
  import defaultConfig from "./config.ts";
14
14
  import useAttrs from "./useAttrs.ts";
15
15
 
16
- import type { UDropdownLinkProps } from "./types.ts";
16
+ import type { UDropdownLinkProps, IconSize } from "./types.ts";
17
17
  import type { Option } from "../ui.dropdown-list/types.ts";
18
18
 
19
19
  defineOptions({ inheritAttrs: false });
@@ -56,7 +56,6 @@ const { config, wrapperAttrs, dropdownLinkAttrs, dropdownListAttrs, dropdownIcon
56
56
  { isShownOptions },
57
57
  );
58
58
 
59
- type IconSize = "sm" | "2xs" | "xs";
60
59
  const iconSize = computed(() => {
61
60
  const sizes = {
62
61
  sm: "2xs",
@@ -4,6 +4,8 @@ import type { Option } from "../ui.dropdown-list/types.ts";
4
4
 
5
5
  export type Config = Partial<typeof defaultConfig>;
6
6
 
7
+ export type IconSize = "sm" | "2xs" | "xs";
8
+
7
9
  export interface UDropdownLinkProps {
8
10
  /**
9
11
  * Link label.
@@ -12,7 +12,7 @@ import { UCheckbox } from "./constants.ts";
12
12
  import useAttrs from "./useAttrs.ts";
13
13
 
14
14
  import type { UnknownObject } from "../types.ts";
15
- import type { UCheckboxProps } from "./types.ts";
15
+ import type { UCheckboxProps, IconSize } from "./types.ts";
16
16
 
17
17
  defineOptions({ inheritAttrs: false });
18
18
 
@@ -73,7 +73,7 @@ const iconSize = computed(() => {
73
73
  lg: "sm",
74
74
  };
75
75
 
76
- return sizes[props.size];
76
+ return sizes[props.size] as IconSize;
77
77
  });
78
78
 
79
79
  const isBinary = computed(() => !Array.isArray(props.modelValue));
@@ -4,6 +4,8 @@ import type { UnknownObject, UnknownArray } from "../types.ts";
4
4
 
5
5
  export type Config = Partial<typeof defaultConfig>;
6
6
 
7
+ export type IconSize = "2xs" | "xs" | "sm";
8
+
7
9
  export interface UCheckboxProps {
8
10
  /**
9
11
  * Checkbox value.
@@ -54,7 +56,6 @@ export interface UCheckboxProps {
54
56
  * Checkbox color.
55
57
  */
56
58
  color?:
57
- | "brand"
58
59
  | "grayscale"
59
60
  | "red"
60
61
  | "orange"
@@ -72,7 +73,9 @@ export interface UCheckboxProps {
72
73
  | "purple"
73
74
  | "fuchsia"
74
75
  | "pink"
75
- | "rose";
76
+ | "rose"
77
+ | "gray"
78
+ | "brand";
76
79
 
77
80
  /**
78
81
  * Checkbox size.
@@ -40,9 +40,7 @@ export interface UCheckboxGroupProps {
40
40
  * Checkbox group color.
41
41
  */
42
42
  color?:
43
- | "brand"
44
43
  | "grayscale"
45
- | "gray"
46
44
  | "red"
47
45
  | "orange"
48
46
  | "amber"
@@ -59,7 +57,9 @@ export interface UCheckboxGroupProps {
59
57
  | "purple"
60
58
  | "fuchsia"
61
59
  | "pink"
62
- | "rose";
60
+ | "rose"
61
+ | "gray"
62
+ | "brand";
63
63
 
64
64
  /**
65
65
  * Name for each checkbox.
@@ -29,7 +29,6 @@ export interface UCheckboxMultiStateProps {
29
29
  * Checkbox color.
30
30
  */
31
31
  color?:
32
- | "brand"
33
32
  | "grayscale"
34
33
  | "red"
35
34
  | "orange"
@@ -47,7 +46,9 @@ export interface UCheckboxMultiStateProps {
47
46
  | "purple"
48
47
  | "fuchsia"
49
48
  | "pink"
50
- | "rose";
49
+ | "rose"
50
+ | "gray"
51
+ | "brand";
51
52
 
52
53
  /**
53
54
  * Label placement.