Skip to content

Commit 5e55da4

Browse files
feat: ✨ 移除Switch默认的size支持在不指定size的情况下使用css变量设置组件尺寸
Closes: #516
1 parent 21f0b17 commit 5e55da4

3 files changed

Lines changed: 10 additions & 5 deletions

File tree

src/uni_modules/wot-design-uni/components/wd-switch/types.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { ExtractPropTypes, PropType } from 'vue'
2-
import { baseProps, makeBooleanProp, makeNumberProp, makeNumericProp } from '../common/props'
2+
import { baseProps, makeBooleanProp, makeNumberProp, makeNumericProp, numericProp } from '../common/props'
33

44
export type SwitchBeforeChangeOption = {
55
value: number | string | boolean
@@ -47,7 +47,9 @@ export const switchProps = {
4747
/**
4848
* 大小
4949
*/
50-
size: makeNumericProp(28),
50+
size: {
51+
type: numericProp
52+
},
5153
/**
5254
* 在改变前执行的函数
5355
*/

src/uni_modules/wot-design-uni/components/wd-switch/wd-switch.vue

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export default {
1515
</script>
1616

1717
<script lang="ts" setup>
18-
import { computed, onBeforeMount } from 'vue'
18+
import { computed, type CSSProperties, onBeforeMount } from 'vue'
1919
import { addUnit, isFunction, objToStyle } from '../common/util'
2020
import { switchProps } from './types'
2121
@@ -27,11 +27,13 @@ const rootClass = computed(() => {
2727
})
2828
2929
const rootStyle = computed(() => {
30-
const rootStyle: Record<string, any> = {
31-
'font-size': addUnit(props.size),
30+
const rootStyle: CSSProperties = {
3231
background: props.modelValue === props.activeValue ? props.activeColor : props.inactiveColor,
3332
'border-color': props.modelValue === props.activeValue ? props.activeColor : props.inactiveColor
3433
}
34+
if (props.size) {
35+
rootStyle['font-size'] = addUnit(props.size)
36+
}
3537
return `${objToStyle(rootStyle)};${props.customStyle}`
3638
})
3739

tsconfig.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
22
"extends": "@vue/tsconfig/tsconfig.json",
33
"compilerOptions": {
4+
"verbatimModuleSyntax":true,
45
"ignoreDeprecations": "5.0",
56
"lib": [
67
"ESNext",

0 commit comments

Comments
 (0)