Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat[cssvar]: switch support cssvar #7940

Open
wants to merge 1 commit into
base: feat-4.3
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion components/switch/demo/basic.vue
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ The most basic usage.
<template>
<a-switch v-model:checked="checked" />
</template>

<script lang="ts" setup>
import { ref } from 'vue';
const checked = ref<boolean>(false);
const checked = ref<boolean>(true);
</script>
2 changes: 1 addition & 1 deletion components/switch/demo/size.vue
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@ title:
import { reactive } from 'vue';
const state = reactive({
checked1: true,
checked2: false,
checked2: true,
});
</script>
4 changes: 2 additions & 2 deletions components/switch/demo/text.vue
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ With text and icon.

<template>
<a-space direction="vertical">
<a-switch v-model:checked="state.checked1" checked-children="" un-checked-children="" />
<a-switch v-model:checked="state.checked1" checked-children="开启" un-checked-children="关闭" />
<a-switch v-model:checked="state.checked2" checked-children="1" un-checked-children="0" />
<a-switch v-model:checked="state.checked3">
<template #checkedChildren><check-outlined /></template>
Expand All @@ -32,6 +32,6 @@ import { CheckOutlined, CloseOutlined } from '@ant-design/icons-vue';
const state = reactive({
checked1: true,
checked2: false,
checked3: false,
checked3: true,
});
</script>
18 changes: 12 additions & 6 deletions components/switch/style/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,22 @@ export interface ComponentToken {
* @desc 开关高度
* @descEN Height of Switch
*/
trackHeight: number;
trackHeight: number | string;
/**
* @desc 小号开关高度
* @descEN Height of small Switch
*/
trackHeightSM: number;
trackHeightSM: number | string;
/**
* @desc 开关最小宽度
* @descEN Minimum width of Switch
*/
trackMinWidth: number;
trackMinWidth: number | string;
/**
* @desc 小号开关最小宽度
* @descEN Minimum width of small Switch
*/
trackMinWidthSM: number;
trackMinWidthSM: number | string;
/**
* @desc 开关内边距
* @descEN Padding of Switch
Expand Down Expand Up @@ -108,6 +108,11 @@ const genSwitchSmallStyle: GenerateStyle<SwitchToken, CSSObject> = token => {
[`${componentCls}-inner`]: {
paddingInlineStart: innerMaxMarginSM,
paddingInlineEnd: innerMinMarginSM,

[`${switchInnerCls}-checked, ${switchInnerCls}-unchecked`]: {
minHeight: trackHeightSM,
},

[`${switchInnerCls}-checked`]: {
marginInlineStart: `calc(-100% + ${trackPaddingCalc} - ${innerMaxMarginCalc})`,
marginInlineEnd: `calc(100% - ${trackPaddingCalc} + ${innerMaxMarginCalc})`,
Expand Down Expand Up @@ -268,6 +273,7 @@ const genSwitchInnerStyle: GenerateStyle<SwitchToken, CSSObject> = token => {
fontSize: token.fontSizeSM,
transition: `margin-inline-start ${token.switchDuration} ease-in-out, margin-inline-end ${token.switchDuration} ease-in-out`,
pointerEvents: 'none',
minHeight: trackHeight,
},

[`${switchInnerCls}-checked`]: {
Expand Down Expand Up @@ -327,7 +333,7 @@ const genSwitchStyle = (token: SwitchToken): CSSObject => {
boxSizing: 'border-box',
minWidth: trackMinWidth,
height: trackHeight,
lineHeight: `${unit(trackHeight)}`,
lineHeight: unit(trackHeight),
verticalAlign: 'middle',
background: token.colorTextQuaternary,
border: '0',
Expand Down Expand Up @@ -365,7 +371,7 @@ const genSwitchStyle = (token: SwitchToken): CSSObject => {
direction: 'rtl',
},
},
} as CSSObject;
};
};

// ============================== Export ==============================
Expand Down
Loading