2023-08-28 10:49:18 +08:00
|
|
|
import { useStyleRegister } from '@ant-design/cssinjs';
|
2024-12-06 01:24:12 +08:00
|
|
|
import type { CSSObject } from '@ant-design/cssinjs';
|
2024-04-03 17:12:02 +08:00
|
|
|
|
2024-12-06 01:30:34 +08:00
|
|
|
import { defaultIconPrefixCls } from '../../config-provider';
|
2023-08-28 10:49:18 +08:00
|
|
|
import type { CSPConfig } from '../../config-provider';
|
2024-04-03 17:12:02 +08:00
|
|
|
import { resetIcon } from '../../style';
|
2023-08-28 10:49:18 +08:00
|
|
|
import useToken from '../useToken';
|
|
|
|
|
2024-12-06 01:30:34 +08:00
|
|
|
export const genIconStyle = (iconPrefixCls = defaultIconPrefixCls): CSSObject => ({
|
2024-12-06 01:24:12 +08:00
|
|
|
[`.${iconPrefixCls}`]: {
|
|
|
|
...resetIcon(),
|
|
|
|
[`.${iconPrefixCls} .${iconPrefixCls}-icon`]: {
|
|
|
|
display: 'block',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2023-08-28 10:49:18 +08:00
|
|
|
const useResetIconStyle = (iconPrefixCls: string, csp?: CSPConfig) => {
|
2024-12-06 01:24:12 +08:00
|
|
|
const [theme, token, hashId] = useToken();
|
2023-08-28 10:49:18 +08:00
|
|
|
|
|
|
|
// Generate style for icons
|
|
|
|
return useStyleRegister(
|
|
|
|
{
|
|
|
|
theme,
|
|
|
|
token,
|
2024-12-06 01:24:12 +08:00
|
|
|
hashId,
|
2023-08-28 10:49:18 +08:00
|
|
|
path: ['ant-design-icons', iconPrefixCls],
|
|
|
|
nonce: () => csp?.nonce!,
|
2024-04-03 17:12:02 +08:00
|
|
|
layer: {
|
|
|
|
name: 'antd',
|
|
|
|
},
|
2023-08-28 10:49:18 +08:00
|
|
|
},
|
2024-12-06 01:24:12 +08:00
|
|
|
() => [genIconStyle(iconPrefixCls)],
|
2023-08-28 10:49:18 +08:00
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default useResetIconStyle;
|