refactor[genericIconComponent]: Refactor icon to type it properly

This commit is contained in:
Igor Carvalho 2023-07-25 19:48:13 -03:00
commit ff2eb2d13d
3 changed files with 14 additions and 5 deletions

View file

@ -1,3 +1,4 @@
import { ReactElement, SVGProps, createElement } from "react";
import { IconComponentProps } from "../../types/components";
import { nodeIconsLucide } from "../../utils/styleUtils";
@ -7,6 +8,9 @@ export default function IconComponent({
iconColor,
}: IconComponentProps): JSX.Element {
// MAYBE PROBLEM HERE?
const TargetIcon = nodeIconsLucide[name] ?? nodeIconsLucide["unknown"];
return <TargetIcon className={className} style={{ color: iconColor }} />;
const TargetIcon = createElement(nodeIconsLucide[name] ?? nodeIconsLucide["unknown"], {
className,
style: { color: iconColor },
});
return TargetIcon as JSX.Element
}

View file

@ -1,4 +1,4 @@
import { ReactElement, ReactNode } from "react";
import { ForwardRefExoticComponent, ReactElement, ReactNode, RefAttributes, SVGProps } from "react";
import { APIClassType } from "../api";
import { FlowStyleType, NodeDataType } from "../flow/index";
import { typesContextType } from "../typesContext";
@ -83,7 +83,7 @@ export type DisclosureComponentType = {
openDisc: boolean;
button: {
title: string;
Icon: React.Component;
Icon: React.ElementType;
buttons?: {
Icon: ReactElement;
title: string;
@ -305,3 +305,7 @@ export type SanitizedHTMLWrapperType = {
onClick: () => void;
suppressWarning: boolean;
};
export type iconsType = {
[key: string]: React.ElementType;
};

View file

@ -89,6 +89,7 @@ import SvgWikipedia from "../icons/Wikipedia/Wikipedia";
import SvgWolfram from "../icons/Wolfram/Wolfram";
import { HackerNewsIcon } from "../icons/hackerNews";
import { SupabaseIcon } from "../icons/supabase";
import { iconsType } from "../types/components";
export const gradients = [
"bg-gradient-to-br from-gray-800 via-rose-700 to-violet-900",
@ -168,7 +169,7 @@ export const nodeNames: { [char: string]: string } = {
unknown: "Unknown",
};
export const nodeIconsLucide = {
export const nodeIconsLucide: iconsType = {
Chroma: ChromaIcon,
AirbyteJSONLoader: AirbyteIcon,
Anthropic: AnthropicIcon,