@veltra/desktop 1.8.4 → 1.9.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 (194) hide show
  1. package/dist/components/alert/alert.js +69 -0
  2. package/dist/components/alert/alert.js.map +1 -0
  3. package/dist/components/alert/style.d.ts +1 -0
  4. package/dist/components/alert/style.js +1 -0
  5. package/dist/components/alert/style2.css +76 -0
  6. package/dist/components/anchor/anchor-item.js +35 -0
  7. package/dist/components/anchor/anchor-item.js.map +1 -0
  8. package/dist/components/anchor/anchor.js +61 -0
  9. package/dist/components/anchor/anchor.js.map +1 -0
  10. package/dist/components/anchor/di.js +6 -0
  11. package/dist/components/anchor/di.js.map +1 -0
  12. package/dist/components/anchor/style.d.ts +1 -0
  13. package/dist/components/anchor/style.js +1 -0
  14. package/dist/components/anchor/style2.css +45 -0
  15. package/dist/components/anchor/use-anchor.js +81 -0
  16. package/dist/components/anchor/use-anchor.js.map +1 -0
  17. package/dist/components/avatar/avatar-group.js +28 -0
  18. package/dist/components/avatar/avatar-group.js.map +1 -0
  19. package/dist/components/avatar/avatar.js +51 -0
  20. package/dist/components/avatar/avatar.js.map +1 -0
  21. package/dist/components/avatar/style.d.ts +1 -0
  22. package/dist/components/avatar/style.js +1 -0
  23. package/dist/components/avatar/style2.css +87 -0
  24. package/dist/components/back-top/back-top.js +82 -0
  25. package/dist/components/back-top/back-top.js.map +1 -0
  26. package/dist/components/back-top/style.d.ts +1 -0
  27. package/dist/components/back-top/style.js +2 -0
  28. package/dist/components/back-top/style2.css +32 -0
  29. package/dist/components/carousel/carousel-item.js +27 -0
  30. package/dist/components/carousel/carousel-item.js.map +1 -0
  31. package/dist/components/carousel/carousel.js +118 -0
  32. package/dist/components/carousel/carousel.js.map +1 -0
  33. package/dist/components/carousel/di.js +7 -0
  34. package/dist/components/carousel/di.js.map +1 -0
  35. package/dist/components/carousel/style.d.ts +1 -0
  36. package/dist/components/carousel/style.js +1 -0
  37. package/dist/components/carousel/style2.css +97 -0
  38. package/dist/components/carousel/use-carousel.js +68 -0
  39. package/dist/components/carousel/use-carousel.js.map +1 -0
  40. package/dist/components/descriptions/descriptions-item.js +16 -0
  41. package/dist/components/descriptions/descriptions-item.js.map +1 -0
  42. package/dist/components/descriptions/descriptions.js +67 -0
  43. package/dist/components/descriptions/descriptions.js.map +1 -0
  44. package/dist/components/descriptions/style.d.ts +1 -0
  45. package/dist/components/descriptions/style.js +1 -0
  46. package/dist/components/descriptions/style2.css +81 -0
  47. package/dist/components/divider/divider.js +41 -0
  48. package/dist/components/divider/divider.js.map +1 -0
  49. package/dist/components/divider/style.d.ts +1 -0
  50. package/dist/components/divider/style.js +1 -0
  51. package/dist/components/divider/style2.css +68 -0
  52. package/dist/components/expression-editor/components/variable-picker.js +1 -1
  53. package/dist/components/expression-editor/components/variable-picker.js.map +1 -1
  54. package/dist/components/file-viewer/previewers/pdf-previewer.js +3 -1
  55. package/dist/components/file-viewer/previewers/pdf-previewer.js.map +1 -1
  56. package/dist/components/image-cropper/image-cropper.js +1 -1
  57. package/dist/components/image-cropper/image-cropper.js.map +1 -1
  58. package/dist/components/index.d.ts +48 -30
  59. package/dist/components/index.js +95 -59
  60. package/dist/components/index.js.map +1 -1
  61. package/dist/components/rate/rate.js +130 -0
  62. package/dist/components/rate/rate.js.map +1 -0
  63. package/dist/components/rate/style.d.ts +1 -0
  64. package/dist/components/rate/style.js +1 -0
  65. package/dist/components/rate/style2.css +58 -0
  66. package/dist/components/skeleton/skeleton.js +74 -0
  67. package/dist/components/skeleton/skeleton.js.map +1 -0
  68. package/dist/components/skeleton/style.d.ts +1 -0
  69. package/dist/components/skeleton/style.js +1 -0
  70. package/dist/components/skeleton/style2.css +86 -0
  71. package/dist/components/space/space.js +47 -0
  72. package/dist/components/space/space.js.map +1 -0
  73. package/dist/components/space/style.d.ts +1 -0
  74. package/dist/components/space/style.js +1 -0
  75. package/dist/components/space/style2.css +43 -0
  76. package/dist/components/time-picker/style.d.ts +2 -0
  77. package/dist/components/time-picker/style.js +3 -0
  78. package/dist/components/time-picker/style2.css +110 -0
  79. package/dist/components/time-picker/time-picker.js +196 -0
  80. package/dist/components/time-picker/time-picker.js.map +1 -0
  81. package/dist/components/timeline/style.d.ts +1 -0
  82. package/dist/components/timeline/style.js +1 -0
  83. package/dist/components/timeline/style2.css +95 -0
  84. package/dist/components/timeline/timeline-item.js +32 -0
  85. package/dist/components/timeline/timeline-item.js.map +1 -0
  86. package/dist/components/timeline/timeline.js +17 -0
  87. package/dist/components/timeline/timeline.js.map +1 -0
  88. package/dist/components/transfer/style.d.ts +2 -0
  89. package/dist/components/transfer/style.js +4 -0
  90. package/dist/components/transfer/style2.css +172 -0
  91. package/dist/components/transfer/transfer-list.js +101 -0
  92. package/dist/components/transfer/transfer-list.js.map +1 -0
  93. package/dist/components/transfer/transfer.js +138 -0
  94. package/dist/components/transfer/transfer.js.map +1 -0
  95. package/dist/index.d.ts +119 -88
  96. package/dist/index.js +106 -88
  97. package/dist/types/alert.d.ts +27 -0
  98. package/dist/types/anchor.d.ts +48 -0
  99. package/dist/types/avatar.d.ts +28 -0
  100. package/dist/types/back-top.d.ts +19 -0
  101. package/dist/types/carousel.d.ts +25 -0
  102. package/dist/types/descriptions.d.ts +22 -0
  103. package/dist/types/divider.d.ts +14 -0
  104. package/dist/types/index.d.ts +14 -1
  105. package/dist/types/layout.d.ts +2 -1
  106. package/dist/types/rate.d.ts +26 -0
  107. package/dist/types/skeleton.d.ts +24 -0
  108. package/dist/types/space.d.ts +20 -0
  109. package/dist/types/time-picker.d.ts +38 -0
  110. package/dist/types/timeline.d.ts +16 -0
  111. package/dist/types/transfer.d.ts +37 -0
  112. package/package.json +3 -1
  113. package/src/components/alert/alert.vue +62 -0
  114. package/src/components/alert/index.ts +1 -0
  115. package/src/components/alert/style.scss +67 -0
  116. package/src/components/alert/style.ts +1 -0
  117. package/src/components/anchor/anchor-item.vue +35 -0
  118. package/src/components/anchor/anchor.vue +63 -0
  119. package/src/components/anchor/di.ts +15 -0
  120. package/src/components/anchor/index.ts +2 -0
  121. package/src/components/anchor/style.scss +44 -0
  122. package/src/components/anchor/style.ts +1 -0
  123. package/src/components/anchor/use-anchor.ts +120 -0
  124. package/src/components/avatar/avatar-group.vue +26 -0
  125. package/src/components/avatar/avatar.vue +52 -0
  126. package/src/components/avatar/index.ts +2 -0
  127. package/src/components/avatar/style.scss +79 -0
  128. package/src/components/avatar/style.ts +1 -0
  129. package/src/components/back-top/back-top.vue +89 -0
  130. package/src/components/back-top/index.ts +1 -0
  131. package/src/components/back-top/style.scss +31 -0
  132. package/src/components/back-top/style.ts +2 -0
  133. package/src/components/carousel/carousel-item.vue +27 -0
  134. package/src/components/carousel/carousel.vue +93 -0
  135. package/src/components/carousel/di.ts +15 -0
  136. package/src/components/carousel/index.ts +2 -0
  137. package/src/components/carousel/style.scss +109 -0
  138. package/src/components/carousel/style.ts +1 -0
  139. package/src/components/carousel/use-carousel.ts +77 -0
  140. package/src/components/descriptions/descriptions-item.vue +12 -0
  141. package/src/components/descriptions/descriptions.vue +81 -0
  142. package/src/components/descriptions/index.ts +2 -0
  143. package/src/components/descriptions/style.scss +73 -0
  144. package/src/components/descriptions/style.ts +1 -0
  145. package/src/components/divider/divider.vue +29 -0
  146. package/src/components/divider/index.ts +1 -0
  147. package/src/components/divider/style.scss +90 -0
  148. package/src/components/divider/style.ts +1 -0
  149. package/src/components/expression-editor/components/variable-picker.vue +1 -1
  150. package/src/components/file-viewer/previewers/pdf-previewer.vue +6 -1
  151. package/src/components/image-cropper/image-cropper.vue +1 -1
  152. package/src/components/index.ts +26 -0
  153. package/src/components/rate/index.ts +1 -0
  154. package/src/components/rate/rate.vue +127 -0
  155. package/src/components/rate/style.scss +51 -0
  156. package/src/components/rate/style.ts +1 -0
  157. package/src/components/skeleton/index.ts +1 -0
  158. package/src/components/skeleton/skeleton.vue +37 -0
  159. package/src/components/skeleton/style.scss +94 -0
  160. package/src/components/skeleton/style.ts +1 -0
  161. package/src/components/space/index.ts +1 -0
  162. package/src/components/space/space.vue +45 -0
  163. package/src/components/space/style.scss +41 -0
  164. package/src/components/space/style.ts +1 -0
  165. package/src/components/time-picker/index.ts +1 -0
  166. package/src/components/time-picker/style.scss +82 -0
  167. package/src/components/time-picker/style.ts +3 -0
  168. package/src/components/time-picker/time-picker.vue +183 -0
  169. package/src/components/timeline/index.ts +2 -0
  170. package/src/components/timeline/style.scss +107 -0
  171. package/src/components/timeline/style.ts +1 -0
  172. package/src/components/timeline/timeline-item.vue +43 -0
  173. package/src/components/timeline/timeline.vue +17 -0
  174. package/src/components/transfer/index.ts +1 -0
  175. package/src/components/transfer/style.scss +135 -0
  176. package/src/components/transfer/style.ts +4 -0
  177. package/src/components/transfer/transfer-list.vue +120 -0
  178. package/src/components/transfer/transfer.vue +134 -0
  179. package/src/env.d.ts +5 -0
  180. package/src/types/alert.ts +29 -0
  181. package/src/types/anchor.ts +50 -0
  182. package/src/types/avatar.ts +31 -0
  183. package/src/types/back-top.ts +20 -0
  184. package/src/types/carousel.ts +29 -0
  185. package/src/types/descriptions.ts +22 -0
  186. package/src/types/divider.ts +14 -0
  187. package/src/types/index.ts +16 -0
  188. package/src/types/layout.ts +2 -1
  189. package/src/types/rate.ts +27 -0
  190. package/src/types/skeleton.ts +29 -0
  191. package/src/types/space.ts +22 -0
  192. package/src/types/time-picker.ts +40 -0
  193. package/src/types/timeline.ts +15 -0
  194. package/src/types/transfer.ts +45 -0
