Skip to content

Commit

Permalink
Refactor Icons Implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
gigincg committed Oct 12, 2024
1 parent abb7241 commit d84ea85
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 58 deletions.
37 changes: 28 additions & 9 deletions src/CAREUI/icons/CareIcon.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import iconData from "./UniconPaths.json";
import { transformIcons } from "./icon";
import { useEffect } from "react";
import "./icon.css";

export type IconName = keyof typeof iconData;

export interface CareIconProps {
icon: IconName;
className?: string | undefined;
onClick?: React.MouseEventHandler<HTMLSpanElement> | undefined;
className?: string;
onClick?: React.MouseEventHandler<SVGSVGElement>;
id?: string;
}

Expand All @@ -25,12 +24,32 @@ export default function CareIcon({
className,
onClick,
}: CareIconProps) {
const effectiveClassName = icon
? `care-${icon} ${className ?? ""}`
: className;
// TODO: fill & strokeWidth are defined for only one icon
// Rethink Implementation
const [viewBox, path, fill, strokeWidth] = iconData[icon] as [
number,
string,
boolean | undefined,
number | undefined,
];

const svgClassName = `care-svg-icon__baseline ${className || ""}`.trim();

useEffect(() => transformIcons(), [effectiveClassName]);
return (
<i id={id} className={`care ${effectiveClassName}`} onClick={onClick} />
<svg
id={id}
className={`${icon} ${svgClassName}`}
role="img"
xmlns="http://www.w3.org/2000/svg"
onClick={onClick}
viewBox={`0 0 ${viewBox} ${viewBox}`}
>
<path
d={path}
fill={fill === false ? "none" : "currentColor"}
stroke={fill === false ? "currentColor" : undefined}
strokeWidth={fill === false ? strokeWidth : undefined}
/>
</svg>
);
}
49 changes: 0 additions & 49 deletions src/CAREUI/icons/icon.js

This file was deleted.

0 comments on commit d84ea85

Please sign in to comment.