Skip to content

Commit

Permalink
Add update handler for tone attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
lemonmade committed Jan 3, 2024
1 parent 8e1fad4 commit a0caee3
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion examples/minimal-iframes/app/index.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<!DOCTYPE html>
<!doctype html>
<html>
<body>
<div id="root"></div>
Expand All @@ -7,6 +7,10 @@

<script type="module">
class UIBanner extends HTMLElement {
static get observedAttributes() {
return ['tone'];
}

connectedCallback() {
// We will allow you to pass a `tone` attribute to the element, which
// styles the banner according to our design system. We’ll see how to
Expand All @@ -33,6 +37,16 @@
<div class="Banner Banner--${tone}"><slot></slot></div>
`;
}

attributeChangedCallback(name, oldValue, newValue) {
if (name === 'tone') {
const banner = this.shadowRoot?.querySelector('.Banner');
if (banner == null) return;

banner.classList.remove(`Banner--${oldValue ?? 'neutral'}`);
banner.classList.add(`Banner--${newValue ?? 'neutral'}`);
}
}
}

customElements.define('ui-banner', UIBanner);
Expand Down

0 comments on commit a0caee3

Please sign in to comment.