index.js 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. "use strict";
  2. var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
  3. Object.defineProperty(exports, "__esModule", {
  4. value: true
  5. });
  6. exports.default = void 0;
  7. var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
  8. var _internal = require("../../theme/internal");
  9. var _style = require("../../style");
  10. // ============================== Mixins ==============================
  11. function getItemDisabledStyle(cls, token) {
  12. return {
  13. [`${cls}, ${cls}:hover, ${cls}:focus`]: {
  14. color: token.colorTextDisabled,
  15. cursor: 'not-allowed'
  16. }
  17. };
  18. }
  19. function getItemSelectedStyle(token) {
  20. return {
  21. backgroundColor: token.bgColorSelected,
  22. boxShadow: token.boxShadow
  23. };
  24. }
  25. const segmentedTextEllipsisCss = (0, _extends2.default)({
  26. overflow: 'hidden'
  27. }, _style.textEllipsis);
  28. // ============================== Styles ==============================
  29. const genSegmentedStyle = token => {
  30. const {
  31. componentCls
  32. } = token;
  33. return {
  34. [componentCls]: (0, _extends2.default)((0, _extends2.default)((0, _extends2.default)((0, _extends2.default)((0, _extends2.default)({}, (0, _style.resetComponent)(token)), {
  35. display: 'inline-block',
  36. padding: token.segmentedContainerPadding,
  37. color: token.labelColor,
  38. backgroundColor: token.bgColor,
  39. borderRadius: token.borderRadius,
  40. transition: `all ${token.motionDurationMid} ${token.motionEaseInOut}`,
  41. [`${componentCls}-group`]: {
  42. position: 'relative',
  43. display: 'flex',
  44. alignItems: 'stretch',
  45. justifyItems: 'flex-start',
  46. width: '100%'
  47. },
  48. // RTL styles
  49. [`&${componentCls}-rtl`]: {
  50. direction: 'rtl'
  51. },
  52. // block styles
  53. [`&${componentCls}-block`]: {
  54. display: 'flex'
  55. },
  56. [`&${componentCls}-block ${componentCls}-item`]: {
  57. flex: 1,
  58. minWidth: 0
  59. },
  60. // item styles
  61. [`${componentCls}-item`]: {
  62. position: 'relative',
  63. textAlign: 'center',
  64. cursor: 'pointer',
  65. transition: `color ${token.motionDurationMid} ${token.motionEaseInOut}`,
  66. borderRadius: token.borderRadiusSM,
  67. '&-selected': (0, _extends2.default)((0, _extends2.default)({}, getItemSelectedStyle(token)), {
  68. color: token.labelColorHover
  69. }),
  70. '&::after': {
  71. content: '""',
  72. position: 'absolute',
  73. width: '100%',
  74. height: '100%',
  75. top: 0,
  76. insetInlineStart: 0,
  77. borderRadius: 'inherit',
  78. transition: `background-color ${token.motionDurationMid}`,
  79. pointerEvents: 'none'
  80. },
  81. [`&:hover:not(${componentCls}-item-selected):not(${componentCls}-item-disabled)`]: {
  82. color: token.labelColorHover,
  83. '&::after': {
  84. backgroundColor: token.bgColorHover
  85. }
  86. },
  87. '&-label': (0, _extends2.default)({
  88. minHeight: token.controlHeight - token.segmentedContainerPadding * 2,
  89. lineHeight: `${token.controlHeight - token.segmentedContainerPadding * 2}px`,
  90. padding: `0 ${token.segmentedPaddingHorizontal}px`
  91. }, segmentedTextEllipsisCss),
  92. // syntactic sugar to add `icon` for Segmented Item
  93. '&-icon + *': {
  94. marginInlineStart: token.marginSM / 2
  95. },
  96. '&-input': {
  97. position: 'absolute',
  98. insetBlockStart: 0,
  99. insetInlineStart: 0,
  100. width: 0,
  101. height: 0,
  102. opacity: 0,
  103. pointerEvents: 'none'
  104. }
  105. },
  106. // thumb styles
  107. [`${componentCls}-thumb`]: (0, _extends2.default)((0, _extends2.default)({}, getItemSelectedStyle(token)), {
  108. position: 'absolute',
  109. insetBlockStart: 0,
  110. insetInlineStart: 0,
  111. width: 0,
  112. height: '100%',
  113. padding: `${token.paddingXXS}px 0`,
  114. borderRadius: token.borderRadiusSM,
  115. [`& ~ ${componentCls}-item:not(${componentCls}-item-selected):not(${componentCls}-item-disabled)::after`]: {
  116. backgroundColor: 'transparent'
  117. }
  118. }),
  119. // size styles
  120. [`&${componentCls}-lg`]: {
  121. borderRadius: token.borderRadiusLG,
  122. [`${componentCls}-item-label`]: {
  123. minHeight: token.controlHeightLG - token.segmentedContainerPadding * 2,
  124. lineHeight: `${token.controlHeightLG - token.segmentedContainerPadding * 2}px`,
  125. padding: `0 ${token.segmentedPaddingHorizontal}px`,
  126. fontSize: token.fontSizeLG
  127. },
  128. [`${componentCls}-item, ${componentCls}-thumb`]: {
  129. borderRadius: token.borderRadius
  130. }
  131. },
  132. [`&${componentCls}-sm`]: {
  133. borderRadius: token.borderRadiusSM,
  134. [`${componentCls}-item-label`]: {
  135. minHeight: token.controlHeightSM - token.segmentedContainerPadding * 2,
  136. lineHeight: `${token.controlHeightSM - token.segmentedContainerPadding * 2}px`,
  137. padding: `0 ${token.segmentedPaddingHorizontalSM}px`
  138. },
  139. [`${componentCls}-item, ${componentCls}-thumb`]: {
  140. borderRadius: token.borderRadiusXS
  141. }
  142. }
  143. }), getItemDisabledStyle(`&-disabled ${componentCls}-item`, token)), getItemDisabledStyle(`${componentCls}-item-disabled`, token)), {
  144. // transition effect when `appear-active`
  145. [`${componentCls}-thumb-motion-appear-active`]: {
  146. transition: `transform ${token.motionDurationSlow} ${token.motionEaseInOut}, width ${token.motionDurationSlow} ${token.motionEaseInOut}`,
  147. willChange: 'transform, width'
  148. }
  149. })
  150. };
  151. };
  152. // ============================== Export ==============================
  153. var _default = exports.default = (0, _internal.genComponentStyleHook)('Segmented', token => {
  154. const {
  155. lineWidthBold,
  156. lineWidth,
  157. colorTextLabel,
  158. colorText,
  159. colorFillSecondary,
  160. colorBgLayout,
  161. colorBgElevated
  162. } = token;
  163. const segmentedToken = (0, _internal.mergeToken)(token, {
  164. segmentedPaddingHorizontal: token.controlPaddingHorizontal - lineWidth,
  165. segmentedPaddingHorizontalSM: token.controlPaddingHorizontalSM - lineWidth,
  166. segmentedContainerPadding: lineWidthBold,
  167. labelColor: colorTextLabel,
  168. labelColorHover: colorText,
  169. bgColor: colorBgLayout,
  170. bgColorHover: colorFillSecondary,
  171. bgColorSelected: colorBgElevated
  172. });
  173. return [genSegmentedStyle(segmentedToken)];
  174. });