Tooltip picture elements (#3111)

* Added noTitle option to supress tooltip

* Additional strings

* Updated name

* refactored name

* Refactored strings

* Refactored to allow null in title
This commit is contained in:
Yosi Levy 2019-04-27 23:03:31 +03:00 committed by Paulus Schoutsen
parent d66cf3f787
commit 8ca70ace4c
2 changed files with 39 additions and 7 deletions

View File

@ -11,6 +11,10 @@ interface Config extends LovelaceElementConfig {
} }
export const computeTooltip = (hass: HomeAssistant, config: Config): string => { export const computeTooltip = (hass: HomeAssistant, config: Config): string => {
if (config.title === null) {
return "";
}
if (config.title) { if (config.title) {
return config.title; return config.title;
} }
@ -26,10 +30,10 @@ export const computeTooltip = (hass: HomeAssistant, config: Config): string => {
} }
const tapTooltip = config.tap_action const tapTooltip = config.tap_action
? computeActionTooltip(stateName, config.tap_action, false) ? computeActionTooltip(hass, stateName, config.tap_action, false)
: ""; : "";
const holdTooltip = config.hold_action const holdTooltip = config.hold_action
? computeActionTooltip(stateName, config.hold_action, true) ? computeActionTooltip(hass, stateName, config.hold_action, true)
: ""; : "";
const newline = tapTooltip && holdTooltip ? "\n" : ""; const newline = tapTooltip && holdTooltip ? "\n" : "";
@ -40,6 +44,7 @@ export const computeTooltip = (hass: HomeAssistant, config: Config): string => {
}; };
function computeActionTooltip( function computeActionTooltip(
hass: HomeAssistant,
state: string, state: string,
config: ActionConfig, config: ActionConfig,
isHold: boolean isHold: boolean
@ -48,20 +53,39 @@ function computeActionTooltip(
return ""; return "";
} }
let tooltip = isHold ? "Hold: " : "Tap: "; let tooltip =
(isHold
? hass.localize("ui.panel.lovelace.cards.picture-elements.hold")
: hass.localize("ui.panel.lovelace.cards.picture-elements.tap")) + " ";
switch (config.action) { switch (config.action) {
case "navigate": case "navigate":
tooltip += `Navigate to ${config.navigation_path}`; tooltip += `${hass.localize(
"ui.panel.lovelace.cards.picture-elements.navigate_to",
"location",
config.navigation_path
)}`;
break; break;
case "toggle": case "toggle":
tooltip += `Toggle ${state}`; tooltip += `${hass.localize(
"ui.panel.lovelace.cards.picture-elements.toggle",
"name",
state
)}`;
break; break;
case "call-service": case "call-service":
tooltip += `Call service ${config.service}`; tooltip += `${hass.localize(
"ui.panel.lovelace.cards.picture-elements.call_service",
"name",
config.service
)}`;
break; break;
case "more-info": case "more-info":
tooltip += `Show more-info: ${state}`; tooltip += `${hass.localize(
"ui.panel.lovelace.cards.picture-elements.more_info",
"name",
state
)}`;
break; break;
} }

View File

@ -916,6 +916,14 @@
"checked_items": "Checked items", "checked_items": "Checked items",
"clear_items": "Clear checked items", "clear_items": "Clear checked items",
"add_item": "Add item" "add_item": "Add item"
},
"picture-elements": {
"hold": "Hold:",
"tap": "Tap:",
"navigate_to": "Navigate to {location}",
"toggle": "Toggle {name}",
"call_service": "Call service {name}",
"more_info": "Show more-info: {name}"
} }
}, },
"menu": { "menu": {