import { mdiExclamationThick } from "@mdi/js"; import { LitElement, PropertyValues, TemplateResult, css, html, nothing, svg, } from "lit"; import { customElement, property } from "lit/decorators"; import { isSafari } from "../../util/is_safari"; import { NODE_SIZE, SPACING } from "./hat-graph-const"; /** * @attribute active * @attribute track */ @customElement("hat-graph-node") export class HatGraphNode extends LitElement { @property() iconPath?: string; @property({ type: Boolean, reflect: true }) public disabled = false; @property({ type: Boolean }) public error = false; @property({ reflect: true, type: Boolean }) notEnabled = false; @property({ reflect: true, type: Boolean }) graphStart = false; @property({ type: Boolean, attribute: "nofocus" }) noFocus = false; @property({ reflect: true, type: Number }) badge?: number; protected updated(changedProps: PropertyValues) { if (changedProps.has("noFocus")) { if (!this.hasAttribute("tabindex") && !this.noFocus) { this.setAttribute("tabindex", "0"); } else if (changedProps.get("noFocus") !== undefined && this.noFocus) { this.removeAttribute("tabindex"); } } } protected render(): TemplateResult { const height = NODE_SIZE + (this.graphStart ? 2 : SPACING + 1); const width = SPACING + NODE_SIZE; return html` ${this.graphStart ? nothing : svg` `} ${this.error ? svg` ` : nothing} ${this.badge ? svg` ${this.badge > 9 ? "9+" : this.badge} ` : nothing} ${this.iconPath ? svg`` : svg``} `; } static get styles() { return css` :host { display: flex; flex-direction: column; min-width: calc(var(--hat-graph-node-size) + var(--hat-graph-spacing)); height: calc( var(--hat-graph-node-size) + var(--hat-graph-spacing) + 1px ); } :host([graphStart]) { height: calc(var(--hat-graph-node-size) + 2px); } :host([track]) { --stroke-clr: var(--track-clr); --icon-clr: var(--default-icon-clr); } :host([active]) circle { --stroke-clr: var(--active-clr); --icon-clr: var(--default-icon-clr); } :host(:focus) { outline: none; } :host(:hover) circle { --stroke-clr: var(--hover-clr); --icon-clr: var(--default-icon-clr); } :host([notEnabled]) circle { --stroke-clr: var(--disabled-clr); } :host([notEnabled][active]) circle { --stroke-clr: var(--disabled-active-clr); } :host([notEnabled]:hover) circle { --stroke-clr: var(--disabled-hover-clr); } svg:not(.safari) { width: 100%; height: 100%; } circle, path.connector { stroke: var(--stroke-clr); stroke-width: 2; fill: none; } circle { fill: var(--background-clr); stroke: var(--circle-clr, var(--stroke-clr)); } .error circle { fill: var(--error-color); stroke: none; stroke-width: 0; } .error .exclamation { fill: var(--text-primary-color); } .number circle { fill: var(--track-clr); stroke: none; stroke-width: 0; } .number text { font-size: 10px; fill: var(--text-primary-color); } path.icon { fill: var(--icon-clr); } foreignObject { width: 24px; height: 24px; } .icon { color: var(--icon-clr); } `; } } declare global { interface HTMLElementTagNameMap { "hat-graph-node": HatGraphNode; } }