File explorer
Project files, with the ones the agent touched marked. Free and MIT licensed, as HTML, a typed React component or an Astro component, in three styles with light and dark mode.
Need this designed into your product? Book a call
Install
Add it to your project with the CLI.
HTML, CSS and JS
npx designme add file-explorerReact
npx designme add file-explorer --reactAstro
npx designme add file-explorer --astroshadcn, React
npx shadcn@latest add https://designme.dev/r/shadcn/file-explorer.json shadcn, Astro
npx shadcn@latest add https://designme.dev/r/shadcn/astro/file-explorer.json The CLI copies the source into your project, so you own it and can change anything. Where each version lands, what it needs and the shadcn theme bridge: Installation.
About
What it is for and what it does.
A project file tree that marks every file the agent changed with M, A or D for modified, added and deleted. Folders that hold a changed file get a dot, so people can find the agent's work without opening every folder. A filter box and an "only changed" switch narrow the tree down.
- When a coding or design agent edits files and people need to see which ones.
- Beside a diff or code viewer, to pick the file to review.
- When a project is large and people want to see only what the agent touched.
- Renders
treeas nested folders and files; a node withchildrenis a folder that opens and closes on click. Each level steps in 14px, and the top level's chevrons sit under the filter's search glyph. - Letters each changed file by its
status('M', 'A' or 'D') in its status colour, and puts a dot on folders with a changed file inside, in the same column. - The filter box keeps names that contain the typed text, along with the folders that lead to them, and opens those folders. When nothing matches it shows an empty state with Clear filter. As the filter or Only changed changes the tree, the rows that stay glide to their new places, new ones rise in and the ones that go fade where they were.
- The "Only changed" button hides every file the agent did not change, and the footer then reads how many files changed, worded by
summary. - Clicking a file selects it, shows its path in the footer and calls
onSelectedChange. - Picks a file icon from the extension, or from your own
fileIconfunction. - The card grows and shrinks with the folders that are open, eased, up to about eleven rows; past that the tree scrolls inside the panel with a thin scrollbar in the style's line grey (square in Blueprint), and its last row fades while there is more below.
- The list has role="tree" and each row has role="treeitem", with aria-expanded on folders and aria-selected on files.
- Each folder's children sit in a role="group", which is inert while the folder is closed.
- A changed file's letter is labelled in words: Modified, Added or Deleted.
- The filter input is labelled "Filter files", and the "Only changed" button uses aria-pressed.
Usage
Import it in React and drive it from your own state, or place it in an Astro page.
React
import { FileExplorer } from '@/components/designme/file-explorer/FileExplorer';React example
The demo above as a React component, 23 lines you can copy.
'use client';
// The preview from designme.dev, rebuilt from the React component: the tree opens on the file being worked on.
import { FileExplorer, type FileExplorerNode } from './FileExplorer';
const TREE: FileExplorerNode[] = [
{ name: 'src', children: [
{ name: 'components', children: [{ name: 'PlanCard.tsx', status: 'M' }, { name: 'PriceTag.tsx', status: 'A' }, { name: 'Button.tsx' }, { name: 'LegacyCTA.tsx', status: 'D' }] },
{ name: 'styles', children: [{ name: 'tokens.css', status: 'M' }, { name: 'globals.css' }] },
{ name: 'pages', children: [{ name: 'pricing.mdx', status: 'M' }, { name: 'index.mdx' }] }
] },
{ name: 'public', children: [{ name: 'og-pricing.png', status: 'A' }, { name: 'favicon.svg' }] },
{ name: 'package.json' }, { name: 'README.md' }
];
/* ---------- File explorer: the agent's changes marked, filter and "only changed" to narrow it down ---------- */
export default function FileExplorerDemo() {
return (
<div style={{ width: '100%' }}>
<FileExplorer tree={TREE} defaultOpen={['src', 'src/components']} defaultSelected="src/components/PlanCard.tsx" />
</div>
);
}
Astro
In a page in src/pages. It plays the demo above; change its file-explorer.js to show your own data. Attributes like class go on its root element.
---
import FileExplorer from '../components/designme/file-explorer/FileExplorer.astro';
---
<FileExplorer />
<FileExplorer data-style="soft" class="my-class" />Props
Everything FileExplorer takes.
| Prop | Type | What it does |
|---|---|---|
treerequired | FileExplorerNode[] | |
open | string[] | Paths of the open folders, like "src/components". Leave it out to let the folders open and close by themselves |
defaultOpen | string[] | |
onOpenChange | (paths: string[]) => void | |
selected | string | Path of the selected file |
defaultSelected | string | |
onSelectedChange | (path: string) => void | |
query | string | The filter text |
defaultQuery | string | |
onQueryChange | (query: string) => void | |
onlyChanged | boolean | Shows only the files the agent changed |
defaultOnlyChanged | boolean | |
onOnlyChangedChange | (only: boolean) => void | |
summary | (changed: number) => string | The footer while only changed files show. Defaults to "6 files changed by the agent" |
fileIcon | (name: string) => IconName | The icon for a file. Defaults to one picked by its extension |
placeholder | string | |
className | string |
Code
The full source, as the CLI installs it.
FileExplorer.tsxReact · 140 lines
'use client';
import { Fragment, useEffect, useRef, useState, type ReactNode } from 'react';
import { cx } from '../lib/cx';
import { useControllable } from '../lib/hooks';
import { Icon, type IconName } from '../lib/icons';
import { enter, Swap, Tip, useGrow, useReflow } from '../lib/motion';
import { useHoverGlide } from '../lib/glide';
import '../designme.css';
import './file-explorer.css';
/** How the agent changed a file: modified, added or deleted */
export type FileExplorerStatus = 'M' | 'A' | 'D';
/** A file, or a folder when it has children */
export interface FileExplorerNode {
name: string;
/** Marks a file the agent changed. Folders with a changed file inside get a dot */
status?: FileExplorerStatus;
children?: FileExplorerNode[];
}
export interface FileExplorerProps {
tree: FileExplorerNode[];
/** Paths of the open folders, like "src/components". Leave it out to let the folders open and close by themselves */
open?: string[];
defaultOpen?: string[];
onOpenChange?: (paths: string[]) => void;
/** Path of the selected file */
selected?: string;
defaultSelected?: string;
onSelectedChange?: (path: string) => void;
/** The filter text */
query?: string;
defaultQuery?: string;
onQueryChange?: (query: string) => void;
/** Shows only the files the agent changed */
onlyChanged?: boolean;
defaultOnlyChanged?: boolean;
onOnlyChangedChange?: (only: boolean) => void;
/** The footer while only changed files show. Defaults to "6 files changed by the agent" */
summary?: (changed: number) => string;
/** The icon for a file. Defaults to one picked by its extension */
fileIcon?: (name: string) => IconName;
placeholder?: string;
className?: string;
}
const WORD: Record<FileExplorerStatus, string> = { M: 'Modified', A: 'Added', D: 'Deleted' };
const changed = (n: FileExplorerNode): boolean => !!n.status || !!n.children?.some(changed);
const count = (ns: FileExplorerNode[]): number => ns.reduce((s, n) => s + (n.children ? count(n.children) : n.status ? 1 : 0), 0);
const matches = (n: FileExplorerNode, q: string): boolean => !q || n.name.toLowerCase().includes(q) || !!n.children?.some(k => matches(k, q));
const iconFor = (name: string): IconName => /\.tsx$/.test(name) ? 'code' : /\.css$/.test(name) ? 'palette' : /\.png|\.svg$/.test(name) ? 'image' : 'file-text';
/** Project files in a tree you can filter, with the ones the agent touched marked. */
export function FileExplorer({
tree, open, defaultOpen = [], onOpenChange, selected, defaultSelected = '', onSelectedChange, query, defaultQuery = '', onQueryChange,
onlyChanged, defaultOnlyChanged = false, onOnlyChangedChange, summary = n => `${n} files changed by the agent`, fileIcon = iconFor,
placeholder = 'Filter files', className
}: FileExplorerProps) {
const [opened, setOpened] = useControllable(open, defaultOpen, onOpenChange);
const [sel, setSel] = useControllable(selected, defaultSelected, onSelectedChange);
const [text, setText] = useControllable(query, defaultQuery, onQueryChange);
const [only, setOnly] = useControllable(onlyChanged, defaultOnlyChanged, onOnlyChangedChange);
const [foot, setFoot] = useState<'selected' | 'summary'>(only ? 'summary' : 'selected');
const q = text.trim().toLowerCase();
// the card grows as folders open and shrinks as they close or the filter narrows (as grow() on the site)
const [root, inner] = useGrow();
// while there is more of the tree below, its last row fades at the edge instead of being cut off (a row's entrance lifts it
// a few pixels, so less than half a row more doesn't count)
const treeRef = useRef<HTMLDivElement>(null), [more, setMore] = useState(false);
// Studio's one hover: a highlight that glides from row to row; the picked file keeps its own fill
useHoverGlide(treeRef, '.dm-fxp-n', { keep: '.dm-sel' });
useEffect(() => {
const t = treeRef.current; if (!t) return;
const edge = () => setMore(t.scrollTop + t.clientHeight < t.scrollHeight - 12);
const ro = new ResizeObserver(edge); ro.observe(t); edge();
t.addEventListener('scroll', edge, { passive: true }); t.addEventListener('transitionend', edge); t.addEventListener('animationend', edge);
return () => { ro.disconnect(); t.removeEventListener('scroll', edge); t.removeEventListener('transitionend', edge); t.removeEventListener('animationend', edge); };
}, []);
// the rows stagger in when the tree first appears; after that a filter or Only changed moves them: the ones that stay glide
// to their new places, new ones rise in out of a short blur and the ones that go fade where they were (motion pieces)
const first = useRef(true);
useEffect(() => { first.current = false; }, []);
useReflow(root, '.dm-fxp-n', { blur: true, host: treeRef });
let index = 0;
const branch = (nodes: FileExplorerNode[], path: string, depth: number): ReactNode[] => nodes
.filter(k => matches(k, q) && (!only || changed(k)))
.map(k => {
const p = path ? path + '/' + k.name : k.name, folder = !!k.children, isOpen = folder && (opened.includes(p) || !!q || only);
const anim = first.current ? enter(index++ * 25) : undefined;
const row = (
<button type="button" role="treeitem" data-key={p} aria-expanded={folder ? isOpen : undefined} aria-selected={folder ? undefined : p === sel}
className={cx('dm-fxp-n', isOpen && 'dm-open', p === sel && 'dm-sel', k.status && 'dm-' + k.status, anim?.className)}
style={{ paddingLeft: 9 + depth * 14, ...anim?.style }}
onClick={() => {
if (folder) setOpened(opened.includes(p) ? opened.filter(x => x !== p) : [...opened, p]);
else { setSel(p); setFoot('selected'); }
}}>
<span className="dm-cv">{folder && <Icon name="chev-r" size="xs" />}</span>
<span className="dm-ic"><Icon name={folder ? 'folder' : fileIcon(k.name)} size="xs" /></span>
<span className="dm-nm">{k.name}</span>
{k.status ? <span className={cx('dm-bd', 'dm-' + k.status)} aria-label={WORD[k.status]}>{k.status}</span> : folder && changed(k) ? <span className="dm-ag" aria-hidden="true" /> : null}
</button>
);
return (
<Fragment key={p}>
{row}
{folder && <div className={cx('dm-fxp-k', !isOpen && 'dm-shut')} role="group" inert={!isOpen}><div>{branch(k.children!, p, depth + 1)}</div></div>}
</Fragment>
);
});
const rows = branch(tree, '', 0);
return (
<div data-dm="" ref={root} className={cx('dm-fxp dm-panel dm-growing dm-mx-grow', className)}>
<div ref={inner} className="dm-grow">
<div className="dm-fxp-h">
<div className="dm-fxp-s">
<Icon name="search" size="xs" />
<input placeholder={placeholder} aria-label="Filter files" spellCheck={false} value={text} onChange={e => setText(e.target.value)} />
</div>
<Tip label="Only changed files">
<button type="button" className="dm-ib dm-fxp-ch dm-mx-press" aria-label="Only changed" aria-pressed={only}
onClick={() => { setOnly(!only); setFoot(only ? 'selected' : 'summary'); }}><Icon name="filter" size="xs" /></button>
</Tip>
</div>
<div ref={treeRef} className={cx('dm-fxp-tree dm-mx-glide', more && 'dm-more')} role="tree" aria-label="Files" hidden={!rows.length}>{rows}</div>
{/* nothing matches the filter: the empty state, and Clear filter brings the tree back */}
{!rows.length && (
<div className="dm-fxp-em"><span className="dm-fxp-em-art" aria-hidden="true" /><b>No matching files</b><span>Nothing in the project is called “{text.trim()}”.</span>
<button type="button" className="dm-pill dm-line dm-sm dm-mx-press" onClick={() => setText('')}>Clear filter</button></div>
)}
<div className="dm-fxp-f dm-muted"><Swap className="dm-fxp-st">{foot === 'summary' ? summary(count(tree)) : sel}</Swap></div>
</div>
</div>
);
}
file-explorer.cssReact · 76 lines
/* Generated from designme.dev by scripts/sync.mjs. Edit the site, then sync. */
/* ---------- File explorer ---------- */
/* the project's files as a tree, with the ones the agent changed lettered M, A or D in their status colour and a dot on
every folder that holds one. Its content is 16px from every edge, on shared columns (owner, 18 Nov): the top level's
chevrons sit centred under the filter's search glyph, each level steps in 14px, and the Only changed button's glyph is
centred over the letters' column; a row's hover and selection fill is the content's width, no wider. The card grows and
shrinks with the folders it has open, smoothly (grow()), up to about eleven rows, then the tree scrolls with a thin
scrollbar and its last row fades while there is more below. A filter that matches nothing shows the empty state */
.dm-fxp{padding:var(--dm-s-4);display:flex;flex-direction:column;gap:var(--dm-s-2)}
/* the filter sits over a hairline and the path under one, in Soft and Blueprint (owner, 21 Nov: "soft and blueprint need
divider lines"), each 8px from it, as the rows are spaced; Studio sets the path on its foot strip */
.dm-fxp-h{display:flex;gap:var(--dm-s-1);align-items:center;padding-bottom:var(--dm-s-4);border-bottom:1px solid color-mix(in srgb,var(--dm-line) 50%,transparent)}
.dm-fxp-s{flex:1;min-width:0;display:flex;align-items:center;gap:var(--dm-s-2);height:32px;padding:0 10px;border-radius:var(--dm-r-field);background:var(--dm-surface);box-shadow:inset 0 0 0 1px color-mix(in srgb,var(--dm-field-line) 50%,transparent);color:var(--dm-muted);transition:box-shadow var(--dm-t-fast)}
@supports (corner-shape:squircle){.dm-fxp-s{corner-shape:squircle;border-radius:var(--dm-r-field-sq)}}
.dm-fxp-s input{flex:1;min-width:0;border:0;outline:0;background:transparent;font:inherit;font-size:13px;color:var(--dm-fg)}
.dm-fxp-s:has(input:focus){box-shadow:inset 0 0 0 1px color-mix(in srgb,var(--dm-field-line-strong) 50%,transparent)}
.dm-fxp-s input::placeholder{color:var(--dm-muted)}
/* Only changed: its box ends on the content's right edge, which puts its glyph over the letters' column */
.dm-fxp-ch{flex:none;width:28px;height:28px}
.dm-fxp-ch[aria-pressed="true"]{background:var(--dm-accent-bg);color:var(--dm-accent-fg,var(--dm-accent))}
.dm-fxp .dm-fxp-tree{max-height:330px;overflow:auto;overscroll-behavior:contain}
.dm-fxp-tree.dm-more{-webkit-mask-image:linear-gradient(180deg,#000 calc(100% - 28px),transparent);mask-image:linear-gradient(180deg,#000 calc(100% - 28px),transparent)}
/* a thin scrollbar in the style's hairline grey, not the browser's thick one */
.dm-fxp-tree{scrollbar-width:thin;scrollbar-color:var(--dm-rail) transparent}
.dm-fxp-tree::-webkit-scrollbar{width:8px;height:8px}
.dm-fxp-tree::-webkit-scrollbar-track{background:transparent}
.dm-fxp-tree::-webkit-scrollbar-thumb{background:var(--dm-rail);border:2px solid transparent;background-clip:padding-box;border-radius:var(--dm-r-pill)}
:root:not([data-style="soft"],[data-style="studio"]) .dm-fxp-tree:not(:where([data-style="soft"],[data-style="soft"] *,[data-style="studio"],[data-style="studio"] *))::-webkit-scrollbar-thumb{border-radius:0}
.dm-fxp-n{display:flex;align-items:center;gap:6px;width:100%;height:30px;padding-right:var(--dm-s-2);border-radius:var(--dm-r-sm);font-size:13px;text-align:left;color:var(--dm-fg2);transition:background-color var(--dm-t-fast) var(--dm-ease),color var(--dm-t-fast) var(--dm-ease)}
@media (hover:hover) and (pointer:fine){.dm-fxp-n:hover{background:var(--dm-row);color:var(--dm-fg)}}
/* rows fill the scrolling tree, which would cut an outside ring: theirs is drawn inside */
.dm-fxp-n:focus-visible{outline-offset:-2px}
/* the open file: the accent tint (Blueprint's lime takes its darker mark so the tint shows on white) */
.dm-fxp-n.dm-sel{background:var(--dm-accent-bg);color:var(--dm-fg)}
:root:not([data-style="soft"],[data-style="studio"]) .dm-fxp-n.dm-sel:not(:where([data-style="soft"],[data-style="soft"] *,[data-style="studio"],[data-style="studio"] *)){background:var(--dm-bp-pick)}
.dm-fxp-n .dm-cv{width:14px;flex:none;display:grid;place-items:center;color:var(--dm-muted);transition:transform var(--dm-t) var(--dm-ease)}
.dm-fxp-n.dm-open .dm-cv{transform:rotate(90deg)}
.dm-fxp-n .dm-ic{color:var(--dm-muted);display:grid;flex:none}
.dm-fxp-n .dm-nm{flex:1;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
/* the agent's change, as a letter in its status colour (4.5:1 on the row, its hover and its selection) */
/* the letters and the folders' dots end on one right edge, 8px inside the row's fill (owner, 21 Nov) */
.dm-fxp-n .dm-bd{flex:none;width:14px;font-size:11px;font-weight:500;line-height:1;text-align:right}
.dm-fxp-n .dm-bd.dm-M{color:var(--dm-warn)}.dm-fxp-n .dm-bd.dm-A{color:var(--dm-ok)}.dm-fxp-n .dm-bd.dm-D{color:var(--dm-bad)}
.dm-fxp-n.dm-D .dm-nm{text-decoration:line-through;color:var(--dm-muted)}
/* a folder that holds a change: a dot, in the letters' column */
.dm-fxp-n .dm-ag{flex:none;width:14px;display:grid;place-items:center end}
.dm-fxp-n .dm-ag::before{content:"";width:6px;height:6px;border-radius:50%;background:var(--dm-accent-mark,var(--dm-accent))}
.dm-fxp-k{display:grid;grid-template-rows:1fr;transition:grid-template-rows var(--dm-t) var(--dm-ease)}
.dm-fxp-k.dm-shut{grid-template-rows:0fr}
.dm-fxp-k>div{overflow:hidden;min-height:0}
.dm-fxp-f{padding-top:var(--dm-s-4);border-top:1px solid color-mix(in srgb,var(--dm-line) 50%,transparent);font-size:12px;line-height:18px;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
.dm-fxp-st{display:block;overflow:hidden;text-overflow:ellipsis}
/* no file matches the filter: the empty state (the lab's): a small sketch of a file list on a white card, a
title, one muted line and Clear filter as an outline button */
.dm-fxp-em{display:flex;flex-direction:column;align-items:center;gap:4px;padding:16px 16px 12px;text-align:center}
.dm-fxp-em[hidden]{display:none}
.dm-fxp-em b{font-size:13.5px;line-height:18px;font-weight:500;color:var(--dm-fg)}
.dm-fxp-em>span:not(.dm-fxp-em-art){max-width:290px;font-size:12.5px;line-height:1.5;color:var(--dm-muted);overflow-wrap:anywhere}
.dm-fxp-em .dm-pill{margin-top:12px}
.dm-fxp-em-art{position:relative;display:block;width:136px;height:70px;margin:0 0 16px;border-radius:calc(10px * var(--dm-rk-l,var(--dm-rk)));background:var(--dm-surface);box-shadow:var(--dm-shadow)}
.dm-fxp-em-art::before{content:"";position:absolute;left:14px;top:14px;width:10px;height:10px;border-radius:3px;background:var(--dm-ghost,var(--dm-chip));box-shadow:0 16px 0 var(--dm-ghost,var(--dm-chip)),0 32px 0 var(--dm-ghost-2,var(--dm-wash))}
.dm-fxp-em-art::after{content:"";position:absolute;left:32px;top:16px;width:58px;height:6px;border-radius:3px;background:var(--dm-ghost,var(--dm-chip));box-shadow:0 16px 0 var(--dm-ghost,var(--dm-chip)),0 32px 0 var(--dm-ghost-2,var(--dm-wash))}
:root:not([data-style="soft"],[data-style="studio"]) .dm-fxp-em-art:not(:where([data-style="soft"],[data-style="soft"] *,[data-style="studio"],[data-style="studio"] *)){box-shadow:0 0 0 1px color-mix(in srgb,var(--dm-rail) 60%,transparent)}
:root:not([data-style="soft"],[data-style="studio"]) :is(.dm-fxp-em-art::before,.dm-fxp-em-art::after):not(:where([data-style="soft"],[data-style="soft"] *,[data-style="studio"],[data-style="studio"] *)){border-radius:0}
/* nothing in it grows or shrinks when it is pressed (owner, 18 Nov) */
.dm-fxp :is(.dm-ib,.dm-pill):active,:root[data-style="studio"] .dm-fxp .dm-ib:active,:root [data-style="studio"] .dm-fxp .dm-ib:active,:root [data-style="studio"].dm-fxp .dm-ib:active{transform:none}
/* Studio (owner, 17 and 18 Nov): its content 16px in from each edge; rows and the field with 10px corners; the path under
the tree on an off-white foot strip with a hairline over it, 16px under the last row */
:root[data-style="studio"] .dm-fxp.dm-panel,:root [data-style="studio"] .dm-fxp.dm-panel,:root [data-style="studio"].dm-fxp.dm-panel{padding:var(--dm-s-4) var(--dm-s-4) 0}
:root[data-style="studio"] .dm-fxp-h,:root [data-style="studio"] .dm-fxp-h,:root [data-style="studio"].dm-fxp-h{padding-bottom:0;border-bottom:0}
:root[data-style="studio"] .dm-fxp-n,:root [data-style="studio"] .dm-fxp-n,:root [data-style="studio"].dm-fxp-n{border-radius:10px}
:root[data-style="studio"] .dm-fxp-n.dm-sel,:root [data-style="studio"] .dm-fxp-n.dm-sel,:root [data-style="studio"].dm-fxp-n.dm-sel{background:var(--dm-row-on)}
:root[data-style="studio"] .dm-fxp-f,:root [data-style="studio"] .dm-fxp-f,:root [data-style="studio"].dm-fxp-f{margin:var(--dm-s-2) calc(-1 * var(--dm-s-4)) 0;padding:calc(var(--dm-strip-y) + 5px) var(--dm-s-4);background:var(--dm-strip);border-top:1px solid var(--dm-line);border-radius:0 0 var(--dm-r-card) var(--dm-r-card)}
:root[data-style="studio"] .dm-fxp-ch,:root [data-style="studio"] .dm-fxp-ch,:root [data-style="studio"].dm-fxp-ch{transition:background-color var(--dm-t-fast) var(--dm-ease),color var(--dm-t-fast) var(--dm-ease)}
:root[data-style="studio"] .dm-fxp-ch[aria-pressed="true"],:root [data-style="studio"] .dm-fxp-ch[aria-pressed="true"],:root [data-style="studio"].dm-fxp-ch[aria-pressed="true"]{background:var(--dm-row-on);color:var(--dm-fg);box-shadow:none}
FileExplorer.astroAstro · 29 lines
---
// Generated from designme.dev by scripts/sync.mjs. Edit the site, then sync.
// File explorer: Project files, with the ones the agent touched marked.
// The markup, CSS and script are designme.dev's own, run by the shared core in ../core, which mounts the component when it scrolls
// into view and plays its demo. To show your own data, change file-explorer.js. The markup is kept exactly as it is (is:raw).
import type { HTMLAttributes } from 'astro/types';
import '../core/designme.css';
import './file-explorer.css';
export interface Props extends HTMLAttributes<'div'> {
/** "soft" or "studio" draws it in that style. Leave it out for Blueprint, or for the style set on <html> (data-style="soft" or "studio") */
'data-style'?: 'soft' | 'studio';
}
const { class: className, ...rest } = Astro.props;
---
<div class:list={['card', className]} data-c="file-explorer" {...rest}>
<div class="stage-in"><Fragment is:raw>
<div class="fxp panel mx-grow" data-reveal="flat">
<div class="fxp-h"><div class="fxp-s"><svg class="i xs"><use href="#i-search"/></svg><input placeholder="Filter files" aria-label="Filter files" spellcheck="false"></div><button class="ib fxp-ch mx-press" aria-label="Only changed" aria-pressed="false" data-tip="Only changed files"><svg class="i xs"><use href="#i-filter"/></svg></button></div>
<div class="fxp-tree mx-glide" role="tree" aria-label="Files"></div>
<div class="fxp-em" hidden><span class="fxp-em-art" aria-hidden="true"></span><b>No matching files</b><span></span><button class="pill line sm mx-press">Clear filter</button></div>
<div class="fxp-f muted"><span class="fxp-st"></span></div>
</div>
</Fragment></div>
</div>
<script>
import './file-explorer.js';
</script>
file-explorer.htmlHTML · 11 lines
<div class="card" data-c="file-explorer">
<div class="stage-in">
<div class="fxp panel mx-grow" data-reveal="flat">
<div class="fxp-h"><div class="fxp-s"><svg class="i xs"><use href="#i-search"/></svg><input placeholder="Filter files" aria-label="Filter files" spellcheck="false"></div><button class="ib fxp-ch mx-press" aria-label="Only changed" aria-pressed="false" data-tip="Only changed files"><svg class="i xs"><use href="#i-filter"/></svg></button></div>
<div class="fxp-tree mx-glide" role="tree" aria-label="Files"></div>
<div class="fxp-em" hidden><span class="fxp-em-art" aria-hidden="true"></span><b>No matching files</b><span></span><button class="pill line sm mx-press">Clear filter</button></div>
<div class="fxp-f muted"><span class="fxp-st"></span></div>
</div>
</div>
</div>
file-explorer.cssHTML · 75 lines
/* ---------- File explorer ---------- */
/* the project's files as a tree, with the ones the agent changed lettered M, A or D in their status colour and a dot on
every folder that holds one. Its content is 16px from every edge, on shared columns (owner, 18 Nov): the top level's
chevrons sit centred under the filter's search glyph, each level steps in 14px, and the Only changed button's glyph is
centred over the letters' column; a row's hover and selection fill is the content's width, no wider. The card grows and
shrinks with the folders it has open, smoothly (grow()), up to about eleven rows, then the tree scrolls with a thin
scrollbar and its last row fades while there is more below. A filter that matches nothing shows the empty state */
.fxp{padding:var(--dm-s-4);display:flex;flex-direction:column;gap:var(--dm-s-2)}
/* the filter sits over a hairline and the path under one, in Soft and Blueprint (owner, 21 Nov: "soft and blueprint need
divider lines"), each 8px from it, as the rows are spaced; Studio sets the path on its foot strip */
.fxp-h{display:flex;gap:var(--dm-s-1);align-items:center;padding-bottom:var(--dm-s-4);border-bottom:1px solid color-mix(in srgb,var(--dm-line) 50%,transparent)}
.fxp-s{flex:1;min-width:0;display:flex;align-items:center;gap:var(--dm-s-2);height:32px;padding:0 10px;border-radius:var(--dm-r-field);background:var(--dm-surface);box-shadow:inset 0 0 0 1px color-mix(in srgb,var(--dm-field-line) 50%,transparent);color:var(--dm-muted);transition:box-shadow var(--dm-t-fast)}
@supports (corner-shape:squircle){.fxp-s{corner-shape:squircle;border-radius:var(--dm-r-field-sq)}}
.fxp-s input{flex:1;min-width:0;border:0;outline:0;background:transparent;font:inherit;font-size:13px;color:var(--dm-fg)}
.fxp-s:has(input:focus){box-shadow:inset 0 0 0 1px color-mix(in srgb,var(--dm-field-line-strong) 50%,transparent)}
.fxp-s input::placeholder{color:var(--dm-muted)}
/* Only changed: its box ends on the content's right edge, which puts its glyph over the letters' column */
.fxp-ch{flex:none;width:28px;height:28px}
.fxp-ch[aria-pressed="true"]{background:var(--dm-accent-bg);color:var(--dm-accent-fg,var(--dm-accent))}
.fxp .fxp-tree{max-height:330px;overflow:auto;overscroll-behavior:contain}
.fxp-tree.more{-webkit-mask-image:linear-gradient(180deg,#000 calc(100% - 28px),transparent);mask-image:linear-gradient(180deg,#000 calc(100% - 28px),transparent)}
/* a thin scrollbar in the style's hairline grey, not the browser's thick one */
.fxp-tree{scrollbar-width:thin;scrollbar-color:var(--dm-rail) transparent}
.fxp-tree::-webkit-scrollbar{width:8px;height:8px}
.fxp-tree::-webkit-scrollbar-track{background:transparent}
.fxp-tree::-webkit-scrollbar-thumb{background:var(--dm-rail);border:2px solid transparent;background-clip:padding-box;border-radius:var(--dm-r-pill)}
:root:not([data-style="soft"],[data-style="studio"]) .fxp-tree:not(:where([data-style="soft"],[data-style="soft"] *,[data-style="studio"],[data-style="studio"] *))::-webkit-scrollbar-thumb{border-radius:0}
.fxp-n{display:flex;align-items:center;gap:6px;width:100%;height:30px;padding-right:var(--dm-s-2);border-radius:var(--dm-r-sm);font-size:13px;text-align:left;color:var(--dm-fg2);transition:background-color var(--dm-t-fast) var(--dm-ease),color var(--dm-t-fast) var(--dm-ease)}
@media (hover:hover) and (pointer:fine){.fxp-n:hover{background:var(--dm-row);color:var(--dm-fg)}}
/* rows fill the scrolling tree, which would cut an outside ring: theirs is drawn inside */
.fxp-n:focus-visible{outline-offset:-2px}
/* the open file: the accent tint (Blueprint's lime takes its darker mark so the tint shows on white) */
.fxp-n.sel{background:var(--dm-accent-bg);color:var(--dm-fg)}
:root:not([data-style="soft"],[data-style="studio"]) .fxp-n.sel:not(:where([data-style="soft"],[data-style="soft"] *,[data-style="studio"],[data-style="studio"] *)){background:var(--dm-bp-pick)}
.fxp-n .cv{width:14px;flex:none;display:grid;place-items:center;color:var(--dm-muted);transition:transform var(--dm-t) var(--dm-ease)}
.fxp-n.open .cv{transform:rotate(90deg)}
.fxp-n .ic{color:var(--dm-muted);display:grid;flex:none}
.fxp-n .nm{flex:1;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
/* the agent's change, as a letter in its status colour (4.5:1 on the row, its hover and its selection) */
/* the letters and the folders' dots end on one right edge, 8px inside the row's fill (owner, 21 Nov) */
.fxp-n .bd{flex:none;width:14px;font-size:11px;font-weight:500;line-height:1;text-align:right}
.fxp-n .bd.M{color:var(--dm-warn)}.fxp-n .bd.A{color:var(--dm-ok)}.fxp-n .bd.D{color:var(--dm-bad)}
.fxp-n.D .nm{text-decoration:line-through;color:var(--dm-muted)}
/* a folder that holds a change: a dot, in the letters' column */
.fxp-n .ag{flex:none;width:14px;display:grid;place-items:center end}
.fxp-n .ag::before{content:"";width:6px;height:6px;border-radius:50%;background:var(--dm-accent-mark,var(--dm-accent))}
.fxp-k{display:grid;grid-template-rows:1fr;transition:grid-template-rows var(--dm-t) var(--dm-ease)}
.fxp-k.shut{grid-template-rows:0fr}
.fxp-k>div{overflow:hidden;min-height:0}
.fxp-f{padding-top:var(--dm-s-4);border-top:1px solid color-mix(in srgb,var(--dm-line) 50%,transparent);font-size:12px;line-height:18px;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
.fxp-st{display:block;overflow:hidden;text-overflow:ellipsis}
/* no file matches the filter: the empty state (the lab's): a small sketch of a file list on a white card, a
title, one muted line and Clear filter as an outline button */
.fxp-em{display:flex;flex-direction:column;align-items:center;gap:4px;padding:16px 16px 12px;text-align:center}
.fxp-em[hidden]{display:none}
.fxp-em b{font-size:13.5px;line-height:18px;font-weight:500;color:var(--dm-fg)}
.fxp-em>span:not(.fxp-em-art){max-width:290px;font-size:12.5px;line-height:1.5;color:var(--dm-muted);overflow-wrap:anywhere}
.fxp-em .pill{margin-top:12px}
.fxp-em-art{position:relative;display:block;width:136px;height:70px;margin:0 0 16px;border-radius:calc(10px * var(--dm-rk-l,var(--dm-rk)));background:var(--dm-surface);box-shadow:var(--dm-shadow)}
.fxp-em-art::before{content:"";position:absolute;left:14px;top:14px;width:10px;height:10px;border-radius:3px;background:var(--dm-ghost,var(--dm-chip));box-shadow:0 16px 0 var(--dm-ghost,var(--dm-chip)),0 32px 0 var(--dm-ghost-2,var(--dm-wash))}
.fxp-em-art::after{content:"";position:absolute;left:32px;top:16px;width:58px;height:6px;border-radius:3px;background:var(--dm-ghost,var(--dm-chip));box-shadow:0 16px 0 var(--dm-ghost,var(--dm-chip)),0 32px 0 var(--dm-ghost-2,var(--dm-wash))}
:root:not([data-style="soft"],[data-style="studio"]) .fxp-em-art:not(:where([data-style="soft"],[data-style="soft"] *,[data-style="studio"],[data-style="studio"] *)){box-shadow:0 0 0 1px color-mix(in srgb,var(--dm-rail) 60%,transparent)}
:root:not([data-style="soft"],[data-style="studio"]) :is(.fxp-em-art::before,.fxp-em-art::after):not(:where([data-style="soft"],[data-style="soft"] *,[data-style="studio"],[data-style="studio"] *)){border-radius:0}
/* nothing in it grows or shrinks when it is pressed (owner, 18 Nov) */
.fxp :is(.ib,.pill):active,:root[data-style="studio"] .fxp .ib:active,:root [data-style="studio"] .fxp .ib:active,:root [data-style="studio"].fxp .ib:active{transform:none}
/* Studio (owner, 17 and 18 Nov): its content 16px in from each edge; rows and the field with 10px corners; the path under
the tree on an off-white foot strip with a hairline over it, 16px under the last row */
:root[data-style="studio"] .fxp.panel,:root [data-style="studio"] .fxp.panel,:root [data-style="studio"].fxp.panel{padding:var(--dm-s-4) var(--dm-s-4) 0}
:root[data-style="studio"] .fxp-h,:root [data-style="studio"] .fxp-h,:root [data-style="studio"].fxp-h{padding-bottom:0;border-bottom:0}
:root[data-style="studio"] .fxp-n,:root [data-style="studio"] .fxp-n,:root [data-style="studio"].fxp-n{border-radius:10px}
:root[data-style="studio"] .fxp-n.sel,:root [data-style="studio"] .fxp-n.sel,:root [data-style="studio"].fxp-n.sel{background:var(--dm-row-on)}
:root[data-style="studio"] .fxp-f,:root [data-style="studio"] .fxp-f,:root [data-style="studio"].fxp-f{margin:var(--dm-s-2) calc(-1 * var(--dm-s-4)) 0;padding:calc(var(--dm-strip-y) + 5px) var(--dm-s-4);background:var(--dm-strip);border-top:1px solid var(--dm-line);border-radius:0 0 var(--dm-r-card) var(--dm-r-card)}
:root[data-style="studio"] .fxp-ch,:root [data-style="studio"] .fxp-ch,:root [data-style="studio"].fxp-ch{transition:background-color var(--dm-t-fast) var(--dm-ease),color var(--dm-t-fast) var(--dm-ease)}
:root[data-style="studio"] .fxp-ch[aria-pressed="true"],:root [data-style="studio"] .fxp-ch[aria-pressed="true"],:root [data-style="studio"].fxp-ch[aria-pressed="true"]{background:var(--dm-row-on);color:var(--dm-fg);box-shadow:none}
file-explorer.jsHTML · 54 lines
DM.def('file-explorer', (r, c) => {
r.innerHTML = r.innerHTML.replace('{search}', I('search','xs')).replace('{filter}', I('filter','xs'));
// Studio's one hover: a highlight that glides from row to row (hoverGlide)
c.offs.push(hoverGlide($('.fxp-tree', r), '.fxp-n', { keep:'.sel' }));
const T = { n:'', k:[
{ n:'src', k:[
{ n:'components', k:[ { n:'PlanCard.tsx', s:'M' }, { n:'PriceTag.tsx', s:'A' }, { n:'Button.tsx' }, { n:'LegacyCTA.tsx', s:'D' } ] },
{ n:'styles', k:[ { n:'tokens.css', s:'M' }, { n:'globals.css' } ] },
{ n:'pages', k:[ { n:'pricing.mdx', s:'M' }, { n:'index.mdx' } ] }
]},
{ n:'public', k:[ { n:'og-pricing.png', s:'A' }, { n:'favicon.svg' } ] },
{ n:'package.json' }, { n:'README.md' }
]};
const root = $('.fxp', r) || r, tree = $('.fxp-tree', r), inp = $('.fxp-s input', r), chB = $('.fxp-ch', r), st = $('.fxp-st', r), em = $('.fxp-em', r);
// the folders open at first: the components the agent changed, with the other folders closed on their dots
const open = new Set(['src','src/components']); let only = false, sel = 'src/components/PlanCard.tsx';
const changed = n => n.s || (n.k && n.k.some(changed));
const match = (n, q) => !q || n.n.toLowerCase().includes(q) || (n.k && n.k.some(k => match(k, q)));
const ext = n => /\.(tsx)$/.test(n) ? 'code' : /\.css$/.test(n) ? 'palette' : /\.png|\.svg$/.test(n) ? 'image' : 'file-text';
// each level steps in 14px from the top level's 9px, which puts its chevrons under the filter's search glyph
function build(n, path, d, q){
return n.k.filter(k => match(k, q) && (!only || changed(k))).map(k => {
const p = path ? path + '/' + k.n : k.n, isD = !!k.k, op = isD && (open.has(p) || !!q || only);
return `<button class="fxp-n${isD && op ? ' open' : ''}${p === sel ? ' sel' : ''}${k.s ? ' ' + k.s : ''}" data-p="${p}" ${isD ? `data-d="1" aria-expanded="${op}"` : `aria-selected="${p === sel}"`} style="padding-left:${9 + d * 14}px" role="treeitem"><span class="cv">${isD ? I('chev-r','xs') : ''}</span><span class="ic">${I(isD ? 'folder' : ext(k.n),'xs')}</span><span class="nm">${k.n}</span>${k.s ? `<span class="bd ${k.s}" aria-label="${{ M:'Modified', A:'Added', D:'Deleted' }[k.s]}">${k.s}</span>` : isD && changed(k) ? '<span class="ag" aria-hidden="true"></span>' : ''}</button>` + (isD ? `<div class="fxp-k${op ? '' : ' shut'}" role="group"${op ? '' : ' inert'}><div>${build(k, p, d + 1, q)}</div></div>` : '');
}).join('');
}
// while there is more of the tree below, its last row fades at the edge instead of being cut off
// (a row's entrance lifts it a few pixels, so less than half a row more doesn't count)
const edge = () => tree.classList.toggle('more', tree.scrollTop + tree.clientHeight < tree.scrollHeight - 12);
c.on(tree, 'scroll', edge, { passive:true }); c.on(tree, 'transitionend', edge); c.on(tree, 'animationend', edge);
const ro = new ResizeObserver(edge); ro.observe(tree); c.offs.push(() => ro.disconnect());
function paint(){
const q = inp.value.trim().toLowerCase();
tree.innerHTML = build(T, '', 0, q);
// nothing matches: the empty state says so, and Clear filter brings the tree back
em.hidden = !!tree.children.length; tree.hidden = !tree.children.length;
if (!tree.children.length) $('span:not(.fxp-em-art)', em).textContent = `Nothing in the project is called “${inp.value.trim()}”.`;
$$('.fxp-n', tree).forEach(b => b.onclick = () => {
if (b.dataset.d){ const p = b.dataset.p, k = b.nextElementSibling; const o = !open.has(p); o ? open.add(p) : open.delete(p); b.classList.toggle('open', o); b.setAttribute('aria-expanded', o); k.classList.toggle('shut', !o); k.inert = !o; }
else { sel = b.dataset.p; $$('.fxp-n:not([data-d])', tree).forEach(x => { x.classList.toggle('sel', x === b); x.setAttribute('aria-selected', x === b); }); swap(st, sel); }
});
requestAnimationFrame(edge);
}
// a filter or Only changed moves the rows: the ones that stay glide to their new places, new ones rise in out of a short blur
// and the ones that go fade where they were (reflow(), motion pieces); the card eases to its new height
const repaint = () => reflow(() => $$('.fxp-n', tree), paint, { by:'data-p', root, host:tree, blur:true });
inp.oninput = repaint;
$('.pill', em).onclick = () => { inp.value = ''; repaint(); inp.focus({ preventScroll:true }); };
chB.onclick = () => { only = !only; chB.setAttribute('aria-pressed', only); swap(st, only ? '6 files changed by the agent' : sel); repaint(); };
st.textContent = sel; paint(); stagger($$('.fxp-n', tree), 25);
// the card grows as folders open and shrinks as they close or the filter narrows (owner, 17 Nov: no room kept for later)
c.offs.push(grow(root));
});
Questions
What people ask about it.
- How do I mark files the agent changed?
- Set
statuson a file node to 'M', 'A' or 'D'. Parent folders work out on their own that they hold a change and show a dot. - How do I open the tree on a particular file?
- Pass the folder paths in
defaultOpen(oropen), like ['src', 'src/components'], and the file's path indefaultSelected(orselected). - How do I load a file when someone clicks it?
- Use
onSelectedChange. It receives the file's path, built from the folder names joined with slashes, like "src/components/PlanCard.tsx". - Can I change the file icons?
- Yes. Pass
fileIcon, a function that takes the file name and returns an icon name.
More in Workspace
Navigation, search, settings, models and automations around the agent.