Agent Skills › home-assistant/frontend › ha-frontend-components

ha-frontend-components

GitHub

规范 Home Assistant 前端组件(如对话框、按钮、表单、提示)的开发与审查,涵盖交互模式、API 使用及加载状态指导。

.agents/skills/ha-frontend-components/SKILL.md home-assistant/frontend

触发场景

实现或审查 HA 前端 UI 组件 配置 ha-dialog, ha-button, ha-form 等组件

安装

npx skills add home-assistant/frontend --skill ha-frontend-components -g -y
更多选项

非标准路径

npx skills add https://github.com/home-assistant/frontend/tree/dev/.agents/skills/ha-frontend-components -g -y

不安装直接使用

npx skills use home-assistant/frontend@ha-frontend-components

指定 Agent (Claude Code)

npx skills add home-assistant/frontend --skill ha-frontend-components -a claude-code -g -y

安装 repo 全部 skill

npx skills add home-assistant/frontend --all -g -y

预览 repo 内 skill

npx skills add home-assistant/frontend --list

SKILL.md

Frontmatter
{
    "name": "ha-frontend-components",
    "description": "Home Assistant frontend component patterns. Use when implementing or reviewing dialogs, ha-form, ha-alert, loading states, keyboard shortcuts, tooltips, panels, Lovelace cards, or ha-button usage."
}

HA Frontend Components

Use this skill when creating or reviewing Home Assistant UI components and common interaction patterns.

Cross-load ha-frontend-events when component work includes event listener typing, custom event dispatch, or event-map declarations.

Dialogs

Open dialogs through the fire-event pattern:

fireEvent(this, "show-dialog", {
  dialogTag: "dialog-example",
  dialogImport: () => import("./dialog-example"),
  dialogParams: { title: "Example", data: someData },
});

Dialog implementation requirements:

  • Use ha-dialog.
  • Use DialogMixin, which implements HassDialogNext<T>, for new dialogs. See src/dialogs/dialog-mixin.ts.
  • Read dialog parameters from the mixin's params property and render the dialog open. Return nothing while required parameters are absent.
  • Call the mixin's closeDialog() to close a new dialog. The mixin handles the closed event, fires dialog-closed, and removes the host element.
  • Existing dialogs may implement the legacy HassDialog<T> interface from src/dialogs/make-dialog-manager.ts.
  • Preserve the existing showDialog(), open-state, and close-event lifecycle when maintaining a legacy dialog; do not copy that lifecycle into a DialogMixin dialog.
  • Use header-title and header-subtitle for simple header text.
  • Use slots when standard header attributes are not enough.
  • Use ha-dialog-footer with primaryAction and secondaryAction slots.
  • Add autofocus to the first focusable element, such as <ha-form autofocus>, and forward it internally if needed.

Use standard dialog widths: small, medium, large, or full. Avoid custom dialog sizing unless there is a clear product need.

Buttons

ha-button wraps the Web Awesome button in src/components/ha-button.ts.

Axes:

  • variant: brand, neutral, danger, warning, success.
  • appearance: accent, filled, outlined, plain.
  • size: xs, s, m, l, xl.

Common usage:

  • Use appearance="filled" for primary emphasis when needed.
  • Use appearance="plain" for cancel and dismiss actions.
  • Use variant="danger" for destructive actions.
  • Place primary actions in slot="primaryAction" and secondary actions in slot="secondaryAction".

Forms

ha-form is schema-driven with HaFormSchema[] and supports common selectors for entities, devices, areas, targets, numbers, booleans, time, actions, text, objects, selects, icons, media, and location.

Use computeLabel, computeError, and computeHelper for translated labels, validation, and helper text.

<ha-form
  .hass=${this.hass}
  .data=${this._data}
  .schema=${this._schema}
  .error=${this._errors}
  .computeLabel=${(schema) => this._localize(`ui.panel.${schema.name}`)}
  @value-changed=${this._valueChanged}
></ha-form>

Alerts

Use ha-alert for user-visible status messaging.

  • Alert types: error, warning, info, success.
  • Useful properties: title, alert-type, dismissable, narrow.
  • Slots: icon for custom leading icon, action for custom action content.
  • Content is announced by screen readers when dynamically displayed.
