index.js 6.1 KB

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