theme.js 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  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 _style = require("../../style");
  9. const accessibilityFocus = token => (0, _extends2.default)({}, (0, _style.genFocusOutline)(token));
  10. const getThemeStyle = (token, themeSuffix) => {
  11. const {
  12. componentCls,
  13. colorItemText,
  14. colorItemTextSelected,
  15. colorGroupTitle,
  16. colorItemBg,
  17. colorSubItemBg,
  18. colorItemBgSelected,
  19. colorActiveBarHeight,
  20. colorActiveBarWidth,
  21. colorActiveBarBorderSize,
  22. motionDurationSlow,
  23. motionEaseInOut,
  24. motionEaseOut,
  25. menuItemPaddingInline,
  26. motionDurationMid,
  27. colorItemTextHover,
  28. lineType,
  29. colorSplit,
  30. // Disabled
  31. colorItemTextDisabled,
  32. // Danger
  33. colorDangerItemText,
  34. colorDangerItemTextHover,
  35. colorDangerItemTextSelected,
  36. colorDangerItemBgActive,
  37. colorDangerItemBgSelected,
  38. colorItemBgHover,
  39. menuSubMenuBg,
  40. // Horizontal
  41. colorItemTextSelectedHorizontal,
  42. colorItemBgSelectedHorizontal
  43. } = token;
  44. return {
  45. [`${componentCls}-${themeSuffix}`]: {
  46. color: colorItemText,
  47. background: colorItemBg,
  48. [`&${componentCls}-root:focus-visible`]: (0, _extends2.default)({}, accessibilityFocus(token)),
  49. // ======================== Item ========================
  50. [`${componentCls}-item-group-title`]: {
  51. color: colorGroupTitle
  52. },
  53. [`${componentCls}-submenu-selected`]: {
  54. [`> ${componentCls}-submenu-title`]: {
  55. color: colorItemTextSelected
  56. }
  57. },
  58. // Disabled
  59. [`${componentCls}-item-disabled, ${componentCls}-submenu-disabled`]: {
  60. color: `${colorItemTextDisabled} !important`
  61. },
  62. // Hover
  63. [`${componentCls}-item:hover, ${componentCls}-submenu-title:hover`]: {
  64. [`&:not(${componentCls}-item-selected):not(${componentCls}-submenu-selected)`]: {
  65. color: colorItemTextHover
  66. }
  67. },
  68. [`&:not(${componentCls}-horizontal)`]: {
  69. [`${componentCls}-item:not(${componentCls}-item-selected)`]: {
  70. '&:hover': {
  71. backgroundColor: colorItemBgHover
  72. },
  73. '&:active': {
  74. backgroundColor: colorItemBgSelected
  75. }
  76. },
  77. [`${componentCls}-submenu-title`]: {
  78. '&:hover': {
  79. backgroundColor: colorItemBgHover
  80. },
  81. '&:active': {
  82. backgroundColor: colorItemBgSelected
  83. }
  84. }
  85. },
  86. // Danger - only Item has
  87. [`${componentCls}-item-danger`]: {
  88. color: colorDangerItemText,
  89. [`&${componentCls}-item:hover`]: {
  90. [`&:not(${componentCls}-item-selected):not(${componentCls}-submenu-selected)`]: {
  91. color: colorDangerItemTextHover
  92. }
  93. },
  94. [`&${componentCls}-item:active`]: {
  95. background: colorDangerItemBgActive
  96. }
  97. },
  98. [`${componentCls}-item a`]: {
  99. '&, &:hover': {
  100. color: 'inherit'
  101. }
  102. },
  103. [`${componentCls}-item-selected`]: {
  104. color: colorItemTextSelected,
  105. // Danger
  106. [`&${componentCls}-item-danger`]: {
  107. color: colorDangerItemTextSelected
  108. },
  109. [`a, a:hover`]: {
  110. color: 'inherit'
  111. }
  112. },
  113. [`& ${componentCls}-item-selected`]: {
  114. backgroundColor: colorItemBgSelected,
  115. // Danger
  116. [`&${componentCls}-item-danger`]: {
  117. backgroundColor: colorDangerItemBgSelected
  118. }
  119. },
  120. [`${componentCls}-item, ${componentCls}-submenu-title`]: {
  121. [`&:not(${componentCls}-item-disabled):focus-visible`]: (0, _extends2.default)({}, accessibilityFocus(token))
  122. },
  123. [`&${componentCls}-submenu > ${componentCls}`]: {
  124. backgroundColor: menuSubMenuBg
  125. },
  126. [`&${componentCls}-popup > ${componentCls}`]: {
  127. backgroundColor: colorItemBg
  128. },
  129. // ====================== Horizontal ======================
  130. [`&${componentCls}-horizontal`]: (0, _extends2.default)((0, _extends2.default)({}, themeSuffix === 'dark' ? {
  131. borderBottom: 0
  132. } : {}), {
  133. [`> ${componentCls}-item, > ${componentCls}-submenu`]: {
  134. top: colorActiveBarBorderSize,
  135. marginTop: -colorActiveBarBorderSize,
  136. marginBottom: 0,
  137. borderRadius: 0,
  138. '&::after': {
  139. position: 'absolute',
  140. insetInline: menuItemPaddingInline,
  141. bottom: 0,
  142. borderBottom: `${colorActiveBarHeight}px solid transparent`,
  143. transition: `border-color ${motionDurationSlow} ${motionEaseInOut}`,
  144. content: '""'
  145. },
  146. [`&:hover, &-active, &-open`]: {
  147. '&::after': {
  148. borderBottomWidth: colorActiveBarHeight,
  149. borderBottomColor: colorItemTextSelectedHorizontal
  150. }
  151. },
  152. [`&-selected`]: {
  153. color: colorItemTextSelectedHorizontal,
  154. backgroundColor: colorItemBgSelectedHorizontal,
  155. '&::after': {
  156. borderBottomWidth: colorActiveBarHeight,
  157. borderBottomColor: colorItemTextSelectedHorizontal
  158. }
  159. }
  160. }
  161. }),
  162. // ================== Inline & Vertical ===================
  163. //
  164. [`&${componentCls}-root`]: {
  165. [`&${componentCls}-inline, &${componentCls}-vertical`]: {
  166. borderInlineEnd: `${colorActiveBarBorderSize}px ${lineType} ${colorSplit}`
  167. }
  168. },
  169. // ======================== Inline ========================
  170. [`&${componentCls}-inline`]: {
  171. // Sub
  172. [`${componentCls}-sub${componentCls}-inline`]: {
  173. background: colorSubItemBg
  174. },
  175. // Item
  176. [`${componentCls}-item, ${componentCls}-submenu-title`]: colorActiveBarBorderSize && colorActiveBarWidth ? {
  177. width: `calc(100% + ${colorActiveBarBorderSize}px)`
  178. } : {},
  179. [`${componentCls}-item`]: {
  180. position: 'relative',
  181. '&::after': {
  182. position: 'absolute',
  183. insetBlock: 0,
  184. insetInlineEnd: 0,
  185. borderInlineEnd: `${colorActiveBarWidth}px solid ${colorItemTextSelected}`,
  186. transform: 'scaleY(0.0001)',
  187. opacity: 0,
  188. transition: [`transform ${motionDurationMid} ${motionEaseOut}`, `opacity ${motionDurationMid} ${motionEaseOut}`].join(','),
  189. content: '""'
  190. },
  191. // Danger
  192. [`&${componentCls}-item-danger`]: {
  193. '&::after': {
  194. borderInlineEndColor: colorDangerItemTextSelected
  195. }
  196. }
  197. },
  198. [`${componentCls}-selected, ${componentCls}-item-selected`]: {
  199. '&::after': {
  200. transform: 'scaleY(1)',
  201. opacity: 1,
  202. transition: [`transform ${motionDurationMid} ${motionEaseInOut}`, `opacity ${motionDurationMid} ${motionEaseInOut}`].join(',')
  203. }
  204. }
  205. }
  206. }
  207. };
  208. };
  209. var _default = exports.default = getThemeStyle;