Skip to content

Commit 7367a81

Browse files
karooolisfrolic
andauthored
feat(explorer): textarea string fields (#3746)
Co-authored-by: Kevin Ingersoll <kingersoll@gmail.com>
1 parent a85caf4 commit 7367a81

3 files changed

Lines changed: 55 additions & 5 deletions

File tree

.changeset/tame-gorillas-draw.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@latticexyz/explorer": patch
3+
---
4+
5+
String fields in the "Interact" tab now support multiline values.

packages/explorer/src/app/(explorer)/[chainName]/worlds/[worldAddress]/interact/content/FunctionInput.tsx

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { useCallback, useEffect } from "react";
44
import { useFormContext } from "react-hook-form";
55
import { FormControl, FormField, FormItem, FormLabel, FormMessage } from "../../../../../../../components/ui/Form";
66
import { Input } from "../../../../../../../components/ui/Input";
7+
import { Textarea } from "../../../../../../../components/ui/Textarea";
78
import { useEnsAddress } from "./useEnsAddress";
89

910
type Props = {
@@ -23,6 +24,21 @@ const getInputPlaceholder = (input: AbiParameter): string => {
2324
return `[${componentsString}]`;
2425
};
2526

27+
type TextFieldProps = {
28+
fieldType: string;
29+
className?: string;
30+
placeholder?: string;
31+
value?: string;
32+
onChange?: (evt: React.ChangeEvent<HTMLInputElement | HTMLTextAreaElement>) => void;
33+
};
34+
35+
function TextField({ fieldType, ...props }: TextFieldProps) {
36+
if (fieldType === "string") {
37+
return <Textarea {...props} />;
38+
}
39+
return <Input {...props} />;
40+
}
41+
2642
export function FunctionInput({ input, index }: Props) {
2743
const form = useFormContext();
2844
const currentValue = form.watch(`inputs.${index}`);
@@ -60,15 +76,18 @@ export function FunctionInput({ input, index }: Props) {
6076
name={`inputs.${index}`}
6177
render={({ field }) => (
6278
<FormItem className="flex flex-col gap-2">
63-
<div className="flex items-start gap-4">
64-
{input.name && <FormLabel className="shrink-0 pt-2 font-mono text-sm opacity-70">{input.name}</FormLabel>}
79+
<div className="flex items-center gap-4">
80+
{input.name && <FormLabel className="shrink-0 font-mono text-sm opacity-70">{input.name}</FormLabel>}
6581
<div className="flex-1">
6682
<FormControl>
67-
<Input
83+
<TextField
84+
className="font-mono text-sm"
6885
placeholder={getInputPlaceholder(input)}
86+
fieldType={input.type}
6987
value={field.value}
70-
onChange={(evt) => handleChange(evt.target.value)}
71-
className="font-mono text-sm"
88+
onChange={(evt: React.ChangeEvent<HTMLInputElement | HTMLTextAreaElement>) =>
89+
handleChange(evt.target.value)
90+
}
7291
/>
7392
</FormControl>
7493
<FormMessage />
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import * as React from "react";
2+
import { cn } from "../../utils";
3+
4+
const Textarea = React.forwardRef<HTMLTextAreaElement, React.ComponentProps<"textarea">>(
5+
({ className, ...props }, ref) => {
6+
return (
7+
<textarea
8+
className={cn(
9+
"flex min-h-[80px] w-full",
10+
"px-3 py-2",
11+
"rounded-md border border-input ring-offset-background focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2",
12+
"bg-background text-base",
13+
"text-base md:text-sm",
14+
"placeholder:text-muted-foreground disabled:cursor-not-allowed disabled:opacity-50",
15+
"focus-visible:outline-none",
16+
className,
17+
)}
18+
ref={ref}
19+
{...props}
20+
/>
21+
);
22+
},
23+
);
24+
Textarea.displayName = "Textarea";
25+
26+
export { Textarea };

0 commit comments

Comments
 (0)