index.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316
  1. "use strict";
  2. var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
  3. Object.defineProperty(exports, "__esModule", {
  4. value: true
  5. });
  6. exports.prepareToken = exports.prepareComponentToken = exports.genModalMaskStyle = exports.default = void 0;
  7. var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
  8. var _cssinjs = require("@ant-design/cssinjs");
  9. var _style = require("../../grid/style");
  10. var _style2 = require("../../style");
  11. var _motion = require("../../style/motion");
  12. var _internal = require("../../theme/internal");
  13. function box(position) {
  14. return {
  15. position,
  16. inset: 0
  17. };
  18. }
  19. const genModalMaskStyle = token => {
  20. const {
  21. componentCls,
  22. antCls
  23. } = token;
  24. return [{
  25. [`${componentCls}-root`]: {
  26. [`${componentCls}${antCls}-zoom-enter, ${componentCls}${antCls}-zoom-appear`]: {
  27. // reset scale avoid mousePosition bug
  28. transform: 'none',
  29. opacity: 0,
  30. animationDuration: token.motionDurationSlow,
  31. // https://github.com/ant-design/ant-design/issues/11777
  32. userSelect: 'none'
  33. },
  34. // https://github.com/ant-design/ant-design/issues/37329
  35. // https://github.com/ant-design/ant-design/issues/40272
  36. [`${componentCls}${antCls}-zoom-leave ${componentCls}-content`]: {
  37. pointerEvents: 'none'
  38. },
  39. [`${componentCls}-mask`]: Object.assign(Object.assign({}, box('fixed')), {
  40. zIndex: token.zIndexPopupBase,
  41. height: '100%',
  42. backgroundColor: token.colorBgMask,
  43. pointerEvents: 'none',
  44. [`${componentCls}-hidden`]: {
  45. display: 'none'
  46. }
  47. }),
  48. [`${componentCls}-wrap`]: Object.assign(Object.assign({}, box('fixed')), {
  49. zIndex: token.zIndexPopupBase,
  50. overflow: 'auto',
  51. outline: 0,
  52. WebkitOverflowScrolling: 'touch'
  53. })
  54. }
  55. }, {
  56. [`${componentCls}-root`]: (0, _motion.initFadeMotion)(token)
  57. }];
  58. };
  59. exports.genModalMaskStyle = genModalMaskStyle;
  60. const genModalStyle = token => {
  61. const {
  62. componentCls
  63. } = token;
  64. return [
  65. // ======================== Root =========================
  66. {
  67. [`${componentCls}-root`]: {
  68. [`${componentCls}-wrap-rtl`]: {
  69. direction: 'rtl'
  70. },
  71. [`${componentCls}-centered`]: {
  72. textAlign: 'center',
  73. '&::before': {
  74. display: 'inline-block',
  75. width: 0,
  76. height: '100%',
  77. verticalAlign: 'middle',
  78. content: '""'
  79. },
  80. [componentCls]: {
  81. top: 0,
  82. display: 'inline-block',
  83. paddingBottom: 0,
  84. textAlign: 'start',
  85. verticalAlign: 'middle'
  86. }
  87. },
  88. [`@media (max-width: ${token.screenSMMax}px)`]: {
  89. [componentCls]: {
  90. maxWidth: 'calc(100vw - 16px)',
  91. margin: `${(0, _cssinjs.unit)(token.marginXS)} auto`
  92. },
  93. [`${componentCls}-centered`]: {
  94. [componentCls]: {
  95. flex: 1
  96. }
  97. }
  98. }
  99. }
  100. },
  101. // ======================== Modal ========================
  102. {
  103. [componentCls]: Object.assign(Object.assign({}, (0, _style2.resetComponent)(token)), {
  104. pointerEvents: 'none',
  105. position: 'relative',
  106. top: 100,
  107. width: 'auto',
  108. maxWidth: `calc(100vw - ${(0, _cssinjs.unit)(token.calc(token.margin).mul(2).equal())})`,
  109. margin: '0 auto',
  110. paddingBottom: token.paddingLG,
  111. [`${componentCls}-title`]: {
  112. margin: 0,
  113. color: token.titleColor,
  114. fontWeight: token.fontWeightStrong,
  115. fontSize: token.titleFontSize,
  116. lineHeight: token.titleLineHeight,
  117. wordWrap: 'break-word'
  118. },
  119. [`${componentCls}-content`]: {
  120. position: 'relative',
  121. backgroundColor: token.contentBg,
  122. backgroundClip: 'padding-box',
  123. border: 0,
  124. borderRadius: token.borderRadiusLG,
  125. boxShadow: token.boxShadow,
  126. pointerEvents: 'auto',
  127. padding: token.contentPadding
  128. },
  129. [`${componentCls}-close`]: Object.assign({
  130. position: 'absolute',
  131. top: token.calc(token.modalHeaderHeight).sub(token.modalCloseBtnSize).div(2).equal(),
  132. insetInlineEnd: token.calc(token.modalHeaderHeight).sub(token.modalCloseBtnSize).div(2).equal(),
  133. zIndex: token.calc(token.zIndexPopupBase).add(10).equal(),
  134. padding: 0,
  135. color: token.modalCloseIconColor,
  136. fontWeight: token.fontWeightStrong,
  137. lineHeight: 1,
  138. textDecoration: 'none',
  139. background: 'transparent',
  140. borderRadius: token.borderRadiusSM,
  141. width: token.modalCloseBtnSize,
  142. height: token.modalCloseBtnSize,
  143. border: 0,
  144. outline: 0,
  145. cursor: 'pointer',
  146. transition: `color ${token.motionDurationMid}, background-color ${token.motionDurationMid}`,
  147. '&-x': {
  148. display: 'flex',
  149. fontSize: token.fontSizeLG,
  150. fontStyle: 'normal',
  151. lineHeight: (0, _cssinjs.unit)(token.modalCloseBtnSize),
  152. justifyContent: 'center',
  153. textTransform: 'none',
  154. textRendering: 'auto'
  155. },
  156. '&:disabled': {
  157. pointerEvents: 'none'
  158. },
  159. '&:hover': {
  160. color: token.modalCloseIconHoverColor,
  161. backgroundColor: token.colorBgTextHover,
  162. textDecoration: 'none'
  163. },
  164. '&:active': {
  165. backgroundColor: token.colorBgTextActive
  166. }
  167. }, (0, _style2.genFocusStyle)(token)),
  168. [`${componentCls}-header`]: {
  169. color: token.colorText,
  170. background: token.headerBg,
  171. borderRadius: `${(0, _cssinjs.unit)(token.borderRadiusLG)} ${(0, _cssinjs.unit)(token.borderRadiusLG)} 0 0`,
  172. marginBottom: token.headerMarginBottom,
  173. padding: token.headerPadding,
  174. borderBottom: token.headerBorderBottom
  175. },
  176. [`${componentCls}-body`]: {
  177. fontSize: token.fontSize,
  178. lineHeight: token.lineHeight,
  179. wordWrap: 'break-word',
  180. padding: token.bodyPadding,
  181. [`${componentCls}-body-skeleton`]: {
  182. width: '100%',
  183. height: '100%',
  184. display: 'flex',
  185. justifyContent: 'center',
  186. alignItems: 'center',
  187. margin: `${(0, _cssinjs.unit)(token.margin)} auto`
  188. }
  189. },
  190. [`${componentCls}-footer`]: {
  191. textAlign: 'end',
  192. background: token.footerBg,
  193. marginTop: token.footerMarginTop,
  194. padding: token.footerPadding,
  195. borderTop: token.footerBorderTop,
  196. borderRadius: token.footerBorderRadius,
  197. [`> ${token.antCls}-btn + ${token.antCls}-btn`]: {
  198. marginInlineStart: token.marginXS
  199. }
  200. },
  201. [`${componentCls}-open`]: {
  202. overflow: 'hidden'
  203. }
  204. })
  205. },
  206. // ======================== Pure =========================
  207. {
  208. [`${componentCls}-pure-panel`]: {
  209. top: 'auto',
  210. padding: 0,
  211. display: 'flex',
  212. flexDirection: 'column',
  213. [`${componentCls}-content,
  214. ${componentCls}-body,
  215. ${componentCls}-confirm-body-wrapper`]: {
  216. display: 'flex',
  217. flexDirection: 'column',
  218. flex: 'auto'
  219. },
  220. [`${componentCls}-confirm-body`]: {
  221. marginBottom: 'auto'
  222. }
  223. }
  224. }];
  225. };
  226. const genRTLStyle = token => {
  227. const {
  228. componentCls
  229. } = token;
  230. return {
  231. [`${componentCls}-root`]: {
  232. [`${componentCls}-wrap-rtl`]: {
  233. direction: 'rtl',
  234. [`${componentCls}-confirm-body`]: {
  235. direction: 'rtl'
  236. }
  237. }
  238. }
  239. };
  240. };
  241. const genResponsiveWidthStyle = token => {
  242. const {
  243. componentCls
  244. } = token;
  245. const oriGridMediaSizesMap = (0, _style.getMediaSize)(token);
  246. const gridMediaSizesMap = Object.assign({}, oriGridMediaSizesMap);
  247. delete gridMediaSizesMap.xs;
  248. const cssVarPrefix = `--${componentCls.replace('.', '')}-`;
  249. const responsiveStyles = Object.keys(gridMediaSizesMap).map(key => ({
  250. [`@media (min-width: ${(0, _cssinjs.unit)(gridMediaSizesMap[key])})`]: {
  251. width: `var(${cssVarPrefix}${key}-width)`
  252. }
  253. }));
  254. return {
  255. [`${componentCls}-root`]: {
  256. [componentCls]: [].concat((0, _toConsumableArray2.default)(Object.keys(oriGridMediaSizesMap).map((currentKey, index) => {
  257. const previousKey = Object.keys(oriGridMediaSizesMap)[index - 1];
  258. return previousKey ? {
  259. [`${cssVarPrefix}${currentKey}-width`]: `var(${cssVarPrefix}${previousKey}-width)`
  260. } : null;
  261. })), [{
  262. width: `var(${cssVarPrefix}xs-width)`
  263. }], (0, _toConsumableArray2.default)(responsiveStyles))
  264. }
  265. };
  266. };
  267. // ============================== Export ==============================
  268. const prepareToken = token => {
  269. const headerPaddingVertical = token.padding;
  270. const headerFontSize = token.fontSizeHeading5;
  271. const headerLineHeight = token.lineHeightHeading5;
  272. const modalToken = (0, _internal.mergeToken)(token, {
  273. modalHeaderHeight: token.calc(token.calc(headerLineHeight).mul(headerFontSize).equal()).add(token.calc(headerPaddingVertical).mul(2).equal()).equal(),
  274. modalFooterBorderColorSplit: token.colorSplit,
  275. modalFooterBorderStyle: token.lineType,
  276. modalFooterBorderWidth: token.lineWidth,
  277. modalCloseIconColor: token.colorIcon,
  278. modalCloseIconHoverColor: token.colorIconHover,
  279. modalCloseBtnSize: token.controlHeight,
  280. modalConfirmIconSize: token.fontHeight,
  281. modalTitleHeight: token.calc(token.titleFontSize).mul(token.titleLineHeight).equal()
  282. });
  283. return modalToken;
  284. };
  285. exports.prepareToken = prepareToken;
  286. const prepareComponentToken = token => ({
  287. footerBg: 'transparent',
  288. headerBg: token.colorBgElevated,
  289. titleLineHeight: token.lineHeightHeading5,
  290. titleFontSize: token.fontSizeHeading5,
  291. contentBg: token.colorBgElevated,
  292. titleColor: token.colorTextHeading,
  293. // internal
  294. contentPadding: token.wireframe ? 0 : `${(0, _cssinjs.unit)(token.paddingMD)} ${(0, _cssinjs.unit)(token.paddingContentHorizontalLG)}`,
  295. headerPadding: token.wireframe ? `${(0, _cssinjs.unit)(token.padding)} ${(0, _cssinjs.unit)(token.paddingLG)}` : 0,
  296. headerBorderBottom: token.wireframe ? `${(0, _cssinjs.unit)(token.lineWidth)} ${token.lineType} ${token.colorSplit}` : 'none',
  297. headerMarginBottom: token.wireframe ? 0 : token.marginXS,
  298. bodyPadding: token.wireframe ? token.paddingLG : 0,
  299. footerPadding: token.wireframe ? `${(0, _cssinjs.unit)(token.paddingXS)} ${(0, _cssinjs.unit)(token.padding)}` : 0,
  300. footerBorderTop: token.wireframe ? `${(0, _cssinjs.unit)(token.lineWidth)} ${token.lineType} ${token.colorSplit}` : 'none',
  301. footerBorderRadius: token.wireframe ? `0 0 ${(0, _cssinjs.unit)(token.borderRadiusLG)} ${(0, _cssinjs.unit)(token.borderRadiusLG)}` : 0,
  302. footerMarginTop: token.wireframe ? 0 : token.marginSM,
  303. confirmBodyPadding: token.wireframe ? `${(0, _cssinjs.unit)(token.padding * 2)} ${(0, _cssinjs.unit)(token.padding * 2)} ${(0, _cssinjs.unit)(token.paddingLG)}` : 0,
  304. confirmIconMarginInlineEnd: token.wireframe ? token.margin : token.marginSM,
  305. confirmBtnsMarginTop: token.wireframe ? token.marginLG : token.marginSM
  306. });
  307. exports.prepareComponentToken = prepareComponentToken;
  308. var _default = exports.default = (0, _internal.genStyleHooks)('Modal', token => {
  309. const modalToken = prepareToken(token);
  310. return [genModalStyle(modalToken), genRTLStyle(modalToken), genModalMaskStyle(modalToken), (0, _motion.initZoomMotion)(modalToken, 'zoom'), genResponsiveWidthStyle(modalToken)];
  311. }, prepareComponentToken, {
  312. unitless: {
  313. titleLineHeight: true
  314. }
  315. });