Type ButtonWidget (#583)

* Type ButtonWidget

* nit
This commit is contained in:
Chenlei Hu
2025-02-24 16:30:04 -05:00
committed by GitHub
parent 630fd00086
commit 170341db73
3 changed files with 16 additions and 9 deletions

View File

@@ -45,6 +45,7 @@ export type IWidget =
| IComboWidget
| ICustomWidget
| ISliderWidget
| IButtonWidget
export interface IBooleanWidget extends IBaseWidget {
type?: "toggle"
@@ -74,10 +75,16 @@ export type IStringWidgetType = IStringWidget["type"] | IMultilineStringWidget["
/** A widget with a string value */
export interface IStringWidget extends IBaseWidget {
type?: "string" | "text" | "button"
type?: "string" | "text"
value: string
}
export interface IButtonWidget extends IBaseWidget {
type?: "button"
value: undefined
clicked: boolean
}
/** A widget with a string value and a multiline text input */
export interface IMultilineStringWidget<TElement extends HTMLElement = HTMLTextAreaElement> extends
IBaseWidget {
@@ -117,7 +124,6 @@ export interface IBaseWidget<TElement extends HTMLElement = HTMLElement> {
options: IWidgetOptions
marker?: number
label?: string
clicked?: boolean
name?: string
/** Widget type (see {@link TWidgetType}) */
type?: TWidgetType

View File

@@ -1,19 +1,20 @@
import type { IStringWidget, IWidgetOptions } from "@/types/widgets"
import type { IButtonWidget, IWidgetOptions } from "@/types/widgets"
import { BaseWidget } from "./BaseWidget"
import type { LGraphNode } from "@/LGraphNode"
import type { CanvasMouseEvent } from "@/types/events"
import type { LGraphCanvas } from "@/LGraphCanvas"
export class ButtonWidget extends BaseWidget implements IStringWidget {
// IStringWidget properties
export class ButtonWidget extends BaseWidget implements IButtonWidget {
// IButtonWidget properties
declare type: "button"
declare value: string
declare options: IWidgetOptions<boolean>
declare clicked: boolean
declare value: undefined
constructor(widget: IStringWidget) {
constructor(widget: IButtonWidget) {
super(widget)
this.type = "button"
this.value = widget.value ?? ""
this.clicked = widget.clicked ?? false
}
/**

View File

@@ -12,7 +12,7 @@ export class TextWidget extends BaseWidget implements IStringWidget {
constructor(widget: IStringWidget) {
super(widget)
this.type = widget.type as "text" | "string"
this.type = widget.type ?? "string"
this.value = widget.value?.toString() ?? ""
}