Files
cal.diy/packages/ui/components/icon/IconProd.tsx
T
3f02de8214 chore: icon cleanup (#13770)
Co-authored-by: Joe Au-Yeung <[email protected]>
Co-authored-by: sean-brydon <[email protected]>
2024-04-03 23:23:57 +00:00

31 lines
825 B
TypeScript

"use client";
// find all lucide icons at https://lucide.dev/
// github https://github.com/lucide-icons/lucide
import type { LucideProps } from "lucide-react";
import { memo } from "react";
import { dynamicIconImports } from "./dynamicIconImports";
export type IconName = keyof typeof dynamicIconImports;
interface IconProps extends Omit<LucideProps, "ref"> {
name: IconName;
}
const fallback = <div className="bg-emphasis h-4 w-4 animate-pulse rounded-lg" />;
const LazyIcon = memo(({ name, ...props }: IconProps) => {
const LucideIcon = dynamicIconImports[name];
// This should never happen, but just in case
if (!LucideIcon) return fallback;
// @ts-expect-error - LucideIcon is a lazy loaded component
return <LucideIcon {...props} />;
});
LazyIcon.displayName = "LazyIcon";
export default LazyIcon;