So `_Upload` becomes `UploadComponent` which doesnt break the naming convention of react components and **we no longer export these internal components**
106 lines
2.8 KiB
TypeScript
106 lines
2.8 KiB
TypeScript
'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<TextareaFieldProps> = (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<string>({
|
|
path: pathFromContext ?? pathFromProps ?? name,
|
|
validate: memoizedValidate,
|
|
})
|
|
|
|
const disabled = readOnlyFromProps || readOnlyFromContext || formProcessing || formInitializing
|
|
|
|
return (
|
|
<TextareaInput
|
|
AfterInput={AfterInput}
|
|
BeforeInput={BeforeInput}
|
|
CustomDescription={CustomDescription}
|
|
CustomError={CustomError}
|
|
CustomLabel={CustomLabel}
|
|
className={className}
|
|
descriptionProps={descriptionProps}
|
|
errorProps={errorProps}
|
|
label={label}
|
|
labelProps={labelProps}
|
|
onChange={(e) => {
|
|
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)
|