vueless 0.0.579 → 0.0.580

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 (240) hide show
  1. package/composables/useUI.ts +46 -60
  2. package/constants.js +3 -0
  3. package/package.json +1 -1
  4. package/types.ts +39 -48
  5. package/ui.button/UButton.vue +2 -3
  6. package/ui.button/types.ts +2 -2
  7. package/ui.button-link/ULink.vue +23 -24
  8. package/ui.button-link/storybook/stories.ts +2 -2
  9. package/ui.button-link/types.ts +7 -6
  10. package/ui.button-toggle/UToggle.vue +15 -16
  11. package/ui.button-toggle/storybook/stories.ts +2 -2
  12. package/ui.button-toggle/types.ts +6 -4
  13. package/ui.button-toggle-item/UToggleItem.vue +29 -20
  14. package/ui.button-toggle-item/storybook/stories.ts +2 -2
  15. package/ui.button-toggle-item/types.ts +5 -4
  16. package/ui.container-accordion/UAccordion.vue +22 -17
  17. package/ui.container-accordion/storybook/stories.ts +2 -2
  18. package/ui.container-accordion/types.ts +5 -4
  19. package/ui.container-card/UCard.vue +12 -5
  20. package/ui.container-card/storybook/stories.ts +2 -2
  21. package/ui.container-card/types.ts +4 -3
  22. package/ui.container-col/UCol.vue +11 -12
  23. package/ui.container-col/storybook/stories.ts +2 -2
  24. package/ui.container-col/types.ts +5 -3
  25. package/ui.container-divider/UDivider.vue +13 -13
  26. package/ui.container-divider/storybook/stories.ts +2 -2
  27. package/ui.container-divider/types.ts +5 -3
  28. package/ui.container-group/UGroup.vue +10 -8
  29. package/ui.container-group/storybook/stories.ts +2 -2
  30. package/ui.container-group/types.ts +5 -3
  31. package/ui.container-groups/UGroups.vue +10 -7
  32. package/ui.container-groups/storybook/stories.ts +2 -2
  33. package/ui.container-groups/types.ts +5 -3
  34. package/ui.container-modal/UModal.vue +43 -43
  35. package/ui.container-modal/storybook/stories.ts +2 -3
  36. package/ui.container-modal/types.ts +5 -3
  37. package/ui.container-modal-confirm/UModalConfirm.vue +14 -17
  38. package/ui.container-modal-confirm/storybook/stories.ts +8 -6
  39. package/ui.container-modal-confirm/types.ts +5 -3
  40. package/ui.container-page/UPage.vue +32 -31
  41. package/ui.container-page/storybook/stories.ts +2 -2
  42. package/ui.container-page/types.ts +4 -3
  43. package/ui.container-row/URow.vue +10 -13
  44. package/ui.container-row/storybook/stories.ts +2 -2
  45. package/ui.container-row/types.ts +5 -3
  46. package/ui.data-list/UDataList.vue +40 -51
  47. package/ui.data-list/storybook/stories.ts +2 -2
  48. package/ui.data-list/types.ts +4 -4
  49. package/ui.data-table/UTable.vue +61 -60
  50. package/ui.data-table/types.ts +4 -3
  51. package/ui.dropdown-badge/UDropdownBadge.vue +21 -25
  52. package/ui.dropdown-badge/storybook/stories.ts +3 -3
  53. package/ui.dropdown-badge/types.ts +4 -3
  54. package/ui.dropdown-button/UDropdownButton.vue +20 -23
  55. package/ui.dropdown-button/storybook/stories.ts +3 -3
  56. package/ui.dropdown-button/types.ts +4 -3
  57. package/ui.dropdown-link/UDropdownLink.vue +20 -23
  58. package/ui.dropdown-link/storybook/stories.ts +3 -3
  59. package/ui.dropdown-link/types.ts +4 -3
  60. package/ui.dropdown-list/UDropdownList.vue +28 -32
  61. package/ui.dropdown-list/storybook/stories.ts +4 -4
  62. package/ui.dropdown-list/types.ts +4 -4
  63. package/ui.form-calendar/UCalendar.vue +36 -34
  64. package/ui.form-calendar/UCalendarDayView.vue +28 -23
  65. package/ui.form-calendar/UCalendarMonthView.vue +24 -19
  66. package/ui.form-calendar/UCalendarYearView.vue +24 -19
  67. package/ui.form-calendar/config.ts +2 -2
  68. package/ui.form-calendar/storybook/stories.ts +2 -2
  69. package/ui.form-calendar/types.ts +8 -7
  70. package/ui.form-checkbox/UCheckbox.vue +23 -21
  71. package/ui.form-checkbox/storybook/stories.ts +2 -2
  72. package/ui.form-checkbox/types.ts +7 -5
  73. package/ui.form-checkbox-group/UCheckboxGroup.vue +17 -14
  74. package/ui.form-checkbox-group/storybook/stories.ts +2 -2
  75. package/ui.form-checkbox-group/types.ts +6 -6
  76. package/ui.form-checkbox-multi-state/UCheckboxMultiState.vue +33 -14
  77. package/ui.form-checkbox-multi-state/storybook/stories.ts +2 -2
  78. package/ui.form-checkbox-multi-state/types.ts +4 -4
  79. package/ui.form-color-picker/UColorPicker.vue +23 -21
  80. package/ui.form-color-picker/storybook/stories.ts +2 -2
  81. package/ui.form-color-picker/types.ts +5 -5
  82. package/ui.form-date-picker/UDatePicker.vue +42 -27
  83. package/ui.form-date-picker/config.ts +5 -5
  84. package/ui.form-date-picker/types.ts +5 -2
  85. package/ui.form-date-picker-range/UDatePickerRange.vue +80 -53
  86. package/ui.form-date-picker-range/types.ts +7 -4
  87. package/ui.form-input/UInput.vue +32 -28
  88. package/ui.form-input/storybook/stories.ts +2 -2
  89. package/ui.form-input/types.ts +5 -3
  90. package/ui.form-input-file/UInputFile.vue +37 -32
  91. package/ui.form-input-file/storybook/stories.ts +2 -2
  92. package/ui.form-input-file/types.ts +6 -4
  93. package/ui.form-input-money/UInputMoney.vue +13 -18
  94. package/ui.form-input-money/storybook/stories.ts +2 -2
  95. package/ui.form-input-money/types.ts +5 -3
  96. package/ui.form-input-number/UInputNumber.vue +23 -24
  97. package/ui.form-input-number/types.ts +4 -2
  98. package/ui.form-input-rating/UInputRating.vue +24 -19
  99. package/ui.form-input-rating/storybook/stories.ts +2 -2
  100. package/ui.form-input-rating/types.ts +5 -3
  101. package/ui.form-input-search/UInputSearch.vue +22 -20
  102. package/ui.form-input-search/storybook/stories.ts +2 -2
  103. package/ui.form-input-search/types.ts +5 -3
  104. package/ui.form-label/ULabel.vue +19 -11
  105. package/ui.form-label/config.ts +0 -1
  106. package/ui.form-label/storybook/stories.ts +2 -2
  107. package/ui.form-label/types.ts +10 -8
  108. package/ui.form-radio/URadio.vue +22 -12
  109. package/ui.form-radio/storybook/stories.ts +2 -2
  110. package/ui.form-radio/types.ts +5 -5
  111. package/ui.form-radio-group/URadioGroup.vue +16 -12
  112. package/ui.form-radio-group/storybook/stories.ts +2 -2
  113. package/ui.form-radio-group/types.ts +7 -7
  114. package/ui.form-select/USelect.vue +53 -39
  115. package/ui.form-switch/USwitch.vue +30 -23
  116. package/ui.form-switch/storybook/stories.ts +2 -2
  117. package/ui.form-switch/types.ts +5 -3
  118. package/ui.form-textarea/UTextarea.vue +19 -15
  119. package/ui.form-textarea/storybook/stories.ts +2 -2
  120. package/ui.form-textarea/types.ts +5 -3
  121. package/ui.image-avatar/UAvatar.vue +12 -11
  122. package/ui.image-avatar/types.ts +4 -2
  123. package/ui.image-icon/UIcon.vue +31 -18
  124. package/ui.image-icon/storybook/stories.ts +2 -2
  125. package/ui.image-icon/types.ts +12 -5
  126. package/ui.loader/ULoader.vue +11 -9
  127. package/ui.loader/storybook/stories.ts +2 -2
  128. package/ui.loader/types.ts +10 -3
  129. package/ui.loader-overlay/ULoaderOverlay.vue +11 -7
  130. package/ui.loader-overlay/storybook/stories.ts +2 -2
  131. package/ui.loader-overlay/types.ts +4 -3
  132. package/ui.loader-progress/ULoaderProgress.vue +14 -10
  133. package/ui.loader-progress/storybook/stories.ts +2 -2
  134. package/ui.loader-progress/types.ts +4 -3
  135. package/ui.navigation-pagination/UPagination.vue +34 -33
  136. package/ui.navigation-pagination/storybook/stories.ts +2 -2
  137. package/ui.navigation-pagination/types.ts +4 -3
  138. package/ui.navigation-progress/StepperProgress.vue +25 -12
  139. package/ui.navigation-progress/UProgress.vue +12 -12
  140. package/ui.navigation-progress/types.ts +4 -3
  141. package/ui.navigation-tab/UTab.vue +18 -9
  142. package/ui.navigation-tab/storybook/stories.ts +2 -2
  143. package/ui.navigation-tab/types.ts +4 -3
  144. package/ui.navigation-tabs/UTabs.vue +13 -8
  145. package/ui.navigation-tabs/storybook/stories.ts +2 -2
  146. package/ui.navigation-tabs/types.ts +5 -5
  147. package/ui.other-dot/UDot.vue +10 -8
  148. package/ui.other-dot/storybook/stories.ts +2 -2
  149. package/ui.other-dot/types.ts +4 -3
  150. package/ui.text-alert/UAlert.vue +24 -27
  151. package/ui.text-alert/storybook/stories.ts +2 -2
  152. package/ui.text-alert/types.ts +4 -3
  153. package/ui.text-badge/UBadge.vue +25 -13
  154. package/ui.text-badge/storybook/stories.ts +2 -2
  155. package/ui.text-badge/types.ts +4 -3
  156. package/ui.text-block/UText.vue +10 -9
  157. package/ui.text-block/storybook/stories.ts +2 -2
  158. package/ui.text-block/types.ts +4 -3
  159. package/ui.text-empty/UEmpty.vue +22 -19
  160. package/ui.text-empty/storybook/stories.ts +2 -2
  161. package/ui.text-empty/types.ts +4 -3
  162. package/ui.text-file/UFile.vue +23 -20
  163. package/ui.text-file/storybook/stories.ts +2 -2
  164. package/ui.text-file/types.ts +4 -3
  165. package/ui.text-files/UFiles.vue +16 -10
  166. package/ui.text-files/storybook/stories.ts +2 -2
  167. package/ui.text-files/types.ts +4 -3
  168. package/ui.text-header/UHeader.vue +11 -11
  169. package/ui.text-header/storybook/stories.ts +2 -2
  170. package/ui.text-header/types.ts +4 -3
  171. package/ui.text-money/UMoney.vue +20 -27
  172. package/ui.text-money/storybook/stories.ts +2 -2
  173. package/ui.text-money/types.ts +4 -3
  174. package/ui.text-notify/UNotify.vue +58 -41
  175. package/ui.text-notify/config.ts +3 -3
  176. package/ui.text-notify/constants.ts +18 -20
  177. package/ui.text-notify/storybook/stories.ts +2 -2
  178. package/ui.text-notify/types.ts +10 -5
  179. package/ui.text-notify/utilNotify.ts +17 -11
  180. package/utils/helper.ts +5 -5
  181. package/utils/storybook.ts +11 -1
  182. package/utils/ui.ts +19 -9
  183. package/web-types.json +521 -368
  184. package/ui.button-link/useAttrs.ts +0 -20
  185. package/ui.button-toggle/useAttrs.ts +0 -12
  186. package/ui.button-toggle-item/useAttrs.ts +0 -29
  187. package/ui.container-accordion/useAttrs.ts +0 -26
  188. package/ui.container-card/useAttrs.ts +0 -12
  189. package/ui.container-col/useAttrs.ts +0 -12
  190. package/ui.container-divider/useAttrs.ts +0 -17
  191. package/ui.container-group/useAttrs.ts +0 -12
  192. package/ui.container-groups/useAttrs.ts +0 -12
  193. package/ui.container-modal/useAttrs.ts +0 -12
  194. package/ui.container-modal-confirm/useAttrs.ts +0 -12
  195. package/ui.container-page/useAttrs.ts +0 -12
  196. package/ui.container-row/useAttrs.ts +0 -12
  197. package/ui.data-list/useAttrs.ts +0 -12
  198. package/ui.data-table/useAttrs.ts +0 -31
  199. package/ui.dropdown-badge/useAttrs.ts +0 -26
  200. package/ui.dropdown-button/useAttrs.ts +0 -26
  201. package/ui.dropdown-link/useAttrs.ts +0 -26
  202. package/ui.dropdown-list/useAttrs.ts +0 -12
  203. package/ui.form-calendar/useAttrs.ts +0 -12
  204. package/ui.form-checkbox/useAttrs.ts +0 -29
  205. package/ui.form-checkbox-group/useAttrs.ts +0 -12
  206. package/ui.form-checkbox-multi-state/useAttrs.ts +0 -37
  207. package/ui.form-color-picker/useAttrs.ts +0 -15
  208. package/ui.form-date-picker/useAttrs.ts +0 -43
  209. package/ui.form-date-picker-range/useAttrs.ts +0 -53
  210. package/ui.form-input/useAttrs.ts +0 -31
  211. package/ui.form-input-file/useAttrs.ts +0 -21
  212. package/ui.form-input-money/useAttrs.ts +0 -15
  213. package/ui.form-input-number/useAttrs.ts +0 -15
  214. package/ui.form-input-rating/useAttrs.ts +0 -14
  215. package/ui.form-input-search/useAttrs.ts +0 -15
  216. package/ui.form-label/useAttrs.ts +0 -20
  217. package/ui.form-radio/useAttrs.ts +0 -29
  218. package/ui.form-radio-group/useAttrs.ts +0 -12
  219. package/ui.form-select/useAttrs.js +0 -19
  220. package/ui.form-switch/useAttrs.ts +0 -28
  221. package/ui.form-textarea/useAttrs.ts +0 -21
  222. package/ui.image-avatar/useAttrs.ts +0 -12
  223. package/ui.image-icon/useAttrs.ts +0 -12
  224. package/ui.loader/useAttrs.ts +0 -12
  225. package/ui.loader-overlay/useAttrs.ts +0 -12
  226. package/ui.loader-progress/useAttrs.ts +0 -12
  227. package/ui.navigation-pagination/useAttrs.ts +0 -12
  228. package/ui.navigation-progress/useAttrs.ts +0 -17
  229. package/ui.navigation-tab/useAttrs.ts +0 -28
  230. package/ui.navigation-tabs/useAttrs.ts +0 -12
  231. package/ui.other-dot/useAttrs.ts +0 -12
  232. package/ui.text-alert/useAttrs.ts +0 -12
  233. package/ui.text-badge/useAttrs.ts +0 -21
  234. package/ui.text-block/useAttrs.ts +0 -12
  235. package/ui.text-empty/useAttrs.ts +0 -12
  236. package/ui.text-file/useAttrs.ts +0 -12
  237. package/ui.text-files/useAttrs.ts +0 -12
  238. package/ui.text-header/useAttrs.ts +0 -12
  239. package/ui.text-money/useAttrs.ts +0 -12
  240. package/ui.text-notify/useAttrs.ts +0 -12
