index.js 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. import { Keyframes } from '@ant-design/cssinjs';
  2. import { CONTAINER_MAX_OFFSET } from '../../_util/hooks/useZIndex';
  3. import { resetComponent } from '../../style';
  4. import { genStyleHooks, mergeToken } from '../../theme/internal';
  5. const genMessageStyle = token => {
  6. const {
  7. componentCls,
  8. iconCls,
  9. boxShadow,
  10. colorText,
  11. colorSuccess,
  12. colorError,
  13. colorWarning,
  14. colorInfo,
  15. fontSizeLG,
  16. motionEaseInOutCirc,
  17. motionDurationSlow,
  18. marginXS,
  19. paddingXS,
  20. borderRadiusLG,
  21. zIndexPopup,
  22. // Custom token
  23. contentPadding,
  24. contentBg
  25. } = token;
  26. const noticeCls = `${componentCls}-notice`;
  27. const messageMoveIn = new Keyframes('MessageMoveIn', {
  28. '0%': {
  29. padding: 0,
  30. transform: 'translateY(-100%)',
  31. opacity: 0
  32. },
  33. '100%': {
  34. padding: paddingXS,
  35. transform: 'translateY(0)',
  36. opacity: 1
  37. }
  38. });
  39. const messageMoveOut = new Keyframes('MessageMoveOut', {
  40. '0%': {
  41. maxHeight: token.height,
  42. padding: paddingXS,
  43. opacity: 1
  44. },
  45. '100%': {
  46. maxHeight: 0,
  47. padding: 0,
  48. opacity: 0
  49. }
  50. });
  51. const noticeStyle = {
  52. padding: paddingXS,
  53. textAlign: 'center',
  54. [`${componentCls}-custom-content`]: {
  55. display: 'flex',
  56. alignItems: 'center'
  57. },
  58. [`${componentCls}-custom-content > ${iconCls}`]: {
  59. marginInlineEnd: marginXS,
  60. // affected by ltr or rtl
  61. fontSize: fontSizeLG
  62. },
  63. [`${noticeCls}-content`]: {
  64. display: 'inline-block',
  65. padding: contentPadding,
  66. background: contentBg,
  67. borderRadius: borderRadiusLG,
  68. boxShadow,
  69. pointerEvents: 'all'
  70. },
  71. [`${componentCls}-success > ${iconCls}`]: {
  72. color: colorSuccess
  73. },
  74. [`${componentCls}-error > ${iconCls}`]: {
  75. color: colorError
  76. },
  77. [`${componentCls}-warning > ${iconCls}`]: {
  78. color: colorWarning
  79. },
  80. [`${componentCls}-info > ${iconCls},
  81. ${componentCls}-loading > ${iconCls}`]: {
  82. color: colorInfo
  83. }
  84. };
  85. return [
  86. // ============================ Holder ============================
  87. {
  88. [componentCls]: Object.assign(Object.assign({}, resetComponent(token)), {
  89. color: colorText,
  90. position: 'fixed',
  91. top: marginXS,
  92. width: '100%',
  93. pointerEvents: 'none',
  94. zIndex: zIndexPopup,
  95. [`${componentCls}-move-up`]: {
  96. animationFillMode: 'forwards'
  97. },
  98. [`
  99. ${componentCls}-move-up-appear,
  100. ${componentCls}-move-up-enter
  101. `]: {
  102. animationName: messageMoveIn,
  103. animationDuration: motionDurationSlow,
  104. animationPlayState: 'paused',
  105. animationTimingFunction: motionEaseInOutCirc
  106. },
  107. [`
  108. ${componentCls}-move-up-appear${componentCls}-move-up-appear-active,
  109. ${componentCls}-move-up-enter${componentCls}-move-up-enter-active
  110. `]: {
  111. animationPlayState: 'running'
  112. },
  113. [`${componentCls}-move-up-leave`]: {
  114. animationName: messageMoveOut,
  115. animationDuration: motionDurationSlow,
  116. animationPlayState: 'paused',
  117. animationTimingFunction: motionEaseInOutCirc
  118. },
  119. [`${componentCls}-move-up-leave${componentCls}-move-up-leave-active`]: {
  120. animationPlayState: 'running'
  121. },
  122. '&-rtl': {
  123. direction: 'rtl',
  124. span: {
  125. direction: 'rtl'
  126. }
  127. }
  128. })
  129. },
  130. // ============================ Notice ============================
  131. {
  132. [componentCls]: {
  133. [`${noticeCls}-wrapper`]: Object.assign({}, noticeStyle)
  134. }
  135. },
  136. // ============================= Pure =============================
  137. {
  138. [`${componentCls}-notice-pure-panel`]: Object.assign(Object.assign({}, noticeStyle), {
  139. padding: 0,
  140. textAlign: 'start'
  141. })
  142. }];
  143. };
  144. export const prepareComponentToken = token => ({
  145. zIndexPopup: token.zIndexPopupBase + CONTAINER_MAX_OFFSET + 10,
  146. contentBg: token.colorBgElevated,
  147. contentPadding: `${(token.controlHeightLG - token.fontSize * token.lineHeight) / 2}px ${token.paddingSM}px`
  148. });
  149. // ============================== Export ==============================
  150. export default genStyleHooks('Message', token => {
  151. // Gen-style functions here
  152. const combinedToken = mergeToken(token, {
  153. height: 150
  154. });
  155. return genMessageStyle(combinedToken);
  156. }, prepareComponentToken);