index.js 4.9 KB

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