@veltra/mobile 1.0.0 → 1.1.0

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 (245) hide show
  1. package/package.json +32 -6
  2. package/src/components/_internal/bottom-sheet/bottom-sheet.vue +81 -0
  3. package/src/components/_internal/bottom-sheet/index.ts +1 -0
  4. package/src/components/_internal/bottom-sheet/style.scss +116 -0
  5. package/src/components/_internal/bottom-sheet/style.ts +1 -0
  6. package/src/components/_internal/overlay-container.ts +34 -0
  7. package/src/components/avatar/avatar.vue +44 -0
  8. package/src/components/avatar/index.ts +1 -0
  9. package/src/components/avatar/style.scss +53 -0
  10. package/src/components/avatar/style.ts +1 -0
  11. package/src/components/badge/badge.vue +59 -0
  12. package/src/components/badge/index.ts +1 -0
  13. package/src/components/badge/style.scss +62 -0
  14. package/src/components/badge/style.ts +1 -0
  15. package/src/components/button/button.vue +76 -0
  16. package/src/components/button/index.ts +1 -0
  17. package/src/components/button/style.scss +207 -0
  18. package/src/components/button/style.ts +1 -0
  19. package/src/components/card/card.vue +24 -0
  20. package/src/components/card/index.ts +1 -0
  21. package/src/components/card/style.scss +35 -0
  22. package/src/components/card/style.ts +1 -0
  23. package/src/components/cascade/cascade.vue +595 -0
  24. package/src/components/cascade/index.ts +1 -0
  25. package/src/components/cascade/node.ts +29 -0
  26. package/src/components/cascade/style.scss +424 -0
  27. package/src/components/cascade/style.ts +2 -0
  28. package/src/components/check-tag/check-tag.vue +35 -0
  29. package/src/components/check-tag/index.ts +1 -0
  30. package/src/components/check-tag/style.scss +46 -0
  31. package/src/components/check-tag/style.ts +1 -0
  32. package/src/components/checkbox/checkbox.vue +67 -0
  33. package/src/components/checkbox/index.ts +1 -0
  34. package/src/components/checkbox/style.scss +132 -0
  35. package/src/components/checkbox/style.ts +2 -0
  36. package/src/components/checkbox-group/checkbox-group.vue +94 -0
  37. package/src/components/checkbox-group/index.ts +1 -0
  38. package/src/components/checkbox-group/style.scss +57 -0
  39. package/src/components/checkbox-group/style.ts +2 -0
  40. package/src/components/collapse/collapse-item.vue +134 -0
  41. package/src/components/collapse/collapse.vue +117 -0
  42. package/src/components/collapse/di.ts +18 -0
  43. package/src/components/collapse/index.ts +3 -0
  44. package/src/components/collapse/style.scss +157 -0
  45. package/src/components/collapse/style.ts +1 -0
  46. package/src/components/date-picker/date-picker.vue +326 -0
  47. package/src/components/date-picker/index.ts +1 -0
  48. package/src/components/date-picker/style.scss +236 -0
  49. package/src/components/date-picker/style.ts +2 -0
  50. package/src/components/descriptions/descriptions-item.vue +12 -0
  51. package/src/components/descriptions/descriptions.vue +50 -0
  52. package/src/components/descriptions/index.ts +2 -0
  53. package/src/components/descriptions/style.scss +120 -0
  54. package/src/components/descriptions/style.ts +1 -0
  55. package/src/components/dialog/dialog.vue +143 -0
  56. package/src/components/dialog/index.ts +1 -0
  57. package/src/components/dialog/style.scss +163 -0
  58. package/src/components/dialog/style.ts +4 -0
  59. package/src/components/divider/divider.vue +29 -0
  60. package/src/components/divider/index.ts +1 -0
  61. package/src/components/divider/style.scss +91 -0
  62. package/src/components/divider/style.ts +1 -0
  63. package/src/components/drawer/drawer.vue +168 -0
  64. package/src/components/drawer/index.ts +1 -0
  65. package/src/components/drawer/style.scss +240 -0
  66. package/src/components/drawer/style.ts +2 -0
  67. package/src/components/empty/empty.vue +22 -0
  68. package/src/components/empty/index.ts +1 -0
  69. package/src/components/empty/style.scss +36 -0
  70. package/src/components/empty/style.ts +1 -0
  71. package/src/components/form/form.vue +119 -0
  72. package/src/components/form/index.ts +1 -0
  73. package/src/components/form/is-field-modified.ts +16 -0
  74. package/src/components/form/style.scss +58 -0
  75. package/src/components/form/style.ts +2 -0
  76. package/src/components/form/use-form-fields.ts +115 -0
  77. package/src/components/form/use-node-interceptor.ts +101 -0
  78. package/src/components/form-item/form-item.vue +171 -0
  79. package/src/components/form-item/helper.ts +9 -0
  80. package/src/components/form-item/index.ts +1 -0
  81. package/src/components/form-item/style.scss +121 -0
  82. package/src/components/form-item/style.ts +1 -0
  83. package/src/components/form-item/validate.ts +131 -0
  84. package/src/components/icon/icon.vue +23 -0
  85. package/src/components/icon/index.ts +1 -0
  86. package/src/components/icon/style.scss +37 -0
  87. package/src/components/icon/style.ts +1 -0
  88. package/src/components/input/index.ts +1 -0
  89. package/src/components/input/input.vue +187 -0
  90. package/src/components/input/style.scss +121 -0
  91. package/src/components/input/style.ts +1 -0
  92. package/src/components/list/index.ts +3 -0
  93. package/src/components/list/list-item.vue +20 -0
  94. package/src/components/list/list.vue +20 -0
  95. package/src/components/list/style.scss +50 -0
  96. package/src/components/list/style.ts +1 -0
  97. package/src/components/loading/directive.ts +34 -0
  98. package/src/components/loading/index.ts +3 -0
  99. package/src/components/loading/loading.vue +25 -0
  100. package/src/components/loading/style.scss +179 -0
  101. package/src/components/loading/style.ts +2 -0
  102. package/src/components/message/helper.ts +28 -0
  103. package/src/components/message/index.ts +3 -0
  104. package/src/components/message/message-box.vue +31 -0
  105. package/src/components/message/message.ts +122 -0
  106. package/src/components/message/message.vue +54 -0
  107. package/src/components/message/style.scss +130 -0
  108. package/src/components/message/style.ts +1 -0
  109. package/src/components/message-confirm/index.ts +3 -0
  110. package/src/components/message-confirm/message-confirm-box.vue +36 -0
  111. package/src/components/message-confirm/message-confirm.ts +139 -0
  112. package/src/components/message-confirm/message-confirm.vue +53 -0
  113. package/src/components/message-confirm/style.scss +138 -0
  114. package/src/components/message-confirm/style.ts +1 -0
  115. package/src/components/multi-select/index.ts +1 -0
  116. package/src/components/multi-select/multi-select.vue +410 -0
  117. package/src/components/multi-select/style.scss +376 -0
  118. package/src/components/multi-select/style.ts +2 -0
  119. package/src/components/number-input/index.ts +1 -0
  120. package/src/components/number-input/number-input.vue +407 -0
  121. package/src/components/number-input/style.scss +118 -0
  122. package/src/components/number-input/style.ts +2 -0
  123. package/src/components/password-input/index.ts +1 -0
  124. package/src/components/password-input/password-input.vue +134 -0
  125. package/src/components/password-input/style.scss +40 -0
  126. package/src/components/password-input/style.ts +2 -0
  127. package/src/components/progress/index.ts +1 -0
  128. package/src/components/progress/progress.vue +90 -0
  129. package/src/components/progress/style.scss +73 -0
  130. package/src/components/progress/style.ts +1 -0
  131. package/src/components/radio/index.ts +1 -0
  132. package/src/components/radio/radio.vue +57 -0
  133. package/src/components/radio/style.scss +113 -0
  134. package/src/components/radio/style.ts +1 -0
  135. package/src/components/radio-group/index.ts +1 -0
  136. package/src/components/radio-group/radio-group.vue +60 -0
  137. package/src/components/radio-group/style.scss +29 -0
  138. package/src/components/radio-group/style.ts +2 -0
  139. package/src/components/segment/index.ts +1 -0
  140. package/src/components/segment/segment.vue +121 -0
  141. package/src/components/segment/style.scss +118 -0
  142. package/src/components/segment/style.ts +1 -0
  143. package/src/components/select/index.ts +1 -0
  144. package/src/components/select/select.vue +278 -0
  145. package/src/components/select/style.scss +237 -0
  146. package/src/components/select/style.ts +2 -0
  147. package/src/components/select/use-options.ts +195 -0
  148. package/src/components/skeleton/index.ts +1 -0
  149. package/src/components/skeleton/skeleton.vue +37 -0
  150. package/src/components/skeleton/style.scss +95 -0
  151. package/src/components/skeleton/style.ts +1 -0
  152. package/src/components/space/index.ts +1 -0
  153. package/src/components/space/space.vue +45 -0
  154. package/src/components/space/style.scss +41 -0
  155. package/src/components/space/style.ts +1 -0
  156. package/src/components/steps/index.ts +1 -0
  157. package/src/components/steps/steps.vue +114 -0
  158. package/src/components/steps/style.scss +231 -0
  159. package/src/components/steps/style.ts +1 -0
  160. package/src/components/switch/index.ts +1 -0
  161. package/src/components/switch/style.scss +137 -0
  162. package/src/components/switch/style.ts +1 -0
  163. package/src/components/switch/switch.vue +63 -0
  164. package/src/components/tabs/index.ts +1 -0
  165. package/src/components/tabs/style.scss +285 -0
  166. package/src/components/tabs/style.ts +1 -0
  167. package/src/components/tabs/tabs.vue +127 -0
  168. package/src/components/tag/index.ts +1 -0
  169. package/src/components/tag/style.scss +114 -0
  170. package/src/components/tag/style.ts +1 -0
  171. package/src/components/tag/tag.vue +49 -0
  172. package/src/components/text/index.ts +1 -0
  173. package/src/components/text/style.scss +63 -0
  174. package/src/components/text/style.ts +1 -0
  175. package/src/components/text/text.vue +63 -0
  176. package/src/components/textarea/index.ts +1 -0
  177. package/src/components/textarea/style.scss +124 -0
  178. package/src/components/textarea/style.ts +1 -0
  179. package/src/components/textarea/textarea.vue +121 -0
  180. package/src/components/textarea/utils.ts +11 -0
  181. package/src/components/time-picker/index.ts +1 -0
  182. package/src/components/time-picker/style.scss +216 -0
  183. package/src/components/time-picker/style.ts +2 -0
  184. package/src/components/time-picker/time-picker.vue +263 -0
  185. package/src/components/timeline/index.ts +2 -0
  186. package/src/components/timeline/style.scss +107 -0
  187. package/src/components/timeline/style.ts +1 -0
  188. package/src/components/timeline/timeline-item.vue +43 -0
  189. package/src/components/timeline/timeline.vue +16 -0
  190. package/src/components/uploader/index.ts +1 -0
  191. package/src/components/uploader/style.scss +220 -0
  192. package/src/components/uploader/style.ts +1 -0
  193. package/src/components/uploader/uploader.vue +306 -0
  194. package/src/env.d.ts +7 -0
  195. package/src/index.ts +99 -1
  196. package/src/shared/bem.ts +12 -0
  197. package/src/shared/use-scroll-lock.ts +111 -0
  198. package/src/shared/use-touch-gesture.ts +150 -0
  199. package/src/styles/_tokens.scss +129 -0
  200. package/src/types/avatar.ts +31 -0
  201. package/src/types/badge.ts +28 -0
  202. package/src/types/button.ts +48 -0
  203. package/src/types/card.ts +16 -0
  204. package/src/types/cascade.ts +87 -0
  205. package/src/types/check-tag.ts +24 -0
  206. package/src/types/checkbox-group.ts +20 -0
  207. package/src/types/checkbox.ts +15 -0
  208. package/src/types/collapse.ts +79 -0
  209. package/src/types/date-picker.ts +39 -0
  210. package/src/types/descriptions.ts +22 -0
  211. package/src/types/dialog.ts +54 -0
  212. package/src/types/divider.ts +14 -0
  213. package/src/types/drawer.ts +38 -0
  214. package/src/types/empty.ts +19 -0
  215. package/src/types/form-item.ts +22 -0
  216. package/src/types/form.ts +54 -0
  217. package/src/types/icon.ts +10 -0
  218. package/src/types/input.ts +51 -0
  219. package/src/types/list.ts +13 -0
  220. package/src/types/loading.ts +20 -0
  221. package/src/types/message-confirm.ts +72 -0
  222. package/src/types/message.ts +71 -0
  223. package/src/types/multi-select.ts +38 -0
  224. package/src/types/number-input.ts +32 -0
  225. package/src/types/password-input.ts +19 -0
  226. package/src/types/progress.ts +22 -0
  227. package/src/types/radio-group.ts +33 -0
  228. package/src/types/radio.ts +18 -0
  229. package/src/types/segment.ts +42 -0
  230. package/src/types/select.ts +63 -0
  231. package/src/types/skeleton.ts +29 -0
  232. package/src/types/space.ts +22 -0
  233. package/src/types/steps.ts +67 -0
  234. package/src/types/switch.ts +17 -0
  235. package/src/types/tabs.ts +63 -0
  236. package/src/types/tag.ts +19 -0
  237. package/src/types/text.ts +28 -0
  238. package/src/types/textarea.ts +76 -0
  239. package/src/types/time-picker.ts +40 -0
  240. package/src/types/timeline.ts +15 -0
  241. package/src/types/uploader.ts +50 -0
  242. package/.turbo/turbo-build.log +0 -2
  243. package/.turbo/turbo-check-types.log +0 -1
  244. package/tsconfig.json +0 -12
  245. package/tsconfig.tsbuildinfo +0 -1
