Add AutoResizeTextArea (#7)
This commit is contained in:
24
src/components/AutoResizeTextArea.tsx
Normal file
24
src/components/AutoResizeTextArea.tsx
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
import { Textarea, type TextareaProps } from "@chakra-ui/react";
|
||||||
|
import ResizeTextarea from "react-textarea-autosize";
|
||||||
|
import React from "react";
|
||||||
|
|
||||||
|
export const AutoResizeTextarea: React.ForwardRefRenderFunction<
|
||||||
|
HTMLTextAreaElement,
|
||||||
|
TextareaProps
|
||||||
|
> = (props, ref) => {
|
||||||
|
return (
|
||||||
|
<Textarea
|
||||||
|
minH="unset"
|
||||||
|
overflow="hidden"
|
||||||
|
w="100%"
|
||||||
|
resize="none"
|
||||||
|
ref={ref}
|
||||||
|
minRows={1}
|
||||||
|
transition="height none"
|
||||||
|
as={ResizeTextarea}
|
||||||
|
{...props}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default React.forwardRef(AutoResizeTextarea);
|
||||||
@@ -4,12 +4,12 @@ import { isEqual } from "lodash";
|
|||||||
import { type Scenario } from "./types";
|
import { type Scenario } from "./types";
|
||||||
import { useExperiment, useHandledAsyncCallback } from "~/utils/hooks";
|
import { useExperiment, useHandledAsyncCallback } from "~/utils/hooks";
|
||||||
import { useState } from "react";
|
import { useState } from "react";
|
||||||
import ResizeTextarea from "react-textarea-autosize";
|
|
||||||
|
|
||||||
import { Box, Button, Flex, HStack, Icon, Stack, Textarea, Tooltip } from "@chakra-ui/react";
|
import { Box, Button, Flex, HStack, Icon, Stack, Tooltip } from "@chakra-ui/react";
|
||||||
import { cellPadding } from "../constants";
|
import { cellPadding } from "../constants";
|
||||||
import { BsX } from "react-icons/bs";
|
import { BsX } from "react-icons/bs";
|
||||||
import { RiDraggable } from "react-icons/ri";
|
import { RiDraggable } from "react-icons/ri";
|
||||||
|
import AutoResizeTextArea from "../AutoResizeTextArea";
|
||||||
|
|
||||||
export default function ScenarioEditor({
|
export default function ScenarioEditor({
|
||||||
scenario,
|
scenario,
|
||||||
@@ -132,7 +132,7 @@ export default function ScenarioEditor({
|
|||||||
<Box bgColor="blue.100" color="blue.600" px={2} my="3px" fontSize="xs" fontWeight="bold">
|
<Box bgColor="blue.100" color="blue.600" px={2} my="3px" fontSize="xs" fontWeight="bold">
|
||||||
{key}
|
{key}
|
||||||
</Box>
|
</Box>
|
||||||
<Textarea
|
<AutoResizeTextArea
|
||||||
px={2}
|
px={2}
|
||||||
py={1}
|
py={1}
|
||||||
placeholder="empty"
|
placeholder="empty"
|
||||||
@@ -150,9 +150,6 @@ export default function ScenarioEditor({
|
|||||||
}}
|
}}
|
||||||
resize="none"
|
resize="none"
|
||||||
overflow="hidden"
|
overflow="hidden"
|
||||||
minRows={1}
|
|
||||||
minH="unset"
|
|
||||||
as={ResizeTextarea}
|
|
||||||
flex={layoutDirection === "row" ? 1 : undefined}
|
flex={layoutDirection === "row" ? 1 : undefined}
|
||||||
borderColor={hasChanged ? "blue.300" : "transparent"}
|
borderColor={hasChanged ? "blue.300" : "transparent"}
|
||||||
_hover={{ borderColor: "gray.300" }}
|
_hover={{ borderColor: "gray.300" }}
|
||||||
|
|||||||
@@ -2,10 +2,11 @@ import { useState, type DragEvent } from "react";
|
|||||||
import { type PromptVariant } from "./types";
|
import { type PromptVariant } from "./types";
|
||||||
import { api } from "~/utils/api";
|
import { api } from "~/utils/api";
|
||||||
import { useHandledAsyncCallback } from "~/utils/hooks";
|
import { useHandledAsyncCallback } from "~/utils/hooks";
|
||||||
import { Button, HStack, Input, Icon, Tooltip } from "@chakra-ui/react"; // Changed here
|
import { Button, HStack, Icon, Tooltip } from "@chakra-ui/react"; // Changed here
|
||||||
import { BsX } from "react-icons/bs";
|
import { BsX } from "react-icons/bs";
|
||||||
import { RiDraggable } from "react-icons/ri";
|
import { RiDraggable } from "react-icons/ri";
|
||||||
import { cellPadding, headerMinHeight } from "../constants";
|
import { cellPadding, headerMinHeight } from "../constants";
|
||||||
|
import AutoResizeTextArea from "../AutoResizeTextArea";
|
||||||
|
|
||||||
export default function VariantHeader(props: { variant: PromptVariant }) {
|
export default function VariantHeader(props: { variant: PromptVariant }) {
|
||||||
const utils = api.useContext();
|
const utils = api.useContext();
|
||||||
@@ -76,11 +77,12 @@ export default function VariantHeader(props: { variant: PromptVariant }) {
|
|||||||
color="gray.400"
|
color="gray.400"
|
||||||
_hover={{ color: "gray.800", cursor: "pointer" }}
|
_hover={{ color: "gray.800", cursor: "pointer" }}
|
||||||
/>
|
/>
|
||||||
<Input // Changed to Input
|
<AutoResizeTextArea // Changed to Input
|
||||||
size="sm"
|
size="sm"
|
||||||
value={label}
|
value={label}
|
||||||
onChange={(e) => setLabel(e.target.value)}
|
onChange={(e) => setLabel(e.target.value)}
|
||||||
onBlur={onSaveLabel}
|
onBlur={onSaveLabel}
|
||||||
|
placeholder="Variant Name"
|
||||||
borderWidth={1}
|
borderWidth={1}
|
||||||
borderColor="transparent"
|
borderColor="transparent"
|
||||||
fontWeight="bold"
|
fontWeight="bold"
|
||||||
|
|||||||
Reference in New Issue
Block a user