Building a Studio Editor
A studio is a full-size Home Assistant dialog with a config panel on the left and a live preview on the right. LCARdS uses one for every card whose config is too big for a form: MSD, chart, data grid, layout, alert overlay, astrometrics, and the data source editor. All of them share one shell, so they look and behave alike.
This page shows how to build one, how to launch it from a card editor and how to test it. The short Basic Card Editor section at the end covers the plain tabbed editor every card has, which is also where a studio is launched from.
The full rule set for editor code is .claude/rules/editor.md (Field Rendering, Approved Shared Components, "Dialogs, surfaces and messages", CSS and Theming). This page follows it and cites the files every sample comes from; when the two disagree, the code wins and the instructions file needs fixing.
When to Build a Studio
Build a studio when the user needs to see the card while editing it, or when the config has more structure than a tab of fields can show. Otherwise a plain card editor is enough.
- Studio: nested lists (chart series, MSD overlays, astrometrics objects), placement on a canvas (MSD anchors, layout areas), something that never shows on the dashboard by itself (the alert overlay only appears during an alert, so its studio shows each condition on a mock screen), or a preview with tools (pick a point, replay an animation).
- Plain editor: a card with a handful of options, where Home Assistant's own preview beside the card editor already shows the change (button, elbow, slider, select menu).
- Both: a card with a studio still has a card editor. For the layout card, alert overlay and astrometrics card it is mostly a launcher (a summary and an "Open ... Studio" button, plus the YAML and Main Engineering tabs); the chart, data grid and MSD editors keep a few settings beside the button.
The Existing Studios
| Studio | Element | File | Opened from | Split (config / preview) |
|---|---|---|---|---|
| MSD | lcards-msd-studio-dialog | src/editor/dialogs/lcards-msd-studio-dialog.js (+ msd-studio/) | lcards-msd-editor.js _openMsdStudio() | 33.3% / 66.6% |
| Chart | lcards-chart-studio-dialog | lcards-chart-studio-dialog.js | lcards-chart-editor.js _openChartStudio() | 40% / 60% |
| Data Grid | lcards-data-grid-studio-dialog-v4 | lcards-data-grid-studio-dialog.js | lcards-data-grid-editor.js _openConfigurationStudio() | 50% / 50% (shared default) |
| Layout | lcards-layout-studio-dialog | lcards-layout-studio-dialog.js | lcards-layout-card-editor.js _openStudio() | 1fr / 2fr |
| Alert | lcards-alert-overlay-studio-dialog | lcards-alert-overlay-studio-dialog.js (+ alert-studio/) | lcards-alert-overlay-editor.js _openAlertStudio() | 40% / 60% |
| Astrometrics | lcards-astrometrics-studio-dialog | lcards-astrometrics-studio-dialog.js (+ astro-studio/) | lcards-astrometrics-editor.js _openStudio() | 33.3% / 66.6% |
| Data source | lcards-datasource-studio-dialog | lcards-datasource-studio-dialog.js | Main Engineering > Data Sources (lcards-datasource-editor-tab.js), the chart studio's "Manage data sources" | 50% / 50% |
Studio files live in src/editor/dialogs/, editors in src/editor/cards/. The Alert Studio is the smallest complete one (about 300 lines plus its forms mixin in alert-studio/alert-studio-forms.js), and the example below follows it. The data source studio is the odd one out: it is a sub-studio rendered inside other editors' templates, with an open property and save / cancel events instead of the launcher pattern.
Anatomy of a Studio
A studio is a LitElement that renders an ha-dialog with the shared shell classes, keeps its own working copy of the config, and sends the whole config back once, on Save.
- Shell:
ha-dialogwithopen,flexcontentandheader-title. Withoutflexcontentthe dialog body doesn't stretch its content, so the inset shrinks to fit a short tab. There is no LCARdS dialog wrapper and noDialogMixin(that is internal to Home Assistant's own source). - Styles:
studioDialogStyles(src/editor/dialogs/studio-dialog-styles.js) fixes the dialog at 90vh and 95vw, keeps.dialog-contentin the flex chain so only.tab-contentscrolls, draws.studio-layoutas the black inset (var(--primary-background-color)), and styles the tab group, the floating.canvas-toolbar,.zoom-controlsand.placeholder-content. It also setsfont-family: var(--ha-font-family-body)on.dialog-content, so LCARdS text follows the theme font like Home Assistant's controls do. AddeditorStyles(src/editor/base/editor-styles.js, which includes the info guide styles) andmessageStyles(src/editor/base/surface-styles.js, for.hintand.banner). - Split:
.studio-layoutis 50/50 and stacks into two rows below 1024px. A studio changes onlygrid-template-columns, and when it does it must setgrid-template-rows: minmax(0, 1fr)in the same rule, or the shared narrow-screen rule leaves an empty second row (tests/editor/studio-layout-css.test.js). Don't set heights on.dialog-content,.tab-contentor the panels. - Sections: group fields in
lcards-form-section(src/editor/components/shared/lcards-form-section.js), the outlined section card built onha-expansion-panel. Every section has anicon, nested sections included (nestedgives the tighter spacing). Don't add tinted containers, accent borders or your own card styles around them: the section is the container. - Help: one way for each kind (Help Text and Messages):
renderInfoGuide()for explanations, the section'sdescriptionfor one line about a section, the field'shelperfor one line about a field,lcards-messagefor something to notice now (at most 200 characters for an info message). - Preview: the real card element (chart, data grid, astrometrics, layout) or a dedicated preview element (
lcards-alert-preview, the MSD canvas), fed from the working copy. - Footer:
<ha-dialog-footer slot="footer">with Cancel (slot="secondaryAction",appearance="plain") then Save (slot="primaryAction",variant="brand", anmdi:checkicon). Documentation and Reset go first, in a<div class="footer-start" slot="secondaryAction">, whichstudioDialogStylespushes to the left.tests/editor/dialog-footer-guards.test.jsfails on a hand-builtdiv slot="footer"and on a Cancel that isn't plain. - YAML: the last tab is
lcards-studio-yaml-tab(src/editor/components/yaml/lcards-studio-yaml-tab.js) with the iconmdi:code-braces.
Open, Edit, Save
This is the flow of the Alert Studio and its launcher (src/editor/cards/lcards-alert-overlay-editor.js:148-167, src/editor/dialogs/lcards-alert-overlay-studio-dialog.js); the chart, data grid, layout, MSD and astrometrics studios follow the same steps.
- The studio never commits while it is open. Edits change only
_workingConfig; the card editor and Home Assistant see nothing until Save.tests/browser/alert-studio.spec.jschecks this: an edit shows in the preview, the editor has received noconfig-changed, Save hands over the whole config, and Cancel hands over nothing. - Save replaces the config. The studio sends the whole config, so keys the user deleted must disappear. That is why the launcher assigns
this.configinstead of calling_updateConfig(), which deep-merges and would keep them (see Working Copy vs Committed Config). - Home Assistant calls
setConfig()back.hui-element-editor(in the Home Assistant frontend) answers aconfig-changedby calling the editor'ssetConfig()with the new config, which clones it, rebuilds the YAML tab and runs validation (LCARdSBaseEditor.js:102-133).
Dialogs and Portals
Mount every dialog, studio or portal near <home-assistant> with mountDialogNearHomeAssistant(), never on document.body.
// src/utils/lcards-shared-helpers.js:64
export function mountDialogNearHomeAssistant(dialogEl, startEl) {
const haRoot = (startEl && findHomeAssistantRoot(startEl)) ?? document.querySelector('home-assistant');
const mountRoot = haRoot?.shadowRoot ?? document.body;
mountRoot.appendChild(dialogEl);
}- Why: since Home Assistant 2026.7, its pickers (
ha-entity-pickerand the rest) andha-dialogread states, registries and settings from Lit contexts that<home-assistant>provides. A dialog underdocument.bodyis a sibling of<home-assistant>, not a descendant, so the contexts never resolve and pickers come up empty, with no error. Mounting in its shadow root mirrors Home Assistant's own dialog manager. startEl: passthis.findHomeAssistantRoot()walks up through slots and shadow roots from there. In the browser test harness there is no<home-assistant>, so the helper falls back todocument.body, which is whytests/browser/alert-studio.spec.jsfinds the studio withdocument.querySelector.- Dialogs inside a studio (a card picker, a confirm) are mounted the same way, with the studio as
startEl(alert-studio/alert-studio-forms.js:1164). - Imperative dialogs (built with
document.createElement('ha-dialog')) get their footer fromcreateDialogFooter({ secondary, primary })in the same file (lcards-shared-helpers.js:78). - No native dialogs. Never
confirm(),alert()orprompt()(tests/editor/editor-guards.test.js). UseshowConfirmDeleteDialog,showInfoDialogandshowPromptDialogfromsrc/views/layout-edit-dialogs.js. The chart studio's "Discard unsaved changes?" isshowConfirmDeleteDialog({ title, message, confirmText: 'Discard' })(lcards-chart-studio-dialog.js:698). - Closing:
ha-dialogfiresclosedwhen it closes for any reason (Esc, its close button,open = false), and some components inside a dialog fire their ownclosed, which bubbles. Stop the event so it doesn't close the card editor around the studio, and act only whene.target === e.currentTarget(_onDialogClosed(),lcards-astrometrics-studio-dialog.js:2072).tests/editor/studio-dialog-guards.test.jsfails on an@closedhandler that acts without the check. - Imperative
closedlisteners go throughonDialogClosed(dialog, handler)(lcards-shared-helpers.js), which runs the handler only for the dialog's ownclosed. A bareaddEventListener('closed', ...)failstests/editor/editor-guards.test.js: a card picker'sha-selector a nested dialog inside would otherwise remove the outer dialog. - Home Assistant's card picker (
hui-card-picker; recipe inlcards-layout-studio-dialog.js_openCardPickerandalert-studio/alert-studio-forms.js):- Home Assistant registers it lazily: check
customElements.get('hui-card-picker')first, and if it is missing tell the user (showInfoDialog) to open "Add card" on a dashboard once. The layout view primes it (src/views/lcards-layout-view.js). - Create an
ha-dialogwithheaderTitle, mount it withmountDialogNearHomeAssistant, setopen = trueand awaitupdateComplete. - Set
picker.hassandpicker.lovelace(a config withviews: [{ title: 'Home', path: 'home', cards: [] }]), append the picker as a direct child of the dialog, thenrequestUpdate()it after about 80ms. - On the picker's
config-changed: stop it, close the dialog, deep-copydetail.config. Remove the dialog inonDialogClosed. - The MSD Studio still reaches the picker through an event proxy (
open-card-pickerto the MSD editor,card-picker-resultback ondocument); new code opens it directly.
- Home Assistant registers it lazily: check
Build a Studio, Step by Step
The example builds lcards-mycard-studio-dialog for a card lcards-mycard (card type mycard). It is the Alert Studio reduced to two tabs, with a real-card preview in the style of the astrometrics and data grid studios. The names mycard, getMyCardSchema and DOCS.mycard are placeholders; every LCARdS import and method is real.
1. The Element, the Working Copy and the Edit Methods
The studio is the "editor" that FormField.renderField() writes to, so it implements the four members FormField calls: hass, _getSchemaForPath(), _getConfigValue() and _setConfigValue() (lcards-form-field.js:80,97,302).
// src/editor/dialogs/lcards-mycard-studio-dialog.js
// Based on src/editor/dialogs/lcards-alert-overlay-studio-dialog.js:15-157
import { LitElement, html, css } from 'lit';
import { createRef, ref } from 'lit/directives/ref.js';
import { editorStyles } from '../base/editor-styles.js';
import { messageStyles } from '../base/surface-styles.js';
import { studioDialogStyles } from './studio-dialog-styles.js';
import { LCARdSBaseEditor } from '../base/LCARdSBaseEditor.js';
import { LCARdSFormFieldHelper as FormField } from '../components/shared/lcards-form-field.js';
import { renderInfoGuide } from '../components/shared/info-guide.js';
import { lcardsLog } from '../../utils/lcards-logging.js';
import { docsUrl, DOCS } from '../../utils/docs-url.js';
import { getMyCardSchema } from '../../cards/schemas/lcards-mycard-schema.js';
import '../components/shared/lcards-form-section.js';
import '../components/shared/lcards-message.js';
import '../components/yaml/lcards-studio-yaml-tab.js';
const TABS = [
{ id: 'config', label: 'Config', icon: 'mdi:cog-outline' },
{ id: 'yaml', label: 'YAML', icon: 'mdi:code-braces' },
];
/** A config without its undefined values (deleted keys stay deleted). @param {any} c */
const clean = (c) => JSON.parse(JSON.stringify(c ?? {}));
const PREVIEW_DELAY = 150;
export class LCARdSMyCardStudioDialog extends LitElement {
static get properties() {
return {
hass: { attribute: false },
_workingConfig: { state: true },
_activeTab: { state: true },
};
}
set config(value) {
this._handled = false;
this._initialConfig = clean(value);
this._workingConfig = clean(value);
}
get config() { return this._workingConfig; }
constructor() {
super();
/** @type {any} */
this.hass = undefined;
/** @type {any} */
this._initialConfig = {};
/** @type {any} */
this._workingConfig = {};
this._handled = false;
this._activeTab = 'config';
this.cardType = 'mycard';
this._previewRef = createRef();
/** @type {any} */
this._previewCard = null;
/** @type {ReturnType<typeof setTimeout> | undefined} */
this._previewTimer = undefined;
}
// ── The edit methods FormField uses, on the working copy ──
_getSchema() {
return getMyCardSchema();
}
/** @param {string} path */
_getSchemaForPath(path) {
// The card editors' path lookup (patternProperties, additionalProperties, oneOf)
return LCARdSBaseEditor.prototype._getSchemaForPath.call(this, path);
}
/** @param {string} path */
_getConfigValue(path) {
/** @type {any} */
let value = this._workingConfig;
for (const key of path.split('.')) {
if (value === undefined || value === null) return undefined;
value = value[key];
}
return value;
}
/**
* Set one key; empty values remove it (and empty parents).
* @param {string} path
* @param {any} value
*/
_setConfigValue(path, value) {
if (value === undefined || value === null || value === '') {
this._removeConfigPath(path);
return;
}
const next = clean(this._workingConfig);
const keys = path.split('.');
let node = next;
for (const key of keys.slice(0, -1)) {
if (!node[key] || typeof node[key] !== 'object') node[key] = {};
node = node[key];
}
node[keys[keys.length - 1]] = value;
this._workingConfig = next;
}
/** @param {string} path */
_removeConfigPath(path) {
const next = clean(this._workingConfig);
const keys = path.split('.');
/** @type {any[]} */
const chain = [next];
for (const key of keys.slice(0, -1)) {
const child = chain[chain.length - 1]?.[key];
if (!child || typeof child !== 'object') return;
chain.push(child);
}
delete chain[chain.length - 1][keys[keys.length - 1]];
// prune parents left empty
for (let i = chain.length - 1; i > 0; i--) {
if (Object.keys(chain[i]).length) break;
delete chain[i - 1][keys[i - 1]];
}
this._workingConfig = next;
}
}- The config setter takes a copy twice:
_initialConfigis the baseline (for an unsaved-changes check or a Reset),_workingConfigis what the tabs and preview show. The launcher already passes a JSON copy; cloning again keeps the studio safe from any caller. - Every edit assigns a new object to
_workingConfig. It is a reactivestateproperty, so the assignment re-renders the tabs and the preview; mutating it in place would not. - Empty values remove the key. A cleared field leaves no
color: ''behind, and empty parent objects are pruned, so the saved YAML stays clean. _getSchemaForPathis borrowed fromLCARdSBaseEditor. It resolves dotted paths throughproperties,patternProperties,additionalProperties, arrayitemsandoneOf, and callsthis._getSchema(), which the studio supplies. Import the schema module directly rather than reading it fromwindow.lcards.core.configManager.cardTypeis what FormField and the YAML tab use for docs links and schema lookups that go by card type.
2. Render the Shell
render() is the shared shell: the dialog, the split, the tabs, the preview host and the footer. Only the tab bodies and the preview are yours.
// Based on lcards-alert-overlay-studio-dialog.js:159-229
/** @param {Event} e */
_onTab(e) {
const value = /** @type {any} */ (e.target).activeTab?.getAttribute('value');
if (value) this._activeTab = value;
}
/** Only the dialog's own `closed` cancels; closes bubbling from inside must not. @param {Event} e */
_onDialogClosed(e) {
e.stopPropagation();
if (e.target === e.currentTarget) this._handleCancel();
}
render() {
return html`
<ha-dialog open flexcontent header-title="My Card Studio" @closed=${this._onDialogClosed}>
<div class="dialog-content">
<div class="studio-layout">
<div class="config-panel">
<ha-tab-group @wa-tab-show=${this._onTab}>
${TABS.map((t) => html`
<ha-tab-group-tab value=${t.id} ?active=${this._activeTab === t.id}>
<ha-icon icon=${t.icon}></ha-icon>
${t.label}
</ha-tab-group-tab>`)}
</ha-tab-group>
<div class="tab-content">${this._renderActiveTab()}</div>
</div>
<div class="preview-panel">
<div class="preview-host" ${ref(this._previewRef)}></div>
</div>
</div>
</div>
<ha-dialog-footer slot="footer">
<div class="footer-start" slot="secondaryAction">
<ha-button appearance="plain" @click=${() => window.open(docsUrl(DOCS.mycard), '_blank', 'noopener')}>
<ha-icon icon="mdi:book-open-variant" slot="start"></ha-icon>
Documentation
</ha-button>
</div>
<ha-button slot="secondaryAction" appearance="plain" @click=${this._handleCancel}>Cancel</ha-button>
<ha-button slot="primaryAction" variant="brand" @click=${this._handleSave}>
<ha-icon icon="mdi:check" slot="start"></ha-icon>
Save
</ha-button>
</ha-dialog-footer>
</ha-dialog>
`;
}
_renderActiveTab() {
switch (this._activeTab) {
case 'yaml': return html`
<lcards-studio-yaml-tab
.hass=${this.hass}
.config=${this._workingConfig}
.schema=${getMyCardSchema()}
cardType="mycard"
@yaml-config-changed=${(/** @type {CustomEvent} */ e) => { this._workingConfig = clean(e.detail.config); }}>
</lcards-studio-yaml-tab>`;
default: return this._renderConfigTab();
}
}- Tabs:
ha-tab-groupfireswa-tab-show; read the tab withactiveTab?.getAttribute('value'), not a.valueproperty. Each tab has anmdi:icon and a label; YAML is last. - Render only the active tab. The tab body is rebuilt on switch, so a tab that is not shown costs nothing. The inset keeps one height on every tab because
.tab-contentscrolls inside a fixed dialog (tests/ha/ha.spec.js, "the inset keeps one height on every tab"). - The title is a name ("My Card Studio"); the card editor's button says "Open My Card Studio".
- The YAML tab fires
yaml-config-changedwith the parsed config only for YAML that parses to an object. It leaves the text and cursor alone when the studio echoes back the config it just sent, so typing is never interrupted (lcards-studio-yaml-tab.js:60-71). - A floating toolbar over the preview uses the shared
.canvas-toolbar,.canvas-toolbar-group,.canvas-toolbar-group-labeland.canvas-toolbar-buttonclasses (studio-dialog-styles.js); see the Alert Studio's_renderToolbar()(lcards-alert-overlay-studio-dialog.js:231-266) for the collapsed and expanded states.
3. The Config Tab
Fields come from the card schema through FormField.renderField(), grouped in outlined lcards-form-sections with icons, with explanations in an info guide.
// Pattern: alert-studio/alert-studio-forms.js:87-140
_renderConfigTab() {
return html`
${renderInfoGuide({
header: 'How My Card works',
icon: 'mdi:information-outline',
body: html`
<p>The card shows one entity's state as a bar. The preview updates as you edit; Save keeps the changes.</p>
`,
})}
<lcards-form-section
header="Entity"
description="The entity the card shows"
icon="mdi:home-automation"
?expanded=${true}
outlined>
${FormField.renderField(this, 'entity')}
${FormField.renderField(this, 'height', { label: 'Height' })}
<lcards-form-section
header="Colours"
icon="mdi:palette-outline"
outlined
nested>
${FormField.renderField(this, 'style.color')}
${FormField.renderField(this, 'style.background')}
</lcards-form-section>
</lcards-form-section>
`;
}- No raw controls. No
<input>,<select>,<textarea>, bareha-selectorbeside a label div, orha-textfield(it renders at 0px).FormField.renderField(editor, path, options)picks theha-selectorfrom the schema (see Validation and Schema Hints);optionstakeslabel,helper,selectorOverride,value,disabledandrequired(lcards-form-field.js:57-70). - Reuse the shared controls before writing new ones (
src/editor/components/shared/):lcards-color-pickerandlcards-color-listfor colours (FormField renders the colour picker for a schema withx-ui-hints.widget: 'lcards-color-picker'),lcards-form-sectionandlcards-collapsible-section,renderInfoGuide(),renderFilterChips()for a single-choice row of pills,lcards-message,lcards-asset-source-picker, andlcards-zone-list-editor(insrc/editor/components/). The Alert Studio edits a content card with that card's own editor instead of rebuilding its fields. - No added decoration. No accent-coloured panels, tinted boxes, gradient headers, emoji or badges: the section card, its icon and Home Assistant's controls are the look. Colours come from theme variables (
var(--primary-color),var(--divider-color),var(--secondary-text-color)), never hex values or a new palette. - Spacing, radius and motion use Home Assistant's variables:
var(--ha-space-N),var(--ha-border-radius-*),var(--ha-border-width-*),var(--ha-box-shadow-s/m/l)(never a hand-written shadow),var(--ha-animation-duration-*)andvar(--ha-font-size-*). See the Home Assistant CSS Variable Reference. - Home Assistant elements:
ha-inputandha-textarea(withhint, nothelper-text) for text that isn't a schema field,ha-buttonwithvariant="brand","danger"or"warning"andappearance="plain"for cancel-like actions,ha-spinner size="small"while loading (ha-circular-progressno longer exists),ha-switchwith its label inside,ha-icon-buttonwith.label. The dead elements are listed in Home Assistant Elements, andnpm run validate:ha-compatfails the build on the dead ones.ha-buttonsizes arexs,s,m,landxl: any other value (small,large) is ignored, andvalidate:ha-compatflags it;?loadingshows a spinner and blocks clicks. - Text: sentence case for new labels, "Home Assistant" in full, no em dashes. Delete is permanent, Remove is reversible.
4. The Live Preview
The preview shows the working copy and nothing else: mount the real card once, then hand it each new config.
// Based on lcards-astrometrics-studio-dialog.js:264-271,478-514
firstUpdated() {
const host = /** @type {HTMLElement | undefined} */ (this._previewRef.value);
if (!host) return;
const card = /** @type {any} */ (document.createElement('lcards-mycard'));
try {
card.setConfig(this._previewConfig());
} catch (error) {
lcardsLog.warn('[MyCardStudio] Preview config rejected', error);
}
card.hass = this.hass;
host.replaceChildren(card);
this._previewCard = card;
}
/** @param {Map<string, unknown>} changed */
updated(changed) {
if (changed.has('hass') && this._previewCard) this._previewCard.hass = this.hass;
if (changed.has('_workingConfig') && this._previewCard) {
clearTimeout(this._previewTimer);
this._previewTimer = setTimeout(() => this._updatePreview(), PREVIEW_DELAY);
}
}
_updatePreview() {
try {
this._previewCard?.setConfig(this._previewConfig());
} catch (error) {
lcardsLog.warn('[MyCardStudio] Preview config rejected', error);
}
}
/** The config the preview shows: the working copy, filling the panel. */
_previewConfig() {
return { ...clean(this._workingConfig), type: 'custom:lcards-mycard', height: '100%' };
}
disconnectedCallback() {
super.disconnectedCallback();
clearTimeout(this._previewTimer);
this._previewCard = null;
}- Config before connect. Call
setConfig()and sethassbefore appending the card, so its first update has both (lcards-chart-studio-dialog.js:556-560). - Hand the preview a copy, and only preview-only changes on top of it (
height: '100%', a chosen alert condition, a look picked in the toolbar). Preview-only values never go into_workingConfig, so they are never saved. - Debounce rebuilds. The astrometrics studio waits 150ms, the chart studio 300ms and rebuilds the whole card (
_schedulePreviewUpdate(),lcards-chart-studio-dialog.js:528-566), which suits a card whosesetConfig()can't change everything in place. - Catch a rejected config.
setConfig()throws on a config the card can't take; log it and keep the last good preview, or show an empty or error state next to the mount (the chart studio's.preview-state), never inside it. - Keep
hasslive. Forwardhassto the preview card inupdated(), and have the launcher forward it to the open studio (step 5). - A preview never acts. It must not call services, change helpers or raise anything on the real screen: the Alert Studio's
lcards-alert-previewbuilds the alert inside a mock screen and never touchesinput_select.lcards_alert_mode, and the astrometrics card in studio mode turns taps into selections (attachStudio()). - Tear it down on close. Clear timers, observers and listeners in
disconnectedCallback(); the launcher removes the dialog onclosed, which disconnects the preview card and runs its own cleanup.
5. Save, Cancel and Register
// lcards-alert-overlay-studio-dialog.js:268-285, 287-316
_handleSave() {
if (this._handled) return;
this._handled = true;
this.dispatchEvent(new CustomEvent('config-changed', { detail: { config: clean(this._workingConfig) } }));
this._handleClose();
}
_handleCancel() {
if (this._handled) return;
this._handled = true;
this._handleClose();
}
_handleClose() {
this.dispatchEvent(new CustomEvent('closed'));
}
static get styles() {
return [
editorStyles,
studioDialogStyles,
messageStyles,
css`
:host { display: block; }
.studio-layout { grid-template-columns: 40% 60%; grid-template-rows: minmax(0, 1fr); }
ha-tab-group { flex-shrink: 0; }
lcards-form-section { display: block; }
.preview-host { flex: 1; min-height: 0; display: flex; padding: var(--ha-space-4); }
`,
];
}
}
if (!customElements.get('lcards-mycard-studio-dialog')) {
customElements.define('lcards-mycard-studio-dialog', LCARdSMyCardStudioDialog);
}_handledmakes Save and Cancel run once. Save closes the studio, and the dialog's ownclosedcan follow; without the flag a Save could also count as a Cancel.- Save sends a clean copy of the whole config. A studio can tidy it first: the data grid studio runs
compactDataGridConfig(), the chart studio drops an emptydata_sourcesobject. - Cancel sends no config. If the studio tracks changes, it can ask first: the chart studio compares
_initialConfigwith_workingConfigand confirms withshowConfirmDeleteDialogbefore discarding. - The events need not bubble. The launcher listens on the studio element itself. The alert, chart and layout studios add
bubbles: true, composed: true; the astrometrics and data grid studios don't. Both work. - The studio registers itself in its own file with the guard, like an editor. Only cards are registered centrally in
src/lcards-main.js.
Launching the Studio from the Card Editor
The card editor creates the studio on demand, passes it a copy of its config, replaces its config on Save and removes the studio on close.
// src/editor/cards/lcards-mycard-editor.js
// Based on src/editor/cards/lcards-alert-overlay-editor.js:25-38,107-167
import { html } from 'lit';
import { fireEvent } from 'custom-card-helpers';
import { LCARdSBaseEditor } from '../base/LCARdSBaseEditor.js';
import { configToYaml } from '../utils/yaml-utils.js';
import { mountDialogNearHomeAssistant, onDialogClosed } from '../../utils/lcards-shared-helpers.js';
export class LCARdSMyCardEditor extends LCARdSBaseEditor {
constructor() {
super();
this.cardType = 'mycard';
/** @type {any} Open studio dialog, kept in sync with hass */
this._studio = null;
}
/** @param {Map<string, unknown>} changedProps */
updated(changedProps) {
super.updated(changedProps);
if (changedProps.has('hass') && this._studio) this._studio.hass = this.hass;
}
_getTabDefinitions() {
return [
{ label: 'Configuration', content: () => this._renderLauncher() },
...this._getUtilityTabs(),
];
}
_renderLauncher() {
return html`
<div class="info-card">
<div class="info-card-content">
<h3>My Card Studio</h3>
<p>Every setting, with a live preview of the card.</p>
</div>
<div class="info-card-actions">
<ha-button @click=${this._openStudio}>
<ha-icon icon="mdi:tune-variant" slot="start"></ha-icon>
Open My Card Studio
</ha-button>
</div>
</div>
`;
}
/** Open the studio on a copy of the config; Save replaces it (deleted keys must go). */
async _openStudio() {
await import('../dialogs/lcards-mycard-studio-dialog.js');
const dialog = /** @type {any} */ (document.createElement('lcards-mycard-studio-dialog'));
dialog.hass = this.hass;
dialog.config = JSON.parse(JSON.stringify(this.config || {}));
this._studio = dialog;
dialog.addEventListener('config-changed', (/** @type {CustomEvent} */ e) => {
this.config = e.detail.config;
this._isUpdatingYaml = true;
this._yamlValue = configToYaml(this.config);
requestAnimationFrame(() => { this._isUpdatingYaml = false; });
fireEvent(this, 'config-changed', { config: this.config });
this.requestUpdate();
});
onDialogClosed(dialog, () => {
dialog.remove();
if (this._studio === dialog) this._studio = null;
});
mountDialogNearHomeAssistant(dialog, this);
}
}
if (!customElements.get('lcards-mycard-editor')) customElements.define('lcards-mycard-editor', LCARdSMyCardEditor);- Load the studio with
import()when the button is pressed (the Alert Studio does), or with a staticimport '../dialogs/lcards-mycard-studio-dialog.js'at the top of the editor (chart, data grid, layout, MSD and astrometrics do). Both keep it out of the main chunk, because the editor itself is a lazy chunk; a dynamic import also keeps a large studio out of the editor chunk until it is needed. Never import a studio from a card file orsrc/lcards-main.js(see Lazy Loading). - The launcher card uses the
.info-cardclasses fromeditorStyles; a few counts in the card (the Alert Studio shows the display, dismiss mode and custom card count) tell the user what is configured without opening the studio. _isUpdatingYamlstops the YAML tab's own change handler from echoing the rebuilt text back as an edit.- Forward
hassto the open studio inupdated(), as every studio launcher does (tests/editor/studio-dialog-guards.test.js), so its pickers and preview follow state changes. A preview that rebuilds its card on a config change sets onlyhasson the card it has on a state tick (lcards-msd-live-preview.js, the Layout Studio'supdated()), or every state change would rebuild it. - Remove the studio on
closed. A studio is created per opening; nothing is reused.
Working Copy vs Committed Config
Inside a studio, every edit changes only _workingConfig. The card editor's config changes once, on Save, by replacement.
Studio (_workingConfig) | Card editor (this.config) | |
|---|---|---|
| Written by | _setConfigValue(), _removeConfigPath(), the YAML tab, the studio's own forms | _updateConfig() for its own fields; the studio launcher on Save |
| Merge rule | Replace: each edit assigns a new object | _updateConfig() deep-merges (deepMerge, LCARdSBaseEditor.js:249-292); the launcher replaces |
| Reaches Home Assistant | Never directly | config-changed (debounced 50ms in _updateConfig(), immediate from the launcher) |
| Validation | The studio's own (see below) | _validateConfig() on setConfig() and _updateConfig(), shown above the tabs |
- Why the launcher replaces.
_updateConfig({ ... })deep-merges a partial update into the current config, which is right for a field edit and wrong for a studio result: a key the user removed in the studio would survive the merge. So the launcher assignsthis.configand firesconfig-changeditself, doing the same YAML sync_updateConfig()does. This is the one place a card editor setsthis.configdirectly; field edits always go through_updateConfig(). - Why the studio is mounted outside the editor.
LCARdSBaseEditor.render()listens forconfig-changedfrom its children and merges them with_updateConfig()(_handleChildConfigChange,LCARdSBaseEditor.js:141-150). A studio mounted inside the editor would have its whole config merged, not replaced, before the launcher saw it. Mounting near<home-assistant>avoids that as well as fixing the contexts. - A studio's own
_updateConfigis not the base one. Studios are notLCARdSBaseEditors, and the name means different things in each: the Alert Studio's replaces top-level keys (_updateConfig(updates), for its forms mixin), the chart studio's sets one path (_updateConfig(path, value)). Only FormField's four members have a fixed contract. - Nested hosts. When a studio embeds a component written for a card editor (the chart studio's data source tab), give it a host object that reads and writes the working copy and swallows its events, so nothing commits before Save (
_dataSourceHost,lcards-chart-studio-dialog.js:108-132).
Validation and Schema Hints
The card schema drives a studio twice: FormField picks each control from it, and the YAML tab completes and lints against it.
// In the card schema (src/cards/schemas/*.js): the control is a property of the schema
height: {
type: 'number',
description: 'Height of the bar in pixels.',
'x-ui-hints': {
label: 'Height',
helper: 'Bar height in pixels',
selector: { number: { min: 8, max: 200, mode: 'slider', unit_of_measurement: 'px' } }
}
}- Selector order:
options.selectorOverride, thenx-ui-hints.selector, then one generated from the schema (type,enum,format: 'entity' | 'icon' | 'color' | 'action') (lcards-form-field.js:100-103,_getSelectorConfig()and_autoGenerateSelector()below it). A field label and helper come fromx-ui-hintsunless the call overrides them. - Generated selectors (
_autoGenerateSelector()):number/integergives a number selector (sliderwhenmaximumis 100 or less, elsebox; step 1 for an integer, elsemultipleOfor 0.1);booleana toggle; a string withformatentity,icon,colororactiongivesentity,icon,ui_color(Home Assistant's colour picker, notlcards-color-picker) orui_action; a stringenuma dropdown;objectthe object selector; anything else text. oneOfwithout anx-ui-hints.selectorbecomes Home Assistant'schooseselector, one choice per branch, labelled by the branchtitleor inferred (Number, Text, Theme Token, By State, ...). FormField converts to and from the selector's{ active_choice, ... }value, so the saved config stays plain.- Special renderers win over any selector,
selectorOverrideincluded:format: 'font-family'renderslcards-font-selector; an enum of position words with at least one compound (top-left) renderslcards-position-picker;x-ui-hints.widget: 'lcards-color-picker'renders the LCARdS colour picker; the pathtagsrenders a multi-select of the tags in use. - Labels and helpers: the label is
options.label, thenx-ui-hints.label, then the schematitle, then the last path key; the helper isoptions.helper, thenx-ui-hints.helper, then the schemadescription. FormField reads onlylabel,helper,selectorandwidgetfromx-ui-hints. - A path with no schema renders "No schema found for path" as a warning, so a typo or a missing schema entry shows at once.
tests/browser/alert-overlay-editor.spec.jschecks that every Alert Studio field resolves. - Unset fields show the schema
default. Passoptions.valueto show a value the config implies instead. - Every schema property needs a
description(scripts/check-schema-descriptions.jsruns innpm run build). New keys follow thelcards-card-optionproject skill: schema, runtime, editor, docs and tests together, reusing the words other cards already use. - The YAML tab (
lcards-studio-yaml-taboverlcards-yaml-editor) gives schema completion, inline lint and the "Options here" panel from the same schema. - Blocking checks belong in the studio when a config can't be saved at all. The data source studio collects them in
_errors()(name required and unique, entity required), shows them aslcards-message type="error"above the tab content, and disables Save until they pass, showing errors only after the first input (lcards-datasource-studio-dialog.js:183-225,566-590). Schema warnings that don't block saving are left to the card editor, which validates the saved config insetConfig().
Testing a Studio
Every studio change gets a test in the layer that can see it (COOKBOOK.md, "Tests"). Run one node file with node --no-maglev --import ./tests/setup/browser-shims.js --import ./tests/setup/vite-imports.js --test <file>; the browser and Home Assistant layers need npm run build first.
| Layer | What to test | Examples |
|---|---|---|
Node (npm test) | Pure helpers the studio uses (config transforms, history, field lists), and the source guards | tests/editor/astro-studio-*.test.js, tests/editor/studio-layout-css.test.js, tests/editor/dialog-footer-guards.test.js, tests/editor/editor-guards.test.js, tests/editor/editor-element-imports.test.js |
A: browser (npm run test:browser) | Open the studio from its editor against the fake hass; an edit shows in the preview; Save hands the whole config to the editor, Cancel nothing; the preview never calls a service | tests/browser/alert-studio.spec.js, tests/browser/astro-studio.spec.js, tests/browser/chart-studio-series.spec.js, tests/browser/alert-overlay-editor.spec.js |
C: real Home Assistant (npm run test:ha) | Layout and Home Assistant elements: the inset keeps one height on every tab, flexcontent, the footer order and button appearance, pickers working inside the dialog | tests/ha/ha.spec.js (the STUDIOS list, "alert studio: ...", "data source studio: ...", "Layout studio: ...") |
- Open it the way the editor does. The browser specs call the card's
getConfigElement()(which loads the editor chunk),setConfig()on the editor, then the editor's open method, and read the studio'srenderRootand_workingConfig(tests/browser/alert-studio.spec.js:11-25). - The harness has no Home Assistant elements.
ha-dialog,ha-selectorand friends are undefined there, so Layer A drives fields through_setConfigValue()or theirvalue-changedevents, and checks state rather than layout. Layout, sizing and Home Assistant controls are checked in Layer C. - Add the studio to
STUDIOSintests/ha/ha.spec.js(name, card tag, config, open method, dialog tag). The loop checks the one-height inset,flexcontentand the footer for every listed studio. - The node guards scan all of
src/: footers and Cancel appearance, no native dialogs, no<textarea>or raw<select>, shortlcards-messagetext, no emoji, a.studio-layoutthat sets columns also sets rows, and every<lcards-*>element the studio renders is imported by a module it imports. - Look at it in real Home Assistant. Tests check behaviour, not looks. Build, hard-refresh the dev Home Assistant (Ctrl+Shift+R), open the studio on a real dashboard, under the default theme and HA-LCARS, at full width and below 1024px, and look at every tab before calling it done. Add a view for the card to the
lcards-demoboard (demo/views/,npm run demo:push) so the change can be reviewed.
Studio Checklist
src/editor/dialogs/lcards-<card>-studio-dialog.js: aLitElementwithconfigsetter and getter,_initialConfigand_workingConfig, and FormField's members (hass,_getSchemaForPath,_getConfigValue,_setConfigValue).- Styles
[editorStyles, studioDialogStyles, messageStyles, css`...`]; if you change the split, setgrid-template-rows: minmax(0, 1fr)in the same rule; no heights on the shell. ha-dialog open flexcontent header-title=...;.dialog-content>.studio-layout>.config-panel(ha-tab-groupwith icon tabs,.tab-content) and.preview-panel.- Fields through
FormField.renderField()with selectors in the schema'sx-ui-hints; outlinedlcards-form-sections with icons, nested ones too; help throughrenderInfoGuide(),description,helperandlcards-message; shared controls reused; no tinted containers, accent colours or emoji. - YAML as the last tab:
lcards-studio-yaml-tabwith the card schema andmdi:code-braces. - Preview from a copy of the working config, debounced, with
hassforwarded; preview-only values stay out of the saved config; nothing acts on the real system. - Footer:
ha-dialog-footerwith.footer-start(Documentation), Cancel (plain), Save (brand,mdi:check);_handledguard;closedstopped and checked againste.currentTarget. - Save sends the whole config in
config-changed; Cancel sends onlyclosed. - Guarded
customElements.define()in the studio file. - Card editor: an "Open ... Studio" button, the studio imported only from the editor, mounted with
mountDialogNearHomeAssistant(dialog, this), config replaced on Save,hassforwarded, studio removed onclosed. - Tests: a Layer A spec for open, edit, Save and Cancel; the studio in
STUDIOSintests/ha/ha.spec.js; node tests for helpers. Thennpm run buildand a look in real Home Assistant.
Basic Card Editor
Every card has a card editor: a class extending LCARdSBaseEditor that Home Assistant shows in its card editor dialog. It supplies the tabs; the base class supplies tab rendering, config state, YAML sync, validation and the Main Engineering and YAML tabs.
// src/editor/cards/lcards-mycard-editor.js
// Patterns: src/editor/cards/lcards-elbow-editor.js:219-231,456-522 and .claude/rules/editor.md
import { html } from 'lit';
import { LCARdSBaseEditor } from '../base/LCARdSBaseEditor.js';
import { LCARdSFormFieldHelper as FormField } from '../components/shared/lcards-form-field.js';
import '../components/shared/lcards-form-section.js';
export class LCARdSMyCardEditor extends LCARdSBaseEditor {
constructor() {
super();
// The schema name the card registers (configManager.registerCardSchema('mycard', ...))
this.cardType = 'mycard';
}
_getTabDefinitions() {
return [
{ label: 'Config', content: () => this._renderFromConfig(this._getConfigTabConfig()) },
{ label: 'Style', content: () => this._renderStyleTab() },
...this._getUtilityTabs(),
];
}
_getConfigTabConfig() {
return this._buildConfigTab({
infoMessage: 'Configure your My Card.',
modeSections: [
{
type: 'section',
header: 'Display',
description: 'Size and label',
icon: 'mdi:resize',
expanded: true,
children: [
{ type: 'field', path: 'height' },
{ type: 'field', path: 'name', label: 'Name', helper: 'Shown on the card' },
],
},
],
});
}
_renderStyleTab() {
return html`
<lcards-form-section header="Colours" icon="mdi:palette-outline" ?expanded=${true} outlined>
${FormField.renderField(this, 'style.color')}
${FormField.renderField(this, 'style.background')}
</lcards-form-section>
`;
}
}
// Cards are registered centrally in src/lcards-main.js; editors register themselves, guarded.
if (!customElements.get('lcards-mycard-editor')) {
customElements.define('lcards-mycard-editor', LCARdSMyCardEditor);
}cardTypemust equal the name the card's staticregisterSchema()passes toconfigManager.registerCardSchema()(called fromsrc/lcards-main.js:380-389after core init)._getSchema()looks it up there, and a missing schema shows a "Schema Not Registered" error above the tabs._updateConfig()andsetConfig()also restore a missingtypeascustom:lcards-${cardType}.- Read config from
this.config. It is the editor's reactive property (LCARdSBaseEditor.js:27-31);setConfig()stores a deep clone there. - Tabs:
_getTabDefinitions()returns{ label, content, docs? }entries. The base renders them in anha-tab-group, each body in a plaindiv.tab-panel, and adds a "Docs" link at the top of each tab fromdocsor fromeditorTabDocs(cardType, label)(src/editor/utils/yaml-docs-links.js). Spread...this._getUtilityTabs()last for "🖖 Main Engineering" (data sources, rules, templates, theme, provenance) and YAML. _buildConfigTab({ ... })returns a declarative list for_renderFromConfig(): anlcards-messagewithinfoMessage, yourmodeSections, then a "Card Identification" section withentity,idandtags. Don't add another entity field in your sections; change that section withbasicFields(the elbow editor passes onlyidandtags, because its entity has its own section), or turn it off withshowBasicSection: false(the button editor). Other options:basicSectionHeader,basicSectionDescription,basicSectionIcon,basicSectionExpanded(LCARdSBaseEditor.js:1150-1240).- Declarative entries (
_renderFromConfig(),LCARdSBaseEditor.js:761-886):section(header,description,icon,expanded,outlined,headerLevel,children),grid(two columns),field(path,label,helper, rendered byFormField.renderField()) andcustom(render, called with the editor asthis). Any entry can take acondition. - Fields are schema-driven. Prefer
fieldentries andFormField.renderField()calls; declare the control in the schema'sx-ui-hints(see Validation and Schema Hints). For options known only at run time, passselectorOverriderather than rendering a bareha-selectorin acustomentry. - Commit with
_updateConfig(partial). It deep-merges the partial update, restorestype, validates, re-syncs the YAML tab and firesconfig-changedto Home Assistant after a 50ms debounce (LCARdSBaseEditor.js:249-292). Nested updates need no spreading:this._updateConfig({ style: { background: ev.detail.value } })keeps the rest ofstyle. The second argument is the source,'visual'(the default) or'yaml'; only'visual're-syncs the YAML tab, so leave it out. Never assignthis.config = ...or fireconfig-changedyourself (the studio launcher above is the one exception, and it does the YAML sync itself). - Path setters (what FormField writes through):
_getConfigValue(path)reads a dotted path;_setConfigValue(path, value)removes the key when the value isundefined,nullor''(_removeConfigPath()also prunes parents left empty) and otherwise calls_updateConfig(). A path with a numeric segment (style.ranges.0.min) builds arrays and firesconfig-changedat once, without the debounce or YAML resync (LCARdSBaseEditor.js,_setConfigValue). - Merge rules (
deepMerge,src/core/config-manager/merge-helpers.js): arrays replace, plain objects merge,nullandundefinedare set as values (the key stays). To drop a key, set the field empty or call_removeConfigPath(path); to drop keys inside an object, replace the whole object. - Styles:
LCARdSBaseEditor.stylesalready includeseditorStylesandmessageStyles. An editor that adds styles returns[...super.styles, css`...`]. Two more shared modules:editorComponentStyles(src/editor/base/editor-component-styles.js:.info-card,.two-column-grid,.button-group,.empty-state,.toolbar) andeditorWidgetStyles(src/editor/components/editors/editor-widget-styles.js:.editor-list,.editor-item,.drag-handle,.add-button, for collapsible list editors). - Reuse a sub-editor before writing one (
src/editor/components/editors/):lcards-multi-action-editor:.hassand.actions=${{ tap_action, hold_action, double_tap_action }}; firesvalue-changedwith all three indetail.value.lcards-color-section-v2: one colour path, plain or by state:.editor,basePath,header,description,.suggestedStates,?allowCustomStates,.entityId(a string); reads and writes through the editor's path setters.lcards-object-editor: one control per key of an object (.editor,path,.properties,controlType,columns); a declarativegridentry renderslcards-grid-layout.- Also
lcards-icon-section,lcards-border-editor,lcards-unified-segment-editor,lcards-multi-text-editor-v2,lcards-text-field-editor,lcards-font-selector,lcards-position-picker,lcards-padding-editor.
- Where things live in
src/editor/:base/(base class, styles),cards/(card editors),dialogs/(studios and their*-studio/helpers),components/shared/(FormField, form section, colour picker, info guide),components/editors/(sub-editors and pickers),components/yaml/(YAML editor and the studio YAML tab),components/{datasources,dashboard,templates,provenance,theme-browser,sound}/(the Main Engineering and utility tabs),utils/yaml-utils.js(configToYaml,yamlToConfig). The base editor imports every element it renders itself (tests/editor/editor-element-imports.test.js).
Lazy Loading
The card loads its editor only when Home Assistant asks for it.
// src/cards/lcards-mycard.js (pattern: src/cards/lcards-chart.js:747-752)
static async getConfigElement() {
// Editors load on demand (HA awaits getConfigElement), keeping them out of
// the bundle every dashboard loads.
await import('../editor/cards/lcards-mycard-editor.js');
return document.createElement('lcards-mycard-editor');
}- Home Assistant awaits
getConfigElement()when it opens the visual editor. The dynamicimport()loads the editor module, which registers its element, at that moment; Vite emits it as a lazy chunk (chunks/lcards-<card>-editor-<hash>.js). - Never import an editor or a studio statically from a card or
src/lcards-main.js. That pulls it into the main chunk every dashboard loads. Studios are imported only from their editor (statically or withimport()), so they ride in, or after, the editor chunk. tests/browser/bundle.spec.jsguards it: every card'sgetConfigElement()defines its editor, rendering cards loads no editor chunk, an editor chunk reuses the same core, and the main chunk stays under its size ceiling.getStubConfig()on the card gives Home Assistant's card picker a starting config; the card side (schema registration,registerSchema(), registration insrc/lcards-main.js) is in Building a Custom Card.
Editor UI Conventions
The studios (chart, data grid, layout, MSD, data source) and the config panel are the reference look for every editor surface. New or reworked UI follows them, and older dialogs are brought in line when they are touched. The short rules are in .claude/rules/editor.md; this section explains them.
Help Text and Messages
There is one way to show each kind of help. tests/editor/editor-guards.test.js keeps the old patterns out of src/editor/ and src/panels/.
| Need | Use |
|---|---|
| How something works, a reference, tips, examples | Info guide: renderInfoGuide({ header, icon, body }) (src/editor/components/shared/info-guide.js), an lcards-form-section variant="guide": the section's shape, dark, primary colour on border and header, closed by default |
| One line about a section | the section's description |
| One line about a field | the field's helper (or a .hint from messageStyles) |
| Something to notice now (warning, error, "has no effect while...") | lcards-message warning or error, one or two sentences |
| A short contextual note | lcards-message info, at most 200 characters (the guard's MESSAGE_LIMIT); anything longer is an info guide |
| A status bar at the top of a panel tab | .banner from messageStyles (info, warning, error, success) |
- Info guide body classes:
.info-guide-example(code),.info-guide-tip,.info-guide-noteand.info-guide-links(src/editor/components/shared/info-guide-styles.js). A section that is itself an explainer, such as a reference diagram, takesvariant="guide"directly. - Messages stay plain: no headings, bullet characters, emoji or inline styles inside an
lcards-message. Lists and examples belong in an info guide. ha-alertdirectly appears only in thelcards-messagewrapper, in developer errors inside shared components and in the theme lab's previews of Home Assistant's own alerts (the guard'sHA_ALERT_ALLOWEDlist).- Surfaces: panel tabs take
surfaceStyles(src/editor/base/surface-styles.js: the inset area.studio-layout/.inset-surfaceand its.scrollable-body/.scroll-body) and never copy that CSS. Studio dialogs importmessageStylesinstead, because their own.studio-layoutis the split grid. - Code always goes in a code editor:
lcards-yaml-editororlcards-studio-yaml-tabfor LCARdS YAML (they add schema completion),ha-code-editorfor any other text (mode="yaml"also suits JSON,jinja2for templates).
Plain Dialogs
A dialog without a preview is a plain ha-dialog with header-title; there is no LCARdS wrapper. Mount it with mountDialogNearHomeAssistant() like a studio (see Dialogs and Portals).
- Footer:
<ha-dialog-footer slot="footer">with Cancel (appearance="plain") insecondaryAction, then the main action (variant="brand") inprimaryAction. Imperative dialogs build it withcreateDialogFooter({ secondary, primary })(src/utils/lcards-shared-helpers.js). A lone Close is theprimaryActionwith the default appearance.tests/editor/dialog-footer-guards.test.jschecks footers and button appearance. - Closing: stop the dialog's
closedevent (e.stopPropagation()) so it doesn't close the editor around it, and act only whene.target === e.currentTarget, because pickers inside fire their ownclosed. - Focus: put
autofocuson the first field. A destructive confirm focuses Cancel; any other confirm focuses its main button, as Home Assistant's own dialog box does. Tabbed dialogs need neither. - Deletes and resets confirm with
showConfirmDeleteDialog(src/views/layout-edit-dialogs.js), not an inline banner.
Panel Typography and Controls
Text in editors and panels follows the theme font and Home Assistant's type scale.
- Font: the config panel host sets
font-family: var(--ha-font-family-body), as Home Assistant'shaStyledoes. Without it LCARdS text inherits the page's hardcoded Roboto while Home Assistant's controls follow the theme font (Antonio or Tungsten under HA-LCARS). - Sizes: use the
--ha-font-size-*steps (orem), never fixedpxorrem, and keep Home Assistant's sizes. A theme that wants larger text setsha-font-size-scale, which scales all of Home Assistant together (Home Assistant CSS Variable Reference). - Labels: label a control with the selector's own
labelandhelper, never a separate label div beside a label-less control. - Buttons: no raw
<button>;ha-buttonfor actions. A single-choice row (category filter, scope picker) isrenderFilterChips()(src/editor/components/shared/filter-chips.js): default-sizeha-buttonpills, the selected one solid (brand, accent), the rest grey (neutral, filled). - Choices and sliders: a choice is an
ha-selectorwith aselectselector (mode: 'dropdown','list', or'box'for tiles with a description), never a raw<select>; a number slider is anumberselector withmode: 'slider'. - No emoji in labels, headings, options or messages: put an
ha-icon(mdi) beside the text, or nothing. The one exception is the 🖖 on the Main Engineering tab; log messages may keep theirs.
Home Assistant Elements
LCARdS requires Home Assistant 2026.11 or later, so several older elements and CSS hooks are gone. npm run build runs scripts/validate-ha-compat.js, which fails on the known-dead ones.
- Gone:
ha-textfield(useha-input,ha-textareaor anha-selectortext or number selector),ha-formfield,ha-circular-progress(renders as an unregistered 0×0 element, with no error),mwc-icon-button,ha-md-list,ha-md-list-itemand everymd-*tag. Since 2026.12 the MWC list elementsha-list,ha-list-item,ha-check-list-itemandha-radio-list-itemare gone too: useha-list-base/ha-list-selectablewithha-list-item-base,-button,-option,-switchor-value, orha-row-item. helper-textis ignored. It was the MDC /ha-textfieldattribute and exists on no current component, so the text silently never renders. Usehintonha-inputandha-textarea,helperonha-selector.ha-switchandha-checkboxare WebAwesome components with a clickable default-slot label: put the label text inside the control, as Home Assistant'sha-form-boolean.tsdoes.ha-icon-buttontakes a.path(an mdi/js SVG path) or an<ha-icon icon="mdi:...">child; it has noiconproperty, soicon="mdi:x"renders an empty button. Always set.label. Size it with--ha-icon-button-sizeand colour the icon withcolor:(the icon usescurrentColor);--md-icon-button-*and--mdc-icon-button-sizeare dead.- Chips (
ha-assist-chip,ha-filter-chip,ha-input-chip,ha-chip-set) read only--ha-*names, such as--ha-assist-chip-filled-container-color,--ha-assist-chip-label-text-color,--ha-assist-chip-outline-color,--ha-filter-chip-selected-container-colorand--ha-input-chip-selected-container-color. Size them with--ha-button-height(chip height) and--ha-chip-label-size. Every--md-*-chip-*and--md-sys-*variable is dead, and--ha-assist-chip-container-heightdoes nothing.ha-filter-chiptoggles its ownselectedon click: in a radio-style group, calle.preventDefault()on the click when the chip is already active, or it shows deselected. ha-spinnertakessizetiny,small,mediumorlargeand has noindeterminateoractiveattribute. Since 2026.12 it subclassesHacSpinnerfrom Home Assistant's@home-assistant/componentspackage: aninline-flexhost sized persize, with a default "Loading" accessible label. Style it with--hac-spinner-size,--hac-spinner-indicator-color,--hac-spinner-track-colorand--hac-spinner-track-width(the--ha-spinner-*names are only temporary fallbacks), and passaccessible-labelwhen a spinner marks a specific task.ha-buttoncolour comes fromvariant(brand,danger,warning,neutral,success), andappearanceis onlyaccent,filled,outlinedorplain.--mdc-theme-primaryoverrides are dead.