import React from 'react'; import GenericIconMap from './Generics/GenericIconMap'; import MatrixResourceMap from './MatrixResources/MatrixResourceMap'; export const iconSources = { generic: GenericIconMap, matrix: MatrixResourceMap, component: [], }; // The resource sources options export type ResourceSources = keyof typeof iconSources; export type IconOptions = string; /** * Renders an icon based on the resource source and the icon name * @param {{resourceSource?: ResourceSources; icon?: IconOptions; props: React.HTMLAttributes}} props - The props for the Icon component * @returns {React.FunctionComponent} - The icon component * @example * * @example * * @example * * @example * * @example * */ export function Icon({ resourceSource = 'generic', icon, componentIcon, isDecorative = true, ...props }: { icon?: IconOptions; resourceSource?: ResourceSources; isDecorative?: boolean; componentIcon?: React.ReactNode | undefined; } & React.HTMLAttributes & React.SVGAttributes) { if (resourceSource === 'component' && componentIcon !== undefined) { const className = props?.className || ''; return
{componentIcon}
; } const icons = (iconSources[resourceSource] as any) || null; // If the resource source is the current source and the icon is in the current source map, render the icon if (icons && icon && icon in icons) { // Get the icon from the current source map const Icon = icons[icon] as React.FunctionComponent<{ isDecorative: boolean } & React.SVGProps>; // Render the icon return ; } // If the icon is not defined, render the default icon const DefaultIcon = MatrixResourceMap['generic_file']; return ; }