| 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; |
| Philip Zeyliger | 25f6ff1 | 2025-05-02 04:24:10 +0000 | [diff] [blame] | 21 | justify-content: center; |
| Sean McCullough | 71941bd | 2025-04-18 13:31:48 -0700 | [diff] [blame] | 22 | } |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 23 | |
| Philip Zeyliger | 25f6ff1 | 2025-05-02 04:24:10 +0000 | [diff] [blame] | 24 | .status-indicator { |
| 25 | width: 10px; |
| 26 | height: 10px; |
| 27 | border-radius: 50%; |
| 28 | } |
| 29 | |
| 30 | .status-indicator.connected { |
| 31 | background-color: #2e7d32; /* Green */ |
| 32 | box-shadow: 0 0 5px rgba(46, 125, 50, 0.5); |
| 33 | } |
| 34 | |
| 35 | .status-indicator.disconnected { |
| 36 | background-color: #d32f2f; /* Red */ |
| 37 | box-shadow: 0 0 5px rgba(211, 47, 47, 0.5); |
| 38 | } |
| 39 | |
| 40 | .status-indicator.connecting { |
| 41 | background-color: #f57c00; /* Orange */ |
| 42 | box-shadow: 0 0 5px rgba(245, 124, 0, 0.5); |
| 43 | animation: pulse 1.5s infinite; |
| 44 | } |
| 45 | |
| 46 | @keyframes pulse { |
| 47 | 0% { |
| 48 | opacity: 0.6; |
| 49 | } |
| 50 | 50% { |
| 51 | opacity: 1; |
| 52 | } |
| 53 | 100% { |
| 54 | opacity: 0.6; |
| 55 | } |
| Sean McCullough | 71941bd | 2025-04-18 13:31:48 -0700 | [diff] [blame] | 56 | } |
| 57 | `; |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 58 | |
| 59 | constructor() { |
| 60 | super(); |
| 61 | } |
| 62 | |
| 63 | // See https://lit.dev/docs/components/lifecycle/ |
| 64 | connectedCallback() { |
| 65 | super.connectedCallback(); |
| 66 | } |
| 67 | |
| 68 | // See https://lit.dev/docs/components/lifecycle/ |
| 69 | disconnectedCallback() { |
| Sean McCullough | 71941bd | 2025-04-18 13:31:48 -0700 | [diff] [blame] | 70 | super.disconnectedCallback(); |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 71 | } |
| 72 | |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 73 | render() { |
| Philip Zeyliger | 25f6ff1 | 2025-05-02 04:24:10 +0000 | [diff] [blame] | 74 | // Only show the status indicator dot (no text) |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 75 | return html` |
| Sean McCullough | 71941bd | 2025-04-18 13:31:48 -0700 | [diff] [blame] | 76 | <div class="status-container"> |
| Philip Zeyliger | 25f6ff1 | 2025-05-02 04:24:10 +0000 | [diff] [blame] | 77 | <div |
| 78 | class="status-indicator ${this.connection}" |
| 79 | title="Connection status: ${this.connection}${this.error |
| 80 | ? ` - ${this.error}` |
| 81 | : ""}" |
| 82 | ></div> |
| Sean McCullough | 71941bd | 2025-04-18 13:31:48 -0700 | [diff] [blame] | 83 | </div> |
| Sean McCullough | 86b5686 | 2025-04-18 13:04:03 -0700 | [diff] [blame] | 84 | `; |
| 85 | } |
| 86 | } |
| 87 | |
| 88 | declare global { |
| 89 | interface HTMLElementTagNameMap { |
| 90 | "sketch-network-status": SketchNetworkStatus; |
| 91 | } |
| Sean McCullough | 71941bd | 2025-04-18 13:31:48 -0700 | [diff] [blame] | 92 | } |