index.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385
  1. "use strict";
  2. var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
  3. Object.defineProperty(exports, "__esModule", {
  4. value: true
  5. });
  6. exports.genModalMaskStyle = exports.default = void 0;
  7. var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
  8. var _motion = require("../../style/motion");
  9. var _internal = require("../../theme/internal");
  10. var _style = require("../../style");
  11. require("vue");
  12. function box(position) {
  13. return {
  14. position,
  15. top: 0,
  16. insetInlineEnd: 0,
  17. bottom: 0,
  18. insetInlineStart: 0
  19. };
  20. }
  21. const genModalMaskStyle = token => {
  22. const {
  23. componentCls
  24. } = token;
  25. return [{
  26. [`${componentCls}-root`]: {
  27. [`${componentCls}${token.antCls}-zoom-enter, ${componentCls}${token.antCls}-zoom-appear`]: {
  28. // reset scale avoid mousePosition bug
  29. transform: 'none',
  30. opacity: 0,
  31. animationDuration: token.motionDurationSlow,
  32. // https://github.com/ant-design/ant-design/issues/11777
  33. userSelect: 'none'
  34. },
  35. [`${componentCls}${token.antCls}-zoom-leave ${componentCls}-content`]: {
  36. pointerEvents: 'none'
  37. },
  38. [`${componentCls}-mask`]: (0, _extends2.default)((0, _extends2.default)({}, box('fixed')), {
  39. zIndex: token.zIndexPopupBase,
  40. height: '100%',
  41. backgroundColor: token.colorBgMask,
  42. [`${componentCls}-hidden`]: {
  43. display: 'none'
  44. }
  45. }),
  46. [`${componentCls}-wrap`]: (0, _extends2.default)((0, _extends2.default)({}, box('fixed')), {
  47. overflow: 'auto',
  48. outline: 0,
  49. WebkitOverflowScrolling: 'touch'
  50. })
  51. }
  52. }, {
  53. [`${componentCls}-root`]: (0, _motion.initFadeMotion)(token)
  54. }];
  55. };
  56. exports.genModalMaskStyle = genModalMaskStyle;
  57. const genModalStyle = token => {
  58. const {
  59. componentCls
  60. } = token;
  61. return [
  62. // ======================== Root =========================
  63. {
  64. [`${componentCls}-root`]: {
  65. [`${componentCls}-wrap`]: {
  66. zIndex: token.zIndexPopupBase,
  67. position: 'fixed',
  68. inset: 0,
  69. overflow: 'auto',
  70. outline: 0,
  71. WebkitOverflowScrolling: 'touch'
  72. },
  73. [`${componentCls}-wrap-rtl`]: {
  74. direction: 'rtl'
  75. },
  76. [`${componentCls}-centered`]: {
  77. textAlign: 'center',
  78. '&::before': {
  79. display: 'inline-block',
  80. width: 0,
  81. height: '100%',
  82. verticalAlign: 'middle',
  83. content: '""'
  84. },
  85. [componentCls]: {
  86. top: 0,
  87. display: 'inline-block',
  88. paddingBottom: 0,
  89. textAlign: 'start',
  90. verticalAlign: 'middle'
  91. }
  92. },
  93. [`@media (max-width: ${token.screenSMMax})`]: {
  94. [componentCls]: {
  95. maxWidth: 'calc(100vw - 16px)',
  96. margin: `${token.marginXS} auto`
  97. },
  98. [`${componentCls}-centered`]: {
  99. [componentCls]: {
  100. flex: 1
  101. }
  102. }
  103. }
  104. }
  105. },
  106. // ======================== Modal ========================
  107. {
  108. [componentCls]: (0, _extends2.default)((0, _extends2.default)({}, (0, _style.resetComponent)(token)), {
  109. pointerEvents: 'none',
  110. position: 'relative',
  111. top: 100,
  112. width: 'auto',
  113. maxWidth: `calc(100vw - ${token.margin * 2}px)`,
  114. margin: '0 auto',
  115. paddingBottom: token.paddingLG,
  116. [`${componentCls}-title`]: {
  117. margin: 0,
  118. color: token.modalHeadingColor,
  119. fontWeight: token.fontWeightStrong,
  120. fontSize: token.modalHeaderTitleFontSize,
  121. lineHeight: token.modalHeaderTitleLineHeight,
  122. wordWrap: 'break-word'
  123. },
  124. [`${componentCls}-content`]: {
  125. position: 'relative',
  126. backgroundColor: token.modalContentBg,
  127. backgroundClip: 'padding-box',
  128. border: 0,
  129. borderRadius: token.borderRadiusLG,
  130. boxShadow: token.boxShadowSecondary,
  131. pointerEvents: 'auto',
  132. padding: `${token.paddingMD}px ${token.paddingContentHorizontalLG}px`
  133. },
  134. [`${componentCls}-close`]: (0, _extends2.default)({
  135. position: 'absolute',
  136. top: (token.modalHeaderCloseSize - token.modalCloseBtnSize) / 2,
  137. insetInlineEnd: (token.modalHeaderCloseSize - token.modalCloseBtnSize) / 2,
  138. zIndex: token.zIndexPopupBase + 10,
  139. padding: 0,
  140. color: token.modalCloseColor,
  141. fontWeight: token.fontWeightStrong,
  142. lineHeight: 1,
  143. textDecoration: 'none',
  144. background: 'transparent',
  145. borderRadius: token.borderRadiusSM,
  146. width: token.modalConfirmIconSize,
  147. height: token.modalConfirmIconSize,
  148. border: 0,
  149. outline: 0,
  150. cursor: 'pointer',
  151. transition: `color ${token.motionDurationMid}, background-color ${token.motionDurationMid}`,
  152. '&-x': {
  153. display: 'block',
  154. fontSize: token.fontSizeLG,
  155. fontStyle: 'normal',
  156. lineHeight: `${token.modalCloseBtnSize}px`,
  157. textAlign: 'center',
  158. textTransform: 'none',
  159. textRendering: 'auto'
  160. },
  161. '&:hover': {
  162. color: token.modalIconHoverColor,
  163. backgroundColor: token.wireframe ? 'transparent' : token.colorFillContent,
  164. textDecoration: 'none'
  165. },
  166. '&:active': {
  167. backgroundColor: token.wireframe ? 'transparent' : token.colorFillContentHover
  168. }
  169. }, (0, _style.genFocusStyle)(token)),
  170. [`${componentCls}-header`]: {
  171. color: token.colorText,
  172. background: token.modalHeaderBg,
  173. borderRadius: `${token.borderRadiusLG}px ${token.borderRadiusLG}px 0 0`,
  174. marginBottom: token.marginXS
  175. },
  176. [`${componentCls}-body`]: {
  177. fontSize: token.fontSize,
  178. lineHeight: token.lineHeight,
  179. wordWrap: 'break-word'
  180. },
  181. [`${componentCls}-footer`]: {
  182. textAlign: 'end',
  183. background: token.modalFooterBg,
  184. marginTop: token.marginSM,
  185. [`${token.antCls}-btn + ${token.antCls}-btn:not(${token.antCls}-dropdown-trigger)`]: {
  186. marginBottom: 0,
  187. marginInlineStart: token.marginXS
  188. }
  189. },
  190. [`${componentCls}-open`]: {
  191. overflow: 'hidden'
  192. }
  193. })
  194. },
  195. // ======================== Pure =========================
  196. {
  197. [`${componentCls}-pure-panel`]: {
  198. top: 'auto',
  199. padding: 0,
  200. display: 'flex',
  201. flexDirection: 'column',
  202. [`${componentCls}-content,
  203. ${componentCls}-body,
  204. ${componentCls}-confirm-body-wrapper`]: {
  205. display: 'flex',
  206. flexDirection: 'column',
  207. flex: 'auto'
  208. },
  209. [`${componentCls}-confirm-body`]: {
  210. marginBottom: 'auto'
  211. }
  212. }
  213. }];
  214. };
  215. const genModalConfirmStyle = token => {
  216. const {
  217. componentCls
  218. } = token;
  219. const confirmComponentCls = `${componentCls}-confirm`;
  220. return {
  221. [confirmComponentCls]: {
  222. '&-rtl': {
  223. direction: 'rtl'
  224. },
  225. [`${token.antCls}-modal-header`]: {
  226. display: 'none'
  227. },
  228. [`${confirmComponentCls}-body-wrapper`]: (0, _extends2.default)({}, (0, _style.clearFix)()),
  229. [`${confirmComponentCls}-body`]: {
  230. display: 'flex',
  231. flexWrap: 'wrap',
  232. alignItems: 'center',
  233. [`${confirmComponentCls}-title`]: {
  234. flex: '0 0 100%',
  235. display: 'block',
  236. // create BFC to avoid
  237. // https://user-images.githubusercontent.com/507615/37702510-ba844e06-2d2d-11e8-9b67-8e19be57f445.png
  238. overflow: 'hidden',
  239. color: token.colorTextHeading,
  240. fontWeight: token.fontWeightStrong,
  241. fontSize: token.modalHeaderTitleFontSize,
  242. lineHeight: token.modalHeaderTitleLineHeight,
  243. [`+ ${confirmComponentCls}-content`]: {
  244. marginBlockStart: token.marginXS,
  245. flexBasis: '100%',
  246. maxWidth: `calc(100% - ${token.modalConfirmIconSize + token.marginSM}px)`
  247. }
  248. },
  249. [`${confirmComponentCls}-content`]: {
  250. color: token.colorText,
  251. fontSize: token.fontSize
  252. },
  253. [`> ${token.iconCls}`]: {
  254. flex: 'none',
  255. marginInlineEnd: token.marginSM,
  256. fontSize: token.modalConfirmIconSize,
  257. [`+ ${confirmComponentCls}-title`]: {
  258. flex: 1
  259. },
  260. // `content` after `icon` should set marginLeft
  261. [`+ ${confirmComponentCls}-title + ${confirmComponentCls}-content`]: {
  262. marginInlineStart: token.modalConfirmIconSize + token.marginSM
  263. }
  264. }
  265. },
  266. [`${confirmComponentCls}-btns`]: {
  267. textAlign: 'end',
  268. marginTop: token.marginSM,
  269. [`${token.antCls}-btn + ${token.antCls}-btn`]: {
  270. marginBottom: 0,
  271. marginInlineStart: token.marginXS
  272. }
  273. }
  274. },
  275. [`${confirmComponentCls}-error ${confirmComponentCls}-body > ${token.iconCls}`]: {
  276. color: token.colorError
  277. },
  278. [`${confirmComponentCls}-warning ${confirmComponentCls}-body > ${token.iconCls},
  279. ${confirmComponentCls}-confirm ${confirmComponentCls}-body > ${token.iconCls}`]: {
  280. color: token.colorWarning
  281. },
  282. [`${confirmComponentCls}-info ${confirmComponentCls}-body > ${token.iconCls}`]: {
  283. color: token.colorInfo
  284. },
  285. [`${confirmComponentCls}-success ${confirmComponentCls}-body > ${token.iconCls}`]: {
  286. color: token.colorSuccess
  287. },
  288. // https://github.com/ant-design/ant-design/issues/37329
  289. [`${componentCls}-zoom-leave ${componentCls}-btns`]: {
  290. pointerEvents: 'none'
  291. }
  292. };
  293. };
  294. const genRTLStyle = token => {
  295. const {
  296. componentCls
  297. } = token;
  298. return {
  299. [`${componentCls}-root`]: {
  300. [`${componentCls}-wrap-rtl`]: {
  301. direction: 'rtl',
  302. [`${componentCls}-confirm-body`]: {
  303. direction: 'rtl'
  304. }
  305. }
  306. }
  307. };
  308. };
  309. const genWireframeStyle = token => {
  310. const {
  311. componentCls,
  312. antCls
  313. } = token;
  314. const confirmComponentCls = `${componentCls}-confirm`;
  315. return {
  316. [componentCls]: {
  317. [`${componentCls}-content`]: {
  318. padding: 0
  319. },
  320. [`${componentCls}-header`]: {
  321. padding: token.modalHeaderPadding,
  322. borderBottom: `${token.modalHeaderBorderWidth}px ${token.modalHeaderBorderStyle} ${token.modalHeaderBorderColorSplit}`,
  323. marginBottom: 0
  324. },
  325. [`${componentCls}-body`]: {
  326. padding: token.modalBodyPadding
  327. },
  328. [`${componentCls}-footer`]: {
  329. padding: `${token.modalFooterPaddingVertical}px ${token.modalFooterPaddingHorizontal}px`,
  330. borderTop: `${token.modalFooterBorderWidth}px ${token.modalFooterBorderStyle} ${token.modalFooterBorderColorSplit}`,
  331. borderRadius: `0 0 ${token.borderRadiusLG}px ${token.borderRadiusLG}px`,
  332. marginTop: 0
  333. }
  334. },
  335. [confirmComponentCls]: {
  336. [`${antCls}-modal-body`]: {
  337. padding: `${token.padding * 2}px ${token.padding * 2}px ${token.paddingLG}px`
  338. },
  339. [`${confirmComponentCls}-body`]: {
  340. [`> ${token.iconCls}`]: {
  341. marginInlineEnd: token.margin,
  342. // `content` after `icon` should set marginLeft
  343. [`+ ${confirmComponentCls}-title + ${confirmComponentCls}-content`]: {
  344. marginInlineStart: token.modalConfirmIconSize + token.margin
  345. }
  346. }
  347. },
  348. [`${confirmComponentCls}-btns`]: {
  349. marginTop: token.marginLG
  350. }
  351. }
  352. };
  353. };
  354. // ============================== Export ==============================
  355. var _default = exports.default = (0, _internal.genComponentStyleHook)('Modal', token => {
  356. const headerPaddingVertical = token.padding;
  357. const headerFontSize = token.fontSizeHeading5;
  358. const headerLineHeight = token.lineHeightHeading5;
  359. const modalToken = (0, _internal.mergeToken)(token, {
  360. modalBodyPadding: token.paddingLG,
  361. modalHeaderBg: token.colorBgElevated,
  362. modalHeaderPadding: `${headerPaddingVertical}px ${token.paddingLG}px`,
  363. modalHeaderBorderWidth: token.lineWidth,
  364. modalHeaderBorderStyle: token.lineType,
  365. modalHeaderTitleLineHeight: headerLineHeight,
  366. modalHeaderTitleFontSize: headerFontSize,
  367. modalHeaderBorderColorSplit: token.colorSplit,
  368. modalHeaderCloseSize: headerLineHeight * headerFontSize + headerPaddingVertical * 2,
  369. modalContentBg: token.colorBgElevated,
  370. modalHeadingColor: token.colorTextHeading,
  371. modalCloseColor: token.colorTextDescription,
  372. modalFooterBg: 'transparent',
  373. modalFooterBorderColorSplit: token.colorSplit,
  374. modalFooterBorderStyle: token.lineType,
  375. modalFooterPaddingVertical: token.paddingXS,
  376. modalFooterPaddingHorizontal: token.padding,
  377. modalFooterBorderWidth: token.lineWidth,
  378. modalConfirmTitleFontSize: token.fontSizeLG,
  379. modalIconHoverColor: token.colorIconHover,
  380. modalConfirmIconSize: token.fontSize * token.lineHeight,
  381. modalCloseBtnSize: token.controlHeightLG * 0.55
  382. });
  383. return [genModalStyle(modalToken), genModalConfirmStyle(modalToken), genRTLStyle(modalToken), genModalMaskStyle(modalToken), token.wireframe && genWireframeStyle(modalToken), (0, _motion.initZoomMotion)(modalToken, 'zoom')];
  384. });