import React, { AllHTMLAttributes, ElementType, FC, ReactNode, MouseEvent } from 'react';
import { classNames } from '../../lib/classNames';
import { usePlatform } from '../../hooks/usePlatform';
import { getClassName } from '../../helpers/getClassName';
import { hasReactNode } from '../../lib/utils';
import Subhead from '../Typography/Subhead/Subhead';
import Caption from '../Typography/Caption/Caption';
import { withAdaptivity, AdaptivityProps } from '../../hoc/withAdaptivity';
import { Removable, RemovePlaceholderProps } from '../Removable/Removable';
export interface FormItemProps extends AllHTMLAttributes, RemovePlaceholderProps {
top?: ReactNode;
bottom?: ReactNode;
status?: 'default' | 'error' | 'valid';
Component?: ElementType;
/**
* Дает возможность удалить `FormItem`. Рекомендуется использовать только для `Input` или `Select`.
*/
removable?: boolean;
/**
* Коллбэк срабатывает при клике на контрол удаления.
*/
onRemove?: (e: MouseEvent) => void;
}
export const FormItem: FC = withAdaptivity((props: FormItemProps & Pick) => {
const {
className,
children,
top,
bottom,
status,
Component,
sizeY,
removable,
onRemove,
removePlaceholder,
...restProps
} = props;
const platform = usePlatform();
const wrappedChildren = (
<>
{hasReactNode(top) && {top}}
{children}
{hasReactNode(bottom) && {bottom}}
>
);
return (
{removable ? (
{wrappedChildren}
) : wrappedChildren}
);
}, {
sizeY: true,
});
FormItem.defaultProps = {
status: 'default',
Component: 'div',
removePlaceholder: 'Удалить',
};