"use client"; import "./components/ui/tidal.css"; import { useLayoutEffect, useMemo, useRef, useState } from "react"; import { FileText, Folder, FolderOpen, RotateCcw, X } from "lucide-react"; import { TidalFileBrowser, type TidalFileBrowserItem } from "./components/ui/file-browser"; import "./components/ui/file-browser.css"; const tidalExampleStyles = ".tidal-scope .file-browser-demo {\n width: min(100%, 980px);\n margin-inline: auto;\n}\n\n.tidal-scope .file-browser-demo-detail {\n position: relative;\n min-width: 0;\n}\n\n.tidal-scope .file-browser-demo-detail-mark {\n display: grid;\n width: 46px;\n height: 46px;\n margin-bottom: 34px;\n place-items: center;\n color: var(--t-ink);\n background: var(--t-surface);\n border-radius: 12px;\n box-shadow:\n 8px 8px 0 color-mix(in srgb, var(--t-surface) 18%, transparent),\n 0 0 0 1px color-mix(in srgb, var(--t-surface) 22%, transparent);\n}\n\n.tidal-scope .file-browser-demo-detail-close {\n position: absolute;\n inset-block-start: 0;\n inset-inline-end: 0;\n display: grid;\n width: 44px;\n height: 44px;\n padding: 0;\n place-items: center;\n color: var(--t-surface);\n background: transparent;\n border: 1px solid color-mix(in srgb, var(--t-surface) 34%, transparent);\n border-radius: var(--t-radius-control);\n cursor: pointer;\n transition:\n background 140ms,\n transform 140ms var(--t-ease-out);\n}\n\n.tidal-scope .file-browser-demo-detail-close:hover {\n background: color-mix(in srgb, var(--t-surface) 14%, transparent);\n}\n\n.tidal-scope .file-browser-demo-detail-close:active {\n transform: scale(0.96);\n}\n\n.tidal-scope\n .file-browser-demo-detail\n > span:not(.file-browser-demo-detail-static) {\n display: block;\n color: color-mix(in srgb, var(--t-surface) 67%, transparent);\n font-size: 11px;\n font-weight: 760;\n letter-spacing: 0.13em;\n text-transform: uppercase;\n}\n\n.tidal-scope .file-browser-demo-detail h3 {\n margin: 8px 0 0;\n overflow-wrap: anywhere;\n font-size: clamp(20px, 2.3cqi, 27px);\n line-height: 1;\n letter-spacing: -0.045em;\n}\n\n.tidal-scope .file-browser-demo-detail p {\n margin: 13px 0 0;\n color: color-mix(in srgb, var(--t-surface) 72%, transparent);\n font-size: 11px;\n line-height: 1.55;\n overflow-wrap: anywhere;\n}\n\n.tidal-scope .file-browser-demo-detail dl {\n display: grid;\n grid-template-columns: repeat(2, minmax(0, 1fr));\n gap: 1px;\n margin: 20px 0;\n background: color-mix(in srgb, var(--t-surface) 22%, transparent);\n border: 1px solid color-mix(in srgb, var(--t-surface) 22%, transparent);\n border-radius: 10px;\n overflow: hidden;\n}\n\n.tidal-scope .file-browser-demo-detail dl > div {\n min-width: 0;\n padding: 10px;\n background: var(--t-ink);\n}\n\n.tidal-scope .file-browser-demo-detail dt {\n color: color-mix(in srgb, var(--t-surface) 59%, transparent);\n font-size: 11px;\n letter-spacing: 0.12em;\n text-transform: uppercase;\n}\n\n.tidal-scope .file-browser-demo-detail dd {\n margin: 4px 0 0;\n overflow-wrap: anywhere;\n font-size: 11px;\n}\n\n.tidal-scope .file-browser-demo-detail > a,\n.tidal-scope .file-browser-demo-detail-static {\n display: inline-flex;\n align-items: center;\n justify-content: center;\n width: 100%;\n min-height: 44px;\n padding: 8px 12px;\n color: var(--t-ink);\n background: var(--t-surface);\n border-radius: var(--t-radius-control);\n font-size: 11px;\n font-weight: 760;\n line-height: 1.25;\n text-align: center;\n text-decoration: none;\n overflow-wrap: anywhere;\n}\n\n.tidal-scope .file-browser-demo-detail > a:hover {\n text-decoration: underline;\n text-underline-offset: 3px;\n}\n\n.tidal-scope .file-browser-demo-detail-static {\n color: color-mix(in srgb, var(--t-surface) 72%, transparent);\n background: color-mix(in srgb, var(--t-surface) 10%, transparent);\n border: 1px solid color-mix(in srgb, var(--t-surface) 22%, transparent);\n}\n\n.tidal-scope .file-browser-demo-empty {\n display: grid;\n gap: 4px;\n justify-items: center;\n}\n\n.tidal-scope .file-browser-demo-empty strong {\n color: var(--t-ink);\n font-size: 12px;\n}\n\n.tidal-scope .file-browser-demo-empty span {\n font-size: 11px;\n}\n\n.tidal-scope .file-browser-demo-footer {\n display: flex;\n align-items: center;\n justify-content: space-between;\n gap: 14px;\n}\n\n.tidal-scope .file-browser-demo-footer > span {\n max-width: 64ch;\n}\n\n.tidal-scope .file-browser-demo-footer button {\n display: inline-flex;\n flex: 0 0 auto;\n align-items: center;\n justify-content: center;\n gap: 7px;\n min-width: 44px;\n min-height: 44px;\n padding: 8px 12px;\n color: var(--t-ink);\n background: var(--t-surface);\n border: 1px solid var(--t-border);\n border-radius: var(--t-radius-control);\n font: inherit;\n font-size: 11px;\n font-weight: 720;\n cursor: pointer;\n transition:\n background 140ms,\n transform 140ms var(--t-ease-out);\n}\n\n.tidal-scope .file-browser-demo-footer button:hover {\n background: var(--t-wash);\n}\n\n.tidal-scope .file-browser-demo-footer button:active {\n transform: scale(0.97);\n}\n\n.tidal-scope .file-browser-demo-status {\n min-height: 1.4em;\n margin: 11px 6px 0;\n color: var(--t-muted);\n font-size: 11px;\n line-height: 1.4;\n text-align: center;\n overflow-wrap: anywhere;\n}\n\n@container tidal-file-browser (max-width: 470px) {\n .tidal-scope .file-browser-demo-footer {\n align-items: stretch;\n flex-direction: column;\n }\n\n .tidal-scope .file-browser-demo-footer button {\n width: 100%;\n }\n}\n\n@media (prefers-reduced-motion: reduce) {\n .tidal-scope .file-browser-demo-detail-close:active,\n .tidal-scope .file-browser-demo-footer button:active {\n transform: none;\n }\n}"; type FolderId = "workspace" | "launch"; type SortId = "name" | "recent"; interface SampleItem extends TidalFileBrowserItem { folderTarget?: FolderId; detail: string; } const FILES: Record = { workspace: [ { id: "launch", kind: "folder", name: "Product launch", accessibleName: "Product launch folder", subtitle: "Four sample documents", modified: "Today", modifiedDateTime: "2026-10-14", icon: , folderTarget: "launch", detail: "A local folder containing the launch planning sample.", }, { id: "research", kind: "folder", name: "Research notes", accessibleName: "Research notes folder", subtitle: "Empty fictional folder", modified: "Oct 11", modifiedDateTime: "2026-10-11", icon: , detail: "An empty fictional folder included to demonstrate folder rows.", disabled: true, }, { id: "workspace-readme", kind: "file", name: "Workspace readme.md", accessibleName: "Workspace readme markdown file", subtitle: "Fictional orientation note", size: "3 KB", modified: "Oct 9", modifiedDateTime: "2026-10-09", icon: , detail: "This fictional note explains how the local sample workspace is organized.", }, ], launch: [ { id: "brief", kind: "file", name: "sample-project-brief.txt", accessibleName: "Sample project brief text file", subtitle: "Repository sample document", size: "2 KB", modified: "Today", modifiedDateTime: "2026-10-14", icon: , detail: "The repository includes this fictional text file. Open or download it from the detail panel.", }, { id: "checklist", kind: "file", name: "launch-checklist.md", accessibleName: "Launch checklist markdown file", subtitle: "Fictional checklist summary", size: "6 KB", modified: "Oct 13", modifiedDateTime: "2026-10-13", icon: , detail: "A fictional checklist row. No file is created or read by this preview.", }, { id: "assets", kind: "folder", name: "Approved assets", accessibleName: "Approved assets folder", subtitle: "Fictional folder", modified: "Oct 12", modifiedDateTime: "2026-10-12", icon: , detail: "A fictional folder row with consumer-owned detail content.", }, { id: "notes", kind: "file", name: "review-notes.txt", accessibleName: "Review notes text file", subtitle: "Fictional review notes", size: "4 KB", modified: "Oct 10", modifiedDateTime: "2026-10-10", icon: , detail: "Fictional review notes supplied as display data only. No file access occurs.", }, ], }; export function FileBrowserDemo() { const [folder, setFolder] = useState("launch"); const [query, setQuery] = useState(""); const [sort, setSort] = useState("recent"); const [selected, setSelected] = useState>( () => new Set(["brief"]), ); const [detailId, setDetailId] = useState("brief"); const [message, setMessage] = useState( "Product launch is open. One fictional file is selected.", ); const searchRef = useRef(null); const rowActionRefs = useRef(new Map()); const pendingFocus = useRef<"search" | { rowId: string } | null>(null); const visibleItems = useMemo(() => { const normalizedQuery = query.trim().toLocaleLowerCase(); return FILES[folder] .filter( (item) => !normalizedQuery || `${item.accessibleName} ${String(item.subtitle ?? "")}` .toLocaleLowerCase() .includes(normalizedQuery), ) .slice() .sort((left, right) => { if (sort === "name") { return left.accessibleName.localeCompare(right.accessibleName); } return (right.modifiedDateTime ?? "").localeCompare( left.modifiedDateTime ?? "", ); }) .map((item) => ({ ...item, selected: selected.has(item.id), buttonRef: (node: HTMLButtonElement | null) => { if (node) rowActionRefs.current.set(item.id, node); else rowActionRefs.current.delete(item.id); }, })); }, [folder, query, selected, sort]); const detailItem = visibleItems.find((item) => item.id === detailId); useLayoutEffect(() => { const intent = pendingFocus.current; if (!intent) return; pendingFocus.current = null; const target = intent === "search" ? searchRef.current : rowActionRefs.current.get(intent.rowId); target?.focus({ preventScroll: true }); }, [detailId, folder]); function openFolder(nextFolder: FolderId) { pendingFocus.current = "search"; setFolder(nextFolder); setQuery(""); setDetailId(""); setMessage( nextFolder === "workspace" ? "Sample workspace opened locally." : "Product launch folder opened locally.", ); } function reset() { setFolder("launch"); setQuery(""); setSort("recent"); setSelected(new Set(["brief"])); setDetailId("brief"); setMessage("File browser sample reset. No files or folders changed."); searchRef.current?.focus({ preventScroll: true }); } return (
openFolder("workspace"), }, ...(folder === "launch" ? [ { id: "launch", label: "Product launch", accessibleLabel: "Product launch folder", current: true, }, ] : []), ]} items={visibleItems} search={{ value: query, label: "Search this folder", placeholder: "Search files and folders", inputRef: searchRef, inputProps: { name: "file-query", autoComplete: "off" }, onValueChange: (nextQuery) => { setQuery(nextQuery); setMessage( nextQuery.trim() ? `Showing local matches for “${nextQuery.trim()}”.` : "File search cleared.", ); }, }} sort={{ value: sort, label: "Sort rows", options: [ { value: "recent", label: "Recently modified" }, { value: "name", label: "Name" }, ], onValueChange: (nextSort) => { setSort(nextSort as SortId); setMessage( nextSort === "name" ? "Rows sorted by name." : "Rows sorted by fictional modification date.", ); }, }} onSelectionChange={(item, nextSelected) => { setSelected((current) => { const next = new Set(current); if (nextSelected) next.add(item.id); else next.delete(item.id); return next; }); setMessage( `${item.accessibleName} ${nextSelected ? "selected" : "unselected"}.`, ); }} onOpenItem={(item) => { const sample = item as SampleItem; if (sample.folderTarget) { openFolder(sample.folderTarget); return; } setDetailId(item.id); setMessage(`${item.accessibleName} details opened.`); }} detail={ detailItem ? ( { pendingFocus.current = { rowId: detailItem.id }; setDetailId(""); setMessage("File detail closed."); }} /> ) : null } emptyMessage={
} footer={
Fictional rows and local React state. No filesystem, upload, request, or storage access.
} />

{message}

); } function FileDetail({ item, onClose, }: { item: SampleItem; onClose: () => void; }) { return (
Selected item

{item.name}

{item.detail}

Type
{item.kind}
Size
{item.size ?? "Folder"}
{item.id === "brief" ? ( Download sample brief ) : ( Display-only sample row )}
); } export default function AgentExample() { return (
); }