index.js 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.prepareComponentToken = exports.default = void 0;
  6. var _cssinjs = require("@ant-design/cssinjs");
  7. var _style = require("../../style");
  8. var _internal = require("../../theme/internal");
  9. // ============================== Mixins ==============================
  10. function getItemDisabledStyle(cls, token) {
  11. return {
  12. [`${cls}, ${cls}:hover, ${cls}:focus`]: {
  13. color: token.colorTextDisabled,
  14. cursor: 'not-allowed'
  15. }
  16. };
  17. }
  18. function getItemSelectedStyle(token) {
  19. return {
  20. backgroundColor: token.itemSelectedBg,
  21. boxShadow: token.boxShadowTertiary
  22. };
  23. }
  24. const segmentedTextEllipsisCss = Object.assign({
  25. overflow: 'hidden'
  26. }, _style.textEllipsis);
  27. // ============================== Styles ==============================
  28. const genSegmentedStyle = token => {
  29. const {
  30. componentCls
  31. } = token;
  32. const labelHeight = token.calc(token.controlHeight).sub(token.calc(token.trackPadding).mul(2)).equal();
  33. const labelHeightLG = token.calc(token.controlHeightLG).sub(token.calc(token.trackPadding).mul(2)).equal();
  34. const labelHeightSM = token.calc(token.controlHeightSM).sub(token.calc(token.trackPadding).mul(2)).equal();
  35. return {
  36. [componentCls]: Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, (0, _style.resetComponent)(token)), {
  37. display: 'inline-block',
  38. padding: token.trackPadding,
  39. color: token.itemColor,
  40. background: token.trackBg,
  41. borderRadius: token.borderRadius,
  42. transition: `all ${token.motionDurationMid} ${token.motionEaseInOut}`
  43. }), (0, _style.genFocusStyle)(token)), {
  44. [`${componentCls}-group`]: {
  45. position: 'relative',
  46. display: 'flex',
  47. alignItems: 'stretch',
  48. justifyItems: 'flex-start',
  49. flexDirection: 'row',
  50. width: '100%'
  51. },
  52. // RTL styles
  53. [`&${componentCls}-rtl`]: {
  54. direction: 'rtl'
  55. },
  56. [`&${componentCls}-vertical`]: {
  57. [`${componentCls}-group`]: {
  58. flexDirection: 'column'
  59. },
  60. [`${componentCls}-thumb`]: {
  61. width: '100%',
  62. height: 0,
  63. padding: `0 ${(0, _cssinjs.unit)(token.paddingXXS)}`
  64. }
  65. },
  66. // block styles
  67. [`&${componentCls}-block`]: {
  68. display: 'flex'
  69. },
  70. [`&${componentCls}-block ${componentCls}-item`]: {
  71. flex: 1,
  72. minWidth: 0
  73. },
  74. // item styles
  75. [`${componentCls}-item`]: {
  76. position: 'relative',
  77. textAlign: 'center',
  78. cursor: 'pointer',
  79. transition: `color ${token.motionDurationMid} ${token.motionEaseInOut}`,
  80. borderRadius: token.borderRadiusSM,
  81. // Fix Safari render bug
  82. // https://github.com/ant-design/ant-design/issues/45250
  83. transform: 'translateZ(0)',
  84. '&-selected': Object.assign(Object.assign({}, getItemSelectedStyle(token)), {
  85. color: token.itemSelectedColor
  86. }),
  87. '&-focused': (0, _style.genFocusOutline)(token),
  88. '&::after': {
  89. content: '""',
  90. position: 'absolute',
  91. zIndex: -1,
  92. width: '100%',
  93. height: '100%',
  94. top: 0,
  95. insetInlineStart: 0,
  96. borderRadius: 'inherit',
  97. opacity: 0,
  98. transition: `opacity ${token.motionDurationMid}`,
  99. // This is mandatory to make it not clickable or hoverable
  100. // Ref: https://github.com/ant-design/ant-design/issues/40888
  101. pointerEvents: 'none'
  102. },
  103. [`&:hover:not(${componentCls}-item-selected):not(${componentCls}-item-disabled)`]: {
  104. color: token.itemHoverColor,
  105. '&::after': {
  106. opacity: 1,
  107. backgroundColor: token.itemHoverBg
  108. }
  109. },
  110. [`&:active:not(${componentCls}-item-selected):not(${componentCls}-item-disabled)`]: {
  111. color: token.itemHoverColor,
  112. '&::after': {
  113. opacity: 1,
  114. backgroundColor: token.itemActiveBg
  115. }
  116. },
  117. '&-label': Object.assign({
  118. minHeight: labelHeight,
  119. lineHeight: (0, _cssinjs.unit)(labelHeight),
  120. padding: `0 ${(0, _cssinjs.unit)(token.segmentedPaddingHorizontal)}`
  121. }, segmentedTextEllipsisCss),
  122. // syntactic sugar to add `icon` for Segmented Item
  123. '&-icon + *': {
  124. marginInlineStart: token.calc(token.marginSM).div(2).equal()
  125. },
  126. '&-input': {
  127. position: 'absolute',
  128. insetBlockStart: 0,
  129. insetInlineStart: 0,
  130. width: 0,
  131. height: 0,
  132. opacity: 0,
  133. pointerEvents: 'none'
  134. }
  135. },
  136. // thumb styles
  137. [`${componentCls}-thumb`]: Object.assign(Object.assign({}, getItemSelectedStyle(token)), {
  138. position: 'absolute',
  139. insetBlockStart: 0,
  140. insetInlineStart: 0,
  141. width: 0,
  142. height: '100%',
  143. padding: `${(0, _cssinjs.unit)(token.paddingXXS)} 0`,
  144. borderRadius: token.borderRadiusSM,
  145. transition: `transform ${token.motionDurationSlow} ${token.motionEaseInOut}, height ${token.motionDurationSlow} ${token.motionEaseInOut}`,
  146. [`& ~ ${componentCls}-item:not(${componentCls}-item-selected):not(${componentCls}-item-disabled)::after`]: {
  147. backgroundColor: 'transparent'
  148. }
  149. }),
  150. // size styles
  151. [`&${componentCls}-lg`]: {
  152. borderRadius: token.borderRadiusLG,
  153. [`${componentCls}-item-label`]: {
  154. minHeight: labelHeightLG,
  155. lineHeight: (0, _cssinjs.unit)(labelHeightLG),
  156. padding: `0 ${(0, _cssinjs.unit)(token.segmentedPaddingHorizontal)}`,
  157. fontSize: token.fontSizeLG
  158. },
  159. [`${componentCls}-item, ${componentCls}-thumb`]: {
  160. borderRadius: token.borderRadius
  161. }
  162. },
  163. [`&${componentCls}-sm`]: {
  164. borderRadius: token.borderRadiusSM,
  165. [`${componentCls}-item-label`]: {
  166. minHeight: labelHeightSM,
  167. lineHeight: (0, _cssinjs.unit)(labelHeightSM),
  168. padding: `0 ${(0, _cssinjs.unit)(token.segmentedPaddingHorizontalSM)}`
  169. },
  170. [`${componentCls}-item, ${componentCls}-thumb`]: {
  171. borderRadius: token.borderRadiusXS
  172. }
  173. }
  174. }), getItemDisabledStyle(`&-disabled ${componentCls}-item`, token)), getItemDisabledStyle(`${componentCls}-item-disabled`, token)), {
  175. // transition effect when `appear-active`
  176. [`${componentCls}-thumb-motion-appear-active`]: {
  177. transition: `transform ${token.motionDurationSlow} ${token.motionEaseInOut}, width ${token.motionDurationSlow} ${token.motionEaseInOut}`,
  178. willChange: 'transform, width'
  179. },
  180. [`&${componentCls}-shape-round`]: {
  181. borderRadius: 9999,
  182. [`${componentCls}-item, ${componentCls}-thumb`]: {
  183. borderRadius: 9999
  184. }
  185. }
  186. })
  187. };
  188. };
  189. // ============================== Export ==============================
  190. const prepareComponentToken = token => {
  191. const {
  192. colorTextLabel,
  193. colorText,
  194. colorFillSecondary,
  195. colorBgElevated,
  196. colorFill,
  197. lineWidthBold,
  198. colorBgLayout
  199. } = token;
  200. return {
  201. trackPadding: lineWidthBold,
  202. trackBg: colorBgLayout,
  203. itemColor: colorTextLabel,
  204. itemHoverColor: colorText,
  205. itemHoverBg: colorFillSecondary,
  206. itemSelectedBg: colorBgElevated,
  207. itemActiveBg: colorFill,
  208. itemSelectedColor: colorText
  209. };
  210. };
  211. exports.prepareComponentToken = prepareComponentToken;
  212. var _default = exports.default = (0, _internal.genStyleHooks)('Segmented', token => {
  213. const {
  214. lineWidth,
  215. calc
  216. } = token;
  217. const segmentedToken = (0, _internal.mergeToken)(token, {
  218. segmentedPaddingHorizontal: calc(token.controlPaddingHorizontal).sub(lineWidth).equal(),
  219. segmentedPaddingHorizontalSM: calc(token.controlPaddingHorizontalSM).sub(lineWidth).equal()
  220. });
  221. return genSegmentedStyle(segmentedToken);
  222. }, prepareComponentToken);