import React, { FC, HTMLAttributes, ReactNode, useContext, useEffect } from 'react';
import { getClassName } from '../../helpers/getClassName';
import { classNames } from '../../lib/classNames';
import { ModalRootContext } from '../ModalRoot/ModalRootContext';
import { usePlatform } from '../../hooks/usePlatform';
import { withAdaptivity, AdaptivityProps, ViewHeight, ViewWidth } from '../../hoc/withAdaptivity';
import ModalDismissButton from '../ModalDismissButton/ModalDismissButton';
import { Ref } from '../../types';
export interface ModalPageProps extends HTMLAttributes, AdaptivityProps {
/**
* Шапка модальной страницы, ``
*/
header?: ReactNode;
onClose?: VoidFunction;
/**
* Процент, на который изначально будет открыта модальная страница. При `settlingHeight={100}` модальная страница раскрывается на всю высоту.
*/
settlingHeight?: number;
/**
* Если высота контента в модальной странице может поменяться, нужно установить это свойство
*/
dynamicContentHeight?: boolean;
getModalContentRef?: Ref;
}
const ModalPage: FC = (props: ModalPageProps) => {
const platform = usePlatform();
const { updateModalHeight } = useContext(ModalRootContext);
const {
children,
className,
header,
viewWidth,
viewHeight,
sizeX,
hasMouse,
onClose,
settlingHeight,
dynamicContentHeight,
getModalContentRef,
...restProps
} = props;
useEffect(() => {
updateModalHeight();
}, [children]);
const isDesktop = viewWidth >= ViewWidth.SMALL_TABLET && (hasMouse || viewHeight >= ViewHeight.MEDIUM);
const canShowCloseBtn = viewWidth >= ViewWidth.SMALL_TABLET;
const modalContext = useContext(ModalRootContext);
return (
{header}
{canShowCloseBtn &&
}
);
};
ModalPage.defaultProps = {
settlingHeight: 75,
};
export default withAdaptivity(ModalPage, {
viewWidth: true,
viewHeight: true,
sizeX: true,
hasMouse: true,
});