blob: 8a5a88399948c04619fcc78af4ca671010d2196b [file] [log] [blame]
Sean McCullough71941bd2025-04-18 13:31:48 -07001import { css, html, LitElement } from "lit";
2import { customElement, property } from "lit/decorators.js";
Sean McCullough86b56862025-04-18 13:04:03 -07003
Sean McCullough71941bd2025-04-18 13:31:48 -07004@customElement("sketch-network-status")
Sean McCullough86b56862025-04-18 13:04:03 -07005export class SketchNetworkStatus extends LitElement {
Sean McCullough86b56862025-04-18 13:04:03 -07006 @property()
7 connection: string;
Sean McCulloughb29f8912025-04-20 15:39:11 -07008
Sean McCullough86b56862025-04-18 13:04:03 -07009 @property()
Sean McCullough86b56862025-04-18 13:04:03 -070010 error: string;
Sean McCullough71941bd2025-04-18 13:31:48 -070011
Sean McCullough86b56862025-04-18 13:04:03 -070012 // 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 McCullough71941bd2025-04-18 13:31:48 -070018 .status-container {
19 display: flex;
20 align-items: center;
Philip Zeyliger25f6ff12025-05-02 04:24:10 +000021 justify-content: center;
Sean McCullough71941bd2025-04-18 13:31:48 -070022 }
Sean McCullough86b56862025-04-18 13:04:03 -070023
Philip Zeyliger25f6ff12025-05-02 04:24:10 +000024 .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 McCullough71941bd2025-04-18 13:31:48 -070056 }
57 `;
Sean McCullough86b56862025-04-18 13:04:03 -070058
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 McCullough71941bd2025-04-18 13:31:48 -070070 super.disconnectedCallback();
Sean McCullough86b56862025-04-18 13:04:03 -070071 }
72
Sean McCullough86b56862025-04-18 13:04:03 -070073 render() {
Philip Zeyliger25f6ff12025-05-02 04:24:10 +000074 // Only show the status indicator dot (no text)
Sean McCullough86b56862025-04-18 13:04:03 -070075 return html`
Sean McCullough71941bd2025-04-18 13:31:48 -070076 <div class="status-container">
Philip Zeyliger25f6ff12025-05-02 04:24:10 +000077 <div
78 class="status-indicator ${this.connection}"
79 title="Connection status: ${this.connection}${this.error
80 ? ` - ${this.error}`
81 : ""}"
82 ></div>
Sean McCullough71941bd2025-04-18 13:31:48 -070083 </div>
Sean McCullough86b56862025-04-18 13:04:03 -070084 `;
85 }
86}
87
88declare global {
89 interface HTMLElementTagNameMap {
90 "sketch-network-status": SketchNetworkStatus;
91 }
Sean McCullough71941bd2025-04-18 13:31:48 -070092}