import React from "react" ; import { hasOwnProperty } from "@next-core/brick-utils" ; import categories from "./generated/categories" ; export interface BrickIconProps { icon : string ; category ? : string ; } export const BrickIcon = ( { category , icon , } ) : React . ReactElement => { const actualCategory = category || "default" ; const [ iconComponent , setIconComponent ] = React . useState < SvgrComponent > ( ) ; React . useEffect ( ( ) => { ( async ( ) => { let component ; if ( hasOwnProperty ( categories , actualCategory ) ) { let categoryIcons = { } ; try { categoryIcons = await categories [ actualCategory ] ( ) ; } catch ( error ) { console . error ( "Load icons failed:" , error ) ; } if ( hasOwnProperty ( categoryIcons , icon ) ) { component = categoryIcons [ icon ] ; } } setIconComponent ( ( ) => component ) ; } ) ( ) ; } , [ icon , actualCategory ] ) ; return iconComponent ? React . createElement ( iconComponent , { width : null , height : null , className : `easyops-icon easyops-icon-${ actualCategory }-${ icon }` , } ) : null ; } ;