Component Files
A CWA component has two parts: a display component the visitor sees, and optionally one or more admin manager tabs that appear when an admin selects the component in edit mode. The file structure drives auto-discovery, so no registration is needed. The display component declares its own name, styles and admin settings with defineCwaConfig.
File Convention
app/app/cwa/components/
Title/
Title.vue # the component type → CwaComponentTitle
admin/
Title.vue # a manager tab (optional)
ui/
Large.vue # a UI variant (optional)
_parts/
Underline.vue # a helper the other files import (optional)
icon.svg # the add dialog's icon (optional)
preview.webp # the add dialog's preview (optional)
Each file in the folder has one role:
| Path | Role |
|---|---|
<Type>/<Type>.vue | The component type. The folder name matches the PHP class name, and this file has the same name. Its defineCwaConfig configures the type |
<Type>/admin/*.vue | Manager tabs, one tab per file |
<Type>/ui/*.vue | UI variants an admin can pick instead of the primary file |
<Type>/_parts/*.vue | Anything else, such as a helper the type or its variants import. It is neither a type nor a variant |
See How uiComponent Names Resolve for the names these register under.
Part 1: The Display Component
The Mandatory Pattern
Every display component must do four things:
- Take the
iriprop, typed withIriProp. - Pass its props to
useCwaComponent(props), which returns the resource. - Call
defineExpose(exposeMeta), so the admin can select it. - Render only once
resource.datahas loaded.
<!-- app/app/cwa/components/Title/Title.vue -->
<template>
<div v-if="resource?.data">
<h2>{{ resource.data.title }}</h2>
</div>
</template>
<script setup lang="ts">
import type { IriProp } from '#cwa/composables/cwa-resource'
import { useCwaComponent } from '#imports'
const props = defineProps<IriProp>()
const { resource, exposeMeta } = useCwaComponent(props)
defineExpose(exposeMeta) // required — allows the admin panel to select this component
</script>
If you forget defineExpose(exposeMeta), the admin overlay cannot attach to this component.
Accessing Your Data
// resource is returned directly from useCwaComponent(props)
// Your PHP entity fields are under resource.value?.data
const title = computed(() => resource.value?.data?.title)
const publishedAt = computed(() => resource.value?.data?.publishedAt)
resource.value states:
undefined— not requested yet- an object with
data === undefined— in flight, or errored (checkresource.value.apiState.status) - an object with
data— loaded
Always guard with v-if="resource?.data" before rendering.
Opting Out of Admin Management
For presentational components that have no editable fields:
const { resource, exposeMeta } = useCwaComponent(props, [], {
manager: { disabled: true }
})
The component still renders but the admin overlay won't attach to it.
Configuring a Component
Call defineCwaConfig in the component's <script setup>. It is a compiler macro: the module reads it when the app builds, and it does nothing at runtime.
<!-- app/app/cwa/components/Title/Title.vue -->
<script setup lang="ts">
defineCwaConfig({
name: 'Title',
description: 'The main heading of a page',
icon: 'heading',
group: 'Text',
defaultData: { title: 'New title' },
styles: {
centred: { label: 'Centred', classes: 'text-center' },
underlined: { label: 'Underlined', classes: 'pb-1' },
},
})
const props = defineProps<IriProp>()
const { resource, exposeMeta, styleKeys } = useCwaComponent(props)
defineExpose(exposeMeta)
</script>
Every key is optional. Without a defineCwaConfig, the component still appears in the add component dialog, named after its folder (HeroBlock → "Hero Block").
| Key | Description |
|---|---|
name | The name in the add component dialog and the admin |
description | A line for editors in the add component dialog. Inline Markdown, see Descriptions |
icon | The icon in the add component dialog. See Icons and Previews |
group | The section of the add component dialog the component is listed under, such as 'Text' or 'Media' |
image | An extra preview in the add component dialog's detail view |
defaultData | Field values a new component starts with |
styles | The styles an admin can pick. See Style Variants |
allowMultiple | Let an admin pick several styles at once |
instantAdd | Save the component as soon as it is added, without opening it for editing first |
${}, or a second call in the same file, makes the build warn and ignore that file's config. A key the file can't declare is ignored with a warning too.defineCwaConfig only has an effect in <Type>/<Type>.vue, <Type>/ui/*.vue, a layout or a page template. In any other file the build warns once and ignores it. With implicit auto-imports off, import it: import { defineCwaConfig } from '#imports'.
What Each Kind of File Can Declare
| File | Keys |
|---|---|
A component, <Type>/<Type>.vue | name, description, icon, group, image, defaultData, styles, allowMultiple, instantAdd |
A UI variant, <Type>/ui/<Name>.vue | name, styles, allowMultiple |
| A layout or a page template | name, styles |
A variant's name is its label in the UI select. See Layouts › Configuring a Layout and Page Templates › Configuring a Page Template.
Descriptions
description is inline Markdown: **bold**, *italic* or _italic_, `code`, [text](url) links, line breaks, and blank-line paragraphs. Headings, lists, images, tables and HTML aren't supported; HTML tags are removed with a build warning, and \ keeps a Markdown character literal. The add component dialog shows it as plain text in the list and formatted in the detail view.
A link may be http(s):, mailto:, relative or #…. Any other URL, such as javascript:, shows only its text. http(s): links open in a new tab. The description is converted when the app builds and written only to admin code, so visitors never load it.
Icons and Previews
icon is one of:
- A built-in component kind:
heading,rich-text,image,gallery,carousel,video,hero,banner,card,card-grid,section,media-text,columns,container,link,button,link-group,tabs,accordion,quote,testimonial,form,newsletter,sign-up,collection,articles,table,steps,file,chart,heatmap,map,contact,social,person,peopleornotice. - A Lucide icon:
'lucide:<name>', such as'lucide:quote'. - Your own SVG in the component's folder:
'./icon.svg'.
Without icon, a <Type>/icon.svg beside the component is used, and with neither, the generic component icon. The icon shows in the component's row and beside its name in the detail view.
A custom SVG is inlined at build time into admin-only code. Scripts, event handlers, foreignObject, styles, animations and links outside the file are removed, and only its viewBox and root fill/stroke attributes are kept. Draw it with currentColor, so it takes the text colour like the built-in icons.
image is an extra preview, shown in the detail view only; it never replaces the icon. A /… or http(s): URL is used as given, and anything else, such as ~/assets/hero.webp, is imported as an asset. Without image, a <Type>/preview.webp beside the component is used.
defaultData
defaultData is an object of field values the new component starts with. When an admin adds the component from the add component dialog, these values are copied into the new resource before it is saved. Keys are the PHP entity's property names. A component added from a page data position's tab starts without them.
instantAdd
Without instantAdd, the dialog's button reads Add: the component appears in the group, still unsaved, with the manager panel open, and the admin fills in its tabs and clicks + Draft (or + Add for a component that isn't publishable). With instantAdd: true, the button reads Add now, and the component is saved straight away. Use it for a component with nothing to set up front, such as a divider.
A component with a file doesn't need it. A file can be chosen before Add, and it is uploaded straight after; see Images & Media › Admin Upload Tab.
Style Variants
Declare the styles an admin can choose in defineCwaConfig, each under a key, with a label and a class string:
defineCwaConfig({
styles: {
light: { label: 'Light', classes: 'bg-white text-black' },
dark: { label: 'Dark', classes: 'bg-black text-white' },
},
})
The picked style's classes go on the component's root element, so you don't bind them. The resource stores the key, as style:dark in uiClassNames, so pick a key you won't need to rename; the label and the classes can change freely.
For logic keyed off the picked style, use styleKeys:
const { styleKeys } = useCwaComponent(props)
const isDark = computed(() => styleKeys.value.includes('dark'))
// <div :class="{ 'ring-2': isDark }">
See useCwaComponent › Style Variants for several styles at once, styles on UI variants and how uiClassNames is stored.
Part 2: Admin Manager Tabs
One Tab
A tab is a <CwaUiManagerTab> holding kit fields. A field bound with field saves that property of the selected component:
<!-- app/app/cwa/components/Title/admin/Title.vue -->
<script setup lang="ts">
import { useCwaResourceManagerTab } from '#imports'
const { exposeMeta } = useCwaResourceManagerTab({ name: 'Title' })
defineExpose(exposeMeta) </script>
<template>
<CwaUiManagerTab> <CwaUiInput field="title" label="Title" width="lg" /> </CwaUiManagerTab></template>
defineExpose(exposeMeta) is required — it's how the resource manager discovers the tab's name and order. Without it the tab renders with no label and no ordering.<CwaUiManagerTab> lays the tab out in the manager bar's one row, scrolling sideways when the fields don't fit. Each field takes its own label; there is no wrapper component for labels. label-hidden hides it visually, and info adds an ⓘ with an explanation.
useCwaResourceManagerTab Options
| Option | Type | Description |
|---|---|---|
name | string | Tab label shown in the admin panel |
order | number | Lower numbers appear first |
disabled | boolean | Ref<boolean> | Hide the tab. A plain boolean is read once at setup; pass a ref or computed to toggle the tab on and off |
The Kit Fields
| Field | Edits |
|---|---|
<CwaUiInput> | One line of text. type sets email, url, password and others; width is xs to full |
<CwaUiNumber> | A number, with steps. Takes min, max, step and a noun for its announcements |
<CwaUiToggle> | A boolean |
<CwaUiSelect> | One choice from options of string values. nullable adds a None option, named by noneLabel |
<CwaUiMultiSelect> | Several choices, stored as an array of strings |
<CwaUiSegmented> | One choice from a few options, as buttons |
<CwaUiDatePicker> | A date and time, as a UTC ISO string. See Date and Time Pickers |
<CwaUiResourceSearch> | A reference to another resource, searched from an endpoint |
<CwaUiFileUpload> | An uploaded file. See Images & Media › Admin Upload Tab |
<CwaUiLinkInput> | A link: a page (the route field) or a URL (rawPath). The first save after switching clears the other, with Undo |
<CwaUiInlineHandoff> | A field edited on the page, such as rich text. See Multi-Line Text |
Each field shows its own save state: a line along its edge while it saves, then green, or red or amber with Retry and Reset. Another admin in the field shows as a ring with their name. Every field takes disabled and a disabledReason, shown behind its ⓘ.
Binding a Field
field, :model or v-model. With more than one, the field logs an error in development.| Binding | Use it for |
|---|---|
field="title" | The usual case. The field saves title on the tab's resource, with the debounce, save state, presence and co-editing conflicts. It needs a <CwaUiManagerTab> around it |
:model="titleModel" | A model you created with useCwaResourceModel, to pass options such as debounceTime, get/set or valid. Saves the same way |
v-model="value" | A value of your own. Nothing is saved for you |
<script setup lang="ts">
import { useCwaResourceManagerTab, useCwaResourceModel } from '#imports'
const { exposeMeta, iri } = useCwaResourceManagerTab({ name: 'Settings' })
const perPage = useCwaResourceModel<number>(iri, 'perPage', { debounceTime: 0 })
defineExpose(exposeMeta)
</script>
<template>
<CwaUiManagerTab>
<CwaUiSelect field="resourceIri" label="Data category" :options="categoryOptions" />
<CwaUiNumber :model="perPage" label="Items per page" :min="1" noun="item" />
</CwaUiManagerTab>
</template>
<CwaUiFileUpload> takes field, or the return of useCwaResourceUpload as :upload. <CwaUiLinkInput> binds its route and rawPath fields by name.
Multi-Line Text
The manager bar is one row, so multi-line text isn't edited in a tab. <CwaUiTextarea> renders nothing in a manager tab and warns once in development. Edit the text on the page instead, and put a <CwaUiInlineHandoff> in the tab:
<!-- app/app/cwa/components/HtmlContent/admin/Content.vue -->
<template>
<CwaUiManagerTab>
<CwaUiInlineHandoff field="html" label="Content" />
</CwaUiManagerTab>
</template>
The hand-off shows a preview of the field with Edit on page, which moves focus to the editor on the page, or opens a dialog when there isn't one. The editor registers itself with useCwaInlineEditor; see Rich-Text Editor.
Multiple Tabs
Create one file per tab:
app/app/cwa/components/Article/admin/
Content.vue # useCwaResourceManagerTab({ name: 'Content', order: 1 })
Image.vue # useCwaResourceManagerTab({ name: 'Image', order: 2 })
Settings.vue # useCwaResourceManagerTab({ name: 'Settings', order: 3 })
Each file is independent. The manager bar shows a selection's tabs once they have all loaded.
Read-Only Admin Tab
Not every tab needs to write. A field given disabled or readonly shows a value without saving it:
<template>
<CwaUiManagerTab>
<CwaUiInput :model-value="resource?.data?.createdAt" label="Created" readonly />
</CwaUiManagerTab>
</template>
<script setup lang="ts">
import { useCwaResourceManagerTab } from '#imports'
const { exposeMeta, resource } = useCwaResourceManagerTab({ name: 'Dates', order: 99 })
defineExpose(exposeMeta)
</script>
Part 3: Editing on the Page
Short text, such as a title, can be edited where it sits. <LazyCwaUiInlineEdit> takes a model from useCwaResourceModel:
<!-- app/app/cwa/components/Title/Title.vue -->
<template>
<h1>
<LazyCwaUiInlineEdit
v-if="$cwa.admin.isEditing"
:model="title"
label="Title"
placeholder="Add a title"
/>
<template v-else>
{{ resource?.data?.title }}
</template>
</h1>
</template>
<script setup lang="ts">
import { toRef } from 'vue'
import type { IriProp } from '#cwa/composables/cwa-resource'
import { useCwaComponent, useCwaResourceModel } from '#imports'
const props = defineProps<IriProp>()
const { resource, exposeMeta, $cwa } = useCwaComponent(props)
const title = useCwaResourceModel<string>(toRef(props, 'iri'), 'title')
defineExpose(exposeMeta)
</script>
It saves as you type, as the manager bar's input does. A click, Enter or Space starts editing. Enter finishes, and Escape stops and keeps what was typed. While a save has failed, it says so, and Escape opens the bar's status with Retry and Reset.
An empty component needs something to click in edit mode. <LazyCwaUiEditPlaceholder label="Add an image" /> draws an empty box with that label, and an optional info behind an ⓘ. See Images & Media › Display Component.
Lazy prefix and a v-if on $cwa.admin.isEditing, as above, so visitors never download the editing components.Before you ship your components, see Categorise and Restrict for how to keep the add component dialog easy for editors.
Page Templates
How to create CWA page template components that place a page's component groups using CwaComponentGroup and CwaPage.
CLI Generator
Scaffold a new CWA display component from the command line — generates the Vue file with the correct useCwaComponent boilerplate and prints the matching API command.