'use client'; import * as React from 'react'; import { hasReactNode } from '@vkontakte/vkjs'; import { useMergeProps } from '../../hooks/useMergeProps'; import { warnOnce } from '../../lib/warnOnce'; import type { HasDataAttribute, HasRootRef } from '../../types'; import { WriteBarBeforeOrAfter } from './WriteBarBeforeOrAfter/WriteBarBeforeOrAfter'; import { WriteBarFormField } from './WriteBarFormField/WriteBarFormField'; import { WriteBarFormFieldInlineAfter } from './WriteBarFormField/WriteBarFormFieldInlineAfter/WriteBarFormFieldInlineAfter'; import { WriteBarRoot } from './WriteBarRoot/WriteBarRoot'; import { WriteBarTextarea } from './WriteBarTextarea/WriteBarTextarea'; const warn = warnOnce('WriteBar'); export interface WriteBarProps extends Pick< React.TextareaHTMLAttributes, | 'autoComplete' | 'autoCapitalize' | 'autoCorrect' | 'cols' | 'dirName' | 'disabled' | 'maxLength' | 'minLength' | 'name' | 'placeholder' | 'readOnly' | 'required' | 'rows' | 'value' | 'wrap' | 'form' | 'onChange' | 'onFocus' | 'onBlur' >, Omit, 'onChange' | 'onFocus' | 'onBlur'>, HasRootRef { /** * @deprecated Since 7.9.0. Вместо этого используйте `slotProps={ textArea: { getRootRef: ... } }`. */ getRef?: React.Ref | undefined; /** * Свойства, которые можно прокинуть внутрь компонента: * - `root`: свойства для прокидывания в корень компонента; * - `textArea`: свойства для прокидывания в поле ввода. */ slotProps?: | { root?: | (Omit, 'children'> & HasRootRef & HasDataAttribute) | undefined; textArea?: | (React.TextareaHTMLAttributes & HasRootRef & HasDataAttribute) | undefined; } | undefined; /** * Содержимое, отображаемое слева от поля ввода. */ before?: React.ReactNode | undefined; /** * Содержимое, отображаемое поверх поля ввода (актуально для iOS). */ inlineAfter?: React.ReactNode | undefined; /** * Содержимое, отображаемое справа от поля ввода. */ after?: React.ReactNode | undefined; /** * Вызывается при смене высоты поля ввода. */ onHeightChange?: VoidFunction | undefined; /** * Добавляет тень вокруг поля ввода. */ shadow?: boolean | undefined; /** * @deprecated Неиспользуемое свойство. */ children?: never | undefined; } /** * @see https://vkui.io/components/write-bar */ export const WriteBar = ({ // WriteBarProps before, inlineAfter, after, onHeightChange, shadow = false, getRef, // textarea props autoComplete, autoCapitalize, autoCorrect, cols, dirName, disabled, maxLength, minLength, name, placeholder, readOnly, required, value: valueProp, wrap, rows, form, onChange, onFocus, onBlur, id, inputMode, defaultValue, autoFocus, tabIndex, spellCheck, slotProps, ...restProps }: WriteBarProps): React.ReactNode => { /* istanbul ignore if: не проверяем в тестах */ if (process.env.NODE_ENV === 'development' && getRef) { warn('Свойство `getRef` устаревшее, используйте `slotProps={ textArea: { getRootRef: ... } }`'); } const rootProps = useMergeProps(restProps, slotProps?.root); const textAreaRest = useMergeProps( { getRootRef: getRef, autoComplete, autoCapitalize, autoCorrect, cols, dirName, disabled, maxLength, minLength, name, placeholder, readOnly, required, value: valueProp, wrap, rows, form, onChange, onFocus, onBlur, id, inputMode, defaultValue, autoFocus, tabIndex, spellCheck, }, slotProps?.textArea, ); return ( {hasReactNode(before) && {before}} {hasReactNode(inlineAfter) && ( {inlineAfter} )} {hasReactNode(after) && {after}} ); }; WriteBar.FormField = WriteBarFormField; WriteBar.Textarea = WriteBarTextarea; WriteBar.Root = WriteBarRoot; WriteBar.Before = WriteBarBeforeOrAfter; WriteBar.After = WriteBarBeforeOrAfter;