11import type { Component , JSX } from "solid-js"
2- import { createMemo , splitProps , Show } from "solid-js"
2+ import { createMemo , createUniqueId , splitProps , Show } from "solid-js"
33import sprite from "./file-icons/sprite.svg"
44import type { IconName } from "./file-icons/types"
55
6- let filter = 0
7-
86export type FileIconProps = JSX . GSVGAttributes < SVGSVGElement > & {
97 node : { path : string ; type : "file" | "directory" }
108 expanded ?: boolean
@@ -14,7 +12,7 @@ export type FileIconProps = JSX.GSVGAttributes<SVGSVGElement> & {
1412export const FileIcon : Component < FileIconProps > = ( props ) => {
1513 const [ local , rest ] = splitProps ( props , [ "node" , "class" , "classList" , "expanded" , "mono" ] )
1614 const name = createMemo ( ( ) => chooseIconName ( local . node . path , local . node . type , local . expanded || false ) )
17- const id = `file-icon-mono-${ filter ++ } `
15+ const id = `file-icon-mono-${ createUniqueId ( ) } `
1816 return (
1917 < svg
2018 data-component = "file-icon"
@@ -24,15 +22,14 @@ export const FileIcon: Component<FileIconProps> = (props) => {
2422 [ local . class ?? "" ] : ! ! local . class ,
2523 } }
2624 >
27- < Show when = { local . mono } >
25+ < Show when = { local . mono } fallback = { < use href = { ` ${ sprite } # ${ name ( ) } ` } /> } >
2826 < defs >
29- < filter id = { id } color-interpolation-filters = "sRGB" >
30- < feFlood flood-color = "currentColor" result = "flood" />
31- < feComposite in = "flood" in2 = "SourceAlpha" operator = "in" />
32- </ filter >
27+ < mask id = { id } mask-type = "alpha" >
28+ < use href = { `${ sprite } #${ name ( ) } ` } />
29+ </ mask >
3330 </ defs >
31+ < rect width = "100%" height = "100%" fill = "currentColor" mask = { `url(#${ id } )` } />
3432 </ Show >
35- < use href = { `${ sprite } #${ name ( ) } ` } filter = { local . mono ? `url(#${ id } )` : undefined } />
3633 </ svg >
3734 )
3835}
0 commit comments