@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.
- package/package.json +32 -6
- package/src/components/_internal/bottom-sheet/bottom-sheet.vue +81 -0
- package/src/components/_internal/bottom-sheet/index.ts +1 -0
- package/src/components/_internal/bottom-sheet/style.scss +116 -0
- package/src/components/_internal/bottom-sheet/style.ts +1 -0
- package/src/components/_internal/overlay-container.ts +34 -0
- package/src/components/avatar/avatar.vue +44 -0
- package/src/components/avatar/index.ts +1 -0
- package/src/components/avatar/style.scss +53 -0
- package/src/components/avatar/style.ts +1 -0
- package/src/components/badge/badge.vue +59 -0
- package/src/components/badge/index.ts +1 -0
- package/src/components/badge/style.scss +62 -0
- package/src/components/badge/style.ts +1 -0
- package/src/components/button/button.vue +76 -0
- package/src/components/button/index.ts +1 -0
- package/src/components/button/style.scss +207 -0
- package/src/components/button/style.ts +1 -0
- package/src/components/card/card.vue +24 -0
- package/src/components/card/index.ts +1 -0
- package/src/components/card/style.scss +35 -0
- package/src/components/card/style.ts +1 -0
- package/src/components/cascade/cascade.vue +595 -0
- package/src/components/cascade/index.ts +1 -0
- package/src/components/cascade/node.ts +29 -0
- package/src/components/cascade/style.scss +424 -0
- package/src/components/cascade/style.ts +2 -0
- package/src/components/check-tag/check-tag.vue +35 -0
- package/src/components/check-tag/index.ts +1 -0
- package/src/components/check-tag/style.scss +46 -0
- package/src/components/check-tag/style.ts +1 -0
- package/src/components/checkbox/checkbox.vue +67 -0
- package/src/components/checkbox/index.ts +1 -0
- package/src/components/checkbox/style.scss +132 -0
- package/src/components/checkbox/style.ts +2 -0
- package/src/components/checkbox-group/checkbox-group.vue +94 -0
- package/src/components/checkbox-group/index.ts +1 -0
- package/src/components/checkbox-group/style.scss +57 -0
- package/src/components/checkbox-group/style.ts +2 -0
- package/src/components/collapse/collapse-item.vue +134 -0
- package/src/components/collapse/collapse.vue +117 -0
- package/src/components/collapse/di.ts +18 -0
- package/src/components/collapse/index.ts +3 -0
- package/src/components/collapse/style.scss +157 -0
- package/src/components/collapse/style.ts +1 -0
- package/src/components/date-picker/date-picker.vue +326 -0
- package/src/components/date-picker/index.ts +1 -0
- package/src/components/date-picker/style.scss +236 -0
- package/src/components/date-picker/style.ts +2 -0
- package/src/components/descriptions/descriptions-item.vue +12 -0
- package/src/components/descriptions/descriptions.vue +50 -0
- package/src/components/descriptions/index.ts +2 -0
- package/src/components/descriptions/style.scss +120 -0
- package/src/components/descriptions/style.ts +1 -0
- package/src/components/dialog/dialog.vue +143 -0
- package/src/components/dialog/index.ts +1 -0
- package/src/components/dialog/style.scss +163 -0
- package/src/components/dialog/style.ts +4 -0
- package/src/components/divider/divider.vue +29 -0
- package/src/components/divider/index.ts +1 -0
- package/src/components/divider/style.scss +91 -0
- package/src/components/divider/style.ts +1 -0
- package/src/components/drawer/drawer.vue +168 -0
- package/src/components/drawer/index.ts +1 -0
- package/src/components/drawer/style.scss +240 -0
- package/src/components/drawer/style.ts +2 -0
- package/src/components/empty/empty.vue +22 -0
- package/src/components/empty/index.ts +1 -0
- package/src/components/empty/style.scss +36 -0
- package/src/components/empty/style.ts +1 -0
- package/src/components/form/form.vue +119 -0
- package/src/components/form/index.ts +1 -0
- package/src/components/form/is-field-modified.ts +16 -0
- package/src/components/form/style.scss +58 -0
- package/src/components/form/style.ts +2 -0
- package/src/components/form/use-form-fields.ts +115 -0
- package/src/components/form/use-node-interceptor.ts +101 -0
- package/src/components/form-item/form-item.vue +171 -0
- package/src/components/form-item/helper.ts +9 -0
- package/src/components/form-item/index.ts +1 -0
- package/src/components/form-item/style.scss +121 -0
- package/src/components/form-item/style.ts +1 -0
- package/src/components/form-item/validate.ts +131 -0
- package/src/components/icon/icon.vue +23 -0
- package/src/components/icon/index.ts +1 -0
- package/src/components/icon/style.scss +37 -0
- package/src/components/icon/style.ts +1 -0
- package/src/components/input/index.ts +1 -0
- package/src/components/input/input.vue +187 -0
- package/src/components/input/style.scss +121 -0
- package/src/components/input/style.ts +1 -0
- package/src/components/list/index.ts +3 -0
- package/src/components/list/list-item.vue +20 -0
- package/src/components/list/list.vue +20 -0
- package/src/components/list/style.scss +50 -0
- package/src/components/list/style.ts +1 -0
- package/src/components/loading/directive.ts +34 -0
- package/src/components/loading/index.ts +3 -0
- package/src/components/loading/loading.vue +25 -0
- package/src/components/loading/style.scss +179 -0
- package/src/components/loading/style.ts +2 -0
- package/src/components/message/helper.ts +28 -0
- package/src/components/message/index.ts +3 -0
- package/src/components/message/message-box.vue +31 -0
- package/src/components/message/message.ts +122 -0
- package/src/components/message/message.vue +54 -0
- package/src/components/message/style.scss +130 -0
- package/src/components/message/style.ts +1 -0
- package/src/components/message-confirm/index.ts +3 -0
- package/src/components/message-confirm/message-confirm-box.vue +36 -0
- package/src/components/message-confirm/message-confirm.ts +139 -0
- package/src/components/message-confirm/message-confirm.vue +53 -0
- package/src/components/message-confirm/style.scss +138 -0
- package/src/components/message-confirm/style.ts +1 -0
- package/src/components/multi-select/index.ts +1 -0
- package/src/components/multi-select/multi-select.vue +410 -0
- package/src/components/multi-select/style.scss +376 -0
- package/src/components/multi-select/style.ts +2 -0
- package/src/components/number-input/index.ts +1 -0
- package/src/components/number-input/number-input.vue +407 -0
- package/src/components/number-input/style.scss +118 -0
- package/src/components/number-input/style.ts +2 -0
- package/src/components/password-input/index.ts +1 -0
- package/src/components/password-input/password-input.vue +134 -0
- package/src/components/password-input/style.scss +40 -0
- package/src/components/password-input/style.ts +2 -0
- package/src/components/progress/index.ts +1 -0
- package/src/components/progress/progress.vue +90 -0
- package/src/components/progress/style.scss +73 -0
- package/src/components/progress/style.ts +1 -0
- package/src/components/radio/index.ts +1 -0
- package/src/components/radio/radio.vue +57 -0
- package/src/components/radio/style.scss +113 -0
- package/src/components/radio/style.ts +1 -0
- package/src/components/radio-group/index.ts +1 -0
- package/src/components/radio-group/radio-group.vue +60 -0
- package/src/components/radio-group/style.scss +29 -0
- package/src/components/radio-group/style.ts +2 -0
- package/src/components/segment/index.ts +1 -0
- package/src/components/segment/segment.vue +121 -0
- package/src/components/segment/style.scss +118 -0
- package/src/components/segment/style.ts +1 -0
- package/src/components/select/index.ts +1 -0
- package/src/components/select/select.vue +278 -0
- package/src/components/select/style.scss +237 -0
- package/src/components/select/style.ts +2 -0
- package/src/components/select/use-options.ts +195 -0
- package/src/components/skeleton/index.ts +1 -0
- package/src/components/skeleton/skeleton.vue +37 -0
- package/src/components/skeleton/style.scss +95 -0
- package/src/components/skeleton/style.ts +1 -0
- package/src/components/space/index.ts +1 -0
- package/src/components/space/space.vue +45 -0
- package/src/components/space/style.scss +41 -0
- package/src/components/space/style.ts +1 -0
- package/src/components/steps/index.ts +1 -0
- package/src/components/steps/steps.vue +114 -0
- package/src/components/steps/style.scss +231 -0
- package/src/components/steps/style.ts +1 -0
- package/src/components/switch/index.ts +1 -0
- package/src/components/switch/style.scss +137 -0
- package/src/components/switch/style.ts +1 -0
- package/src/components/switch/switch.vue +63 -0
- package/src/components/tabs/index.ts +1 -0
- package/src/components/tabs/style.scss +285 -0
- package/src/components/tabs/style.ts +1 -0
- package/src/components/tabs/tabs.vue +127 -0
- package/src/components/tag/index.ts +1 -0
- package/src/components/tag/style.scss +114 -0
- package/src/components/tag/style.ts +1 -0
- package/src/components/tag/tag.vue +49 -0
- package/src/components/text/index.ts +1 -0
- package/src/components/text/style.scss +63 -0
- package/src/components/text/style.ts +1 -0
- package/src/components/text/text.vue +63 -0
- package/src/components/textarea/index.ts +1 -0
- package/src/components/textarea/style.scss +124 -0
- package/src/components/textarea/style.ts +1 -0
- package/src/components/textarea/textarea.vue +121 -0
- package/src/components/textarea/utils.ts +11 -0
- package/src/components/time-picker/index.ts +1 -0
- package/src/components/time-picker/style.scss +216 -0
- package/src/components/time-picker/style.ts +2 -0
- package/src/components/time-picker/time-picker.vue +263 -0
- package/src/components/timeline/index.ts +2 -0
- package/src/components/timeline/style.scss +107 -0
- package/src/components/timeline/style.ts +1 -0
- package/src/components/timeline/timeline-item.vue +43 -0
- package/src/components/timeline/timeline.vue +16 -0
- package/src/components/uploader/index.ts +1 -0
- package/src/components/uploader/style.scss +220 -0
- package/src/components/uploader/style.ts +1 -0
- package/src/components/uploader/uploader.vue +306 -0
- package/src/env.d.ts +7 -0
- package/src/index.ts +99 -1
- package/src/shared/bem.ts +12 -0
- package/src/shared/use-scroll-lock.ts +111 -0
- package/src/shared/use-touch-gesture.ts +150 -0
- package/src/styles/_tokens.scss +129 -0
- package/src/types/avatar.ts +31 -0
- package/src/types/badge.ts +28 -0
- package/src/types/button.ts +48 -0
- package/src/types/card.ts +16 -0
- package/src/types/cascade.ts +87 -0
- package/src/types/check-tag.ts +24 -0
- package/src/types/checkbox-group.ts +20 -0
- package/src/types/checkbox.ts +15 -0
- package/src/types/collapse.ts +79 -0
- package/src/types/date-picker.ts +39 -0
- package/src/types/descriptions.ts +22 -0
- package/src/types/dialog.ts +54 -0
- package/src/types/divider.ts +14 -0
- package/src/types/drawer.ts +38 -0
- package/src/types/empty.ts +19 -0
- package/src/types/form-item.ts +22 -0
- package/src/types/form.ts +54 -0
- package/src/types/icon.ts +10 -0
- package/src/types/input.ts +51 -0
- package/src/types/list.ts +13 -0
- package/src/types/loading.ts +20 -0
- package/src/types/message-confirm.ts +72 -0
- package/src/types/message.ts +71 -0
- package/src/types/multi-select.ts +38 -0
- package/src/types/number-input.ts +32 -0
- package/src/types/password-input.ts +19 -0
- package/src/types/progress.ts +22 -0
- package/src/types/radio-group.ts +33 -0
- package/src/types/radio.ts +18 -0
- package/src/types/segment.ts +42 -0
- package/src/types/select.ts +63 -0
- package/src/types/skeleton.ts +29 -0
- package/src/types/space.ts +22 -0
- package/src/types/steps.ts +67 -0
- package/src/types/switch.ts +17 -0
- package/src/types/tabs.ts +63 -0
- package/src/types/tag.ts +19 -0
- package/src/types/text.ts +28 -0
- package/src/types/textarea.ts +76 -0
- package/src/types/time-picker.ts +40 -0
- package/src/types/timeline.ts +15 -0
- package/src/types/uploader.ts +50 -0
- package/.turbo/turbo-build.log +0 -2
- package/.turbo/turbo-check-types.log +0 -1
- package/tsconfig.json +0 -12
- package/tsconfig.tsbuildinfo +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default as UProgress } from './progress.vue'
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<div :class="className">
|
|
3
|
+
<!-- 条形进度条 -->
|
|
4
|
+
<div :class="cls.e('bar-wrap')" v-if="!circle">
|
|
5
|
+
<div :class="cls.e('bar')" :style="{ width: percentage + '%' }">
|
|
6
|
+
<slot v-bind="{ percentage, type }">{{ percentage }}%</slot>
|
|
7
|
+
</div>
|
|
8
|
+
</div>
|
|
9
|
+
|
|
10
|
+
<!-- 环形进度条 -->
|
|
11
|
+
<div
|
|
12
|
+
v-else
|
|
13
|
+
:class="cls.e('circle')"
|
|
14
|
+
:style="{ height: withUnit(size, 'px'), width: withUnit(size, 'px') }"
|
|
15
|
+
>
|
|
16
|
+
<svg viewBox="0 0 100 100">
|
|
17
|
+
<circle
|
|
18
|
+
:class="cls.e('circle-track')"
|
|
19
|
+
cx="50"
|
|
20
|
+
cy="50"
|
|
21
|
+
:r="r"
|
|
22
|
+
fill="none"
|
|
23
|
+
stroke-width="8"
|
|
24
|
+
/>
|
|
25
|
+
<circle
|
|
26
|
+
:class="cls.e('circle-ring')"
|
|
27
|
+
cx="50"
|
|
28
|
+
cy="50"
|
|
29
|
+
:r="r"
|
|
30
|
+
fill="none"
|
|
31
|
+
stroke-width="8"
|
|
32
|
+
:stroke-dasharray="dashArray"
|
|
33
|
+
:stroke-dashoffset="offset"
|
|
34
|
+
:stroke-linecap="percentage === 0 ? undefined : 'round'"
|
|
35
|
+
/>
|
|
36
|
+
</svg>
|
|
37
|
+
|
|
38
|
+
<div :class="cls.e('circle-content')">
|
|
39
|
+
<slot v-bind="{ percentage, type }"> {{ percentage }}% </slot>
|
|
40
|
+
</div>
|
|
41
|
+
</div>
|
|
42
|
+
</div>
|
|
43
|
+
</template>
|
|
44
|
+
|
|
45
|
+
<script lang="ts" setup>
|
|
46
|
+
import { withUnit } from '@veltra/utils'
|
|
47
|
+
import type { ColorType } from '@veltra/utils'
|
|
48
|
+
import { computed } from 'vue'
|
|
49
|
+
|
|
50
|
+
import { bem } from '../../shared/bem'
|
|
51
|
+
import type { ProgressProps } from '../../types/progress'
|
|
52
|
+
|
|
53
|
+
defineOptions({ name: 'UProgress' })
|
|
54
|
+
|
|
55
|
+
const props = defineProps<ProgressProps>()
|
|
56
|
+
|
|
57
|
+
defineSlots<{
|
|
58
|
+
default: (props: {
|
|
59
|
+
/** 进度百分比 */
|
|
60
|
+
percentage: number
|
|
61
|
+
/** 样式类型 */
|
|
62
|
+
type: ColorType
|
|
63
|
+
}) => any
|
|
64
|
+
}>()
|
|
65
|
+
|
|
66
|
+
const cls = bem('progress')
|
|
67
|
+
|
|
68
|
+
const percentage = computed(() => {
|
|
69
|
+
return Math.min(100, Math.max(0, props.percentage ?? 0))
|
|
70
|
+
})
|
|
71
|
+
|
|
72
|
+
const type = computed<ColorType>(() => {
|
|
73
|
+
const { type } = props
|
|
74
|
+
return typeof type === 'function' ? type(percentage.value) : type
|
|
75
|
+
})
|
|
76
|
+
|
|
77
|
+
const className = computed(() => {
|
|
78
|
+
return [cls.b, bem.is('circle', props.circle), cls.m(type.value)]
|
|
79
|
+
})
|
|
80
|
+
|
|
81
|
+
const r = 44
|
|
82
|
+
const c = 2 * Math.PI * r
|
|
83
|
+
const offset = c / 4
|
|
84
|
+
|
|
85
|
+
/** 圆周 */
|
|
86
|
+
const dashArray = computed(() => {
|
|
87
|
+
const dashLen = (c * percentage.value) / 100
|
|
88
|
+
return `${dashLen}, ${c - dashLen}`
|
|
89
|
+
})
|
|
90
|
+
</script>
|
|
@@ -0,0 +1,73 @@
|
|
|
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';
|
|
4
|
+
@use '../../styles/tokens' as t;
|
|
5
|
+
|
|
6
|
+
// 方便拼接
|
|
7
|
+
$root-name: progress;
|
|
8
|
+
|
|
9
|
+
// 进度文本走辅助字号档,条形高度按字号推导以容纳内嵌百分比文本
|
|
10
|
+
@include m.b($root-name) {
|
|
11
|
+
font-size: t.use-var(font-size-secondary);
|
|
12
|
+
|
|
13
|
+
$bar-height: 1.4em;
|
|
14
|
+
|
|
15
|
+
@include m.e(bar-wrap) {
|
|
16
|
+
height: $bar-height;
|
|
17
|
+
background-color: fn.use-var(bg-color, hover);
|
|
18
|
+
border-radius: $bar-height;
|
|
19
|
+
overflow: hidden;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
@include m.e(bar) {
|
|
23
|
+
height: 100%;
|
|
24
|
+
color: fn.use-var(text-color, white);
|
|
25
|
+
overflow: hidden;
|
|
26
|
+
transition:
|
|
27
|
+
width 0.4s cubic-bezier(0.25, 0.1, 0.25, 1),
|
|
28
|
+
background-color 0.4s cubic-bezier(0.25, 0.1, 0.25, 1);
|
|
29
|
+
@include m.flex($justify: center);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// 环形进度条:直径兜底走 token(size 未传时),传 size 后由内联样式覆盖
|
|
33
|
+
@include m.e(circle) {
|
|
34
|
+
width: t.use-var(progress-circle);
|
|
35
|
+
height: t.use-var(progress-circle);
|
|
36
|
+
position: relative;
|
|
37
|
+
|
|
38
|
+
& > svg {
|
|
39
|
+
width: 100%;
|
|
40
|
+
height: 100%;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
@include m.e(circle-track) {
|
|
45
|
+
stroke: fn.use-var(bg-color, hover);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
@include m.e(circle-ring) {
|
|
49
|
+
transition: stroke-dasharray 0.4s cubic-bezier(0.25, 0.1, 0.25, 1);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
@include m.e(circle-content) {
|
|
53
|
+
width: 100%;
|
|
54
|
+
height: 100%;
|
|
55
|
+
position: absolute;
|
|
56
|
+
top: 0;
|
|
57
|
+
left: 0;
|
|
58
|
+
@include m.flex($justify: center);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// 颜色
|
|
62
|
+
@each $type, $_ in vars.$color-types {
|
|
63
|
+
@include m.m($type) {
|
|
64
|
+
@include m.bem($root-name, bar) {
|
|
65
|
+
background-color: fn.use-var(color, $type);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
@include m.bem($root-name, circle-ring) {
|
|
69
|
+
stroke: fn.use-var(color, $type);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import './style.scss'
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default as URadio } from './radio.vue'
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<label :class="classList">
|
|
3
|
+
<input
|
|
4
|
+
type="radio"
|
|
5
|
+
:class="cls.e('native')"
|
|
6
|
+
:value="value"
|
|
7
|
+
v-model="model"
|
|
8
|
+
:disabled="disabled"
|
|
9
|
+
/>
|
|
10
|
+
|
|
11
|
+
<span :class="cls.e('label')">
|
|
12
|
+
<slot>{{ label }}</slot>
|
|
13
|
+
</span>
|
|
14
|
+
|
|
15
|
+
<!-- 右侧圆形选中标记:列表行式选项的移动端惯例 -->
|
|
16
|
+
<span :class="cls.e('indicator')">
|
|
17
|
+
<span :class="cls.e('dot')" v-if="radioChecked"></span>
|
|
18
|
+
</span>
|
|
19
|
+
</label>
|
|
20
|
+
</template>
|
|
21
|
+
|
|
22
|
+
<script lang="ts" setup>
|
|
23
|
+
import { useFormFallbackProps } from '@veltra/compositions'
|
|
24
|
+
import { injectFormContext } from '@veltra/utils'
|
|
25
|
+
import { computed } from 'vue'
|
|
26
|
+
|
|
27
|
+
import { bem } from '../../shared/bem'
|
|
28
|
+
import type { RadioEmits, RadioProps } from '../../types/radio'
|
|
29
|
+
|
|
30
|
+
defineOptions({ name: 'URadio' })
|
|
31
|
+
|
|
32
|
+
const model = defineModel<any>()
|
|
33
|
+
|
|
34
|
+
const props = withDefaults(defineProps<RadioProps>(), { disabled: undefined })
|
|
35
|
+
|
|
36
|
+
defineEmits<RadioEmits>()
|
|
37
|
+
|
|
38
|
+
const cls = bem('radio')
|
|
39
|
+
|
|
40
|
+
const { formProps } = injectFormContext()
|
|
41
|
+
|
|
42
|
+
const { size, disabled } = useFormFallbackProps([formProps ?? {}, props], {
|
|
43
|
+
size: 'default',
|
|
44
|
+
disabled: false
|
|
45
|
+
})
|
|
46
|
+
|
|
47
|
+
const radioChecked = computed(() => model.value === props.value)
|
|
48
|
+
|
|
49
|
+
const classList = computed(() => {
|
|
50
|
+
return [
|
|
51
|
+
cls.b,
|
|
52
|
+
cls.m(size.value),
|
|
53
|
+
bem.is('disabled', disabled.value),
|
|
54
|
+
bem.is('checked', radioChecked.value)
|
|
55
|
+
]
|
|
56
|
+
})
|
|
57
|
+
</script>
|
|
@@ -0,0 +1,113 @@
|
|
|
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: radio;
|
|
6
|
+
|
|
7
|
+
// 移动端单选框指示器下限:过小难以辨认选中状态
|
|
8
|
+
$indicator-min: 20px;
|
|
9
|
+
|
|
10
|
+
@include m.b($root-name) {
|
|
11
|
+
vertical-align: middle;
|
|
12
|
+
user-select: none;
|
|
13
|
+
-webkit-tap-highlight-color: transparent;
|
|
14
|
+
border-radius: t.control-radius(small);
|
|
15
|
+
@include m.flex(inline-flex);
|
|
16
|
+
gap: t.spacing(default);
|
|
17
|
+
|
|
18
|
+
@include m.size using ($size) {
|
|
19
|
+
// 触控热区:整个 label 可点,不小于触控下限
|
|
20
|
+
min-height: max(t.control-height($size), t.use-var(touch-target));
|
|
21
|
+
min-width: t.use-var(touch-target);
|
|
22
|
+
|
|
23
|
+
@include m.bem($root-name, indicator) {
|
|
24
|
+
$indicator: max(calc(t.control-height($size) / 2), $indicator-min);
|
|
25
|
+
|
|
26
|
+
width: $indicator;
|
|
27
|
+
height: $indicator;
|
|
28
|
+
padding: 3px;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
@include m.bem($root-name, label) {
|
|
32
|
+
font-size: t.use-var(font-size-main);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
@include m.e(label) {
|
|
37
|
+
line-height: 1.4;
|
|
38
|
+
color: fn.use-var(text-color, main);
|
|
39
|
+
// 文本占满剩余宽度,把圆形选中标记推到行右
|
|
40
|
+
flex-grow: 1;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
@include m.e(indicator) {
|
|
44
|
+
border-radius: 50%;
|
|
45
|
+
border: fn.use-var(border, width) fn.use-var(border, style)
|
|
46
|
+
#{fn.component-var(radio, border, fn.use-var(text-color, assist))};
|
|
47
|
+
box-sizing: border-box;
|
|
48
|
+
flex-shrink: 0;
|
|
49
|
+
overflow: hidden;
|
|
50
|
+
transition:
|
|
51
|
+
border-color fn.use-var(transition, fast) fn.use-var(transition, ease),
|
|
52
|
+
box-shadow fn.use-var(transition, fast) fn.use-var(transition, ease);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
@include m.e(dot) {
|
|
56
|
+
background-color: fn.use-var(color, primary);
|
|
57
|
+
border-radius: 50%;
|
|
58
|
+
display: block;
|
|
59
|
+
height: 100%;
|
|
60
|
+
width: 100%;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
@include m.is(checked) {
|
|
64
|
+
@include m.bem($root-name, indicator) {
|
|
65
|
+
border-color: fn.use-var(color, primary);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
@include m.e(native) {
|
|
70
|
+
position: absolute;
|
|
71
|
+
width: 0;
|
|
72
|
+
height: 0;
|
|
73
|
+
opacity: 0;
|
|
74
|
+
margin: 0;
|
|
75
|
+
pointer-events: none;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
// label 不可聚焦,ring 由视觉隐藏的原生 input 驱动;移动端无 hover,按压反馈走 :active(整行底色)
|
|
79
|
+
@include m.is-not(disabled) {
|
|
80
|
+
&:active {
|
|
81
|
+
background-color: fn.use-var(color, default, light-9);
|
|
82
|
+
|
|
83
|
+
@include m.bem($root-name, indicator) {
|
|
84
|
+
border-color: fn.use-var(color, primary);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
.um-#{$root-name}__native:focus-visible ~ .um-#{$root-name}__indicator {
|
|
89
|
+
box-shadow: fn.use-var(focus-ring);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
@include m.is(disabled) {
|
|
94
|
+
color: fn.use-var(text-color, disabled);
|
|
95
|
+
cursor: not-allowed;
|
|
96
|
+
|
|
97
|
+
@include m.bem($root-name, indicator) {
|
|
98
|
+
border-color: fn.use-var(border, muted-color);
|
|
99
|
+
background-color: fn.use-var(color, disabled);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
@include m.bem($root-name, dot) {
|
|
103
|
+
background-color: fn.use-var(text-color, disabled);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
// 嵌入表单行时占满控件区,整行热区与列表行式布局协同
|
|
109
|
+
.um-form-item__content .um-#{$root-name} {
|
|
110
|
+
display: flex;
|
|
111
|
+
width: 100%;
|
|
112
|
+
min-height: t.use-var(form-row-height);
|
|
113
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import './style.scss'
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default as URadioGroup } from './radio-group.vue'
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<div v-if="!readonly" v-bind="$attrs" :class="[cls.b, cls.m(size), bem.is('divider', divider)]">
|
|
3
|
+
<URadio
|
|
4
|
+
v-for="item of items"
|
|
5
|
+
:key="item[valueKey]"
|
|
6
|
+
:value="item[valueKey]"
|
|
7
|
+
:model-value="model"
|
|
8
|
+
@update:model-value="handleUpdate($event, item)"
|
|
9
|
+
:disabled="disabledItem?.(item) || disabled"
|
|
10
|
+
:size="size"
|
|
11
|
+
>
|
|
12
|
+
{{ item[labelKey] }}
|
|
13
|
+
</URadio>
|
|
14
|
+
</div>
|
|
15
|
+
|
|
16
|
+
<template v-else>
|
|
17
|
+
{{ items.find((item) => item[valueKey] === model)?.[labelKey] || FORM_EMPTY_CONTENT }}
|
|
18
|
+
</template>
|
|
19
|
+
</template>
|
|
20
|
+
|
|
21
|
+
<script lang="ts" setup>
|
|
22
|
+
import { useFormFallbackProps } from '@veltra/compositions'
|
|
23
|
+
import { fieldKey, FORM_EMPTY_CONTENT, injectFormContext } from '@veltra/utils'
|
|
24
|
+
import { computed } from 'vue'
|
|
25
|
+
|
|
26
|
+
import { bem } from '../../shared/bem'
|
|
27
|
+
import type { RadioGroupEmits, RadioGroupProps } from '../../types/radio-group'
|
|
28
|
+
import URadio from '../radio/radio.vue'
|
|
29
|
+
|
|
30
|
+
defineOptions({ name: 'URadioGroup', inheritAttrs: false })
|
|
31
|
+
|
|
32
|
+
const props = withDefaults(defineProps<RadioGroupProps>(), {
|
|
33
|
+
labelKey: 'label',
|
|
34
|
+
valueKey: 'value',
|
|
35
|
+
disabled: undefined,
|
|
36
|
+
readonly: undefined
|
|
37
|
+
})
|
|
38
|
+
|
|
39
|
+
const model = defineModel<any>()
|
|
40
|
+
|
|
41
|
+
const emit = defineEmits<RadioGroupEmits>()
|
|
42
|
+
|
|
43
|
+
const { formProps } = injectFormContext()
|
|
44
|
+
|
|
45
|
+
const { size, disabled, readonly } = useFormFallbackProps([formProps ?? {}, props], {
|
|
46
|
+
size: 'default',
|
|
47
|
+
disabled: false,
|
|
48
|
+
readonly: false
|
|
49
|
+
})
|
|
50
|
+
|
|
51
|
+
const cls = bem('radio-group')
|
|
52
|
+
|
|
53
|
+
const labelKey = computed(() => fieldKey(props.labelKey, 'label'))
|
|
54
|
+
const valueKey = computed(() => fieldKey(props.valueKey, 'value'))
|
|
55
|
+
|
|
56
|
+
const handleUpdate = (value: any, item: Record<string, any>) => {
|
|
57
|
+
model.value = value
|
|
58
|
+
emit('change', item)
|
|
59
|
+
}
|
|
60
|
+
</script>
|
|
@@ -0,0 +1,29 @@
|
|
|
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: radio-group;
|
|
6
|
+
|
|
7
|
+
@include m.b($root-name) {
|
|
8
|
+
vertical-align: middle;
|
|
9
|
+
// 列表行式:选项纵向排列,整组占满可用宽度(表单内占满控件区)
|
|
10
|
+
display: flex;
|
|
11
|
+
flex-direction: column;
|
|
12
|
+
align-items: stretch;
|
|
13
|
+
width: 100%;
|
|
14
|
+
|
|
15
|
+
@include m.bem(radio) {
|
|
16
|
+
margin: 0;
|
|
17
|
+
display: flex;
|
|
18
|
+
min-height: t.use-var(form-row-height);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
// 行间细分隔线可选
|
|
22
|
+
@include m.is(divider) {
|
|
23
|
+
@include m.bem(radio) {
|
|
24
|
+
&:not(:last-of-type) {
|
|
25
|
+
border-bottom: 1px solid fn.use-var(border, muted-color);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default as USegment } from './segment.vue'
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<div
|
|
3
|
+
v-if="!readonly"
|
|
4
|
+
v-bind="$attrs"
|
|
5
|
+
ref="trackRef"
|
|
6
|
+
:class="[cls.b, bem.is('block', block), bem.is('disabled', disabled), cls.m(size)]"
|
|
7
|
+
role="radiogroup"
|
|
8
|
+
>
|
|
9
|
+
<div :class="cls.e('thumb')" :style="thumbStyle" aria-hidden="true" />
|
|
10
|
+
<div
|
|
11
|
+
v-for="item of items"
|
|
12
|
+
:key="item[valueKey]"
|
|
13
|
+
:class="[
|
|
14
|
+
cls.e('item'),
|
|
15
|
+
bem.is('active', item[valueKey] === model),
|
|
16
|
+
bem.is('disabled', disabled || Boolean(disabledItem?.(item)))
|
|
17
|
+
]"
|
|
18
|
+
role="radio"
|
|
19
|
+
:aria-checked="item[valueKey] === model"
|
|
20
|
+
:aria-disabled="disabled || Boolean(disabledItem?.(item))"
|
|
21
|
+
tabindex="0"
|
|
22
|
+
@click="handleSelect(item)"
|
|
23
|
+
@keydown.enter.prevent="handleSelect(item)"
|
|
24
|
+
@keydown.space.prevent="handleSelect(item)"
|
|
25
|
+
>
|
|
26
|
+
<slot name="item" :item="item" :active="item[valueKey] === model">
|
|
27
|
+
<span :class="cls.e('item-label')">{{ item[labelKey] }}</span>
|
|
28
|
+
</slot>
|
|
29
|
+
</div>
|
|
30
|
+
</div>
|
|
31
|
+
|
|
32
|
+
<template v-else>
|
|
33
|
+
{{ items.find((item) => item[valueKey] === model)?.[labelKey] || FORM_EMPTY_CONTENT }}
|
|
34
|
+
</template>
|
|
35
|
+
</template>
|
|
36
|
+
|
|
37
|
+
<script lang="ts" setup>
|
|
38
|
+
import { useFormFallbackProps, useResizeObserver } from '@veltra/compositions'
|
|
39
|
+
import { fieldKey, FORM_EMPTY_CONTENT, injectFormContext } from '@veltra/utils'
|
|
40
|
+
import { computed, nextTick, onMounted, shallowRef, watch } from 'vue'
|
|
41
|
+
|
|
42
|
+
import { bem } from '../../shared/bem'
|
|
43
|
+
import type { SegmentEmits, SegmentItem, SegmentProps } from '../../types/segment'
|
|
44
|
+
|
|
45
|
+
defineOptions({ name: 'USegment', inheritAttrs: false })
|
|
46
|
+
|
|
47
|
+
const props = withDefaults(defineProps<SegmentProps>(), {
|
|
48
|
+
items: () => [],
|
|
49
|
+
labelKey: 'label',
|
|
50
|
+
valueKey: 'value',
|
|
51
|
+
disabled: undefined,
|
|
52
|
+
readonly: undefined,
|
|
53
|
+
block: false
|
|
54
|
+
})
|
|
55
|
+
|
|
56
|
+
const model = defineModel<any>()
|
|
57
|
+
|
|
58
|
+
const emit = defineEmits<SegmentEmits>()
|
|
59
|
+
|
|
60
|
+
const { formProps } = injectFormContext()
|
|
61
|
+
|
|
62
|
+
const { size, disabled, readonly } = useFormFallbackProps([formProps ?? {}, props], {
|
|
63
|
+
size: 'default',
|
|
64
|
+
disabled: false,
|
|
65
|
+
readonly: false
|
|
66
|
+
})
|
|
67
|
+
|
|
68
|
+
const cls = bem('segment')
|
|
69
|
+
|
|
70
|
+
const labelKey = computed(() => fieldKey(props.labelKey, 'label'))
|
|
71
|
+
const valueKey = computed(() => fieldKey(props.valueKey, 'value'))
|
|
72
|
+
|
|
73
|
+
const trackRef = shallowRef<HTMLElement>()
|
|
74
|
+
const thumbX = shallowRef(0)
|
|
75
|
+
const thumbY = shallowRef(0)
|
|
76
|
+
const thumbW = shallowRef(0)
|
|
77
|
+
const thumbH = shallowRef(0)
|
|
78
|
+
const thumbRadius = shallowRef('0px')
|
|
79
|
+
const thumbOn = shallowRef(false)
|
|
80
|
+
|
|
81
|
+
const thumbStyle = computed(() => ({
|
|
82
|
+
width: `${thumbW.value}px`,
|
|
83
|
+
height: `${thumbH.value}px`,
|
|
84
|
+
borderRadius: thumbRadius.value,
|
|
85
|
+
transform: `translate(${thumbX.value}px, ${thumbY.value}px)`,
|
|
86
|
+
opacity: thumbOn.value ? '1' : '0'
|
|
87
|
+
}))
|
|
88
|
+
|
|
89
|
+
function measure() {
|
|
90
|
+
const track = trackRef.value
|
|
91
|
+
if (!track) return
|
|
92
|
+
const active = track.querySelector<HTMLElement>(':scope > .is-active')
|
|
93
|
+
if (!active) {
|
|
94
|
+
thumbOn.value = false
|
|
95
|
+
return
|
|
96
|
+
}
|
|
97
|
+
// 用布局坐标(offset*):thumb 是 track 内的绝对定位元素,需要的正是 track 坐标系内的
|
|
98
|
+
// 位置与尺寸。getBoundingClientRect 是视觉坐标,祖先链上有 transform: scale(如演示用
|
|
99
|
+
// 设备壳)时会把缩放差引入 translate,导致滑块越偏离原点偏移越大。
|
|
100
|
+
thumbX.value = active.offsetLeft
|
|
101
|
+
thumbY.value = active.offsetTop
|
|
102
|
+
thumbW.value = active.offsetWidth
|
|
103
|
+
thumbH.value = active.offsetHeight
|
|
104
|
+
thumbRadius.value = getComputedStyle(active).borderRadius
|
|
105
|
+
thumbOn.value = true
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
useResizeObserver({ targets: trackRef, onResize: () => measure() })
|
|
109
|
+
|
|
110
|
+
watch([model, () => props.items, size], () => nextTick(measure), { deep: true })
|
|
111
|
+
|
|
112
|
+
onMounted(() => nextTick(measure))
|
|
113
|
+
|
|
114
|
+
const handleSelect = (item: SegmentItem) => {
|
|
115
|
+
if (disabled.value || props.disabledItem?.(item)) return
|
|
116
|
+
const val = item[valueKey.value]
|
|
117
|
+
if (model.value === val) return
|
|
118
|
+
model.value = val
|
|
119
|
+
emit('change', item)
|
|
120
|
+
}
|
|
121
|
+
</script>
|
|
@@ -0,0 +1,118 @@
|
|
|
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
|
+
@include m.b(segment) {
|
|
6
|
+
position: relative;
|
|
7
|
+
vertical-align: middle;
|
|
8
|
+
@include m.flex($display: inline-flex, $align: center);
|
|
9
|
+
gap: 2px;
|
|
10
|
+
padding: 2px;
|
|
11
|
+
background-color: fn.use-var(bg-color, bottom);
|
|
12
|
+
box-sizing: border-box;
|
|
13
|
+
max-width: 100%;
|
|
14
|
+
-webkit-tap-highlight-color: transparent;
|
|
15
|
+
|
|
16
|
+
@include m.e(thumb) {
|
|
17
|
+
position: absolute;
|
|
18
|
+
left: 0;
|
|
19
|
+
top: 0;
|
|
20
|
+
z-index: 0;
|
|
21
|
+
pointer-events: none;
|
|
22
|
+
background-color: fn.use-var(bg-color, top);
|
|
23
|
+
box-shadow: fn.use-var(shadow, sm);
|
|
24
|
+
transition:
|
|
25
|
+
transform 200ms cubic-bezier(0.77, 0, 0.175, 1),
|
|
26
|
+
opacity 200ms cubic-bezier(0.77, 0, 0.175, 1);
|
|
27
|
+
|
|
28
|
+
@media (prefers-reduced-motion: reduce) {
|
|
29
|
+
transition: none;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
@include m.size using ($size) {
|
|
34
|
+
border-radius: t.control-radius($size);
|
|
35
|
+
|
|
36
|
+
@include m.bem(segment, item) {
|
|
37
|
+
// 密度走移动端 token:视觉高度 ≥32px、触控热区 ≥44×44
|
|
38
|
+
// (block 形态由更高特异性保持 min-width: 0 的弹性分配)
|
|
39
|
+
min-height: max(calc(#{t.control-height($size)} - 4px), t.use-var('touch-target'));
|
|
40
|
+
min-width: max(calc(#{t.control-height($size)} - 4px), t.use-var('touch-target'));
|
|
41
|
+
padding: 0 calc(#{t.spacing($size)} * 1.5);
|
|
42
|
+
border-radius: calc(#{t.control-radius($size)} - 2px);
|
|
43
|
+
font-size: t.use-var('font-size-main');
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
@include m.e(item) {
|
|
48
|
+
position: relative;
|
|
49
|
+
z-index: 1;
|
|
50
|
+
margin: 0;
|
|
51
|
+
display: inline-flex;
|
|
52
|
+
align-items: center;
|
|
53
|
+
justify-content: center;
|
|
54
|
+
box-sizing: border-box;
|
|
55
|
+
background-color: transparent;
|
|
56
|
+
box-shadow: none;
|
|
57
|
+
font-weight: 500;
|
|
58
|
+
color: fn.use-var(text-color, second);
|
|
59
|
+
cursor: pointer;
|
|
60
|
+
user-select: none;
|
|
61
|
+
outline: none;
|
|
62
|
+
transition:
|
|
63
|
+
color fn.use-var(transition, fast) fn.use-var(transition, ease),
|
|
64
|
+
background-color fn.use-var(transition, fast) fn.use-var(transition, ease),
|
|
65
|
+
box-shadow fn.use-var(transition, fast) fn.use-var(transition, ease);
|
|
66
|
+
|
|
67
|
+
// 按压态(移动端无 hover,用 :active 提供触控反馈)
|
|
68
|
+
&:active:not(.is-active):not(.is-disabled) {
|
|
69
|
+
color: fn.use-var(text-color, title);
|
|
70
|
+
background-color: fn.color-a(color, 5, primary);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
@include m.is(active) {
|
|
74
|
+
color: fn.use-var(color, primary);
|
|
75
|
+
background-color: transparent;
|
|
76
|
+
box-shadow: none;
|
|
77
|
+
font-weight: 600;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
@include m.is(disabled) {
|
|
81
|
+
opacity: 0.5;
|
|
82
|
+
cursor: not-allowed;
|
|
83
|
+
color: fn.use-var(text-color, disabled);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
&:focus-visible:not(.is-disabled) {
|
|
87
|
+
box-shadow: fn.use-var(focus-ring);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
@include m.e(item-label) {
|
|
92
|
+
@include m.ellipsis;
|
|
93
|
+
display: inline-flex;
|
|
94
|
+
align-items: center;
|
|
95
|
+
justify-content: center;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
@include m.is(block) {
|
|
99
|
+
display: flex;
|
|
100
|
+
width: 100%;
|
|
101
|
+
|
|
102
|
+
@include m.bem(segment, item) {
|
|
103
|
+
flex: 1 1 0%;
|
|
104
|
+
width: 0;
|
|
105
|
+
min-width: 0;
|
|
106
|
+
display: inline-flex;
|
|
107
|
+
justify-content: center;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
@include m.is(disabled) {
|
|
112
|
+
opacity: 0.7;
|
|
113
|
+
|
|
114
|
+
@include m.bem(segment, item) {
|
|
115
|
+
opacity: 1;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import './style.scss'
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default as USelect } from './select.vue'
|