import React, { useRef } from 'react'; import styled, { css } from 'styled-components'; import type { JSX } from 'react'; import { useOutsideClick, useThemeHooks } from '@redocly/theme/core/hooks'; import { RadioCheckButtonIcon } from '@redocly/theme/icons/RadioCheckButtonIcon/RadioCheckButtonIcon'; import { Button } from '@redocly/theme/components/Button/Button'; import { MAX_CONTEXT_LENGTH } from '@redocly/theme/core/constants'; export type CommentProps = { onSubmit: (value: { comment: string }) => void; onCancel?: () => unknown; settings?: { label?: string; submitText?: string; }; standAlone?: boolean; isDialog?: boolean; className?: string; }; export function Comment({ settings, onSubmit, onCancel, className, standAlone = true, isDialog = false, }: CommentProps): JSX.Element { const { useTranslate } = useThemeHooks(); const { translate } = useTranslate(); const { label, submitText } = settings || {}; const [text, setText] = React.useState(''); const [submitValue, setSubmitValue] = React.useState(''); const [isMaxLengthReached, setIsMaxLengthReached] = React.useState(false); const modalRef = useRef(null); useOutsideClick(modalRef, onCancel); const send = () => { const trimmedText = text.trim(); if (!trimmedText) return; setSubmitValue(trimmedText); onSubmit({ comment: trimmedText }); }; const handleTextAreaChange = (e: React.ChangeEvent) => { const commentValue = e.target.value; setText(commentValue); setIsMaxLengthReached(commentValue.length >= MAX_CONTEXT_LENGTH); if (!standAlone) { onSubmit({ comment: commentValue }); } }; if (submitValue) { return ( ); } return (