'use client' import { useState } from 'react' import { Eye, Pencil } from 'lucide-react' import { FieldWrapper } from './shared' import MarkdownRender from '@components/markdownrender/markdownRender' export type TextareaProps = Omit, 'name'> & { name: string label?: string error?: string className?: string info?: string description?: string type?: 'markdown' | 'json' | 'text' textSize?: 'sm' | 'md' } function isValidJson(str: string): string | null { try { JSON.parse(str) return null } catch(error) { return (error as Error).message } } export default function Textarea(props: TextareaProps) { const { name, label, error, className, info, description, type = 'text', rows = 4, textSize = 'sm', ...textareaProps } = props const { value } = textareaProps const [preview, setPreview] = useState(false) const jsonError = type === 'json' && value ? isValidJson(value as string) : undefined const displayError = jsonError || error return (
{type === 'markdown' && (
)} {type === 'markdown' && preview && (
)}