Record panel — Form block
Freeform-record-panel · for app, forms pages
Record panel
The same form in a drawer or a narrow column: one field per row, no cards, a sticky save bar
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/form-record-panelUsage
Its demo data, shortened (Using blocks).
<script setup lang="ts">
import FormRecordPanel from '@/components/trame/blocks/form/form-record-panel.vue'
const props = {
title: "New product",
intro: "It stays saved as a draft until you publish it.",
fields: [
{
name: "name",
label: "Product name",
required: true,
placeholder: "Scented candle"
},
{
name: "category",
label: "Collection",
type: "relation",
help: "Where the product appears in the shop.",
options: [
{
value: "bougies",
label: "Scented candles"
},
{
value: "diffuseurs",
label: "Diffusers and room sprays"
}
],
search: "collection.options",
required: true
}
],
sections: [
{
id: "identity",
title: "Overview",
description: "What customers read first.",
fields: [
"name",
"category"
]
},
{
id: "sale",
title: "Price and stock",
fields: [
"price",
"stock"
]
}
],
submit: "product.create",
cancel: "product.list",
options: {
currency: "USD",
submitLabel: "Create product"
}
}
</script>
<template>
<FormRecordPanel v-bind="props" />
</template>Props
Each prop says who changes it: Words, Picture, Action, Design, Data.* required.
| Prop | Type | Description |
|---|---|---|
| title* | string | Wordsthe record being created or edited ("New product", "Edit the amber candle") |
| intro | string | Wordsone line under the title |
| fields* | Field[] | the form’s fields, in order |
| sections | Section[] | the sections shown, in order |
| values | Record<string, unknown> | Datathe record’s current values by field name when editing, with its `id`; absent when creating (the fields start empty) |
| errors | Record<string, string> | Datawhat the server refused, by field name: the message says what to correct |
| submit* | string | Actionthe page action the form posts to; through the host it receives `{ data }` when creating, `{ id, patch }` (the changed fields) when editing; an image or file field carries the `File` picked (the host uploads it), `null` once removed. Posted natively, the form is multipart: `<name>` holds the new file, `<name>:remove` is "1" when the current one is removed |
| cancel | string | Actionwhere Cancel leads (the list or the record) |
| after | string | Actionwhere the app goes once the record is saved (the record, the list): the host’s answer is its record |
| options | Options | the block’s settings: layout choices and secondary words, read by every variant |
Field fields[] · 12 props
| Prop | Type | Description |
|---|---|---|
| name* | string | Designthe key of the field in `values`, in `errors` and in what the form sends |
| label* | string | Wordsthe field’s name ("Product name") |
| type | 'text' | 'email' | 'tel' | 'url' | 'number' | 'money' | 'date' | 'time' | 'datetime' | 'textarea' | 'select' | 'switch' | 'radio-cards' | 'relation' | 'image' | 'file' | text by default; money: an amount in the main unit with its currency; radio-cards: a few exclusive choices shown as cards; relation: another record chosen among the options the host answered; date "YYYY-MM-DD", time "HH:MM", datetime: a moment (an ISO date with its zone is shown in the browser’s own time once the page runs, one without is the wall time as written); image and file: what it holds now (its address, or `{ url, name, size }`) with a choice to remove it, and a dropzone for a new one |
| help | string | Wordsone sentence on what the field is for, said under its label |
| placeholder | string | Wordsthe shape expected, never a value that looks real |
| options | Option[] | the choices, for a select or a relation |
| search | string | Actionrelation: the query action the host answers as the user types (`{ q }` → `{ items: [{ value, label }] }`); the options are the first list |
| accept | string | Designimage and file: the kinds the picker offers (".pdf,.jpg", "image/*"); any picture for an image by default |
| unit | string | Wordsa unit written after a number ("g", "days") |
| required | boolean | true: it must be filled in |
| readonly | boolean | true: the field is shown but cannot be changed |
| half | boolean | half the width on wide screens, two to a row (page) |
Option fields[].options[] · 3 props
| Prop | Type | Description |
|---|---|---|
| value* | string | Designwhat is sent (the record’s id for a relation) |
| label* | string | Wordswhat is read |
| description | string | Wordsradio-cards: one line under the label |
Section sections[] · 4 props
| Prop | Type | Description |
|---|---|---|
| id* | string | Designthe section’s key |
| title* | string | Wordswhat the fields of the section are about ("Price and stock") |
| description | string | Wordsone sentence under the title |
| fields* | string[] | Designa field name |
Options options · 7 props
| Prop | Type | Description |
|---|---|---|
| submitLabel | string | Wordsthe save button ("Save the product") |
| cancelLabel | string | Wordsthe cancel link ("Cancel") |
| unsavedLabel | string | Wordsthe hint shown while edits are not saved ("Unsaved changes") |
| formError | string | Wordswhat the server said about the whole form, if it refused it ("The product could not be saved") |
| currency | string | DesignISO 4217 for money fields, euro by default |
| markOptional | boolean | write "optional" after the optional fields, beside the "*" of the required ones |
| 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 } |
| query | a live read: a quick search, « see more » |
| go | navigates after a success |
| can | whether the page has this action |
| asset | a picture’s address as your app serves it |
| 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. |
| rf.file.new | New, sent on save | Nouveau, envoyé à l’enregistrement |
| rf.file.pick | Drop a file here or click to choose one | Glissez un fichier ici ou cliquez pour le choisir |
| rf.file.remove | Remove | Retirer |
| rf.file.removed | Will be removed on save | Sera retiré à l’enregistrement |
| rf.file.replace | To replace it, drop another one or click | Pour le remplacer, glissez-en un autre ou cliquez |
| rf.file.undo | Undo this choice | Annuler ce choix |
| rf.image.pick | Drop a picture here or click to choose one | Glissez une image ici ou cliquez pour la choisir |
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:
fields[].search,record.save,cancel,after
A form section, for app, forms 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 form blocks
- Multi step wizard vertical: six steps or more, or long ones: a vertical step list on the left and a single card on the right.
- Option group editor inline: every group as a card, one under the other, beside a preview of the whole product as the buyer will choose it: the options section of a product’s own edit page.
- Option group editor list: one ruled row per group with its rule and options in words, moved up or down, opened one at a time to edit: a menu with many groups to put in order.
- Option group editor sheet: the groups listed on the page and the one chosen open in a side sheet, its fields above the buyer’s preview and the save bar: a back office where a dish or a product is edited in a panel over its list.
- Product editor full: Edit product content and ordered pictures beside publishing and pricing controls.
- Product editor side panel: Edit a product in a narrow workspace with a compact product preview above stacked controls.
- Product editor variants grid: Prioritize the size and colour stock matrix for a product with multiple SKUs.
- Responses table: Read the received answers in a table using the current field labels.