2022-05-09 22:20:07 +08:00
|
|
|
import type { CSSInterpolation, CSSObject } from '@ant-design/cssinjs';
|
2023-08-17 15:00:04 +08:00
|
|
|
import type { CSSProperties } from 'react';
|
2023-06-06 10:53:28 +08:00
|
|
|
import { resetComponent } from '../../style';
|
2022-11-23 20:22:38 +08:00
|
|
|
import type { FullToken, GenerateStyle } from '../../theme/internal';
|
2023-08-17 15:00:04 +08:00
|
|
|
import { genComponentStyleHook } from '../../theme/internal';
|
|
|
|
|
|
|
|
export interface ComponentToken {
|
|
|
|
// Component token here
|
|
|
|
/**
|
|
|
|
* @desc 默认内间距
|
|
|
|
* @descEN Default padding
|
|
|
|
*/
|
|
|
|
defaultPadding: CSSProperties['padding'];
|
|
|
|
/**
|
|
|
|
* @desc 带有描述的内间距
|
|
|
|
* @descEN Padding with description
|
|
|
|
*/
|
|
|
|
withDescriptionPadding: CSSProperties['padding'];
|
|
|
|
/**
|
|
|
|
* @desc 带有描述时的图标尺寸
|
|
|
|
* @descEN Icon size with description
|
|
|
|
*/
|
|
|
|
withDescriptionIconSize: number;
|
|
|
|
}
|
2022-03-04 19:09:55 +08:00
|
|
|
|
2022-04-07 21:29:50 +08:00
|
|
|
type AlertToken = FullToken<'Alert'> & {
|
2023-08-17 15:00:04 +08:00
|
|
|
// Custom token here
|
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,
|
2023-08-17 15:00:04 +08:00
|
|
|
withDescriptionIconSize,
|
2022-05-24 15:45:41 +08:00
|
|
|
colorText,
|
2023-06-06 10:53:28 +08:00
|
|
|
colorTextHeading,
|
2023-08-17 15:00:04 +08:00
|
|
|
withDescriptionPadding,
|
|
|
|
defaultPadding,
|
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',
|
2023-08-17 15:00:04 +08:00
|
|
|
padding: defaultPadding,
|
2022-03-04 19:09:55 +08:00
|
|
|
wordWrap: 'break-word',
|
|
|
|
borderRadius,
|
|
|
|
|
2023-01-20 10:31:27 +08:00
|
|
|
[`&${componentCls}-rtl`]: {
|
2022-03-11 17:07:16 +08:00
|
|
|
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': {
|
2023-08-17 15:00:04 +08:00
|
|
|
color: colorTextHeading,
|
2022-03-04 19:09:55 +08:00
|
|
|
},
|
|
|
|
|
2023-01-20 10:31:27 +08:00
|
|
|
[`&${componentCls}-motion-leave`]: {
|
2022-03-04 19:09:55 +08:00
|
|
|
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
|
|
|
},
|
|
|
|
|
2023-01-20 10:31:27 +08:00
|
|
|
[`&${componentCls}-motion-leave-active`]: {
|
2022-03-04 19:09:55 +08:00
|
|
|
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',
|
2023-08-17 15:00:04 +08:00
|
|
|
padding: withDescriptionPadding,
|
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,
|
2023-08-17 15:00:04 +08:00
|
|
|
fontSize: withDescriptionIconSize,
|
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,
|
2023-06-06 10:53:28 +08:00
|
|
|
color: colorTextHeading,
|
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',
|
2023-08-17 15:00:04 +08:00
|
|
|
color: colorText,
|
2022-03-04 19:09:55 +08:00
|
|
|
},
|
|
|
|
},
|
|
|
|
|
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-11-17 23:31:41 +08:00
|
|
|
motionDurationMid,
|
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-11-17 23:31:41 +08:00
|
|
|
transition: `color ${motionDurationMid}`,
|
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-11-17 23:31:41 +08:00
|
|
|
transition: `color ${motionDurationMid}`,
|
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),
|
|
|
|
];
|
|
|
|
|
2023-08-17 15:00:04 +08:00
|
|
|
export default genComponentStyleHook(
|
|
|
|
'Alert',
|
|
|
|
(token) => [genAlertStyle(token)],
|
|
|
|
(token) => {
|
|
|
|
const paddingHorizontal = 12; // Fixed value here.
|
|
|
|
|
|
|
|
return {
|
|
|
|
withDescriptionIconSize: token.fontSizeHeading3,
|
|
|
|
defaultPadding: `${token.paddingContentVerticalSM}px ${paddingHorizontal}px`,
|
|
|
|
withDescriptionPadding: `${token.paddingMD}px ${token.paddingContentHorizontalLG}px`,
|
|
|
|
};
|
|
|
|
},
|
|
|
|
);
|