2022-03-18 17:26:17 +08:00
|
|
|
// deps-lint-skip-all
|
|
|
|
import { CSSObject, Keyframes } from '@ant-design/cssinjs';
|
|
|
|
import {
|
|
|
|
resetComponent,
|
|
|
|
GenerateStyle,
|
2022-03-21 16:48:25 +08:00
|
|
|
PresetColors,
|
2022-03-18 17:26:17 +08:00
|
|
|
PresetColorType,
|
2022-04-08 00:18:02 +08:00
|
|
|
genComponentStyleHook,
|
|
|
|
FullToken,
|
2022-04-11 16:04:00 +08:00
|
|
|
mergeToken,
|
2022-03-18 17:26:17 +08:00
|
|
|
} from '../../_util/theme';
|
|
|
|
|
2022-04-08 00:18:02 +08:00
|
|
|
interface BadgeToken extends FullToken<'Badge'> {
|
2022-03-18 17:26:17 +08:00
|
|
|
badgeZIndex: number | string;
|
|
|
|
badgeHeight: number;
|
|
|
|
badgeHeightSm: number;
|
|
|
|
badgeTextColor: string;
|
|
|
|
badgeFontWeight: string;
|
|
|
|
badgeFontSize: number;
|
|
|
|
badgeColor: string;
|
|
|
|
badgeDotSize: number;
|
|
|
|
badgeFontSizeSm: number;
|
|
|
|
badgeStatusSize: number;
|
|
|
|
}
|
|
|
|
|
|
|
|
const antStatusProcessing = new Keyframes('antStatusProcessing', {
|
|
|
|
'0%': { transform: 'scale(0.8)', opacity: 0.5 },
|
|
|
|
'100%': { transform: 'scale(2.4)', opacity: 0 },
|
|
|
|
});
|
|
|
|
|
|
|
|
const antZoomBadgeIn = new Keyframes('antZoomBadgeIn', {
|
|
|
|
'0%': { transform: 'scale(0) translate(50%, -50%)', opacity: 0 },
|
|
|
|
'100%': { transform: 'scale(1) translate(50%, -50%)' },
|
|
|
|
});
|
|
|
|
|
|
|
|
const antZoomBadgeOut = new Keyframes('antZoomBadgeOut', {
|
|
|
|
'0%': { transform: 'scale(1) translate(50%, -50%)' },
|
|
|
|
'100%': { transform: 'scale(0) translate(50%, -50%)', opacity: 0 },
|
|
|
|
});
|
|
|
|
|
|
|
|
const antNoWrapperZoomBadgeIn = new Keyframes('antNoWrapperZoomBadgeIn', {
|
|
|
|
'0%': { transform: 'scale(0)', opacity: 0 },
|
|
|
|
'100%': { transform: 'scale(1)' },
|
|
|
|
});
|
|
|
|
const antNoWrapperZoomBadgeOut = new Keyframes('antNoWrapperZoomBadgeOut', {
|
|
|
|
'0%': { transform: 'scale(1)' },
|
|
|
|
'100%': { transform: 'scale(0)', opacity: 0 },
|
|
|
|
});
|
|
|
|
const antBadgeLoadingCircle = new Keyframes('antBadgeLoadingCircle', {
|
|
|
|
'0%': { transformOrigin: '50%' },
|
|
|
|
'100%': {
|
|
|
|
transform: 'translate(50%, -50%) rotate(360deg)',
|
|
|
|
transformOrigin: '50%',
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
const genSharedBadgeStyle: GenerateStyle<BadgeToken> = (
|
|
|
|
token: BadgeToken,
|
|
|
|
hashId: string,
|
|
|
|
): CSSObject => {
|
2022-04-08 00:18:02 +08:00
|
|
|
const { componentCls, iconCls, antCls } = token;
|
|
|
|
const numberPrefixCls = `${antCls}-scroll-number`;
|
|
|
|
const ribbonPrefixCls = `${antCls}-ribbon`;
|
|
|
|
const ribbonWrapperPrefixCls = `${antCls}-ribbon-wrapper`;
|
2022-03-18 17:26:17 +08:00
|
|
|
|
|
|
|
// FIXME preset color 后面可能要统一重构
|
2022-03-21 16:48:25 +08:00
|
|
|
const statusPreset = PresetColors.reduce((prev: CSSObject, colorKey: keyof PresetColorType) => {
|
|
|
|
const darkColor = token[`${colorKey}-6`];
|
|
|
|
return {
|
|
|
|
...prev,
|
2022-04-08 00:18:02 +08:00
|
|
|
[`${componentCls}-status-${colorKey}`]: {
|
2022-03-21 16:48:25 +08:00
|
|
|
background: darkColor,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}, {} as CSSObject);
|
|
|
|
const statusRibbonPreset = PresetColors.reduce(
|
2022-03-18 17:26:17 +08:00
|
|
|
(prev: CSSObject, colorKey: keyof PresetColorType) => {
|
|
|
|
const darkColor = token[`${colorKey}-6`];
|
|
|
|
return {
|
|
|
|
...prev,
|
2022-04-08 00:18:02 +08:00
|
|
|
[`&${ribbonPrefixCls}-color-${colorKey}`]: {
|
2022-03-18 17:26:17 +08:00
|
|
|
background: darkColor,
|
|
|
|
color: darkColor,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
},
|
|
|
|
{} as CSSObject,
|
|
|
|
);
|
|
|
|
|
|
|
|
return {
|
2022-04-08 00:18:02 +08:00
|
|
|
[componentCls]: {
|
2022-03-18 17:26:17 +08:00
|
|
|
...resetComponent(token),
|
|
|
|
position: 'relative',
|
|
|
|
display: 'inline-block',
|
|
|
|
lineHeight: 1,
|
|
|
|
|
2022-04-08 00:18:02 +08:00
|
|
|
[`${componentCls}-count`]: {
|
2022-03-18 17:26:17 +08:00
|
|
|
zIndex: token.badgeZIndex,
|
|
|
|
minWidth: token.badgeHeight,
|
|
|
|
height: token.badgeHeight,
|
|
|
|
padding: '0 6px', // FIXME: hard code, copied from old less file
|
|
|
|
color: token.badgeTextColor,
|
|
|
|
fontWeight: token.badgeFontWeight,
|
|
|
|
fontSize: token.badgeFontSize,
|
|
|
|
lineHeight: `${token.badgeHeight}px`,
|
|
|
|
whiteSpace: 'nowrap',
|
|
|
|
textAlign: 'center',
|
|
|
|
background: token.badgeColor,
|
|
|
|
borderRadius: token.badgeHeight / 2,
|
2022-03-22 20:02:04 +08:00
|
|
|
boxShadow: `0 0 0 1px ${token.colorBgComponent}`,
|
2022-03-18 17:26:17 +08:00
|
|
|
a: {
|
|
|
|
color: token.badgeTextColor,
|
|
|
|
},
|
|
|
|
'a:hover': {
|
|
|
|
color: token.badgeTextColor,
|
|
|
|
},
|
|
|
|
},
|
2022-04-08 00:18:02 +08:00
|
|
|
[`${componentCls}-count-sm`]: {
|
2022-03-18 17:26:17 +08:00
|
|
|
minWidth: token.badgeHeightSm,
|
|
|
|
height: token.badgeHeightSm,
|
|
|
|
padding: 0,
|
|
|
|
fontSize: token.badgeFontSizeSm,
|
|
|
|
lineHeight: `${token.badgeHeightSm}px`,
|
|
|
|
borderRadius: token.badgeHeightSm / 2,
|
|
|
|
},
|
|
|
|
|
2022-04-08 00:18:02 +08:00
|
|
|
[`${componentCls}-multiple-words`]: {
|
2022-03-18 17:26:17 +08:00
|
|
|
padding: `0 ${token.paddingXS}px`,
|
|
|
|
},
|
|
|
|
|
2022-04-08 00:18:02 +08:00
|
|
|
[`${componentCls}-dot`]: {
|
2022-03-18 17:26:17 +08:00
|
|
|
zIndex: token.badgeZIndex,
|
|
|
|
width: token.badgeDotSize,
|
|
|
|
minWidth: token.badgeDotSize,
|
|
|
|
height: token.badgeDotSize,
|
|
|
|
background: token.badgeColor,
|
|
|
|
borderRadius: '100%',
|
2022-03-22 20:02:04 +08:00
|
|
|
boxShadow: `0 0 0 1px ${token.colorBgComponent}`,
|
2022-03-18 17:26:17 +08:00
|
|
|
},
|
2022-04-08 00:18:02 +08:00
|
|
|
[`${componentCls}-dot${numberPrefixCls}`]: {
|
2022-03-18 17:26:17 +08:00
|
|
|
transition: 'background 1.5s', // FIXME: hard code, copied from old less file
|
|
|
|
},
|
2022-04-08 00:18:02 +08:00
|
|
|
[`${componentCls}-count, ${componentCls}-dot, ${numberPrefixCls}-custom-component`]: {
|
2022-03-18 17:26:17 +08:00
|
|
|
position: 'absolute',
|
|
|
|
top: 0,
|
|
|
|
insetInlineEnd: 0,
|
|
|
|
transform: 'translate(50%, -50%)',
|
|
|
|
transformOrigin: '100% 0%',
|
2022-04-08 00:18:02 +08:00
|
|
|
[`${iconCls}-spin`]: {
|
2022-03-18 17:26:17 +08:00
|
|
|
animation: `${antBadgeLoadingCircle.getName(hashId)} ${
|
2022-03-22 20:02:04 +08:00
|
|
|
token.motionDurationFast
|
2022-03-18 17:26:17 +08:00
|
|
|
} infinite linear`,
|
|
|
|
},
|
|
|
|
},
|
2022-04-08 00:18:02 +08:00
|
|
|
[`&${componentCls}-status`]: {
|
2022-03-18 17:26:17 +08:00
|
|
|
lineHeight: 'inherit',
|
|
|
|
verticalAlign: 'baseline',
|
|
|
|
|
2022-04-08 00:18:02 +08:00
|
|
|
[`${componentCls}-status-dot`]: {
|
2022-03-18 17:26:17 +08:00
|
|
|
position: 'relative',
|
|
|
|
top: -1, // FIXME: hard code, copied from old less file
|
|
|
|
display: 'inline-block',
|
|
|
|
width: token.badgeStatusSize,
|
|
|
|
height: token.badgeStatusSize,
|
|
|
|
verticalAlign: 'middle',
|
|
|
|
borderRadius: '50%',
|
|
|
|
},
|
|
|
|
|
2022-04-08 00:18:02 +08:00
|
|
|
[`${componentCls}-status-success`]: {
|
2022-03-22 09:37:37 +08:00
|
|
|
backgroundColor: token.colorSuccess,
|
2022-03-18 17:26:17 +08:00
|
|
|
},
|
2022-04-08 00:18:02 +08:00
|
|
|
[`${componentCls}-status-processing`]: {
|
2022-03-18 17:26:17 +08:00
|
|
|
position: 'relative',
|
2022-03-22 09:37:37 +08:00
|
|
|
backgroundColor: token.colorPrimary,
|
2022-03-18 17:26:17 +08:00
|
|
|
|
|
|
|
'&::after': {
|
|
|
|
position: 'absolute',
|
|
|
|
top: 0,
|
|
|
|
insetInlineStart: 0,
|
|
|
|
width: '100%',
|
|
|
|
height: '100%',
|
2022-03-22 09:37:37 +08:00
|
|
|
border: `1px solid ${token.colorPrimary}`,
|
2022-03-18 17:26:17 +08:00
|
|
|
borderRadius: '50%',
|
|
|
|
animation: `${antStatusProcessing.getName(hashId)} 1.2s infinite ease-in-out`, // FIXME: hard code, copied from old less file
|
|
|
|
content: '""',
|
|
|
|
},
|
|
|
|
},
|
2022-04-08 00:18:02 +08:00
|
|
|
[`${componentCls}-status-default`]: {
|
2022-03-18 17:26:17 +08:00
|
|
|
backgroundColor: '#d9d9d9', // FIXME: @normal-color;
|
|
|
|
},
|
|
|
|
|
2022-04-08 00:18:02 +08:00
|
|
|
[`${componentCls}-status-error`]: {
|
2022-03-22 09:37:37 +08:00
|
|
|
backgroundColor: token.colorError,
|
2022-03-18 17:26:17 +08:00
|
|
|
},
|
|
|
|
|
2022-04-08 00:18:02 +08:00
|
|
|
[`${componentCls}-status-warning`]: {
|
2022-03-22 09:37:37 +08:00
|
|
|
backgroundColor: token.colorWarning,
|
2022-03-18 17:26:17 +08:00
|
|
|
},
|
|
|
|
...statusPreset,
|
2022-04-08 00:18:02 +08:00
|
|
|
[`${componentCls}-status-text`]: {
|
2022-03-18 17:26:17 +08:00
|
|
|
marginInlineStart: token.marginXS,
|
2022-03-22 09:37:37 +08:00
|
|
|
color: token.colorText,
|
2022-03-18 17:26:17 +08:00
|
|
|
fontSize: token.fontSize,
|
|
|
|
},
|
|
|
|
},
|
2022-04-08 00:18:02 +08:00
|
|
|
[`${componentCls}-zoom-appear, ${componentCls}-zoom-enter`]: {
|
2022-03-22 20:02:04 +08:00
|
|
|
animation: `${antZoomBadgeIn.getName(hashId)} ${token.motionDurationSlow} ${
|
|
|
|
token.motionEaseOutBack
|
|
|
|
}`,
|
2022-03-18 17:26:17 +08:00
|
|
|
animationFillMode: 'both',
|
|
|
|
},
|
2022-04-08 00:18:02 +08:00
|
|
|
[`${componentCls}-zoom-leave`]: {
|
2022-03-22 20:02:04 +08:00
|
|
|
animation: `${antZoomBadgeOut.getName(hashId)} ${token.motionDurationSlow} ${
|
2022-03-22 09:37:37 +08:00
|
|
|
token.motionEaseOutBack
|
|
|
|
}`,
|
2022-03-18 17:26:17 +08:00
|
|
|
animationFillMode: 'both',
|
|
|
|
},
|
2022-04-08 00:18:02 +08:00
|
|
|
[`&${componentCls}-not-a-wrapper`]: {
|
|
|
|
[`${componentCls}-zoom-appear, ${componentCls}-zoom-enter`]: {
|
2022-03-22 20:02:04 +08:00
|
|
|
animation: `${antNoWrapperZoomBadgeIn.getName(hashId)} ${token.motionDurationSlow} ${
|
2022-03-22 09:37:37 +08:00
|
|
|
token.motionEaseOutBack
|
2022-03-18 17:26:17 +08:00
|
|
|
}`,
|
|
|
|
},
|
|
|
|
|
2022-04-08 00:18:02 +08:00
|
|
|
[`${componentCls}-zoom-leave`]: {
|
2022-03-22 20:02:04 +08:00
|
|
|
animation: `${antNoWrapperZoomBadgeOut.getName(hashId)} ${token.motionDurationSlow} ${
|
2022-03-22 09:37:37 +08:00
|
|
|
token.motionEaseOutBack
|
2022-03-18 17:26:17 +08:00
|
|
|
}`,
|
|
|
|
},
|
2022-04-08 00:18:02 +08:00
|
|
|
[`&:not(${componentCls}-status)`]: {
|
2022-03-18 17:26:17 +08:00
|
|
|
verticalAlign: 'middle',
|
|
|
|
},
|
2022-04-08 00:18:02 +08:00
|
|
|
[`${numberPrefixCls}-custom-component, ${componentCls}-count`]: {
|
2022-03-18 17:26:17 +08:00
|
|
|
transform: 'none',
|
|
|
|
},
|
2022-04-08 00:18:02 +08:00
|
|
|
[`${numberPrefixCls}-custom-component, ${numberPrefixCls}`]: {
|
2022-03-18 17:26:17 +08:00
|
|
|
position: 'relative',
|
|
|
|
top: 'auto',
|
|
|
|
display: 'block',
|
|
|
|
transformOrigin: '50% 50%',
|
|
|
|
},
|
|
|
|
},
|
2022-04-08 00:18:02 +08:00
|
|
|
[`${numberPrefixCls}`]: {
|
2022-03-18 17:26:17 +08:00
|
|
|
overflow: 'hidden',
|
|
|
|
direction: 'ltr',
|
2022-04-08 00:18:02 +08:00
|
|
|
[`${numberPrefixCls}-only`]: {
|
2022-03-18 17:26:17 +08:00
|
|
|
position: 'relative',
|
|
|
|
display: 'inline-block',
|
|
|
|
height: token.badgeHeight,
|
2022-03-22 20:02:04 +08:00
|
|
|
transition: `all ${token.motionDurationSlow} ${token.motionEaseOutBack}`,
|
2022-03-18 17:26:17 +08:00
|
|
|
WebkitTransformStyle: 'preserve-3d',
|
|
|
|
WebkitBackfaceVisibility: 'hidden',
|
2022-04-08 00:18:02 +08:00
|
|
|
[`> p${numberPrefixCls}-only-unit`]: {
|
2022-03-18 17:26:17 +08:00
|
|
|
height: token.badgeHeight,
|
|
|
|
margin: 0,
|
|
|
|
WebkitTransformStyle: 'preserve-3d',
|
|
|
|
WebkitBackfaceVisibility: 'hidden',
|
|
|
|
},
|
|
|
|
},
|
2022-04-08 00:18:02 +08:00
|
|
|
[`${numberPrefixCls}-symbol`]: { verticalAlign: 'top' },
|
2022-03-18 17:26:17 +08:00
|
|
|
},
|
|
|
|
},
|
2022-04-08 00:18:02 +08:00
|
|
|
[`${ribbonWrapperPrefixCls}`]: { position: 'relative' },
|
|
|
|
[`${ribbonPrefixCls}`]: {
|
2022-03-18 17:26:17 +08:00
|
|
|
...resetComponent(token),
|
|
|
|
position: 'absolute',
|
|
|
|
top: 8, // FIXME: hard code, copied from old less file
|
|
|
|
height: 22, // FIXME: hard code, copied from old less file
|
|
|
|
padding: `0 ${token.paddingXS}px`,
|
|
|
|
color: token.badgeTextColor,
|
2022-03-22 09:37:37 +08:00
|
|
|
lineHeight: '22px', // colorPrimarycode, copied from old less file
|
2022-03-18 17:26:17 +08:00
|
|
|
whiteSpace: 'nowrap',
|
2022-03-22 09:37:37 +08:00
|
|
|
backgroundColor: token.colorPrimary,
|
2022-03-22 13:26:29 +08:00
|
|
|
borderRadius: token.controlRadius,
|
2022-04-08 00:18:02 +08:00
|
|
|
[`${ribbonPrefixCls}-text`]: { color: '#fff' },
|
|
|
|
[`${ribbonPrefixCls}-corner`]: {
|
2022-03-18 17:26:17 +08:00
|
|
|
position: 'absolute',
|
|
|
|
top: '100%',
|
|
|
|
width: 8,
|
|
|
|
height: 8,
|
|
|
|
color: 'currentcolor',
|
|
|
|
border: '4px solid', // FIXME: hard code, copied from old less file
|
|
|
|
transform: 'scaleY(0.75)', // FIXME: hard code, copied from old less file
|
|
|
|
transformOrigin: 'top',
|
|
|
|
'&::after': {
|
|
|
|
position: 'absolute',
|
|
|
|
top: `${-0.5 * token.paddingXS}px`,
|
|
|
|
insetInlineStart: `${-0.5 * token.paddingXS}px`,
|
|
|
|
width: 'inherit',
|
|
|
|
height: 'inherit',
|
|
|
|
color: 'rgba(0, 0, 0, 0.25)',
|
|
|
|
border: 'inherit',
|
|
|
|
content: "''",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
...statusRibbonPreset,
|
2022-04-08 00:18:02 +08:00
|
|
|
[`&${ribbonPrefixCls}-placement-end`]: {
|
2022-03-18 17:26:17 +08:00
|
|
|
insetInlineEnd: -1 * token.marginXS,
|
2022-04-19 11:27:09 +08:00
|
|
|
borderEndEndRadius: 0,
|
2022-04-08 00:18:02 +08:00
|
|
|
[`${ribbonPrefixCls}-corner`]: {
|
2022-03-18 17:26:17 +08:00
|
|
|
insetInlineEnd: 0,
|
|
|
|
borderColor: 'currentcolor transparent transparent currentcolor',
|
|
|
|
},
|
|
|
|
},
|
2022-04-08 00:18:02 +08:00
|
|
|
[`&${ribbonPrefixCls}-placement-start`]: {
|
2022-03-18 17:26:17 +08:00
|
|
|
insetInlineStart: -1 * token.marginXS,
|
2022-04-19 11:27:09 +08:00
|
|
|
borderEndStartRadius: 0,
|
2022-04-08 00:18:02 +08:00
|
|
|
[`${ribbonPrefixCls}-corner`]: {
|
2022-03-18 17:26:17 +08:00
|
|
|
insetInlineStart: 0,
|
|
|
|
borderColor: 'currentcolor currentcolor transparent transparent',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
antStatusProcessing,
|
|
|
|
antZoomBadgeIn,
|
|
|
|
antZoomBadgeOut,
|
|
|
|
antNoWrapperZoomBadgeIn,
|
|
|
|
antNoWrapperZoomBadgeOut,
|
|
|
|
antBadgeLoadingCircle,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
// ============================== Export ==============================
|
2022-04-08 00:18:02 +08:00
|
|
|
export default genComponentStyleHook('Badge', (token, { hashId }) => {
|
2022-03-18 17:26:17 +08:00
|
|
|
const badgeZIndex = 'auto';
|
|
|
|
const badgeHeight = 20; // FIXME: hard code
|
2022-03-22 20:02:04 +08:00
|
|
|
const badgeTextColor = token.colorBgComponent;
|
2022-03-18 17:26:17 +08:00
|
|
|
const badgeFontWeight = 'normal';
|
|
|
|
const badgeFontSize = token.fontSizeSM;
|
2022-03-24 14:30:48 +08:00
|
|
|
const badgeColor = token.colorHighlight;
|
2022-03-18 17:26:17 +08:00
|
|
|
const badgeHeightSm = 14; // FIXME: hard code
|
|
|
|
const badgeDotSize = 6; // FIXME: hard code
|
|
|
|
const badgeFontSizeSm = token.fontSizeSM;
|
|
|
|
const badgeStatusSize = 6; // FIXME: hard code
|
|
|
|
|
2022-04-11 16:04:00 +08:00
|
|
|
const badgeToken = mergeToken<BadgeToken>(token, {
|
2022-03-18 17:26:17 +08:00
|
|
|
badgeZIndex,
|
|
|
|
badgeHeight,
|
|
|
|
badgeTextColor,
|
|
|
|
badgeFontWeight,
|
|
|
|
badgeFontSize,
|
|
|
|
badgeColor,
|
|
|
|
badgeHeightSm,
|
|
|
|
badgeDotSize,
|
|
|
|
badgeFontSizeSm,
|
|
|
|
badgeStatusSize,
|
2022-04-11 16:04:00 +08:00
|
|
|
});
|
2022-03-18 17:26:17 +08:00
|
|
|
|
2022-04-08 00:18:02 +08:00
|
|
|
return [genSharedBadgeStyle(badgeToken, hashId), { display: 'none' }];
|
|
|
|
});
|