@atlaskit/modal-dialog
Version:
A modal dialog displays content that requires user interaction, in a layer above the page.
62 lines (59 loc) • 2.07 kB
JavaScript
/** @jsx jsx */
import React from 'react';
import { css, jsx } from '@emotion/react';
import { TouchScrollable } from 'react-scrolllock';
import { useModal } from './hooks';
import ScrollContainer from './internal/components/scroll-container';
import { keylineHeight, padding } from './internal/constants';
import useScroll from './internal/hooks/use-scroll';
const bodyStyles = css({
/* This ensures the body fills the whole space between header and footer. */
flex: '1 1 auto'
});
/**
* Adding the padding here avoids cropping the keyline on its sides.
* The combined vertical spacing is maintained by subtracting the
* keyline height from header and footer.
*/
const bodyScrollStyles = css({
// eslint-disable-next-line @atlaskit/design-system/ensure-design-token-usage-spacing
padding: `${keylineHeight}px ${padding}px`
});
/**
* Keylines will not be shown if scrolling in viewport so we do
* not account for them in this case.
*/
const viewportScrollStyles = css({
// eslint-disable-next-line @atlaskit/design-system/ensure-design-token-usage-spacing
padding: `0px ${padding}px`
});
/**
* __Modal body__
*
* A modal body is used to display the main content of a modal.
*
* - [Examples](https://atlassian.design/components/modal-dialog/examples)
* - [Code](https://atlassian.design/components/modal-dialog/code#modal-body-props)
* - [Usage](https://atlassian.design/components/modal-dialog/usage)
*/
const ModalBody = props => {
const {
children,
testId: userDefinedTestId
} = props;
const {
testId: modalTestId
} = useModal();
const shouldScrollInViewport = useScroll();
const testId = userDefinedTestId || modalTestId && `${modalTestId}--body`;
return shouldScrollInViewport ? jsx("div", {
css: [bodyStyles, viewportScrollStyles],
"data-testid": testId
}, children) : jsx(TouchScrollable, null, jsx(ScrollContainer, {
testId: userDefinedTestId || modalTestId
}, jsx("div", {
css: [bodyStyles, bodyScrollStyles],
"data-testid": testId
}, children)));
};
export default ModalBody;