| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175 |
- "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 _internal = require("../../theme/internal");
- var _style = require("../../style");
- // ============================== Mixins ==============================
- function getItemDisabledStyle(cls, token) {
- return {
- [`${cls}, ${cls}:hover, ${cls}:focus`]: {
- color: token.colorTextDisabled,
- cursor: 'not-allowed'
- }
- };
- }
- function getItemSelectedStyle(token) {
- return {
- backgroundColor: token.bgColorSelected,
- boxShadow: token.boxShadow
- };
- }
- const segmentedTextEllipsisCss = (0, _extends2.default)({
- overflow: 'hidden'
- }, _style.textEllipsis);
- // ============================== Styles ==============================
- const genSegmentedStyle = token => {
- const {
- componentCls
- } = token;
- return {
- [componentCls]: (0, _extends2.default)((0, _extends2.default)((0, _extends2.default)((0, _extends2.default)((0, _extends2.default)({}, (0, _style.resetComponent)(token)), {
- display: 'inline-block',
- padding: token.segmentedContainerPadding,
- color: token.labelColor,
- backgroundColor: token.bgColor,
- borderRadius: token.borderRadius,
- transition: `all ${token.motionDurationMid} ${token.motionEaseInOut}`,
- [`${componentCls}-group`]: {
- position: 'relative',
- display: 'flex',
- alignItems: 'stretch',
- justifyItems: 'flex-start',
- width: '100%'
- },
- // RTL styles
- [`&${componentCls}-rtl`]: {
- direction: 'rtl'
- },
- // block styles
- [`&${componentCls}-block`]: {
- display: 'flex'
- },
- [`&${componentCls}-block ${componentCls}-item`]: {
- flex: 1,
- minWidth: 0
- },
- // item styles
- [`${componentCls}-item`]: {
- position: 'relative',
- textAlign: 'center',
- cursor: 'pointer',
- transition: `color ${token.motionDurationMid} ${token.motionEaseInOut}`,
- borderRadius: token.borderRadiusSM,
- '&-selected': (0, _extends2.default)((0, _extends2.default)({}, getItemSelectedStyle(token)), {
- color: token.labelColorHover
- }),
- '&::after': {
- content: '""',
- position: 'absolute',
- width: '100%',
- height: '100%',
- top: 0,
- insetInlineStart: 0,
- borderRadius: 'inherit',
- transition: `background-color ${token.motionDurationMid}`,
- pointerEvents: 'none'
- },
- [`&:hover:not(${componentCls}-item-selected):not(${componentCls}-item-disabled)`]: {
- color: token.labelColorHover,
- '&::after': {
- backgroundColor: token.bgColorHover
- }
- },
- '&-label': (0, _extends2.default)({
- minHeight: token.controlHeight - token.segmentedContainerPadding * 2,
- lineHeight: `${token.controlHeight - token.segmentedContainerPadding * 2}px`,
- padding: `0 ${token.segmentedPaddingHorizontal}px`
- }, segmentedTextEllipsisCss),
- // syntactic sugar to add `icon` for Segmented Item
- '&-icon + *': {
- marginInlineStart: token.marginSM / 2
- },
- '&-input': {
- position: 'absolute',
- insetBlockStart: 0,
- insetInlineStart: 0,
- width: 0,
- height: 0,
- opacity: 0,
- pointerEvents: 'none'
- }
- },
- // thumb styles
- [`${componentCls}-thumb`]: (0, _extends2.default)((0, _extends2.default)({}, getItemSelectedStyle(token)), {
- position: 'absolute',
- insetBlockStart: 0,
- insetInlineStart: 0,
- width: 0,
- height: '100%',
- padding: `${token.paddingXXS}px 0`,
- borderRadius: token.borderRadiusSM,
- [`& ~ ${componentCls}-item:not(${componentCls}-item-selected):not(${componentCls}-item-disabled)::after`]: {
- backgroundColor: 'transparent'
- }
- }),
- // size styles
- [`&${componentCls}-lg`]: {
- borderRadius: token.borderRadiusLG,
- [`${componentCls}-item-label`]: {
- minHeight: token.controlHeightLG - token.segmentedContainerPadding * 2,
- lineHeight: `${token.controlHeightLG - token.segmentedContainerPadding * 2}px`,
- padding: `0 ${token.segmentedPaddingHorizontal}px`,
- fontSize: token.fontSizeLG
- },
- [`${componentCls}-item, ${componentCls}-thumb`]: {
- borderRadius: token.borderRadius
- }
- },
- [`&${componentCls}-sm`]: {
- borderRadius: token.borderRadiusSM,
- [`${componentCls}-item-label`]: {
- minHeight: token.controlHeightSM - token.segmentedContainerPadding * 2,
- lineHeight: `${token.controlHeightSM - token.segmentedContainerPadding * 2}px`,
- padding: `0 ${token.segmentedPaddingHorizontalSM}px`
- },
- [`${componentCls}-item, ${componentCls}-thumb`]: {
- borderRadius: token.borderRadiusXS
- }
- }
- }), getItemDisabledStyle(`&-disabled ${componentCls}-item`, token)), getItemDisabledStyle(`${componentCls}-item-disabled`, token)), {
- // transition effect when `appear-active`
- [`${componentCls}-thumb-motion-appear-active`]: {
- transition: `transform ${token.motionDurationSlow} ${token.motionEaseInOut}, width ${token.motionDurationSlow} ${token.motionEaseInOut}`,
- willChange: 'transform, width'
- }
- })
- };
- };
- // ============================== Export ==============================
- var _default = exports.default = (0, _internal.genComponentStyleHook)('Segmented', token => {
- const {
- lineWidthBold,
- lineWidth,
- colorTextLabel,
- colorText,
- colorFillSecondary,
- colorBgLayout,
- colorBgElevated
- } = token;
- const segmentedToken = (0, _internal.mergeToken)(token, {
- segmentedPaddingHorizontal: token.controlPaddingHorizontal - lineWidth,
- segmentedPaddingHorizontalSM: token.controlPaddingHorizontalSM - lineWidth,
- segmentedContainerPadding: lineWidthBold,
- labelColor: colorTextLabel,
- labelColorHover: colorText,
- bgColor: colorBgLayout,
- bgColorHover: colorFillSecondary,
- bgColorSelected: colorBgElevated
- });
- return [genSegmentedStyle(segmentedToken)];
- });
|