'use client' import type { ClientValidate } from 'payload' import { getTranslation } from '@payloadcms/translations' import React, { useCallback } from 'react' import type { TextAreaInputProps, TextareaFieldProps } from './types.js' import { useFieldProps } from '../../forms/FieldPropsProvider/index.js' import { useField } from '../../forms/useField/index.js' import { withCondition } from '../../forms/withCondition/index.js' import { useConfig } from '../../providers/Config/index.js' import { useTranslation } from '../../providers/Translation/index.js' import { isFieldRTL } from '../shared/index.js' import { TextareaInput } from './Input.js' import './index.scss' export { TextAreaInputProps, TextareaFieldProps, TextareaInput } const TextareaFieldComponent: React.FC = (props) => { const { name, AfterInput, BeforeInput, CustomDescription, CustomError, CustomLabel, className, descriptionProps, errorProps, label, labelProps, locale, localized, maxLength, minLength, path: pathFromProps, placeholder, readOnly: readOnlyFromProps, required, rows, rtl, style, validate, width, } = props const { i18n } = useTranslation() const { localization } = useConfig() const isRTL = isFieldRTL({ fieldLocalized: localized, fieldRTL: rtl, locale, localizationConfig: localization || undefined, }) const memoizedValidate: ClientValidate = useCallback( (value, options) => { if (typeof validate === 'function') return validate(value, { ...options, maxLength, minLength, required }) }, [validate, required, maxLength, minLength], ) const { path: pathFromContext, readOnly: readOnlyFromContext } = useFieldProps() const { formInitializing, formProcessing, path, setValue, showError, value } = useField({ path: pathFromContext ?? pathFromProps ?? name, validate: memoizedValidate, }) const disabled = readOnlyFromProps || readOnlyFromContext || formProcessing || formInitializing return ( { setValue(e.target.value) }} path={path} placeholder={getTranslation(placeholder, i18n)} readOnly={disabled} required={required} rows={rows} rtl={isRTL} showError={showError} style={style} value={value} width={width} /> ) } export const TextareaField = withCondition(TextareaFieldComponent)