Skip to content

Commit

Permalink
Add option to clear child cards
Browse files Browse the repository at this point in the history
Note: does not apply to children of child-cards
  • Loading branch information
Alia5 committed Sep 30, 2024
1 parent b215486 commit 9be454a
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 4 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ Yaml:
| type | string | **Required** | `custom:expander-card` | Type of the card. |
| title | string | _Expander_ | * | Title (Not displayed if using Title-Card) |
| clear | boolean | _false_ | true\|false | Remove Background |
| clear-children | boolean | _false_ | true\|false | Remove Backgrounds/Borders of child cards |
| expanded | boolean | _false_ | true\|false | Start expanded |
| expand-id | string | **optional** | string | Unique ID to use for JS LocalStorage. Will save expanded state |
| button-background | string | _transparent_ | css-color | Background color of expand button |
Expand Down
15 changes: 13 additions & 2 deletions src/Card.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@ limitations under the License.
const {
type = 'div',
config,
hass
}: { type: string; config: LovelaceCardConfig; hass: HomeAssistant } = $props();
hass,
clearChild = false
}: { type: string; config: LovelaceCardConfig; hass: HomeAssistant; clearChild: boolean } = $props();
let container = $state<LovelaceCard>();
let loading = $state(true);
Expand All @@ -47,6 +48,16 @@ limitations under the License.
}
container.replaceWith(el);
container = el;
if (clearChild) {
const shadowStyle = document.createElement('style');
shadowStyle.innerHTML = `
ha-card {
background-color: transparent !important;
border-style: none !important;
}
`;
el.shadowRoot?.appendChild(shadowStyle);
}
loading = false;
});
</script>
Expand Down
25 changes: 23 additions & 2 deletions src/ExpanderCard.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
'gap': '0.6em',
'padding': '1em',
'clear': false,
'clear-children': false,
'title': 'Expander',
'overlay-margin': '2em',
'child-padding': '0.5em',
Expand Down Expand Up @@ -91,7 +92,11 @@
{#if config['title-card']}
<div class={`title-card-header${config['title-card-button-overlay'] ? '-overlay' : ''}`}>
<div class="title-card-container" style="--title-padding:{config['title-card-padding']}">
<Card hass={hass} config={config['title-card']} type={config['title-card'].type} />
<Card
hass={hass}
config={config['title-card']}
type={config['title-card'].type}
clearChild={config['clear-children'] || false} />
</div>
<button
aria-label="Toggle"
Expand Down Expand Up @@ -141,7 +146,11 @@
class="children-container"
>
{#each config.cards as card (card)}
<Card hass={hass} config={card} type={card.type} />
<Card
hass={hass}
config={card}
type={card.type}
clearChild={config['clear-children'] || false} />
{/each}
</div>
</div>
Expand Down Expand Up @@ -177,6 +186,18 @@
background-color: transparent;
border-style: none;
}
.clear-children {
& :global(::slotted(ha-card)) {
background-color: transparent !important;
border-style: none !important;
}
}
:global(::slotted(ha-card)) {
background-color: transparent !important;
border-style: none !important;
}
.title-card-header {
display: flex;
align-items: center;
Expand Down
3 changes: 3 additions & 0 deletions src/ExpanderCardEditor.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ limitations under the License.
'clear': ['boolean', {
label: 'Remove background'
}],
'clear-children': ['boolean', {
label: 'Remove child card background/borders'
}],
'expanded': ['boolean', {
label: 'Start expanded (Always expanded in editor)'
}],
Expand Down
1 change: 1 addition & 0 deletions src/configtype.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import type { LovelaceCardConfig } from 'custom-card-helpers';

export interface ExpanderConfig {
clear?: boolean;
'clear-children'?: boolean;
cards?: { type: string }[];
gap: string;
padding: string;
Expand Down

0 comments on commit 9be454a

Please sign in to comment.