Skip to content

Commit 8cbe7b4

Browse files
committed
fix(app): file icon stability
1 parent 07348d1 commit 8cbe7b4

2 files changed

Lines changed: 8 additions & 10 deletions

File tree

packages/ui/src/components/file-icon.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
[data-component="file-icon"] {
2+
display: block;
23
flex-shrink: 0;
34
width: 16px;
45
height: 16px;

packages/ui/src/components/file-icon.tsx

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
import type { Component, JSX } from "solid-js"
2-
import { createMemo, splitProps, Show } from "solid-js"
2+
import { createMemo, createUniqueId, splitProps, Show } from "solid-js"
33
import sprite from "./file-icons/sprite.svg"
44
import type { IconName } from "./file-icons/types"
55

6-
let filter = 0
7-
86
export 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> & {
1412
export 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

Comments
 (0)