Add hint helpers to fields that support markdown (#25528)

* Add hint helpers to fields that support markdown

* reduce duplication
This commit is contained in:
karwosts 2025-05-20 22:13:28 -07:00 committed by GitHub
parent 07e5f53469
commit f0beef22d2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 21 additions and 1 deletions

View File

@ -0,0 +1,14 @@
import { html } from "lit";
import type { LocalizeFunc } from "./localize";
const MARKDOWN_SUPPORT_URL = "https://commonmark.org/help/";
export const supportsMarkdownHelper = (localize: LocalizeFunc) =>
localize("ui.common.supports_markdown", {
markdown_help_link: html`<a
href=${MARKDOWN_SUPPORT_URL}
target="_blank"
rel="noreferrer"
>${localize("ui.common.markdown")}</a
>`,
});

View File

@ -23,6 +23,7 @@ import type {
EntityRegistryUpdate, EntityRegistryUpdate,
SaveDialogParams, SaveDialogParams,
} from "./show-dialog-automation-save"; } from "./show-dialog-automation-save";
import { supportsMarkdownHelper } from "../../../../common/translations/markdown_support";
@customElement("ha-dialog-automation-save") @customElement("ha-dialog-automation-save")
class DialogAutomationSave extends LitElement implements HassDialog { class DialogAutomationSave extends LitElement implements HassDialog {
@ -156,6 +157,7 @@ class DialogAutomationSave extends LitElement implements HassDialog {
name="description" name="description"
autogrow autogrow
.value=${this._newDescription} .value=${this._newDescription}
.helper=${supportsMarkdownHelper(this.hass.localize)}
@input=${this._valueChanged} @input=${this._valueChanged}
></ha-textarea>` ></ha-textarea>`
: nothing} : nothing}

View File

@ -25,6 +25,7 @@ import { showConfirmationDialog } from "../../dialogs/generic/show-dialog-box";
import { haStyleDialog } from "../../resources/styles"; import { haStyleDialog } from "../../resources/styles";
import type { HomeAssistant } from "../../types"; import type { HomeAssistant } from "../../types";
import type { TodoItemEditDialogParams } from "./show-dialog-todo-item-editor"; import type { TodoItemEditDialogParams } from "./show-dialog-todo-item-editor";
import { supportsMarkdownHelper } from "../../common/translations/markdown_support";
@customElement("dialog-todo-item-editor") @customElement("dialog-todo-item-editor")
class DialogTodoItemEditor extends LitElement { class DialogTodoItemEditor extends LitElement {
@ -146,6 +147,7 @@ class DialogTodoItemEditor extends LitElement {
.label=${this.hass.localize( .label=${this.hass.localize(
"ui.components.todo.item.description" "ui.components.todo.item.description"
)} )}
.helper=${supportsMarkdownHelper(this.hass.localize)}
.value=${this._description} .value=${this._description}
@input=${this._handleDescriptionChanged} @input=${this._handleDescriptionChanged}
autogrow autogrow

View File

@ -374,7 +374,9 @@
"copy": "Copy", "copy": "Copy",
"show": "Show", "show": "Show",
"replace": "Replace", "replace": "Replace",
"append": "Append" "append": "Append",
"supports_markdown": "Supports {markdown_help_link}",
"markdown": "Markdown"
}, },
"components": { "components": {
"selectors": { "selectors": {