Skip to content

FileIcon ​

The icon a file gets in a file tree, and anywhere else its name shows up: a tab, a picker row, a search result. It is the only icon outside Lucide.

tsx
import { FILE_TREE_ICONS, FileIcon } from '@adecore/ui';
tsx
import { FileIcon } from '@adecore/ui';

const FILES = ['src/index.ts', 'App.vue', 'package.json', 'README.md', 'styles.css', 'Dockerfile', 'main.go', 'logo.svg', '.gitignore', 'notes.txt'];

export default function FileIconDemo() {
    return (
        <ul className="grid grid-cols-2 gap-x-8 gap-y-1.5 text-sm text-text">
            {FILES.map((path) => (
                <li key={path} className="flex items-center gap-2">
                    <FileIcon path={path} />
                    {path.slice(path.lastIndexOf('/') + 1)}
                </li>
            ))}
        </ul>
    );
}

The glyphs and colors are those of Seti UI, through the --file-icon-* tokens of the theme. The last segment of the path picks the icon: by whole name (package.json), then a part of it (Dockerfile.dev), then the longest extension (spec.ts before ts). Anything else gets the generic file icon. The icon is hidden from screen readers.

An icon of the app's own ​

setFileIconOverride lets an app draw some files with an icon of its own. The function gets each path and returns the address of an SVG for it, or null to keep the icon from this set. Pass null to remove it. Every mounted FileIcon draws again when you set or remove one. A FileTree does not read it. Its rows keep the icons of FILE_TREE_ICONS.

tsx
setFileIconOverride((path) => (path.endsWith('.acme') ? '/icons/acme.svg' : null));

With a file tree ​

useFileTree already hands a FileTree FILE_TREE_ICONS. Pass it as the icons option yourself only for a @pierre/trees model built without useFileTree.

Props ​

PropTypeDefault
pathstringRequired. Absolute or relative.
sizenumber16In pixels.
classNamestring
refRef<SVGSVGElement | HTMLImageElement>The <img> when an override gives the file its own icon, the <svg> otherwise.

FileIconProps is an exported type.

Licenses and third-party notices are listed in each package.