Skip to content

Commit

Permalink
feat: 🎸 [IconWrapper] Added component to centralize Icon usage
Browse files Browse the repository at this point in the history
✅ Closes: 166
  • Loading branch information
luciobordonaro committed Jun 24, 2021
1 parent cb01637 commit c8d6359
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
37 changes: 37 additions & 0 deletions src/components/IconWrapper/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import React, { FC } from "react";

import { IconSize } from "../../types/Icon";
import { IIconWrapper } from "../../types/IconWrapper";
import { logWarn } from "../../utils/logger";
import Icon from "../Icon";

export const DATA_CY_DEFAULT = "icon-wrapper";

const IconWrapper: FC<IIconWrapper> = ({
dataCy = DATA_CY_DEFAULT,
forwarded,
icon,
loading = false,
rotate = false,
size = IconSize.default,
style,
}) => {
if (!icon) {
logWarn("IconWrapper", "Skip rendering, both children and name are not set");
return null;
}

return (
<Icon
dataCy={dataCy}
forwarded={forwarded}
loading={loading}
name={icon}
rotate={rotate}
size={size}
style={style}
/>
);
};

export default IconWrapper;
4 changes: 4 additions & 0 deletions src/types/IconWrapper.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { IBase } from "./Base";
import { IIcon, IPartialIconUtilizer } from "./Icon";

export type IIconWrapper = IBase & IPartialIconUtilizer & Omit<IIcon, "name">;

0 comments on commit c8d6359

Please sign in to comment.