"use client"; import "./components/ui/tidal.css"; import { useEffect, useState, type FormEvent } from "react"; import { TidalExportOptions, TidalExportDialog, type TidalExportValue } from "./components/ui/export-dialog"; import { TidalButton } from "./components/ui/tidal-button"; import "./components/ui/export-dialog.css"; import "./components/ui/dialog.css"; import "./components/ui/native-select.css"; const tidalExampleStyles = ".tidal-scope .export-dialog-demo {\n width: 100%;\n max-width: 580px;\n min-width: 0;\n}\n.tidal-scope .export-dialog-demo > .tidal-export-options {\n border: 1px solid var(--t-border);\n border-radius: 18px;\n background: var(--t-surface);\n padding: 26px;\n box-shadow:\n 0 2px 3px #00000003,\n 0 12px 32px #00000005;\n}\n.tidal-scope .export-dialog-note {\n font-size: 11px;\n color: var(--t-muted);\n line-height: 1.6;\n text-align: center;\n margin: 14px 8px 0;\n}\n.tidal-scope .export-dialog-open {\n display: flex;\n margin: 16px auto 0;\n}\n@media (max-width: 400px) {\n .tidal-scope .export-dialog-demo > .tidal-export-options {\n padding: 20px;\n }\n}"; const formats = [ { id: "csv", label: "CSV spreadsheet" }, { id: "json", label: "JSON data" }, ]; const scopes = [ { id: "all", label: "All contacts", detail: "Every row in this sample", countLabel: "3 rows", }, { id: "filtered", label: "Current filter", detail: "Contacts with an active project", countLabel: "2 rows", }, { id: "selected", label: "Selected contacts", detail: "Only the current selection", countLabel: "1 row", }, ]; const fields = [ { id: "name", label: "Name" }, { id: "email", label: "Email address" }, { id: "company", label: "Company" }, { id: "role", label: "Role" }, ]; const rows = [ { name: "Mira Chen", email: "mira@example.com", company: "Northstar", role: "Admin", }, { name: "Jon Bell", email: "jon@example.com", company: "Field Office", role: "Editor", }, { name: "Sam Rivera", email: "sam@example.com", company: "Studio", role: "Viewer", }, ]; export function ExportDialogDemo({ theme = "light", }: { theme?: "light" | "dark"; }) { const [open, setOpen] = useState(false), [value, setValue] = useState({ formatId: "csv", scopeId: "all", fieldIds: ["name", "email", "company", "role"], }), [file, setFile] = useState<{ url: string; name: string; rows: number; } | null>(null); useEffect( () => () => { if (file) URL.revokeObjectURL(file.url); }, [file], ); const update = (next: TidalExportValue) => { setValue(next); setFile(null); }; const prepare = ( next: TidalExportValue, event: FormEvent, ) => { event.preventDefault(); const chosen = rows .slice( 0, next.scopeId === "selected" ? 1 : next.scopeId === "filtered" ? 2 : 3, ) .map((row) => Object.fromEntries( next.fieldIds.map((id) => [id, row[id as keyof typeof row]]), ), ); const text = next.formatId === "json" ? JSON.stringify(chosen, null, 2) : [ next.fieldIds, ...chosen.map((row) => next.fieldIds.map((id) => row[id])), ] .map((row) => row .map( (cell) => '"' + String(cell ?? "").replaceAll('"', '""') + '"', ) .join(","), ) .join("\r\n"); setFile({ url: URL.createObjectURL( new Blob([text], { type: next.formatId === "json" ? "application/json" : "text/csv;charset=utf-8", }), ), name: "sample-contacts." + next.formatId, rows: chosen.length, }); }; const options = { formats, scopes, fields, value, onValueChange: update, onExportRequest: prepare, footer: file ? ( Download {file.name} ) : ( {value.fieldIds.length} fields selected ), }; return (
Open as dialog } />

Files contain fictional sample contacts only.

); } export default function AgentExample() { return (
); }