mirror of
https://github.com/misode/misode.github.io.git
synced 2026-04-25 16:16:50 +00:00
Add conditional rendering
This commit is contained in:
@@ -2,26 +2,20 @@ import { AbstractNode, NodeMods, RenderOptions } from "./AbstractNode";
|
||||
import { Path } from "../model/Path";
|
||||
import { TreeView } from "../view/TreeView";
|
||||
|
||||
export interface BooleanNodeMods extends NodeMods<boolean> {
|
||||
force?: boolean
|
||||
}
|
||||
|
||||
export class BooleanNode extends AbstractNode<boolean> {
|
||||
force: boolean
|
||||
|
||||
constructor(mods?: BooleanNodeMods) {
|
||||
constructor(mods?: NodeMods<boolean>) {
|
||||
super({
|
||||
default: () => false,
|
||||
...mods})
|
||||
this.force = (mods?.force === true)
|
||||
}
|
||||
|
||||
renderRaw(path: Path, value: boolean, view: TreeView, options?: RenderOptions) {
|
||||
const falseButton = view.registerClick(el => {
|
||||
view.model.set(path, !this.force && value === false ? undefined : false)
|
||||
view.model.set(path, !this.force() && value === false ? undefined : false)
|
||||
})
|
||||
const trueButton = view.registerClick(el => {
|
||||
view.model.set(path, !this.force && value === true ? undefined : true)
|
||||
view.model.set(path, !this.force() && value === true ? undefined : true)
|
||||
})
|
||||
return `${options?.hideLabel ? `` : `<label>${path.last()}</label>`}
|
||||
<button${value === false ? ' style="font-weight: bold"' : ' '} data-id="${falseButton}">False</button>
|
||||
|
||||
Reference in New Issue
Block a user