1
1
import { IconType } from "@flanksource/icons" ;
2
2
import { IconMap as Icons } from "@flanksource/icons/mi" ;
3
3
import { isEmpty } from "lodash" ;
4
- import React , { useMemo } from "react" ;
4
+ import { useMemo } from "react" ;
5
5
6
6
type IconMap = Record < string , string > ;
7
7
export const aliases : IconMap = {
@@ -760,13 +760,28 @@ export const findByName = function (name?: string): IconType | undefined {
760
760
return icon ;
761
761
} ;
762
762
763
+ const iconColorsClasssNamesMap = {
764
+ error : "fill-red-500" ,
765
+ success : "fill-green-500" ,
766
+ healthy : "fill-green-500" ,
767
+ unhealthy : "fill-red-500" ,
768
+ warning : "fill-orange-500" ,
769
+ unknown : "fill-gray-500" ,
770
+ orange : "fill-orange-500" ,
771
+ red : "fill-red-500" ,
772
+ green : "fill-green-500" ,
773
+ blue : "fill-blue-500" ,
774
+ gray : "fill-gray-500"
775
+ } satisfies Readonly < Record < string , string > > ;
776
+
763
777
export type IconProps = {
764
778
name ?: string ;
765
779
secondary ?: string ;
766
780
className ?: string ;
767
781
alt ?: string ;
768
782
prefix ?: any ;
769
783
size ?: any ;
784
+ iconWithColor ?: string ;
770
785
} ;
771
786
772
787
export function Icon ( {
@@ -775,9 +790,20 @@ export function Icon({
775
790
className = "h-6 max-w-6" ,
776
791
alt = "" ,
777
792
prefix,
793
+ iconWithColor,
778
794
...props
779
795
} : IconProps ) {
780
796
const IconSVG = useMemo ( ( ) => {
797
+ if ( iconWithColor ) {
798
+ const [ icon ] = iconWithColor . split ( ":" ) ;
799
+ if ( icon ) {
800
+ const iconType = findByName ( icon ) ;
801
+ if ( iconType ) {
802
+ return iconType ;
803
+ }
804
+ }
805
+ }
806
+
781
807
if ( ! name && ! secondary ) {
782
808
return undefined ;
783
809
}
@@ -792,7 +818,21 @@ export function Icon({
792
818
}
793
819
const secondaryIcon = findByName ( secondary ) ;
794
820
return secondaryIcon ;
795
- } , [ name , secondary ] ) ;
821
+ } , [ iconWithColor , name , secondary ] ) ;
822
+
823
+ const colorClassName = useMemo ( ( ) => {
824
+ if ( iconWithColor ) {
825
+ const [ _ , color ] = iconWithColor . split ( ":" ) ;
826
+ if ( color ) {
827
+ return iconColorsClasssNamesMap [
828
+ color as keyof typeof iconColorsClasssNamesMap
829
+ ] ;
830
+ }
831
+ }
832
+ return "text-gray-700" ;
833
+ } , [ iconWithColor ] ) ;
834
+
835
+ console . log ( "IconSVG" , IconSVG , colorClassName ) ;
796
836
797
837
if ( name && ( name . startsWith ( "http:" ) || name . startsWith ( "https://" ) ) ) {
798
838
// eslint-disable-next-line @next/next/no-img-element
@@ -807,26 +847,9 @@ export function Icon({
807
847
< >
808
848
{ prefix } { " " }
809
849
< IconSVG
810
- className = { `inline-block fill-current object-center text-gray-700 ${ className } ` }
850
+ className = { `inline-block fill-current object-center ${ className } ${ colorClassName } ` }
811
851
{ ...props }
812
852
/>
813
853
</ >
814
854
) ;
815
855
}
816
-
817
- type AvatarProps = React . ImgHTMLAttributes < HTMLImageElement > & {
818
- url : string ;
819
- alt ?: string ;
820
- } ;
821
-
822
- export function Avatar ( { url, alt = "" , ...props } : AvatarProps ) {
823
- return (
824
- // eslint-disable-next-line @next/next/no-img-element
825
- < img
826
- className = "flex h-10 w-10 items-center justify-center rounded-full bg-gray-400 ring-8 ring-white"
827
- src = { url }
828
- alt = { alt }
829
- { ...props }
830
- />
831
- ) ;
832
- }
0 commit comments