index.js 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. import _extends from "@babel/runtime/helpers/esm/extends";
  2. import { genComponentStyleHook, mergeToken } from '../../theme/internal';
  3. import genLayoutLightStyle from './light';
  4. const genLayoutStyle = token => {
  5. const {
  6. antCls,
  7. // .ant
  8. componentCls,
  9. // .ant-layout
  10. colorText,
  11. colorTextLightSolid,
  12. colorBgHeader,
  13. colorBgBody,
  14. colorBgTrigger,
  15. layoutHeaderHeight,
  16. layoutHeaderPaddingInline,
  17. layoutHeaderColor,
  18. layoutFooterPadding,
  19. layoutTriggerHeight,
  20. layoutZeroTriggerSize,
  21. motionDurationMid,
  22. motionDurationSlow,
  23. fontSize,
  24. borderRadius
  25. } = token;
  26. return {
  27. [componentCls]: _extends(_extends({
  28. display: 'flex',
  29. flex: 'auto',
  30. flexDirection: 'column',
  31. color: colorText,
  32. /* fix firefox can't set height smaller than content on flex item */
  33. minHeight: 0,
  34. background: colorBgBody,
  35. '&, *': {
  36. boxSizing: 'border-box'
  37. },
  38. [`&${componentCls}-has-sider`]: {
  39. flexDirection: 'row',
  40. [`> ${componentCls}, > ${componentCls}-content`]: {
  41. // https://segmentfault.com/a/1190000019498300
  42. width: 0
  43. }
  44. },
  45. [`${componentCls}-header, &${componentCls}-footer`]: {
  46. flex: '0 0 auto'
  47. },
  48. [`${componentCls}-header`]: {
  49. height: layoutHeaderHeight,
  50. paddingInline: layoutHeaderPaddingInline,
  51. color: layoutHeaderColor,
  52. lineHeight: `${layoutHeaderHeight}px`,
  53. background: colorBgHeader,
  54. // Other components/menu/style/index.less line:686
  55. // Integration with header element so menu items have the same height
  56. [`${antCls}-menu`]: {
  57. lineHeight: 'inherit'
  58. }
  59. },
  60. [`${componentCls}-footer`]: {
  61. padding: layoutFooterPadding,
  62. color: colorText,
  63. fontSize,
  64. background: colorBgBody
  65. },
  66. [`${componentCls}-content`]: {
  67. flex: 'auto',
  68. // fix firefox can't set height smaller than content on flex item
  69. minHeight: 0
  70. },
  71. [`${componentCls}-sider`]: {
  72. position: 'relative',
  73. // fix firefox can't set width smaller than content on flex item
  74. minWidth: 0,
  75. background: colorBgHeader,
  76. transition: `all ${motionDurationMid}, background 0s`,
  77. '&-children': {
  78. height: '100%',
  79. // Hack for fixing margin collapse bug
  80. // https://github.com/ant-design/ant-design/issues/7967
  81. // solution from https://stackoverflow.com/a/33132624/3040605
  82. marginTop: -0.1,
  83. paddingTop: 0.1,
  84. [`${antCls}-menu${antCls}-menu-inline-collapsed`]: {
  85. width: 'auto'
  86. }
  87. },
  88. '&-has-trigger': {
  89. paddingBottom: layoutTriggerHeight
  90. },
  91. '&-right': {
  92. order: 1
  93. },
  94. '&-trigger': {
  95. position: 'fixed',
  96. bottom: 0,
  97. zIndex: 1,
  98. height: layoutTriggerHeight,
  99. color: colorTextLightSolid,
  100. lineHeight: `${layoutTriggerHeight}px`,
  101. textAlign: 'center',
  102. background: colorBgTrigger,
  103. cursor: 'pointer',
  104. transition: `all ${motionDurationMid}`
  105. },
  106. '&-zero-width': {
  107. '> *': {
  108. overflow: 'hidden'
  109. },
  110. '&-trigger': {
  111. position: 'absolute',
  112. top: layoutHeaderHeight,
  113. insetInlineEnd: -layoutZeroTriggerSize,
  114. zIndex: 1,
  115. width: layoutZeroTriggerSize,
  116. height: layoutZeroTriggerSize,
  117. color: colorTextLightSolid,
  118. fontSize: token.fontSizeXL,
  119. display: 'flex',
  120. alignItems: 'center',
  121. justifyContent: 'center',
  122. background: colorBgHeader,
  123. borderStartStartRadius: 0,
  124. borderStartEndRadius: borderRadius,
  125. borderEndEndRadius: borderRadius,
  126. borderEndStartRadius: 0,
  127. cursor: 'pointer',
  128. transition: `background ${motionDurationSlow} ease`,
  129. '&::after': {
  130. position: 'absolute',
  131. inset: 0,
  132. background: 'transparent',
  133. transition: `all ${motionDurationSlow}`,
  134. content: '""'
  135. },
  136. '&:hover::after': {
  137. // FIXME: Hardcode, but seems no need to create a token for this
  138. background: `rgba(255, 255, 255, 0.2)`
  139. },
  140. '&-right': {
  141. insetInlineStart: -layoutZeroTriggerSize,
  142. borderStartStartRadius: borderRadius,
  143. borderStartEndRadius: 0,
  144. borderEndEndRadius: 0,
  145. borderEndStartRadius: borderRadius
  146. }
  147. }
  148. }
  149. }
  150. }, genLayoutLightStyle(token)), {
  151. // RTL
  152. '&-rtl': {
  153. direction: 'rtl'
  154. }
  155. })
  156. };
  157. };
  158. // ============================== Export ==============================
  159. export default genComponentStyleHook('Layout', token => {
  160. const {
  161. colorText,
  162. controlHeightSM,
  163. controlHeight,
  164. controlHeightLG,
  165. marginXXS
  166. } = token;
  167. const layoutHeaderPaddingInline = controlHeightLG * 1.25;
  168. const layoutToken = mergeToken(token, {
  169. // Layout
  170. layoutHeaderHeight: controlHeight * 2,
  171. layoutHeaderPaddingInline,
  172. layoutHeaderColor: colorText,
  173. layoutFooterPadding: `${controlHeightSM}px ${layoutHeaderPaddingInline}px`,
  174. layoutTriggerHeight: controlHeightLG + marginXXS * 2,
  175. layoutZeroTriggerSize: controlHeightLG
  176. });
  177. return [genLayoutStyle(layoutToken)];
  178. }, token => {
  179. const {
  180. colorBgLayout
  181. } = token;
  182. return {
  183. colorBgHeader: '#001529',
  184. colorBgBody: colorBgLayout,
  185. colorBgTrigger: '#002140'
  186. };
  187. });