@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,132 @@
|
|
|
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: checkbox;
|
|
6
|
+
|
|
7
|
+
// 移动端复选框指示器下限:过小难以辨认勾选状态
|
|
8
|
+
$indicator-min: 20px;
|
|
9
|
+
|
|
10
|
+
@include m.b($root-name) {
|
|
11
|
+
user-select: none;
|
|
12
|
+
vertical-align: middle;
|
|
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
|
+
height: $indicator;
|
|
27
|
+
width: $indicator;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
@include m.bem($root-name, label) {
|
|
31
|
+
font-size: t.use-var(font-size-main);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
@include m.is(checked) {
|
|
36
|
+
@include m.bem($root-name, indicator) {
|
|
37
|
+
background-color: fn.use-var(color, primary);
|
|
38
|
+
border-color: fn.use-var(color, primary);
|
|
39
|
+
color: fn.use-var(text-color, white);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
@include m.is(disabled) {
|
|
43
|
+
@include m.bem($root-name, indicator) {
|
|
44
|
+
background-color: fn.use-var(text-color, disabled);
|
|
45
|
+
border-color: fn.use-var(border, muted-color);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
@include m.is(disabled) {
|
|
51
|
+
cursor: not-allowed;
|
|
52
|
+
|
|
53
|
+
@include m.bem($root-name, indicator) {
|
|
54
|
+
background-color: fn.use-var(color, disabled);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
@include m.bem($root-name, label) {
|
|
58
|
+
color: fn.use-var(text-color, disabled);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
@include m.is(readonly) {
|
|
63
|
+
cursor: default;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
@include m.e(native) {
|
|
67
|
+
position: absolute;
|
|
68
|
+
width: 0;
|
|
69
|
+
height: 0;
|
|
70
|
+
opacity: 0;
|
|
71
|
+
margin: 0;
|
|
72
|
+
pointer-events: none;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
@include m.e(indicator) {
|
|
76
|
+
border: fn.use-var(border, width) fn.use-var(border, style)
|
|
77
|
+
#{fn.component-var(checkbox, border, fn.use-var(text-color, assist))};
|
|
78
|
+
// 圆形勾选惯例:与方形桌面形态区分,贴合移动端列表行式选项
|
|
79
|
+
border-radius: 50%;
|
|
80
|
+
color: fn.use-var(text-color, white);
|
|
81
|
+
box-sizing: border-box;
|
|
82
|
+
flex-shrink: 0;
|
|
83
|
+
transition:
|
|
84
|
+
background-color fn.use-var(transition, fast) fn.use-var(transition, ease),
|
|
85
|
+
border-color fn.use-var(transition, fast) fn.use-var(transition, ease),
|
|
86
|
+
box-shadow fn.use-var(transition, fast) fn.use-var(transition, ease);
|
|
87
|
+
@include m.flex(inline-flex, center);
|
|
88
|
+
|
|
89
|
+
svg {
|
|
90
|
+
width: 100%;
|
|
91
|
+
height: 100%;
|
|
92
|
+
padding: 15%;
|
|
93
|
+
box-sizing: border-box;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
// label 不可聚焦,ring 由视觉隐藏的原生 input 驱动;移动端无 hover,按压反馈走 :active(整行底色)
|
|
98
|
+
@include m.is-not(disabled, readonly) {
|
|
99
|
+
&:active {
|
|
100
|
+
background-color: fn.use-var(color, default, light-9);
|
|
101
|
+
|
|
102
|
+
@include m.bem($root-name, indicator) {
|
|
103
|
+
border-color: fn.use-var(color, primary);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
.um-#{$root-name}__native:focus-visible + .um-#{$root-name}__indicator {
|
|
108
|
+
box-shadow: fn.use-var(focus-ring);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
@include m.e(label) {
|
|
113
|
+
line-height: 1.4;
|
|
114
|
+
color: fn.use-var(text-color, main);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
@include m.m(indeterminate) {
|
|
118
|
+
background-color: fn.use-var(text-color, white);
|
|
119
|
+
width: 10px;
|
|
120
|
+
height: 2px;
|
|
121
|
+
vertical-align: middle;
|
|
122
|
+
display: block;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
// 嵌入表单行时占满控件区,整行热区与列表行式布局协同。
|
|
127
|
+
// :where 降特异性:checkbox-group 内的行高由组规则收敛,此规则只约束单个复选框
|
|
128
|
+
.um-form-item__content :where(.um-#{$root-name}) {
|
|
129
|
+
display: flex;
|
|
130
|
+
width: 100%;
|
|
131
|
+
min-height: t.use-var(form-row-height);
|
|
132
|
+
}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<div v-if="!readonly" v-bind="$attrs" :class="[cls.b, cls.m(size), bem.is('divider', divider)]">
|
|
3
|
+
<UCheckbox
|
|
4
|
+
v-for="item of items"
|
|
5
|
+
:key="item[valueKey]"
|
|
6
|
+
:model-value="getCheckStatus(item)"
|
|
7
|
+
@update:model-value="handleUpdate($event, item)"
|
|
8
|
+
:disabled="disabled"
|
|
9
|
+
:size="size"
|
|
10
|
+
>
|
|
11
|
+
{{ item[labelKey] }}
|
|
12
|
+
</UCheckbox>
|
|
13
|
+
</div>
|
|
14
|
+
|
|
15
|
+
<div v-else-if="model?.length" :class="[cls.m(size), cls.e('readonly-tags')]">
|
|
16
|
+
<div :class="cls.e('tags')">
|
|
17
|
+
<UTag v-for="tag of model" :key="tag">
|
|
18
|
+
{{ getLabel(tag) }}
|
|
19
|
+
</UTag>
|
|
20
|
+
</div>
|
|
21
|
+
</div>
|
|
22
|
+
|
|
23
|
+
<template v-else>
|
|
24
|
+
{{ FORM_EMPTY_CONTENT }}
|
|
25
|
+
</template>
|
|
26
|
+
</template>
|
|
27
|
+
|
|
28
|
+
<script lang="ts" setup>
|
|
29
|
+
import { useFormFallbackProps } from '@veltra/compositions'
|
|
30
|
+
import { fieldKey, FORM_EMPTY_CONTENT, injectFormContext } from '@veltra/utils'
|
|
31
|
+
import { computed } from 'vue'
|
|
32
|
+
|
|
33
|
+
import { bem } from '../../shared/bem'
|
|
34
|
+
import type { CheckboxGroupEmits, CheckboxGroupProps } from '../../types/checkbox-group'
|
|
35
|
+
import { UCheckbox } from '../checkbox'
|
|
36
|
+
import { UTag } from '../tag'
|
|
37
|
+
|
|
38
|
+
defineOptions({ name: 'UCheckboxGroup', inheritAttrs: false })
|
|
39
|
+
|
|
40
|
+
const props = withDefaults(defineProps<CheckboxGroupProps>(), {
|
|
41
|
+
labelKey: 'label',
|
|
42
|
+
valueKey: 'value',
|
|
43
|
+
disabled: undefined,
|
|
44
|
+
readonly: undefined
|
|
45
|
+
})
|
|
46
|
+
defineEmits<CheckboxGroupEmits>()
|
|
47
|
+
|
|
48
|
+
const model = defineModel<any[]>()
|
|
49
|
+
|
|
50
|
+
const cls = bem('checkbox-group')
|
|
51
|
+
|
|
52
|
+
const labelKey = computed(() => fieldKey(props.labelKey, 'label'))
|
|
53
|
+
const valueKey = computed(() => fieldKey(props.valueKey, 'value'))
|
|
54
|
+
|
|
55
|
+
const { formProps } = injectFormContext()
|
|
56
|
+
|
|
57
|
+
const { size, disabled, readonly } = useFormFallbackProps([formProps ?? {}, props], {
|
|
58
|
+
size: 'default',
|
|
59
|
+
disabled: false,
|
|
60
|
+
readonly: false
|
|
61
|
+
})
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* 获取checkbox的选中状态
|
|
65
|
+
* @param item - 模型对象
|
|
66
|
+
* @returns 模型值是否存在于model.value中
|
|
67
|
+
*/
|
|
68
|
+
const getCheckStatus = (item: Record<string, string | number>): boolean => {
|
|
69
|
+
const value = item[valueKey.value]
|
|
70
|
+
if (!value || !model.value) return false
|
|
71
|
+
return model.value.includes(value)
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* 处理更新操作
|
|
76
|
+
* @param checked - 指示是否选中
|
|
77
|
+
* @param item - 更新的项
|
|
78
|
+
*/
|
|
79
|
+
const handleUpdate = (checked: boolean, item: Record<string, string | number>) => {
|
|
80
|
+
const value = item[valueKey.value]
|
|
81
|
+
if (!value) return
|
|
82
|
+
if (checked) {
|
|
83
|
+
model.value = [...(model.value ?? []), value]
|
|
84
|
+
} else {
|
|
85
|
+
model.value = model.value?.filter((v) => v !== value)
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
const getLabel = (value: string | number) => {
|
|
90
|
+
const { items } = props
|
|
91
|
+
const item = items.find((item) => item[valueKey.value] === value)
|
|
92
|
+
return item?.[labelKey.value]
|
|
93
|
+
}
|
|
94
|
+
</script>
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default as UCheckboxGroup } from './checkbox-group.vue'
|
|
@@ -0,0 +1,57 @@
|
|
|
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: checkbox-group;
|
|
6
|
+
|
|
7
|
+
@include m.b($root-name) {
|
|
8
|
+
line-height: 1;
|
|
9
|
+
vertical-align: middle;
|
|
10
|
+
// 列表行式:选项纵向排列,整组占满可用宽度(表单内占满控件区)
|
|
11
|
+
display: flex;
|
|
12
|
+
flex-direction: column;
|
|
13
|
+
align-items: stretch;
|
|
14
|
+
width: 100%;
|
|
15
|
+
|
|
16
|
+
@include m.bem(checkbox) {
|
|
17
|
+
margin: 0;
|
|
18
|
+
display: flex;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
// 行高按尺寸收敛(不用 48px 表单行高):组内项内容小,行高过大显得间隔稀疏;
|
|
22
|
+
// 仍保留 44px 触控热区下限
|
|
23
|
+
@include m.size using ($size) {
|
|
24
|
+
@include m.bem(checkbox) {
|
|
25
|
+
min-height: max(t.control-height($size), t.use-var(touch-target));
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// 行间细分隔线可选
|
|
30
|
+
@include m.is(divider) {
|
|
31
|
+
@include m.bem(checkbox) {
|
|
32
|
+
&:not(:last-of-type) {
|
|
33
|
+
border-bottom: 1px solid fn.use-var(border, muted-color);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
@include m.size using ($size) {
|
|
39
|
+
@include m.bem($root-name, tags) {
|
|
40
|
+
gap: calc((fn.use-var(form-component-height, $size) - fn.use-var(tag, $size)) / 2);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
@include m.e(tags) {
|
|
45
|
+
flex-grow: 1;
|
|
46
|
+
@include m.flex($justify: flex-start, $align: center, $wrap: wrap);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
@include m.e(readonly-tags) {
|
|
50
|
+
padding-left: 0;
|
|
51
|
+
padding-right: 0;
|
|
52
|
+
|
|
53
|
+
@include m.bem(tag) {
|
|
54
|
+
border: 1px dashed fn.use-var(text-color, main);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<div :class="classList">
|
|
3
|
+
<div
|
|
4
|
+
:class="headerClassList"
|
|
5
|
+
role="button"
|
|
6
|
+
:aria-expanded="isActive"
|
|
7
|
+
:aria-disabled="disabled"
|
|
8
|
+
:tabindex="disabled ? -1 : 0"
|
|
9
|
+
@click="handleClick"
|
|
10
|
+
@keydown.enter.prevent="handleClick"
|
|
11
|
+
@keydown.space.prevent="handleClick"
|
|
12
|
+
>
|
|
13
|
+
<span :class="cls.e('title')">
|
|
14
|
+
<slot name="header" :is-active="isActive">{{ title }}</slot>
|
|
15
|
+
</span>
|
|
16
|
+
|
|
17
|
+
<span :class="cls.e('icon')">
|
|
18
|
+
<component :is="iconComponent" />
|
|
19
|
+
</span>
|
|
20
|
+
</div>
|
|
21
|
+
<div ref="wrapperEl" :class="cls.e('content-wrapper')" :aria-hidden="!isActive">
|
|
22
|
+
<div v-if="contentMounted" :class="cls.e('content')">
|
|
23
|
+
<slot />
|
|
24
|
+
</div>
|
|
25
|
+
</div>
|
|
26
|
+
</div>
|
|
27
|
+
</template>
|
|
28
|
+
|
|
29
|
+
<script lang="ts" setup>
|
|
30
|
+
import { ArrowDown } from '@veltra/icons/normal'
|
|
31
|
+
import { ExpandTransition } from '@veltra/utils'
|
|
32
|
+
import { computed, inject, nextTick, onBeforeUnmount, onMounted, ref, watch } from 'vue'
|
|
33
|
+
|
|
34
|
+
import { bem } from '../../shared/bem'
|
|
35
|
+
import type { CollapseItemEmits, CollapseItemProps } from '../../types/collapse'
|
|
36
|
+
import { CollapseDIKey } from './di'
|
|
37
|
+
|
|
38
|
+
defineOptions({ name: 'UCollapseItem' })
|
|
39
|
+
|
|
40
|
+
const props = defineProps<CollapseItemProps>()
|
|
41
|
+
|
|
42
|
+
const emit = defineEmits<CollapseItemEmits>()
|
|
43
|
+
|
|
44
|
+
defineSlots<{
|
|
45
|
+
/** 自定义标题区,作用域参数 `isActive` 指示展开状态;缺省渲染 title。展开图标始终由组件渲染,活动态旋转 180° */
|
|
46
|
+
header?: (scope: { isActive: boolean }) => any
|
|
47
|
+
/** 折叠面板内容 */
|
|
48
|
+
default?: () => any
|
|
49
|
+
}>()
|
|
50
|
+
|
|
51
|
+
const context = inject(CollapseDIKey, undefined)
|
|
52
|
+
|
|
53
|
+
const cls = context?.cls ?? bem('collapse')
|
|
54
|
+
|
|
55
|
+
const standaloneModel = defineModel<boolean>({ default: false })
|
|
56
|
+
|
|
57
|
+
const isActive = computed(() => {
|
|
58
|
+
if (context) {
|
|
59
|
+
return props.value !== undefined && context.activeValues.value.includes(props.value)
|
|
60
|
+
}
|
|
61
|
+
return !!standaloneModel.value
|
|
62
|
+
})
|
|
63
|
+
|
|
64
|
+
const iconComponent = computed(() => context?.expandIcon.value ?? props.expandIcon ?? ArrowDown)
|
|
65
|
+
|
|
66
|
+
const classList = computed(() => [
|
|
67
|
+
cls.e('item'),
|
|
68
|
+
bem.is('active', isActive.value),
|
|
69
|
+
bem.is('disabled', props.disabled)
|
|
70
|
+
])
|
|
71
|
+
|
|
72
|
+
const headerClassList = computed(() => [
|
|
73
|
+
cls.e('header'),
|
|
74
|
+
bem.is('disabled', props.disabled),
|
|
75
|
+
bem.is('active', isActive.value)
|
|
76
|
+
])
|
|
77
|
+
|
|
78
|
+
const expandTransition =
|
|
79
|
+
context?.expandTransition ??
|
|
80
|
+
new ExpandTransition({ transition: 'height 0.24s cubic-bezier(0.4, 0, 0.2, 1)' })
|
|
81
|
+
|
|
82
|
+
const handleClick = () => {
|
|
83
|
+
if (props.disabled) return
|
|
84
|
+
|
|
85
|
+
if (context) {
|
|
86
|
+
if (props.value === undefined) return
|
|
87
|
+
context.toggle(props.value)
|
|
88
|
+
return
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
const next = !standaloneModel.value
|
|
92
|
+
standaloneModel.value = next
|
|
93
|
+
emit('change', next)
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
const wrapperEl = ref<HTMLElement>()
|
|
97
|
+
|
|
98
|
+
/** 内容是否挂载:destroyOnCollapse 时折叠态卸载内容 DOM,展开前重新挂载 */
|
|
99
|
+
const contentMounted = ref(isActive.value || !props.destroyOnCollapse)
|
|
100
|
+
|
|
101
|
+
onMounted(() => {
|
|
102
|
+
if (context && props.value !== undefined) {
|
|
103
|
+
context.register(props.value)
|
|
104
|
+
}
|
|
105
|
+
if (!wrapperEl.value) return
|
|
106
|
+
expandTransition.setExpanded(wrapperEl.value, isActive.value)
|
|
107
|
+
})
|
|
108
|
+
|
|
109
|
+
watch(isActive, async (active) => {
|
|
110
|
+
if (active) {
|
|
111
|
+
// 展开前先挂载内容,待 DOM 更新后再测量高度驱动展开动画
|
|
112
|
+
if (!contentMounted.value) {
|
|
113
|
+
contentMounted.value = true
|
|
114
|
+
await nextTick()
|
|
115
|
+
}
|
|
116
|
+
if (!wrapperEl.value || !isActive.value) return
|
|
117
|
+
expandTransition.expand(wrapperEl.value)
|
|
118
|
+
return
|
|
119
|
+
}
|
|
120
|
+
if (!wrapperEl.value) return
|
|
121
|
+
// 收起动画落定后再卸载内容 DOM;期间被重新展开则不卸载
|
|
122
|
+
expandTransition.collapse(wrapperEl.value, () => {
|
|
123
|
+
if (!isActive.value && props.destroyOnCollapse) contentMounted.value = false
|
|
124
|
+
})
|
|
125
|
+
})
|
|
126
|
+
|
|
127
|
+
onBeforeUnmount(() => {
|
|
128
|
+
if (context && props.value !== undefined) {
|
|
129
|
+
context.unregister(props.value)
|
|
130
|
+
}
|
|
131
|
+
if (!wrapperEl.value) return
|
|
132
|
+
expandTransition.cancel(wrapperEl.value)
|
|
133
|
+
})
|
|
134
|
+
</script>
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<div :class="classList" role="region">
|
|
3
|
+
<slot />
|
|
4
|
+
</div>
|
|
5
|
+
</template>
|
|
6
|
+
|
|
7
|
+
<script lang="ts" setup>
|
|
8
|
+
import { ExpandTransition } from '@veltra/utils'
|
|
9
|
+
import { computed, provide, ref } from 'vue'
|
|
10
|
+
|
|
11
|
+
import { bem } from '../../shared/bem'
|
|
12
|
+
import type {
|
|
13
|
+
CollapseEmits,
|
|
14
|
+
CollapseModelValue,
|
|
15
|
+
CollapseProps,
|
|
16
|
+
CollapseValue
|
|
17
|
+
} from '../../types/collapse'
|
|
18
|
+
import { CollapseDIKey } from './di'
|
|
19
|
+
|
|
20
|
+
defineOptions({ name: 'UCollapse' })
|
|
21
|
+
|
|
22
|
+
const props = withDefaults(defineProps<CollapseProps>(), {
|
|
23
|
+
accordion: false,
|
|
24
|
+
defaultCollapseAll: false
|
|
25
|
+
})
|
|
26
|
+
|
|
27
|
+
const emit = defineEmits<CollapseEmits>()
|
|
28
|
+
|
|
29
|
+
const cls = bem('collapse')
|
|
30
|
+
|
|
31
|
+
const expandTransition = new ExpandTransition({
|
|
32
|
+
transition: 'height 0.24s cubic-bezier(0.4, 0, 0.2, 1)'
|
|
33
|
+
})
|
|
34
|
+
|
|
35
|
+
const size = computed(() => props.size ?? 'default')
|
|
36
|
+
|
|
37
|
+
const expandIcon = computed(() => props.expandIcon)
|
|
38
|
+
|
|
39
|
+
const classList = computed(() => [cls.b, cls.m(size.value)])
|
|
40
|
+
|
|
41
|
+
const modelValue = defineModel<CollapseModelValue>()
|
|
42
|
+
|
|
43
|
+
const activeValues = computed<CollapseValue[]>(() => {
|
|
44
|
+
const v = modelValue.value
|
|
45
|
+
if (v === undefined || v === null) return []
|
|
46
|
+
return Array.isArray(v) ? v : [v]
|
|
47
|
+
})
|
|
48
|
+
|
|
49
|
+
const update = (next: CollapseModelValue) => {
|
|
50
|
+
modelValue.value = next
|
|
51
|
+
emit('change', next)
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const toggle = (value: CollapseValue) => {
|
|
55
|
+
if (props.accordion) {
|
|
56
|
+
update(activeValues.value[0] === value ? [] : value)
|
|
57
|
+
return
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
const values = activeValues.value.slice()
|
|
61
|
+
const index = values.indexOf(value)
|
|
62
|
+
if (index > -1) values.splice(index, 1)
|
|
63
|
+
else values.push(value)
|
|
64
|
+
update(values)
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
// 收集子组件已注册的 values
|
|
68
|
+
const registeredValues = ref<CollapseValue[]>([])
|
|
69
|
+
|
|
70
|
+
// 初始捕获 modelValue 是否具有有效初值
|
|
71
|
+
const hasInitialValue =
|
|
72
|
+
modelValue.value !== undefined &&
|
|
73
|
+
modelValue.value !== null &&
|
|
74
|
+
(!Array.isArray(modelValue.value) || modelValue.value.length > 0)
|
|
75
|
+
|
|
76
|
+
const register = (value: CollapseValue) => {
|
|
77
|
+
if (!registeredValues.value.includes(value)) {
|
|
78
|
+
registeredValues.value.push(value)
|
|
79
|
+
|
|
80
|
+
// 若默认展开全部(defaultCollapseAll 为 false)且外部未指定初始值,则自动展开该子项
|
|
81
|
+
if (!props.defaultCollapseAll && !hasInitialValue) {
|
|
82
|
+
if (props.accordion) {
|
|
83
|
+
if (registeredValues.value.length === 1) {
|
|
84
|
+
update(value)
|
|
85
|
+
}
|
|
86
|
+
} else {
|
|
87
|
+
const current = Array.isArray(modelValue.value)
|
|
88
|
+
? modelValue.value
|
|
89
|
+
: modelValue.value !== undefined && modelValue.value !== null
|
|
90
|
+
? [modelValue.value]
|
|
91
|
+
: []
|
|
92
|
+
if (!current.includes(value)) {
|
|
93
|
+
update([...current, value])
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
const unregister = (value: CollapseValue) => {
|
|
101
|
+
const idx = registeredValues.value.indexOf(value)
|
|
102
|
+
if (idx > -1) {
|
|
103
|
+
registeredValues.value.splice(idx, 1)
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
provide(CollapseDIKey, {
|
|
108
|
+
cls,
|
|
109
|
+
size,
|
|
110
|
+
expandIcon,
|
|
111
|
+
activeValues,
|
|
112
|
+
toggle,
|
|
113
|
+
expandTransition,
|
|
114
|
+
register,
|
|
115
|
+
unregister
|
|
116
|
+
})
|
|
117
|
+
</script>
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { type ComponentSize, ExpandTransition } from '@veltra/utils'
|
|
2
|
+
import type { Component, ComputedRef, InjectionKey } from 'vue'
|
|
3
|
+
|
|
4
|
+
import { type MobileBEM } from '../../shared/bem'
|
|
5
|
+
import type { CollapseValue } from '../../types/collapse'
|
|
6
|
+
|
|
7
|
+
export interface CollapseContext {
|
|
8
|
+
cls: MobileBEM<'collapse'>
|
|
9
|
+
size: ComputedRef<ComponentSize>
|
|
10
|
+
expandIcon: ComputedRef<Component | undefined>
|
|
11
|
+
activeValues: ComputedRef<CollapseValue[]>
|
|
12
|
+
toggle: (value: CollapseValue) => void
|
|
13
|
+
expandTransition: ExpandTransition
|
|
14
|
+
register: (value: CollapseValue) => void
|
|
15
|
+
unregister: (value: CollapseValue) => void
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export const CollapseDIKey: InjectionKey<CollapseContext> = Symbol('Collapse')
|