Skip to content

Commit d5598a7

Browse files
committed
Added icon size prop
1 parent 9d7897a commit d5598a7

File tree

3 files changed

+275
-246
lines changed

3 files changed

+275
-246
lines changed

__tests__/Icon.test.tsx

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { render } from 'enzyme';
2+
import { Icon } from '@/components';
3+
import React from 'react';
4+
5+
describe('Icon test', () => {
6+
it('should render icon', () => {
7+
const container = render(
8+
<div>
9+
<Icon icon="home"/>
10+
</div>
11+
);
12+
13+
expect(container.find('.cui-icon.cui-icon-home').length).toBe(1);
14+
});
15+
16+
it('should render icon with specific size', () => {
17+
const container = render(
18+
<div>
19+
<Icon icon="home" size={12} />
20+
</div>
21+
);
22+
23+
expect(container.find('.cui-icon.cui-icon-home.cui-icon-size-12').length).toBe(1);
24+
});
25+
});

src/components/Icon/Icon.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,14 @@ import { IconName } from '@/components/Icon/IconName';
55

66
interface IconProps extends React.HTMLAttributes<HTMLElement> {
77
icon: IconName | string;
8+
size?: string | number;
89
}
910

1011
const Icon = React.forwardRef<HTMLElement, IconProps>((
1112
{
1213
className,
13-
icon
14+
icon,
15+
size
1416
},
1517
ref
1618
): React.ReactElement => (
@@ -19,6 +21,7 @@ const Icon = React.forwardRef<HTMLElement, IconProps>((
1921
className={clsx(
2022
'cui-icon',
2123
`cui-icon-${icon}`,
24+
size && `cui-icon-size-${size}`,
2225
className
2326
)}
2427
/>
@@ -27,7 +30,8 @@ const Icon = React.forwardRef<HTMLElement, IconProps>((
2730
Icon.displayName = 'Icon';
2831
Icon.propTypes = {
2932
className: PropTypes.string,
30-
icon: PropTypes.string.isRequired
33+
icon: PropTypes.string.isRequired,
34+
size: PropTypes.oneOfType([PropTypes.string, PropTypes.number])
3135
}
3236

3337
export default Icon;

0 commit comments

Comments
 (0)