Upload sources — Files block

Pro

files-upload-sources · for forms, app pages

Upload sources

Files can also come from a link, a camera or a library: the zone plus a row of source buttons

Documentation

Installation

One command copies the block into your project with the shadcn CLI (the registry is set once: Installation).

pnpm dlx shadcn-vue@latest add @trame/files-upload-sources

Usage

Its demo data, shortened (Using blocks).

<script setup lang="ts">
import FilesUploadSources from '@/components/trame/blocks/files/files-upload-sources.vue'

const props = {
title: "Add documents",
limits: "PDF, JPG or PNG · up to 5 files · 10 MB each",
accept: ".pdf,image/jpeg,image/png",
maxFiles: 5,
maxSize: 10485760,
submit: "upload",
fields: [
{
name: "project",
label: "Project name",
placeholder: "Kitchen remodel",
required: true
},
{
name: "note",
label: "Message",
type: "textarea",
help: "Optional. Visible to the team receiving the files."
}
],
files: [
{
id: 1,
name: "kitchen-quote.pdf",
size: "2.4 MB"
},
{
id: 2,
name: "site-plan.png",
size: "860 KB",
progress: 64
}
],
options: {
cancel: "back"
},
sources: [
{
label: "Device",
action: "source-device",
icon: "device"
},
{
label: "Link",
action: "source-link",
icon: "link"
}
]
}
</script>

<template>
<FilesUploadSources v-bind="props" />
</template>

Props

Each prop says who changes it: Words, Picture, Action, Design, Data.* required.

PropTypeDescription
title*stringWordswhat is being uploaded ("Add documents")
limits*stringWordsthe limits as the server enforces them ("PDF, JPG or PNG · 5 files · 10 MB each")
acceptstringDesignthe file types the input accepts, as an accept attribute (".pdf,image/*")
maxFilesnumberthe most files at once
maxSizenumberthe most bytes per file
fieldsField[]the form’s fields, in order
filesFile[]Datathe files already chosen or being sent, with their real progress
sourcesSource[]where files can come from, e.g. "Camera"
submit*stringActionthe page action that receives the files
optionsOptionsthe block’s settings: layout choices and secondary words, read by every variant
Field fields[] · 7 props
PropTypeDescription
name*stringDesignthe key of the field in what the form sends
label*stringWordsthe field’s name ("Project name")
type'text' | 'email' | 'date' | 'textarea' | 'select'what kind of field it is: text, email, date, textarea, select
helpstringWordsone sentence on how the field is used
placeholderstringWordsthe shape expected, never a value that looks real
optionsOption[]the choices, for a select
requiredbooleantrue: it must be filled in
Option fields[].options[] · 2 props
PropTypeDescription
value*stringDesignwhat is sent
label*stringWordswhat is read
File files[] · 6 props
PropTypeDescription
id*string | numberthe file’s id
name*stringWordsthe file’s name
sizestringWordsits size as the app writes it ("2.4 MB")
progressnumberthe real upload progress, in percent; absent once finished
errorstringWordswhy it was refused, naming the limit
removestringActionremoves the file
Source sources[] · 3 props
PropTypeDescription
label*stringWordswhere files come from ("Camera")
action*stringActionopens that source
iconstringDesigndevice, link, camera, library, drive
Options options · 3 props
PropTypeDescription
cancelstringActionwhere Cancel leads
submitLabelstringWordsthe send button ("Upload")
mood'inverse' | 'brand' | 'warm' | 'tint' | stringa band of the page that redefines the theme surfaces inside it
What it asks your app for

The block never knows your app: it asks it, through one context provided once, where its links lead, what its actions do, how a price reads and which words to say (The host context).

MemberWhat it is for
hrefthe address an action leads to, or null to hide what leads there
actruns a change (subscribe, add to cart, save) and answers { ok } or { ok: false, error }
canwhether the page has this action
Linkyour router’s link component
cartCountthe cart badge’s number
cartDrawerwhether your app has a cart drawer
cartOpenwhether the cart drawer is open
labelyour word for an interface key, or undefined to keep the block’s own

The words it says itself, in English and French; label(key) replaces any of them:

KeyEnglishFrench
newsletter.alreadyYou are already subscribed.Vous êtes déjà inscrit.
newsletter.doneDone: you are subscribed.C’est noté : vous êtes inscrit.
newsletter.invalidCheck the email address.Vérifiez l’adresse e-mail.
newsletter.tooManyToo many attempts, try again in a moment.Trop de tentatives, réessayez dans un moment.

Features

  • Every word in the server HTML
  • Same markup in Vue and React
  • Theme tokens only: every theme, light and dark
  • Shows what you give it, invents nothing
  • No motion; still under reduced motion
  • Real buttons and links, a visible focus
  • Asks your app through actions: files[].remove, sources[], submit, options.cancel

A files section, for forms, app pages; it uses @lucide/vue, @vueuse/core, class-variance-authority, clsx, reka-ui, tailwind-merge.

Built with

The components this block is made of; each one installs on its own too.

More files blocks

  • Import mapping stepped: the import in numbered steps: match each column to a field, choose the duplicates to merge when there are any, review and send.
  • List browser: A file browser with list and grid views, using the merchant's own files only.
  • List links: A shared-file ledger with access and expiry, using the merchant's own system values only.
  • Media library grid: a wall of previews with a box on each to pick several assets at once, and the upload entry at hand.
  • Media library table: a dense table when there are many files: a small preview, the name and folder, the kind, the weight, the date.
  • Recent dated list: A date-grouped reading list for returning to the merchant's own recently used files, in host order.
  • Recent event rail: An event rail with file details and actors, using the merchant's own recorded activity only.
  • Upload request panel: someone else must send files: a panel with the folder, the deadline and a link to copy.

All 12 files blocks