blob: 4b01e5edaaef1267098a3029b82f36c295e48f4b [file] [log] [blame]
Sean McCullough86b56862025-04-18 13:04:03 -07001import {css, html, LitElement} from 'lit';
2import {customElement, property} from 'lit/decorators.js';
3import {DataManager, ConnectionStatus} from '../data';
4import {State, TimelineMessage} from '../types';
5import './sketch-container-status';
6
7@customElement('sketch-network-status')
8export class SketchNetworkStatus extends LitElement {
9 // Header bar: view mode buttons
10
11 @property()
12 connection: string;
13 @property()
14 message: string;
15 @property()
16 error: string;
17
18 // See https://lit.dev/docs/components/styles/ for how lit-element handles CSS.
19 // Note that these styles only apply to the scope of this web component's
20 // shadow DOM node, so they won't leak out or collide with CSS declared in
21 // other components or the containing web page (...unless you want it to do that).
22
23 static styles = css`
24.status-container {
25 display: flex;
26 align-items: center;
27}
28
29.polling-indicator {
30 display: inline-block;
31 width: 8px;
32 height: 8px;
33 border-radius: 50%;
34 margin-right: 4px;
35 background-color: #ccc;
36}
37
38.polling-indicator.active {
39 background-color: #4caf50;
40 animation: pulse 1.5s infinite;
41}
42
43.polling-indicator.error {
44 background-color: #f44336;
45 animation: pulse 1.5s infinite;
46}
47
48@keyframes pulse {
49 0% {
50 opacity: 1;
51 }
52 50% {
53 opacity: 0.5;
54 }
55 100% {
56 opacity: 1;
57 }
58}
59
60.status-text {
61 font-size: 11px;
62 color: #666;
63}
64`;
65
66 constructor() {
67 super();
68 }
69
70 // See https://lit.dev/docs/components/lifecycle/
71 connectedCallback() {
72 super.connectedCallback();
73 }
74
75 // See https://lit.dev/docs/components/lifecycle/
76 disconnectedCallback() {
77 super.disconnectedCallback();
78 }
79
80 indicator() {
81 if (this.connection === "disabled") {
82 return '';
83 }
84 return this.connection === "connected" ? "active": "error";
85 }
86
87 render() {
88 return html`
89 <div class="status-container">
90 <span id="pollingIndicator" class="polling-indicator ${this.indicator()}"></span>
91 <span id="statusText" class="status-text">${this.error || this.message}</span>
92 </div>
93 `;
94 }
95}
96
97declare global {
98 interface HTMLElementTagNameMap {
99 "sketch-network-status": SketchNetworkStatus;
100 }
101}