[Refactor] useBooleanWidget composable (#2516)

This commit is contained in:
Chenlei Hu
2025-02-11 11:05:58 -05:00
committed by GitHub
parent ab305059bc
commit cfa46ebacb
2 changed files with 27 additions and 12 deletions

View File

@@ -0,0 +1,25 @@
import type { LGraphNode } from '@comfyorg/litegraph'
import type { ComfyWidgetConstructor } from '@/scripts/widgets'
import type { InputSpec } from '@/types/apiTypes'
export const useBooleanWidget = () => {
const widgetConstructor: ComfyWidgetConstructor = (
node: LGraphNode,
inputName: string,
inputData: InputSpec
) => {
const inputOptions = inputData[1]
const defaultVal = inputOptions?.default ?? false
const options = {
on: inputOptions?.label_on,
off: inputOptions?.label_off
}
return {
widget: node.addWidget('toggle', inputName, defaultVal, () => {}, options)
}
}
return widgetConstructor
}