import React, { FunctionComponent, HTMLAttributes, MouseEvent } from 'react'; import { getClassName } from '../../helpers/getClassName'; import { classNames } from '../../lib/classNames'; import { usePlatform } from '../../hooks/usePlatform'; import { Removable, RemovePlaceholderProps } from '../Removable/Removable'; import { withAdaptivity, AdaptivityProps } from '../../hoc/withAdaptivity'; export interface FormLayoutGroupProps extends HTMLAttributes, RemovePlaceholderProps { mode?: 'vertical' | 'horizontal'; /** * Только для режима horizontal. Дает возможность удалить всю группу `FormItem`. */ removable?: boolean; /** * Коллбэк срабатывает при клике на контрол удаления. */ onRemove?: (e: MouseEvent) => void; } const FormLayoutGroup: FunctionComponent = withAdaptivity(({ children, className, mode, removable, removePlaceholder, onRemove, sizeY, ...restProps }: FormLayoutGroupProps & Pick) => { const platform = usePlatform(); const isRemovable = removable && mode === 'horizontal'; return (
{isRemovable ? {children} : children }
); }, { sizeY: true, }); FormLayoutGroup.defaultProps = { mode: 'vertical', removePlaceholder: 'Удалить', }; export default FormLayoutGroup;