mirror of
https://github.com/ant-design/ant-design.git
synced 2024-12-19 03:54:28 +08:00
Merge pull request #51897 from ant-design/fix/duplicate-style-tags
Some checks are pending
Publish Any Commit / build (push) Waiting to run
🔀 Sync mirror to Gitee / mirror (push) Waiting to run
✅ test / lint (push) Waiting to run
✅ test / test-react-legacy (16, 1/2) (push) Waiting to run
✅ test / test-react-legacy (16, 2/2) (push) Waiting to run
✅ test / test-react-legacy (17, 1/2) (push) Waiting to run
✅ test / test-react-legacy (17, 2/2) (push) Waiting to run
✅ test / test-node (push) Waiting to run
✅ test / test-react-latest (dom, 1/2) (push) Waiting to run
✅ test / test-react-latest (dom, 2/2) (push) Waiting to run
✅ test / test-react-latest-dist (dist, 1/2) (push) Blocked by required conditions
✅ test / test-react-latest-dist (dist, 2/2) (push) Blocked by required conditions
✅ test / test-react-latest-dist (dist-min, 1/2) (push) Blocked by required conditions
✅ test / test-react-latest-dist (dist-min, 2/2) (push) Blocked by required conditions
✅ test / test-coverage (push) Blocked by required conditions
✅ test / build (push) Waiting to run
✅ test / test lib/es module (es, 1/2) (push) Waiting to run
✅ test / test lib/es module (es, 2/2) (push) Waiting to run
✅ test / test lib/es module (lib, 1/2) (push) Waiting to run
✅ test / test lib/es module (lib, 2/2) (push) Waiting to run
👁️ Visual Regression Persist Start / test image (push) Waiting to run
Some checks are pending
Publish Any Commit / build (push) Waiting to run
🔀 Sync mirror to Gitee / mirror (push) Waiting to run
✅ test / lint (push) Waiting to run
✅ test / test-react-legacy (16, 1/2) (push) Waiting to run
✅ test / test-react-legacy (16, 2/2) (push) Waiting to run
✅ test / test-react-legacy (17, 1/2) (push) Waiting to run
✅ test / test-react-legacy (17, 2/2) (push) Waiting to run
✅ test / test-node (push) Waiting to run
✅ test / test-react-latest (dom, 1/2) (push) Waiting to run
✅ test / test-react-latest (dom, 2/2) (push) Waiting to run
✅ test / test-react-latest-dist (dist, 1/2) (push) Blocked by required conditions
✅ test / test-react-latest-dist (dist, 2/2) (push) Blocked by required conditions
✅ test / test-react-latest-dist (dist-min, 1/2) (push) Blocked by required conditions
✅ test / test-react-latest-dist (dist-min, 2/2) (push) Blocked by required conditions
✅ test / test-coverage (push) Blocked by required conditions
✅ test / build (push) Waiting to run
✅ test / test lib/es module (es, 1/2) (push) Waiting to run
✅ test / test lib/es module (es, 2/2) (push) Waiting to run
✅ test / test lib/es module (lib, 1/2) (push) Waiting to run
✅ test / test lib/es module (lib, 2/2) (push) Waiting to run
👁️ Visual Regression Persist Start / test image (push) Waiting to run
fix: the icon style is being created repeatedly
This commit is contained in:
commit
49940c2c37
@ -202,10 +202,12 @@ describe('App', () => {
|
|||||||
|
|
||||||
expect(container.querySelector('.anticon')).toBeTruthy();
|
expect(container.querySelector('.anticon')).toBeTruthy();
|
||||||
const dynamicStyles = Array.from(document.querySelectorAll('style[data-css-hash]'));
|
const dynamicStyles = Array.from(document.querySelectorAll('style[data-css-hash]'));
|
||||||
|
// Self-contained .anticon style
|
||||||
|
const regex = /(?:^|\})\s*\.anticon\s*{[^}]*}/;
|
||||||
expect(
|
expect(
|
||||||
dynamicStyles.some((style) => {
|
dynamicStyles.some((style) => {
|
||||||
const { innerHTML } = style;
|
const { innerHTML } = style;
|
||||||
return innerHTML.startsWith('.anticon');
|
return regex.test(innerHTML);
|
||||||
}),
|
}),
|
||||||
).toBeTruthy();
|
).toBeTruthy();
|
||||||
});
|
});
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
import { unit } from '@ant-design/cssinjs';
|
import { unit } from '@ant-design/cssinjs';
|
||||||
import type { CSSObject } from '@ant-design/cssinjs';
|
import type { CSSObject } from '@ant-design/cssinjs';
|
||||||
|
|
||||||
import type { AliasToken } from '../theme/internal';
|
import type { AliasToken } from '../theme/internal';
|
||||||
|
|
||||||
export const textEllipsis: CSSObject = {
|
export const textEllipsis: CSSObject = {
|
||||||
@ -144,6 +143,15 @@ export const genFocusStyle = (token: AliasToken): CSSObject => ({
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
export const genIconStyle = (iconPrefixCls: string): CSSObject => ({
|
||||||
|
[`.${iconPrefixCls}`]: {
|
||||||
|
...resetIcon(),
|
||||||
|
[`.${iconPrefixCls} .${iconPrefixCls}-icon`]: {
|
||||||
|
display: 'block',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
export const operationUnit = (token: AliasToken): CSSObject => ({
|
export const operationUnit = (token: AliasToken): CSSObject => ({
|
||||||
// FIXME: This use link but is a operation unit. Seems should be a colorPrimary.
|
// 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.
|
// And Typography use this to generate link style which should not do this.
|
||||||
|
@ -2,11 +2,10 @@ import { useContext } from 'react';
|
|||||||
import { genStyleUtils } from '@ant-design/cssinjs-utils';
|
import { genStyleUtils } from '@ant-design/cssinjs-utils';
|
||||||
import type { GetCompUnitless } from '@ant-design/cssinjs-utils/es/util/genStyleUtils';
|
import type { GetCompUnitless } from '@ant-design/cssinjs-utils/es/util/genStyleUtils';
|
||||||
|
|
||||||
import { ConfigContext } from '../../config-provider/context';
|
import { ConfigContext, defaultIconPrefixCls } from '../../config-provider/context';
|
||||||
import { genCommonStyle, genLinkStyle } from '../../style';
|
import { genCommonStyle, genLinkStyle, genIconStyle } from '../../style';
|
||||||
import type { AliasToken, ComponentTokenMap, SeedToken } from '../interface';
|
import type { AliasToken, ComponentTokenMap, SeedToken } from '../interface';
|
||||||
import useLocalToken, { unitless } from '../useToken';
|
import useLocalToken, { unitless } from '../useToken';
|
||||||
import useResetIconStyle from './useResetIconStyle';
|
|
||||||
|
|
||||||
export const { genStyleHooks, genComponentStyleHook, genSubStyleComponent } = genStyleUtils<
|
export const { genStyleHooks, genComponentStyleHook, genSubStyleComponent } = genStyleUtils<
|
||||||
ComponentTokenMap,
|
ComponentTokenMap,
|
||||||
@ -28,14 +27,13 @@ export const { genStyleHooks, genComponentStyleHook, genSubStyleComponent } = ge
|
|||||||
return { theme, realToken, hashId, token, cssVar };
|
return { theme, realToken, hashId, token, cssVar };
|
||||||
},
|
},
|
||||||
useCSP: () => {
|
useCSP: () => {
|
||||||
const { csp, iconPrefixCls } = useContext(ConfigContext);
|
const { csp } = useContext(ConfigContext);
|
||||||
|
|
||||||
// Generate style for icons
|
|
||||||
useResetIconStyle(iconPrefixCls, csp);
|
|
||||||
|
|
||||||
return csp ?? {};
|
return csp ?? {};
|
||||||
},
|
},
|
||||||
getResetStyles: (token) => [{ '&': genLinkStyle(token) }],
|
getResetStyles: (token, config) => [
|
||||||
|
{ '&': genLinkStyle(token) },
|
||||||
|
genIconStyle(config?.prefix.iconPrefixCls ?? defaultIconPrefixCls),
|
||||||
|
],
|
||||||
getCommonStyle: genCommonStyle,
|
getCommonStyle: genCommonStyle,
|
||||||
getCompUnitless: (() => unitless) as GetCompUnitless<ComponentTokenMap, AliasToken>,
|
getCompUnitless: (() => unitless) as GetCompUnitless<ComponentTokenMap, AliasToken>,
|
||||||
});
|
});
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import { useStyleRegister } from '@ant-design/cssinjs';
|
import { useStyleRegister } from '@ant-design/cssinjs';
|
||||||
|
|
||||||
import type { CSPConfig } from '../../config-provider';
|
import type { CSPConfig } from '../../config-provider';
|
||||||
import { resetIcon } from '../../style';
|
import { genIconStyle } from '../../style';
|
||||||
import useToken from '../useToken';
|
import useToken from '../useToken';
|
||||||
|
|
||||||
const useResetIconStyle = (iconPrefixCls: string, csp?: CSPConfig) => {
|
const useResetIconStyle = (iconPrefixCls: string, csp?: CSPConfig) => {
|
||||||
@ -19,16 +19,7 @@ const useResetIconStyle = (iconPrefixCls: string, csp?: CSPConfig) => {
|
|||||||
name: 'antd',
|
name: 'antd',
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
() => [
|
() => [genIconStyle(iconPrefixCls)],
|
||||||
{
|
|
||||||
[`.${iconPrefixCls}`]: {
|
|
||||||
...resetIcon(),
|
|
||||||
[`.${iconPrefixCls} .${iconPrefixCls}-icon`]: {
|
|
||||||
display: 'block',
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
],
|
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user