theme.js 6.7 KB

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