index.js 12 KB

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