parent
c18b0bc08b
commit
43632a9719
@ -0,0 +1,23 @@
|
||||
######################################################################
|
||||
# @CCOSTAN - Follow Me on X
|
||||
# For more info visit https://www.vcloudinfo.com/click-here
|
||||
# Original Repo : https://github.com/CCOSTAN/Home-AssistantConfig
|
||||
# -------------------------------------------------------------------
|
||||
# Native dashboard buttons - large, wrapping controls
|
||||
# -------------------------------------------------------------------
|
||||
# Notes: Home Assistant supplies action handling and accessible names.
|
||||
######################################################################
|
||||
|
||||
|
|
||||
ha-card.type-button {
|
||||
min-height: 112px;
|
||||
padding: 12px 10px;
|
||||
border-radius: 20px;
|
||||
flex-direction: row;
|
||||
gap: 8px;
|
||||
font-size: 18px;
|
||||
font-weight: 700;
|
||||
}
|
||||
ha-card ha-state-icon { width: 28px; flex-shrink: 0; }
|
||||
ha-card ha-state-icon + span { margin: 0; white-space: normal; overflow-wrap: anywhere; }
|
||||
ha-card:focus-visible { outline: 3px solid var(--primary-color); outline-offset: -3px; }
|
||||
@ -0,0 +1,12 @@
|
||||
######################################################################
|
||||
# @CCOSTAN - Follow Me on X
|
||||
# For more info visit https://www.vcloudinfo.com/click-here
|
||||
# Original Repo : https://github.com/CCOSTAN/Home-AssistantConfig
|
||||
# -------------------------------------------------------------------
|
||||
# Lighting tiles - native state display and keyboard controls
|
||||
# -------------------------------------------------------------------
|
||||
# Notes: The On Now template emits the same settings for its live list.
|
||||
######################################################################
|
||||
|
||||
class: lighting-toggle
|
||||
style: '@import url("/local/lighting-tile.css?v=275608177ba5");'
|
||||
@ -0,0 +1,91 @@
|
||||
// The native gesture handler can retain its hold state on the next keyboard activation.
|
||||
// Send keyboard gestures directly to the opt-in tile's configured action handler.
|
||||
let pressedSpace;
|
||||
|
||||
function lightingButton(event) {
|
||||
const button = event.composedPath()[0];
|
||||
if (button?.getAttribute?.("role") !== "button") return;
|
||||
const container = button.getRootNode().host;
|
||||
if (container?.localName === "ha-tile-container" && container.closest("ha-card.lighting-toggle")) {
|
||||
return button;
|
||||
}
|
||||
}
|
||||
|
||||
// Auto-entities rebuilds the grid when an On Now light turns off.
|
||||
function followOnNowRemoval(button, path) {
|
||||
const list = path.find(node => node.localName === "auto-entities");
|
||||
if (!list) return;
|
||||
const tiles = () => list.querySelector("layout-card")?.shadowRoot
|
||||
?.querySelector("grid-layout")?.shadowRoot?.querySelectorAll("hui-tile-card");
|
||||
const index = Array.from(tiles() ?? []).findIndex(tile => path.includes(tile));
|
||||
if (index < 0) return;
|
||||
|
||||
const observer = new MutationObserver(() => {
|
||||
if (button.isConnected) return;
|
||||
observer.disconnect();
|
||||
clearTimeout(timeout);
|
||||
requestAnimationFrame(() => {
|
||||
if (!list.isConnected || document.activeElement !== document.body) return;
|
||||
const remaining = tiles();
|
||||
const tile = remaining?.length ? remaining[Math.min(index, remaining.length - 1)] : null;
|
||||
const next = tile?.shadowRoot?.querySelector("ha-tile-container")?.shadowRoot?.querySelector('[role="button"]');
|
||||
if (next) {
|
||||
next.focus();
|
||||
} else {
|
||||
list.tabIndex = -1;
|
||||
list.setAttribute("role", "region");
|
||||
list.setAttribute("aria-label", "On Now");
|
||||
list.focus();
|
||||
}
|
||||
});
|
||||
});
|
||||
// A failed toggle leaves the original tile in place.
|
||||
const timeout = setTimeout(() => observer.disconnect(), 5000);
|
||||
// The old grid can be replaced in the same frame as the keyboard action.
|
||||
for (const node of path) {
|
||||
if (node === list || node instanceof ShadowRoot) observer.observe(node, { childList: true, subtree: true });
|
||||
if (node === list) break;
|
||||
}
|
||||
}
|
||||
|
||||
function activate(button, action, event) {
|
||||
if (action === "tap") followOnNowRemoval(button, event.composedPath());
|
||||
button.dispatchEvent(new CustomEvent("action", {
|
||||
bubbles: true,
|
||||
composed: true,
|
||||
detail: { action },
|
||||
}));
|
||||
}
|
||||
|
||||
window.addEventListener("keydown", (event) => {
|
||||
if (event.defaultPrevented || event.isComposing || event.ctrlKey || event.altKey || event.metaKey) return;
|
||||
const details = event.key === "ContextMenu" || (event.shiftKey && event.key === "F10");
|
||||
if (!details && (event.shiftKey || !["Enter", " "].includes(event.key))) return;
|
||||
const button = lightingButton(event);
|
||||
if (!button) return;
|
||||
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
if (event.repeat) return;
|
||||
if (event.key === " ") {
|
||||
pressedSpace = button;
|
||||
} else {
|
||||
activate(button, details ? "hold" : "tap", event);
|
||||
}
|
||||
}, true);
|
||||
|
||||
window.addEventListener("keyup", (event) => {
|
||||
if (event.key !== " " || !pressedSpace) return;
|
||||
const button = pressedSpace;
|
||||
pressedSpace = undefined;
|
||||
if (lightingButton(event) !== button) return;
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
activate(button, "tap", event);
|
||||
}, true);
|
||||
|
||||
window.addEventListener("focusout", (event) => {
|
||||
if (pressedSpace && event.composedPath()[0] === pressedSpace) pressedSpace = undefined;
|
||||
}, true);
|
||||
|
||||
window.addEventListener("blur", () => { pressedSpace = undefined; });
|
||||
@ -0,0 +1,31 @@
|
||||
/* Shared by the fixed room tiles and the live On Now list. */
|
||||
ha-card.type-tile {
|
||||
min-height: 112px;
|
||||
border-radius: 20px;
|
||||
--ha-tile-info-primary-font-size: 18px;
|
||||
--ha-tile-info-primary-font-weight: 700;
|
||||
--ha-tile-info-secondary-font-size: 15px;
|
||||
--ha-tile-info-secondary-font-weight: 700;
|
||||
}
|
||||
ha-card.type-tile:has(ha-tile-icon[data-state="on"]) {
|
||||
background: color-mix(in srgb, var(--info-color) 12%, var(--card-background-color));
|
||||
border-color: color-mix(in srgb, var(--info-color) 45%, var(--divider-color));
|
||||
}
|
||||
ha-card.type-tile:has(ha-tile-icon[data-state="off"]) {
|
||||
background: color-mix(in srgb, var(--success-color) 10%, var(--card-background-color));
|
||||
border-color: color-mix(in srgb, var(--success-color) 45%, var(--divider-color));
|
||||
}
|
||||
ha-card.type-tile:has(ha-tile-icon:is([data-state="unavailable"], [data-state="unknown"])) {
|
||||
border-color: var(--error-color);
|
||||
}
|
||||
ha-card.type-tile [slot="primary"],
|
||||
ha-card.type-tile [slot="secondary"] {
|
||||
white-space: normal;
|
||||
overflow-wrap: anywhere;
|
||||
text-overflow: clip;
|
||||
}
|
||||
ha-card.type-tile [slot="secondary"] { text-transform: uppercase; }
|
||||
ha-card.type-tile:has(ha-tile-container[focused]) {
|
||||
outline: 3px solid var(--primary-color);
|
||||
outline-offset: -3px;
|
||||
}
|
||||
Loading…
Reference in new issue