2022-03-04 19:09:55 +08:00
|
|
|
// import '../../style/index.less';
|
|
|
|
// import './index.less';
|
|
|
|
|
|
|
|
// deps-lint-skip-all
|
|
|
|
import { CSSInterpolation, CSSObject } from '@ant-design/cssinjs';
|
|
|
|
|
2022-04-11 16:04:00 +08:00
|
|
|
import {
|
|
|
|
resetComponent,
|
|
|
|
GenerateStyle,
|
|
|
|
FullToken,
|
|
|
|
genComponentStyleHook,
|
|
|
|
mergeToken,
|
|
|
|
} from '../../_util/theme';
|
2022-03-04 19:09:55 +08:00
|
|
|
|
|
|
|
// FIXME: missing token
|
2022-04-07 21:29:50 +08:00
|
|
|
type AlertToken = FullToken<'Alert'> & {
|
2022-03-08 10:29:00 +08:00
|
|
|
alertMessageColor: string;
|
|
|
|
alertCloseColor: string;
|
|
|
|
alertCloseHoverColor: string;
|
|
|
|
alertWithDescriptionIconSize: number;
|
|
|
|
alertWithDescriptionPaddingVertical: number;
|
|
|
|
alertWithDescriptionNoIconPaddingVertical: number;
|
|
|
|
};
|
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-03-22 13:26:29 +08:00
|
|
|
border: `${token.controlLineWidth}px ${token.controlLineType} ${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,
|
|
|
|
fontSize,
|
|
|
|
fontSizeLG,
|
2022-03-22 13:26:29 +08:00
|
|
|
controlRadius: borderRadius,
|
2022-03-22 09:37:37 +08:00
|
|
|
motionEaseInOutCirc,
|
2022-03-04 19:09:55 +08:00
|
|
|
alertMessageColor,
|
|
|
|
alertWithDescriptionIconSize,
|
|
|
|
alertWithDescriptionPaddingVertical,
|
|
|
|
alertWithDescriptionNoIconPaddingVertical,
|
|
|
|
} = 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',
|
|
|
|
padding: '8px 15px',
|
|
|
|
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,
|
|
|
|
},
|
|
|
|
|
|
|
|
[`&-description`]: {
|
|
|
|
display: 'none',
|
|
|
|
fontSize,
|
|
|
|
lineHeight: `${fontSize + 8}px`,
|
|
|
|
},
|
|
|
|
|
|
|
|
'&-message': {
|
|
|
|
color: alertMessageColor,
|
|
|
|
},
|
|
|
|
|
|
|
|
'&&-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-03-11 17:07:16 +08:00
|
|
|
paddingInlineStart: alertWithDescriptionIconSize,
|
|
|
|
paddingInlineEnd: alertWithDescriptionPaddingVertical,
|
|
|
|
paddingBlock: alertWithDescriptionPaddingVertical,
|
2022-03-04 19:09:55 +08:00
|
|
|
|
2022-04-07 21:29:50 +08:00
|
|
|
[`&${componentCls}-no-icon`]: {
|
2022-03-04 19:09:55 +08:00
|
|
|
padding: `${alertWithDescriptionNoIconPaddingVertical}px 15px`,
|
|
|
|
},
|
|
|
|
|
2022-04-07 21:29:50 +08:00
|
|
|
[`${componentCls}-icon`]: {
|
2022-03-04 19:09:55 +08:00
|
|
|
marginInlineEnd: alertWithDescriptionPaddingVertical,
|
|
|
|
fontSize: alertWithDescriptionIconSize,
|
|
|
|
},
|
|
|
|
|
2022-04-07 21:29:50 +08:00
|
|
|
[`${componentCls}-message`]: {
|
2022-03-04 19:09:55 +08:00
|
|
|
display: 'block',
|
|
|
|
marginBottom: '4px',
|
|
|
|
color: alertMessageColor,
|
|
|
|
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,
|
|
|
|
colorSuccessSecondary,
|
|
|
|
colorBgSuccess,
|
|
|
|
|
|
|
|
colorWarning,
|
|
|
|
colorWarningSecondary,
|
|
|
|
colorBgWarning,
|
2022-03-04 19:09:55 +08:00
|
|
|
|
2022-03-24 14:30:48 +08:00
|
|
|
colorError,
|
|
|
|
colorErrorSecondary,
|
|
|
|
colorBgError,
|
2022-03-04 19:09:55 +08:00
|
|
|
|
2022-03-24 14:30:48 +08:00
|
|
|
colorInfo,
|
|
|
|
colorInfoSecondary,
|
|
|
|
colorBgInfo,
|
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-03-24 14:30:48 +08:00
|
|
|
colorBgSuccess,
|
|
|
|
colorSuccessSecondary,
|
|
|
|
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-04-07 21:29:50 +08:00
|
|
|
'&-info': genAlertTypeStyle(colorBgInfo, colorInfoSecondary, colorInfo, token, componentCls),
|
2022-03-08 10:29:00 +08:00
|
|
|
'&-warning': genAlertTypeStyle(
|
2022-03-24 14:30:48 +08:00
|
|
|
colorBgWarning,
|
|
|
|
colorWarningSecondary,
|
|
|
|
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-04-07 21:29:50 +08:00
|
|
|
...genAlertTypeStyle(colorBgError, colorErrorSecondary, colorError, token, componentCls),
|
|
|
|
[`${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-03-22 20:02:04 +08:00
|
|
|
motionDurationSlow: duration,
|
2022-03-11 14:29:29 +08:00
|
|
|
marginXS,
|
2022-03-29 15:57:39 +08:00
|
|
|
fontSizeIcon,
|
2022-03-11 14:29:29 +08:00
|
|
|
alertCloseColor,
|
|
|
|
alertCloseHoverColor,
|
|
|
|
} = 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-03-04 19:09:55 +08:00
|
|
|
color: alertCloseColor,
|
|
|
|
transition: `color ${duration}`,
|
|
|
|
'&:hover': {
|
|
|
|
color: alertCloseHoverColor,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
'&-close-text': {
|
|
|
|
color: alertCloseColor,
|
|
|
|
transition: `color ${duration}`,
|
|
|
|
'&:hover': {
|
|
|
|
color: alertCloseHoverColor,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
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-03-22 20:02:04 +08:00
|
|
|
const alertMessageColor = token.colorTextHeading;
|
2022-03-24 14:30:48 +08:00
|
|
|
const alertCloseColor = token.colorAction;
|
|
|
|
const alertCloseHoverColor = token.colorActionHover;
|
2022-03-04 19:09:55 +08:00
|
|
|
// FIXME
|
|
|
|
const alertWithDescriptionIconSize = 24;
|
|
|
|
const alertWithDescriptionPaddingVertical = token.padding - 1;
|
|
|
|
const alertWithDescriptionNoIconPaddingVertical = token.padding - 1;
|
|
|
|
|
2022-04-11 16:04:00 +08:00
|
|
|
const alertToken = mergeToken<AlertToken>(token, {
|
2022-03-04 19:09:55 +08:00
|
|
|
alertMessageColor,
|
|
|
|
alertCloseColor,
|
|
|
|
alertCloseHoverColor,
|
|
|
|
alertWithDescriptionIconSize,
|
|
|
|
alertWithDescriptionPaddingVertical,
|
|
|
|
alertWithDescriptionNoIconPaddingVertical,
|
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)];
|
|
|
|
});
|