Files
TREK/client/src/components/shared/PluginIcon.tsx
T
Maurice b77c246df4 fix(deps): keep Lucide SVG markup and Undici tests compatible
Build standalone SVG icons without a React context. Use accessible actions in tests and give the mocked dispatchers the interface the adapter expects.
2026-12-01 13:44:02 +01:00

28 lines
1.1 KiB
TypeScript

import type { CSSProperties } from 'react'
import { Blocks, type LucideIcon } from 'lucide-react'
import { lucideIconByName } from './lucideIconLookup'
/**
* Resolves a plugin manifest's `icon` (a lucide icon name, e.g. "Stethoscope") to the
* matching lucide component, falling back to Blocks for a missing or unknown name.
*
* Note lucide icons are forwardRef objects, not functions — never narrow this with
* `typeof x === 'function'`. The lookup returns a module-level reference, so the
* component identity is stable across renders and is safe to call inline while
* building nav/tab arrays.
*/
export function resolvePluginIcon(name: string | null | undefined): LucideIcon {
return lucideIconByName[name ?? ''] ?? Blocks
}
/** Renders the lucide icon a plugin declares in its manifest (Blocks if unknown). */
export default function PluginIcon({ name, size = 20, className, style }: {
name: string | null | undefined
size?: number
className?: string
style?: CSSProperties
}) {
const Icon = resolvePluginIcon(name)
return <Icon size={size} className={className} style={style} />
}