import type { CSSInterpolation, CSSObject } from '@ant-design/cssinjs'; import type { FullToken, GenerateStyle } from '../../theme'; import { genComponentStyleHook, mergeToken } from '../../theme'; import { resetComponent } from '../../style'; export interface ComponentToken {} type AlertToken = FullToken<'Alert'> & { alertIconSizeLG: number; }; const genAlertTypeStyle = ( bgColor: string, borderColor: string, iconColor: string, token: AlertToken, alertCls: string, ): CSSObject => ({ backgroundColor: bgColor, border: `${token.controlLineWidth}px ${token.controlLineType} ${borderColor}`, [`${alertCls}-icon`]: { color: iconColor, }, }); export const genBaseStyle: GenerateStyle = (token: AlertToken): CSSObject => { const { componentCls, motionDurationSlow: duration, marginXS, marginSM, fontSize, fontSizeLG, lineHeight, radiusLG: borderRadius, motionEaseInOutCirc, alertIconSizeLG, colorText, paddingSM, paddingXS, paddingTmp, paddingLG, } = token; return { [componentCls]: { ...resetComponent(token), position: 'relative', display: 'flex', alignItems: 'center', padding: `${paddingXS}px ${paddingSM}px`, wordWrap: 'break-word', borderRadius, '&&-rtl': { direction: 'rtl', }, [`${componentCls}-content`]: { flex: 1, minWidth: 0, }, [`${componentCls}-icon`]: { marginInlineEnd: marginXS, lineHeight: 0, }, [`&-description`]: { display: 'none', fontSize, lineHeight, }, '&-message': { color: colorText, }, '&&-motion-leave': { overflow: 'hidden', opacity: 1, transition: `max-height ${duration} ${motionEaseInOutCirc}, opacity ${duration} ${motionEaseInOutCirc}, padding-top ${duration} ${motionEaseInOutCirc}, padding-bottom ${duration} ${motionEaseInOutCirc}, margin-bottom ${duration} ${motionEaseInOutCirc}`, }, '&&-motion-leave-active': { maxHeight: 0, marginBottom: '0 !important', paddingTop: 0, paddingBottom: 0, opacity: 0, }, }, [`${componentCls}-with-description`]: { alignItems: 'flex-start', paddingInline: paddingLG, paddingBlock: paddingTmp, [`${componentCls}-icon`]: { marginInlineEnd: marginSM, fontSize: alertIconSizeLG, lineHeight: 0, }, [`${componentCls}-message`]: { display: 'block', marginBottom: marginXS, color: colorText, fontSize: fontSizeLG, }, [`${componentCls}-description`]: { display: 'block', }, }, [`${componentCls}-banner`]: { marginBottom: 0, border: '0 !important', borderRadius: 0, }, }; }; export const genTypeStyle: GenerateStyle = (token: AlertToken): CSSObject => { const { componentCls, colorSuccess, colorSuccessBorder, colorSuccessBg, colorWarning, colorWarningBorder, colorWarningBg, colorError, colorErrorBorder, colorErrorBg, colorInfo, colorInfoBorder, colorInfoBg, } = token; return { [componentCls]: { '&-success': genAlertTypeStyle( colorSuccessBg, colorSuccessBorder, colorSuccess, token, componentCls, ), '&-info': genAlertTypeStyle(colorInfoBg, colorInfoBorder, colorInfo, token, componentCls), '&-warning': genAlertTypeStyle( colorWarningBg, colorWarningBorder, colorWarning, token, componentCls, ), '&-error': { ...genAlertTypeStyle(colorErrorBg, colorErrorBorder, colorError, token, componentCls), [`${componentCls}-description > pre`]: { margin: 0, padding: 0, }, }, }, }; }; export const genActionStyle: GenerateStyle = (token: AlertToken): CSSObject => { const { componentCls, iconCls, motionDurationSlow: duration, marginXS, fontSizeIcon, colorIcon, colorIconHover, } = token; return { [componentCls]: { [`&-action`]: { marginInlineStart: marginXS, }, [`${componentCls}-close-icon`]: { marginInlineStart: marginXS, padding: 0, overflow: 'hidden', fontSize: fontSizeIcon, lineHeight: `${fontSizeIcon}px`, backgroundColor: 'transparent', border: 'none', outline: 'none', cursor: 'pointer', [`${iconCls}-close`]: { color: colorIcon, transition: `color ${duration}`, '&:hover': { color: colorIconHover, }, }, }, '&-close-text': { color: colorIcon, transition: `color ${duration}`, '&:hover': { color: colorIconHover, }, }, }, }; }; export const genAlertStyle: GenerateStyle = (token: AlertToken): CSSInterpolation => [ genBaseStyle(token), genTypeStyle(token), genActionStyle(token), ]; export default genComponentStyleHook('Alert', token => { const { fontSizeHeading3 } = token; const alertToken = mergeToken(token, { alertIconSizeLG: fontSizeHeading3, }); return [genAlertStyle(alertToken)]; });