Skip to content

AutoGPT is the vision of accessible AI for everyone, to use and to build on. Our mission is to provide the tools, so that you can focus on what matters.

feat(frontend): add expandable text input modal for better editing experience (#11510)

Abhimanyu Yadavf6608e99c811
diff --git a/autogpt_platform/frontend/src/components/renderers/input-renderer/widgets/TextInputWidget/InputExpanderModal.tsx b/autogpt_platform/frontend/src/components/renderers/input-renderer/widgets/TextInputWidget/InputExpanderModal.tsx
new file mode 100644
index 0000000000..5b19874bfb
--- /dev/null
+++ b/autogpt_platform/frontend/src/components/renderers/input-renderer/widgets/TextInputWidget/InputExpanderModal.tsx
@@ -0,0 +1,118 @@
+"use client";
+
+import React, { FC, useEffect, useState } from "react";
+import { Button } from "@/components/atoms/Button/Button";
+import { Text } from "@/components/atoms/Text/Text";
+import { useToast } from "@/components/molecules/Toast/use-toast";
+import { CheckIcon, CopyIcon } from "@phosphor-icons/react";
+import { Dialog } from "@/components/molecules/Dialog/Dialog";
+import { cn } from "@/lib/utils";
+import { Input } from "@/components/atoms/Input/Input";
+
+interface InputExpanderModalProps {
+ isOpen: boolean;
+ onClose: () => void;
+ onSave: (value: string) => void;
+ title?: string;
+ defaultValue: string;
+ description?: string;
+ placeholder?: string;
+}
+
+export const InputExpanderModal: FC<InputExpanderModalProps> = ({
+ isOpen,
+ onClose,
+ onSave,
+ title,
+ defaultValue,
+ description,
+ placeholder,
+}) => {
+ const [tempValue, setTempValue] = useState(defaultValue);
+ const [isCopied, setIsCopied] = useState(false);
+ const { toast } = useToast();
+
+ useEffect(() => {
+ if (isOpen) {
+ setTempValue(defaultValue);
+ setIsCopied(false);
+ }
+ }, [isOpen, defaultValue]);
+
+ const handleSave = () => {
+ onSave(tempValue);
+ onClose();
+ };
+
+ const copyValue = () => {
+ navigator.clipboard.writeText(tempValue).then(() => {
+ setIsCopied(true);
+ toast({
+ title: "Copied to clipboard!",
+ duration: 2000,
+ });
+ setTimeout(() => setIsCopied(false), 2000);
+ });
+ };
+
+ return (
+ <Dialog
+ controlled={{
+ isOpen,
+ set: async (open) => {
+ if (!open) onClose();
+ },
+ }}
+ onClose={onClose}
+ styling={{ maxWidth: "600px", minWidth: "600px" }}
+ >
+ <Dialog.Content>
+ <div className="flex flex-col gap-4 px-1">
+ <Text variant="h4" className="text-slate-900">
+ {title || "Edit Text"}
+ </Text>
+ <Text variant="body">{description}</Text>
+ <Input
+ type="textarea"
+ label=""
+ hideLabel
+ id="input-expander-modal"
+ value={tempValue}
+ className="!min-h-[300px] rounded-2xlarge"
+ onChange={(e) => setTempValue(e.target.value)}
+ placeholder={placeholder || "Enter text..."}
+ autoFocus
+ />
+
+ <div className="flex items-center justify-end gap-1">
+ <Button
+ variant="secondary"
+ size="small"
+ onClick={copyValue}
+ className={cn(
+ "h-fit min-w-0 gap-1.5 border border-zinc-200 p-2 text-black hover:text-slate-900",
+ isCopied &&
+ "border-green-400 bg-green-100 hover:border-green-400 hover:bg-green-200",
+ )}
+ >
+ {isCopied ? (
+ <CheckIcon size={16} className="text-green-600" />
+ ) : (
+ <CopyIcon size={16} />
+ )}
+ </Button>
+ </div>
+
+ <Dialog.Footer>
+ <Button variant="secondary" size="small" onClick={onClose}>
+ Cancel
+ </Button>
+ <Button variant="primary" size="small" onClick={handleSave}>
+ Save
+ </Button>
+ </Dialog.Footer>
+ </div>
+ </Dialog.Content>
+ </Dialog>
+ );
+};
diff --git a/autogpt_platform/frontend/src/components/renderers/input-renderer/widgets/TextInputWidget.tsx b/autogpt_platform/frontend/src/components/renderers/input-renderer/widgets/TextInputWidget/TextInputWidget.tsx
similarity index 52%
rename from autogpt_platform/frontend/src/components/renderers/input-renderer/widgets/TextInputWidget.tsx
rename to autogpt_platform/frontend/src/components/renderers/input-renderer/widgets/TextInputWidget/TextInputWidget.tsx
index e10b09bcf9..d9fea28a8d 100644
--- a/autogpt_platform/frontend/src/components/renderers/input-renderer/widgets/TextInputWidget.tsx
+++ b/autogpt_platform/frontend/src/components/renderers/input-renderer/widgets/TextInputWidget/TextInputWidget.tsx
@@ -1,10 +1,21 @@
+"use client";
+
+import { useState } from "react";
import { WidgetProps } from "@rjsf/utils";
import {
InputType,
mapJsonSchemaTypeToInputType,
} from "@/app/(platform)/build/components/FlowEditor/nodes/helpers";
import { Input } from "@/components/atoms/Input/Input";
+import { Button } from "@/components/atoms/Button/Button";
+import {
+ Tooltip,
+ TooltipContent,
+ TooltipTrigger,
+} from "@/components/atoms/Tooltip/BaseTooltip";
import { BlockUIType } from "@/lib/autogpt-server-api/types";
+import { InputExpanderModal } from "./InputExpanderModal";
+import { ArrowsOutIcon } from "@phosphor-icons/react";
export const TextInputWidget = (props: WidgetProps) => {
const { schema, formContext } = props;
@@ -13,6 +24,8 @@ export const TextInputWidget = (props: WidgetProps) => {
size?: string;
};
+ const [isModalOpen, setIsModalOpen] = useState(false);
+
const mapped = mapJsonSchemaTypeToInputType(schema);
type InputConfig = {
@@ -59,9 +72,25 @@ export const TextInputWidget = (props: WidgetProps) => {
return props.onChange(config.handleChange(v));
};
+ const handleModalSave = (value: string) => {
+ props.onChange(config.handleChange(value));
+ setIsModalOpen(false);
+ };
+
+ const handleModalOpen = () => {
+ setIsModalOpen(true);
+ };
+
// Determine input size based on context
const inputSize = size === "large" ? "medium" : "small";
+ // Check if this input type should show the expand button
+ // Show for text and password types, not for number/integer
+ const showExpandButton =
+ config.htmlType === "text" ||
+ config.htmlType === "password" ||
+ config.htmlType === "textarea";
+
if (uiType === BlockUIType.NOTE) {
return (
<Input
@@ -82,18 +111,49 @@ export const TextInputWidget = (props: WidgetProps) => {
}
return (
- <Input
- id={props.id}
- hideLabel={true}
- type={config.htmlType as any}
- label={""}
- size={inputSize as any}
- wrapperClassName="mb-0"
- value={props.value ?? ""}
- onChange={handleChange}
- placeholder={schema.placeholder || config.placeholder}
- required={props.required}
- disabled={props.disabled}
- />
+ <>
+ <div className="nodrag relative flex items-center gap-2">
+ <Input
+ id={props.id}
+ hideLabel={true}
+ type={config.htmlType as any}
+ label={""}
+ size={inputSize as any}
+ wrapperClassName="mb-0 flex-1"
+ value={props.value ?? ""}
+ onChange={handleChange}
+ placeholder={schema.placeholder || config.placeholder}
+ required={props.required}
+ disabled={props.disabled}
+ className={showExpandButton ? "pr-8" : ""}
+ />
+ {showExpandButton && (
+ <Tooltip delayDuration={0}>
+ <TooltipTrigger asChild>
+ <Button
+ variant="ghost"
+ size="icon"
+ onClick={handleModalOpen}
+ type="button"
+ className="p-1"
+ >
+ <ArrowsOutIcon className="size-4" />
+ </Button>
+ </TooltipTrigger>
+ <TooltipContent>Expand input</TooltipContent>
+ </Tooltip>
+ )}
+ </div>
+
+ <InputExpanderModal
+ isOpen={isModalOpen}
+ onClose={() => setIsModalOpen(false)}
+ onSave={handleModalSave}
+ title={schema.title || "Edit value"}
+ description={schema.description || ""}
+ defaultValue={props.value ?? ""}
+ placeholder={schema.placeholder || config.placeholder}
+ />
+ </>
);
};
diff --git a/autogpt_platform/frontend/src/components/renderers/input-renderer/widgets/index.ts b/autogpt_platform/frontend/src/components/renderers/input-renderer/widgets/index.ts
index cdb02c728c..3788e74fbf 100644
--- a/autogpt_platform/frontend/src/components/renderers/input-renderer/widgets/index.ts
+++ b/autogpt_platform/frontend/src/components/renderers/input-renderer/widgets/index.ts
@@ -1,6 +1,6 @@
import { RegistryWidgetsType } from "@rjsf/utils";
import { SelectWidget } from "./SelectWidget";
-import { TextInputWidget } from "./TextInputWidget";
+import { TextInputWidget } from "./TextInputWidget/TextInputWidget";
import { SwitchWidget } from "./SwitchWidget";
import { FileWidget } from "./FileWidget";
import { DateInputWidget } from "./DateInputWidget";