Skip to content

Commit c9443e0

Browse files
authored
feat: switch support cssvar (#7940)
1 parent 68a3f08 commit c9443e0

File tree

4 files changed

+17
-10
lines changed

4 files changed

+17
-10
lines changed

components/switch/demo/basic.vue

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ The most basic usage.
1919
<template>
2020
<a-switch v-model:checked="checked" />
2121
</template>
22+
2223
<script lang="ts" setup>
2324
import { ref } from 'vue';
24-
const checked = ref<boolean>(false);
25+
const checked = ref<boolean>(true);
2526
</script>

components/switch/demo/size.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,6 @@ title:
2727
import { reactive } from 'vue';
2828
const state = reactive({
2929
checked1: true,
30-
checked2: false,
30+
checked2: true,
3131
});
3232
</script>

components/switch/demo/text.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ With text and icon.
1818

1919
<template>
2020
<a-space direction="vertical">
21-
<a-switch v-model:checked="state.checked1" checked-children="" un-checked-children="" />
21+
<a-switch v-model:checked="state.checked1" checked-children="开启" un-checked-children="关闭" />
2222
<a-switch v-model:checked="state.checked2" checked-children="1" un-checked-children="0" />
2323
<a-switch v-model:checked="state.checked3">
2424
<template #checkedChildren><check-outlined /></template>
@@ -32,6 +32,6 @@ import { CheckOutlined, CloseOutlined } from '@ant-design/icons-vue';
3232
const state = reactive({
3333
checked1: true,
3434
checked2: false,
35-
checked3: false,
35+
checked3: true,
3636
});
3737
</script>

components/switch/style/index.ts

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,22 +10,22 @@ export interface ComponentToken {
1010
* @desc 开关高度
1111
* @descEN Height of Switch
1212
*/
13-
trackHeight: number;
13+
trackHeight: number | string;
1414
/**
1515
* @desc 小号开关高度
1616
* @descEN Height of small Switch
1717
*/
18-
trackHeightSM: number;
18+
trackHeightSM: number | string;
1919
/**
2020
* @desc 开关最小宽度
2121
* @descEN Minimum width of Switch
2222
*/
23-
trackMinWidth: number;
23+
trackMinWidth: number | string;
2424
/**
2525
* @desc 小号开关最小宽度
2626
* @descEN Minimum width of small Switch
2727
*/
28-
trackMinWidthSM: number;
28+
trackMinWidthSM: number | string;
2929
/**
3030
* @desc 开关内边距
3131
* @descEN Padding of Switch
@@ -108,6 +108,11 @@ const genSwitchSmallStyle: GenerateStyle<SwitchToken, CSSObject> = token => {
108108
[`${componentCls}-inner`]: {
109109
paddingInlineStart: innerMaxMarginSM,
110110
paddingInlineEnd: innerMinMarginSM,
111+
112+
[`${switchInnerCls}-checked, ${switchInnerCls}-unchecked`]: {
113+
minHeight: trackHeightSM,
114+
},
115+
111116
[`${switchInnerCls}-checked`]: {
112117
marginInlineStart: `calc(-100% + ${trackPaddingCalc} - ${innerMaxMarginCalc})`,
113118
marginInlineEnd: `calc(100% - ${trackPaddingCalc} + ${innerMaxMarginCalc})`,
@@ -268,6 +273,7 @@ const genSwitchInnerStyle: GenerateStyle<SwitchToken, CSSObject> = token => {
268273
fontSize: token.fontSizeSM,
269274
transition: `margin-inline-start ${token.switchDuration} ease-in-out, margin-inline-end ${token.switchDuration} ease-in-out`,
270275
pointerEvents: 'none',
276+
minHeight: trackHeight,
271277
},
272278

273279
[`${switchInnerCls}-checked`]: {
@@ -327,7 +333,7 @@ const genSwitchStyle = (token: SwitchToken): CSSObject => {
327333
boxSizing: 'border-box',
328334
minWidth: trackMinWidth,
329335
height: trackHeight,
330-
lineHeight: `${unit(trackHeight)}`,
336+
lineHeight: unit(trackHeight),
331337
verticalAlign: 'middle',
332338
background: token.colorTextQuaternary,
333339
border: '0',
@@ -365,7 +371,7 @@ const genSwitchStyle = (token: SwitchToken): CSSObject => {
365371
direction: 'rtl',
366372
},
367373
},
368-
} as CSSObject;
374+
};
369375
};
370376

371377
// ============================== Export ==============================

0 commit comments

Comments
 (0)