Contextual side cards — Form block

Pro

form-contextual-side-cards · for app, forms pages

Contextual side cards

A form whose author needs help or a check while typing: tips or a live summary of the record beside it

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-contextual-side-cards

Usage

Its demo data, shortened (Using blocks).

<script setup lang="ts">
import FormContextualSideCards from '@/components/trame/blocks/form/form-contextual-side-cards.vue'

const props = {
title: "New product",
aside: [
{
title: "Preview",
kind: "summary",
fields: [
"name",
"category"
]
},
{
title: "Tips",
kind: "tips",
items: [
"A short name, with the scent first.",
"Mention the burn time in the description."
]
}
],
intro: "It will be 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 store.",
options: [
{
value: "bougies",
label: "Scented candles"
},
{
value: "diffuseurs",
label: "Diffusers and mists"
}
],
required: true
}
],
sections: [
{
id: "identity",
title: "Presentation",
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>
<FormContextualSideCards v-bind="props" />
</template>

Props

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

PropTypeDescription
title*stringWordsthe record being created or edited ("New product", "Edit the amber candle")
introstringWordsone line under the title
fields*Field[]the form’s fields, in order
sectionsSection[]the sections shown, in order
valuesRecord<string, unknown>Datathe record’s current values by field name when editing; absent when creating (the fields start empty)
errorsRecord<string, string>Datawhat the server refused, by field name: the message says what to correct
asideAside[]cards beside the form, e.g. tips or a preview
submit*stringActionthe page action the form posts to; through the host it receives `{ data }` when creating, `{ id, patch }` (the changed fields) when the values have an id
cancelstringActionwhere Cancel leads (the list or the record)
optionsOptionsthe block’s settings: layout choices and secondary words, read by every variant
Field fields[] · 10 props
PropTypeDescription
name*stringDesignthe key of the field in `values`, in `errors` and in what the form sends
label*stringWordsthe field’s name ("Product name")
type'text' | 'email' | 'tel' | 'url' | 'number' | 'money' | 'date' | 'textarea' | 'select' | 'switch' | 'radio-cards' | 'relation'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
helpstringWordsone sentence on what the field is for, said under its label
placeholderstringWordsthe shape expected, never a value that looks real
optionsOption[]the choices, for a select or a relation
unitstringWordsa unit written after a number ("g", "days")
requiredbooleantrue: it must be filled in
readonlybooleantrue: the field is shown but cannot be changed
halfbooleanhalf the width on wide screens, two to a row
Option fields[].options[] · 3 props
PropTypeDescription
value*stringDesignwhat is sent (the record’s id for a relation)
label*stringWordswhat is read
descriptionstringWordsradio-cards: one line under the label
Section sections[] · 4 props
PropTypeDescription
id*stringDesignthe section’s key
title*stringWordswhat the fields of the section are about ("Price and stock")
descriptionstringWordsone sentence under the title
fields*string[]Designa field name
Aside aside[] · 4 props
PropTypeDescription
title*stringWordsthe card’s heading ("Tips", "Preview")
kind*'tips' | 'summary'tips: a list of advice; summary: the record as typed so far, echoing only what was typed
itemsstring[]Wordsone tip
fieldsstring[]Designsummary: the fields to echo, the first as the heading
Options options · 7 props
PropTypeDescription
submitLabelstringWordsthe save button ("Save the product")
cancelLabelstringWordsthe cancel link ("Cancel")
unsavedLabelstringWordsthe hint shown while edits are not saved ("Unsaved changes")
formErrorstringWordswhat the server said about the whole form, if it refused it ("The product could not be saved")
currencystringDesignISO 4217 for money fields, euro by default
markOptionalbooleanwrite "optional" after the optional fields, beside the "*" of the required ones
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: record.save, cancel

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

  • Builder preview: Review the full respondent-facing form with a compact field outline beside it.
  • Builder: Arrange fields and edit their settings alongside a live form preview, then save them in one go.
  • Multi step accordion: short steps that read as sections (address, delivery, payment): collapsible cards, one open at a time, the phone default.
  • Multi step stepper top: a creation flow of three to five steps: numbered steps across the top, the form beside tips and a live preview.
  • 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.

All 17 form blocks