Add description to sections demo (#19991)

* Add description to sections demo

* Update wording
pull/20000/head
Paul Bottein 2024-03-06 05:45:16 +01:00 committed by GitHub
parent 8ca5b7528b
commit a5bcf87c08
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 63 additions and 14 deletions

View File

@ -0,0 +1,16 @@
import { html } from "lit";
import { DemoConfig } from "../types";
export const demoLovelaceDescription: DemoConfig["description"] = (
localize
) => html`
<p>
${localize("ui.panel.page-demo.config.sections.description", {
blog_post: html`<a
href="https://www.home-assistant.io/blog/2024/03/04/dashboard-chapter-1/"
target="_blank"
>${localize("ui.panel.page-demo.config.sections.description_blog_post")}
</a>`,
})}
</p>
`;

View File

@ -1,4 +1,5 @@
import { DemoConfig } from "../types"; import { DemoConfig } from "../types";
import { demoLovelaceDescription } from "./description";
import { demoEntitiesSections } from "./entities"; import { demoEntitiesSections } from "./entities";
import { demoLovelaceSections } from "./lovelace"; import { demoLovelaceSections } from "./lovelace";
@ -6,6 +7,7 @@ export const demoSections: DemoConfig = {
authorName: "Home Assistant", authorName: "Home Assistant",
authorUrl: "https://github.com/home-assistant/frontend/", authorUrl: "https://github.com/home-assistant/frontend/",
name: "Home Demo", name: "Home Demo",
description: demoLovelaceDescription,
lovelace: demoLovelaceSections, lovelace: demoLovelaceSections,
entities: demoEntitiesSections, entities: demoEntitiesSections,
theme: () => ({}), theme: () => ({}),

View File

@ -1,3 +1,4 @@
import { TemplateResult } from "lit";
import { LocalizeFunc } from "../../../src/common/translations/localize"; import { LocalizeFunc } from "../../../src/common/translations/localize";
import { LovelaceConfig } from "../../../src/data/lovelace/config/types"; import { LovelaceConfig } from "../../../src/data/lovelace/config/types";
import { Entity } from "../../../src/fake_data/entity"; import { Entity } from "../../../src/fake_data/entity";
@ -7,6 +8,9 @@ export interface DemoConfig {
name: string; name: string;
authorName: string; authorName: string;
authorUrl: string; authorUrl: string;
description?:
| string
| ((localize: LocalizeFunc) => string | TemplateResult<1>);
lovelace: (localize: LocalizeFunc) => LovelaceConfig; lovelace: (localize: LocalizeFunc) => LovelaceConfig;
entities: (localize: LocalizeFunc) => Entity[]; entities: (localize: LocalizeFunc) => Entity[];
theme: () => Record<string, string> | null; theme: () => Record<string, string> | null;

View File

@ -39,32 +39,51 @@ export class HADemoCard extends LitElement implements LovelaceCard {
<div class="picker"> <div class="picker">
<div class="label"> <div class="label">
${this._switching ${this._switching
? html`<ha-circular-progress ? html`
indeterminate <ha-circular-progress indeterminate></ha-circular-progress>
></ha-circular-progress>` `
: until( : until(
selectedDemoConfig.then( selectedDemoConfig.then(
(conf) => html` (conf) => html`
${conf.name} ${conf.name}
<small> <small>
<a target="_blank" href=${conf.authorUrl}> ${this.hass.localize(
${this.hass.localize( "ui.panel.page-demo.cards.demo.demo_by",
"ui.panel.page-demo.cards.demo.demo_by", {
{ name: conf.authorName } name: html`
)} <a target="_blank" href=${conf.authorUrl}>
</a> ${conf.authorName}
</a>
`,
}
)}
</small> </small>
` `
), ),
"" ""
)} )}
</div> </div>
<mwc-button @click=${this._nextConfig} .disabled=${this._switching}> <mwc-button @click=${this._nextConfig} .disabled=${this._switching}>
${this.hass.localize("ui.panel.page-demo.cards.demo.next_demo")} ${this.hass.localize("ui.panel.page-demo.cards.demo.next_demo")}
</mwc-button> </mwc-button>
</div> </div>
<div class="content small-hidden"> <div class="content">
${this.hass.localize("ui.panel.page-demo.cards.demo.introduction")} <p class="small-hidden">
${this.hass.localize("ui.panel.page-demo.cards.demo.introduction")}
</p>
${until(
selectedDemoConfig.then((conf) => {
if (typeof conf.description === "function") {
return conf.description(this.hass.localize);
}
if (conf.description) {
return html`<p>${conf.description}</p>`;
}
return nothing;
}),
nothing
)}
</div> </div>
<div class="actions small-hidden"> <div class="actions small-hidden">
<a href="https://www.home-assistant.io" target="_blank"> <a href="https://www.home-assistant.io" target="_blank">
@ -108,6 +127,7 @@ export class HADemoCard extends LitElement implements LovelaceCard {
css` css`
a { a {
color: var(--primary-color); color: var(--primary-color);
display: inline-block;
} }
.actions a { .actions a {
@ -115,7 +135,11 @@ export class HADemoCard extends LitElement implements LovelaceCard {
} }
.content { .content {
padding: 16px; padding: 0 16px;
}
.content p {
margin: 16px 0;
} }
.picker { .picker {
@ -138,9 +162,8 @@ export class HADemoCard extends LitElement implements LovelaceCard {
} }
.actions { .actions {
padding-left: 8px; padding: 0px 8px 4px 8px;
} }
@media only screen and (max-width: 500px) { @media only screen and (max-width: 500px) {
.small-hidden { .small-hidden {
display: none; display: none;

View File

@ -6218,6 +6218,10 @@
"watching": "watching", "watching": "watching",
"minutes_abbr": "min" "minutes_abbr": "min"
} }
},
"sections": {
"description": "This dashboard is using the sections view released in Home Assistant 2024.3. Learn more about it in this {blog_post}.",
"description_blog_post": "blog post"
} }
} }
}, },