index.js 7.2 KB

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