index.js 6.9 KB

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