From 365d0d796aaef7d1419518f404f49a0bdb3e7d64 Mon Sep 17 00:00:00 2001 From: Kevin Hoyt Date: Mon, 29 Jan 2024 17:09:35 -0700 Subject: [PATCH] Add hidden to alert Some additional style tweaks for displaying full width of parent container. --- components/alert.js | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/components/alert.js b/components/alert.js index fef2d0d..23bac87 100644 --- a/components/alert.js +++ b/components/alert.js @@ -13,6 +13,10 @@ export default class RainforestAlert extends HTMLElement { position: relative; } + :host( [hidden] ) { + display: none; + } + div[part=alert] { background-color: var( --alert-background-color, #f2f8fd ); border-color: var( --alert-border-color, #0972d3 ); @@ -24,6 +28,10 @@ export default class RainforestAlert extends HTMLElement { padding: 8px 16px 8px 16px; } + div[part=alert] > div { + width: 100%; + } + div[part=content] { color: var( --alert-content-color ); font-family: 'Open Sans', 'Helvetica Neue', Roboto, Arial, sans-serif; @@ -47,6 +55,7 @@ export default class RainforestAlert extends HTMLElement { flex-grow: 1; margin: 4px; padding: 2px 0 2px 0; + width: 100%; } rf-button[part=button] { @@ -222,6 +231,7 @@ export default class RainforestAlert extends HTMLElement { // Setup connectedCallback() { this._upgrade( 'dismissable' ); + this._upgrade( 'hidden' ); this._upgrade( 'type' ); this._render(); } @@ -230,6 +240,7 @@ export default class RainforestAlert extends HTMLElement { static get observedAttributes() { return [ 'dismissable', + 'hidden', 'type' ]; } @@ -261,6 +272,26 @@ export default class RainforestAlert extends HTMLElement { } else { this.removeAttribute( 'dismissable' ); } + } + + get hidden() { + return this.hasAttribute( 'hidden' ); + } + + set hidden( value ) { + if( value !== null ) { + if( typeof value === 'boolean' ) { + value = value.toString(); + } + + if( value === 'false' ) { + this.removeAttribute( 'hidden' ); + } else { + this.setAttribute( 'hidden', '' ); + } + } else { + this.removeAttribute( 'hidden' ); + } } get type() {