mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-02-02 22:37:32 +00:00
35 lines
765 B
TypeScript
35 lines
765 B
TypeScript
import type { LGraphNode } from '@comfyorg/litegraph'
|
|
|
|
import {
|
|
type InputSpec,
|
|
isBooleanInputSpec
|
|
} from '@/schemas/nodeDef/nodeDefSchemaV2'
|
|
import { type ComfyWidgetConstructorV2 } from '@/scripts/widgets'
|
|
|
|
export const useBooleanWidget = () => {
|
|
const widgetConstructor: ComfyWidgetConstructorV2 = (
|
|
node: LGraphNode,
|
|
inputSpec: InputSpec
|
|
) => {
|
|
if (!isBooleanInputSpec(inputSpec)) {
|
|
throw new Error(`Invalid input data: ${inputSpec}`)
|
|
}
|
|
|
|
const defaultVal = inputSpec.default ?? false
|
|
const options = {
|
|
on: inputSpec.label_on,
|
|
off: inputSpec.label_off
|
|
}
|
|
|
|
return node.addWidget(
|
|
'toggle',
|
|
inputSpec.name,
|
|
defaultVal,
|
|
() => {},
|
|
options
|
|
)
|
|
}
|
|
|
|
return widgetConstructor
|
|
}
|