theme.js 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.default = void 0;
  6. var _cssinjs = require("@ant-design/cssinjs");
  7. var _style = require("../../style");
  8. const accessibilityFocus = token => (0, _style.genFocusOutline)(token);
  9. const getThemeStyle = (token, themeSuffix) => {
  10. const {
  11. componentCls,
  12. itemColor,
  13. itemSelectedColor,
  14. subMenuItemSelectedColor,
  15. groupTitleColor,
  16. itemBg,
  17. subMenuItemBg,
  18. itemSelectedBg,
  19. activeBarHeight,
  20. activeBarWidth,
  21. activeBarBorderWidth,
  22. motionDurationSlow,
  23. motionEaseInOut,
  24. motionEaseOut,
  25. itemPaddingInline,
  26. motionDurationMid,
  27. itemHoverColor,
  28. lineType,
  29. colorSplit,
  30. // Disabled
  31. itemDisabledColor,
  32. // Danger
  33. dangerItemColor,
  34. dangerItemHoverColor,
  35. dangerItemSelectedColor,
  36. dangerItemActiveBg,
  37. dangerItemSelectedBg,
  38. // Bg
  39. popupBg,
  40. itemHoverBg,
  41. itemActiveBg,
  42. menuSubMenuBg,
  43. // Horizontal
  44. horizontalItemSelectedColor,
  45. horizontalItemSelectedBg,
  46. horizontalItemBorderRadius,
  47. horizontalItemHoverBg
  48. } = token;
  49. return {
  50. [`${componentCls}-${themeSuffix}, ${componentCls}-${themeSuffix} > ${componentCls}`]: {
  51. color: itemColor,
  52. background: itemBg,
  53. [`&${componentCls}-root:focus-visible`]: Object.assign({}, accessibilityFocus(token)),
  54. // ======================== Item ========================
  55. [`${componentCls}-item`]: {
  56. '&-group-title, &-extra': {
  57. color: groupTitleColor
  58. }
  59. },
  60. [`${componentCls}-submenu-selected > ${componentCls}-submenu-title`]: {
  61. color: subMenuItemSelectedColor
  62. },
  63. [`${componentCls}-item, ${componentCls}-submenu-title`]: {
  64. color: itemColor,
  65. [`&:not(${componentCls}-item-disabled):focus-visible`]: Object.assign({}, accessibilityFocus(token))
  66. },
  67. // Disabled
  68. [`${componentCls}-item-disabled, ${componentCls}-submenu-disabled`]: {
  69. color: `${itemDisabledColor} !important`
  70. },
  71. // Hover
  72. [`${componentCls}-item:not(${componentCls}-item-selected):not(${componentCls}-submenu-selected)`]: {
  73. [`&:hover, > ${componentCls}-submenu-title:hover`]: {
  74. color: itemHoverColor
  75. }
  76. },
  77. [`&:not(${componentCls}-horizontal)`]: {
  78. [`${componentCls}-item:not(${componentCls}-item-selected)`]: {
  79. '&:hover': {
  80. backgroundColor: itemHoverBg
  81. },
  82. '&:active': {
  83. backgroundColor: itemActiveBg
  84. }
  85. },
  86. [`${componentCls}-submenu-title`]: {
  87. '&:hover': {
  88. backgroundColor: itemHoverBg
  89. },
  90. '&:active': {
  91. backgroundColor: itemActiveBg
  92. }
  93. }
  94. },
  95. // Danger - only Item has
  96. [`${componentCls}-item-danger`]: {
  97. color: dangerItemColor,
  98. [`&${componentCls}-item:hover`]: {
  99. [`&:not(${componentCls}-item-selected):not(${componentCls}-submenu-selected)`]: {
  100. color: dangerItemHoverColor
  101. }
  102. },
  103. [`&${componentCls}-item:active`]: {
  104. background: dangerItemActiveBg
  105. }
  106. },
  107. [`${componentCls}-item a`]: {
  108. '&, &:hover': {
  109. color: 'inherit'
  110. }
  111. },
  112. [`${componentCls}-item-selected`]: {
  113. color: itemSelectedColor,
  114. // Danger
  115. [`&${componentCls}-item-danger`]: {
  116. color: dangerItemSelectedColor
  117. },
  118. 'a, a:hover': {
  119. color: 'inherit'
  120. }
  121. },
  122. [`& ${componentCls}-item-selected`]: {
  123. backgroundColor: itemSelectedBg,
  124. // Danger
  125. [`&${componentCls}-item-danger`]: {
  126. backgroundColor: dangerItemSelectedBg
  127. }
  128. },
  129. [`&${componentCls}-submenu > ${componentCls}`]: {
  130. backgroundColor: menuSubMenuBg
  131. },
  132. // ===== 设置浮层的颜色 =======
  133. // !dark 模式会被popupBg 会被rest 为 darkPopupBg
  134. [`&${componentCls}-popup > ${componentCls}`]: {
  135. backgroundColor: popupBg
  136. },
  137. [`&${componentCls}-submenu-popup > ${componentCls}`]: {
  138. backgroundColor: popupBg
  139. },
  140. // ===== 设置浮层的颜色 end =======
  141. // ====================== Horizontal ======================
  142. [`&${componentCls}-horizontal`]: Object.assign(Object.assign({}, themeSuffix === 'dark' ? {
  143. borderBottom: 0
  144. } : {}), {
  145. [`> ${componentCls}-item, > ${componentCls}-submenu`]: {
  146. top: activeBarBorderWidth,
  147. marginTop: token.calc(activeBarBorderWidth).mul(-1).equal(),
  148. marginBottom: 0,
  149. borderRadius: horizontalItemBorderRadius,
  150. '&::after': {
  151. position: 'absolute',
  152. insetInline: itemPaddingInline,
  153. bottom: 0,
  154. borderBottom: `${(0, _cssinjs.unit)(activeBarHeight)} solid transparent`,
  155. transition: `border-color ${motionDurationSlow} ${motionEaseInOut}`,
  156. content: '""'
  157. },
  158. '&:hover, &-active, &-open': {
  159. background: horizontalItemHoverBg,
  160. '&::after': {
  161. borderBottomWidth: activeBarHeight,
  162. borderBottomColor: horizontalItemSelectedColor
  163. }
  164. },
  165. '&-selected': {
  166. color: horizontalItemSelectedColor,
  167. backgroundColor: horizontalItemSelectedBg,
  168. '&:hover': {
  169. backgroundColor: horizontalItemSelectedBg
  170. },
  171. '&::after': {
  172. borderBottomWidth: activeBarHeight,
  173. borderBottomColor: horizontalItemSelectedColor
  174. }
  175. }
  176. }
  177. }),
  178. // ================== Inline & Vertical ===================
  179. //
  180. [`&${componentCls}-root`]: {
  181. [`&${componentCls}-inline, &${componentCls}-vertical`]: {
  182. borderInlineEnd: `${(0, _cssinjs.unit)(activeBarBorderWidth)} ${lineType} ${colorSplit}`
  183. }
  184. },
  185. // ======================== Inline ========================
  186. [`&${componentCls}-inline`]: {
  187. // Sub
  188. [`${componentCls}-sub${componentCls}-inline`]: {
  189. background: subMenuItemBg
  190. },
  191. [`${componentCls}-item`]: {
  192. position: 'relative',
  193. '&::after': {
  194. position: 'absolute',
  195. insetBlock: 0,
  196. insetInlineEnd: 0,
  197. borderInlineEnd: `${(0, _cssinjs.unit)(activeBarWidth)} solid ${itemSelectedColor}`,
  198. transform: 'scaleY(0.0001)',
  199. opacity: 0,
  200. transition: [`transform ${motionDurationMid} ${motionEaseOut}`, `opacity ${motionDurationMid} ${motionEaseOut}`].join(','),
  201. content: '""'
  202. },
  203. // Danger
  204. [`&${componentCls}-item-danger`]: {
  205. '&::after': {
  206. borderInlineEndColor: dangerItemSelectedColor
  207. }
  208. }
  209. },
  210. [`${componentCls}-selected, ${componentCls}-item-selected`]: {
  211. '&::after': {
  212. transform: 'scaleY(1)',
  213. opacity: 1,
  214. transition: [`transform ${motionDurationMid} ${motionEaseInOut}`, `opacity ${motionDurationMid} ${motionEaseInOut}`].join(',')
  215. }
  216. }
  217. }
  218. }
  219. };
  220. };
  221. var _default = exports.default = getThemeStyle;