From e0deb2af50f66e519fdc05cab728f3a8b119193c Mon Sep 17 00:00:00 2001 From: Xevion Date: Thu, 16 Feb 2023 04:25:10 -0600 Subject: [PATCH] Add @loader/component based Icon displays --- src/components/render/DisplayIconSingle.tsx | 42 +++++++++++++++++++++ src/components/render/IconCatalog.tsx | 18 +++++++++ 2 files changed, 60 insertions(+) create mode 100644 src/components/render/DisplayIconSingle.tsx create mode 100644 src/components/render/IconCatalog.tsx diff --git a/src/components/render/DisplayIconSingle.tsx b/src/components/render/DisplayIconSingle.tsx new file mode 100644 index 0000000..98b2b41 --- /dev/null +++ b/src/components/render/DisplayIconSingle.tsx @@ -0,0 +1,42 @@ +import type {FunctionComponent, ReactNode} from "react"; +import loadable from "@loadable/component"; +import {getIcons} from "@utils/getIcons"; +import type {IconType} from "react-icons"; +import {BiError} from "react-icons/bi"; +import {BsQuestionCircle} from "react-icons/bs"; + +type DisplayIconSingleProps = { + id: string; + setId: string; +}; + +type IconInternalProps = { + children?: ReactNode; + label: ReactNode; +}; + +const IconInternal: FunctionComponent = ({label, children}) => { + return
+ {children ?? } + + {label} + +
+} + +const DisplayIconSingle: FunctionComponent = ({setId, id}) => { + const IconSet = loadable.lib(() => getIcons(setId)); + + return } > + {(module) => { + const Icon: IconType | undefined = (module as { [icon: string]: IconType })[id] ?? BiError; + return + + + + }} + +} +export default DisplayIconSingle; \ No newline at end of file diff --git a/src/components/render/IconCatalog.tsx b/src/components/render/IconCatalog.tsx new file mode 100644 index 0000000..d2e2078 --- /dev/null +++ b/src/components/render/IconCatalog.tsx @@ -0,0 +1,18 @@ +import type {FunctionComponent} from "react"; +import DisplayIconSingle from "@components/render/DisplayIconSingle"; + +const regex = /^([A-Z][a-z]{1,})[A-Z]\w+$/; + +type Props = { + icons: { id: string, setId: string }[]; +}; + +const IconCatalog: FunctionComponent = ({icons}) => { + return
{icons.map(({id, setId}) => { + return + })} +
+} + +export default IconCatalog; \ No newline at end of file