From 86ccae87fb4e59f8ff3e8f9c6bf4c1ee6811d0f3 Mon Sep 17 00:00:00 2001 From: igorrCarvalho Date: Mon, 5 Feb 2024 11:42:08 -0300 Subject: [PATCH 01/83] Feat: make text input capable of support dropdown inputs also --- .../src/components/inputComponent/index.tsx | 169 +++++++++++++++--- src/frontend/src/style/applies.css | 2 +- src/frontend/src/types/components/index.ts | 1 + 3 files changed, 142 insertions(+), 30 deletions(-) diff --git a/src/frontend/src/components/inputComponent/index.tsx b/src/frontend/src/components/inputComponent/index.tsx index 8017c5458f..a91d0a40d2 100644 --- a/src/frontend/src/components/inputComponent/index.tsx +++ b/src/frontend/src/components/inputComponent/index.tsx @@ -1,8 +1,10 @@ +import { Listbox, Transition } from "@headlessui/react"; import * as Form from "@radix-ui/react-form"; -import { useEffect, useRef, useState } from "react"; +import { Fragment, useEffect, useRef, useState } from "react"; import { InputComponentType } from "../../types/components"; import { handleKeyDown } from "../../utils/reactflowUtils"; import { classNames } from "../../utils/utils"; +import IconComponent from "../genericIconComponent"; import { Input } from "../ui/input"; export default function InputComponent({ @@ -19,9 +21,11 @@ export default function InputComponent({ className, id = "", blurOnEnter = false, + options = [], }: InputComponentType): JSX.Element { const [pwdVisible, setPwdVisible] = useState(false); const refInput = useRef(null); + const [showOptions, setShowOptions] = useState(false); // Clear component state useEffect(() => { if (disabled && value !== "") { @@ -29,6 +33,11 @@ export default function InputComponent({ } }, [disabled]); + function onInputLostFocus(event): void { + if (onBlur) onBlur(event); + setShowOptions(false); + } + return (
{isForm ? ( @@ -36,7 +45,7 @@ export default function InputComponent({ ) : ( - { - onChange(e.target.value); - }} - onKeyDown={(e) => { - handleKeyDown(e, value, ""); - if (blurOnEnter && e.key === "Enter") refInput.current?.blur(); - }} - /> + <> + setShowOptions(false)} + value={value} + autoFocus={autoFocus} + disabled={disabled} + required={required} + className={classNames( + password && !pwdVisible && value !== "" + ? " text-clip password " + : "", + editNode ? " input-edit-node " : "", + password && editNode ? "pr-8" : "", + password && !editNode ? "pr-10" : "", + className! + )} + placeholder={password && editNode ? "Key" : placeholder} + onChange={(e) => { + onChange(e.target.value); + setShowOptions(false); + }} + onKeyDown={(e) => { + handleKeyDown(e, value, ""); + if (blurOnEnter && e.key === "Enter") refInput.current?.blur(); + }} + onFocus={() => setShowOptions(true)} + /> + { + /* options.length > 0 */ true ? ( + { + onChange(val); + }} + > + <> +
+ + + {["key", "key2", "key3", "key4", "key5"].map( + (option, id) => ( + + classNames( + active ? " bg-accent" : "", + editNode + ? "dropdown-component-false-option" + : "dropdown-component-true-option", + " hover:bg-accent" + ) + } + value={option} + > + {({ selected, active }) => ( + <> + + {option} + + + {selected ? ( + + + ) : null} + + )} + + ) + )} + + +
+ +
+ ) : null + } + )} + + + + {password && ( + + +
+
+ + +
+
+ +