2022-05-09 22:20:07 +08:00
|
|
|
import type { CSSInterpolation, CSSObject } from '@ant-design/cssinjs';
|
2022-06-27 14:25:59 +08:00
|
|
|
import type { FullToken, GenerateStyle } from '../../theme';
|
2022-07-11 15:35:58 +08:00
|
|
|
import { genComponentStyleHook, mergeToken } from '../../theme';
|
|
|
|
import { resetComponent } from '../../style';
|
2022-03-04 19:09:55 +08:00
|
|
|
|
2022-05-24 15:45:41 +08:00
|
|
|
export interface ComponentToken {}
|
2022-03-04 19:09:55 +08:00
|
|
|
|
2022-04-07 21:29:50 +08:00
|
|
|
type AlertToken = FullToken<'Alert'> & {
|
2022-05-24 15:45:41 +08:00
|
|
|
alertIconSizeLG: number;
|
2022-10-25 17:04:36 +08:00
|
|
|
alertPaddingHorizontal: number;
|
2022-03-08 10:29:00 +08:00
|
|
|
};
|
2022-03-04 19:09:55 +08:00
|
|
|
|
2022-03-08 10:29:00 +08:00
|
|
|
const genAlertTypeStyle = (
|
|
|
|
bgColor: string,
|
|
|
|
borderColor: string,
|
|
|
|
iconColor: string,
|
|
|
|
token: AlertToken,
|
|
|
|
alertCls: string,
|
|
|
|
): CSSObject => ({
|
2022-03-04 19:09:55 +08:00
|
|
|
backgroundColor: bgColor,
|
2022-11-01 15:06:38 +08:00
|
|
|
border: `${token.lineWidth}px ${token.lineType} ${borderColor}`,
|
2022-03-04 19:09:55 +08:00
|
|
|
[`${alertCls}-icon`]: {
|
|
|
|
color: iconColor,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2022-03-11 14:29:29 +08:00
|
|
|
export const genBaseStyle: GenerateStyle<AlertToken> = (token: AlertToken): CSSObject => {
|
2022-03-04 19:09:55 +08:00
|
|
|
const {
|
2022-04-07 21:29:50 +08:00
|
|
|
componentCls,
|
2022-03-22 20:02:04 +08:00
|
|
|
motionDurationSlow: duration,
|
2022-03-04 19:09:55 +08:00
|
|
|
marginXS,
|
2022-08-29 17:09:41 +08:00
|
|
|
marginSM,
|
2022-03-04 19:09:55 +08:00
|
|
|
fontSize,
|
|
|
|
fontSizeLG,
|
2022-05-24 15:45:41 +08:00
|
|
|
lineHeight,
|
2022-11-01 15:06:38 +08:00
|
|
|
borderRadiusLG: borderRadius,
|
2022-03-22 09:37:37 +08:00
|
|
|
motionEaseInOutCirc,
|
2022-05-24 15:45:41 +08:00
|
|
|
alertIconSizeLG,
|
|
|
|
colorText,
|
2022-10-25 17:04:36 +08:00
|
|
|
paddingContentVerticalSM,
|
|
|
|
alertPaddingHorizontal,
|
|
|
|
paddingMD,
|
|
|
|
paddingContentHorizontalLG,
|
2022-03-04 19:09:55 +08:00
|
|
|
} = token;
|
|
|
|
|
|
|
|
return {
|
2022-04-07 21:29:50 +08:00
|
|
|
[componentCls]: {
|
2022-03-04 19:09:55 +08:00
|
|
|
...resetComponent(token),
|
|
|
|
position: 'relative',
|
|
|
|
display: 'flex',
|
|
|
|
alignItems: 'center',
|
2022-10-25 17:04:36 +08:00
|
|
|
padding: `${paddingContentVerticalSM}px ${alertPaddingHorizontal}px`, // Fixed horizontal padding here.
|
2022-03-04 19:09:55 +08:00
|
|
|
wordWrap: 'break-word',
|
|
|
|
borderRadius,
|
|
|
|
|
2022-03-11 17:07:16 +08:00
|
|
|
'&&-rtl': {
|
|
|
|
direction: 'rtl',
|
|
|
|
},
|
|
|
|
|
2022-04-07 21:29:50 +08:00
|
|
|
[`${componentCls}-content`]: {
|
2022-03-04 19:09:55 +08:00
|
|
|
flex: 1,
|
|
|
|
minWidth: 0,
|
|
|
|
},
|
|
|
|
|
2022-04-07 21:29:50 +08:00
|
|
|
[`${componentCls}-icon`]: {
|
2022-03-04 19:09:55 +08:00
|
|
|
marginInlineEnd: marginXS,
|
2022-08-29 19:06:55 +08:00
|
|
|
lineHeight: 0,
|
2022-03-04 19:09:55 +08:00
|
|
|
},
|
|
|
|
|
|
|
|
[`&-description`]: {
|
|
|
|
display: 'none',
|
|
|
|
fontSize,
|
2022-05-24 15:45:41 +08:00
|
|
|
lineHeight,
|
2022-03-04 19:09:55 +08:00
|
|
|
},
|
|
|
|
|
|
|
|
'&-message': {
|
2022-05-24 15:45:41 +08:00
|
|
|
color: colorText,
|
2022-03-04 19:09:55 +08:00
|
|
|
},
|
|
|
|
|
|
|
|
'&&-motion-leave': {
|
|
|
|
overflow: 'hidden',
|
|
|
|
opacity: 1,
|
2022-03-22 09:37:37 +08:00
|
|
|
transition: `max-height ${duration} ${motionEaseInOutCirc}, opacity ${duration} ${motionEaseInOutCirc},
|
|
|
|
padding-top ${duration} ${motionEaseInOutCirc}, padding-bottom ${duration} ${motionEaseInOutCirc},
|
|
|
|
margin-bottom ${duration} ${motionEaseInOutCirc}`,
|
2022-03-04 19:09:55 +08:00
|
|
|
},
|
|
|
|
|
|
|
|
'&&-motion-leave-active': {
|
|
|
|
maxHeight: 0,
|
|
|
|
marginBottom: '0 !important',
|
|
|
|
paddingTop: 0,
|
|
|
|
paddingBottom: 0,
|
|
|
|
opacity: 0,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
2022-04-07 21:29:50 +08:00
|
|
|
[`${componentCls}-with-description`]: {
|
2022-03-04 19:09:55 +08:00
|
|
|
alignItems: 'flex-start',
|
2022-10-25 17:04:36 +08:00
|
|
|
paddingInline: paddingContentHorizontalLG,
|
|
|
|
paddingBlock: paddingMD,
|
2022-03-04 19:09:55 +08:00
|
|
|
|
2022-04-07 21:29:50 +08:00
|
|
|
[`${componentCls}-icon`]: {
|
2022-08-29 17:09:41 +08:00
|
|
|
marginInlineEnd: marginSM,
|
2022-05-24 15:45:41 +08:00
|
|
|
fontSize: alertIconSizeLG,
|
2022-08-29 19:06:55 +08:00
|
|
|
lineHeight: 0,
|
2022-03-04 19:09:55 +08:00
|
|
|
},
|
|
|
|
|
2022-04-07 21:29:50 +08:00
|
|
|
[`${componentCls}-message`]: {
|
2022-03-04 19:09:55 +08:00
|
|
|
display: 'block',
|
2022-08-29 17:09:41 +08:00
|
|
|
marginBottom: marginXS,
|
2022-05-24 15:45:41 +08:00
|
|
|
color: colorText,
|
2022-03-04 19:09:55 +08:00
|
|
|
fontSize: fontSizeLG,
|
|
|
|
},
|
|
|
|
|
2022-04-07 21:29:50 +08:00
|
|
|
[`${componentCls}-description`]: {
|
2022-03-04 19:09:55 +08:00
|
|
|
display: 'block',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
2022-04-07 21:29:50 +08:00
|
|
|
[`${componentCls}-banner`]: {
|
2022-03-04 19:09:55 +08:00
|
|
|
marginBottom: 0,
|
|
|
|
border: '0 !important',
|
|
|
|
borderRadius: 0,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2022-03-11 14:29:29 +08:00
|
|
|
export const genTypeStyle: GenerateStyle<AlertToken> = (token: AlertToken): CSSObject => {
|
2022-03-04 19:09:55 +08:00
|
|
|
const {
|
2022-04-07 21:29:50 +08:00
|
|
|
componentCls,
|
2022-03-04 19:09:55 +08:00
|
|
|
|
2022-03-24 14:30:48 +08:00
|
|
|
colorSuccess,
|
2022-06-28 20:33:01 +08:00
|
|
|
colorSuccessBorder,
|
2022-06-24 11:11:42 +08:00
|
|
|
colorSuccessBg,
|
2022-03-24 14:30:48 +08:00
|
|
|
|
|
|
|
colorWarning,
|
2022-06-28 20:33:01 +08:00
|
|
|
colorWarningBorder,
|
2022-06-24 11:11:42 +08:00
|
|
|
colorWarningBg,
|
2022-03-04 19:09:55 +08:00
|
|
|
|
2022-03-24 14:30:48 +08:00
|
|
|
colorError,
|
2022-06-28 20:33:01 +08:00
|
|
|
colorErrorBorder,
|
2022-06-24 11:11:42 +08:00
|
|
|
colorErrorBg,
|
2022-03-04 19:09:55 +08:00
|
|
|
|
2022-03-24 14:30:48 +08:00
|
|
|
colorInfo,
|
2022-06-28 20:33:01 +08:00
|
|
|
colorInfoBorder,
|
2022-06-24 11:11:42 +08:00
|
|
|
colorInfoBg,
|
2022-03-04 19:09:55 +08:00
|
|
|
} = token;
|
|
|
|
|
|
|
|
return {
|
2022-04-07 21:29:50 +08:00
|
|
|
[componentCls]: {
|
2022-03-08 10:29:00 +08:00
|
|
|
'&-success': genAlertTypeStyle(
|
2022-06-24 11:11:42 +08:00
|
|
|
colorSuccessBg,
|
2022-06-28 20:33:01 +08:00
|
|
|
colorSuccessBorder,
|
2022-03-24 14:30:48 +08:00
|
|
|
colorSuccess,
|
2022-03-08 10:29:00 +08:00
|
|
|
token,
|
2022-04-07 21:29:50 +08:00
|
|
|
componentCls,
|
2022-03-08 10:29:00 +08:00
|
|
|
),
|
2022-06-28 20:33:01 +08:00
|
|
|
'&-info': genAlertTypeStyle(colorInfoBg, colorInfoBorder, colorInfo, token, componentCls),
|
2022-03-08 10:29:00 +08:00
|
|
|
'&-warning': genAlertTypeStyle(
|
2022-06-24 11:11:42 +08:00
|
|
|
colorWarningBg,
|
2022-06-28 20:33:01 +08:00
|
|
|
colorWarningBorder,
|
2022-03-24 14:30:48 +08:00
|
|
|
colorWarning,
|
2022-03-08 10:29:00 +08:00
|
|
|
token,
|
2022-04-07 21:29:50 +08:00
|
|
|
componentCls,
|
2022-03-08 10:29:00 +08:00
|
|
|
),
|
2022-03-04 19:09:55 +08:00
|
|
|
'&-error': {
|
2022-06-28 20:33:01 +08:00
|
|
|
...genAlertTypeStyle(colorErrorBg, colorErrorBorder, colorError, token, componentCls),
|
2022-04-07 21:29:50 +08:00
|
|
|
[`${componentCls}-description > pre`]: {
|
2022-03-04 19:09:55 +08:00
|
|
|
margin: 0,
|
|
|
|
padding: 0,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2022-03-11 14:29:29 +08:00
|
|
|
export const genActionStyle: GenerateStyle<AlertToken> = (token: AlertToken): CSSObject => {
|
|
|
|
const {
|
2022-04-07 21:29:50 +08:00
|
|
|
componentCls,
|
|
|
|
iconCls,
|
2022-09-07 14:08:14 +08:00
|
|
|
motionDurationFast,
|
2022-03-11 14:29:29 +08:00
|
|
|
marginXS,
|
2022-03-29 15:57:39 +08:00
|
|
|
fontSizeIcon,
|
2022-07-21 17:00:42 +08:00
|
|
|
colorIcon,
|
|
|
|
colorIconHover,
|
2022-03-11 14:29:29 +08:00
|
|
|
} = token;
|
2022-03-04 19:09:55 +08:00
|
|
|
|
|
|
|
return {
|
2022-04-07 21:29:50 +08:00
|
|
|
[componentCls]: {
|
2022-03-04 19:09:55 +08:00
|
|
|
[`&-action`]: {
|
|
|
|
marginInlineStart: marginXS,
|
|
|
|
},
|
|
|
|
|
2022-04-07 21:29:50 +08:00
|
|
|
[`${componentCls}-close-icon`]: {
|
2022-03-04 19:09:55 +08:00
|
|
|
marginInlineStart: marginXS,
|
|
|
|
padding: 0,
|
|
|
|
overflow: 'hidden',
|
2022-03-29 15:57:39 +08:00
|
|
|
fontSize: fontSizeIcon,
|
|
|
|
lineHeight: `${fontSizeIcon}px`,
|
2022-03-04 19:09:55 +08:00
|
|
|
backgroundColor: 'transparent',
|
|
|
|
border: 'none',
|
|
|
|
outline: 'none',
|
|
|
|
cursor: 'pointer',
|
|
|
|
|
2022-04-07 21:29:50 +08:00
|
|
|
[`${iconCls}-close`]: {
|
2022-07-21 17:00:42 +08:00
|
|
|
color: colorIcon,
|
2022-09-07 14:08:14 +08:00
|
|
|
transition: `color ${motionDurationFast}`,
|
2022-03-04 19:09:55 +08:00
|
|
|
'&:hover': {
|
2022-07-21 17:00:42 +08:00
|
|
|
color: colorIconHover,
|
2022-03-04 19:09:55 +08:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
'&-close-text': {
|
2022-07-21 17:00:42 +08:00
|
|
|
color: colorIcon,
|
2022-09-07 14:08:14 +08:00
|
|
|
transition: `color ${motionDurationFast}`,
|
2022-03-04 19:09:55 +08:00
|
|
|
'&:hover': {
|
2022-07-21 17:00:42 +08:00
|
|
|
color: colorIconHover,
|
2022-03-04 19:09:55 +08:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2022-03-11 14:29:29 +08:00
|
|
|
export const genAlertStyle: GenerateStyle<AlertToken> = (token: AlertToken): CSSInterpolation => [
|
|
|
|
genBaseStyle(token),
|
|
|
|
genTypeStyle(token),
|
|
|
|
genActionStyle(token),
|
|
|
|
];
|
|
|
|
|
2022-04-07 21:29:50 +08:00
|
|
|
export default genComponentStyleHook('Alert', token => {
|
2022-08-29 17:09:41 +08:00
|
|
|
const { fontSizeHeading3 } = token;
|
2022-03-04 19:09:55 +08:00
|
|
|
|
2022-04-11 16:04:00 +08:00
|
|
|
const alertToken = mergeToken<AlertToken>(token, {
|
2022-05-24 15:45:41 +08:00
|
|
|
alertIconSizeLG: fontSizeHeading3,
|
2022-10-25 17:04:36 +08:00
|
|
|
alertPaddingHorizontal: 12, // Fixed value here.
|
2022-04-11 16:04:00 +08:00
|
|
|
});
|
2022-03-04 19:09:55 +08:00
|
|
|
|
2022-04-07 21:29:50 +08:00
|
|
|
return [genAlertStyle(alertToken)];
|
|
|
|
});
|