sider.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. import { unit } from '@ant-design/cssinjs';
  2. import { DEPRECATED_TOKENS, prepareComponentToken } from '.';
  3. import { genStyleHooks } from '../../theme/internal';
  4. const genSiderStyle = token => {
  5. const {
  6. componentCls,
  7. siderBg,
  8. motionDurationMid,
  9. motionDurationSlow,
  10. antCls,
  11. triggerHeight,
  12. triggerColor,
  13. triggerBg,
  14. headerHeight,
  15. zeroTriggerWidth,
  16. zeroTriggerHeight,
  17. borderRadiusLG,
  18. lightSiderBg,
  19. lightTriggerColor,
  20. lightTriggerBg,
  21. bodyBg
  22. } = token;
  23. return {
  24. [componentCls]: {
  25. position: 'relative',
  26. // fix firefox can't set width smaller than content on flex item
  27. minWidth: 0,
  28. background: siderBg,
  29. transition: `all ${motionDurationMid}, background 0s`,
  30. '&-has-trigger': {
  31. paddingBottom: triggerHeight
  32. },
  33. '&-right': {
  34. order: 1
  35. },
  36. [`${componentCls}-children`]: {
  37. height: '100%',
  38. // Hack for fixing margin collapse bug
  39. // https://github.com/ant-design/ant-design/issues/7967
  40. // solution from https://stackoverflow.com/a/33132624/3040605
  41. marginTop: -0.1,
  42. paddingTop: 0.1,
  43. [`${antCls}-menu${antCls}-menu-inline-collapsed`]: {
  44. width: 'auto'
  45. }
  46. },
  47. [`&-zero-width ${componentCls}-children`]: {
  48. overflow: 'hidden'
  49. },
  50. [`${componentCls}-trigger`]: {
  51. position: 'fixed',
  52. bottom: 0,
  53. zIndex: 1,
  54. height: triggerHeight,
  55. color: triggerColor,
  56. lineHeight: unit(triggerHeight),
  57. textAlign: 'center',
  58. background: triggerBg,
  59. cursor: 'pointer',
  60. transition: `all ${motionDurationMid}`
  61. },
  62. [`${componentCls}-zero-width-trigger`]: {
  63. position: 'absolute',
  64. top: headerHeight,
  65. insetInlineEnd: token.calc(zeroTriggerWidth).mul(-1).equal(),
  66. zIndex: 1,
  67. width: zeroTriggerWidth,
  68. height: zeroTriggerHeight,
  69. color: triggerColor,
  70. fontSize: token.fontSizeXL,
  71. display: 'flex',
  72. alignItems: 'center',
  73. justifyContent: 'center',
  74. background: siderBg,
  75. borderRadius: `0 ${unit(borderRadiusLG)} ${unit(borderRadiusLG)} 0`,
  76. cursor: 'pointer',
  77. transition: `background ${motionDurationSlow} ease`,
  78. '&::after': {
  79. position: 'absolute',
  80. inset: 0,
  81. background: 'transparent',
  82. transition: `all ${motionDurationSlow}`,
  83. content: '""'
  84. },
  85. '&:hover::after': {
  86. background: `rgba(255, 255, 255, 0.2)`
  87. },
  88. '&-right': {
  89. insetInlineStart: token.calc(zeroTriggerWidth).mul(-1).equal(),
  90. borderRadius: `${unit(borderRadiusLG)} 0 0 ${unit(borderRadiusLG)}`
  91. }
  92. },
  93. // Light
  94. '&-light': {
  95. background: lightSiderBg,
  96. [`${componentCls}-trigger`]: {
  97. color: lightTriggerColor,
  98. background: lightTriggerBg
  99. },
  100. [`${componentCls}-zero-width-trigger`]: {
  101. color: lightTriggerColor,
  102. background: lightTriggerBg,
  103. border: `1px solid ${bodyBg}`,
  104. // Safe to modify to any other color
  105. borderInlineStart: 0
  106. }
  107. }
  108. }
  109. };
  110. };
  111. export default genStyleHooks(['Layout', 'Sider'], genSiderStyle, prepareComponentToken, {
  112. deprecatedTokens: DEPRECATED_TOKENS
  113. });