Skip to content

Commit

Permalink
feat(Icons): create IconFactory HOC util component
Browse files Browse the repository at this point in the history
issue #82
  • Loading branch information
sabertazimi committed Aug 2, 2021
1 parent 922cefb commit bfadb4f
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 9 deletions.
5 changes: 2 additions & 3 deletions src/components/Icons/Close.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import Icon from '@ant-design/icons';
import IconFactory from './IconFactory';

const Svg = () => (
<svg
Expand All @@ -16,6 +16,5 @@ const Svg = () => (
</svg>
);

const Close = (props) => <Icon component={Svg} {...props} />;

const Close = IconFactory(Svg);
export default Close;
5 changes: 2 additions & 3 deletions src/components/Icons/Comment.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import Icon from '@ant-design/icons';
import IconFactory from './IconFactory';

const Svg = () => (
<svg
Expand All @@ -24,6 +24,5 @@ const Svg = () => (
</svg>
);

const Comment = (props) => <Icon component={Svg} {...props} />;

const Comment = IconFactory(Svg);
export default Comment;
5 changes: 2 additions & 3 deletions src/components/Icons/Hamburger.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import Icon from '@ant-design/icons';
import IconFactory from './IconFactory';

const Svg = () => (
<svg
Expand All @@ -16,6 +16,5 @@ const Svg = () => (
</svg>
);

const Hamburger = (props) => <Icon component={Svg} {...props} />;

const Hamburger = IconFactory(Svg);
export default Hamburger;
19 changes: 19 additions & 0 deletions src/components/Icons/IconFactory.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import React from 'react';
import Icon from '@ant-design/icons';

interface Props {
className?: string;
}

type IconType = (props: Props) => JSX.Element;

const IconFactory = (
svg: React.ComponentType<React.SVGProps<SVGSVGElement>>
): IconType => {
const IconComponent = ({ className }: Props): JSX.Element => (
<Icon component={svg} className={className} />
);
return IconComponent;
};

export default IconFactory;

0 comments on commit bfadb4f

Please sign in to comment.