Attachment tray
Drop files for the agent and watch each one upload. 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
The demo switches between Default, Composer and Context budget. The CLI installs the Default design; the others are previews for now.
Install
Add it to your project with the CLI.
HTML, CSS and JS
npx designme add attachment-trayReact
npx designme add attachment-tray --reactAstro
npx designme add attachment-tray --astroshadcn, React
npx shadcn@latest add https://designme.dev/r/shadcn/attachment-tray.json shadcn, Astro
npx shadcn@latest add https://designme.dev/r/shadcn/astro/attachment-tray.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.
Attachment tray is a drop zone plus a list of the files a person is giving the agent. Each file wears its type's colour: a badge, a progress ring and a wash that fills its row as it uploads. Once it is up the agent reads it, and the file says what the agent found, like "12 pages", with a line underneath saying how many files the agent can read.
- When people hand your agent documents, images or spreadsheets to work from.
- When uploads take long enough that people should see each file's progress before they ask anything.
- When you want a sample-files link so new users can try the agent without their own files.
- Files dropped on the zone or chosen with the file dialog go to
onFilesas a list ofFileobjects.acceptlimits the dialog to certain types. - Each file gets a coloured badge from its extension, like PDF, PNG or CSV, and its size in KB or MB. The badge's colour, red for PDF, violet for images and Figma, green for spreadsheets and blue for the rest, also draws its ring and its upload wash.
progressfrom 0 to 100 closes the ring, shows the percentage after the size and fills the row from the left. At 100 the wash fades and the ring becomes a check. Files that arrive together come in one after another.- Set
readingonce a file is up and the agent is reading it: a spinner takes the ring's place and "Reading" shimmers after the size. Then setdetailto what the agent found, like "12 pages" or "1,204 rows", and it shows after the size. onRemoveadds a remove button to each file and is called after the file has animated out.- The line under the list counts files that are up and read, like "The agent can read 2 files now", unless you pass your own
summary. - The drop zone takes the accent under the pointer. While a file is dragged over it, its dashed edge marches, its arrow bobs and rings spread from the badge.
titlechanges its heading,actionadds a link after "or", anddraggingshows the drag state for a scripted demo. - Ships in Studio too (
data-style="studio"): a round card with 16px all round that grows with its files instead of keeping room for them, and the whole card is the drop target: a file dragged over it turns it grey with a dashed line 8px inside its edge. Empty, it shows a small sketch of a file list, the title, a browse link andactionas a button. Every file sits on the same neutral circle (one colour, not a hue per type), the divider under it fills with ink as it uploads and a green tick draws itself once it is read. Once there are files, an off-white foot strip holds the count, which rolls up, and an Add files button.
- The drop zone wraps a real file input labelled "Choose files", so it also works without dragging. In Studio the browse link holds it, and the foot strip's Add files button holds another, labelled "Add files".
- Each upload ring is a
role="progressbar"witharia-valuenowfrom 0 to 100 and a label naming the file. - Remove buttons are labelled with the file name, like "Remove brief.pdf".
- With reduced motion the edge, the arrow, the rings and the shimmer stay still; the ring and the percentage still show the progress.
Usage
Import it in React and drive it from your own state, or place it in an Astro page.
React
import { AttachmentTray } from '@/components/designme/attachment-tray/AttachmentTray';React example
The demo above as a React component, 46 lines you can copy.
'use client';
// The animated preview from designme.dev, rebuilt from the React component: an example of driving it from your own state.
import { useEffect, useRef, useState } from 'react';
import { useStory } from '../lib/useScript';
import { AttachmentTray, type Attachment } from './AttachmentTray';
/* ---------- Attachment tray: dropped or picked files upload one by one; sample files show the flow ---------- */
const SAMPLES: [string, number, string?][] = [['brief.pdf', 2.4e6, '12 pages'], ['Pricing.fig', 8.1e6, '6 frames'], ['signups.csv', 3.2e5, '1,204 rows']];
export default function AttachmentTrayDemo() {
const [files, setFiles] = useState<Attachment[]>([]);
const [dragging, setDragging] = useState(false);
const count = useRef(0);
count.current = files.length;
const timers = useRef<ReturnType<typeof setInterval>[]>([]);
useEffect(() => () => timers.current.forEach(t => { clearInterval(t); clearTimeout(t); }), []);
// a real app would report upload progress here; the demo fakes it, a little faster or slower each tick
const add = (list: [string, number, string?][]) => list.forEach(([name, size, detail]) => {
const id = Math.random().toString(36).slice(2);
setFiles(fs => [...fs, { id, name, size, progress: 0 }]);
let p = 0;
const iv = setInterval(() => {
p = Math.min(100, p + 2.5 + Math.random() * 5);
setFiles(fs => fs.map(f => f.id === id ? { ...f, progress: p, reading: p >= 100 } : f));
if (p < 100) return;
clearInterval(iv);
// once it is up, the agent reads it and says what it found
timers.current.push(setTimeout(() => setFiles(fs => fs.map(f => f.id === id ? { ...f, reading: false, detail } : f)), 900));
}, 70);
timers.current.push(iv);
});
// once it has entered, three sample files drop in and upload, unless files are already there or you have taken over
const ref = useRef<HTMLDivElement>(null);
useStory(ref, async s => {
await s.wait(950); if (count.current) return;
setDragging(true); s.taken(() => setDragging(false)); await s.wait(1300); setDragging(false);
if (!count.current) add(SAMPLES);
}, { hold: false });
return (
<div ref={ref} style={{ width: '100%' }}>
<AttachmentTray files={files} dragging={dragging} action={{ label: 'add sample files', onClick: () => add(SAMPLES) }}
onFiles={fs => add(fs.map(f => [f.name, f.size]))} onRemove={id => setFiles(fs => fs.filter(f => f.id !== id))} />
</div>
);
}
Astro
In a page in src/pages. It plays the demo above; change its attachment-tray.js to show your own data. Attributes like class go on its root element.
---
import AttachmentTray from '../components/designme/attachment-tray/AttachmentTray.astro';
---
<AttachmentTray />
<AttachmentTray data-style="soft" class="my-class" />Props
Everything AttachmentTray takes.
| Prop | Type | What it does |
|---|---|---|
filesrequired | Attachment[] | |
onFiles | (files: File[]) => void | Files the person dropped on the tray or picked with the file dialog |
onRemove | (id: string) => void | Adds a remove button to each file. Called once the file has animated out |
title | ReactNode | The drop zone's heading (in Studio, the empty state's title) |
action | { label: string; onClick: () => void } | A link after "or" in the drop zone, like "add sample files". In Studio it is a button under the empty state, its label starting with a capital ("Add sample files") |
accept | string | Passed to the file input, like "image/*,.pdf" |
summary | string | The line under the list. Defaults to how many files the agent can read |
dragging | boolean | Shows the drop zone as if a file were being dragged over it, for a scripted demo. A real drag shows it by itself |
className | string |
Code
The full source, as the CLI installs it.
AttachmentTray.tsxReact · 179 lines
'use client';
import { useEffect, useRef, useState, type ChangeEvent, type CSSProperties, type DragEvent, type ReactNode } from 'react';
import { cx } from '../lib/cx';
import { useIsoLayoutEffect } from '../lib/hooks';
import { Icon } from '../lib/icons';
import { growFit, Swap, Tip } from '../lib/motion';
import '../designme.css';
import './attachment-tray.css';
export interface Attachment {
id: string;
name: string;
/** In bytes */
size: number;
/** 0 to 100. The ring closes and the row fills with the file type's colour; at 100 the ring turns into a check */
progress: number;
/** After the upload, while the agent reads the file: a spinner, and "Reading" shimmering after the size */
reading?: boolean;
/** What the agent found once it has read the file, like "12 pages", shown after the size */
detail?: string;
}
export interface AttachmentTrayProps {
files: Attachment[];
/** Files the person dropped on the tray or picked with the file dialog */
onFiles?: (files: File[]) => void;
/** Adds a remove button to each file. Called once the file has animated out */
onRemove?: (id: string) => void;
/** The drop zone's heading (in Studio, the empty state's title) */
title?: ReactNode;
/** A link after "or" in the drop zone, like "add sample files". In Studio it is a button under the empty state, its label
* starting with a capital ("Add sample files") */
action?: { label: string; onClick: () => void };
/** Passed to the file input, like "image/*,.pdf" */
accept?: string;
/** The line under the list. Defaults to how many files the agent can read */
summary?: string;
/** Shows the drop zone as if a file were being dragged over it, for a scripted demo. A real drag shows it by itself */
dragging?: boolean;
className?: string;
}
// the badge for a file type: its letters, its colour and its background
const kind = (name: string): [string, string, string] => {
const e = (name.split('.').pop() || '').toLowerCase();
if (e === 'pdf') return ['PDF', 'var(--dm-pr)', 'var(--dm-pr-bg)'];
if (/png|jpg|jpeg|gif|webp|fig/.test(e)) return [e.toUpperCase().slice(0, 3), 'var(--dm-pl)', 'var(--dm-pl-bg)'];
if (/csv|xlsx/.test(e)) return ['CSV', 'var(--dm-pm)', 'var(--dm-pm-bg)'];
return [e.toUpperCase().slice(0, 3) || 'TXT', 'var(--dm-pb)', 'var(--dm-pb-bg)'];
};
const bytes = (b: number) => b > 1e6 ? (b / 1e6).toFixed(1) + ' MB' : Math.max(1, Math.round(b / 1e3)) + ' KB';
const RING = 50.3;
function Item({ file, delay, onRemove, studio }: { file: Attachment; delay: number; onRemove?: (id: string) => void; studio?: boolean }) {
const [leaving, setLeaving] = useState(false);
const t = useRef<ReturnType<typeof setTimeout>>(undefined);
useEffect(() => () => clearTimeout(t.current), []);
const [label, fg, bg] = kind(file.name), p = Math.max(0, Math.min(100, file.progress)) / 100, up = p >= 1;
const meta = !up ? `${bytes(file.size)} · ${Math.round(p * 100)}%` : file.detail && !file.reading ? `${bytes(file.size)} · ${file.detail}` : bytes(file.size);
return (
<div className={cx('dm-atx-it', up && 'dm-up', leaving ? 'dm-leave' : 'dm-enter')}
style={{ '--dm-c': fg, '--dm-cb': bg, '--dm-p': `${(p * 100).toFixed(1)}%`, ...(leaving ? {} : { animationDelay: delay + 'ms' }) } as CSSProperties}>
{/* Studio: one neutral circle for every file type (the type's hue is Soft's and Blueprint's) */}
<span className="dm-atx-ti">{label}</span>
<span className="dm-atx-n"><span className="dm-atx-nm">{file.name}</span>
{/* the percentage counts in place; the line crossfades when the file moves on to being read and to what was found */}
{!up ? <span className="dm-atx-m dm-num">{meta}</span>
: file.reading ? <span className="dm-atx-m"><span className="dm-shim">{bytes(file.size)} · Reading</span></span> : <Swap className="dm-atx-m">{meta}</Swap>}
</span>
{up
? file.reading ? <span className="dm-atx-rd"><span className="dm-spin" aria-hidden="true" /></span>
// Studio: a green disc lands and its tick draws itself
: <span className="dm-atx-ok">{studio ? <span className="dm-atx-okc"><svg viewBox="0 0 16 16" aria-hidden="true"><path pathLength={1} d="M4.6 8.3l2.3 2.3 4.5-4.8" /></svg></span> : <Icon name="ok" />}</span>
: <svg className="dm-atx-ring" viewBox="0 0 22 22" role="progressbar" aria-label={`Uploading ${file.name}`} aria-valuemin={0} aria-valuemax={100} aria-valuenow={Math.round(p * 100)}>
<circle cx="11" cy="11" r="8" fill="none" stroke="var(--dm-line)" strokeWidth="2" />
<circle cx="11" cy="11" r="8" fill="none" stroke={fg} strokeWidth="2" strokeLinecap="round" strokeDasharray={RING} transform="rotate(-90 11 11)" style={{ strokeDashoffset: RING * (1 - p) }} />
</svg>}
{onRemove && (
<Tip label="Remove">
<button type="button" className="dm-ib dm-mx-press" aria-label={`Remove ${file.name}`} disabled={leaving}
onClick={() => { setLeaving(true); t.current = setTimeout(() => onRemove(file.id), 320); }}><Icon name="x" size="xs" /></button>
</Tip>
)}
{/* Studio: the divider under the text, which is the upload's rail; its ink fill follows the progress */}
{studio && <span className="dm-atx-ln" aria-hidden="true"><i /></span>}
</div>
);
}
/** The dashed edge of the drop zone, drawn in SVG so its dashes can march around the corners. It follows the zone's size and
* corner radius, and spaces the dashes so they meet evenly all the way round */
function Ants() {
const svg = useRef<SVGSVGElement>(null);
const [g, setG] = useState<{ w: number; h: number; rx: number; ap: number; ag: number } | null>(null);
useIsoLayoutEffect(() => {
// the drop zone is the parent; its own ref isn't attached yet when this first runs
const el = svg.current?.parentElement; if (!el) return;
const fit = () => {
const w = el.offsetWidth, h = el.offsetHeight; if (!w || !h) return;
const k = .75, rx = Math.max(0, Math.min(parseFloat(getComputedStyle(el).borderTopLeftRadius) || 0, w / 2, h / 2) - k);
const per = 2 * (w + h - 4 * k) - (8 - 2 * Math.PI) * rx, step = per / Math.max(8, Math.round(per / 11));
setG({ w: w - 2 * k, h: h - 2 * k, rx, ap: step, ag: step - 4.5 });
};
fit();
const ro = new ResizeObserver(fit); ro.observe(el);
return () => ro.disconnect();
}, []);
return (
<svg ref={svg} className="dm-atx-ants" aria-hidden="true">
{g && <rect x={.75} y={.75} width={g.w} height={g.h} rx={g.rx} style={{ '--dm-ap': g.ap + 'px', '--dm-ag': g.ag + 'px' } as CSSProperties} />}
</svg>
);
}
/** Drop files for the agent and watch each one upload, in its file type's colour, then get read. */
export function AttachmentTray({ files, onFiles, onRemove, title = 'Drop files here', action, accept, summary, dragging, className }: AttachmentTrayProps) {
const [over, setOver] = useState(false);
// files that arrive together come in one after another
const ids = files.map(f => f.id).join('\u0000');
const [seen, setSeen] = useState<{ ids: string; delay: Record<string, number> }>({ ids, delay: {} });
if (seen.ids !== ids) {
const old = new Set(seen.ids.split('\u0000')), delay = { ...seen.delay };
let k = 0; for (const f of files) if (!old.has(f.id)) delay[f.id] = k++ * 80;
setSeen({ ids, delay });
}
const hold = (e: DragEvent) => { e.preventDefault(); setOver(true); };
// in Studio the card holds the rows and buttons, so moving between them is not leaving it
const leave = (e: DragEvent) => { if (studio && e.currentTarget.contains(e.relatedTarget as Node | null)) return; setOver(false); };
const dropped = (e: DragEvent) => { e.preventDefault(); setOver(false); if (e.dataTransfer.files.length) onFiles?.(Array.from(e.dataTransfer.files)); };
// (the file inputs carry an empty title, so the browser's own "No file chosen" tip never shows over them)
const picked = (e: ChangeEvent<HTMLInputElement>) => { if (e.target.files?.length) onFiles?.(Array.from(e.target.files)); e.target.value = ''; };
const read = files.filter(f => f.progress >= 100 && !f.reading).length;
const line = summary ?? (read ? `The agent can read ${read} ${read > 1 ? 'files' : 'file'} now` : '');
// Studio (data-style="studio" on the page or around the tray) is a card that grows with its files and is the drop target
// as a whole. Empty, it shows Studio's empty state (a sketch of a file list, the title, a browse link and the action as a
// button); with files, a foot strip holds the count, which rolls, and Add files. Soft and Blueprint are as they were
const root = useRef<HTMLDivElement>(null), inner = useRef<HTMLDivElement>(null);
const [studio, setStudio] = useState(false);
useIsoLayoutEffect(() => { setStudio(root.current?.closest('[data-style]')?.getAttribute('data-style') === 'studio'); }, []);
useIsoLayoutEffect(() => { const el = root.current, w = inner.current; if (studio && el && w) return growFit(el, w); }, [studio]);
const list = <div className="dm-atx-list">{files.map(f => <Item key={f.id} file={f} delay={seen.delay[f.id] ?? 0} onRemove={onRemove} studio={studio} />)}</div>;
const body = !studio ? (<>
<label className={cx('dm-atx-drop', (over || dragging) && 'dm-over')} onDragEnter={hold} onDragOver={hold} onDragLeave={leave} onDrop={dropped}>
<input type="file" multiple accept={accept} className="dm-atx-file" aria-label="Choose files" title="" onChange={picked} />
<Ants />
<span className="dm-atx-ic"><Icon name="upload" /></span>
<b>{title}</b>
{action && <span className="dm-muted">or <button type="button" className="dm-atx-sample" onClick={action.onClick}>{action.label}</button></span>}
</label>
{list}
<Swap className="dm-atx-sum dm-muted">{line}</Swap>
</>) : (<>
{list}
{/* the empty state comes after the list so CSS shows it only while the list is empty, and the strip only once it isn't */}
<div className="dm-atx-em">
<span className="dm-atx-em-art" aria-hidden="true" />
<b>{title}</b>
<span>or <label className="dm-atx-br">browse your files<input type="file" multiple accept={accept} className="dm-atx-file" aria-label="Choose files" title="" onChange={picked} /></label></span>
{action && <button type="button" className="dm-pill dm-line dm-sm dm-atx-smp" onClick={action.onClick}><Icon name="plus" size="xs" />{action.label.charAt(0).toUpperCase() + action.label.slice(1)}</button>}
</div>
<div className="dm-atx-ft">
<div className="dm-atx-sum dm-muted">{line && <>
<span className="dm-atx-tk"><Icon name="check" size="xs" /></span>
{summary != null ? <span>{summary}</span>
: <span>The agent can read <span className="dm-atx-roll dm-num"><i key={read} className="dm-in">{read}</i></span> {read > 1 ? 'files' : 'file'} now</span>}
</>}</div>
<label className="dm-pill dm-line dm-sm dm-atx-add"><Icon name="plus" size="xs" />Add files<input type="file" multiple accept={accept} className="dm-atx-file" aria-label="Add files" title="" onChange={picked} /></label>
</div>
</>);
return (
<div data-dm="" ref={root} className={cx('dm-atx dm-mx-grow', studio && 'dm-growing', studio && (over || dragging) && 'dm-over', className)}
{...(studio ? { onDragEnter: hold, onDragOver: hold, onDragLeave: leave, onDrop: dropped } : {})}>
{studio ? <div className="dm-grow" ref={inner}>{body}</div> : body}
</div>
);
}
attachment-tray.cssReact · 134 lines
/* Generated from designme.dev by scripts/sync.mjs. Edit the site, then sync. */
/* ---------- Attachment tray ---------- */
/* a drop zone, then the files as plain rows. Each file wears its type's hue: its badge, its ring and the wash that fills its
row from the left as it uploads. Once it is up the agent reads it (the line shimmers) and says what it found, like 12 pages */
.dm-atx{display:flex;flex-direction:column;gap:10px}
/* its motion (the core's motion pieces, owner, 26 Nov): a press on a file's remove button shows at once (.mx-press), and in
Studio the card grows with its files on the spring (.mx-grow) */
.dm-atx-drop{display:flex;flex-direction:column;align-items:center;gap:6px;padding:26px var(--dm-s-4);border-radius:var(--dm-r-card);background:none;cursor:pointer;position:relative;font-size:13.5px;transition:background .35s,box-shadow .35s,transform .45s var(--dm-ease)}
/* the dashed edge is drawn in SVG so its dashes can march around the corners: drifting slowly at rest, taking the accent
under the pointer, and marching faster while a file is dragged over */
.dm-atx-ants{position:absolute;inset:0;width:100%;height:100%;overflow:visible;pointer-events:none}
.dm-atx-ants rect{fill:none;stroke:var(--dm-faint);stroke-width:1.5;stroke-linecap:round;stroke-dasharray:4.5px var(--dm-ag,6.5px);transition:stroke .35s}
@keyframes dm-atxants{to{stroke-dashoffset:calc(var(--dm-ap,11px) * -1)}}
.dm-atx-drop.dm-over{background:var(--dm-accent-bg)}
@media (hover:hover) and (pointer:fine){.dm-atx-drop:hover{background:var(--dm-accent-bg)}}
.dm-atx-drop.dm-over .dm-atx-ants rect{stroke:var(--dm-accent-mark,var(--dm-accent))}
@media (hover:hover) and (pointer:fine){.dm-atx-drop:hover .dm-atx-ants rect{stroke:var(--dm-accent-mark,var(--dm-accent))}}
.dm-atx-ants rect{animation:dm-atxants 2.6s linear infinite}
.dm-atx-drop.dm-over .dm-atx-ants rect{animation-duration:.9s}
.dm-atx-drop.dm-over{transform:scale(1.015)}
.dm-atx-file{position:absolute;inset:0;opacity:0;cursor:pointer}
/* the file input is clear over the drop zone, so the zone shows its focus */
.dm-atx-drop:has(.dm-atx-file:focus-visible){outline:2px solid var(--dm-focus);outline-offset:2px}
.dm-atx-ic{position:relative;width:34px;height:34px;border-radius:calc(11px * var(--dm-rk-l,var(--dm-rk)));background:var(--dm-surface);box-shadow:var(--dm-shadow);display:grid;place-items:center;color:var(--dm-fg2);transition:transform .45s var(--dm-ease),background .35s,color .35s}
.dm-atx-drop.dm-over .dm-atx-ic{transform:translateY(-3px);background:var(--dm-surface);color:var(--dm-accent-fg,var(--dm-accent))}
@media (hover:hover) and (pointer:fine){.dm-atx-drop:hover .dm-atx-ic{transform:translateY(-3px);background:var(--dm-surface);color:var(--dm-accent-fg,var(--dm-accent))}}
/* while a file is over the zone its arrow bobs, and rings spread from the badge */
.dm-atx-drop.dm-over .dm-atx-ic .dm-i{animation:dm-atxbob .9s var(--dm-ease-io) infinite}
@keyframes dm-atxbob{50%{transform:translateY(-2px)}}
.dm-atx-ic::before,.dm-atx-ic::after{content:"";position:absolute;inset:0;border-radius:inherit;box-shadow:0 0 0 1.5px var(--dm-accent-mark,var(--dm-accent));opacity:0;pointer-events:none}
.dm-atx-drop.dm-over .dm-atx-ic::before{animation:dm-atxring 1.4s var(--dm-ease) infinite}
.dm-atx-drop.dm-over .dm-atx-ic::after{animation:dm-atxring 1.4s var(--dm-ease) .7s infinite}
@keyframes dm-atxring{from{opacity:.5;transform:scale(1)}to{opacity:0;transform:scale(1.9)}}
.dm-atx-sample{color:var(--dm-accent-fg,var(--dm-accent));font-weight:500;position:relative;z-index:1}
.dm-atx-list{display:flex;flex-direction:column;gap:2px}
.dm-atx-it{--dm-p:0%;position:relative;display:flex;align-items:center;gap:10px;padding:var(--dm-s-2) 6px var(--dm-s-2) var(--dm-s-2);border-radius:var(--dm-r-in);overflow:hidden;background:linear-gradient(90deg,color-mix(in srgb,var(--dm-c,var(--dm-accent)) 8%,transparent) calc(var(--dm-p) - 24px),color-mix(in srgb,var(--dm-c,var(--dm-accent)) 16%,transparent) calc(var(--dm-p) - 1px),transparent var(--dm-p)) no-repeat}
/* the wash fades once the file is up */
.dm-atx-it.dm-up{background-size:0 100%;transition:background-size .6s var(--dm-ease) .2s}
.dm-atx-ti{width:30px;height:30px;border-radius:calc(9px * var(--dm-rk-m,var(--dm-rk)));display:grid;place-items:center;flex:none;font-size:9.5px;font-weight:500;letter-spacing:.02em;color:var(--dm-c);background:var(--dm-cb)}
.dm-atx-n{flex:1;min-width:0;font-size:13px}
.dm-atx-nm{display:block;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
.dm-atx-m{display:block;font-size:12px;color:var(--dm-muted);white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
.dm-atx-m .dm-shim{font-size:inherit}
/* on the wash, the line steps up a grey so it keeps its contrast */
.dm-atx-it:not(.dm-up) .dm-atx-m{color:var(--dm-fg2)}
.dm-atx-ring{width:22px;height:22px;flex:none}
.dm-atx-ring circle{transition:stroke-dashoffset .3s linear}
.dm-atx-ok{display:grid;place-items:center;width:22px;flex:none;color:var(--dm-ok)}
.dm-atx-ok .dm-i{animation:dm-atxpop .45s var(--dm-ease) backwards}
@keyframes dm-atxpop{0%{transform:scale(.4);opacity:0}60%{transform:scale(1.15);opacity:1}100%{transform:none}}
.dm-atx-rd{display:grid;place-items:center;width:22px;flex:none;color:var(--dm-c)}
.dm-atx-rd .dm-spin{width:12px;height:12px}
/* (a file's remove button is a 28px icon button, as most icon buttons in a row are) */
.dm-atx-it .dm-ib{width:28px;height:28px;flex:none}
.dm-atx-sum{font-size:12.5px;text-align:center;min-height:18px}
:root:not([data-style="soft"],[data-style="studio"]) .dm-atx-it:not(:where([data-style="soft"],[data-style="soft"] *,[data-style="studio"],[data-style="studio"] *)){background:linear-gradient(var(--dm-c,var(--dm-accent)),var(--dm-c,var(--dm-accent))) 0 100%/var(--dm-p) 2px no-repeat}
:root:not([data-style="soft"],[data-style="studio"]) .dm-atx-it.dm-up:not(:where([data-style="soft"],[data-style="soft"] *,[data-style="studio"],[data-style="studio"] *)){background-size:0 2px}
:root:not([data-style="soft"],[data-style="studio"]) .dm-atx-drop.dm-over .dm-atx-ic:not(:where([data-style="soft"],[data-style="soft"] *,[data-style="studio"],[data-style="studio"] *))::before{animation:dm-atxringbp 1s steps(4,end) infinite}
:root:not([data-style="soft"],[data-style="studio"]) .dm-atx-drop.dm-over .dm-atx-ic:not(:where([data-style="soft"],[data-style="soft"] *,[data-style="studio"],[data-style="studio"] *))::after{animation:none}
@keyframes dm-atxringbp{from{opacity:.6;transform:scale(1)}to{opacity:0;transform:scale(1.6)}}
:root:not([data-style="soft"],[data-style="studio"]) .dm-atx-ok .dm-i:not(:where([data-style="soft"],[data-style="soft"] *,[data-style="studio"],[data-style="studio"] *)){animation:none}
/* Studio (owner, 18 Nov): one card that grows as files arrive (grow()), its content 16px from each edge, and the whole card is
the drop target: a file dragged over it fills it with the row grey and draws a dashed hairline 8px in from its edge. Empty,
it shows Studio's empty state (.atx-em): a small sketch of a file list on a white card, the title, one muted line with a
browse link, and Add sample files. Files are rows with hairline dividers under their text: one neutral grey circle with the
type's letters for every file (owner, 18 Nov: one colour, not a hue per type), and while a file uploads its divider becomes
a rail that fills with ink, the same for every file, a soft sheen running along
it while the agent reads, then fades as a green tick draws itself. Once there are files, the off-white foot strip (.atx-ft)
says what the agent can read, its count rolling as each file is read, and holds Add files 16px from the card's side and
bottom and from the strip's hairline (owner, 23 Nov) */
/* (the dashed hairline is an outline drawn 8px inside the card, so it follows the card's corners) */
:root[data-style="studio"] .dm-atx,:root [data-style="studio"] .dm-atx,:root [data-style="studio"].dm-atx{position:relative;gap:0;background:var(--dm-surface);border-radius:var(--dm-r-card);box-shadow:var(--dm-shadow);overflow:clip;outline:1px dashed transparent;outline-offset:-9px;transition:background-color var(--dm-t-fast) var(--dm-ease),outline-color var(--dm-t-fast) var(--dm-ease)}
:root[data-style="studio"] .dm-atx.dm-over,:root [data-style="studio"] .dm-atx.dm-over,:root [data-style="studio"].dm-atx.dm-over{background:var(--dm-row);outline-color:var(--dm-faint)}
/* the empty state, the lab's: the sketch is a white card with a hairline and three rows, each a square and a bar,
fading downward; under it the title, one grey line and a secondary button */
.dm-atx-em{display:flex;flex-direction:column;align-items:center;gap:4px;padding:16px;text-align:center}
.dm-atx-em b{font-size:13.5px;line-height:18px;font-weight:500;color:var(--dm-fg)}
.dm-atx-em>span:not(.dm-atx-em-art){max-width:290px;font-size:12.5px;line-height:1.5;color:var(--dm-muted)}
.dm-atx-em .dm-pill{margin-top:12px}
.dm-atx-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-atx-em-art::before{content:"";position:absolute;left:14px;top:14px;width:10px;height:10px;border-radius:3px;background:var(--dm-ghost);box-shadow:0 16px 0 var(--dm-ghost),0 32px 0 var(--dm-ghost-2)}
.dm-atx-em-art::after{content:"";position:absolute;left:32px;top:16px;width:58px;height:6px;border-radius:3px;background:var(--dm-ghost);box-shadow:0 16px 0 var(--dm-ghost),0 32px 0 var(--dm-ghost-2)}
/* the browse link wraps a clear file input, so it opens the file dialog and shows the keyboard's focus */
.dm-atx-br{position:relative;color:var(--dm-accent-fg,var(--dm-accent));font-weight:500;cursor:pointer}
@media (hover:hover) and (pointer:fine){.dm-atx-br:hover{text-decoration:underline;text-underline-offset:2px}}
.dm-atx-br:has(.dm-atx-file:focus-visible),.dm-atx-add:has(:focus-visible){outline:2px solid var(--dm-focus);outline-offset:2px}
.dm-atx-br:has(.dm-atx-file:focus-visible){border-radius:4px}
/* the empty state shows until the first file lands, and the foot strip from then on */
.dm-atx-list:not(:empty)~.dm-atx-em,.dm-atx-list:empty~.dm-atx-ft{display:none}
/* (on a phone the count can take two lines: the strip grows with it and Add files stays 16px from the corner) */
.dm-atx-ft{display:flex;align-items:flex-end;gap:12px;padding:var(--dm-strip-y) 16px;background:var(--dm-strip);border-top:1px solid var(--dm-line);border-radius:0 0 var(--dm-r-card) var(--dm-r-card)}
.dm-atx-add{position:relative;overflow:hidden;flex:none;margin-left:auto;cursor:pointer}
:root[data-style="studio"] .dm-atx-list,:root [data-style="studio"] .dm-atx-list,:root [data-style="studio"].dm-atx-list{gap:0;padding:0 16px}
:root[data-style="studio"] .dm-atx-list:not(:empty),:root [data-style="studio"] .dm-atx-list:not(:empty),:root [data-style="studio"].dm-atx-list:not(:empty){padding-block:6px}
/* while the last file is still going up its rail is the lowest thing in the list, so the list keeps 16px under it before the
foot strip (owner, 18 Nov); once it is read its rail goes, and its words are the lowest, 16px from the strip as they are */
:root[data-style="studio"] .dm-atx-list:has(>.dm-atx-it:last-child :is(.dm-atx-ring,.dm-atx-rd)),:root [data-style="studio"] .dm-atx-list:has(>.dm-atx-it:last-child :is(.dm-atx-ring,.dm-atx-rd)),:root [data-style="studio"].dm-atx-list:has(>.dm-atx-it:last-child :is(.dm-atx-ring,.dm-atx-rd)){padding-bottom:16px}
:root[data-style="studio"] .dm-atx-it,:root [data-style="studio"] .dm-atx-it,:root [data-style="studio"].dm-atx-it{gap:12px;padding:10px 0;border-radius:0;overflow:visible;background:none}
:root[data-style="studio"] .dm-atx-it.dm-up,:root [data-style="studio"] .dm-atx-it.dm-up,:root [data-style="studio"].dm-atx-it.dm-up{background:none}
/* the divider under a row's text (.atx-ln, Studio's own), which is the upload's rail while the file goes up, its ink fill
clipped to the progress with a soft sheen running along it; a file that is read keeps the hairline, the last one none */
.dm-atx-ln{position:absolute;left:44px;right:0;bottom:0;height:1px;border-radius:999px;background:var(--dm-line);pointer-events:none;transition:height var(--dm-t) var(--dm-ease),background-color var(--dm-t) var(--dm-ease)}
.dm-atx-it:last-child .dm-atx-ln{background:transparent}
.dm-atx-it:not(:has(.dm-atx-ok)) .dm-atx-ln{height:2px;background:var(--dm-rail)}
.dm-atx-ln i{position:absolute;inset:0;border-radius:inherit;background:linear-gradient(90deg,var(--dm-fg) 40%,color-mix(in srgb,var(--dm-fg) 35%,var(--dm-surface)) 50%,var(--dm-fg) 60%) 0 0/250% 100%;clip-path:inset(0 calc(100% - var(--dm-p)) 0 0 round 999px);transition:clip-path .2s linear,opacity .4s var(--dm-ease);animation:dm-atxsheen 1.6s linear infinite}
.dm-atx-it:has(.dm-atx-ok) .dm-atx-ln i{opacity:0;animation:none}
@keyframes dm-atxsheen{from{background-position:100% 0}to{background-position:0 0}}
:root[data-style="studio"] .dm-atx-ti,:root [data-style="studio"] .dm-atx-ti,:root [data-style="studio"].dm-atx-ti{position:relative;width:32px;height:32px;border-radius:50%;font-size:9.5px;color:var(--dm-fg2);background:var(--dm-chip)}
:root[data-style="studio"] .dm-atx-it .dm-atx-m,:root [data-style="studio"] .dm-atx-it .dm-atx-m,:root [data-style="studio"].dm-atx-it .dm-atx-m,:root[data-style="studio"] .dm-atx-it:not(.dm-up) .dm-atx-m,:root [data-style="studio"] .dm-atx-it:not(.dm-up) .dm-atx-m,:root [data-style="studio"].dm-atx-it:not(.dm-up) .dm-atx-m{color:var(--dm-muted)}
/* the upload's own ring stays for screen readers; the rail shows the progress */
:root[data-style="studio"] .dm-atx-ring,:root [data-style="studio"] .dm-atx-ring,:root [data-style="studio"].dm-atx-ring{opacity:0}
:root[data-style="studio"] .dm-atx-rd,:root [data-style="studio"] .dm-atx-rd,:root [data-style="studio"].dm-atx-rd{color:var(--dm-muted)}
/* read: a green disc lands and its tick draws itself */
.dm-atx-okc{display:grid;place-items:center;width:16px;height:16px;border-radius:50%;background:var(--dm-ok-mark);color:var(--dm-surface);animation:dm-atxokin .32s var(--dm-ease) backwards}
.dm-atx-okc svg{width:10px;height:10px;fill:none;stroke:currentColor;stroke-width:2.6;stroke-linecap:round;stroke-linejoin:round}
.dm-atx-okc path{stroke-dasharray:1;stroke-dashoffset:1;animation:dm-atxokdraw .34s var(--dm-ease) .16s forwards}
@keyframes dm-atxokin{from{opacity:0;transform:scale(.5)}}
@keyframes dm-atxokdraw{to{stroke-dashoffset:0}}
/* the remove button sits on the content's 16px edge, where the dividers end */
:root[data-style="studio"] .dm-atx-it .dm-ib,:root [data-style="studio"] .dm-atx-it .dm-ib,:root [data-style="studio"].dm-atx-it .dm-ib{width:28px;height:28px}
@media (hover:hover) and (pointer:fine){:root[data-style="studio"] .dm-atx-it .dm-ib:hover,:root [data-style="studio"] .dm-atx-it .dm-ib:hover,:root [data-style="studio"].dm-atx-it .dm-ib:hover{background:var(--dm-row);color:var(--dm-fg)}}
/* in the foot strip: what the agent can read now, its count rolling up as each file is read. The tick and the words belong
together (owner, 18 Nov): the tick on the content's edge, 8px, then the words */
:root[data-style="studio"] .dm-atx-sum,:root [data-style="studio"] .dm-atx-sum,:root [data-style="studio"].dm-atx-sum{display:flex;align-items:center;gap:8px;flex:1;min-width:0;min-height:0;padding:5px 0;font-size:12.5px;line-height:18px;text-align:left;color:var(--dm-fg2)}
:root[data-style="studio"] .dm-atx-sum:empty,:root [data-style="studio"] .dm-atx-sum:empty,:root [data-style="studio"].dm-atx-sum:empty{display:none}
/* (a step of --dm-ok in the vivid green keeps the small tick at 3:1 on the off-white strip) */
:root[data-style="studio"] .dm-atx-tk,:root [data-style="studio"] .dm-atx-tk,:root [data-style="studio"].dm-atx-tk{display:grid;place-items:center;flex:none;color:color-mix(in srgb,var(--dm-ok-mark) 80%,var(--dm-ok))}
:root[data-style="studio"] .dm-atx-tk .dm-i,:root [data-style="studio"] .dm-atx-tk .dm-i,:root [data-style="studio"].dm-atx-tk .dm-i{stroke-width:2.2}
.dm-atx-roll{display:inline-grid;overflow:hidden;height:1lh;vertical-align:top}
.dm-atx-roll i{font-style:normal}
.dm-atx-roll i.dm-in{animation:dm-atxroll .32s var(--dm-ease) both}
@keyframes dm-atxroll{from{opacity:0;transform:translateY(60%)}}
@media (prefers-reduced-motion:reduce){.dm-atx-ln i,.dm-atx-okc,.dm-atx-roll i.dm-in{animation:none}.dm-atx-okc path{animation:none;stroke-dashoffset:0}.dm-atx-ln,:root[data-style="studio"] .dm-atx,:root [data-style="studio"] .dm-atx,:root [data-style="studio"].dm-atx{transition:none}}
AttachmentTray.astroAstro · 30 lines
---
// Generated from designme.dev by scripts/sync.mjs. Edit the site, then sync.
// Attachment tray: Drop files for the agent and watch each one upload.
// 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 attachment-tray.js. The markup is kept exactly as it is (is:raw).
import type { HTMLAttributes } from 'astro/types';
import '../core/designme.css';
import './attachment-tray.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="attachment-tray" {...rest}>
<div class="stage-in"><Fragment is:raw>
<div class="atx mx-grow">
<label class="atx-drop"><input type="file" multiple class="atx-file" aria-label="Choose files" title=""><svg class="atx-ants" aria-hidden="true"><rect/></svg>
<span class="atx-ic"><svg class="i s"><use href="#i-upload"/></svg></span><b>Drop files here</b><span class="muted">or <span class="atx-sample">add sample files</span></span>
</label>
<div class="atx-list"></div>
<div class="atx-sum muted"></div>
</div>
</Fragment></div>
</div>
<script>
import './attachment-tray.js';
</script>
attachment-tray.htmlHTML · 12 lines
<div class="card" data-c="attachment-tray">
<div class="stage-in">
<div class="atx mx-grow">
<label class="atx-drop"><input type="file" multiple class="atx-file" aria-label="Choose files" title=""><svg class="atx-ants" aria-hidden="true"><rect/></svg>
<span class="atx-ic"><svg class="i s"><use href="#i-upload"/></svg></span><b>Drop files here</b><span class="muted">or <span class="atx-sample">add sample files</span></span>
</label>
<div class="atx-list"></div>
<div class="atx-sum muted"></div>
</div>
</div>
</div>
attachment-tray.cssHTML · 133 lines
/* ---------- Attachment tray ---------- */
/* a drop zone, then the files as plain rows. Each file wears its type's hue: its badge, its ring and the wash that fills its
row from the left as it uploads. Once it is up the agent reads it (the line shimmers) and says what it found, like 12 pages */
.atx{display:flex;flex-direction:column;gap:10px}
/* its motion (the core's motion pieces, owner, 26 Nov): a press on a file's remove button shows at once (.mx-press), and in
Studio the card grows with its files on the spring (.mx-grow) */
.atx-drop{display:flex;flex-direction:column;align-items:center;gap:6px;padding:26px var(--dm-s-4);border-radius:var(--dm-r-card);background:none;cursor:pointer;position:relative;font-size:13.5px;transition:background .35s,box-shadow .35s,transform .45s var(--dm-ease)}
/* the dashed edge is drawn in SVG so its dashes can march around the corners: drifting slowly at rest, taking the accent
under the pointer, and marching faster while a file is dragged over */
.atx-ants{position:absolute;inset:0;width:100%;height:100%;overflow:visible;pointer-events:none}
.atx-ants rect{fill:none;stroke:var(--dm-faint);stroke-width:1.5;stroke-linecap:round;stroke-dasharray:4.5px var(--dm-ag,6.5px);transition:stroke .35s}
@keyframes atxants{to{stroke-dashoffset:calc(var(--dm-ap,11px) * -1)}}
.atx-drop.over{background:var(--dm-accent-bg)}
@media (hover:hover) and (pointer:fine){.atx-drop:hover{background:var(--dm-accent-bg)}}
.atx-drop.over .atx-ants rect{stroke:var(--dm-accent-mark,var(--dm-accent))}
@media (hover:hover) and (pointer:fine){.atx-drop:hover .atx-ants rect{stroke:var(--dm-accent-mark,var(--dm-accent))}}
.atx-ants rect{animation:atxants 2.6s linear infinite}
.atx-drop.over .atx-ants rect{animation-duration:.9s}
.atx-drop.over{transform:scale(1.015)}
.atx-file{position:absolute;inset:0;opacity:0;cursor:pointer}
/* the file input is clear over the drop zone, so the zone shows its focus */
.atx-drop:has(.atx-file:focus-visible){outline:2px solid var(--dm-focus);outline-offset:2px}
.atx-ic{position:relative;width:34px;height:34px;border-radius:calc(11px * var(--dm-rk-l,var(--dm-rk)));background:var(--dm-surface);box-shadow:var(--dm-shadow);display:grid;place-items:center;color:var(--dm-fg2);transition:transform .45s var(--dm-ease),background .35s,color .35s}
.atx-drop.over .atx-ic{transform:translateY(-3px);background:var(--dm-surface);color:var(--dm-accent-fg,var(--dm-accent))}
@media (hover:hover) and (pointer:fine){.atx-drop:hover .atx-ic{transform:translateY(-3px);background:var(--dm-surface);color:var(--dm-accent-fg,var(--dm-accent))}}
/* while a file is over the zone its arrow bobs, and rings spread from the badge */
.atx-drop.over .atx-ic .i{animation:atxbob .9s var(--dm-ease-io) infinite}
@keyframes atxbob{50%{transform:translateY(-2px)}}
.atx-ic::before,.atx-ic::after{content:"";position:absolute;inset:0;border-radius:inherit;box-shadow:0 0 0 1.5px var(--dm-accent-mark,var(--dm-accent));opacity:0;pointer-events:none}
.atx-drop.over .atx-ic::before{animation:atxring 1.4s var(--dm-ease) infinite}
.atx-drop.over .atx-ic::after{animation:atxring 1.4s var(--dm-ease) .7s infinite}
@keyframes atxring{from{opacity:.5;transform:scale(1)}to{opacity:0;transform:scale(1.9)}}
.atx-sample{color:var(--dm-accent-fg,var(--dm-accent));font-weight:500;position:relative;z-index:1}
.atx-list{display:flex;flex-direction:column;gap:2px}
.atx-it{--dm-p:0%;position:relative;display:flex;align-items:center;gap:10px;padding:var(--dm-s-2) 6px var(--dm-s-2) var(--dm-s-2);border-radius:var(--dm-r-in);overflow:hidden;background:linear-gradient(90deg,color-mix(in srgb,var(--dm-c,var(--dm-accent)) 8%,transparent) calc(var(--dm-p) - 24px),color-mix(in srgb,var(--dm-c,var(--dm-accent)) 16%,transparent) calc(var(--dm-p) - 1px),transparent var(--dm-p)) no-repeat}
/* the wash fades once the file is up */
.atx-it.up{background-size:0 100%;transition:background-size .6s var(--dm-ease) .2s}
.atx-ti{width:30px;height:30px;border-radius:calc(9px * var(--dm-rk-m,var(--dm-rk)));display:grid;place-items:center;flex:none;font-size:9.5px;font-weight:500;letter-spacing:.02em;color:var(--dm-c);background:var(--dm-cb)}
.atx-n{flex:1;min-width:0;font-size:13px}
.atx-nm{display:block;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
.atx-m{display:block;font-size:12px;color:var(--dm-muted);white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
.atx-m .shim{font-size:inherit}
/* on the wash, the line steps up a grey so it keeps its contrast */
.atx-it:not(.up) .atx-m{color:var(--dm-fg2)}
.atx-ring{width:22px;height:22px;flex:none}
.atx-ring circle{transition:stroke-dashoffset .3s linear}
.atx-ok{display:grid;place-items:center;width:22px;flex:none;color:var(--dm-ok)}
.atx-ok .i{animation:atxpop .45s var(--dm-ease) backwards}
@keyframes atxpop{0%{transform:scale(.4);opacity:0}60%{transform:scale(1.15);opacity:1}100%{transform:none}}
.atx-rd{display:grid;place-items:center;width:22px;flex:none;color:var(--dm-c)}
.atx-rd .spin{width:12px;height:12px}
/* (a file's remove button is a 28px icon button, as most icon buttons in a row are) */
.atx-it .ib{width:28px;height:28px;flex:none}
.atx-sum{font-size:12.5px;text-align:center;min-height:18px}
:root:not([data-style="soft"],[data-style="studio"]) .atx-it:not(:where([data-style="soft"],[data-style="soft"] *,[data-style="studio"],[data-style="studio"] *)){background:linear-gradient(var(--dm-c,var(--dm-accent)),var(--dm-c,var(--dm-accent))) 0 100%/var(--dm-p) 2px no-repeat}
:root:not([data-style="soft"],[data-style="studio"]) .atx-it.up:not(:where([data-style="soft"],[data-style="soft"] *,[data-style="studio"],[data-style="studio"] *)){background-size:0 2px}
:root:not([data-style="soft"],[data-style="studio"]) .atx-drop.over .atx-ic:not(:where([data-style="soft"],[data-style="soft"] *,[data-style="studio"],[data-style="studio"] *))::before{animation:atxringbp 1s steps(4,end) infinite}
:root:not([data-style="soft"],[data-style="studio"]) .atx-drop.over .atx-ic:not(:where([data-style="soft"],[data-style="soft"] *,[data-style="studio"],[data-style="studio"] *))::after{animation:none}
@keyframes atxringbp{from{opacity:.6;transform:scale(1)}to{opacity:0;transform:scale(1.6)}}
:root:not([data-style="soft"],[data-style="studio"]) .atx-ok .i:not(:where([data-style="soft"],[data-style="soft"] *,[data-style="studio"],[data-style="studio"] *)){animation:none}
/* Studio (owner, 18 Nov): one card that grows as files arrive (grow()), its content 16px from each edge, and the whole card is
the drop target: a file dragged over it fills it with the row grey and draws a dashed hairline 8px in from its edge. Empty,
it shows Studio's empty state (.atx-em): a small sketch of a file list on a white card, the title, one muted line with a
browse link, and Add sample files. Files are rows with hairline dividers under their text: one neutral grey circle with the
type's letters for every file (owner, 18 Nov: one colour, not a hue per type), and while a file uploads its divider becomes
a rail that fills with ink, the same for every file, a soft sheen running along
it while the agent reads, then fades as a green tick draws itself. Once there are files, the off-white foot strip (.atx-ft)
says what the agent can read, its count rolling as each file is read, and holds Add files 16px from the card's side and
bottom and from the strip's hairline (owner, 23 Nov) */
/* (the dashed hairline is an outline drawn 8px inside the card, so it follows the card's corners) */
:root[data-style="studio"] .atx,:root [data-style="studio"] .atx,:root [data-style="studio"].atx{position:relative;gap:0;background:var(--dm-surface);border-radius:var(--dm-r-card);box-shadow:var(--dm-shadow);overflow:clip;outline:1px dashed transparent;outline-offset:-9px;transition:background-color var(--dm-t-fast) var(--dm-ease),outline-color var(--dm-t-fast) var(--dm-ease)}
:root[data-style="studio"] .atx.over,:root [data-style="studio"] .atx.over,:root [data-style="studio"].atx.over{background:var(--dm-row);outline-color:var(--dm-faint)}
/* the empty state, the lab's: the sketch is a white card with a hairline and three rows, each a square and a bar,
fading downward; under it the title, one grey line and a secondary button */
.atx-em{display:flex;flex-direction:column;align-items:center;gap:4px;padding:16px;text-align:center}
.atx-em b{font-size:13.5px;line-height:18px;font-weight:500;color:var(--dm-fg)}
.atx-em>span:not(.atx-em-art){max-width:290px;font-size:12.5px;line-height:1.5;color:var(--dm-muted)}
.atx-em .pill{margin-top:12px}
.atx-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)}
.atx-em-art::before{content:"";position:absolute;left:14px;top:14px;width:10px;height:10px;border-radius:3px;background:var(--dm-ghost);box-shadow:0 16px 0 var(--dm-ghost),0 32px 0 var(--dm-ghost-2)}
.atx-em-art::after{content:"";position:absolute;left:32px;top:16px;width:58px;height:6px;border-radius:3px;background:var(--dm-ghost);box-shadow:0 16px 0 var(--dm-ghost),0 32px 0 var(--dm-ghost-2)}
/* the browse link wraps a clear file input, so it opens the file dialog and shows the keyboard's focus */
.atx-br{position:relative;color:var(--dm-accent-fg,var(--dm-accent));font-weight:500;cursor:pointer}
@media (hover:hover) and (pointer:fine){.atx-br:hover{text-decoration:underline;text-underline-offset:2px}}
.atx-br:has(.atx-file:focus-visible),.atx-add:has(:focus-visible){outline:2px solid var(--dm-focus);outline-offset:2px}
.atx-br:has(.atx-file:focus-visible){border-radius:4px}
/* the empty state shows until the first file lands, and the foot strip from then on */
.atx-list:not(:empty)~.atx-em,.atx-list:empty~.atx-ft{display:none}
/* (on a phone the count can take two lines: the strip grows with it and Add files stays 16px from the corner) */
.atx-ft{display:flex;align-items:flex-end;gap:12px;padding:var(--dm-strip-y) 16px;background:var(--dm-strip);border-top:1px solid var(--dm-line);border-radius:0 0 var(--dm-r-card) var(--dm-r-card)}
.atx-add{position:relative;overflow:hidden;flex:none;margin-left:auto;cursor:pointer}
:root[data-style="studio"] .atx-list,:root [data-style="studio"] .atx-list,:root [data-style="studio"].atx-list{gap:0;padding:0 16px}
:root[data-style="studio"] .atx-list:not(:empty),:root [data-style="studio"] .atx-list:not(:empty),:root [data-style="studio"].atx-list:not(:empty){padding-block:6px}
/* while the last file is still going up its rail is the lowest thing in the list, so the list keeps 16px under it before the
foot strip (owner, 18 Nov); once it is read its rail goes, and its words are the lowest, 16px from the strip as they are */
:root[data-style="studio"] .atx-list:has(>.atx-it:last-child :is(.atx-ring,.atx-rd)),:root [data-style="studio"] .atx-list:has(>.atx-it:last-child :is(.atx-ring,.atx-rd)),:root [data-style="studio"].atx-list:has(>.atx-it:last-child :is(.atx-ring,.atx-rd)){padding-bottom:16px}
:root[data-style="studio"] .atx-it,:root [data-style="studio"] .atx-it,:root [data-style="studio"].atx-it{gap:12px;padding:10px 0;border-radius:0;overflow:visible;background:none}
:root[data-style="studio"] .atx-it.up,:root [data-style="studio"] .atx-it.up,:root [data-style="studio"].atx-it.up{background:none}
/* the divider under a row's text (.atx-ln, Studio's own), which is the upload's rail while the file goes up, its ink fill
clipped to the progress with a soft sheen running along it; a file that is read keeps the hairline, the last one none */
.atx-ln{position:absolute;left:44px;right:0;bottom:0;height:1px;border-radius:999px;background:var(--dm-line);pointer-events:none;transition:height var(--dm-t) var(--dm-ease),background-color var(--dm-t) var(--dm-ease)}
.atx-it:last-child .atx-ln{background:transparent}
.atx-it:not(:has(.atx-ok)) .atx-ln{height:2px;background:var(--dm-rail)}
.atx-ln i{position:absolute;inset:0;border-radius:inherit;background:linear-gradient(90deg,var(--dm-fg) 40%,color-mix(in srgb,var(--dm-fg) 35%,var(--dm-surface)) 50%,var(--dm-fg) 60%) 0 0/250% 100%;clip-path:inset(0 calc(100% - var(--dm-p)) 0 0 round 999px);transition:clip-path .2s linear,opacity .4s var(--dm-ease);animation:atxsheen 1.6s linear infinite}
.atx-it:has(.atx-ok) .atx-ln i{opacity:0;animation:none}
@keyframes atxsheen{from{background-position:100% 0}to{background-position:0 0}}
:root[data-style="studio"] .atx-ti,:root [data-style="studio"] .atx-ti,:root [data-style="studio"].atx-ti{position:relative;width:32px;height:32px;border-radius:50%;font-size:9.5px;color:var(--dm-fg2);background:var(--dm-chip)}
:root[data-style="studio"] .atx-it .atx-m,:root [data-style="studio"] .atx-it .atx-m,:root [data-style="studio"].atx-it .atx-m,:root[data-style="studio"] .atx-it:not(.up) .atx-m,:root [data-style="studio"] .atx-it:not(.up) .atx-m,:root [data-style="studio"].atx-it:not(.up) .atx-m{color:var(--dm-muted)}
/* the upload's own ring stays for screen readers; the rail shows the progress */
:root[data-style="studio"] .atx-ring,:root [data-style="studio"] .atx-ring,:root [data-style="studio"].atx-ring{opacity:0}
:root[data-style="studio"] .atx-rd,:root [data-style="studio"] .atx-rd,:root [data-style="studio"].atx-rd{color:var(--dm-muted)}
/* read: a green disc lands and its tick draws itself */
.atx-okc{display:grid;place-items:center;width:16px;height:16px;border-radius:50%;background:var(--dm-ok-mark);color:var(--dm-surface);animation:atxokin .32s var(--dm-ease) backwards}
.atx-okc svg{width:10px;height:10px;fill:none;stroke:currentColor;stroke-width:2.6;stroke-linecap:round;stroke-linejoin:round}
.atx-okc path{stroke-dasharray:1;stroke-dashoffset:1;animation:atxokdraw .34s var(--dm-ease) .16s forwards}
@keyframes atxokin{from{opacity:0;transform:scale(.5)}}
@keyframes atxokdraw{to{stroke-dashoffset:0}}
/* the remove button sits on the content's 16px edge, where the dividers end */
:root[data-style="studio"] .atx-it .ib,:root [data-style="studio"] .atx-it .ib,:root [data-style="studio"].atx-it .ib{width:28px;height:28px}
@media (hover:hover) and (pointer:fine){:root[data-style="studio"] .atx-it .ib:hover,:root [data-style="studio"] .atx-it .ib:hover,:root [data-style="studio"].atx-it .ib:hover{background:var(--dm-row);color:var(--dm-fg)}}
/* in the foot strip: what the agent can read now, its count rolling up as each file is read. The tick and the words belong
together (owner, 18 Nov): the tick on the content's edge, 8px, then the words */
:root[data-style="studio"] .atx-sum,:root [data-style="studio"] .atx-sum,:root [data-style="studio"].atx-sum{display:flex;align-items:center;gap:8px;flex:1;min-width:0;min-height:0;padding:5px 0;font-size:12.5px;line-height:18px;text-align:left;color:var(--dm-fg2)}
:root[data-style="studio"] .atx-sum:empty,:root [data-style="studio"] .atx-sum:empty,:root [data-style="studio"].atx-sum:empty{display:none}
/* (a step of --dm-ok in the vivid green keeps the small tick at 3:1 on the off-white strip) */
:root[data-style="studio"] .atx-tk,:root [data-style="studio"] .atx-tk,:root [data-style="studio"].atx-tk{display:grid;place-items:center;flex:none;color:color-mix(in srgb,var(--dm-ok-mark) 80%,var(--dm-ok))}
:root[data-style="studio"] .atx-tk .i,:root [data-style="studio"] .atx-tk .i,:root [data-style="studio"].atx-tk .i{stroke-width:2.2}
.atx-roll{display:inline-grid;overflow:hidden;height:1lh;vertical-align:top}
.atx-roll i{font-style:normal}
.atx-roll i.in{animation:atxroll .32s var(--dm-ease) both}
@keyframes atxroll{from{opacity:0;transform:translateY(60%)}}
@media (prefers-reduced-motion:reduce){.atx-ln i,.atx-okc,.atx-roll i.in{animation:none}.atx-okc path{animation:none;stroke-dashoffset:0}.atx-ln,:root[data-style="studio"] .atx,:root [data-style="studio"] .atx,:root [data-style="studio"].atx{transition:none}}
attachment-tray.jsHTML · 69 lines
DM.def('attachment-tray', (r, c) => {
r.innerHTML = r.innerHTML.replace('{upload}', I('upload'));
const tray = $('.atx', r), list = $('.atx-list', r), sum = $('.atx-sum', r);
// Studio: the whole card is the drop target. The drop zone gives way to the empty state (after the list, so it shows only
// while the list is empty), and the closing line moves into a foot strip with Add files, shown once there are files. The
// card grows with its files (grow()); Soft and Blueprint as they were
const studio = (r.closest('[data-style]') || document.documentElement).dataset.style === 'studio';
if (studio){
$('.atx-drop', r).remove();
list.after(html(`<div class="atx-em"><span class="atx-em-art" aria-hidden="true"></span><b>Drop files here</b><span>or <label class="atx-br">browse your files<input type="file" multiple class="atx-file" aria-label="Choose files" title=""></label></span><button type="button" class="pill line sm atx-smp">${I('plus','xs')}Add sample files</button></div>`));
const ft = html(`<div class="atx-ft"><label class="pill line sm atx-add">${I('plus','xs')}Add files<input type="file" multiple class="atx-file" aria-label="Add files" title=""></label></div>`);
sum.replaceWith(ft); ft.prepend(sum);
c.offs.push(grow(tray));
}
const drop = studio ? tray : $('.atx-drop', r);
const kind = n => { const e = (n.split('.').pop() || '').toLowerCase(); return e === 'pdf' ? ['PDF','var(--dm-pr)','var(--dm-pr-bg)'] : /png|jpg|jpeg|gif|webp|fig/.test(e) ? [e.toUpperCase().slice(0,3),'var(--dm-pl)','var(--dm-pl-bg)'] : /csv|xlsx/.test(e) ? ['CSV','var(--dm-pm)','var(--dm-pm-bg)'] : [e.toUpperCase().slice(0,3) || 'TXT','var(--dm-pb)','var(--dm-pb-bg)']; };
const size = b => b > 1e6 ? (b / 1e6).toFixed(1) + ' MB' : Math.max(1, Math.round(b / 1e3)) + ' KB';
const esc = s => s.replace(/&/g,'&').replace(/</g,'<');
let read = 0;
// a file uploads (its row fills with its hue and its ring closes), then the agent reads it and says what it found
function add(name, bytes, i = 0, found){
const k = kind(name), sz = size(bytes);
const it = html(`<div class="atx-it" style="--dm-c:${k[1]};--dm-cb:${k[2]}"><span class="atx-ti">${k[0]}</span><span class="atx-n"><span class="atx-nm">${esc(name)}</span><span class="atx-m"><span>${sz} · <span class="num pc">0%</span></span></span></span><svg class="atx-ring" viewBox="0 0 22 22" role="progressbar" aria-label="Uploading ${esc(name).replace(/"/g, '"')}" aria-valuemin="0" aria-valuemax="100" aria-valuenow="0"><circle cx="11" cy="11" r="8" fill="none" stroke="var(--dm-line)" stroke-width="2"/><circle cx="11" cy="11" r="8" fill="none" stroke="${k[1]}" stroke-width="2" stroke-linecap="round" stroke-dasharray="50.3" stroke-dashoffset="50.3" transform="rotate(-90 11 11)"/></svg><button class="ib mx-press" aria-label="Remove ${esc(name).replace(/"/g, '"')}" data-tip="Remove">${I('x','xs')}</button>${studio ? '<span class="atx-ln" aria-hidden="true"><i></i></span>' : ''}</div>`);
list.appendChild(it); enter(it, i * 80);
$('.ib', it).onclick = () => { it.classList.add('leave'); setTimeout(() => it.remove(), 320); };
const svg = $('.atx-ring', it), ring = $$('circle', it)[1], m = $('.atx-m', it); let p = 0;
const iv = c.every(70, () => {
p = Math.min(1, p + .025 + Math.random() * .05); ring.style.strokeDashoffset = 50.3 * (1 - p);
it.style.setProperty('--dm-p', (p * 100).toFixed(1) + '%'); svg.setAttribute('aria-valuenow', Math.round(p * 100)); const pc = $('.pc', m); if (pc) pc.textContent = Math.round(p * 100) + '%';
if (p < 1) return;
clearInterval(iv); it.classList.add('up');
// reading: the ring gives way to a spinner and the line shimmers, then says what the agent found
svg.outerHTML = '<span class="atx-rd"><span class="spin"></span></span>'; swap(m, `<span class="shim">${sz} · Reading</span>`, true);
c.later(REDUCE ? 0 : 900, () => {
const rd = $('.atx-rd', it); if (rd) rd.outerHTML = `<span class="atx-ok">${studio ? '<span class="atx-okc"><svg viewBox="0 0 16 16" aria-hidden="true"><path pathLength="1" d="M4.6 8.3l2.3 2.3 4.5-4.8"/></svg></span>' : I('ok')}</span>`;
swap(m, found ? `${sz} · ${found}` : sz); read++;
if (!studio) { swap(sum, 'The agent can read ' + read + (read > 1 ? ' files' : ' file') + ' now'); return; }
// Studio: the foot strip opens with a green tick, and from then on only its count rolls
const w = read > 1 ? 'files' : 'file', rl = $('.atx-roll', sum);
if (!rl) swap(sum, `<span class="atx-tk">${I('check','xs')}</span><span>The agent can read <span class="atx-roll num"><i>${read}</i></span> <span class="atx-w">${w}</span> now</span>`, true);
else { rl.innerHTML = `<i class="in">${read}</i>`; $('.atx-w', sum).textContent = w; }
});
});
}
const samples = () => [['brief.pdf', 2.4e6, '12 pages'],['Pricing.fig', 8.1e6, '6 frames'],['signups.csv', 3.2e5, '1,204 rows']].forEach((f, i) => add(f[0], f[1], i, f[2]));
$(studio ? '.atx-smp' : '.atx-sample', r).onclick = e => { e.preventDefault(); samples(); };
$$('.atx-file', r).forEach(inp => { inp.onchange = e => { Array.from(e.target.files).forEach((f, i) => add(f.name, f.size, i)); e.target.value = ''; }; });
['dragenter','dragover'].forEach(ev => c.on(drop, ev, e => { e.preventDefault(); drop.classList.add('over'); }));
// (in Studio the card holds the rows and buttons, so moving between them is not leaving it)
['dragleave','drop'].forEach(ev => c.on(drop, ev, e => { if (studio && ev === 'dragleave' && drop.contains(e.relatedTarget)) return; drop.classList.remove('over'); }));
c.on(drop, 'drop', e => { e.preventDefault(); Array.from(e.dataTransfer.files).forEach((f, i) => add(f.name, f.size, i)); });
/* the dashed edge follows the drop zone's size and corners, with the dashes spaced to meet evenly all the way round */
const ants = $('.atx-ants rect', r);
const fit = () => {
const w = drop.offsetWidth, h = drop.offsetHeight; if (!w || !h) return;
const k = .75, rad = Math.max(0, Math.min(parseFloat(getComputedStyle(drop).borderTopLeftRadius) || 0, w / 2, h / 2) - k);
ants.setAttribute('x', k); ants.setAttribute('y', k); ants.setAttribute('width', w - 2 * k); ants.setAttribute('height', h - 2 * k); ants.setAttribute('rx', rad);
const per = 2 * (w + h - 4 * k) - (8 - 2 * Math.PI) * rad, step = per / Math.max(8, Math.round(per / 11));
ants.style.setProperty('--dm-ap', step + 'px'); ants.style.setProperty('--dm-ag', (step - 4.5) + 'px');
};
if (ants){ fit(); const ro = new ResizeObserver(fit); ro.observe(drop); c.offs.push(() => ro.disconnect()); }
/* once it has entered, three sample files are dragged over, drop in and upload, so the tray shows what it does */
c.run(async () => {
await c.step(950); if (list.children.length) return;
drop.classList.add('over'); c.taken(() => drop.classList.remove('over')); await c.step(1300); drop.classList.remove('over');
if (!list.children.length) samples();
});
});
Questions
What people ask about it.
- Does the tray upload the files for me?
- No. It hands you the files through
onFiles. You upload them, add each one tofileswith anid,nameandsize, and update itsprogressas the upload runs. - How do I restrict which file types people can pick?
- Pass
accept, for example "image/*,.pdf". It is set on the file input, so it applies to the file dialog. Dropped files are passed on as they are, so check their type inonFilestoo. - Can I change the line under the list?
- Yes. Pass
summaryand it replaces the default count of files the agent can read.
More in Conversation
Everything for asking, answering and replying, by text or by voice.