-
-
Notifications
You must be signed in to change notification settings - Fork 83
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Select for sub-buttons, open/close action for pop-up and more...
- [x] New feature: Ability to remove the pop-up header - [x] New feature: Select for sub-buttons - [x] New feature: Added support for select entities - [x] New feature: open_action: and close_action: for pop-ups - [x] Fixed the pop-up preview in the HA 2024.7.x editor for all view types #618 - [x] Issue in preview panel with input_select button #613
- Loading branch information
Showing
15 changed files
with
792 additions
and
69 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
import { initializesubButtonIcon } from '../../tools/global-changes.ts'; | ||
import { | ||
applyScrollingEffect, | ||
getIcon, | ||
getImage, | ||
getName, | ||
getState, | ||
getAttribute, | ||
getWeatherIcon, | ||
setLayout, | ||
createElement | ||
} from '../../tools/utils.ts'; | ||
|
||
export function changeIcon(context) { | ||
const icon = getIcon(context); | ||
const image = getImage(context); | ||
|
||
if (image !== '') { | ||
context.elements.image.style.backgroundImage = 'url(' + image + ')'; | ||
context.elements.icon.style.display = 'none'; | ||
context.elements.image.style.display = ''; | ||
} else if (icon !== '') { | ||
context.elements.icon.icon = icon; | ||
context.elements.icon.style.color = 'inherit'; | ||
context.elements.icon.style.display = ''; | ||
context.elements.image.style.display = 'none'; | ||
} else { | ||
context.elements.icon.style.display = 'none'; | ||
context.elements.image.style.display = 'none'; | ||
} | ||
} | ||
|
||
export function changeName(context) { | ||
const name = getName(context); | ||
if (name !== context.elements.previousName) { | ||
applyScrollingEffect(context, context.elements.name, name); | ||
context.elements.previousName = name; | ||
} | ||
} | ||
|
||
export function changeStatus(context) { | ||
const state = getState(context); | ||
|
||
if (state === 'unavailable') { | ||
context.card.classList.add('is-unavailable'); | ||
} else { | ||
context.card.classList.remove('is-unavailable'); | ||
} | ||
} | ||
|
||
export function changeDropdownList(context, elements = context.elements, entity = context.config.entity) { | ||
if (elements.previousEntity === entity) return; | ||
|
||
// Append options to the dropdown select element | ||
let options = context._hass.states[entity].attributes.options; | ||
let state = context._hass.states[entity].state; | ||
|
||
// Clear the dropdown list | ||
while (elements.dropdownSelect.firstChild) { | ||
elements.dropdownSelect.removeChild(elements.dropdownSelect.firstChild); | ||
} | ||
|
||
options.forEach((option, index) => { | ||
const opt = createElement('mwc-list-item'); | ||
opt.setAttribute('value', option); | ||
opt.textContent = option; | ||
if (option === state) { | ||
opt.setAttribute('selected', ''); | ||
} | ||
elements.dropdownSelect.appendChild(opt); | ||
elements.previousEntity = entity; | ||
}); | ||
|
||
elements.dropdownContainer.appendChild(elements.dropdownSelect); | ||
} | ||
|
||
export function changeStyle(context) { | ||
initializesubButtonIcon(context); | ||
setLayout(context); | ||
|
||
const cardLayout = context.config.card_layout; | ||
|
||
function addLayoutWhenShadowRootAvailable() { | ||
const mwcMenu = context.elements.dropdownSelect.shadowRoot?.querySelector('mwc-menu'); | ||
const mwcMenuShadowRoot = mwcMenu?.shadowRoot; | ||
const mwcMenuSurface = mwcMenuShadowRoot?.querySelector('mwc-menu-surface'); | ||
const mwcMenuSurfaceShadowRoot = mwcMenuSurface?.shadowRoot; | ||
const mdcMenuSurface = mwcMenuSurfaceShadowRoot?.querySelector('.mdc-menu-surface'); | ||
|
||
if (mdcMenuSurface) { | ||
if (cardLayout === 'large' || cardLayout === 'large-2-rows') { | ||
mdcMenuSurface.style.marginTop = '14px'; | ||
} else { | ||
mdcMenuSurface.style.marginTop = ''; | ||
} | ||
} else { | ||
setTimeout(addLayoutWhenShadowRootAvailable, 0); | ||
} | ||
} | ||
|
||
addLayoutWhenShadowRootAvailable(); | ||
|
||
const state = getState(context); | ||
|
||
let customStyle = ''; | ||
|
||
try { | ||
customStyle = context.config.styles | ||
? Function('hass', 'entityId', 'state', 'icon', 'subButtonIcon', 'getWeatherIcon', 'card', `return \`${context.config.styles}\`;`) | ||
(context._hass, context.config.entity, state, context.elements.icon, context.subButtonIcon, getWeatherIcon, context.card) | ||
: ''; | ||
} catch (error) { | ||
console.error('Error in generating select custom templates:', error); | ||
} | ||
|
||
if (context.elements.customStyle) { | ||
context.elements.customStyle.innerText = customStyle; | ||
context.elements.dropdownCustomStyleElement.innerText = customStyle; | ||
} | ||
} |
Oops, something went wrong.