index.js 5.7 KB

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