diff --git a/packages/design-system/src/components/ai-input/autogrow-text-area.stories.tsx b/packages/design-system/src/components/ai-input/autogrow-text-area.stories.tsx new file mode 100644 index 0000000000..b2354272fb --- /dev/null +++ b/packages/design-system/src/components/ai-input/autogrow-text-area.stories.tsx @@ -0,0 +1,52 @@ +import { AutogrowTextArea } from "./autogrow-text-area"; +import { Box } from "../box"; +import { Grid } from "../grid"; +import { ScrollArea } from "../scroll-area"; +import { StorySection, StoryGrid } from "../storybook"; + +export default { + title: "Library/Autogrow Text Area", +}; + +export const Demo = () => { + return ( + <> + + + + + + + + + + + + + + + + + + + + + + + + + + + ); +}; +Demo.storyName = "Autogrow Text Area"; diff --git a/packages/design-system/src/components/ai-input/autogrow-text-area.tsx b/packages/design-system/src/components/ai-input/autogrow-text-area.tsx new file mode 100644 index 0000000000..baee1a5e36 --- /dev/null +++ b/packages/design-system/src/components/ai-input/autogrow-text-area.tsx @@ -0,0 +1,97 @@ +/** + * Implementation of the autogrowing text input for the AI + * https://www.figma.com/file/xCBegXEWxROLqA1Y31z2Xo/%F0%9F%93%96-Webstudio-Design-Docs?node-id=7586%3A48784&mode=dev + */ + +import { type ComponentProps, type Ref, forwardRef } from "react"; +import { type CSS, css, theme } from "../../stitches.config"; +import { textVariants } from "../text"; +import { Grid } from "../grid"; +import { useControllableState } from "@radix-ui/react-use-controllable-state"; + +const commonStyle = css(textVariants.regular, { + border: "none", + paddingRight: 0, + paddingLeft: 0, + paddingTop: 0, + paddingBottom: 0, + boxSizing: "border-box", + gridArea: "1 / 1 / 2 / 2", + background: "transparent", + color: "inherit", + textWrap: "wrap", + overflowWrap: "break-word", + whiteSpace: "pre-wrap", + overflow: "hidden", +}); + +const style = css(commonStyle, { + outline: "none", + resize: "none", + "&::placeholder": { + color: theme.colors.foregroundContrastSubtle, + }, + "&:disabled": { + color: theme.colors.foregroundDisabled, + background: theme.colors.backgroundInputDisabled, + }, + variants: { + state: { + invalid: { + color: theme.colors.foregroundDestructive, + }, + }, + }, +}); + +type Props = Omit< + ComponentProps<"textarea">, + "value" | "defaultValue" | "onChange" +> & { + css?: CSS; + state?: "invalid"; + value?: string; + defaultValue?: string; + onChange?: (value: string) => void; +}; + +export const AutogrowTextArea = forwardRef( + ( + { css, className, state, value, defaultValue, onChange, ...props }: Props, + ref: Ref + ) => { + // use + const [textValue, setTextValue] = useControllableState({ + prop: value, + defaultProp: defaultValue, + onChange, + }); + + return ( + +
+ {textValue}{" "} +
+