2024-04-08 14:04:08 +08:00
|
|
|
import { unit } from '@ant-design/cssinjs';
|
|
|
|
import type { CSSObject } from '@ant-design/cssinjs';
|
2023-11-14 16:10:23 +08:00
|
|
|
|
2024-07-23 17:54:26 +08:00
|
|
|
import type { AliasToken } from '../theme/internal';
|
2022-03-08 10:29:00 +08:00
|
|
|
|
2022-10-28 16:44:19 +08:00
|
|
|
export const textEllipsis: CSSObject = {
|
|
|
|
overflow: 'hidden',
|
|
|
|
whiteSpace: 'nowrap',
|
|
|
|
textOverflow: 'ellipsis',
|
|
|
|
};
|
|
|
|
|
2024-07-29 16:38:50 +08:00
|
|
|
export const resetComponent = (token: AliasToken, needInheritFontFamily = false): CSSObject => ({
|
2022-03-08 10:29:00 +08:00
|
|
|
boxSizing: 'border-box',
|
|
|
|
margin: 0,
|
|
|
|
padding: 0,
|
2022-03-22 09:37:37 +08:00
|
|
|
color: token.colorText,
|
2022-03-08 10:29:00 +08:00
|
|
|
fontSize: token.fontSize,
|
|
|
|
// font-variant: @font-variant-base;
|
|
|
|
lineHeight: token.lineHeight,
|
|
|
|
listStyle: 'none',
|
|
|
|
// font-feature-settings: @font-feature-settings-base;
|
2023-10-07 17:06:28 +08:00
|
|
|
fontFamily: needInheritFontFamily ? 'inherit' : token.fontFamily,
|
2022-03-08 10:29:00 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
export const resetIcon = (): CSSObject => ({
|
2022-03-25 17:54:57 +08:00
|
|
|
display: 'inline-flex',
|
|
|
|
alignItems: 'center',
|
2022-03-08 10:29:00 +08:00
|
|
|
color: 'inherit',
|
|
|
|
fontStyle: 'normal',
|
|
|
|
lineHeight: 0,
|
|
|
|
textAlign: 'center',
|
|
|
|
textTransform: 'none',
|
|
|
|
// for SVG icon, see https://blog.prototypr.io/align-svg-icons-to-text-and-say-goodbye-to-font-icons-d44b3d7b26b4
|
|
|
|
verticalAlign: '-0.125em',
|
|
|
|
textRendering: 'optimizeLegibility',
|
|
|
|
'-webkit-font-smoothing': 'antialiased',
|
|
|
|
'-moz-osx-font-smoothing': 'grayscale',
|
|
|
|
|
|
|
|
'> *': {
|
|
|
|
lineHeight: 1,
|
|
|
|
},
|
|
|
|
|
|
|
|
svg: {
|
|
|
|
display: 'inline-block',
|
|
|
|
},
|
|
|
|
});
|
2022-03-09 10:38:02 +08:00
|
|
|
|
|
|
|
export const clearFix = (): CSSObject => ({
|
|
|
|
// https://github.com/ant-design/ant-design/issues/21301#issuecomment-583955229
|
|
|
|
'&::before': {
|
|
|
|
display: 'table',
|
|
|
|
content: '""',
|
|
|
|
},
|
|
|
|
|
|
|
|
'&::after': {
|
|
|
|
// https://github.com/ant-design/ant-design/issues/21864
|
|
|
|
display: 'table',
|
|
|
|
clear: 'both',
|
|
|
|
content: '""',
|
|
|
|
},
|
|
|
|
});
|
2022-07-11 15:35:58 +08:00
|
|
|
|
2024-07-23 17:54:26 +08:00
|
|
|
export const genLinkStyle = (token: AliasToken): CSSObject => ({
|
2022-07-11 15:35:58 +08:00
|
|
|
a: {
|
|
|
|
color: token.colorLink,
|
|
|
|
textDecoration: token.linkDecoration,
|
|
|
|
backgroundColor: 'transparent', // remove the gray background on active links in IE 10.
|
|
|
|
outline: 'none',
|
|
|
|
cursor: 'pointer',
|
|
|
|
transition: `color ${token.motionDurationSlow}`,
|
|
|
|
'-webkit-text-decoration-skip': 'objects', // remove gaps in links underline in iOS 8+ and Safari 8+.
|
|
|
|
|
|
|
|
'&:hover': {
|
|
|
|
color: token.colorLinkHover,
|
|
|
|
},
|
|
|
|
|
|
|
|
'&:active': {
|
|
|
|
color: token.colorLinkActive,
|
|
|
|
},
|
|
|
|
|
2024-06-22 21:59:12 +08:00
|
|
|
'&:active, &:hover': {
|
2022-07-11 15:35:58 +08:00
|
|
|
textDecoration: token.linkHoverDecoration,
|
|
|
|
outline: 0,
|
|
|
|
},
|
|
|
|
|
|
|
|
// https://github.com/ant-design/ant-design/issues/22503
|
|
|
|
'&:focus': {
|
|
|
|
textDecoration: token.linkFocusDecoration,
|
|
|
|
outline: 0,
|
|
|
|
},
|
|
|
|
|
|
|
|
'&[disabled]': {
|
|
|
|
color: token.colorTextDisabled,
|
|
|
|
cursor: 'not-allowed',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|
2022-09-09 10:53:03 +08:00
|
|
|
|
2024-01-30 11:08:02 +08:00
|
|
|
export const genCommonStyle = (
|
2024-07-23 17:54:26 +08:00
|
|
|
token: AliasToken,
|
2024-01-30 11:08:02 +08:00
|
|
|
componentPrefixCls: string,
|
|
|
|
rootCls?: string,
|
2024-04-18 16:06:35 +08:00
|
|
|
resetFont?: boolean,
|
2024-01-30 11:08:02 +08:00
|
|
|
): CSSObject => {
|
|
|
|
const prefixSelector = `[class^="${componentPrefixCls}"], [class*=" ${componentPrefixCls}"]`;
|
|
|
|
const rootPrefixSelector = rootCls ? `.${rootCls}` : prefixSelector;
|
2022-09-30 15:30:20 +08:00
|
|
|
|
2024-04-18 16:06:35 +08:00
|
|
|
const resetStyle: CSSObject = {
|
|
|
|
boxSizing: 'border-box',
|
|
|
|
|
|
|
|
'&::before, &::after': {
|
2022-09-30 15:30:20 +08:00
|
|
|
boxSizing: 'border-box',
|
2024-04-18 16:06:35 +08:00
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
let resetFontStyle: CSSObject = {};
|
2022-09-30 15:30:20 +08:00
|
|
|
|
2024-04-18 16:06:35 +08:00
|
|
|
if (resetFont !== false) {
|
|
|
|
resetFontStyle = {
|
|
|
|
fontFamily: token.fontFamily,
|
|
|
|
fontSize: token.fontSize,
|
|
|
|
};
|
|
|
|
}
|
2022-10-12 17:43:22 +08:00
|
|
|
|
2024-04-18 16:06:35 +08:00
|
|
|
return {
|
|
|
|
[rootPrefixSelector]: {
|
|
|
|
...resetFontStyle,
|
|
|
|
...resetStyle,
|
2022-10-12 17:43:22 +08:00
|
|
|
|
2024-04-18 16:06:35 +08:00
|
|
|
[prefixSelector]: resetStyle,
|
2022-09-15 11:37:10 +08:00
|
|
|
},
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2023-02-22 10:34:38 +08:00
|
|
|
export const genFocusOutline = (token: AliasToken): CSSObject => ({
|
2023-11-14 16:10:23 +08:00
|
|
|
outline: `${unit(token.lineWidthFocus)} solid ${token.colorPrimaryBorder}`,
|
2022-09-09 10:53:03 +08:00
|
|
|
outlineOffset: 1,
|
|
|
|
transition: 'outline-offset 0s, outline 0s',
|
|
|
|
});
|
|
|
|
|
2024-07-23 17:54:26 +08:00
|
|
|
export const genFocusStyle = (token: AliasToken): CSSObject => ({
|
2022-09-09 10:53:03 +08:00
|
|
|
'&:focus-visible': {
|
|
|
|
...genFocusOutline(token),
|
|
|
|
},
|
|
|
|
});
|
2024-09-29 18:02:13 +08:00
|
|
|
|
|
|
|
export const operationUnit = (token: AliasToken): CSSObject => ({
|
|
|
|
// FIXME: This use link but is a operation unit. Seems should be a colorPrimary.
|
|
|
|
// And Typography use this to generate link style which should not do this.
|
|
|
|
color: token.colorLink,
|
|
|
|
textDecoration: token.linkDecoration,
|
|
|
|
outline: 'none',
|
|
|
|
cursor: 'pointer',
|
|
|
|
transition: `all ${token.motionDurationSlow}`,
|
|
|
|
border: 0,
|
|
|
|
padding: 0,
|
|
|
|
background: 'none',
|
|
|
|
userSelect: 'none',
|
|
|
|
|
|
|
|
...genFocusStyle(token),
|
|
|
|
|
|
|
|
'&:focus, &:hover': {
|
|
|
|
color: token.colorLinkHover,
|
|
|
|
},
|
|
|
|
|
|
|
|
'&:active': {
|
|
|
|
color: token.colorLinkActive,
|
|
|
|
},
|
|
|
|
});
|