2022-05-09 22:20:07 +08:00
|
|
|
import type { CSSObject } from '@ant-design/cssinjs';
|
2023-11-16 14:18:32 +08:00
|
|
|
import { unit } from '@ant-design/cssinjs';
|
2022-06-02 17:18:52 +08:00
|
|
|
import { TinyColor } from '@ctrl/tinycolor';
|
2024-04-08 14:04:08 +08:00
|
|
|
|
2023-04-23 15:42:36 +08:00
|
|
|
import { genFocusStyle, resetComponent } from '../../style';
|
2023-11-16 14:18:32 +08:00
|
|
|
import type { FullToken, GenerateStyle, GetDefaultToken } from '../../theme/internal';
|
2023-11-29 17:23:45 +08:00
|
|
|
import { genStyleHooks, mergeToken } from '../../theme/internal';
|
2022-04-08 14:36:26 +08:00
|
|
|
|
2023-08-16 19:17:12 +08:00
|
|
|
export interface ComponentToken {
|
|
|
|
/**
|
|
|
|
* @desc 开关高度
|
|
|
|
* @descEN Height of Switch
|
|
|
|
*/
|
|
|
|
trackHeight: number;
|
|
|
|
/**
|
|
|
|
* @desc 小号开关高度
|
|
|
|
* @descEN Height of small Switch
|
|
|
|
*/
|
|
|
|
trackHeightSM: number;
|
|
|
|
/**
|
|
|
|
* @desc 开关最小宽度
|
|
|
|
* @descEN Minimum width of Switch
|
|
|
|
*/
|
|
|
|
trackMinWidth: number;
|
|
|
|
/**
|
|
|
|
* @desc 小号开关最小宽度
|
|
|
|
* @descEN Minimum width of small Switch
|
|
|
|
*/
|
|
|
|
trackMinWidthSM: number;
|
|
|
|
/**
|
|
|
|
* @desc 开关内边距
|
|
|
|
* @descEN Padding of Switch
|
|
|
|
*/
|
|
|
|
trackPadding: number;
|
|
|
|
/**
|
|
|
|
* @desc 开关把手背景色
|
|
|
|
* @descEN Background color of Switch handle
|
|
|
|
*/
|
|
|
|
handleBg: string;
|
|
|
|
/**
|
|
|
|
* @desc 开关把手阴影
|
|
|
|
* @descEN Shadow of Switch handle
|
|
|
|
*/
|
|
|
|
handleShadow: string;
|
|
|
|
/**
|
|
|
|
* @desc 开关把手大小
|
|
|
|
* @descEN Size of Switch handle
|
|
|
|
*/
|
|
|
|
handleSize: number;
|
|
|
|
/**
|
|
|
|
* @desc 小号开关把手大小
|
|
|
|
* @descEN Size of small Switch handle
|
|
|
|
*/
|
|
|
|
handleSizeSM: number;
|
|
|
|
/**
|
|
|
|
* @desc 内容区域最小边距
|
|
|
|
* @descEN Minimum margin of content area
|
|
|
|
*/
|
|
|
|
innerMinMargin: number;
|
|
|
|
/**
|
|
|
|
* @desc 内容区域最大边距
|
|
|
|
* @descEN Maximum margin of content area
|
|
|
|
*/
|
|
|
|
innerMaxMargin: number;
|
|
|
|
/**
|
|
|
|
* @desc 小号开关内容区域最小边距
|
|
|
|
* @descEN Minimum margin of content area of small Switch
|
|
|
|
*/
|
|
|
|
innerMinMarginSM: number;
|
|
|
|
/**
|
|
|
|
* @desc 小号开关内容区域最大边距
|
|
|
|
* @descEN Maximum margin of content area of small Switch
|
|
|
|
*/
|
|
|
|
innerMaxMarginSM: number;
|
|
|
|
}
|
|
|
|
|
2022-04-08 14:36:26 +08:00
|
|
|
interface SwitchToken extends FullToken<'Switch'> {
|
2022-03-16 15:04:47 +08:00
|
|
|
switchDuration: string;
|
|
|
|
switchColor: string;
|
|
|
|
switchDisabledOpacity: number;
|
2023-11-16 14:18:32 +08:00
|
|
|
switchLoadingIconSize: number | string;
|
2022-06-02 17:18:52 +08:00
|
|
|
switchLoadingIconColor: string;
|
|
|
|
switchHandleActiveInset: string;
|
2022-03-16 15:04:47 +08:00
|
|
|
}
|
|
|
|
|
2022-11-17 23:31:41 +08:00
|
|
|
const genSwitchSmallStyle: GenerateStyle<SwitchToken, CSSObject> = (token) => {
|
2023-08-16 19:17:12 +08:00
|
|
|
const {
|
|
|
|
componentCls,
|
|
|
|
trackHeightSM,
|
|
|
|
trackPadding,
|
|
|
|
trackMinWidthSM,
|
|
|
|
innerMinMarginSM,
|
|
|
|
innerMaxMarginSM,
|
|
|
|
handleSizeSM,
|
2023-11-16 14:18:32 +08:00
|
|
|
calc,
|
2023-08-16 19:17:12 +08:00
|
|
|
} = token;
|
2022-09-20 21:51:28 +08:00
|
|
|
const switchInnerCls = `${componentCls}-inner`;
|
2022-03-16 15:04:47 +08:00
|
|
|
|
2023-11-16 14:18:32 +08:00
|
|
|
const trackPaddingCalc = unit(calc(handleSizeSM).add(calc(trackPadding).mul(2)).equal());
|
|
|
|
const innerMaxMarginCalc = unit(calc(innerMaxMarginSM).mul(2).equal());
|
|
|
|
|
2022-09-20 21:51:28 +08:00
|
|
|
return {
|
|
|
|
[componentCls]: {
|
|
|
|
[`&${componentCls}-small`]: {
|
2023-08-16 19:17:12 +08:00
|
|
|
minWidth: trackMinWidthSM,
|
|
|
|
height: trackHeightSM,
|
2023-11-16 14:18:32 +08:00
|
|
|
lineHeight: unit(trackHeightSM),
|
2022-09-20 21:51:28 +08:00
|
|
|
|
|
|
|
[`${componentCls}-inner`]: {
|
2023-08-16 19:17:12 +08:00
|
|
|
paddingInlineStart: innerMaxMarginSM,
|
|
|
|
paddingInlineEnd: innerMinMarginSM,
|
2024-04-17 22:25:46 +08:00
|
|
|
|
|
|
|
[`${switchInnerCls}-checked, ${switchInnerCls}-unchecked`]: {
|
|
|
|
minHeight: trackHeightSM,
|
|
|
|
},
|
|
|
|
|
2022-09-20 21:51:28 +08:00
|
|
|
[`${switchInnerCls}-checked`]: {
|
2023-11-16 14:18:32 +08:00
|
|
|
marginInlineStart: `calc(-100% + ${trackPaddingCalc} - ${innerMaxMarginCalc})`,
|
|
|
|
marginInlineEnd: `calc(100% - ${trackPaddingCalc} + ${innerMaxMarginCalc})`,
|
2022-09-20 21:51:28 +08:00
|
|
|
},
|
|
|
|
|
|
|
|
[`${switchInnerCls}-unchecked`]: {
|
2023-11-16 14:18:32 +08:00
|
|
|
marginTop: calc(trackHeightSM).mul(-1).equal(),
|
2023-01-30 16:31:54 +08:00
|
|
|
marginInlineStart: 0,
|
|
|
|
marginInlineEnd: 0,
|
2022-09-20 21:51:28 +08:00
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
[`${componentCls}-handle`]: {
|
2023-08-16 19:17:12 +08:00
|
|
|
width: handleSizeSM,
|
|
|
|
height: handleSizeSM,
|
2022-09-20 21:51:28 +08:00
|
|
|
},
|
2022-03-16 15:04:47 +08:00
|
|
|
|
2022-09-20 21:51:28 +08:00
|
|
|
[`${componentCls}-loading-icon`]: {
|
2023-11-16 14:18:32 +08:00
|
|
|
top: calc(calc(handleSizeSM).sub(token.switchLoadingIconSize)).div(2).equal(),
|
2022-09-20 21:51:28 +08:00
|
|
|
fontSize: token.switchLoadingIconSize,
|
|
|
|
},
|
|
|
|
|
|
|
|
[`&${componentCls}-checked`]: {
|
|
|
|
[`${componentCls}-inner`]: {
|
2023-08-16 19:17:12 +08:00
|
|
|
paddingInlineStart: innerMinMarginSM,
|
|
|
|
paddingInlineEnd: innerMaxMarginSM,
|
2022-09-20 21:51:28 +08:00
|
|
|
[`${switchInnerCls}-checked`]: {
|
2023-01-30 16:31:54 +08:00
|
|
|
marginInlineStart: 0,
|
|
|
|
marginInlineEnd: 0,
|
2022-09-20 21:51:28 +08:00
|
|
|
},
|
|
|
|
|
|
|
|
[`${switchInnerCls}-unchecked`]: {
|
2023-11-16 14:18:32 +08:00
|
|
|
marginInlineStart: `calc(100% - ${trackPaddingCalc} + ${innerMaxMarginCalc})`,
|
|
|
|
marginInlineEnd: `calc(-100% + ${trackPaddingCalc} - ${innerMaxMarginCalc})`,
|
2022-09-20 21:51:28 +08:00
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
[`${componentCls}-handle`]: {
|
2023-11-16 14:18:32 +08:00
|
|
|
insetInlineStart: `calc(100% - ${unit(calc(handleSizeSM).add(trackPadding).equal())})`,
|
2022-09-20 21:51:28 +08:00
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
[`&:not(${componentCls}-disabled):active`]: {
|
|
|
|
[`&:not(${componentCls}-checked) ${switchInnerCls}`]: {
|
|
|
|
[`${switchInnerCls}-unchecked`]: {
|
2023-11-16 14:18:32 +08:00
|
|
|
marginInlineStart: calc(token.marginXXS).div(2).equal(),
|
|
|
|
marginInlineEnd: calc(token.marginXXS).mul(-1).div(2).equal(),
|
2022-09-20 21:51:28 +08:00
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
[`&${componentCls}-checked ${switchInnerCls}`]: {
|
|
|
|
[`${switchInnerCls}-checked`]: {
|
2023-11-16 14:18:32 +08:00
|
|
|
marginInlineStart: calc(token.marginXXS).mul(-1).div(2).equal(),
|
|
|
|
marginInlineEnd: calc(token.marginXXS).div(2).equal(),
|
2022-09-20 21:51:28 +08:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2022-03-16 15:04:47 +08:00
|
|
|
},
|
2022-09-20 21:51:28 +08:00
|
|
|
};
|
|
|
|
};
|
2022-03-16 15:04:47 +08:00
|
|
|
|
2022-11-17 23:31:41 +08:00
|
|
|
const genSwitchLoadingStyle: GenerateStyle<SwitchToken, CSSObject> = (token) => {
|
2023-11-16 14:18:32 +08:00
|
|
|
const { componentCls, handleSize, calc } = token;
|
2022-09-20 21:51:28 +08:00
|
|
|
|
|
|
|
return {
|
|
|
|
[componentCls]: {
|
|
|
|
[`${componentCls}-loading-icon${token.iconCls}`]: {
|
|
|
|
position: 'relative',
|
2023-11-16 14:18:32 +08:00
|
|
|
top: calc(calc(handleSize).sub(token.fontSize)).div(2).equal(),
|
2022-09-20 21:51:28 +08:00
|
|
|
color: token.switchLoadingIconColor,
|
|
|
|
verticalAlign: 'top',
|
2022-03-16 15:04:47 +08:00
|
|
|
},
|
|
|
|
|
2022-09-20 21:51:28 +08:00
|
|
|
[`&${componentCls}-checked ${componentCls}-loading-icon`]: {
|
|
|
|
color: token.switchColor,
|
2022-03-16 15:04:47 +08:00
|
|
|
},
|
|
|
|
},
|
2022-09-20 21:51:28 +08:00
|
|
|
};
|
|
|
|
};
|
2022-03-16 15:04:47 +08:00
|
|
|
|
2022-11-17 23:31:41 +08:00
|
|
|
const genSwitchHandleStyle: GenerateStyle<SwitchToken, CSSObject> = (token) => {
|
2023-11-16 14:18:32 +08:00
|
|
|
const { componentCls, trackPadding, handleBg, handleShadow, handleSize, calc } = token;
|
2022-09-20 21:51:28 +08:00
|
|
|
const switchHandleCls = `${componentCls}-handle`;
|
2022-03-16 15:04:47 +08:00
|
|
|
|
|
|
|
return {
|
2022-09-20 21:51:28 +08:00
|
|
|
[componentCls]: {
|
|
|
|
[switchHandleCls]: {
|
2022-03-16 15:04:47 +08:00
|
|
|
position: 'absolute',
|
2023-08-16 19:17:12 +08:00
|
|
|
top: trackPadding,
|
|
|
|
insetInlineStart: trackPadding,
|
|
|
|
width: handleSize,
|
|
|
|
height: handleSize,
|
2022-03-16 15:04:47 +08:00
|
|
|
transition: `all ${token.switchDuration} ease-in-out`,
|
|
|
|
|
2022-09-20 21:51:28 +08:00
|
|
|
'&::before': {
|
|
|
|
position: 'absolute',
|
|
|
|
top: 0,
|
|
|
|
insetInlineEnd: 0,
|
|
|
|
bottom: 0,
|
|
|
|
insetInlineStart: 0,
|
2023-08-16 19:17:12 +08:00
|
|
|
backgroundColor: handleBg,
|
2023-11-16 14:18:32 +08:00
|
|
|
borderRadius: calc(handleSize).div(2).equal(),
|
2023-08-16 19:17:12 +08:00
|
|
|
boxShadow: handleShadow,
|
2022-09-20 21:51:28 +08:00
|
|
|
transition: `all ${token.switchDuration} ease-in-out`,
|
|
|
|
content: '""',
|
|
|
|
},
|
|
|
|
},
|
2022-03-16 15:04:47 +08:00
|
|
|
|
2022-09-20 21:51:28 +08:00
|
|
|
[`&${componentCls}-checked ${switchHandleCls}`]: {
|
2023-11-16 14:18:32 +08:00
|
|
|
insetInlineStart: `calc(100% - ${unit(calc(handleSize).add(trackPadding).equal())})`,
|
2022-03-16 15:04:47 +08:00
|
|
|
},
|
|
|
|
|
2023-11-16 14:18:32 +08:00
|
|
|
[`&:not(${componentCls}-disabled):active`]: {
|
|
|
|
[`${switchHandleCls}::before`]: {
|
|
|
|
insetInlineEnd: token.switchHandleActiveInset,
|
|
|
|
insetInlineStart: 0,
|
|
|
|
},
|
2022-09-20 21:51:28 +08:00
|
|
|
|
2023-11-16 14:18:32 +08:00
|
|
|
[`&${componentCls}-checked ${switchHandleCls}::before`]: {
|
|
|
|
insetInlineEnd: 0,
|
|
|
|
insetInlineStart: token.switchHandleActiveInset,
|
|
|
|
},
|
|
|
|
},
|
2022-03-16 15:04:47 +08:00
|
|
|
},
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2022-11-17 23:31:41 +08:00
|
|
|
const genSwitchInnerStyle: GenerateStyle<SwitchToken, CSSObject> = (token) => {
|
2023-11-16 14:18:32 +08:00
|
|
|
const {
|
|
|
|
componentCls,
|
|
|
|
trackHeight,
|
|
|
|
trackPadding,
|
|
|
|
innerMinMargin,
|
|
|
|
innerMaxMargin,
|
|
|
|
handleSize,
|
|
|
|
calc,
|
|
|
|
} = token;
|
2022-09-20 21:51:28 +08:00
|
|
|
const switchInnerCls = `${componentCls}-inner`;
|
2022-03-16 15:04:47 +08:00
|
|
|
|
2023-11-16 14:18:32 +08:00
|
|
|
const trackPaddingCalc = unit(calc(handleSize).add(calc(trackPadding).mul(2)).equal());
|
|
|
|
const innerMaxMarginCalc = unit(calc(innerMaxMargin).mul(2).equal());
|
|
|
|
|
2022-03-16 15:04:47 +08:00
|
|
|
return {
|
2022-09-20 21:51:28 +08:00
|
|
|
[componentCls]: {
|
|
|
|
[switchInnerCls]: {
|
|
|
|
display: 'block',
|
|
|
|
overflow: 'hidden',
|
|
|
|
borderRadius: 100,
|
2022-12-05 15:03:59 +08:00
|
|
|
height: '100%',
|
2023-08-16 19:17:12 +08:00
|
|
|
paddingInlineStart: innerMaxMargin,
|
|
|
|
paddingInlineEnd: innerMinMargin,
|
2023-01-30 16:31:54 +08:00
|
|
|
transition: `padding-inline-start ${token.switchDuration} ease-in-out, padding-inline-end ${token.switchDuration} ease-in-out`,
|
2022-09-20 21:51:28 +08:00
|
|
|
|
|
|
|
[`${switchInnerCls}-checked, ${switchInnerCls}-unchecked`]: {
|
|
|
|
display: 'block',
|
|
|
|
color: token.colorTextLightSolid,
|
|
|
|
fontSize: token.fontSizeSM,
|
|
|
|
transition: `margin-inline-start ${token.switchDuration} ease-in-out, margin-inline-end ${token.switchDuration} ease-in-out`,
|
|
|
|
pointerEvents: 'none',
|
2024-04-17 22:25:46 +08:00
|
|
|
minHeight: trackHeight,
|
2022-09-20 21:51:28 +08:00
|
|
|
},
|
|
|
|
|
|
|
|
[`${switchInnerCls}-checked`]: {
|
2023-11-16 14:18:32 +08:00
|
|
|
marginInlineStart: `calc(-100% + ${trackPaddingCalc} - ${innerMaxMarginCalc})`,
|
|
|
|
marginInlineEnd: `calc(100% - ${trackPaddingCalc} + ${innerMaxMarginCalc})`,
|
2022-09-20 21:51:28 +08:00
|
|
|
},
|
|
|
|
|
|
|
|
[`${switchInnerCls}-unchecked`]: {
|
2023-11-16 14:18:32 +08:00
|
|
|
marginTop: calc(trackHeight).mul(-1).equal(),
|
2023-01-30 16:31:54 +08:00
|
|
|
marginInlineStart: 0,
|
|
|
|
marginInlineEnd: 0,
|
2022-09-20 21:51:28 +08:00
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
[`&${componentCls}-checked ${switchInnerCls}`]: {
|
2023-08-16 19:17:12 +08:00
|
|
|
paddingInlineStart: innerMinMargin,
|
|
|
|
paddingInlineEnd: innerMaxMargin,
|
2022-09-20 21:51:28 +08:00
|
|
|
[`${switchInnerCls}-checked`]: {
|
2023-01-30 16:31:54 +08:00
|
|
|
marginInlineStart: 0,
|
|
|
|
marginInlineEnd: 0,
|
2022-09-20 21:51:28 +08:00
|
|
|
},
|
2022-03-16 15:04:47 +08:00
|
|
|
|
2022-09-20 21:51:28 +08:00
|
|
|
[`${switchInnerCls}-unchecked`]: {
|
2023-11-16 14:18:32 +08:00
|
|
|
marginInlineStart: `calc(100% - ${trackPaddingCalc} + ${innerMaxMarginCalc})`,
|
|
|
|
marginInlineEnd: `calc(-100% + ${trackPaddingCalc} - ${innerMaxMarginCalc})`,
|
2022-09-20 21:51:28 +08:00
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
[`&:not(${componentCls}-disabled):active`]: {
|
|
|
|
[`&:not(${componentCls}-checked) ${switchInnerCls}`]: {
|
|
|
|
[`${switchInnerCls}-unchecked`]: {
|
2023-11-16 14:18:32 +08:00
|
|
|
marginInlineStart: calc(trackPadding).mul(2).equal(),
|
|
|
|
marginInlineEnd: calc(trackPadding).mul(-1).mul(2).equal(),
|
2022-09-20 21:51:28 +08:00
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
[`&${componentCls}-checked ${switchInnerCls}`]: {
|
|
|
|
[`${switchInnerCls}-checked`]: {
|
2023-11-16 14:18:32 +08:00
|
|
|
marginInlineStart: calc(trackPadding).mul(-1).mul(2).equal(),
|
|
|
|
marginInlineEnd: calc(trackPadding).mul(2).equal(),
|
2022-09-20 21:51:28 +08:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2022-03-16 15:04:47 +08:00
|
|
|
},
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
const genSwitchStyle = (token: SwitchToken): CSSObject => {
|
2023-08-16 19:17:12 +08:00
|
|
|
const { componentCls, trackHeight, trackMinWidth } = token;
|
2022-03-16 15:04:47 +08:00
|
|
|
|
|
|
|
return {
|
2022-04-08 14:36:26 +08:00
|
|
|
[componentCls]: {
|
2022-03-16 15:04:47 +08:00
|
|
|
...resetComponent(token),
|
|
|
|
|
|
|
|
position: 'relative',
|
|
|
|
display: 'inline-block',
|
|
|
|
boxSizing: 'border-box',
|
2023-08-16 19:17:12 +08:00
|
|
|
minWidth: trackMinWidth,
|
|
|
|
height: trackHeight,
|
2023-11-16 14:18:32 +08:00
|
|
|
lineHeight: `${unit(trackHeight)}`,
|
2022-03-16 15:04:47 +08:00
|
|
|
verticalAlign: 'middle',
|
2022-09-07 12:00:00 +08:00
|
|
|
background: token.colorTextQuaternary,
|
2022-03-16 15:04:47 +08:00
|
|
|
border: '0',
|
|
|
|
borderRadius: 100,
|
|
|
|
cursor: 'pointer',
|
2022-11-17 23:31:41 +08:00
|
|
|
transition: `all ${token.motionDurationMid}`,
|
2022-03-16 15:04:47 +08:00
|
|
|
userSelect: 'none',
|
|
|
|
|
2022-09-20 21:50:36 +08:00
|
|
|
[`&:hover:not(${componentCls}-disabled)`]: {
|
2022-09-07 12:00:00 +08:00
|
|
|
background: token.colorTextTertiary,
|
|
|
|
},
|
|
|
|
|
2022-09-09 10:53:03 +08:00
|
|
|
...genFocusStyle(token),
|
2022-03-16 15:04:47 +08:00
|
|
|
|
2022-09-20 21:51:28 +08:00
|
|
|
[`&${componentCls}-checked`]: {
|
2022-04-20 11:30:55 +08:00
|
|
|
background: token.switchColor,
|
2022-09-07 12:00:00 +08:00
|
|
|
|
2022-09-20 21:50:36 +08:00
|
|
|
[`&:hover:not(${componentCls}-disabled)`]: {
|
2022-09-07 12:00:00 +08:00
|
|
|
background: token.colorPrimaryHover,
|
|
|
|
},
|
2022-03-16 15:04:47 +08:00
|
|
|
},
|
|
|
|
|
2022-09-20 21:51:28 +08:00
|
|
|
[`&${componentCls}-loading, &${componentCls}-disabled`]: {
|
2022-03-16 15:04:47 +08:00
|
|
|
cursor: 'not-allowed',
|
|
|
|
opacity: token.switchDisabledOpacity,
|
|
|
|
|
|
|
|
'*': {
|
|
|
|
boxShadow: 'none',
|
|
|
|
cursor: 'not-allowed',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
// rtl style
|
2022-09-20 21:51:28 +08:00
|
|
|
[`&${componentCls}-rtl`]: {
|
2022-03-16 15:04:47 +08:00
|
|
|
direction: 'rtl',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
// ============================== Export ==============================
|
2023-11-16 14:18:32 +08:00
|
|
|
export const prepareComponentToken: GetDefaultToken<'Switch'> = (token) => {
|
|
|
|
const { fontSize, lineHeight, controlHeight, colorWhite } = token;
|
|
|
|
|
|
|
|
const height = fontSize * lineHeight;
|
|
|
|
const heightSM = controlHeight / 2;
|
|
|
|
const padding = 2; // Fixed value
|
|
|
|
const handleSize = height - padding * 2;
|
|
|
|
const handleSizeSM = heightSM - padding * 2;
|
|
|
|
|
|
|
|
return {
|
|
|
|
trackHeight: height,
|
|
|
|
trackHeightSM: heightSM,
|
|
|
|
trackMinWidth: handleSize * 2 + padding * 4,
|
|
|
|
trackMinWidthSM: handleSizeSM * 2 + padding * 2,
|
|
|
|
trackPadding: padding, // Fixed value
|
|
|
|
handleBg: colorWhite,
|
|
|
|
handleSize,
|
|
|
|
handleSizeSM,
|
|
|
|
handleShadow: `0 2px 4px 0 ${new TinyColor('#00230b').setAlpha(0.2).toRgbString()}`,
|
|
|
|
innerMinMargin: handleSize / 2,
|
|
|
|
innerMaxMargin: handleSize + padding + padding * 2,
|
|
|
|
innerMinMarginSM: handleSizeSM / 2,
|
|
|
|
innerMaxMarginSM: handleSizeSM + padding + padding * 2,
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2023-11-29 17:23:45 +08:00
|
|
|
export default genStyleHooks(
|
2023-08-16 19:17:12 +08:00
|
|
|
'Switch',
|
|
|
|
(token) => {
|
|
|
|
const switchToken = mergeToken<SwitchToken>(token, {
|
|
|
|
switchDuration: token.motionDurationMid,
|
|
|
|
switchColor: token.colorPrimary,
|
|
|
|
switchDisabledOpacity: token.opacityLoading,
|
2023-11-16 14:18:32 +08:00
|
|
|
switchLoadingIconSize: token.calc(token.fontSizeIcon).mul(0.75).equal(),
|
2023-08-16 19:17:12 +08:00
|
|
|
switchLoadingIconColor: `rgba(0, 0, 0, ${token.opacityLoading})`,
|
|
|
|
switchHandleActiveInset: '-30%',
|
|
|
|
});
|
|
|
|
|
|
|
|
return [
|
|
|
|
genSwitchStyle(switchToken),
|
|
|
|
|
|
|
|
// inner style
|
|
|
|
genSwitchInnerStyle(switchToken),
|
|
|
|
|
|
|
|
// handle style
|
|
|
|
genSwitchHandleStyle(switchToken),
|
|
|
|
|
|
|
|
// loading style
|
|
|
|
genSwitchLoadingStyle(switchToken),
|
|
|
|
|
|
|
|
// small style
|
|
|
|
genSwitchSmallStyle(switchToken),
|
|
|
|
];
|
|
|
|
},
|
2023-11-16 14:18:32 +08:00
|
|
|
prepareComponentToken,
|
2023-08-16 19:17:12 +08:00
|
|
|
);
|