mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-02-09 17:40:09 +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
|
||||
}
|
||||
@@ -3,6 +3,7 @@ import type { LGraphNode } from '@comfyorg/litegraph'
|
||||
import type { IWidget } from '@comfyorg/litegraph'
|
||||
import type { IComboWidget } from '@comfyorg/litegraph/dist/types/widgets'
|
||||
|
||||
import { useBooleanWidget } from '@/composables/widgets/useBooleanWidget'
|
||||
import { useFloatWidget } from '@/composables/widgets/useFloatWidget'
|
||||
import { useImageUploadWidget } from '@/composables/widgets/useImageUploadWidget'
|
||||
import { useIntWidget } from '@/composables/widgets/useIntWidget'
|
||||
@@ -251,18 +252,7 @@ export const ComfyWidgets: Record<string, ComfyWidgetConstructor> = {
|
||||
'INT:noise_seed': SeedWidget,
|
||||
INT: useIntWidget(),
|
||||
FLOAT: useFloatWidget(),
|
||||
BOOLEAN(node, inputName, inputData) {
|
||||
let defaultVal = false
|
||||
let options = {}
|
||||
if (inputData[1]) {
|
||||
if (inputData[1].default) defaultVal = inputData[1].default
|
||||
if (inputData[1].label_on) options['on'] = inputData[1].label_on
|
||||
if (inputData[1].label_off) options['off'] = inputData[1].label_off
|
||||
}
|
||||
return {
|
||||
widget: node.addWidget('toggle', inputName, defaultVal, () => {}, options)
|
||||
}
|
||||
},
|
||||
BOOLEAN: useBooleanWidget(),
|
||||
STRING: useStringWidget(),
|
||||
MARKDOWN: useMarkdownWidget(),
|
||||
COMBO(node, inputName, inputData: InputSpec) {
|
||||
|
||||
Reference in New Issue
Block a user