07.3Block 07.3 · File uploads
Upload Vessel
A file-import dialog where the upload fills a beaker. Water pours in with the bytes, fizzes while the files are checked, and stands full with a tick when the data is ready.
- Version
- 0.1.0
- Size
- 69.4 KB gzipped
- Access
- With a Pass
- Needs
- upload-vessel.mjs + upload-vessel.css · Vessel
- Tests
- 8 tests · 12 states
On this page
Use it
Make an upload's three phases (sending, processing, ready) readable at a glance without a percentage: for a data import, a media upload or any drop zone in a product, the vessel pours while bytes go up, fizzes while the server works, and stands full when it is done, beside precise file rows, rates and steps.
Copy the upload-vessel folder and the vessel folder from its package next to your page, link the stylesheets and mount it on an element. Every option has a default; the lab’s Code tab writes the same example at any settings, and for React, Vue, Svelte or a custom element (Using a framework).
<link rel="stylesheet" href="vessel/vessel.css">
<link rel="stylesheet" href="upload-vessel/upload-vessel.css">
<div id="upload-vessel"></div>
<script type="module">
import Vessel from './vessel/vessel.mjs';
import { mount } from './upload-vessel/upload-vessel.mjs';
const uploadVessel = mount(document.getElementById('upload-vessel'), {
app: 'Loam',
project: 'North field trial',
title: 'Import sensor logs',
}, { Vessel });
// uploadVessel.update({ … }); change any option in place
// uploadVessel.destroy(); and take it away again
</script>Options
| Option | Type | Default | What it does |
|---|---|---|---|
| app | text | 'Loam' | Product |
| project | text | 'North field trial' | Project |
| title | text | 'Import sensor logs' | Dialog title |
| note | text | 'Files are encrypted in transit and stay in your workspace’s region (eu-west).' | Footnote |
| speed | number, 2 to 60 | 16 | How fast the simulated upload fills the beaker. |
| palette | daylight · console | 'daylight' | The app’s light theme, or its dark one. |
| liquid | water · ink · signal · honey | 'water' | In the beaker |
| light | number, 0 to 345 | 315 | Light from (degrees) |
Methods
mount(element, options, { Vessel })- Builds the block inside the element and returns its handle. Hand it the Vessel it is built with.
handle.vesselhandle.phasehandle.setProgress(f)- Add files (a FileList, or { name, size, rows } objects): they upload at once.
handle.update(next = {})- Change options in place.
handle.destroy()- Stops it and cleans up after it.
States
- IdleAn empty beaker in the drop zone, “Drop your files here”, Browse and a sample run, hints on what the product reads; Import disabled.
- Drag overThe zone's dashed outline turns to the accent and the water in the beaker tilts toward the pointer.
- UploadingWater pours in steadily with the bytes; each file's bar fills in turn; bytes, rate and time left in mono; step one active.
- Refused fileA file of the wrong kind, too large or empty is listed with its reason in the error colour and left out of the upload.
- Checking and indexingThe beaker stands full and fizzes, harder while indexing; the active step's dot pings; announced once.
- DoneThe fizz stops, a green tick appears, every file reads “Ready”, “Open dataset” is enabled; the timer has stopped and the beaker sleeps.
- Import moreThe list empties and the beaker drains.
- PaletteDaylight (white card, cool greys, one blue) or console (the app's dark theme); the glass re-shades itself for the drop zone.
- TabletThe app's rail goes; a narrower drop zone beside the files.
- PhoneOne column: the beaker on top, the files below, the dialog's buttons sharing the full width.
- Reduced motionNo pour, fizz, tilt, ping or slide; the checks run faster; the level, numbers and words all remain.
- Off screenThe beaker's loop pauses; the block's timer runs only while an upload or a check is in progress.
How it works
Made of: Upload fills vessel, Fizz while processing, Drag tilt, File validation, Simulated upload timer, Real upload api, Container query layout, Palette tokens from one table.
Original composition; Loam, its project, datasets and sample files are invented. Nothing is uploaded: the upload is simulated at a set rate until a real upload is wired through setProgress, process and done. Imagery is CSS and SVG icons drawn here, and the Vessel's canvas. Faces: Instrument Sans and Geist Mono (SIL OFL 1.1), Latin subsets as WOFF2.
Built with
More blocks on the same object:
- 06.4Specimen CaseA bento of glass-topped compartments in a machined case, each holding one real Tactile object running small (the Odometer, the Flip-Dot, the Detent Dial, the Vessel) with an engraved label card under the glass.
- 07.1Reading ProgressA long read with a test tube for a progress bar.
- 07.2Crowdfund FlaskA fundraiser where the total is honey in a flask.