@@ -2,31 +2,22 @@
2
2
  import { computed, onBeforeUnmount, onMounted, ref } from "vue";
3
3
  import { merge } from "lodash-es";
4
4
 
5
- import { getDefault, vuelessConfig } from "../utils/ui.ts";
5
+ import useUI from "../composables/useUI.ts";
6
+ import { getDefaults, vuelessConfig } from "../utils/ui.ts";
6
7
  import { useLocale } from "../composables/useLocale.ts";
7
- import useAttrs from "./useAttrs.ts";
8
8
 
9
9
  import defaultConfig from "./config.ts";
10
- import { UNotify, NOTIFY_TYPE, POSITION } from "./constants.ts";
10
+ import { UNotify, NotificationType, NotificationPosition } from "./constants.ts";
11
11
 
12
12
  import UIcon from "../ui.image-icon/UIcon.vue";
13
13
 
14
- import type {
15
- UNotifyProps,
16
- Notification,
17
- NotifyEvent,
18
- NotificationsWrapperRef,
19
- NotificationType,
20
- } from "./types.ts";
14
+ import type { Props, Config, NotifyEvent, Notification, NotificationsWrapperRef } from "./types.ts";
15
+ import type { Transition } from "../types.ts";
21
16
 
22
17
  defineOptions({ inheritAttrs: false });