@@ -0,0 +1,50 @@
1
+ @use 'pkg:@veltra/styles/mixins' as m with ($namespace: um);
2
+ @use 'pkg:@veltra/styles/functions' as fn;
3
+ @use '../../styles/tokens' as t;
4
+
5
+ $root-name: list;
6
+ $item-name: $root-name + '-item';
7
+
8
+ // 移动端列表:无滚动包装层,原生 ul/li 直接承载滚动;
9
+ // 行高、字号、行间距走 --um-* 密度 token,行高保底 44px 触控热区
10
+ @include m.b($root-name) {
11
+ margin: 0;
12
+ padding: 0;
13
+ list-style: none;
14
+
15
+ // 行基础形态(与尺寸档无关)+ 可点行按压态
16
+ @include m.bem($item-name) {
17
+ display: flex;
18
+ align-items: center;
19
+ line-height: 1.4;
20
+ font-size: t.use-var(font-size-main);
21
+
22
+ // 绑定 @click 即视为可点行:移动端无 hover,用 :active 提供按压反馈
23
+ @include m.is(clickable) {
24
+ -webkit-tap-highlight-color: transparent;
25
+
26
+ &:active {
27
+ background-color: fn.use-var(bg-color, hover);
28
+ }
29
+ }
30
+ }
31
+
32
+ // 尺寸档:行高取控件高度档并保底 44px,横向内边距走间距刻度
33
+ @include m.size using ($size) {
34
+ @include m.bem($item-name) {
35
+ $padding: t.use-var(spacing-lg);
36
+
37
+ @if $size == small {
38
+ $padding: t.use-var(spacing-md);
39
+ }
40
+
41
+ @if $size == large {
42
+ $padding: t.use-var(spacing-xl);
43
+ }
44
+
45
+ padding: 0 $padding;
46
+ border-radius: t.control-radius($size);
47
+ min-height: max(t.control-height($size), t.use-var(touch-target));
48
+ }
49
+ }
50
+ }
@@ -0,0 +1 @@
1
+ import './style.scss'
@@ -0,0 +1,34 @@
1
+ import { createVNode, render, type DirectiveBinding, type ObjectDirective } from 'vue'
2
+
3
+ import { bem } from '../../shared/bem'
4
+ import type { LoadingType } from '../../types/loading'
5
+ import LoadingComponent from './loading.vue'
6
+
7
+ const loadingCls = bem('loading')
8
+ const loadingContainerCls = loadingCls.e('container')
9
+
10
+ function renderLoading(el: HTMLElement, binding: DirectiveBinding) {
11
+ el.classList.add(loadingContainerCls)
12
+
13
+ const node = createVNode(LoadingComponent, { type: binding.arg as LoadingType })
14
+
15
+ render(node, el)
16
+ }
17
+
18
+ function removeLoading(el: HTMLElement) {
19
+ render(null, el)
20
+ el.classList.remove(loadingContainerCls)
21
+ }
22
+ export const vLoading: ObjectDirective<HTMLElement> = {
23
+ mounted(el, binding) {
24
+ binding.value && renderLoading(el, binding)
25
+ },
26
+
27
+ updated(el, binding) {
28
+ binding.value ? renderLoading(el, binding) : removeLoading(el)
29
+ },
30
+
31
+ unmounted(el) {
32
+ removeLoading(el)
33
+ }
34
+ }
@@ -0,0 +1,3 @@
1
+ export { default as ULoading } from './loading.vue'
2
+
3
+ export { vLoading } from './directive'
@@ -0,0 +1,25 @@
1
+ <template>
2
+ <transition name="fade" appear>
3
+ <div :class="className" :style="{ zIndex: zIndex() }">
4
+ <div :class="cls.e('loader')"></div>
5
+ </div>
6
+ </transition>
7
+ </template>
8
+
9
+ <script lang="ts" setup>
10
+ import { zIndex } from '@veltra/utils'
11
+ import { computed } from 'vue'
12
+
13
+ import { bem } from '../../shared/bem'
14
+ import type { LoadingProps } from '../../types/loading'
15
+
16
+ defineOptions({ name: 'ULoading' })
17
+
18
+ const props = withDefaults(defineProps<LoadingProps>(), { type: 'dual-ring' })
19
+
20
+ const cls = bem('loading')
21
+
22
+ const className = computed(() => {
23
+ return [cls.b, cls.e(props.type)]
24
+ })
25
+ </script>
@@ -0,0 +1,179 @@
1
+ @use 'pkg:@veltra/styles/mixins' as m with ($namespace: um);
2
+ @use 'pkg:@veltra/styles/functions' as fn;
3
+ @use '../../styles/tokens' as t;
4
+
5
+ $root-name: loading;
6
+
7
+ // 指示器基准边长:走 --um-* 密度 token,各形态几何按其比例推导
8
+ $indicator: t.use-var(loading-indicator);
9
+ // 环形描边与内环参数(比例常量)
10
+ $ring-border: calc(#{$indicator} / 12);
11
+ $ring-inner-border: calc(#{$indicator} / 18);
12
+ $ring-inner-inset: calc(#{$indicator} / 6);
13
+ // 三点 / 竖条的单元尺寸(比例常量)
14
+ $dot-size: calc(#{$indicator} / 4);
15
+ $dot-gap: calc(#{$indicator} / 6);
16
+ $bar-width: calc(#{$indicator} / 6);
17
+ $bar-height: calc(#{$indicator} * 3 / 4);
18
+
19
+ @include m.b($root-name) {
20
+ position: absolute;
21
+ width: 100%;
22
+ height: 100%;
23
+ background-color: fn.use-var(bg-color, top, alpha);
24
+ color: fn.use-var(color, primary);
25
+ @include m.flex($justify: center, $align: center);
26
+
27
+ @include m.e(container) {
28
+ position: relative;
29
+ }
30
+
31
+ // ============================================================
32
+ // dual-ring — 双环反向旋转(经典 loader)
33
+ // 外环顺时针,内嵌小环逆时针,border + linear 旋转无缝循环
34
+ // ============================================================
35
+ @include m.e(dual-ring) {
36
+ @include m.bem($root-name, loader) {
37
+ width: $indicator;
38
+ aspect-ratio: 1;
39
+ border-radius: 50%;
40
+ border: #{$ring-border} solid fn.color-a(color, 22, primary);
41
+ border-top-color: currentColor;
42
+ position: relative;
43
+ animation: um-loading-spin 0.8s linear infinite;
44
+
45
+ &::after {
46
+ content: '';
47
+ position: absolute;
48
+ inset: $ring-inner-inset;
49
+ border-radius: 50%;
50
+ border: #{$ring-inner-border} solid fn.color-a(color, 22, primary);
51
+ border-bottom-color: currentColor;
52
+ animation: um-loading-spin 1.2s linear infinite reverse;
53
+ }
54
+ }
55
+ }
56
+
57
+ // ============================================================
58
+ // dot — 三点呼吸弹跳
59
+ // 元素自身 + 两个伪元素,交错起伏
60
+ // ============================================================
61
+ @include m.e(dot) {
62
+ @include m.bem($root-name, loader) {
63
+ width: $dot-size;
64
+ height: $dot-size;
65
+ border-radius: 50%;
66
+ background: currentColor;
67
+ position: relative;
68
+ animation: um-loading-dot 1.2s cubic-bezier(0.45, 0, 0.55, 1) infinite;
69
+
70
+ &::before,
71
+ &::after {
72
+ content: '';
73
+ position: absolute;
74
+ top: 0;
75
+ width: $dot-size;
76
+ height: $dot-size;
77
+ border-radius: 50%;
78
+ background: currentColor;
79
+ }
80
+
81
+ &::before {
82
+ left: calc(-1 * (#{$dot-size} + #{$dot-gap}));
83
+ animation: um-loading-dot 1.2s cubic-bezier(0.45, 0, 0.55, 1) infinite;
84
+ animation-delay: 0.18s;
85
+ }
86
+
87
+ &::after {
88
+ right: calc(-1 * (#{$dot-size} + #{$dot-gap}));
89
+ animation: um-loading-dot 1.2s cubic-bezier(0.45, 0, 0.55, 1) infinite;
90
+ animation-delay: 0.36s;
91
+ }
92
+ }
93
+ }
94
+
95
+ // ============================================================
96
+ // ring — 单环旋转
97
+ // ============================================================
98
+ @include m.e(ring) {
99
+ @include m.bem($root-name, loader) {
100
+ width: $indicator;
101
+ aspect-ratio: 1;
102
+ border-radius: 50%;
103
+ border: #{$ring-border} solid fn.color-a(color, 22, primary);
104
+ border-top-color: currentColor;
105
+ animation: um-loading-spin 0.9s linear infinite;
106
+ }
107
+ }
108
+
109
+ // ============================================================
110
+ // bars — 三条音频跳动
111
+ // 三根竖条以容器中心为基准上下对称伸缩
112
+ // ============================================================
113
+ @include m.e(bars) {
114
+ @include m.bem($root-name, loader) {
115
+ width: $bar-width;
116
+ height: $bar-height;
117
+ background: currentColor;
118
+ border-radius: calc(#{$bar-width} / 2);
119
+ position: relative;
120
+ animation: um-loading-bars 1s ease-in-out infinite;
121
+ animation-delay: 0.15s;
122
+
123
+ &::before,
124
+ &::after {
125
+ content: '';
126
+ position: absolute;
127
+ top: 50%;
128
+ transform: translateY(-50%);
129
+ width: $bar-width;
130
+ height: $bar-height;
131
+ background: currentColor;
132
+ border-radius: calc(#{$bar-width} / 2);
133
+ animation: um-loading-bars 1s ease-in-out infinite;
134
+ }
135
+
136
+ &::before {
137
+ left: calc(-1 * (#{$bar-width} + #{$dot-gap}));
138
+ }
139
+
140
+ &::after {
141
+ right: calc(-1 * (#{$bar-width} + #{$dot-gap}));
142
+ animation-delay: 0.3s;
143
+ }
144
+ }
145
+ }
146
+ }
147
+
148
+ // ================================================================
149
+ // 关键帧
150
+ // ================================================================
151
+
152
+ @keyframes um-loading-spin {
153
+ to {
154
+ transform: rotate(1turn);
155
+ }
156
+ }
157
+
158
+ @keyframes um-loading-dot {
159
+ 0%,
160
+ 100% {
161
+ transform: scale(0.5);
162
+ opacity: 0.3;
163
+ }
164
+ 50% {
165
+ transform: scale(1);
166
+ opacity: 1;
167
+ }
168
+ }
169
+
170
+ // 竖条伸缩的上下限按指示器基准推导(CSS 变量在关键帧内按动画元素解析)
171
+ @keyframes um-loading-bars {
172
+ 0%,
173
+ 100% {
174
+ height: calc(#{$indicator} / 4);
175
+ }
176
+ 50% {
177
+ height: $bar-height;
178
+ }
179
+ }
@@ -0,0 +1,2 @@
1
+ import '@veltra/styles/transitions/fade.scss'
2
+ import './style.scss'
@@ -0,0 +1,28 @@
1
+ import {
2
+ CircleCheckFilled,
3
+ CircleClose,
4
+ InfoFilled,
5
+ QuestionFilled,
6
+ WarningFilled
7
+ } from '@veltra/icons/normal'
8
+ import type { ColorType } from '@veltra/utils'
9
+ import type { DefineComponent } from 'vue'
10
+
11
+ import type { MessageType } from '../../types/message'
12
+
13
+ const typeIcons = {
14
+ default: InfoFilled,
15
+ info: QuestionFilled,
16
+ success: CircleCheckFilled,
17
+ warn: WarningFilled,
18
+ error: CircleClose
19
+ }
20
+ export function getTypeIcon(type: MessageType, icon?: DefineComponent): DefineComponent {
21
+ return (icon ?? typeIcons[type]) as any
22
+ }
23
+
24
+ const typeColors = { error: 'danger', warn: 'warning' }
25
+
26
+ export function getTypeColor(type: MessageType): ColorType {
27
+ return typeColors[type] ?? type
28
+ }
@@ -0,0 +1,3 @@
1
+ export { default as UMessage } from './message.vue'
2
+
3
+ export { message } from './message'
@@ -0,0 +1,31 @@
1
+ <template>
2
+ <transition-group name="message" appear @after-leave="handleAfterLeave">
3
+ <UMessage
4
+ v-for="({ onClose, ...message }, index) of messages"
5
+ :key="message.key"
6
+ v-bind="message"
7
+ :data-id="message.key"
8
+ @close="handleClose(index, onClose)"
9
+ />
10
+ </transition-group>
11
+ </template>
12
+
13
+ <script lang="ts" setup>
14
+ import type { MessageOptions } from '../../types/message'
15
+ import UMessage from './message.vue'
16
+
17
+ defineOptions({ name: 'UMessageBox' })
18
+
19
+ defineProps<{ messages: Array<Omit<MessageOptions & { key: string }, 'onClosed'>> }>()
20
+
21
+ const emit = defineEmits<{ (e: 'closed', id: string): void; (e: 'close', index: number): void }>()
22
+
23
+ function handleAfterLeave(el: Element) {
24
+ emit('closed', (el as HTMLElement).dataset.id as string)
25
+ }
26
+
27
+ function handleClose(i: number, onClose?: () => void) {
28
+ emit('close', i)
29
+ onClose?.()
30
+ }
31
+ </script>
@@ -0,0 +1,122 @@
1
+ import { setStyles, zIndex } from '@veltra/utils'
2
+ import { h, render, shallowReactive } from 'vue'
3
+
4
+ import { bem } from '../../shared/bem'
5
+ import type { Message, MessageInstance, MessageOptions } from '../../types/message'
6
+ import { getOverlayContainer } from '../_internal/overlay-container'
7
+ import UMessageBox from './message-box.vue'
8
+
9
+ const cls = bem('message')
10
+
11
+ /** 消息项数据结构 */
12
+ type MessageItem = MessageOptions & { key: string }
13
+
14
+ /** --- 状态管理 --- */
15
+ let container: HTMLElement | null = null
16
+ const messages = shallowReactive<MessageItem[]>([])
17
+
18
+ /** 消息关闭后回调 */
19
+ const closedCallbacks = new Map<string, () => void>()
20
+
21
+ /** 用于计数正在显示的 DOM 节点 (包含动画执行中) */
22
+ let activeCount = 0
23
+ let uid = 0
24
+
25
+ /** --- 内部辅助函数 --- */
26
+
27
+ /** 彻底销毁容器 */
28
+ const destroy = () => {
29
+ if (container) {
30
+ render(null, container)
31
+ container.remove()
32
+ container = null
33
+ }
34
+ }
35
+
36
+ /** 离开动画结束后的清理 */
37
+ const handleClosed = (id: string) => {
38
+ activeCount--
39
+
40
+ const cb = closedCallbacks.get(id)
41
+ if (cb) {
42
+ cb()
43
+ closedCallbacks.delete(id)
44
+ }
45
+
46
+ // 没有活跃消息时销毁容器,保持页面干净
47
+ if (activeCount === 0) destroy()
48
+ }
49
+
50
+ /** 触发关闭 (仅从数组移除,触发 Transition 离开动画) */
51
+ const handleClose = (id: string) => {
52
+ const index = messages.findIndex((m) => m.key === id)
53
+ if (index !== -1) messages.splice(index, 1)
54
+ }
55
+
56
+ /** 挂载并渲染容器 */
57
+ const ensureContainer = () => {
58
+ // 宿主容器可能随设备外壳卸载而失效,失联时重建
59
+ if (container?.isConnected) return container
60
+ container = null
61
+
62
+ container = document.createElement('ul')
63
+ container.className = cls.e('container')
64
+ getOverlayContainer().appendChild(container)
65
+ return container
66
+ }
67
+
68
+ /** 执行 Vue 渲染逻辑 */
69
+ const updateView = () => {
70
+ const el = ensureContainer()
71
+ setStyles(el, { zIndex: zIndex() })
72
+
73
+ const vnode = h(UMessageBox, {
74
+ messages,
75
+ onClosed: handleClosed,
76
+ onClose: (i: number) => messages.splice(i, 1)
77
+ })
78
+
79
+ vnode.appContext = message._context
80
+ render(vnode, el)
81
+ }
82
+
83
+ /** 创建消息实例 */
84
+ const createMessage = (options: MessageOptions): MessageInstance => {
85
+ const { onClosed: userOnClosed, ...messageOptions } = options
86
+ const id = `msg_${uid++}`
87
+ activeCount++
88
+
89
+ // 生命周期 Promise
90
+ let resolveClosed: () => void
91
+ const onClosed = new Promise<void>((r) => (resolveClosed = r))
92
+
93
+ closedCallbacks.set(id, () => {
94
+ userOnClosed?.()
95
+ resolveClosed()
96
+ })
97
+
98
+ messages.push({ key: id, ...messageOptions })
99
+ updateView()
100
+
101
+ return { id, close: () => handleClose(id), onClosed }
102
+ }
103
+
104
+ /** --- 导出 API --- */
105
+
106
+ export const message = ((options) => {
107
+ const mergedOptions = typeof options === 'string' ? { message: options } : options
108
+ return createMessage(mergedOptions)
109
+ }) as Message
110
+
111
+ message._context = null
112
+
113
+ // 挂载快捷方法: message.success(...)
114
+ const messageTypes = ['success', 'warn', 'info', 'error', 'default'] as const
115
+ messageTypes.forEach((type) => {
116
+ message[type] = (msg, config) => message({ ...config, message: msg, type })
117
+ })
118
+
119
+ /** 关闭所有当前显示的消息 */
120
+ message.closeAll = () => {
121
+ messages.splice(0)
122
+ }
@@ -0,0 +1,54 @@
1
+ <template>
2
+ <li :class="[cls.b, cls.m('color-' + getTypeColor(type))]">
3
+ <span :class="cls.e('icon')">
4
+ <UIcon>
5
+ <component :is="getTypeIcon(type, icon)" />
6
+ </UIcon>
7
+ </span>
8
+ <div :class="cls.e('content')" v-if="html" v-html="message"></div>
9
+ <div :class="cls.e('content')" v-else>
10
+ {{ message }}
11
+ </div>
12
+ <button
13
+ :class="cls.e('close')"
14
+ v-if="closable || duration === 0"
15
+ type="button"
16
+ aria-label="关闭"
17
+ @click.stop="immediateClose"
18
+ >
19
+ <UIcon><Close /></UIcon>
20
+ </button>
21
+ </li>
22
+ </template>
23
+
24
+ <script lang="ts" setup>
25
+ import { Close } from '@veltra/icons/normal'
26
+ import { onBeforeUnmount, onMounted } from 'vue'
27
+
28
+ import { bem } from '../../shared/bem'
29
+ import type { MessageProps } from '../../types/message'
30
+ import { UIcon } from '../icon'
31
+ import { getTypeColor, getTypeIcon } from './helper'
32
+
33
+ defineOptions({ name: 'UMessage' })
34
+
35
+ const props = withDefaults(defineProps<MessageProps>(), { type: 'default', duration: 3000 })
36
+
37
+ const emit = defineEmits<{ (e: 'close'): void }>()
38
+
39
+ const cls = bem('message')
40
+
41
+ // 移动端无 hover,不做悬停暂停:到时关闭,点击关闭按钮立即关闭
42
+ let timer: number | undefined
43
+
44
+ onMounted(() => {
45
+ if (props.duration <= 0) return
46
+ timer = setTimeout(() => emit('close'), props.duration)
47
+ })
48
+
49
+ onBeforeUnmount(() => clearTimeout(timer))
50
+
51
+ function immediateClose() {
52
+ emit('close')
53
+ }
54
+ </script>
@@ -0,0 +1,130 @@
1
+ @use 'pkg:@veltra/styles/mixins' as m with ($namespace: um);
2
+ @use 'pkg:@veltra/styles/functions' as fn;
3
+ @use 'pkg:@veltra/styles/vars' as vars;
4
+ @use '../../styles/tokens' as t;
5
+
6
+ // 方便拼接
7
+ $root-name: message;
8
+
9
+ // 顶部轻提示容器:视口顶部居中列排,避让刘海安全区
10
+ @include m.bem($root-name, container) {
11
+ position: fixed;
12
+ top: 0;
13
+ left: 0;
14
+ width: 100%;
15
+ box-sizing: border-box;
16
+ display: flex;
17
+ flex-direction: column;
18
+ align-items: center;
19
+ // 两侧留白保证提示在窄视口内不贴边溢出;顶部避让刘海安全区
20
+ padding: calc(#{t.use-var(spacing-md)} + constant(safe-area-inset-top)) #{t.use-var(spacing-md)} 0;
21
+ padding: calc(#{t.use-var(spacing-md)} + env(safe-area-inset-top)) #{t.use-var(spacing-md)} 0;
22
+ pointer-events: none;
23
+ }
24
+
25
+ @include m.b($root-name) {
26
+ pointer-events: auto;
27
+ box-sizing: border-box;
28
+ display: inline-flex;
29
+ align-items: center;
30
+ // 触控热区不小于 44(含可关闭提示的整条热区)
31
+ min-height: t.use-var(touch-target);
32
+ max-width: 100%;
33
+ margin-bottom: t.use-var(spacing-sm);
34
+ padding: t.use-var(spacing-sm) t.use-var(spacing-lg);
35
+ gap: t.use-var(spacing-sm);
36
+ border-radius: t.use-var('panel-radius');
37
+ font-size: t.use-var(font-size-main);
38
+ line-height: 1.5;
39
+ box-shadow: fn.use-var(shadow, lg);
40
+
41
+ @include m.e(icon) {
42
+ display: inline-flex;
43
+ flex-shrink: 0;
44
+
45
+ // 与 UIcon 的 1em 图标对齐
46
+ > svg {
47
+ width: 1em;
48
+ height: 1em;
49
+ }
50
+ }
51
+
52
+ @include m.e(content) {
53
+ min-width: 0;
54
+ word-break: break-all;
55
+ }
56
+
57
+ @include m.e(close) {
58
+ // 关闭热区不小于 44x44(外扩补足,不挤压内容)
59
+ flex-shrink: 0;
60
+ display: inline-flex;
61
+ align-items: center;
62
+ justify-content: center;
63
+ min-width: t.use-var(touch-target);
64
+ min-height: t.use-var(touch-target);
65
+ margin: calc(-1 * #{t.use-var(spacing-sm)}) calc(-1 * #{t.use-var(spacing-lg)});
66
+ padding: 0;
67
+ border: none;
68
+ background: none;
69
+ color: inherit;
70
+ font-size: 1em;
71
+ -webkit-appearance: none;
72
+ -webkit-tap-highlight-color: transparent;
73
+
74
+ > svg {
75
+ width: 1em;
76
+ height: 1em;
77
+ }
78
+ }
79
+
80
+ @each $type, $_ in vars.$color-types {
81
+ @if ($type == 'default') {
82
+ @include m.m(color-#{$type}) {
83
+ background-color: fn.use-var(color, $type);
84
+ color: fn.use-var(text-color, main);
85
+ }
86
+ } @else {
87
+ @include m.m(color-#{$type}) {
88
+ background-color: fn.use-var(color, $type, 'light-9');
89
+ color: fn.use-var(color, $type);
90
+ }
91
+ }
92
+ }
93
+ }
94
+
95
+ /* 进出场:自顶部滑入滑出(transition-group name="message") */
96
+ .#{$root-name}-move,
97
+ .#{$root-name}-enter-active,
98
+ .#{$root-name}-leave-active {
99
+ transition:
100
+ opacity fn.use-var(transition, normal) fn.use-var(transition, ease),
101
+ transform fn.use-var(transition, normal) fn.use-var(transition, ease);
102
+ }
103
+
104
+ .#{$root-name}-enter-from,
105
+ .#{$root-name}-leave-to {
106
+ opacity: 0;
107
+ transform: translateY(-100%);
108
+ }
109
+
110
+ /* 确保将离开的元素从布局流中删除
111
+ 以便能够正确地计算移动的动画。 */
112
+ .#{$root-name}-leave-active {
113
+ position: absolute;
114
+ width: max-content;
115
+ }
116
+
117
+ // 减弱动态效果:不位移、不缩放,堆叠重排也不滑动,只保留透明度
118
+ @media (prefers-reduced-motion: reduce) {
119
+ .message-move,
120
+ .message-enter-active,
121
+ .message-leave-active {
122
+ transition-property: opacity;
123
+ }
124
+
125
+ .message-enter-from,
126
+ .message-leave-to {
127
+ transform: none;
128
+ opacity: 0;
129
+ }
130
+ }
@@ -0,0 +1 @@
1
+ import './style.scss'
@@ -0,0 +1,3 @@
1
+ export { default as UMessageConfirm } from './message-confirm.vue'
2
+
3
+ export { messageConfirm } from './message-confirm'