-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathIcon.tsx
More file actions
65 lines (59 loc) · 1.6 KB
/
Icon.tsx
File metadata and controls
65 lines (59 loc) · 1.6 KB
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import { ComponentType } from 'react';
import styled from 'styled-components';
import { getMargin } from '../../theme/utils';
export type IconVariant = 'basic' | 'circle';
export type IconProps = {
variant: IconVariant;
icon: ComponentType;
size:
| string
| {
width: string;
height: string;
};
margin?: string;
color?: string;
bg?: string;
fillIcon?: boolean;
scale?: number;
rotate?: string;
};
const Component = styled.span<Omit<IconProps, 'icon'>>(
({ variant, margin, size, bg, scale, rotate, color, fillIcon, theme }) => ({
...(theme.ICON[variant] || {}),
display: 'inline-block',
margin: getMargin({ theme, margin }),
padding: 0,
width: typeof size === 'string' ? size : size.width,
height: typeof size === 'string' ? size : size.height,
...(bg && theme.COLOR[bg] ? { backgroundColor: theme.COLOR[bg] } : {}),
svg: {
display: 'block',
width: '100%',
height: '100%',
...(scale ? { padding: `${(1 - scale) * 100}%` } : {}),
...(rotate ? { transform: `rotateZ(${rotate})` } : {}),
},
...(fillIcon && {
'svg > *': {
...theme.ICON[variant]['svg > *'],
...(color || theme.ICON[variant].fill
? { fill: color ? theme.COLOR[color] : theme.ICON[variant].fill }
: {}),
}
})
}),
);
export function Icon(iconProps: IconProps) {
const {
variant,
icon: SvgIcon,
scale = variant === 'circle' ? 0.75 : undefined,
...props
} = iconProps;
return (
<Component variant={variant} scale={scale} {...props}>
<SvgIcon />
</Component>
);
}