Support descriptions in flow menu steps (#12108)

Co-authored-by: Paulus Schoutsen <balloob@gmail.com>
This commit is contained in:
Erik Montnemery 2022-03-23 23:14:57 +01:00 committed by GitHub
parent f493280f0a
commit df96199433
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 49 additions and 0 deletions

View File

@ -189,6 +189,18 @@ export const showConfigFlowDialog = (
);
},
renderMenuDescription(hass, step) {
const description = hass.localize(
`component.${step.handler}.config.step.${step.step_id}.description`,
step.description_placeholders
);
return description
? html`
<ha-markdown allowsvg breaks .content=${description}></ha-markdown>
`
: "";
},
renderMenuOption(hass, step, option) {
return hass.localize(
`component.${step.handler}.config.step.${step.step_id}.menu_options.${option}`,

View File

@ -83,6 +83,11 @@ export interface FlowConfig {
renderMenuHeader(hass: HomeAssistant, step: DataEntryFlowStepMenu): string;
renderMenuDescription(
hass: HomeAssistant,
step: DataEntryFlowStepMenu
): TemplateResult | "";
renderMenuOption(
hass: HomeAssistant,
step: DataEntryFlowStepMenu,

View File

@ -142,6 +142,22 @@ export const showOptionsFlowDialog = (
);
},
renderMenuDescription(hass, step) {
const description = hass.localize(
`component.${step.handler}.option.step.${step.step_id}.description`,
step.description_placeholders
);
return description
? html`
<ha-markdown
allowsvg
breaks
.content=${description}
></ha-markdown>
`
: "";
},
renderMenuOption(hass, step, option) {
return hass.localize(
`component.${step.handler}.options.step.${step.step_id}.menu_options.${option}`,

View File

@ -35,8 +35,14 @@ class StepFlowMenu extends LitElement {
translations = this.step.menu_options;
}
const description = this.flowConfig.renderMenuDescription(
this.hass,
this.step
);
return html`
<h2>${this.flowConfig.renderMenuHeader(this.hass, this.step)}</h2>
${description ? html`<div class="content">${description}</div>` : ""}
<div class="options">
${options.map(
(option) => html`
@ -69,6 +75,16 @@ class StepFlowMenu extends LitElement {
margin-top: 20px;
margin-bottom: 8px;
}
.content {
padding-bottom: 16px;
border-bottom: 1px solid var(--divider-color);
}
.content + .options {
margin-top: 8px;
}
mwc-list-item {
--mdc-list-side-padding: 24px;
}
`,
];
}