Skip to content

Commit

Permalink
feat: support layer (#681)
Browse files Browse the repository at this point in the history
* feat: support layer

* chore: bump version
  • Loading branch information
zombieJ authored Jan 22, 2025
1 parent 6f00108 commit d694b4a
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 2 deletions.
2 changes: 1 addition & 1 deletion packages/icons-react/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@ant-design/icons",
"version": "5.5.1",
"version": "5.5.2",
"repository": "https://github.com/ant-design/ant-design-icons/tree/master/packages/icons-react",
"license": "MIT",
"contributors": [
Expand Down
1 change: 1 addition & 0 deletions packages/icons-react/src/components/Context.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ export interface IconContextProps {
prefixCls?: string;
rootClassName?: string;
csp?: { nonce?: string };
layer?: string;
}

const IconContext = createContext<IconContextProps>({});
Expand Down
6 changes: 5 additions & 1 deletion packages/icons-react/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,13 +155,17 @@ export const iconStyles = `
`;

export const useInsertStyles = (eleRef: React.RefObject<HTMLElement>) => {
const { csp, prefixCls } = useContext(IconContext);
const { csp, prefixCls, layer } = useContext(IconContext);
let mergedStyleStr = iconStyles;

if (prefixCls) {
mergedStyleStr = mergedStyleStr.replace(/anticon/g, prefixCls);
}

if (layer) {
mergedStyleStr = `@layer ${layer} {\n${mergedStyleStr}\n}`;
}

useEffect(() => {
const ele = eleRef.current;
const shadowRoot = getShadowRoot(ele);
Expand Down
11 changes: 11 additions & 0 deletions packages/icons-react/tests/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -512,4 +512,15 @@ describe('Icon.createFromIconfontCN({scriptUrl:[]})', () => {
const wrapper = render(<CloseCircleFilled />);
expect(wrapper).toMatchSnapshot();
});

it('should support layer', () => {
testingLibRender(
<IconProvider value={{ layer: 'test' }}>
<HomeOutlined />
</IconProvider>,
);

const styleEle = document.querySelector('style')!;
expect(styleEle.innerHTML).toContain('@layer test');
});
});

0 comments on commit d694b4a

Please sign in to comment.