added dropdown
This commit is contained in:
parent
19af1e1996
commit
04c96b6868
3 changed files with 44 additions and 32 deletions
|
|
@ -9,6 +9,7 @@ import TextAreaComponent from "../../../../components/textAreaComponent";
|
||||||
import { typesContext } from "../../../../contexts/typesContext";
|
import { typesContext } from "../../../../contexts/typesContext";
|
||||||
import { ParameterComponentType } from "../../../../types/components";
|
import { ParameterComponentType } from "../../../../types/components";
|
||||||
import FloatComponent from "../../../../components/floatComponent";
|
import FloatComponent from "../../../../components/floatComponent";
|
||||||
|
import Dropdown from "../../../../components/dropdownComponent";
|
||||||
|
|
||||||
export default function ParameterComponent({
|
export default function ParameterComponent({
|
||||||
left,
|
left,
|
||||||
|
|
@ -38,6 +39,7 @@ export default function ParameterComponent({
|
||||||
const [enabled, setEnabled] = useState(
|
const [enabled, setEnabled] = useState(
|
||||||
data.node.template[name]?.value ?? false
|
data.node.template[name]?.value ?? false
|
||||||
);
|
);
|
||||||
|
console.log(data.node.template[name]);
|
||||||
const { reactFlowInstance } = useContext(typesContext);
|
const { reactFlowInstance } = useContext(typesContext);
|
||||||
let disabled =
|
let disabled =
|
||||||
reactFlowInstance?.getEdges().some((e) => e.targetHandle === id) ?? false;
|
reactFlowInstance?.getEdges().some((e) => e.targetHandle === id) ?? false;
|
||||||
|
|
@ -52,30 +54,32 @@ export default function ParameterComponent({
|
||||||
{title}
|
{title}
|
||||||
<span className="text-red-600">{required ? " *" : ""}</span>
|
<span className="text-red-600">{required ? " *" : ""}</span>
|
||||||
</div>
|
</div>
|
||||||
{left && (type === "str" || type === "bool" || type === "float") ?
|
{left && (type === "str" || type === "bool" || type === "float") ? (
|
||||||
<></>
|
<></>
|
||||||
:
|
) : (
|
||||||
<Tooltip title={tooltipTitle + (required ? " (required)" : "")}>
|
<Tooltip title={tooltipTitle + (required ? " (required)" : "")}>
|
||||||
<Handle
|
<Handle
|
||||||
type={left ? "target" : "source"}
|
type={left ? "target" : "source"}
|
||||||
position={left ? Position.Left : Position.Right}
|
position={left ? Position.Left : Position.Right}
|
||||||
id={id}
|
id={id}
|
||||||
isValidConnection={(connection) =>
|
isValidConnection={(connection) =>
|
||||||
isValidConnection(connection, reactFlowInstance)
|
isValidConnection(connection, reactFlowInstance)
|
||||||
}
|
}
|
||||||
className={classNames(
|
className={classNames(
|
||||||
left ? "-ml-0.5 " : "-mr-0.5 ",
|
left ? "-ml-0.5 " : "-mr-0.5 ",
|
||||||
"w-3 h-3 rounded-full border-2 bg-white dark:bg-gray-800"
|
"w-3 h-3 rounded-full border-2 bg-white dark:bg-gray-800"
|
||||||
)}
|
)}
|
||||||
style={{
|
style={{
|
||||||
borderColor: color,
|
borderColor: color,
|
||||||
top: position,
|
top: position,
|
||||||
}}
|
}}
|
||||||
></Handle>
|
></Handle>
|
||||||
</Tooltip>
|
</Tooltip>
|
||||||
}
|
)}
|
||||||
|
|
||||||
{left === true && type === "str" ? (
|
{left === true &&
|
||||||
|
type === "str" &&
|
||||||
|
!data.node.template[name].options ? (
|
||||||
<div className="mt-2 w-full">
|
<div className="mt-2 w-full">
|
||||||
{data.node.template[name].list ? (
|
{data.node.template[name].list ? (
|
||||||
<InputListComponent
|
<InputListComponent
|
||||||
|
|
@ -128,6 +132,14 @@ export default function ParameterComponent({
|
||||||
data.node.template[name].value = t;
|
data.node.template[name].value = t;
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
|
) : left === true &&
|
||||||
|
type === "str" &&
|
||||||
|
data.node.template[name].options ? (
|
||||||
|
<Dropdown
|
||||||
|
options={data.node.template[name].options}
|
||||||
|
onSelect={(newValue) => data.node.template[name].value=newValue}
|
||||||
|
value={data.node.template[name].value??"chose an option"}
|
||||||
|
></Dropdown>
|
||||||
) : (
|
) : (
|
||||||
<></>
|
<></>
|
||||||
)}
|
)}
|
||||||
|
|
|
||||||
|
|
@ -1,21 +1,22 @@
|
||||||
import { Listbox, Transition } from "@headlessui/react";
|
import { Listbox, Transition } from "@headlessui/react";
|
||||||
import { ChevronUpDownIcon, CheckIcon } from "@heroicons/react/24/outline";
|
import { ChevronUpDownIcon, CheckIcon } from "@heroicons/react/24/outline";
|
||||||
import { Fragment } from "react";
|
import { Fragment, useState } from "react";
|
||||||
import { DropDownComponentType } from "../../types/components";
|
import { DropDownComponentType } from "../../types/components";
|
||||||
import { classNames } from "../../utils";
|
import { classNames } from "../../utils";
|
||||||
|
|
||||||
export default function Dropdown({title, value, options, onSelect}:DropDownComponentType) {
|
export default function Dropdown({value, options, onSelect}:DropDownComponentType) {
|
||||||
|
let [internalValue,setInternalValue] = useState(value??"choose an option")
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<Listbox value={value} onChange={onSelect}>
|
<Listbox value={internalValue} onChange={(value)=>{
|
||||||
|
setInternalValue(value)
|
||||||
|
onSelect(value)
|
||||||
|
}}>
|
||||||
{({ open }) => (
|
{({ open }) => (
|
||||||
<>
|
<>
|
||||||
<Listbox.Label className="block text-sm font-medium text-gray-700">
|
|
||||||
{title}
|
|
||||||
</Listbox.Label>
|
|
||||||
<div className="relative mt-1">
|
<div className="relative mt-1">
|
||||||
<Listbox.Button className="relative w-full cursor-default rounded-md border border-gray-300 bg-white py-2 pl-3 pr-10 text-left shadow-sm focus:border-indigo-500 focus:outline-none focus:ring-1 focus:ring-indigo-500 sm:text-sm">
|
<Listbox.Button className="relative w-full cursor-default rounded-md border border-gray-300 bg-white py-2 pl-3 pr-10 text-left shadow-sm focus:border-indigo-500 focus:outline-none focus:ring-1 focus:ring-indigo-500 sm:text-sm">
|
||||||
<span className="block truncate">{value}</span>
|
<span className="block w-max truncate">{internalValue}</span>
|
||||||
<span className="pointer-events-none absolute inset-y-0 right-0 flex items-center pr-2">
|
<span className="pointer-events-none absolute inset-y-0 right-0 flex items-center pr-2">
|
||||||
<ChevronUpDownIcon
|
<ChevronUpDownIcon
|
||||||
className="h-5 w-5 text-gray-400"
|
className="h-5 w-5 text-gray-400"
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,6 @@ export type ToggleComponentType = {
|
||||||
disabled: boolean;
|
disabled: boolean;
|
||||||
};
|
};
|
||||||
export type DropDownComponentType = {
|
export type DropDownComponentType = {
|
||||||
title: string;
|
|
||||||
value: string;
|
value: string;
|
||||||
options: string[];
|
options: string[];
|
||||||
onSelect: (value: string) => void;
|
onSelect: (value: string) => void;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue