annotate src/FdClock.ts @ 13:deb0c25655eb

cleanup, add FdClock and Countdown
author drewp@bigasterisk.com
date Thu, 06 Jun 2024 16:39:51 -0700
parents
children 20d1fa4250c0
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
13
deb0c25655eb cleanup, add FdClock and Countdown
drewp@bigasterisk.com
parents:
diff changeset
1 import { css, html, LitElement } from "lit";
deb0c25655eb cleanup, add FdClock and Countdown
drewp@bigasterisk.com
parents:
diff changeset
2 import { shared } from "./shared";
deb0c25655eb cleanup, add FdClock and Countdown
drewp@bigasterisk.com
parents:
diff changeset
3
deb0c25655eb cleanup, add FdClock and Countdown
drewp@bigasterisk.com
parents:
diff changeset
4
deb0c25655eb cleanup, add FdClock and Countdown
drewp@bigasterisk.com
parents:
diff changeset
5 export class FdClock extends LitElement {
deb0c25655eb cleanup, add FdClock and Countdown
drewp@bigasterisk.com
parents:
diff changeset
6 constructor() {
deb0c25655eb cleanup, add FdClock and Countdown
drewp@bigasterisk.com
parents:
diff changeset
7 super();
deb0c25655eb cleanup, add FdClock and Countdown
drewp@bigasterisk.com
parents:
diff changeset
8 setInterval(() => {
deb0c25655eb cleanup, add FdClock and Countdown
drewp@bigasterisk.com
parents:
diff changeset
9 this.requestUpdate();
deb0c25655eb cleanup, add FdClock and Countdown
drewp@bigasterisk.com
parents:
diff changeset
10 }, 1000);
deb0c25655eb cleanup, add FdClock and Countdown
drewp@bigasterisk.com
parents:
diff changeset
11 }
deb0c25655eb cleanup, add FdClock and Countdown
drewp@bigasterisk.com
parents:
diff changeset
12 static styles = [
deb0c25655eb cleanup, add FdClock and Countdown
drewp@bigasterisk.com
parents:
diff changeset
13 shared,
deb0c25655eb cleanup, add FdClock and Countdown
drewp@bigasterisk.com
parents:
diff changeset
14 css`
deb0c25655eb cleanup, add FdClock and Countdown
drewp@bigasterisk.com
parents:
diff changeset
15 :host {
deb0c25655eb cleanup, add FdClock and Countdown
drewp@bigasterisk.com
parents:
diff changeset
16 display: inline block;
deb0c25655eb cleanup, add FdClock and Countdown
drewp@bigasterisk.com
parents:
diff changeset
17 }
deb0c25655eb cleanup, add FdClock and Countdown
drewp@bigasterisk.com
parents:
diff changeset
18 `,
deb0c25655eb cleanup, add FdClock and Countdown
drewp@bigasterisk.com
parents:
diff changeset
19 ];
deb0c25655eb cleanup, add FdClock and Countdown
drewp@bigasterisk.com
parents:
diff changeset
20 render() {
deb0c25655eb cleanup, add FdClock and Countdown
drewp@bigasterisk.com
parents:
diff changeset
21 const t = new Date();
deb0c25655eb cleanup, add FdClock and Countdown
drewp@bigasterisk.com
parents:
diff changeset
22 const h = t.getHours().toString().padStart(2, "0");
deb0c25655eb cleanup, add FdClock and Countdown
drewp@bigasterisk.com
parents:
diff changeset
23 const m = t.getMinutes().toString().padStart(2, "0");
deb0c25655eb cleanup, add FdClock and Countdown
drewp@bigasterisk.com
parents:
diff changeset
24 const s = t.getSeconds().toString().padStart(2, "0");
deb0c25655eb cleanup, add FdClock and Countdown
drewp@bigasterisk.com
parents:
diff changeset
25 return html` <span class="t">${h}:${m.slice(0, 2)}:${s.slice(0, 2)}</span> `;
deb0c25655eb cleanup, add FdClock and Countdown
drewp@bigasterisk.com
parents:
diff changeset
26 }
deb0c25655eb cleanup, add FdClock and Countdown
drewp@bigasterisk.com
parents:
diff changeset
27 }
deb0c25655eb cleanup, add FdClock and Countdown
drewp@bigasterisk.com
parents:
diff changeset
28 customElements.define("fd-clock", FdClock);