From f6bcca0421819f871492f25e92bec9e22420c3ad Mon Sep 17 00:00:00 2001 From: Xevion Date: Fri, 17 Feb 2023 02:07:53 -0600 Subject: [PATCH] Click icons to copy import text to clipboard --- src/components/render/DisplayIconSingle.tsx | 19 ++++++++++++------- src/utils/helpers.ts | 3 +++ 2 files changed, 15 insertions(+), 7 deletions(-) create mode 100644 src/utils/helpers.ts diff --git a/src/components/render/DisplayIconSingle.tsx b/src/components/render/DisplayIconSingle.tsx index 57e095d..bdad492 100644 --- a/src/components/render/DisplayIconSingle.tsx +++ b/src/components/render/DisplayIconSingle.tsx @@ -4,6 +4,7 @@ import {getIcons} from "@utils/getIcons"; import type {IconType} from "react-icons"; import {BiError} from "react-icons/bi"; import {BsQuestionCircle} from "react-icons/bs"; +import {classNames} from "@utils/helpers"; type DisplayIconSingleProps = { id: string; @@ -13,14 +14,16 @@ type DisplayIconSingleProps = { type IconInternalProps = { children?: ReactNode; label: ReactNode; + onClick?: () => void; }; -const IconInternal: FunctionComponent = ({label, children}) => { +const IconInternal: FunctionComponent = ({label, children, onClick}) => { return
- {children ?? } + className={classNames(onClick != undefined ? "cursor-pointer" : null, "group w-32 flex flex-col items-center overflow-clip group-hover:overflow-visible group-hover:z-40")} + onClick={onClick}> + {children ?? } + className="px-1 mt-1 text-[10px]"> {label}
@@ -30,11 +33,13 @@ const DisplayIconSingle: FunctionComponent = ({setId, id // eslint-disable-next-line const IconSet = loadable.lib(() => getIcons(setId)); - return } > + return }> {(module) => { const Icon: IconType | undefined = (module as { [icon: string]: IconType })[id] ?? BiError; - return - + return { + void navigator.clipboard.writeText(`import {${id}} from "react-icons/${setId}";`) + }}> + }} diff --git a/src/utils/helpers.ts b/src/utils/helpers.ts new file mode 100644 index 0000000..03bd2d8 --- /dev/null +++ b/src/utils/helpers.ts @@ -0,0 +1,3 @@ +export function classNames(...classes: (string | undefined | null)[]): string { + return classes.filter(Boolean).join(" "); +} \ No newline at end of file