feat: 移除Switch默认的size支持在不指定size的情况下使用css变量设置组件尺寸

 Closes: #516
This commit is contained in:
Moonofweisheng 2024-11-06 21:23:44 +08:00
parent 21f0b178b6
commit 5e55da4839
3 changed files with 10 additions and 5 deletions

View File

@ -1,5 +1,5 @@
import type { ExtractPropTypes, PropType } from 'vue' import type { ExtractPropTypes, PropType } from 'vue'
import { baseProps, makeBooleanProp, makeNumberProp, makeNumericProp } from '../common/props' import { baseProps, makeBooleanProp, makeNumberProp, makeNumericProp, numericProp } from '../common/props'
export type SwitchBeforeChangeOption = { export type SwitchBeforeChangeOption = {
value: number | string | boolean value: number | string | boolean
@ -47,7 +47,9 @@ export const switchProps = {
/** /**
* *
*/ */
size: makeNumericProp(28), size: {
type: numericProp
},
/** /**
* *
*/ */

View File

@ -15,7 +15,7 @@ export default {
</script> </script>
<script lang="ts" setup> <script lang="ts" setup>
import { computed, onBeforeMount } from 'vue' import { computed, type CSSProperties, onBeforeMount } from 'vue'
import { addUnit, isFunction, objToStyle } from '../common/util' import { addUnit, isFunction, objToStyle } from '../common/util'
import { switchProps } from './types' import { switchProps } from './types'
@ -27,11 +27,13 @@ const rootClass = computed(() => {
}) })
const rootStyle = computed(() => { const rootStyle = computed(() => {
const rootStyle: Record<string, any> = { const rootStyle: CSSProperties = {
'font-size': addUnit(props.size),
background: props.modelValue === props.activeValue ? props.activeColor : props.inactiveColor, background: props.modelValue === props.activeValue ? props.activeColor : props.inactiveColor,
'border-color': props.modelValue === props.activeValue ? props.activeColor : props.inactiveColor 'border-color': props.modelValue === props.activeValue ? props.activeColor : props.inactiveColor
} }
if (props.size) {
rootStyle['font-size'] = addUnit(props.size)
}
return `${objToStyle(rootStyle)};${props.customStyle}` return `${objToStyle(rootStyle)};${props.customStyle}`
}) })

View File

@ -1,6 +1,7 @@
{ {
"extends": "@vue/tsconfig/tsconfig.json", "extends": "@vue/tsconfig/tsconfig.json",
"compilerOptions": { "compilerOptions": {
"verbatimModuleSyntax":true,
"ignoreDeprecations": "5.0", "ignoreDeprecations": "5.0",
"lib": [ "lib": [
"ESNext", "ESNext",