mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-03-11 08:00:21 +00:00
* lint: turn on type import rules setting up for verbatimModuleSyntax * lint: --fix for type imports
34 lines
774 B
TypeScript
34 lines
774 B
TypeScript
import type { LGraphNode } from '@/lib/litegraph/src/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
|
|
}
|