23
18
 
24
- const props = withDefaults(defineProps<UNotifyProps>(), {
25
- xPosition: getDefault<UNotifyProps>(defaultConfig, UNotify).xPosition,
26
- yPosition: getDefault<UNotifyProps>(defaultConfig, UNotify).yPosition,
27
- html: getDefault<UNotifyProps>(defaultConfig, UNotify).html,
28
- dataTest: "",
29
- config: () => ({}),
19
+ const props = withDefaults(defineProps<Props>(), {
20
+ ...getDefaults<Props, Config>(defaultConfig, UNotify),
30
21
  });
31
22
 
32
23
  const { tm } = useLocale();
@@ -39,19 +30,6 @@ const notificationsWrapperRef = ref<NotificationsWrapperRef | null>(null);
39
30
  const i18nGlobal = tm(UNotify);
40
31
  const currentLocale = computed(() => merge(defaultConfig.i18n, i18nGlobal, props.config.i18n));
41
32
 
42
- const {
43
- config,
44
- wrapperAttrs,
45
- bodyAttrs,
46
- contentAttrs,
47
- labelAttrs,
48
- descriptionAttrs,
49
- successIconAttrs,
50
- warningIconAttrs,
51
- errorIconAttrs,
52
- closeIconAttrs,
53
- } = useAttrs(props, { notifications });
54
-
55
33
  onMounted(() => {
56
34
  window.addEventListener("resize", setPosition, { passive: true });
57
35
  window.addEventListener("notifyStart", onNotifyStart);
@@ -111,22 +89,55 @@ function setPosition() {
111
89
 
112
90
  styles[props.yPosition] = "0px";
113
91
 
114
- if (props.xPosition === POSITION.center) {
92
+ if (props.xPosition === NotificationPosition.Center) {
115
93
  styles.left = `calc(50% - ${notifyWidth / 2}px)`;
116
94
  } else {
117
95
  styles[props.xPosition] = "0px";
118
96
  }
119
97
 
120
- if (pageWidth && props.xPosition !== POSITION.right) {
98
+ if (pageWidth && props.xPosition !== NotificationPosition.Right) {
121
99
  styles.left = `${asideWidth + pageWidth / 2 - notifyWidth / 2}px`;
122
100
  }
123
101
 
124
102
  notifyPositionStyles.value = styles;
125
103
  }
126
104
 
127
- function getText(notificationText: string, type: NotificationType): string {
105
+ function getText(notificationText: string, type: Notification["type"]): string {
128
106
  return notificationText || currentLocale.value[type]?.default;
129
107
  }
108
+
109
+ function getBodyAttrs(type: Notification["type"]) {
110
+ if (type === NotificationType.Success) {
111
+ return bodySuccessAttrs.value;
112
+ }
113
+
114
+ if (type === NotificationType.Warning) {
115
+ return bodyWarningAttrs.value;
116
+ }
117
+
118
+ if (type === NotificationType.Error) {
119
+ return bodyErrorAttrs.value;
120
+ }
121
+ }
122
+
123
+ /**
124
+ * Get element / nested component attributes for each config token ✨
125
+ * Applies: `class`, `config`, redefined default `props` and dev `vl-...` attributes.
126
+ */
127
+ const {
128
+ config,
129
+ wrapperAttrs,
130
+ bodySuccessAttrs,
131
+ bodyWarningAttrs,
132
+ bodyErrorAttrs,
133
+ contentAttrs,
134
+ labelAttrs,
135
+ descriptionAttrs,
136
+ successIconAttrs,
137
+ warningIconAttrs,
138
+ errorIconAttrs,
139
+ closeIconAttrs,
140
+ } = useUI<Config>(defaultConfig);
130
141
  </script>
131
142
 
132
143
  <template>
@@ -134,39 +145,44 @@ function getText(notificationText: string, type: NotificationType): string {
134
145
  ref="notificationsWrapperRef"
135
146
  :style="notifyPositionStyles"
136
147
  tag="div"
137
- v-bind="{ ...config?.transitionGroup, ...wrapperAttrs }"
148
+ v-bind="{ ...(config?.transitionGroup as Transition), ...wrapperAttrs }"
149
+ :data-test="dataTest"
138
150
  >
139
- <div v-for="notification in notifications" :key="notification.id" v-bind="bodyAttrs">
151
+ <div
152
+ v-for="notification in notifications"
153
+ :key="notification.id"
154
+ v-bind="getBodyAttrs(notification.type)"
155
+ >
140
156
  <UIcon
141
- v-if="notification.type === NOTIFY_TYPE.success"
157
+ v-if="notification.type === NotificationType.Success"
142
158
  color="green"
143
159
  variant="light"
144
160
  size="md"
145
161
  internal
146
- :name="config.defaults?.successIcon"
162
+ :name="config.defaults.successIcon"
147
163
  v-bind="successIconAttrs"
148
164
  data-test="type-notify"
149
165
  />
150
166
 
151
167
  <UIcon
152
- v-else-if="notification.type === NOTIFY_TYPE.warning"
168
+ v-else-if="notification.type === NotificationType.Warning"
153
169
  color="orange"
154
170
  variant="light"
155
171
  size="md"
156
172
  internal
157
- :name="config.defaults?.warningIcon"
173
+ :name="config.defaults.warningIcon"
158
174
  v-bind="warningIconAttrs"
159
175
  data-test="type-notify"
160
176
  />
161
177
 
162
178
  <UIcon
163
- v-else-if="notification.type === NOTIFY_TYPE.error"
179
+ v-else-if="notification.type === NotificationType.Error"
164
180
  data-test="type-notify"
165
181
  color="red"
166
182
  variant="light"
167
183
  size="md"
168
184
  internal
169
- :name="config.defaults?.errorIcon"
185
+ :name="config.defaults.errorIcon"
170
186
  v-bind="errorIconAttrs"
171
187
  />
172
188
 
@@ -194,8 +210,9 @@ function getText(notificationText: string, type: NotificationType): string {
194
210
  size="xs"
195
211
  internal
196
212
  interactive
197
- :name="config.defaults?.closeIcon"
213
+ :name="config.defaults.closeIcon"
198
214
  v-bind="closeIconAttrs"
215
+ :data-test="`${dataTest}-close`"
199
216
  @click="onClickClose(notification)"
200
217
  />
201
218
  </div>
@@ -11,9 +11,9 @@ export default /*tw*/ {
11
11
  mb-3 flex w-full items-center justify-center gap-3 rounded-2xl bg-gray-900/90
12
12
  p-4 shadow-[0_4px_16px_rgba(17,24,39,0.5)] backdrop-blur-md md:shadow-[0_0px_12px_rgba(0,0,0,0.25)]
13
13
  `,
14
- bodySuccess: "bg-[radial-gradient(100.16%_500.78%_at_0%_50%,rgba(74,222,128,0.1)_2.17%,transparent)]",
15
- bodyWarning: "bg-[radial-gradient(100.16%_500.78%_at_0%_50%,rgba(251,146,60,0.2)_2.17%,transparent)]",
16
- bodyError: "bg-[radial-gradient(100.16%_500.78%_at_0%_50%,rgba(251,113,133,0.2)_2.17%,transparent)]",
14
+ bodySuccess: "{>body} bg-[radial-gradient(100.16%_500.78%_at_0%_50%,rgba(74,222,128,0.1)_2.17%,transparent)]",
15
+ bodyWarning: "{>body} bg-[radial-gradient(100.16%_500.78%_at_0%_50%,rgba(251,146,60,0.2)_2.17%,transparent)]",
16
+ bodyError: "{>body} bg-[radial-gradient(100.16%_500.78%_at_0%_50%,rgba(251,113,133,0.2)_2.17%,transparent)]",
17
17
  content: "w-full flex flex-col max-w-full text-sm text-gray-200",
18
18
  label: "mb-0.5 font-medium",
19
19
  description: "break-words font-normal",
@@ -3,27 +3,25 @@
3
3
  `defineProps` is referencing locally declared variables. (vue/valid-define-props)
4
4
  */
5
5
  export const UNotify = "UNotify";
6
-
7
6
  export const LOCAL_STORAGE_ID = "vueless:notify";
7
+ export const DELAY_BETWEEN_CLONES = 1000;
8
8
 
9
- export const NOTIFY_TYPE = {
10
- success: "success",
11
- warning: "warning",
12
- error: "error",
13
- };
14
-
15
- export const POSITION = {
16
- left: "left",
17
- right: "right",
18
- top: "top",
19
- bottom: "bottom",
20
- center: "center",
21
- };
9
+ export enum NotificationType {
10
+ Success = "success",
11
+ Warning = "warning",
12
+ Error = "error",
13
+ }
22
14
 
23
- export const DURATION = {
24
- short: 4000,
25
- medium: 8000,
26
- long: 12000,
27
- };
15
+ export enum NotificationPosition {
16
+ Left = "left",
17
+ Right = "right",
18
+ Top = "top",
19
+ Bottom = "bottom",
20
+ Center = "center",
21
+ }
28
22
 
29
- export const DELAY_BETWEEN_CLONES = 1000;
23
+ export enum NotificationDuration {
24
+ Short = 4000,
25
+ Medium = 8000,
26
+ Long = 12000,
27
+ }
@@ -12,9 +12,9 @@ import UButton from "../../ui.button/UButton.vue";
12
12
  import UCol from "../../ui.container-col/UCol.vue";
13
13
 
14
14
  import type { Meta, StoryFn } from "@storybook/vue3";
15
- import type { UNotifyProps } from "../types.ts";
15
+ import type { Props } from "../types.ts";
16
16
 
17
- interface UNotifyArgs extends UNotifyProps {
17
+ interface UNotifyArgs extends Props {
18
18
  slotTemplate?: string;
19
19
  }
20
20
 
@@ -1,8 +1,8 @@
1
1
  import defaultConfig from "./config.ts";
2
+ import type { ComponentConfig } from "../types.ts";
3
+ import { NotificationType } from "./constants.ts";
2
4
 
3
- export type Config = Partial<typeof defaultConfig>;
4
-
5
- export type NotificationType = "success" | "warning" | "error";
5
+ export type Config = typeof defaultConfig;
6
6
 
7
7
  export type Notification = {
8
8
  id: string;
@@ -26,7 +26,7 @@ declare global {
26
26
  }
27
27
  }
28
28
 
29
- export interface UNotifyProps {
29
+ export interface Props {
30
30
  /**
31
31
  * A position on the x-axis.
32
32
  */
@@ -45,5 +45,10 @@ export interface UNotifyProps {
45
45
  /**
46
46
  * Component config object.
47
47
  */
48
- config?: Config;
48
+ config?: ComponentConfig<Config>;
49
+
50
+ /**
51
+ * Data-test attribute for automated testing.
52
+ */
53
+ dataTest?: string;
49
54
  }
@@ -1,9 +1,14 @@
1
1
  import { vuelessConfig } from "../utils/ui.ts";
2
2
  import { getRandomId } from "../utils/helper.ts";
3
- import { DELAY_BETWEEN_CLONES, DURATION, LOCAL_STORAGE_ID, NOTIFY_TYPE } from "./constants.ts";
3
+ import {
4
+ LOCAL_STORAGE_ID,
5
+ DELAY_BETWEEN_CLONES,
6
+ NotificationDuration,
7
+ NotificationType,
8
+ } from "./constants.ts";
4
9
 
5
10
  interface NotifyConfig {
6
- type?: (typeof NOTIFY_TYPE)[keyof typeof NOTIFY_TYPE];
11
+ type?: NotificationType;
7
12
  label?: string;
8
13
  description?: string;
9
14
  duration?: number;
@@ -11,7 +16,7 @@ interface NotifyConfig {
11
16
  }
12
17
 
13
18
  interface NotifyEventDetail {
14
- type: (typeof NOTIFY_TYPE)[keyof typeof NOTIFY_TYPE];
19
+ type: NotificationType;
15
20
  id: string;
16
21
  label: string;
17
22
  description: string;
@@ -39,7 +44,8 @@ export function notify({
39
44
  duration,
40
45
  ignoreDuplicates,
41
46
  }: NotifyConfig = {}): void {
42
- const notifyDuration: number = duration || globalNotifyDuration?.short || DURATION.short;
47
+ const notifyDuration: number =
48
+ duration || globalNotifyDuration?.short || NotificationDuration.Short;
43
49
 
44
50
  const isSameMessage = Boolean(
45
51
  lastMessage === description &&
@@ -55,7 +61,7 @@ export function notify({
55
61
  lastMessage = description;
56
62
 
57
63
  const eventDetail: NotifyEventDetail = {
58
- type: type as (typeof NOTIFY_TYPE)[keyof typeof NOTIFY_TYPE],
64
+ type: type as NotificationType,
59
65
  id: getRandomId(),
60
66
  label,
61
67
  description,
@@ -84,8 +90,8 @@ export function notifySuccess({
84
90
  label,
85
91
  description,
86
92
  ignoreDuplicates,
87
- type: NOTIFY_TYPE.success,
88
- duration: duration || globalNotifyDuration?.short || DURATION.short,
93
+ type: NotificationType.Success,
94
+ duration: duration || globalNotifyDuration?.short || NotificationDuration.Short,
89
95
  });
90
96
  }
91
97
 
@@ -99,8 +105,8 @@ export function notifyWarning({
99
105
  label,
100
106
  description,
101
107
  ignoreDuplicates,
102
- type: NOTIFY_TYPE.warning,
103
- duration: duration || globalNotifyDuration?.medium || DURATION.medium,
108
+ type: NotificationType.Warning,
109
+ duration: duration || globalNotifyDuration?.medium || NotificationDuration.Medium,
104
110
  });
105
111
  }
106
112
 
@@ -114,8 +120,8 @@ export function notifyError({
114
120
  label,
115
121
  description,
116
122
  ignoreDuplicates,
117
- type: NOTIFY_TYPE.error,
118
- duration: duration || globalNotifyDuration?.long || DURATION.long,
123
+ type: NotificationType.Error,
124
+ duration: duration || globalNotifyDuration?.long || NotificationDuration.Long,
119
125
  });
120
126
  }
121
127
 
package/utils/helper.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import type { UnknownObject } from "../types.ts";
1
2
  import { Comment, Text, Fragment } from "vue";
2
3
 
3
4
  import type { Slot, VNode } from "vue";
@@ -5,7 +6,7 @@ import type { Slot, VNode } from "vue";
5
6
  /**
6
7
  * Deeply clone given object (same as lodash.cloneDeep).
7
8
  */
8
- export function cloneDeep(entity: unknown, cache = new WeakMap()): unknown {
9
+ export function cloneDeep(entity: unknown, cache = new WeakMap()): unknown | UnknownObject {
9
10
  // primitives
10
11
  if (Object(entity) !== entity || !entity) {
11
12
  return entity;
@@ -42,13 +43,12 @@ export function cloneDeep(entity: unknown, cache = new WeakMap()): unknown {
42
43
  /**
43
44
  * Creates a debounced function with delay (same as lodash.debounce).
44
45
  */
45
- export function createDebounce(func: () => void, ms: number) {
46
+ export function createDebounce<T extends unknown[]>(func: (...args: T) => void, ms: number) {
46
47
  let timeout: ReturnType<typeof setTimeout>;
47
48
 
48
- return function (...args: []) {
49
+ return function (this: unknown, ...args: T) {
49
50
  clearTimeout(timeout);
50
- // @ts-expect-error - this implicitly has type any because it does not have a type annotation.
51
- timeout = setTimeout(() => func.apply(this as unknown, args), ms);
51
+ timeout = setTimeout(() => func.apply(this, args), ms);
52
52
  };
53
53
  }
54
54
 
@@ -14,7 +14,7 @@ interface Types {
14
14
  }
15
15
 
16
16
  export interface ArgType {
17
- control?: "text" | "date" | "number" | "boolean" | "array" | "select" | false;
17
+ control?: "text" | "date" | "number" | "boolean" | "array" | "select" | "object" | false;
18
18
  options?: string[];
19
19
  table?: TableConfig;
20
20
  name?: string;
@@ -113,6 +113,16 @@ export function getArgTypes(componentName: string | undefined) {
113
113
  };
114
114
  }
115
115
 
116
+ if (attribute.enum?.length === 1) {
117
+ types[attribute.name] = {
118
+ control: "object",
119
+ table: {
120
+ defaultValue: { summary: attribute.default || "" },
121
+ type: { summary: attribute.enum.join(" | ") },
122
+ },
123
+ };
124
+ }
125
+
116
126
  if (type === "string" || type.includes("string")) {
117
127
  types[attribute.name] = {
118
128
  control: "text",
package/utils/ui.ts CHANGED
@@ -8,6 +8,7 @@ import {
8
8
  GRAYSCALE_COLOR,
9
9
  DEFAULT_BRAND_COLOR,
10
10
  TAILWIND_MERGE_EXTENSION,
11
+ SYSTEM_NON_PROPS_DEFAULTS,
11
12
  NESTED_COMPONENT_PATTERN_REG_EXP,
12
13
  } from "../constants.js";
13
14
 
@@ -21,13 +22,13 @@ import type {
21
22
  } from "../types.ts";
22
23
 
23
24
  interface MergedConfigOptions {
24
- defaultConfig: Component;
25
- globalConfig: Component;
26
- propsConfig?: Component;
25
+ defaultConfig: unknown;
26
+ globalConfig: unknown;
27
+ propsConfig?: unknown;
27
28
  vuelessStrategy?: Strategies;
28
29
  }
29
30
 
30
- type getMergedConfig = (options: MergedConfigOptions) => Component;
31
+ type GetMergedConfig = (options: MergedConfigOptions) => unknown;
31
32
 
32
33
  /**
33
34
  * Load Vueless config from the project root.
@@ -82,7 +83,7 @@ export const {
82
83
  },
83
84
  });
84
85
 
85
- export const getMergedConfig = createGetMergedConfig(cx) as getMergedConfig;
86
+ export const getMergedConfig = createGetMergedConfig(cx) as GetMergedConfig;
86
87
 
87
88
  /* This allows skipping some CVA config keys in vueless config. */
88
89
  export const cva = ({ base = "", variants = {}, compoundVariants = [], defaultVariants = {} }) =>
@@ -111,23 +112,32 @@ export function getDefault<T>(defaultConfig: Component, name: ComponentNames) {
111
112
  return {
112
113
  ...defaults,
113
114
  dataTest: "",
114
- config: () => {},
115
+ config: () => ({}),
115
116
  };
116
117
  }
117
118
 
118
119
  /**
119
120
  * Return default values for component props, icons, etc..
120
121
  */
121
- export function getDefaults<T>(defaultConfig: Component, name: ComponentNames) {
122
- const componentDefaults = cloneDeep(defaultConfig.defaults) || {};
122
+ export function getDefaults<Props, Config>(defaultConfig: Config, name: ComponentNames) {
123
+ const componentDefaults = cloneDeep((defaultConfig as Component).defaults) || {};
123
124
  const globalDefaults = cloneDeep(vuelessConfig.component?.[name]?.defaults) || {};
124
125
 
125
- const defaults = merge(componentDefaults, globalDefaults) as T & Defaults;
126
+ const defaults = merge(componentDefaults, globalDefaults) as Props & Defaults;
126
127
 
127
128
  if (defaults.color) {
128
129
  defaults.color = getColor(defaults.color as BrandColors);
129
130
  }
130
131
 
132
+ /* Remove non a props defaults. */
133
+ for (const key in defaults) {
134
+ const isNonPropIcon = /Icon/.test(key) && !/(leftIcon|rightIcon)/.test(key);
135
+
136
+ if (SYSTEM_NON_PROPS_DEFAULTS.includes(key) || isNonPropIcon) {
137
+ delete defaults[key];
138
+ }
139
+ }
140
+
131
141
  return {
132
142
  ...defaults,
133
143
  dataTest: "",