index.js 4.0 KB

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