import clsx from "clsx" import React, { useImperativeHandle, useRef } from "react" import InputError from "../../atoms/input-error" import InputHeader from "../../fundamentals/input-header" import EmojiPicker from "../emoji-picker" type TextareaProps = React.ComponentPropsWithRef<"textarea"> & { errors?: { [x: string]: unknown } label: string key?: string enableEmoji?: boolean withTooltip?: boolean tooltipText?: string tooltipProps?: any children?: React.ReactNode containerProps?: React.HTMLAttributes } const TextArea = React.forwardRef( ( { placeholder, label, name, key, required, withTooltip = false, tooltipText, tooltipProps = {}, containerProps, className, enableEmoji = false, rows = 2, children, errors, ...props }: TextareaProps, ref ) => { const inputRef = useRef(null) useImperativeHandle( ref, () => inputRef.current ) const scrollToTop = () => { if (inputRef.current) { inputRef.current.scrollTop = 0 } } const handleAddEmoji = (emoji: string) => { if (!inputRef.current) { return } const position = inputRef.current.selectionStart || 0 const newValue = `${inputRef.current?.value.substring( 0, position )}${emoji}${inputRef.current?.value.substring(position)}` inputRef.current.value = newValue } return (
{label && ( )}