@@ -0,0 +1,44 @@
1
+ @use 'pkg:@veltra/styles/mixins' as m;
2
+ @use 'pkg:@veltra/styles/functions' as fn;
3
+ @use 'pkg:@veltra/styles/vars';
4
+
5
+ // 激活指示线宽度;项左内边距以它为基准(gap large + 指示线宽)
6
+ $indicator-width: 2px;
7
+ // 单列锚点最长宽度,防止长标题撑破侧栏
8
+ $item-max-width: 200px;
9
+
10
+ @include m.b(anchor) {
11
+ display: inline-flex;
12
+ flex-direction: column;
13
+ max-width: $item-max-width;
14
+
15
+ @include m.e(item) {
16
+ margin: 0;
17
+ padding: fn.use-var(gap, small) fn.use-var(gap, default) fn.use-var(gap, small)
18
+ calc(fn.use-var(gap, large) + #{$indicator-width});
19
+ border-left: $indicator-width solid fn.use-var(border-color);
20
+ color: fn.use-var(text-color, second);
21
+ font-size: fn.use-var(font-size-main);
22
+ line-height: 1.5;
23
+ text-decoration: none;
24
+ white-space: nowrap;
25
+ cursor: pointer;
26
+ transition:
27
+ color fn.use-var(transition, fast) fn.use-var(transition, ease),
28
+ border-color fn.use-var(transition, fast) fn.use-var(transition, ease);
29
+
30
+ &:hover {
31
+ color: fn.use-var(text-color, main);
32
+ }
33
+
34
+ &:focus-visible {
35
+ outline: none;
36
+ box-shadow: fn.use-var(focus-ring);
37
+ }
38
+
39
+ &.is-active {
40
+ border-left-color: fn.use-var(color, primary);
41
+ color: fn.use-var(color, primary);
42
+ }
43
+ }
44
+ }
@@ -0,0 +1 @@
1
+ import './style.scss'
@@ -0,0 +1,120 @@
1
+ import type { MaybeRefOrGetter } from 'vue'
2
+ import { onMounted, onScopeDispose, toValue, watch } from 'vue'
3
+
4
+ /** 锚点滚动联动选项 */
5
+ export interface UseAnchorOptions {
6
+ /** 有序锚点列表(锚点项注册顺序) */
7
+ items: MaybeRefOrGetter<string[]>
8
+ /** 滚动容器:CSS 选择器或元素(含 null,缺省 window) */
9
+ container: MaybeRefOrGetter<string | HTMLElement | null | undefined>
10
+ /** 定位偏移 */
11
+ offset: MaybeRefOrGetter<number>
12
+ /** 命中锚点变化回调 */
13
+ onChange: (href: string) => void
14
+ }
15
+
16
+ /**
17
+ * 解析滚动容器。
18
+ * window 滚动统一返回 documentElement,便于复用 scrollTop / scrollHeight。
19
+ */
20
+ function resolveContainer(target: string | HTMLElement | null | undefined): HTMLElement {
21
+ if (typeof target === 'string') {
22
+ return document.querySelector<HTMLElement>(target) ?? document.documentElement
23
+ }
24
+ return target ?? document.documentElement
25
+ }
26
+
27
+ /** 锚点滚动联动:点击平滑定位、滚动时计算当前命中锚点 */
28
+ export function useAnchor(options: UseAnchorOptions) {
29
+ const { items, container, offset, onChange } = options
30
+
31
+ /** 锚点对应的目标元素 */
32
+ function getTarget(href: string): HTMLElement | null {
33
+ return document.querySelector<HTMLElement>(href)
34
+ }
35
+
36
+ /** 点击项:平滑滚动到目标锚点 */
37
+ function scrollTo(href: string) {
38
+ const target = getTarget(href)
39
+ if (!target) return
40
+
41
+ const wrap = resolveContainer(toValue(container))
42
+ const top =
43
+ wrap === document.documentElement
44
+ ? window.scrollY + target.getBoundingClientRect().top - toValue(offset)
45
+ : wrap.scrollTop +
46
+ target.getBoundingClientRect().top -
47
+ wrap.getBoundingClientRect().top -
48
+ toValue(offset)
49
+
50
+ wrap.scrollTo({ top, behavior: 'smooth' })
51
+ }
52
+
53
+ /** 计算当前命中锚点并通知 */
54
+ function update() {
55
+ const hrefs = toValue(items)
56
+ const first = hrefs[0]
57
+ if (!first) return
58
+
59
+ const wrap = resolveContainer(toValue(container))
60
+ const containerTop = wrap === document.documentElement ? 0 : wrap.getBoundingClientRect().top
61
+
62
+ let hit: string | undefined
63
+ for (const href of hrefs) {
64
+ const target = getTarget(href)
65
+ if (target && target.getBoundingClientRect().top - containerTop - toValue(offset) <= 0) {
66
+ hit = href
67
+ }
68
+ }
69
+
70
+ // 滚动到底部时直接命中最后一项(容器实际可滚动时才生效,避免内容不足一屏时误命中末项)
71
+ const scrollable = wrap.scrollHeight - wrap.clientHeight > 1
72
+ if (scrollable && wrap.scrollTop + wrap.clientHeight >= wrap.scrollHeight - 1) {
73
+ hit = hrefs[hrefs.length - 1] ?? first
74
+ }
75
+
76
+ onChange(hit ?? first)
77
+ }
78
+
79
+ // 滚动监听(rAF 节流)
80
+ let rafId = 0
81
+ function handleScroll() {
82
+ if (rafId) return
83
+ rafId = requestAnimationFrame(() => {
84
+ rafId = 0
85
+ update()
86
+ })
87
+ }
88
+
89
+ let bound: HTMLElement = document.documentElement
90
+ function bind() {
91
+ unbind()
92
+ bound = resolveContainer(toValue(container))
93
+ bound.addEventListener('scroll', handleScroll, { passive: true })
94
+ }
95
+
96
+ function unbind() {
97
+ bound.removeEventListener('scroll', handleScroll)
98
+ if (rafId) cancelAnimationFrame(rafId)
99
+ rafId = 0
100
+ }
101
+
102
+ // 容器变化重绑监听;锚点增删只需重算命中
103
+ watch(
104
+ () => toValue(container),
105
+ () => {
106
+ bind()
107
+ update()
108
+ }
109
+ )
110
+ watch(items, update)
111
+
112
+ onMounted(() => {
113
+ bind()
114
+ update()
115
+ })
116
+
117
+ onScopeDispose(unbind)
118
+
119
+ return { scrollTo, update }
120
+ }
@@ -0,0 +1,26 @@
1
+ <template>
2
+ <div :class="cls.b">
3
+ <component :is="item" v-for="(item, index) of shownItems" :key="index" />
4
+ <span v-if="restCount > 0" :class="cls.e('rest')">+{{ restCount }}</span>
5
+ </div>
6
+ </template>
7
+
8
+ <script lang="ts" setup>
9
+ import { bem } from '@veltra/utils'
10
+ import { computed, useSlots } from 'vue'
11
+
12
+ import type { AvatarGroupProps } from '../../types'
13
+
14
+ defineOptions({ name: 'UAvatarGroup' })
15
+
16
+ const props = defineProps<AvatarGroupProps>()
17
+
18
+ const cls = bem('avatar-group')
19
+
20
+ const slots = useSlots()
21
+
22
+ // 插槽 vnode 须在渲染路径读取:插槽内容读取的响应式数据经调用链追踪,内容变化时重新计算
23
+ const items = computed(() => slots.default?.() ?? [])
24
+ const shownItems = computed(() => (props.max ? items.value.slice(0, props.max) : items.value))
25
+ const restCount = computed(() => (props.max ? Math.max(items.value.length - props.max, 0) : 0))
26
+ </script>
@@ -0,0 +1,52 @@
1
+ <template>
2
+ <span :class="classList">
3
+ <img
4
+ v-if="src && !errored"
5
+ :class="cls.e('image')"
6
+ :src="src"
7
+ :alt="alt"
8
+ @error="handleError"
9
+ />
10
+ <span v-else :class="cls.e('fallback')">
11
+ <slot />
12
+ </span>
13
+ </span>
14
+ </template>
15
+
16
+ <script lang="ts" setup>
17
+ import { useFallbackProps } from '@veltra/compositions'
18
+ import { bem } from '@veltra/utils'
19
+ import { computed, shallowRef, watch } from 'vue'
20
+
21
+ import type { AvatarEmits, AvatarProps, ComponentSize } from '../../types'
22
+
23
+ defineOptions({ name: 'UAvatar' })
24
+
25
+ const props = defineProps<AvatarProps>()
26
+
27
+ const emit = defineEmits<AvatarEmits>()
28
+
29
+ const { size } = useFallbackProps([props], { size: 'default' as ComponentSize })
30
+
31
+ const cls = bem('avatar')
32
+
33
+ const errored = shallowRef(false)
34
+
35
+ watch(
36
+ () => props.src,
37
+ () => {
38
+ errored.value = false
39
+ }
40
+ )
41
+
42
+ const classList = computed(() => [
43
+ cls.b,
44
+ cls.m(size.value),
45
+ bem.is('round', props.shape === 'round')
46
+ ])
47
+
48
+ const handleError = (ev: Event) => {
49
+ errored.value = true
50
+ emit('error', ev)
51
+ }
52
+ </script>
@@ -0,0 +1,2 @@
1
+ export { default as UAvatar } from './avatar.vue'
2
+ export { default as UAvatarGroup } from './avatar-group.vue'
@@ -0,0 +1,79 @@
1
+ @use 'pkg:@veltra/styles/mixins' as m;
2
+ @use 'pkg:@veltra/styles/functions' as fn;
3
+
4
+ $root-name: avatar;
5
+
6
+ // 叠放环宽:遮住与前一头像的重叠边,保证每张头像露出统一宽度的描边
7
+ $overlap-ring-width: 2px;
8
+ // 头像重叠量(向左压住前一个),随主题 gap token 变化
9
+ $overlap-shift: fn.use-var(gap, default);
10
+
11
+ @include m.b($root-name) {
12
+ display: inline-flex;
13
+ align-items: center;
14
+ justify-content: center;
15
+ flex-shrink: 0;
16
+ box-sizing: border-box;
17
+ overflow: hidden;
18
+ border-radius: 50%;
19
+ color: fn.use-var(text-color, white);
20
+ background-color: fn.use-var(color, primary);
21
+ user-select: none;
22
+
23
+ @include m.size using ($size) {
24
+ width: fn.use-var(form-component-height, $size);
25
+ height: fn.use-var(form-component-height, $size);
26
+ font-size: fn.use-var(font-size-main, $size);
27
+ }
28
+
29
+ @include m.is(round) {
30
+ border-radius: fn.use-var(radius, large);
31
+ }
32
+
33
+ @include m.e(image) {
34
+ width: 100%;
35
+ height: 100%;
36
+ object-fit: cover;
37
+ }
38
+
39
+ @include m.e(fallback) {
40
+ display: inline-flex;
41
+ align-items: center;
42
+ justify-content: center;
43
+ line-height: 1;
44
+ white-space: nowrap;
45
+ }
46
+ }
47
+
48
+ @include m.b(#{$root-name}-group) {
49
+ display: inline-flex;
50
+ align-items: center;
51
+
52
+ @include m.b($root-name) {
53
+ border: $overlap-ring-width solid fn.use-var(bg-color, top);
54
+
55
+ &:not(:first-child) {
56
+ margin-left: calc(#{$overlap-shift} * -1);
57
+ }
58
+ }
59
+
60
+ // +N 余量位:尺寸与字体取 avatar 的 default 档,与组内未显式指定 size 的头像一致
61
+ @include m.e(rest) {
62
+ display: inline-flex;
63
+ align-items: center;
64
+ justify-content: center;
65
+ flex-shrink: 0;
66
+ box-sizing: border-box;
67
+ width: fn.use-var(form-component-height, default);
68
+ height: fn.use-var(form-component-height, default);
69
+ font-size: fn.use-var(font-size-main, default);
70
+ border-radius: 50%;
71
+ border: $overlap-ring-width solid fn.use-var(bg-color, top);
72
+ color: fn.use-var(text-color, main);
73
+ background-color: fn.use-var(color, default);
74
+
75
+ &:not(:first-child) {
76
+ margin-left: calc(#{$overlap-shift} * -1);
77
+ }
78
+ }
79
+ }
@@ -0,0 +1 @@
1
+ import './style.scss'
@@ -0,0 +1,89 @@
1
+ <template>
2
+ <Teleport to="body">
3
+ <Transition :name="transitionName">
4
+ <u-button
5
+ v-if="visible"
6
+ :class="cls.b"
7
+ circle
8
+ size="large"
9
+ title="回到顶部"
10
+ @click="scrollToTop"
11
+ >
12
+ <u-icon><ArrowUp /></u-icon>
13
+ </u-button>
14
+ </Transition>
15
+ </Teleport>
16
+ </template>
17
+
18
+ <script lang="ts" setup>
19
+ import { ArrowUp } from '@veltra/icons/normal'
20
+ import { bem } from '@veltra/utils'
21
+ import { onBeforeUnmount, onMounted, shallowRef, watch } from 'vue'
22
+
23
+ import type { BackTopEmits, BackTopProps } from '../../types'
24
+ import { UButton } from '../button'
25
+ import { UIcon } from '../icon'
26
+
27
+ defineOptions({ name: 'UBackTop' })
28
+
29
+ const props = withDefaults(defineProps<BackTopProps>(), { visibilityHeight: 400 })
30
+
31
+ const emit = defineEmits<BackTopEmits>()
32
+
33
+ const cls = bem('back-top')
34
+ const transitionName = cls.create('fade').b
35
+
36
+ const visible = shallowRef(false)
37
+
38
+ let scrollTarget: HTMLElement | Window | null = null
39
+
40
+ const resolveTarget = (): HTMLElement | Window => {
41
+ const { target } = props
42
+
43
+ if (!target) return window
44
+ if (typeof target === 'string') {
45
+ return document.querySelector<HTMLElement>(target) ?? window
46
+ }
47
+ return target
48
+ }
49
+
50
+ const updateVisible = () => {
51
+ const top =
52
+ scrollTarget === window ? window.scrollY : ((scrollTarget as HTMLElement)?.scrollTop ?? 0)
53
+
54
+ visible.value = top >= props.visibilityHeight
55
+ }
56
+
57
+ const bind = () => {
58
+ scrollTarget = resolveTarget()
59
+ scrollTarget.addEventListener('scroll', updateVisible, { passive: true })
60
+ }
61
+
62
+ const unbind = () => {
63
+ scrollTarget?.removeEventListener('scroll', updateVisible)
64
+ scrollTarget = null
65
+ }
66
+
67
+ watch(
68
+ () => props.target,
69
+ () => {
70
+ if (!scrollTarget) return
71
+
72
+ unbind()
73
+ bind()
74
+ updateVisible()
75
+ }
76
+ )
77
+
78
+ onMounted(() => {
79
+ bind()
80
+ updateVisible()
81
+ })
82
+
83
+ onBeforeUnmount(unbind)
84
+
85
+ const scrollToTop = () => {
86
+ scrollTarget?.scrollTo({ top: 0, behavior: 'smooth' })
87
+ emit('click')
88
+ }
89
+ </script>
@@ -0,0 +1 @@
1
+ export { default as UBackTop } from './back-top.vue'
@@ -0,0 +1,31 @@
1
+ @use 'pkg:@veltra/styles/mixins' as m;
2
+ @use 'pkg:@veltra/styles/functions' as fn;
3
+
4
+ $root-name: back-top;
5
+
6
+ // 距视口右/下边缘的留白;全局 token 无 10px 档,属组件级几何常量
7
+ $edge-offset: 10px;
8
+
9
+ @include m.b($root-name) {
10
+ position: fixed;
11
+ right: $edge-offset;
12
+ bottom: $edge-offset;
13
+ // 浮在页面内容之上(内容区层级普遍 <=1),低于 message/notification 等弹层(zIndex() 从 1000 起)
14
+ z-index: 100;
15
+ box-shadow: fn.use-var(shadow, lg);
16
+ }
17
+
18
+ @include m.b(#{$root-name}-fade) {
19
+ &-enter-active,
20
+ &-leave-active {
21
+ transition:
22
+ opacity fn.use-var(transition, normal) fn.use-var(transition, ease),
23
+ transform fn.use-var(transition, normal) fn.use-var(transition, ease);
24
+ }
25
+
26
+ &-enter-from,
27
+ &-leave-to {
28
+ opacity: 0;
29
+ transform: scale(0.4);
30
+ }
31
+ }
@@ -0,0 +1,2 @@
1
+ import '../button/style'
2
+ import './style.scss'
@@ -0,0 +1,27 @@
1
+ <template>
2
+ <div :class="cls.e('item')" :aria-hidden="!isActive">
3
+ <slot />
4
+ </div>
5
+ </template>
6
+
7
+ <script lang="ts" setup>
8
+ import { bem } from '@veltra/utils'
9
+ import { computed, getCurrentInstance, inject, onBeforeUnmount, onMounted } from 'vue'
10
+
11
+ import { CarouselDIKey } from './di'
12
+
13
+ defineOptions({ name: 'UCarouselItem' })
14
+
15
+ const context = inject(CarouselDIKey, undefined)
16
+
17
+ const cls = context?.cls ?? bem('carousel')
18
+
19
+ const uid = getCurrentInstance()?.uid ?? -1
20
+
21
+ const isActive = computed(
22
+ () => context !== undefined && context.itemUids.value.indexOf(uid) === context.current.value
23
+ )
24
+
25
+ onMounted(() => context?.register(uid))
26
+ onBeforeUnmount(() => context?.unregister(uid))
27
+ </script>
@@ -0,0 +1,93 @@
1
+ <template>
2
+ <div :class="cls.b" role="region" aria-roledescription="carousel">
3
+ <div :class="cls.e('track')" :style="trackStyle">
4
+ <slot />
5
+ </div>
6
+
7
+ <button
8
+ v-if="arrows"
9
+ type="button"
10
+ :class="[cls.e('arrow'), cls.em('arrow', 'prev')]"
11
+ :disabled="!canPrev"
12
+ aria-label="上一页"
13
+ @click="prev"
14
+ >
15
+ <u-icon><ArrowLeft /></u-icon>
16
+ </button>
17
+
18
+ <button
19
+ v-if="arrows"
20
+ type="button"
21
+ :class="[cls.e('arrow'), cls.em('arrow', 'next')]"
22
+ :disabled="!canNext"
23
+ aria-label="下一页"
24
+ @click="next"
25
+ >
26
+ <u-icon><ArrowRight /></u-icon>
27
+ </button>
28
+
29
+ <div v-if="dots" :class="cls.e('dots')">
30
+ <button
31
+ v-for="page in itemUids.length"
32
+ :key="page"
33
+ type="button"
34
+ :class="[cls.e('dot'), bem.is('active', page - 1 === current)]"
35
+ :aria-label="`切换到第 ${page} 页`"
36
+ @click="goTo(page - 1)"
37
+ />
38
+ </div>
39
+ </div>
40
+ </template>
41
+
42
+ <script lang="ts" setup>
43
+ import { ArrowLeft, ArrowRight } from '@veltra/icons/normal'
44
+ import { bem } from '@veltra/utils'
45
+ import { computed, provide, ref, watch } from 'vue'
46
+
47
+ import type { CarouselEmits, CarouselProps } from '../../types'
48
+ import { UIcon } from '../icon'
49
+ import { CarouselDIKey } from './di'
50
+ import { useCarousel } from './use-carousel'
51
+
52
+ defineOptions({ name: 'UCarousel' })
53
+
54
+ const {
55
+ autoplay = false,
56
+ interval = 3000,
57
+ loop = true,
58
+ arrows = false,
59
+ dots = true
60
+ } = defineProps<CarouselProps>()
61
+
62
+ const emit = defineEmits<CarouselEmits>()
63
+
64
+ const cls = bem('carousel')
65
+
66
+ const model = defineModel<number>('activeIndex', { default: 0 })
67
+
68
+ /** 已注册页 uid,顺序即插槽渲染顺序,页数由此推导 */
69
+ const itemUids = ref<number[]>([])
70
+
71
+ const register = (uid: number) => {
72
+ if (!itemUids.value.includes(uid)) itemUids.value.push(uid)
73
+ }
74
+
75
+ const unregister = (uid: number) => {
76
+ const index = itemUids.value.indexOf(uid)
77
+ if (index > -1) itemUids.value.splice(index, 1)
78
+ }
79
+
80
+ const { current, canPrev, canNext, goTo, prev, next } = useCarousel({
81
+ model,
82
+ count: () => itemUids.value.length,
83
+ autoplay: () => autoplay,
84
+ interval: () => interval,
85
+ loop: () => loop
86
+ })
87
+
88
+ provide(CarouselDIKey, { cls, itemUids, current, register, unregister })
89
+
90
+ const trackStyle = computed(() => ({ transform: `translateX(-${current.value * 100}%)` }))
91
+
92
+ watch(model, (index, prevIndex) => emit('change', index, prevIndex))
93
+ </script>
@@ -0,0 +1,15 @@
1
+ import { type BEM } from '@veltra/utils'
2
+ import type { ComputedRef, InjectionKey, Ref } from 'vue'
3
+
4
+ /** 走马灯页上下文:页注册到容器换页数,取激活态渲染 aria */
5
+ export interface CarouselContext {
6
+ cls: BEM<'carousel'>
7
+ /** 已注册页的 uid,顺序即插槽渲染顺序 */
8
+ itemUids: Ref<number[]>
9
+ /** 当前激活页索引(已收敛到页数范围内) */
10
+ current: ComputedRef<number>
11
+ register: (uid: number) => void
12
+ unregister: (uid: number) => void
13
+ }
14
+
15
+ export const CarouselDIKey: InjectionKey<CarouselContext> = Symbol('Carousel')
@@ -0,0 +1,2 @@
1
+ export { default as UCarousel } from './carousel.vue'
2
+ export { default as UCarouselItem } from './carousel-item.vue'