index.js 5.4 KB

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