mirror of
https://github.com/hanzoai/shadcn.git
synced 2026-11-02 13:07:46 +00:00
Squash merge of shadcn-ui/ui main branch into hanzo/ui, bringing in: - [email protected] through [email protected] releases - New apps/v4 directory structure - Registry system improvements and MCP server - Framework support (Vue, Svelte, React Native) - New templates (vite-app, monorepo-next, laravel) - Zod 4 compatibility (scoped override for zod@>4) - Test fixture corrections for alias resolution All 867 merge conflicts resolved preserving Hanzo customizations. 1020/1020 shadcn tests pass.
52 lines
1.2 KiB
TypeScript
52 lines
1.2 KiB
TypeScript
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
"use client"
|
|
|
|
import { use } from "react"
|
|
import { HugeiconsIcon, type IconSvgElement } from "@hugeicons/react"
|
|
|
|
const iconPromiseCaches = new Map<string, Map<string, Promise<any>>>()
|
|
|
|
function getCache(libraryName: string) {
|
|
if (!iconPromiseCaches.has(libraryName)) {
|
|
iconPromiseCaches.set(libraryName, new Map())
|
|
}
|
|
return iconPromiseCaches.get(libraryName)!
|
|
}
|
|
|
|
function isIconData(data: any): data is IconSvgElement {
|
|
return Array.isArray(data)
|
|
}
|
|
|
|
export function createIconLoader(libraryName: string) {
|
|
const cache = getCache(libraryName)
|
|
|
|
return function IconLoader({
|
|
name,
|
|
strokeWidth = 2,
|
|
...props
|
|
}: {
|
|
name: string
|
|
} & React.ComponentProps<"svg">) {
|
|
if (!cache.has(name)) {
|
|
const promise = import(`./__${libraryName}__`).then((mod) => {
|
|
const icon = mod[name as keyof typeof mod]
|
|
return icon || null
|
|
})
|
|
cache.set(name, promise)
|
|
}
|
|
|
|
const iconData = use(cache.get(name)!)
|
|
|
|
if (!iconData) {
|
|
return null
|
|
}
|
|
|
|
if (isIconData(iconData)) {
|
|
return <HugeiconsIcon icon={iconData} strokeWidth={2} {...props} />
|
|
}
|
|
|
|
const IconComponent = iconData
|
|
return <IconComponent {...props} />
|
|
}
|
|
}
|