index.js 5.3 KB

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