vueless 0.0.569 → 0.0.571

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 (81) hide show
  1. package/package.json +1 -1
  2. package/types.ts +24 -3
  3. package/ui.button/types.ts +2 -2
  4. package/ui.container-accordion/UAccordion.vue +2 -2
  5. package/ui.container-accordion/types.ts +1 -0
  6. package/ui.container-modal/UModal.vue +15 -8
  7. package/ui.container-page/UPage.vue +10 -6
  8. package/ui.form-checkbox/types.ts +7 -0
  9. package/ui.form-checkbox-group/UCheckboxGroup.vue +1 -1
  10. package/ui.form-checkbox-multi-state/UCheckboxMultiState.vue +4 -1
  11. package/ui.form-color-picker/UColorPicker.vue +67 -147
  12. package/ui.form-color-picker/storybook/Docs.mdx +2 -2
  13. package/ui.form-color-picker/storybook/{stories.js → stories.ts} +13 -5
  14. package/ui.form-color-picker/types.ts +64 -0
  15. package/ui.form-color-picker/useAttrs.ts +15 -0
  16. package/ui.form-input/UInput.vue +162 -321
  17. package/ui.form-input/{config.js → config.ts} +3 -0
  18. package/ui.form-input/storybook/Docs.mdx +2 -2
  19. package/ui.form-input/storybook/{stories.js → stories.ts} +14 -6
  20. package/ui.form-input/types.ts +103 -0
  21. package/ui.form-input/useAttrs.ts +31 -0
  22. package/ui.form-input-file/UInputFile.vue +188 -245
  23. package/ui.form-input-file/storybook/Docs.mdx +2 -2
  24. package/ui.form-input-file/storybook/{stories.js → stories.ts} +13 -5
  25. package/ui.form-input-file/types.ts +72 -0
  26. package/ui.form-input-file/useAttrs.ts +21 -0
  27. package/ui.form-input-file/{utilFileForm.js → utilFileForm.ts} +1 -1
  28. package/ui.form-input-money/UInputMoney.vue +76 -223
  29. package/ui.form-input-money/storybook/Docs.mdx +2 -2
  30. package/ui.form-input-money/storybook/{stories.js → stories.ts} +14 -6
  31. package/ui.form-input-money/types.ts +118 -0
  32. package/ui.form-input-money/useAttrs.ts +15 -0
  33. package/ui.form-input-money/{useFormatCurrency.js → useFormatCurrency.ts} +28 -17
  34. package/ui.form-input-money/utilFormat.ts +83 -0
  35. package/ui.form-input-number/UInputNumber.vue +69 -156
  36. package/ui.form-input-number/storybook/Docs.mdx +2 -2
  37. package/ui.form-input-number/storybook/{stories.js → stories.ts} +17 -9
  38. package/ui.form-input-number/types.ts +65 -0
  39. package/ui.form-input-number/useAttrs.ts +15 -0
  40. package/ui.form-input-rating/UInputRating.vue +70 -158
  41. package/ui.form-input-rating/storybook/Docs.mdx +2 -2
  42. package/ui.form-input-rating/storybook/{stories.js → stories.ts} +14 -6
  43. package/ui.form-input-rating/types.ts +67 -0
  44. package/ui.form-input-rating/useAttrs.ts +14 -0
  45. package/ui.form-input-search/UInputSearch.vue +97 -224
  46. package/ui.form-input-search/storybook/Docs.mdx +2 -2
  47. package/ui.form-input-search/storybook/{stories.js → stories.ts} +13 -5
  48. package/ui.form-input-search/types.ts +93 -0
  49. package/ui.form-input-search/useAttrs.ts +15 -0
  50. package/ui.form-radio/URadio.vue +1 -1
  51. package/ui.form-radio-group/URadioGroup.vue +1 -1
  52. package/ui.navigation-pagination/UPagination.vue +15 -15
  53. package/ui.navigation-pagination/types.ts +3 -0
  54. package/ui.navigation-progress/UProgress.vue +16 -2
  55. package/ui.navigation-progress/types.ts +2 -0
  56. package/ui.text-files/UFiles.vue +20 -16
  57. package/ui.text-files/types.ts +1 -1
  58. package/ui.text-notify/UNotify.vue +38 -48
  59. package/ui.text-notify/types.ts +24 -0
  60. package/web-types.json +227 -138
  61. package/ui.form-color-picker/useAttrs.js +0 -9
  62. package/ui.form-input/useAttrs.js +0 -15
  63. package/ui.form-input-file/useAttrs.js +0 -15
  64. package/ui.form-input-money/useAttrs.js +0 -9
  65. package/ui.form-input-money/utilFormat.js +0 -75
  66. package/ui.form-input-number/useAttrs.js +0 -9
  67. package/ui.form-input-rating/useAttrs.js +0 -8
  68. package/ui.form-input-search/useAttrs.js +0 -9
  69. /package/ui.form-color-picker/{config.js → config.ts} +0 -0
  70. /package/ui.form-color-picker/{constants.js → constants.ts} +0 -0
  71. /package/ui.form-input/{constants.js → constants.ts} +0 -0
  72. /package/ui.form-input-file/{config.js → config.ts} +0 -0
  73. /package/ui.form-input-file/{constants.js → constants.ts} +0 -0
  74. /package/ui.form-input-money/{config.js → config.ts} +0 -0
  75. /package/ui.form-input-money/{constants.js → constants.ts} +0 -0
  76. /package/ui.form-input-number/{config.js → config.ts} +0 -0
  77. /package/ui.form-input-number/{constants.js → constants.ts} +0 -0
  78. /package/ui.form-input-rating/{config.js → config.ts} +0 -0
  79. /package/ui.form-input-rating/{constants.js → constants.ts} +0 -0
  80. /package/ui.form-input-search/{config.js → config.ts} +0 -0
  81. /package/ui.form-input-search/{constants.js → constants.ts} +0 -0
