index.js 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  1. "use strict";
  2. var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
  3. Object.defineProperty(exports, "__esModule", {
  4. value: true
  5. });
  6. exports.prepareNotificationToken = exports.prepareComponentToken = exports.genNoticeStyle = exports.default = void 0;
  7. var _cssinjs = require("@ant-design/cssinjs");
  8. var _useZIndex = require("../../_util/hooks/useZIndex");
  9. var _style = require("../../style");
  10. var _internal = require("../../theme/internal");
  11. var _placement = _interopRequireDefault(require("./placement"));
  12. var _stack = _interopRequireDefault(require("./stack"));
  13. const genNoticeStyle = token => {
  14. const {
  15. iconCls,
  16. componentCls,
  17. // .ant-notification
  18. boxShadow,
  19. fontSizeLG,
  20. notificationMarginBottom,
  21. borderRadiusLG,
  22. colorSuccess,
  23. colorInfo,
  24. colorWarning,
  25. colorError,
  26. colorTextHeading,
  27. notificationBg,
  28. notificationPadding,
  29. notificationMarginEdge,
  30. notificationProgressBg,
  31. notificationProgressHeight,
  32. fontSize,
  33. lineHeight,
  34. width,
  35. notificationIconSize,
  36. colorText
  37. } = token;
  38. const noticeCls = `${componentCls}-notice`;
  39. return {
  40. position: 'relative',
  41. marginBottom: notificationMarginBottom,
  42. marginInlineStart: 'auto',
  43. background: notificationBg,
  44. borderRadius: borderRadiusLG,
  45. boxShadow,
  46. [noticeCls]: {
  47. padding: notificationPadding,
  48. width,
  49. maxWidth: `calc(100vw - ${(0, _cssinjs.unit)(token.calc(notificationMarginEdge).mul(2).equal())})`,
  50. overflow: 'hidden',
  51. lineHeight,
  52. wordWrap: 'break-word'
  53. },
  54. [`${noticeCls}-message`]: {
  55. color: colorTextHeading,
  56. fontSize: fontSizeLG,
  57. lineHeight: token.lineHeightLG
  58. },
  59. [`${noticeCls}-description`]: {
  60. fontSize,
  61. color: colorText,
  62. marginTop: token.marginXS
  63. },
  64. [`${noticeCls}-closable ${noticeCls}-message`]: {
  65. paddingInlineEnd: token.paddingLG
  66. },
  67. [`${noticeCls}-with-icon ${noticeCls}-message`]: {
  68. marginInlineStart: token.calc(token.marginSM).add(notificationIconSize).equal(),
  69. fontSize: fontSizeLG
  70. },
  71. [`${noticeCls}-with-icon ${noticeCls}-description`]: {
  72. marginInlineStart: token.calc(token.marginSM).add(notificationIconSize).equal(),
  73. fontSize
  74. },
  75. // Icon & color style in different selector level
  76. // https://github.com/ant-design/ant-design/issues/16503
  77. // https://github.com/ant-design/ant-design/issues/15512
  78. [`${noticeCls}-icon`]: {
  79. position: 'absolute',
  80. fontSize: notificationIconSize,
  81. lineHeight: 1,
  82. // icon-font
  83. [`&-success${iconCls}`]: {
  84. color: colorSuccess
  85. },
  86. [`&-info${iconCls}`]: {
  87. color: colorInfo
  88. },
  89. [`&-warning${iconCls}`]: {
  90. color: colorWarning
  91. },
  92. [`&-error${iconCls}`]: {
  93. color: colorError
  94. }
  95. },
  96. [`${noticeCls}-close`]: Object.assign({
  97. position: 'absolute',
  98. top: token.notificationPaddingVertical,
  99. insetInlineEnd: token.notificationPaddingHorizontal,
  100. color: token.colorIcon,
  101. outline: 'none',
  102. width: token.notificationCloseButtonSize,
  103. height: token.notificationCloseButtonSize,
  104. borderRadius: token.borderRadiusSM,
  105. transition: `background-color ${token.motionDurationMid}, color ${token.motionDurationMid}`,
  106. display: 'flex',
  107. alignItems: 'center',
  108. justifyContent: 'center',
  109. background: 'none',
  110. border: 'none',
  111. '&:hover': {
  112. color: token.colorIconHover,
  113. backgroundColor: token.colorBgTextHover
  114. },
  115. '&:active': {
  116. backgroundColor: token.colorBgTextActive
  117. }
  118. }, (0, _style.genFocusStyle)(token)),
  119. [`${noticeCls}-progress`]: {
  120. position: 'absolute',
  121. display: 'block',
  122. appearance: 'none',
  123. inlineSize: `calc(100% - ${(0, _cssinjs.unit)(borderRadiusLG)} * 2)`,
  124. left: {
  125. _skip_check_: true,
  126. value: borderRadiusLG
  127. },
  128. right: {
  129. _skip_check_: true,
  130. value: borderRadiusLG
  131. },
  132. bottom: 0,
  133. blockSize: notificationProgressHeight,
  134. border: 0,
  135. '&, &::-webkit-progress-bar': {
  136. borderRadius: borderRadiusLG,
  137. backgroundColor: `rgba(0, 0, 0, 0.04)`
  138. },
  139. '&::-moz-progress-bar': {
  140. background: notificationProgressBg
  141. },
  142. '&::-webkit-progress-value': {
  143. borderRadius: borderRadiusLG,
  144. background: notificationProgressBg
  145. }
  146. },
  147. [`${noticeCls}-actions`]: {
  148. float: 'right',
  149. marginTop: token.marginSM
  150. }
  151. };
  152. };
  153. exports.genNoticeStyle = genNoticeStyle;
  154. const genNotificationStyle = token => {
  155. const {
  156. componentCls,
  157. // .ant-notification
  158. notificationMarginBottom,
  159. notificationMarginEdge,
  160. motionDurationMid,
  161. motionEaseInOut
  162. } = token;
  163. const noticeCls = `${componentCls}-notice`;
  164. const fadeOut = new _cssinjs.Keyframes('antNotificationFadeOut', {
  165. '0%': {
  166. maxHeight: token.animationMaxHeight,
  167. marginBottom: notificationMarginBottom
  168. },
  169. '100%': {
  170. maxHeight: 0,
  171. marginBottom: 0,
  172. paddingTop: 0,
  173. paddingBottom: 0,
  174. opacity: 0
  175. }
  176. });
  177. return [
  178. // ============================ Holder ============================
  179. {
  180. [componentCls]: Object.assign(Object.assign({}, (0, _style.resetComponent)(token)), {
  181. position: 'fixed',
  182. zIndex: token.zIndexPopup,
  183. marginRight: {
  184. value: notificationMarginEdge,
  185. _skip_check_: true
  186. },
  187. [`${componentCls}-hook-holder`]: {
  188. position: 'relative'
  189. },
  190. // animation
  191. [`${componentCls}-fade-appear-prepare`]: {
  192. opacity: '0 !important'
  193. },
  194. [`${componentCls}-fade-enter, ${componentCls}-fade-appear`]: {
  195. animationDuration: token.motionDurationMid,
  196. animationTimingFunction: motionEaseInOut,
  197. animationFillMode: 'both',
  198. opacity: 0,
  199. animationPlayState: 'paused'
  200. },
  201. [`${componentCls}-fade-leave`]: {
  202. animationTimingFunction: motionEaseInOut,
  203. animationFillMode: 'both',
  204. animationDuration: motionDurationMid,
  205. animationPlayState: 'paused'
  206. },
  207. [`${componentCls}-fade-enter${componentCls}-fade-enter-active, ${componentCls}-fade-appear${componentCls}-fade-appear-active`]: {
  208. animationPlayState: 'running'
  209. },
  210. [`${componentCls}-fade-leave${componentCls}-fade-leave-active`]: {
  211. animationName: fadeOut,
  212. animationPlayState: 'running'
  213. },
  214. // RTL
  215. '&-rtl': {
  216. direction: 'rtl',
  217. [`${noticeCls}-actions`]: {
  218. float: 'left'
  219. }
  220. }
  221. })
  222. },
  223. // ============================ Notice ============================
  224. {
  225. [componentCls]: {
  226. [`${noticeCls}-wrapper`]: Object.assign({}, genNoticeStyle(token))
  227. }
  228. }];
  229. };
  230. // ============================== Export ==============================
  231. const prepareComponentToken = token => ({
  232. zIndexPopup: token.zIndexPopupBase + _useZIndex.CONTAINER_MAX_OFFSET + 50,
  233. width: 384
  234. });
  235. exports.prepareComponentToken = prepareComponentToken;
  236. const prepareNotificationToken = token => {
  237. const notificationPaddingVertical = token.paddingMD;
  238. const notificationPaddingHorizontal = token.paddingLG;
  239. const notificationToken = (0, _internal.mergeToken)(token, {
  240. notificationBg: token.colorBgElevated,
  241. notificationPaddingVertical,
  242. notificationPaddingHorizontal,
  243. notificationIconSize: token.calc(token.fontSizeLG).mul(token.lineHeightLG).equal(),
  244. notificationCloseButtonSize: token.calc(token.controlHeightLG).mul(0.55).equal(),
  245. notificationMarginBottom: token.margin,
  246. notificationPadding: `${(0, _cssinjs.unit)(token.paddingMD)} ${(0, _cssinjs.unit)(token.paddingContentHorizontalLG)}`,
  247. notificationMarginEdge: token.marginLG,
  248. animationMaxHeight: 150,
  249. notificationStackLayer: 3,
  250. notificationProgressHeight: 2,
  251. notificationProgressBg: `linear-gradient(90deg, ${token.colorPrimaryBorderHover}, ${token.colorPrimary})`
  252. });
  253. return notificationToken;
  254. };
  255. exports.prepareNotificationToken = prepareNotificationToken;
  256. var _default = exports.default = (0, _internal.genStyleHooks)('Notification', token => {
  257. const notificationToken = prepareNotificationToken(token);
  258. return [genNotificationStyle(notificationToken), (0, _placement.default)(notificationToken), (0, _stack.default)(notificationToken)];
  259. }, prepareComponentToken);