-
Notifications
You must be signed in to change notification settings - Fork 2.4k
/
Copy pathIcon.tsx
36 lines (32 loc) · 939 Bytes
/
Icon.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import React, { memo, forwardRef } from 'react';
import { useToken, usePropsResolution } from '../../../hooks';
import type { IIconProps } from './types';
import SVGIcon from './SVGIcon';
import { Factory } from '../../../factory';
const Icon = ({ as, ...props }: IIconProps, ref?: any) => {
const { size, ...resolvedProps } = usePropsResolution('Icon', props);
const tokenizedFontSize = useToken('space', size);
if (!as) {
return <SVGIcon size={size} {...resolvedProps} ref={ref} />;
}
const isJSX = React.isValidElement(as);
const StyledAs = Factory(
isJSX
? (resolvedProps) =>
React.cloneElement(as, {
...resolvedProps,
...as.props,
})
: as
);
return (
<StyledAs
{...resolvedProps}
fontSize={tokenizedFontSize}
lineHeight={tokenizedFontSize}
size={size}
ref={ref}
/>
);
};
export default memo(forwardRef(Icon));