diff --git a/src/cards/dropdown/changes.ts b/src/cards/dropdown/changes.ts deleted file mode 100644 index c5df5154..00000000 --- a/src/cards/dropdown/changes.ts +++ /dev/null @@ -1,93 +0,0 @@ -import { initializesubButtonIcon } from '../../tools/global-changes.ts'; -import { - applyScrollingEffect, - getIcon, - getImage, - getName, - getState, - getAttribute, - getWeatherIcon, - setLayout -} 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 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 dropdown custom templates:', error); - } - - if (context.elements.customStyle) { - context.elements.customStyle.innerText = customStyle; - context.elements.dropdownCustomStyleElement.innerText = customStyle; - } -} diff --git a/src/cards/dropdown/create.ts b/src/cards/dropdown/create.ts deleted file mode 100644 index 2acb8cbd..00000000 --- a/src/cards/dropdown/create.ts +++ /dev/null @@ -1,131 +0,0 @@ -import { addActions, addFeedback } from "../../tools/tap-actions.ts"; -import { createElement, toggleEntity, throttle, forwardHaptic, isEntityType } from "../../tools/utils.ts"; -import styles from "./styles.ts"; - -export function createStructure(context) { - if (!context.elements) context.elements = {}; - - let container = context.content; - - context.elements.selectCardContainer = createElement('div', 'bubble-select-card-container'); - context.elements.selectCard = createElement('div', 'bubble-select-card'); - context.elements.selectBackground = createElement('div', 'bubble-select-background'); - context.elements.nameContainer = createElement('div', 'bubble-name-container'); - context.elements.iconContainer = createElement('div', 'bubble-icon-container'); - context.elements.name = createElement('div', 'bubble-name'); - context.elements.state = createElement('div', 'bubble-state'); - context.elements.feedback = createElement('div', 'bubble-feedback-element'); - context.elements.icon = createElement('ha-icon', 'bubble-icon'); - context.elements.image = createElement('div', 'bubble-entity-picture'); - context.elements.style = createElement('style'); - context.elements.customStyle = createElement('style'); - - // New Dropdown Elements - context.elements.dropdownContainer = createElement('div', 'bubble-dropdown-container'); - context.elements.dropdownSelect = createElement('ha-select', 'bubble-dropdown-select'); - context.elements.dropdownSelect.setAttribute('outlined', ''); - context.elements.dropdownArrow = createElement('ha-icon', 'bubble-dropdown-arrow'); - context.elements.dropdownArrow.setAttribute('icon', 'mdi:chevron-down'); - - context.elements.feedback.style.display = 'none'; - context.elements.style.innerText = styles; - - addFeedback(context.elements.selectBackground, context.elements.feedback); - addActions(context.elements.iconContainer, context.config); - - context.elements.iconContainer.appendChild(context.elements.icon); - context.elements.iconContainer.appendChild(context.elements.image); - - context.elements.nameContainer.appendChild(context.elements.name); - context.elements.nameContainer.appendChild(context.elements.state); - - context.elements.selectCard.appendChild(context.elements.selectBackground); - context.elements.selectCard.appendChild(context.elements.iconContainer); - context.elements.selectCard.appendChild(context.elements.nameContainer); - context.elements.selectCard.appendChild(context.elements.dropdownContainer); - - context.elements.selectCardContainer.appendChild(context.elements.selectCard); - - context.elements.selectBackground.appendChild(context.elements.feedback); - - context.elements.dropdownContainer.appendChild(context.elements.dropdownArrow); - - container.innerHTML = ''; - - container.appendChild(context.elements.selectCardContainer); - - container.appendChild(context.elements.style); - container.appendChild(context.elements.customStyle); - - // Create and append style for ha-select - - context.elements.dropdownStyleElement = createElement('style'); - context.elements.dropdownCustomStyleElement = createElement('style'); - context.elements.dropdownStyleElement.textContent = styles; - - function addStyleWhenShadowRootAvailable() { - if (context.elements.dropdownSelect.shadowRoot) { - context.elements.dropdownSelect.shadowRoot.appendChild(context.elements.dropdownStyleElement); - context.elements.dropdownSelect.shadowRoot.appendChild(context.elements.dropdownCustomStyleElement); - } else { - setTimeout(addStyleWhenShadowRootAvailable, 0); - } - } - - addStyleWhenShadowRootAvailable(); - - context.cardType = `select`; - -} - -export function createDropdownActions(context) { - let dropdownArrow = context.elements.dropdownArrow; - let dropdownSelect = context.elements.dropdownSelect; - let card = context.elements.selectCardContainer; - - // Focus animation - - context.elements.selectBackground.addEventListener('click', function() { - let selectMenu = context.elements.dropdownSelect.shadowRoot.querySelector('mwc-menu'); - card.style.zIndex = '1'; - selectMenu.setAttribute('open', ''); - dropdownArrow.style.transform = 'rotate(180deg)'; - card.style.border = 'solid 2px var(--accent-color)'; - context.elements.dropdownArrow.style.background = 'var(--accent-color)'; - }); - - dropdownSelect.addEventListener('closed', function() { - dropdownArrow.style.transform = 'rotate(0deg)'; - card.style.border = 'solid 2px rgba(0,0,0,0)'; - context.elements.dropdownArrow.style.background = ''; - card.style.zIndex = '0'; - }); - - // Update selected inputt - - context.elements.dropdownSelect.addEventListener('click', function() { - let selectedOption = context.elements.dropdownSelect.shadowRoot?.querySelector('.mdc-select__selected-text').textContent; - let entityId = context.config.entity; - context._hass.callService('input_select', 'select_option', { - entity_id: entityId, - option: selectedOption - }); - }); - - // Append options to the dropdown select element - - let options = context._hass.states[context.config.entity].attributes.options; - let state = context._hass.states[context.config.entity].state; - - options.forEach((option, index) => { - const opt = createElement('mwc-list-item'); - opt.setAttribute('value', option); - opt.textContent = option; - if (option === state) { - opt.setAttribute('selected', ''); - } - context.elements.dropdownSelect.appendChild(opt); - }); - - context.elements.dropdownContainer.appendChild(context.elements.dropdownSelect); -} \ No newline at end of file diff --git a/src/cards/dropdown/index.ts b/src/cards/dropdown/index.ts deleted file mode 100644 index eb22c45f..00000000 --- a/src/cards/dropdown/index.ts +++ /dev/null @@ -1,27 +0,0 @@ -import { changeState, changeSubButtonState } from "../../tools/global-changes.ts"; -import { - changeStatus, - changeName, - changeIcon, - changeStyle -} from './changes.ts' -import { - createStructure, - createDropdownActions -} from './create.ts'; - -export function handleSelect(context) { - const cardType = context.cardType; - - if (context.cardType !== "select") { - createStructure(context); - createDropdownActions(context); - } - - changeStatus(context); - changeIcon(context); - changeName(context); - changeState(context); - changeSubButtonState(context, context.content, context.elements.dropdownContainer, true); - changeStyle(context); -} \ No newline at end of file diff --git a/src/cards/dropdown/styles.ts b/src/cards/dropdown/styles.ts deleted file mode 100644 index 64fca7a4..00000000 --- a/src/cards/dropdown/styles.ts +++ /dev/null @@ -1,221 +0,0 @@ -export default ` - * { - -webkit-tap-highlight-color: transparent !important; - } - ha-card { - margin-top: 0; - background: none; - opacity: 1; - } - mwc-list-item { - border-radius: 24px; - margin: 0 8px; - } - mwc-list-item[selected] { - color: var(--primary-text-color) !important; - background-color: var(--accent-color); - } - ha-select { - --mdc-shape-medium: 30px; - --mdc-shape-large: 30px; - --mdc-shape-small: 64px; - --mdc-menu-max-width: min-content; - --mdc-menu-min-width: 150px; - --mdc-select-max-width: min-content; - --mdc-select-outlined-hover-border-color: transparent; - --mdc-select-outlined-idle-border-color: transparent; - --mdc-theme-primary: transparent; - } - .mdc-select { - color: transparent !important; - width: 150px !important; - position: absolute !important; - pointer-events: none; - right: -4px; - top: -5px; - z-index: 1; - } - .mdc-menu, mwc-list, .mdc-list-item { - pointer-events: auto; - } - .mdc-select__dropdown-icon { - display: none !important; - } - .mdc-select__selected-text { - color: transparent !important; - } - .mdc-select__anchor { - width: 100%; - pointer-events: none; - } - .bubble-dropdown-container { - display: flex; - width: auto; - height: 100%; - align-items: center; - } - .bubble-dropdown-arrow { - display: flex; - position: absolute; - background: var(--card-background-color, var(--ha-card-background)); - height: 36px; - width: 36px; - right: 6px; - z-index: 1; - pointer-events: none; - border-radius: 20px; - align-items: center; - justify-content: center; - transition: transform 0.2s; - } - .bubble-dropdown-select { - width: 42px; - } - .is-unavailable { - opacity: 0.5; - } - .bubble-select-card-container { - position: relative; - width: 100%; - height: 50px; - background-color: var(--background-color-2,var(--secondary-background-color)); - border-radius: 25px; - -webkit-transform: translateZ(0); - touch-action: pan-y; - box-sizing:border-box; - border: solid 2px transparent; - transition: all 0.15s; - cursor: pointer; - } - .bubble-select-card, - .bubble-select-background { - display: flex; - position: absolute; - justify-content: space-between; - align-items: center; - height: 100%; - width: 100%; - transition: background-color 1.5s; - } - .bubble-select-background { - background-color: var(--bubble-select-background-color); - opacity: .5; - overflow: hidden !important; - border-radius: 25px; - } - .is-unavailable .bubble-select-card { - cursor: not-allowed; - } - .bubble-icon-container { - display: flex; - flex-wrap: wrap; - align-content: center; - justify-content: center; - min-width: 38px; - min-height: 38px; - margin: 6px 6px 6px 4px; - border-radius: 50%; - background-color: var(--card-background-color, var(--ha-card-background)); - overflow: hidden; - z-index: 1; - position: relative; - cursor: pointer; - } - .bubble-icon-container::after { - content: ''; - background-color: currentColor; - position: absolute; - display: block; - width: 100%; - height: 100%; - transition: all 1s; - left: 0; - right: 0; - opacity: 0; - } - - .bubble-icon { - display: flex; - opacity: 0.6; - } - - .bubble-entity-picture { - background-size: cover; - background-position: center; - height: 100%; - width: 100%; - position: absolute; - } - - .bubble-name, - .bubble-state { - display: flex; - position: relative; - white-space: nowrap; - } - - .bubble-name-container { - display: flex; - line-height: 18px; - flex-direction: column; - justify-content: center; - flex-grow: 1; - margin: 0 16px 0 4px; - pointer-events: none; - position: relative; - overflow: hidden; - } - - .bubble-name { - font-weight: 600; - } - - .bubble-state { - font-size: 12px; - font-weight: normal; - opacity: 0.7; - } - - .bubble-feedback-element { - position: absolute; - top: 0; - left: 0; - opacity: 0; - width: 100%; - height: 100%; - background-color: rgb(0,0,0); - pointer-events: none; - } - - @keyframes tap-feedback { - 0% {transform: translateX(-100%); opacity: 0;} - 64% {transform: translateX(0); opacity: 0.1;} - 100% {transform: translateX(100%); opacity: 0;} - } - - .large .bubble-select-card-container { - height: 64px; - border-radius: 32px; - } - - .large .bubble-icon-container { - --mdc-icon-size: 28px; - min-width: 48px !important; - min-height: 48px !important; - margin-left: 6px; - } - - .rows-2 .bubble-sub-button-container { - flex-direction: column; - gap: 4px !important; - display: grid !important; - grid-template-columns: repeat(2, min-content); - grid-template-rows: repeat(2, 1fr); - grid-auto-flow: column; - width: auto; - } - - .rows-2 .bubble-sub-button { - height: 20px !important; - } -`; \ No newline at end of file