mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-03-12 08:30:08 +00:00
[Refactor] useBooleanWidget composable (#2516)
This commit is contained in:
25
src/composables/widgets/useBooleanWidget.ts
Normal file
25
src/composables/widgets/useBooleanWidget.ts
Normal 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
|
||||
}
|
||||
Reference in New Issue
Block a user