From 3b170ec19ed8d3bb9eb69676c3f3d135258d8dfe Mon Sep 17 00:00:00 2001 From: space-nuko <24979496+space-nuko@users.noreply.github.com> Date: Sat, 6 May 2023 15:57:35 -0500 Subject: [PATCH] Button options --- src/lib/components/BlockContainer.svelte | 2 ++ src/lib/stores/layoutState.ts | 40 +++++++++++++++++++----- src/lib/widgets/ButtonWidget.svelte | 29 +++++++++-------- 3 files changed, 51 insertions(+), 20 deletions(-) diff --git a/src/lib/components/BlockContainer.svelte b/src/lib/components/BlockContainer.svelte index a593c94..bdfd08f 100644 --- a/src/lib/components/BlockContainer.svelte +++ b/src/lib/components/BlockContainer.svelte @@ -42,6 +42,8 @@ children = layoutState.updateChildren(container, evt.detail.items) // Ensure dragging is stopped on drag finish }; + + const tt = "asd\nasdlkj" {#if container && children} diff --git a/src/lib/stores/layoutState.ts b/src/lib/stores/layoutState.ts index c0f09b8..4e6a204 100644 --- a/src/lib/stores/layoutState.ts +++ b/src/lib/stores/layoutState.ts @@ -93,10 +93,7 @@ export type LayoutState = { } /** - * Attributes for both containers and nodes, or containers only. - * If the attribute can be applicable to both, then it should go here. - * If it only applies to a container it should go here too. - * If it only applies to a node it should be placed in its LGraphNode.properties (nodeProps) instead. + * Attributes for both containers and nodes. **/ export type Attributes = { /* @@ -134,6 +131,11 @@ export type Attributes = { */ disabled?: boolean, + /* + * CSS height + */ + height?: string, + /* * CSS Flex grow */ @@ -145,12 +147,16 @@ export type Attributes = { */ variant?: string, - /*************************************/ - /* Special attributes for containers */ - /*************************************/ + /*********************************************/ + /* Special attributes for widgets/containers */ + /*********************************************/ // Accordion openOnStartup?: boolean + + // Button + buttonVariant?: "primary" | "secondary", + buttonSize?: "large" | "small" } export type AttributesSpec = { @@ -330,6 +336,26 @@ const ALL_ATTRIBUTES: AttributesSpecList = [ defaultValue: false, canShow: (di: IDragItem) => di.type === "container" && di.attrs.variant === "accordion" }, + + // Button + { + name: "buttonVariant", + type: "enum", + location: "widget", + editable: true, + validNodeTypes: ["ui/button"], + values: ["primary", "secondary"], + defaultValue: "primary" + }, + { + name: "buttonSize", + type: "enum", + location: "widget", + editable: true, + validNodeTypes: ["ui/button"], + values: ["large", "small"], + defaultValue: "large" + }, ] }, { diff --git a/src/lib/widgets/ButtonWidget.svelte b/src/lib/widgets/ButtonWidget.svelte index d1c6c6d..d912e8d 100644 --- a/src/lib/widgets/ButtonWidget.svelte +++ b/src/lib/widgets/ButtonWidget.svelte @@ -3,11 +3,11 @@ import type { ComfySliderNode } from "$lib/nodes/index"; import { type WidgetLayout } from "$lib/stores/layoutState"; import { Button } from "@gradio/button"; - import { get, type Writable } from "svelte/store"; + import { get, type Writable, writable } from "svelte/store"; export let widget: WidgetLayout | null = null; let node: ComfyButtonNode | null = null; let nodeValue: Writable | null = null; - let propsChanged: Writable | null = null; + let attrsChanged: Writable | null = null; $: widget && setNodeValue(widget); @@ -15,7 +15,7 @@ if (widget) { node = widget.node as ComfyButtonNode nodeValue = node.value; - propsChanged = node.propsChanged; + attrsChanged = widget.attrsChanged; } }; @@ -24,20 +24,23 @@ } const style = { - full_width: "100%" + full_width: "100%", }
- {#if node !== null} - - {/if} + {#key $attrsChanged} + {#if node !== null} + + {/if} + {/key}