index.js 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. import { genComponentStyleHook, mergeToken } from '../../theme/internal';
  2. import genMotionStyle from './motion';
  3. // =============================== Base ===============================
  4. const genDrawerStyle = token => {
  5. const {
  6. componentCls,
  7. zIndexPopup,
  8. colorBgMask,
  9. colorBgElevated,
  10. motionDurationSlow,
  11. motionDurationMid,
  12. padding,
  13. paddingLG,
  14. fontSizeLG,
  15. lineHeightLG,
  16. lineWidth,
  17. lineType,
  18. colorSplit,
  19. marginSM,
  20. colorIcon,
  21. colorIconHover,
  22. colorText,
  23. fontWeightStrong,
  24. drawerFooterPaddingVertical,
  25. drawerFooterPaddingHorizontal
  26. } = token;
  27. const wrapperCls = `${componentCls}-content-wrapper`;
  28. return {
  29. [componentCls]: {
  30. position: 'fixed',
  31. inset: 0,
  32. zIndex: zIndexPopup,
  33. pointerEvents: 'none',
  34. '&-pure': {
  35. position: 'relative',
  36. background: colorBgElevated,
  37. [`&${componentCls}-left`]: {
  38. boxShadow: token.boxShadowDrawerLeft
  39. },
  40. [`&${componentCls}-right`]: {
  41. boxShadow: token.boxShadowDrawerRight
  42. },
  43. [`&${componentCls}-top`]: {
  44. boxShadow: token.boxShadowDrawerUp
  45. },
  46. [`&${componentCls}-bottom`]: {
  47. boxShadow: token.boxShadowDrawerDown
  48. }
  49. },
  50. '&-inline': {
  51. position: 'absolute'
  52. },
  53. // ====================== Mask ======================
  54. [`${componentCls}-mask`]: {
  55. position: 'absolute',
  56. inset: 0,
  57. zIndex: zIndexPopup,
  58. background: colorBgMask,
  59. pointerEvents: 'auto'
  60. },
  61. // ==================== Content =====================
  62. [wrapperCls]: {
  63. position: 'absolute',
  64. zIndex: zIndexPopup,
  65. transition: `all ${motionDurationSlow}`,
  66. '&-hidden': {
  67. display: 'none'
  68. }
  69. },
  70. // Placement
  71. [`&-left > ${wrapperCls}`]: {
  72. top: 0,
  73. bottom: 0,
  74. left: {
  75. _skip_check_: true,
  76. value: 0
  77. },
  78. boxShadow: token.boxShadowDrawerLeft
  79. },
  80. [`&-right > ${wrapperCls}`]: {
  81. top: 0,
  82. right: {
  83. _skip_check_: true,
  84. value: 0
  85. },
  86. bottom: 0,
  87. boxShadow: token.boxShadowDrawerRight
  88. },
  89. [`&-top > ${wrapperCls}`]: {
  90. top: 0,
  91. insetInline: 0,
  92. boxShadow: token.boxShadowDrawerUp
  93. },
  94. [`&-bottom > ${wrapperCls}`]: {
  95. bottom: 0,
  96. insetInline: 0,
  97. boxShadow: token.boxShadowDrawerDown
  98. },
  99. [`${componentCls}-content`]: {
  100. width: '100%',
  101. height: '100%',
  102. overflow: 'auto',
  103. background: colorBgElevated,
  104. pointerEvents: 'auto'
  105. },
  106. // ===================== Panel ======================
  107. [`${componentCls}-wrapper-body`]: {
  108. display: 'flex',
  109. flexDirection: 'column',
  110. width: '100%',
  111. height: '100%'
  112. },
  113. // Header
  114. [`${componentCls}-header`]: {
  115. display: 'flex',
  116. flex: 0,
  117. alignItems: 'center',
  118. padding: `${padding}px ${paddingLG}px`,
  119. fontSize: fontSizeLG,
  120. lineHeight: lineHeightLG,
  121. borderBottom: `${lineWidth}px ${lineType} ${colorSplit}`,
  122. '&-title': {
  123. display: 'flex',
  124. flex: 1,
  125. alignItems: 'center',
  126. minWidth: 0,
  127. minHeight: 0
  128. }
  129. },
  130. [`${componentCls}-extra`]: {
  131. flex: 'none'
  132. },
  133. [`${componentCls}-close`]: {
  134. display: 'inline-block',
  135. marginInlineEnd: marginSM,
  136. color: colorIcon,
  137. fontWeight: fontWeightStrong,
  138. fontSize: fontSizeLG,
  139. fontStyle: 'normal',
  140. lineHeight: 1,
  141. textAlign: 'center',
  142. textTransform: 'none',
  143. textDecoration: 'none',
  144. background: 'transparent',
  145. border: 0,
  146. outline: 0,
  147. cursor: 'pointer',
  148. transition: `color ${motionDurationMid}`,
  149. textRendering: 'auto',
  150. '&:focus, &:hover': {
  151. color: colorIconHover,
  152. textDecoration: 'none'
  153. }
  154. },
  155. [`${componentCls}-title`]: {
  156. flex: 1,
  157. margin: 0,
  158. color: colorText,
  159. fontWeight: token.fontWeightStrong,
  160. fontSize: fontSizeLG,
  161. lineHeight: lineHeightLG
  162. },
  163. // Body
  164. [`${componentCls}-body`]: {
  165. flex: 1,
  166. minWidth: 0,
  167. minHeight: 0,
  168. padding: paddingLG,
  169. overflow: 'auto'
  170. },
  171. // Footer
  172. [`${componentCls}-footer`]: {
  173. flexShrink: 0,
  174. padding: `${drawerFooterPaddingVertical}px ${drawerFooterPaddingHorizontal}px`,
  175. borderTop: `${lineWidth}px ${lineType} ${colorSplit}`
  176. },
  177. // ====================== RTL =======================
  178. '&-rtl': {
  179. direction: 'rtl'
  180. }
  181. }
  182. };
  183. };
  184. // ============================== Export ==============================
  185. export default genComponentStyleHook('Drawer', token => {
  186. const drawerToken = mergeToken(token, {
  187. drawerFooterPaddingVertical: token.paddingXS,
  188. drawerFooterPaddingHorizontal: token.padding
  189. });
  190. return [genDrawerStyle(drawerToken), genMotionStyle(drawerToken)];
  191. }, token => ({
  192. zIndexPopup: token.zIndexPopupBase
  193. }));