| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282 |
- "use strict";
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
- Object.defineProperty(exports, "__esModule", {
- value: true
- });
- exports.default = void 0;
- var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
- var _tinycolor = require("@ctrl/tinycolor");
- var _internal = require("../../theme/internal");
- var _style = require("../../style");
- const genSwitchSmallStyle = token => {
- const {
- componentCls
- } = token;
- const switchInnerCls = `${componentCls}-inner`;
- return {
- [componentCls]: {
- [`&${componentCls}-small`]: {
- minWidth: token.switchMinWidthSM,
- height: token.switchHeightSM,
- lineHeight: `${token.switchHeightSM}px`,
- [`${componentCls}-inner`]: {
- paddingInlineStart: token.switchInnerMarginMaxSM,
- paddingInlineEnd: token.switchInnerMarginMinSM,
- [`${switchInnerCls}-checked`]: {
- marginInlineStart: `calc(-100% + ${token.switchPinSizeSM + token.switchPadding * 2}px - ${token.switchInnerMarginMaxSM * 2}px)`,
- marginInlineEnd: `calc(100% - ${token.switchPinSizeSM + token.switchPadding * 2}px + ${token.switchInnerMarginMaxSM * 2}px)`
- },
- [`${switchInnerCls}-unchecked`]: {
- marginTop: -token.switchHeightSM,
- marginInlineStart: 0,
- marginInlineEnd: 0
- }
- },
- [`${componentCls}-handle`]: {
- width: token.switchPinSizeSM,
- height: token.switchPinSizeSM
- },
- [`${componentCls}-loading-icon`]: {
- top: (token.switchPinSizeSM - token.switchLoadingIconSize) / 2,
- fontSize: token.switchLoadingIconSize
- },
- [`&${componentCls}-checked`]: {
- [`${componentCls}-inner`]: {
- paddingInlineStart: token.switchInnerMarginMinSM,
- paddingInlineEnd: token.switchInnerMarginMaxSM,
- [`${switchInnerCls}-checked`]: {
- marginInlineStart: 0,
- marginInlineEnd: 0
- },
- [`${switchInnerCls}-unchecked`]: {
- marginInlineStart: `calc(100% - ${token.switchPinSizeSM + token.switchPadding * 2}px + ${token.switchInnerMarginMaxSM * 2}px)`,
- marginInlineEnd: `calc(-100% + ${token.switchPinSizeSM + token.switchPadding * 2}px - ${token.switchInnerMarginMaxSM * 2}px)`
- }
- },
- [`${componentCls}-handle`]: {
- insetInlineStart: `calc(100% - ${token.switchPinSizeSM + token.switchPadding}px)`
- }
- },
- [`&:not(${componentCls}-disabled):active`]: {
- [`&:not(${componentCls}-checked) ${switchInnerCls}`]: {
- [`${switchInnerCls}-unchecked`]: {
- marginInlineStart: token.marginXXS / 2,
- marginInlineEnd: -token.marginXXS / 2
- }
- },
- [`&${componentCls}-checked ${switchInnerCls}`]: {
- [`${switchInnerCls}-checked`]: {
- marginInlineStart: -token.marginXXS / 2,
- marginInlineEnd: token.marginXXS / 2
- }
- }
- }
- }
- }
- };
- };
- const genSwitchLoadingStyle = token => {
- const {
- componentCls
- } = token;
- return {
- [componentCls]: {
- [`${componentCls}-loading-icon${token.iconCls}`]: {
- position: 'relative',
- top: (token.switchPinSize - token.fontSize) / 2,
- color: token.switchLoadingIconColor,
- verticalAlign: 'top'
- },
- [`&${componentCls}-checked ${componentCls}-loading-icon`]: {
- color: token.switchColor
- }
- }
- };
- };
- const genSwitchHandleStyle = token => {
- const {
- componentCls
- } = token;
- const switchHandleCls = `${componentCls}-handle`;
- return {
- [componentCls]: {
- [switchHandleCls]: {
- position: 'absolute',
- top: token.switchPadding,
- insetInlineStart: token.switchPadding,
- width: token.switchPinSize,
- height: token.switchPinSize,
- transition: `all ${token.switchDuration} ease-in-out`,
- '&::before': {
- position: 'absolute',
- top: 0,
- insetInlineEnd: 0,
- bottom: 0,
- insetInlineStart: 0,
- backgroundColor: token.colorWhite,
- borderRadius: token.switchPinSize / 2,
- boxShadow: token.switchHandleShadow,
- transition: `all ${token.switchDuration} ease-in-out`,
- content: '""'
- }
- },
- [`&${componentCls}-checked ${switchHandleCls}`]: {
- insetInlineStart: `calc(100% - ${token.switchPinSize + token.switchPadding}px)`
- },
- [`&:not(${componentCls}-disabled):active`]: {
- [`${switchHandleCls}::before`]: {
- insetInlineEnd: token.switchHandleActiveInset,
- insetInlineStart: 0
- },
- [`&${componentCls}-checked ${switchHandleCls}::before`]: {
- insetInlineEnd: 0,
- insetInlineStart: token.switchHandleActiveInset
- }
- }
- }
- };
- };
- const genSwitchInnerStyle = token => {
- const {
- componentCls
- } = token;
- const switchInnerCls = `${componentCls}-inner`;
- return {
- [componentCls]: {
- [switchInnerCls]: {
- display: 'block',
- overflow: 'hidden',
- borderRadius: 100,
- height: '100%',
- paddingInlineStart: token.switchInnerMarginMax,
- paddingInlineEnd: token.switchInnerMarginMin,
- transition: `padding-inline-start ${token.switchDuration} ease-in-out, padding-inline-end ${token.switchDuration} ease-in-out`,
- [`${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'
- },
- [`${switchInnerCls}-checked`]: {
- marginInlineStart: `calc(-100% + ${token.switchPinSize + token.switchPadding * 2}px - ${token.switchInnerMarginMax * 2}px)`,
- marginInlineEnd: `calc(100% - ${token.switchPinSize + token.switchPadding * 2}px + ${token.switchInnerMarginMax * 2}px)`
- },
- [`${switchInnerCls}-unchecked`]: {
- marginTop: -token.switchHeight,
- marginInlineStart: 0,
- marginInlineEnd: 0
- }
- },
- [`&${componentCls}-checked ${switchInnerCls}`]: {
- paddingInlineStart: token.switchInnerMarginMin,
- paddingInlineEnd: token.switchInnerMarginMax,
- [`${switchInnerCls}-checked`]: {
- marginInlineStart: 0,
- marginInlineEnd: 0
- },
- [`${switchInnerCls}-unchecked`]: {
- marginInlineStart: `calc(100% - ${token.switchPinSize + token.switchPadding * 2}px + ${token.switchInnerMarginMax * 2}px)`,
- marginInlineEnd: `calc(-100% + ${token.switchPinSize + token.switchPadding * 2}px - ${token.switchInnerMarginMax * 2}px)`
- }
- },
- [`&:not(${componentCls}-disabled):active`]: {
- [`&:not(${componentCls}-checked) ${switchInnerCls}`]: {
- [`${switchInnerCls}-unchecked`]: {
- marginInlineStart: token.switchPadding * 2,
- marginInlineEnd: -token.switchPadding * 2
- }
- },
- [`&${componentCls}-checked ${switchInnerCls}`]: {
- [`${switchInnerCls}-checked`]: {
- marginInlineStart: -token.switchPadding * 2,
- marginInlineEnd: token.switchPadding * 2
- }
- }
- }
- }
- };
- };
- const genSwitchStyle = token => {
- const {
- componentCls
- } = token;
- return {
- [componentCls]: (0, _extends2.default)((0, _extends2.default)((0, _extends2.default)((0, _extends2.default)({}, (0, _style.resetComponent)(token)), {
- position: 'relative',
- display: 'inline-block',
- boxSizing: 'border-box',
- minWidth: token.switchMinWidth,
- height: token.switchHeight,
- lineHeight: `${token.switchHeight}px`,
- verticalAlign: 'middle',
- background: token.colorTextQuaternary,
- border: '0',
- borderRadius: 100,
- cursor: 'pointer',
- transition: `all ${token.motionDurationMid}`,
- userSelect: 'none',
- [`&:hover:not(${componentCls}-disabled)`]: {
- background: token.colorTextTertiary
- }
- }), (0, _style.genFocusStyle)(token)), {
- [`&${componentCls}-checked`]: {
- background: token.switchColor,
- [`&:hover:not(${componentCls}-disabled)`]: {
- background: token.colorPrimaryHover
- }
- },
- [`&${componentCls}-loading, &${componentCls}-disabled`]: {
- cursor: 'not-allowed',
- opacity: token.switchDisabledOpacity,
- '*': {
- boxShadow: 'none',
- cursor: 'not-allowed'
- }
- },
- // rtl style
- [`&${componentCls}-rtl`]: {
- direction: 'rtl'
- }
- })
- };
- };
- // ============================== Export ==============================
- var _default = exports.default = (0, _internal.genComponentStyleHook)('Switch', token => {
- const switchHeight = token.fontSize * token.lineHeight;
- const switchHeightSM = token.controlHeight / 2;
- const switchPadding = 2; // This is magic
- const switchPinSize = switchHeight - switchPadding * 2;
- const switchPinSizeSM = switchHeightSM - switchPadding * 2;
- const switchToken = (0, _internal.mergeToken)(token, {
- switchMinWidth: switchPinSize * 2 + switchPadding * 4,
- switchHeight,
- switchDuration: token.motionDurationMid,
- switchColor: token.colorPrimary,
- switchDisabledOpacity: token.opacityLoading,
- switchInnerMarginMin: switchPinSize / 2,
- switchInnerMarginMax: switchPinSize + switchPadding + switchPadding * 2,
- switchPadding,
- switchPinSize,
- switchBg: token.colorBgContainer,
- switchMinWidthSM: switchPinSizeSM * 2 + switchPadding * 2,
- switchHeightSM,
- switchInnerMarginMinSM: switchPinSizeSM / 2,
- switchInnerMarginMaxSM: switchPinSizeSM + switchPadding + switchPadding * 2,
- switchPinSizeSM,
- switchHandleShadow: `0 2px 4px 0 ${new _tinycolor.TinyColor('#00230b').setAlpha(0.2).toRgbString()}`,
- switchLoadingIconSize: token.fontSizeIcon * 0.75,
- 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)];
- });
|