@atlaskit/modal-dialog
Version:
A modal dialog displays content that requires user interaction, in a layer above the page.
61 lines (60 loc) • 2.33 kB
JavaScript
/* modal-header.tsx generated by @compiled/babel-plugin v0.36.1 */
import "./modal-header.compiled.css";
import { ax, ix } from "@compiled/react/runtime";
import React from 'react';
// eslint-disable-next-line @atlaskit/design-system/no-emotion-primitives -- to be migrated to @atlaskit/primitives/compiled – go/akcss
import { Flex, xcss } from '@atlaskit/primitives';
import { CloseButton } from './close-button';
import { useModal } from './hooks';
const headerStyles = null;
const flexStyles = xcss({
flexDirection: 'row-reverse',
width: '100%'
});
/**
* __Modal header__
*
* A modal header contains the title of the modal and can contain other React elements such as a close button.
*
* - [Examples](https://atlassian.design/components/modal-dialog/examples#modal-header)
* - [Code](https://atlassian.design/components/modal-dialog/code#modal-header-props)
* - [Usage](https://atlassian.design/components/modal-dialog/usage)
*/
const ModalHeader = props => {
const {
children,
testId: userDefinedTestId,
hasCloseButton = false
} = props;
const {
hasProvidedOnClose,
onClose,
testId: modalTestId
} = useModal();
const testId = userDefinedTestId || modalTestId && `${modalTestId}--header`;
// Only show if an onClose was provided for the modal dialog
const shouldShowCloseButton = hasCloseButton && hasProvidedOnClose && onClose;
return /*#__PURE__*/React.createElement("div", {
"data-testid": testId,
className: ax(["_18zr1ejb _1e0c1txw _kqswh2mm _4cvr1h6o _1bah1yb4 _6rth1ezb _85i5pxbi _1q511ejb"])
}, shouldShowCloseButton ?
/*#__PURE__*/
// The reason we are putting the close button first in the DOM and then
// reordering them is to ensure that users of assistive technology get
// all the context of a modal when initial focus is placed on the close
// button, since it's the first interactive element.
React.createElement(Flex, {
gap: "space.200",
justifyContent: "space-between",
xcss: flexStyles
}, /*#__PURE__*/React.createElement(Flex, {
justifyContent: "end"
}, /*#__PURE__*/React.createElement(CloseButton, {
onClick: onClose,
testId: modalTestId
})), /*#__PURE__*/React.createElement(Flex, {
justifyContent: "start",
alignItems: "center"
}, children)) : children);
};
export default ModalHeader;