Upload sources — Files block
Profiles-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-sourcesUsage
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.
| Prop | Type | Description |
|---|---|---|
| title* | string | Wordswhat is being uploaded ("Add documents") |
| limits* | string | Wordsthe limits as the server enforces them ("PDF, JPG or PNG · 5 files · 10 MB each") |
| accept | string | Designthe file types the input accepts, as an accept attribute (".pdf,image/*") |
| maxFiles | number | the most files at once |
| maxSize | number | the most bytes per file |
| fields | Field[] | the form’s fields, in order |
| files | File[] | Datathe files already chosen or being sent, with their real progress |
| sources | Source[] | where files can come from, e.g. "Camera" |
| submit* | string | Actionthe page action that receives the files |
| options | Options | the block’s settings: layout choices and secondary words, read by every variant |
Field fields[] · 7 props
| Prop | Type | Description |
|---|---|---|
| name* | string | Designthe key of the field in what the form sends |
| label* | string | Wordsthe field’s name ("Project name") |
| type | 'text' | 'email' | 'date' | 'textarea' | 'select' | what kind of field it is: text, email, date, textarea, select |
| help | string | Wordsone sentence on how the field is used |
| placeholder | string | Wordsthe shape expected, never a value that looks real |
| options | Option[] | the choices, for a select |
| required | boolean | true: it must be filled in |
Option fields[].options[] · 2 props
| Prop | Type | Description |
|---|---|---|
| value* | string | Designwhat is sent |
| label* | string | Wordswhat is read |
File files[] · 6 props
| Prop | Type | Description |
|---|---|---|
| id* | string | number | the file’s id |
| name* | string | Wordsthe file’s name |
| size | string | Wordsits size as the app writes it ("2.4 MB") |
| progress | number | the real upload progress, in percent; absent once finished |
| error | string | Wordswhy it was refused, naming the limit |
| remove | string | Actionremoves the file |
Source sources[] · 3 props
| Prop | Type | Description |
|---|---|---|
| label* | string | Wordswhere files come from ("Camera") |
| action* | string | Actionopens that source |
| icon | string | Designdevice, link, camera, library, drive |
Options options · 3 props
| Prop | Type | Description |
|---|---|---|
| cancel | string | Actionwhere Cancel leads |
| submitLabel | string | Wordsthe send button ("Upload") |
| mood | 'inverse' | 'brand' | 'warm' | 'tint' | string | a 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).
| Member | What it is for |
|---|---|
| href | the address an action leads to, or null to hide what leads there |
| act | runs a change (subscribe, add to cart, save) and answers { ok } or { ok: false, error } |
| can | whether the page has this action |
| Link | your router’s link component |
| cartCount | the cart badge’s number |
| cartDrawer | whether your app has a cart drawer |
| cartOpen | whether the cart drawer is open |
| label | your 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:
| Key | English | French |
|---|---|---|
| newsletter.already | You are already subscribed. | Vous êtes déjà inscrit. |
| newsletter.done | Done: you are subscribed. | C’est noté : vous êtes inscrit. |
| newsletter.invalid | Check the email address. | Vérifiez l’adresse e-mail. |
| newsletter.tooMany | Too 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.