index.js 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. import _extends from "@babel/runtime/helpers/esm/extends";
  2. import { genComponentStyleHook, mergeToken } from '../../theme/internal';
  3. import { resetComponent } from '../../style';
  4. const genAlertTypeStyle = (bgColor, borderColor, iconColor, token, alertCls) => ({
  5. backgroundColor: bgColor,
  6. border: `${token.lineWidth}px ${token.lineType} ${borderColor}`,
  7. [`${alertCls}-icon`]: {
  8. color: iconColor
  9. }
  10. });
  11. export const genBaseStyle = token => {
  12. const {
  13. componentCls,
  14. motionDurationSlow: duration,
  15. marginXS,
  16. marginSM,
  17. fontSize,
  18. fontSizeLG,
  19. lineHeight,
  20. borderRadiusLG: borderRadius,
  21. motionEaseInOutCirc,
  22. alertIconSizeLG,
  23. colorText,
  24. paddingContentVerticalSM,
  25. alertPaddingHorizontal,
  26. paddingMD,
  27. paddingContentHorizontalLG
  28. } = token;
  29. return {
  30. [componentCls]: _extends(_extends({}, resetComponent(token)), {
  31. position: 'relative',
  32. display: 'flex',
  33. alignItems: 'center',
  34. padding: `${paddingContentVerticalSM}px ${alertPaddingHorizontal}px`,
  35. wordWrap: 'break-word',
  36. borderRadius,
  37. [`&${componentCls}-rtl`]: {
  38. direction: 'rtl'
  39. },
  40. [`${componentCls}-content`]: {
  41. flex: 1,
  42. minWidth: 0
  43. },
  44. [`${componentCls}-icon`]: {
  45. marginInlineEnd: marginXS,
  46. lineHeight: 0
  47. },
  48. [`&-description`]: {
  49. display: 'none',
  50. fontSize,
  51. lineHeight
  52. },
  53. '&-message': {
  54. color: colorText
  55. },
  56. [`&${componentCls}-motion-leave`]: {
  57. overflow: 'hidden',
  58. opacity: 1,
  59. transition: `max-height ${duration} ${motionEaseInOutCirc}, opacity ${duration} ${motionEaseInOutCirc},
  60. padding-top ${duration} ${motionEaseInOutCirc}, padding-bottom ${duration} ${motionEaseInOutCirc},
  61. margin-bottom ${duration} ${motionEaseInOutCirc}`
  62. },
  63. [`&${componentCls}-motion-leave-active`]: {
  64. maxHeight: 0,
  65. marginBottom: '0 !important',
  66. paddingTop: 0,
  67. paddingBottom: 0,
  68. opacity: 0
  69. }
  70. }),
  71. [`${componentCls}-with-description`]: {
  72. alignItems: 'flex-start',
  73. paddingInline: paddingContentHorizontalLG,
  74. paddingBlock: paddingMD,
  75. [`${componentCls}-icon`]: {
  76. marginInlineEnd: marginSM,
  77. fontSize: alertIconSizeLG,
  78. lineHeight: 0
  79. },
  80. [`${componentCls}-message`]: {
  81. display: 'block',
  82. marginBottom: marginXS,
  83. color: colorText,
  84. fontSize: fontSizeLG
  85. },
  86. [`${componentCls}-description`]: {
  87. display: 'block'
  88. }
  89. },
  90. [`${componentCls}-banner`]: {
  91. marginBottom: 0,
  92. border: '0 !important',
  93. borderRadius: 0
  94. }
  95. };
  96. };
  97. export const genTypeStyle = token => {
  98. const {
  99. componentCls,
  100. colorSuccess,
  101. colorSuccessBorder,
  102. colorSuccessBg,
  103. colorWarning,
  104. colorWarningBorder,
  105. colorWarningBg,
  106. colorError,
  107. colorErrorBorder,
  108. colorErrorBg,
  109. colorInfo,
  110. colorInfoBorder,
  111. colorInfoBg
  112. } = token;
  113. return {
  114. [componentCls]: {
  115. '&-success': genAlertTypeStyle(colorSuccessBg, colorSuccessBorder, colorSuccess, token, componentCls),
  116. '&-info': genAlertTypeStyle(colorInfoBg, colorInfoBorder, colorInfo, token, componentCls),
  117. '&-warning': genAlertTypeStyle(colorWarningBg, colorWarningBorder, colorWarning, token, componentCls),
  118. '&-error': _extends(_extends({}, genAlertTypeStyle(colorErrorBg, colorErrorBorder, colorError, token, componentCls)), {
  119. [`${componentCls}-description > pre`]: {
  120. margin: 0,
  121. padding: 0
  122. }
  123. })
  124. }
  125. };
  126. };
  127. export const genActionStyle = token => {
  128. const {
  129. componentCls,
  130. iconCls,
  131. motionDurationMid,
  132. marginXS,
  133. fontSizeIcon,
  134. colorIcon,
  135. colorIconHover
  136. } = token;
  137. return {
  138. [componentCls]: {
  139. [`&-action`]: {
  140. marginInlineStart: marginXS
  141. },
  142. [`${componentCls}-close-icon`]: {
  143. marginInlineStart: marginXS,
  144. padding: 0,
  145. overflow: 'hidden',
  146. fontSize: fontSizeIcon,
  147. lineHeight: `${fontSizeIcon}px`,
  148. backgroundColor: 'transparent',
  149. border: 'none',
  150. outline: 'none',
  151. cursor: 'pointer',
  152. [`${iconCls}-close`]: {
  153. color: colorIcon,
  154. transition: `color ${motionDurationMid}`,
  155. '&:hover': {
  156. color: colorIconHover
  157. }
  158. }
  159. },
  160. '&-close-text': {
  161. color: colorIcon,
  162. transition: `color ${motionDurationMid}`,
  163. '&:hover': {
  164. color: colorIconHover
  165. }
  166. }
  167. }
  168. };
  169. };
  170. export const genAlertStyle = token => [genBaseStyle(token), genTypeStyle(token), genActionStyle(token)];
  171. export default genComponentStyleHook('Alert', token => {
  172. const {
  173. fontSizeHeading3
  174. } = token;
  175. const alertToken = mergeToken(token, {
  176. alertIconSizeLG: fontSizeHeading3,
  177. alertPaddingHorizontal: 12 // Fixed value here.
  178. });
  179. return [genAlertStyle(alertToken)];
  180. });