summaryrefslogtreecommitdiff
path: root/web/src/components/grid/index.ts
blob: 18bf75a34439540cbf5804ab4d05466937b2625e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import h, { type CreateElement } from "../../html";
import "./index.css";
import colors from "open-color";

class NotiveGridElement extends HTMLElement {
  canvasEl: HTMLCanvasElement = h.canvas();

  connectedCallback() {
    this.append(this.canvasEl);
    this.draw();
  }

  draw() {
    const ctx = this.canvasEl.getContext("2d");
    if (!ctx) throw new Error("Unable to get canvas context");
    ctx.fillStyle = colors.gray[8];
    ctx.fillRect(0, 0, this.canvasEl.width, this.canvasEl.height);
  }
}

customElements.define("ntv-grid", NotiveGridElement);

export default ((...args: any[]): NotiveGridElement =>
  (h as any)["ntv-grid"](...args)) as CreateElement<NotiveGridElement>;