| Sean McCullough | 71941bd | 2025-04-18 13:31:48 -0700 | [diff] [blame] | 1 | import { css, html, LitElement } from "lit"; |
| 2 | import { customElement, property } from "lit/decorators.js"; |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 3 | |
| Sean McCullough | 71941bd | 2025-04-18 13:31:48 -0700 | [diff] [blame] | 4 | @customElement("sketch-network-status") |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 5 | export class SketchNetworkStatus extends LitElement { |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 6 | @property() |
| 7 | connection: string; |
| Sean McCullough | b29f891 | 2025-04-20 15:39:11 -0700 | [diff] [blame] | 8 | |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 9 | @property() |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 10 | error: string; |
| Sean McCullough | 71941bd | 2025-04-18 13:31:48 -0700 | [diff] [blame] | 11 | |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 12 | // See https://lit.dev/docs/components/styles/ for how lit-element handles CSS. |
| 13 | // Note that these styles only apply to the scope of this web component's |
| 14 | // shadow DOM node, so they won't leak out or collide with CSS declared in |
| 15 | // other components or the containing web page (...unless you want it to do that). |
| 16 | |
| 17 | static styles = css` |
| Sean McCullough | 71941bd | 2025-04-18 13:31:48 -0700 | [diff] [blame] | 18 | .status-container { |
| 19 | display: flex; |
| 20 | align-items: center; |
| 21 | } |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 22 | |
| Sean McCullough | 71941bd | 2025-04-18 13:31:48 -0700 | [diff] [blame] | 23 | .status-text { |
| 24 | font-size: 11px; |
| 25 | color: #666; |
| 26 | } |
| 27 | `; |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 28 | |
| 29 | constructor() { |
| 30 | super(); |
| 31 | } |
| 32 | |
| 33 | // See https://lit.dev/docs/components/lifecycle/ |
| 34 | connectedCallback() { |
| 35 | super.connectedCallback(); |
| 36 | } |
| 37 | |
| 38 | // See https://lit.dev/docs/components/lifecycle/ |
| 39 | disconnectedCallback() { |
| Sean McCullough | 71941bd | 2025-04-18 13:31:48 -0700 | [diff] [blame] | 40 | super.disconnectedCallback(); |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 41 | } |
| 42 | |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 43 | render() { |
| Philip Zeyliger | bce3a13 | 2025-04-30 22:03:39 +0000 | [diff] [blame] | 44 | // Only render if there's an error to display |
| 45 | if (!this.error) { |
| 46 | return html``; |
| 47 | } |
| 48 | |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 49 | return html` |
| Sean McCullough | 71941bd | 2025-04-18 13:31:48 -0700 | [diff] [blame] | 50 | <div class="status-container"> |
| Philip Zeyliger | bce3a13 | 2025-04-30 22:03:39 +0000 | [diff] [blame] | 51 | <span id="statusText" class="status-text">${this.error}</span> |
| Sean McCullough | 71941bd | 2025-04-18 13:31:48 -0700 | [diff] [blame] | 52 | </div> |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 53 | `; |
| 54 | } |
| 55 | } |
| 56 | |
| 57 | declare global { |
| 58 | interface HTMLElementTagNameMap { |
| 59 | "sketch-network-status": SketchNetworkStatus; |
| 60 | } |
| Sean McCullough | 71941bd | 2025-04-18 13:31:48 -0700 | [diff] [blame] | 61 | } |