diff --git a/src/frontend/src/components/inputComponent/index.tsx b/src/frontend/src/components/inputComponent/index.tsx index 8017c5458..a91d0a40d 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 && (