UNPKG

cognitive-complexity-ts

Version:

This program analyses TypeScript and JavaScript code according to the [Cognitive Complexity metric](https://www.sonarsource.com/docs/CognitiveComplexity.pdf). It produces a JSON summary and a GUI for exploring the complexity of your codebase.

45 lines 1.29 kB
import { addStyleSheet, element } from "../../framework.js"; addStyleSheet(import.meta.url); export class ToggleButton { constructor(isOpen, onStateChange, onManualStateChange) { this.onStateChange = onStateChange; this.stateSymbol = new StateSymbol(); this.dom = element("label", { className: "togglebutton-label", }, this.input = element("input", { checked: isOpen, className: "togglebutton-input", type: "checkbox", }), this.stateSymbol.text); this.dom.addEventListener("change", () => { this.handleStateChange(); onManualStateChange(this.input.checked); }); this.setSymbol(); } handleStateChange() { this.setSymbol(); this.onStateChange(this.input.checked); } setState(open) { this.input.checked = open; this.handleStateChange(); } setSymbol() { this.stateSymbol.setState(this.input.checked); } } class StateSymbol { constructor() { this.text = new Text(""); } setState(bool) { if (bool) { this.text.textContent = "-"; } else { this.text.textContent = "+"; } } } //# sourceMappingURL=ToggleButton.js.map