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.

57 lines 2.08 kB
import { addStyleSheet, element, fragment } from "../../framework.js"; import { ButtonControl } from "./ButtonControl.js"; addStyleSheet(import.meta.url); export class ToggleControl { constructor(initialState, inner, onManualChange) { this.state = initialState; const buttonText = element("span", {}, inner); this.cross = CrossSvg(); this.tick = TickSvg(); this.cross.classList.add("togglecontrol-svg"); this.tick.classList.add("togglecontrol-svg"); this.dom = ButtonControl(fragment(this.state ? this.tick : this.cross, buttonText), () => { this.toggleState(); onManualChange(this.state); }); } onChange() { var _a, _b; if (this.state) { (_a = this.cross.parentElement) === null || _a === void 0 ? void 0 : _a.replaceChild(this.tick, this.cross); } else { (_b = this.tick.parentElement) === null || _b === void 0 ? void 0 : _b.replaceChild(this.cross, this.tick); } } getState() { return this.state; } setState(state) { this.state = state; this.onChange(); } toggleState() { this.setState(!this.state); } } const crossTemplate = element("template"); crossTemplate.innerHTML = `<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" height="10" width="10" viewbox="0 0 10 10"> <polygon points="0,1, 1,0, 5.5,3.5, 9,0, 10,1, 6,5.5, 10,9, 9,10, 4.5,6.5, 1,10, 0,9, 4,4.5"/> </svg>`; function CrossSvg() { return crossTemplate.content.firstElementChild.cloneNode(true); } const tickTemplate = element("template"); tickTemplate.innerHTML = `<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" height="10" width="10" viewbox="0 0 10 10"> <polygon points="1,5, 4,7, 9,0, 10,1, 4,10, 0,6"/> </svg>`; function TickSvg() { return tickTemplate.content.firstElementChild.cloneNode(true); } //# sourceMappingURL=ToggleControl.js.map