html`
  <ha-alert alert-type="error">${this._localize("ui.example.error")}</ha-alert>
  <ha-alert alert-type="warning" .title=${this._localize("ui.example.warning")}>
    ${this._localize("ui.example.description")}
  </ha-alert>
  <ha-alert alert-type="success" dismissable>
    ${this._localize("ui.example.success")}
  </ha-alert>
`;

Loading States

Pick the indicator by what is loading, following the Loading pattern:

  • Use a skeleton from src/components/skeleton/ (ha-skeleton, ha-skeleton-text, ha-skeleton-icon) when content loads into a layout you already know, such as table rows, tile text, or a log. It holds the layout, so nothing jumps when the content arrives.
  • Use ha-spinner only when a whole area loads and its shape is unknown.
  • Use ha-button with loading, or ha-progress-button, for an action started from a button. Don't put a separate spinner next to it.

Wrap the indicator in ha-fade-in from src/components/animation/ha-fade-in.ts:

  • Fade a skeleton in straight away over about 300ms (.duration=${300}), as the data table does. It stands in for the content, so a delay would leave an empty gap.
  • Delay a spinner or progress bar, usually by .delay=${500}, so a load that finishes within that time never flashes it. Some slower areas, such as backups and updates, use ${1000}.
  • Don't fade in the loaded content itself.

Give a skeleton group the progressbar role and a translated label, as ha-spinner has, rather than visible "Loading" text. A loading state always ends in the content, an empty state, or an error.

html`
  <ha-fade-in .duration=${300} easing="ease-in">
    <div
      role="progressbar"
      aria-label=${this._i18n.localize("ui.common.loading")}
    >
      <ha-skeleton-text></ha-skeleton-text>
    </div>
  </ha-fade-in>
  <ha-fade-in .delay=${500}><ha-spinner></ha-spinner></ha-fade-in>
`;

Shortcuts And Tooltips

Use ShortcutManager from src/common/keyboard/shortcuts.ts for keyboard shortcuts. It blocks shortcuts in input fields, can prevent shortcuts during text selection, and supports character and KeyCode shortcuts for non-latin keyboards. See src/state/quick-bar-mixin.ts for global shortcut examples.

Use ha-tooltip from src/components/ha-tooltip.ts for contextual hover help. See src/components/ha-label.ts for an example.

Panels And Lovelace Cards

Panels commonly extend SubscribeMixin(LitElement) and receive route and narrow-layout properties.

Lovelace cards should implement LovelaceCard, validate config in setConfig(), handle loading, error, unavailable, and missing-entity states, and add a configuration editor when needed.

Cards are user-story surfaces. Support different households, entity types, responsive layouts, and accessible interaction states.

版本历史

  • 2fdef68 当前 2026-11-03 11:11

    新增关于加载状态(loading state)的指导说明,包括 Spinner 延迟的上下文相关描述。

  • 3c7560a 2026-08-20 08:57

同 Skill 集合

.agents/skills/ha-frontend-contexts/SKILL.md
.agents/skills/ha-frontend-demo/SKILL.md
.agents/skills/ha-frontend-events/SKILL.md
.agents/skills/ha-frontend-gallery/SKILL.md
.agents/skills/ha-frontend-lit/SKILL.md
.agents/skills/ha-frontend-query-params/SKILL.md
.agents/skills/ha-frontend-review/SKILL.md
.agents/skills/ha-frontend-styling/SKILL.md
.agents/skills/ha-frontend-testing/SKILL.md
.agents/skills/ha-frontend-types/SKILL.md
.agents/skills/ha-frontend-user-facing-text/SKILL.md
.agents/skills/ha-frontend-ux-readiness/SKILL.md

元信息

文件数
0
版本
2fdef68
Hash
aca31c3f
收录时间
2026-08-20 08:57

首页 - Wiki
Copyright © 2011-2026 iteam. Current version is 2.156.0. UTC+08:00, 2026-11-06 01:28
浙ICP备14020137号-1