mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-28 11:46:42 +00:00
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:
parent
d66cf3f787
commit
8ca70ace4c
@ -11,6 +11,10 @@ interface Config extends LovelaceElementConfig {
|
||||
}
|
||||
|
||||
export const computeTooltip = (hass: HomeAssistant, config: Config): string => {
|
||||
if (config.title === null) {
|
||||
return "";
|
||||
}
|
||||
|
||||
if (config.title) {
|
||||
return config.title;
|
||||
}
|
||||
@ -26,10 +30,10 @@ export const computeTooltip = (hass: HomeAssistant, config: Config): string => {
|
||||
}
|
||||
|
||||
const tapTooltip = config.tap_action
|
||||
? computeActionTooltip(stateName, config.tap_action, false)
|
||||
? computeActionTooltip(hass, stateName, config.tap_action, false)
|
||||
: "";
|
||||
const holdTooltip = config.hold_action
|
||||
? computeActionTooltip(stateName, config.hold_action, true)
|
||||
? computeActionTooltip(hass, stateName, config.hold_action, true)
|
||||
: "";
|
||||
|
||||
const newline = tapTooltip && holdTooltip ? "\n" : "";
|
||||
@ -40,6 +44,7 @@ export const computeTooltip = (hass: HomeAssistant, config: Config): string => {
|
||||
};
|
||||
|
||||
function computeActionTooltip(
|
||||
hass: HomeAssistant,
|
||||
state: string,
|
||||
config: ActionConfig,
|
||||
isHold: boolean
|
||||
@ -48,20 +53,39 @@ function computeActionTooltip(
|
||||
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) {
|
||||
case "navigate":
|
||||
tooltip += `Navigate to ${config.navigation_path}`;
|
||||
tooltip += `${hass.localize(
|
||||
"ui.panel.lovelace.cards.picture-elements.navigate_to",
|
||||
"location",
|
||||
config.navigation_path
|
||||
)}`;
|
||||
break;
|
||||
case "toggle":
|
||||
tooltip += `Toggle ${state}`;
|
||||
tooltip += `${hass.localize(
|
||||
"ui.panel.lovelace.cards.picture-elements.toggle",
|
||||
"name",
|
||||
state
|
||||
)}`;
|
||||
break;
|
||||
case "call-service":
|
||||
tooltip += `Call service ${config.service}`;
|
||||
tooltip += `${hass.localize(
|
||||
"ui.panel.lovelace.cards.picture-elements.call_service",
|
||||
"name",
|
||||
config.service
|
||||
)}`;
|
||||
break;
|
||||
case "more-info":
|
||||
tooltip += `Show more-info: ${state}`;
|
||||
tooltip += `${hass.localize(
|
||||
"ui.panel.lovelace.cards.picture-elements.more_info",
|
||||
"name",
|
||||
state
|
||||
)}`;
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -916,6 +916,14 @@
|
||||
"checked_items": "Checked items",
|
||||
"clear_items": "Clear checked items",
|
||||
"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": {
|
||||
|
Loading…
x
Reference in New Issue
Block a user