@@ -7,6 +7,7 @@ import { UFiles } from "./constants.ts";
7
7
  import defaultConfig from "./config.ts";
8
8
  import useAttrs from "./useAttrs.ts";
9
9
  import { computed } from "vue";
10
+ import { getRandomId } from "../utils/helper.ts";
10
11
 
11
12
  import type { UFilesProps } from "./types.ts";
12
13
 
@@ -15,6 +16,7 @@ defineOptions({ inheritAttrs: false });
15
16
  const props = withDefaults(defineProps<UFilesProps>(), {
16
17
  labelAlign: getDefault<UFilesProps>(defaultConfig, UFiles).labelAlign,
17
18
  size: getDefault<UFilesProps>(defaultConfig, UFiles).size,
19
+ fileList: () => [],
18
20
  dataTest: "",
19
21
  });
20
22
 
@@ -28,18 +30,20 @@ const emit = defineEmits([
28
30
 
29
31
  const { filesLabelAttrs, itemsAttrs, itemAttrs } = useAttrs(props);
30
32
 
31
- const formattedFileList = computed(() =>
32
- props.fileList.map((file) => {
33
- return {
34
- id: file.name,
35
- label: file.name,
36
- url: URL.createObjectURL(file),
37
- imageUrl: file.type.includes("image") ? URL.createObjectURL(file) : undefined,
38
- };
39
- }),
40
- );
33
+ const formattedFileList = computed(() => {
34
+ return props.fileList.map((file) => {
35
+ if (file instanceof File) {
36
+ return {
37
+ id: getRandomId(),
38
+ label: file.name || "",
39
+ url: URL.createObjectURL(file),
40
+ imageUrl: file.type.includes("image") ? URL.createObjectURL(file) : undefined,
41
+ };
42
+ }
43
+ });
44
+ });
41
45
 
42
- function onRemoveFile(fileId) {
46
+ function onRemoveFile(fileId: string | number) {
43
47
  emit("remove", fileId);
44
48
  }
45
49
  </script>
@@ -57,11 +61,11 @@ function onRemoveFile(fileId) {
57
61
  <slot>
58
62
  <UFile
59
63
  v-for="(file, index) in formattedFileList"
60
- :id="file.id"
61
- :key="file.id"
62
- :label="file.label"
63
- :url="file.url"
64
- :image-url="file.imageUrl"
64
+ :id="file?.id"
65
+ :key="file?.id"
66
+ :label="file?.label"
67
+ :url="file?.url"
68
+ :image-url="file?.imageUrl"
65
69
  :size="size"
66
70
  :removable="removable"
67
71
  v-bind="itemAttrs"
@@ -6,7 +6,7 @@ export interface UFilesProps {
6
6
  /**
7
7
  * List of file objects.
8
8
  */
9
- fileList?: Array<object>;
9
+ fileList: File[];
10
10
 
11
11
  /**
12
12
  * File list label.
@@ -2,7 +2,7 @@
2
2
  import { computed, onBeforeUnmount, onMounted, ref } from "vue";
3
3
  import { merge } from "lodash-es";
4
4
 
5
- import { cx, getDefault, vuelessConfig } from "../utils/ui.ts";
5
+ import { getDefault, vuelessConfig } from "../utils/ui.ts";
6
6
  import { useLocale } from "../composables/useLocale.ts";
7
7
  import useAttrs from "./useAttrs.ts";
8
8
 
@@ -11,7 +11,13 @@ import { UNotify, NOTIFY_TYPE, POSITION } from "./constants.ts";
11
11
 
12
12
  import UIcon from "../ui.image-icon/UIcon.vue";
13
13
 
14
- import type { UNotifyProps } from "./types.ts";
14
+ import type {
15
+ UNotifyProps,
16
+ Notification,
17
+ NotifyEvent,
18
+ NotificationsWrapperRef,
19
+ NotificationType,
20
+ } from "./types.ts";
15
21
 
16
22
  defineOptions({ inheritAttrs: false });
17
23
 
@@ -20,8 +26,19 @@ const props = withDefaults(defineProps<UNotifyProps>(), {
20
26
  yPosition: getDefault<UNotifyProps>(defaultConfig, UNotify).yPosition,
21
27
  html: getDefault<UNotifyProps>(defaultConfig, UNotify).html,
22
28
  dataTest: "",
29
+ config: () => ({}),
23
30
  });
24
31
 
32
+ const { tm } = useLocale();
33
+
34
+ const notifications = ref<Notification[]>([]);
35
+ const notifyPositionStyles = ref({});
36
+
37
+ const notificationsWrapperRef = ref<NotificationsWrapperRef | null>(null);
38
+
39
+ const i18nGlobal = tm(UNotify);
40
+ const currentLocale = computed(() => merge(defaultConfig.i18n, i18nGlobal, props.config.i18n));
41
+
25
42
  const {
26
43
  config,
27
44
  wrapperAttrs,
@@ -33,17 +50,7 @@ const {
33
50
  warningIconAttrs,
34
51
  errorIconAttrs,
35
52
  closeIconAttrs,
36
- } = useAttrs(props);
37
-
38
- const { tm } = useLocale();
39
-
40
- const notifications = ref([]);
41
- const notifyPositionStyles = ref({});
42
-
43
- const notificationsWrapperRef = ref(null);
44
-
45
- const i18nGlobal = tm(UNotify);
46
- const currentLocale = computed(() => merge(defaultConfig.i18n, i18nGlobal, props.config.i18n));
53
+ } = useAttrs(props, { notifications });
47
54
 
48
55
  onMounted(() => {
49
56
  window.addEventListener("resize", setPosition, { passive: true });
@@ -61,11 +68,11 @@ onBeforeUnmount(() => {
61
68
  window.removeEventListener("notifyClearAll", onClearAll);
62
69
  });
63
70
 
64
- function onNotifyStart(event) {
71
+ function onNotifyStart(event: NotifyEvent) {
65
72
  notifications.value.push({ ...event.detail });
66
73
  }
67
74
 
68
- function onNotifyEnd(event) {
75
+ function onNotifyEnd(event: NotifyEvent) {
69
76
  notifications.value = notifications.value.filter(
70
77
  (notification) => notification.id !== event.detail.id,
71
78
  );
@@ -75,25 +82,27 @@ function onClearAll() {
75
82
  notifications.value = [];
76
83
  }
77
84
 
78
- function onClickClose(targetNotification) {
85
+ function onClickClose(targetNotification: Notification) {
79
86
  notifications.value = notifications.value.filter(
80
87
  (notification) => notification.id !== targetNotification.id,
81
88
  );
82
89
  }
83
90
 
84
- function getOffsetWidth(selector) {
85
- return document.querySelector(selector)?.offsetWidth || 0;
91
+ function getOffsetWidth(selector: string): number {
92
+ const element = document.querySelector(selector);
93
+
94
+ return element ? (element as HTMLElement).offsetWidth : 0;
86
95
  }
87
96
 
88
97
  function setPosition() {
89
98
  const positionClasses = vuelessConfig.component?.UNotify?.positionClasses;
90
- const pageClass = positionClasses?.page || config.value.positionClasses.page;
91
- const asideClass = positionClasses?.aside || config.value.positionClasses.aside;
99
+ const pageClass = positionClasses?.page || config.value?.positionClasses?.page;
100
+ const asideClass = positionClasses?.aside || config.value?.positionClasses?.aside;
92
101
  const pageWidth = getOffsetWidth(`${pageClass}`);
93
102
  const asideWidth = getOffsetWidth(`${asideClass}`);
94
- const notifyWidth = notificationsWrapperRef.value.$el?.offsetWidth || 0;
103
+ const notifyWidth = notificationsWrapperRef.value?.$el.offsetWidth || 0;
95
104
 
96
- const styles = {
105
+ const styles: Record<string, string> = {
97
106
  left: "auto",
98
107
  top: "auto",
99
108
  right: "auto",
@@ -115,23 +124,9 @@ function setPosition() {
115
124
  notifyPositionStyles.value = styles;
116
125
  }
117
126
 
118
- function getText(notificationText, type) {
127
+ function getText(notificationText: string, type: NotificationType): string {
119
128
  return notificationText || currentLocale.value[type]?.default;
120
129
  }
121
-
122
- function getNotificationClasses(notification) {
123
- if (notification.type === NOTIFY_TYPE.success) {
124
- return cx([bodyAttrs.value.class, config.value.bodySuccess]);
125
- }
126
-
127
- if (notification.type === NOTIFY_TYPE.warning) {
128
- return cx([bodyAttrs.value.class, config.value.bodyWarning]);
129
- }
130
-
131
- if (notification.type === NOTIFY_TYPE.error) {
132
- return cx([bodyAttrs.value.class, config.value.bodyError]);
133
- }
134
- }
135
130
  </script>
136
131
 
137
132
  <template>
@@ -139,21 +134,16 @@ function getNotificationClasses(notification) {
139
134
  ref="notificationsWrapperRef"
140
135
  :style="notifyPositionStyles"
141
136
  tag="div"
142
- v-bind="{ ...config.transitionGroup, ...wrapperAttrs }"
137
+ v-bind="{ ...config?.transitionGroup, ...wrapperAttrs }"
143
138
  >
144
- <div
145
- v-for="notification in notifications"
146
- :key="notification.id"
147
- v-bind="bodyAttrs"
148
- :class="getNotificationClasses(notification)"
149
- >
139
+ <div v-for="notification in notifications" :key="notification.id" v-bind="bodyAttrs">
150
140
  <UIcon
151
141
  v-if="notification.type === NOTIFY_TYPE.success"
152
142
  color="green"
153
143
  variant="light"
154
144
  size="md"
155
145
  internal
156
- :name="config.defaults.successIcon"
146
+ :name="config.defaults?.successIcon"
157
147
  v-bind="successIconAttrs"
158
148
  data-test="type-notify"
159
149
  />
@@ -164,7 +154,7 @@ function getNotificationClasses(notification) {
164
154
  variant="light"
165
155
  size="md"
166
156
  internal
167
- :name="config.defaults.warningIcon"
157
+ :name="config.defaults?.warningIcon"
168
158
  v-bind="warningIconAttrs"
169
159
  data-test="type-notify"
170
160
  />
@@ -176,7 +166,7 @@ function getNotificationClasses(notification) {
176
166
  variant="light"
177
167
  size="md"
178
168
  internal
179
- :name="config.defaults.errorIcon"
169
+ :name="config.defaults?.errorIcon"
180
170
  v-bind="errorIconAttrs"
181
171
  />
182
172
 
@@ -204,7 +194,7 @@ function getNotificationClasses(notification) {
204
194
  size="xs"
205
195
  internal
206
196
  interactive
207
- :name="config.defaults.closeIcon"
197
+ :name="config.defaults?.closeIcon"
208
198
  v-bind="closeIconAttrs"
209
199
  @click="onClickClose(notification)"
210
200
  />
@@ -2,6 +2,30 @@ import defaultConfig from "./config.ts";
2
2
 
3
3
  export type Config = Partial<typeof defaultConfig>;
4
4
 
5
+ export type NotificationType = "success" | "warning" | "error";
6
+
7
+ export type Notification = {
8
+ id: string;
9
+ type: NotificationType;
10
+ label: string;
11
+ description: string;
12
+ };
13
+
14
+ export interface NotifyEvent extends Event {
15
+ detail: Notification;
16
+ }
17
+
18
+ export interface NotificationsWrapperRef {
19
+ $el: HTMLElement;
20
+ }
21
+
22
+ declare global {
23
+ interface WindowEventMap {
24
+ notifyStart: NotifyEvent;
25
+ notifyEnd: NotifyEvent;
26
+ }
27
+ }
28
+
5
29
  export interface UNotifyProps {
6
30
  /**
7
31
  * A position on the x-axis.