@atlaskit/modal-dialog
Version:
A modal dialog displays content that requires user interaction, in a layer above the page.
69 lines (67 loc) • 3.02 kB
JavaScript
/* modal-header.tsx generated by @compiled/babel-plugin v0.36.1 */
"use strict";
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
require("./modal-header.compiled.css");
var _runtime = require("@compiled/react/runtime");
var _react = _interopRequireDefault(require("react"));
var _primitives = require("@atlaskit/primitives");
var _closeButton = require("./close-button");
var _hooks = require("./hooks");
// eslint-disable-next-line @atlaskit/design-system/no-emotion-primitives -- to be migrated to @atlaskit/primitives/compiled – go/akcss
var headerStyles = null;
var flexStyles = (0, _primitives.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)
*/
var ModalHeader = function ModalHeader(props) {
var children = props.children,
userDefinedTestId = props.testId,
_props$hasCloseButton = props.hasCloseButton,
hasCloseButton = _props$hasCloseButton === void 0 ? false : _props$hasCloseButton;
var _useModal = (0, _hooks.useModal)(),
hasProvidedOnClose = _useModal.hasProvidedOnClose,
onClose = _useModal.onClose,
modalTestId = _useModal.testId;
var testId = userDefinedTestId || modalTestId && "".concat(modalTestId, "--header");
// Only show if an onClose was provided for the modal dialog
var shouldShowCloseButton = hasCloseButton && hasProvidedOnClose && onClose;
return /*#__PURE__*/_react.default.createElement("div", {
"data-testid": testId,
className: (0, _runtime.ax)(["_18zr1ejb _1e0c1txw _kqswh2mm _4cvr1h6o _1bah1yb4 _6rthmufe _85i5pxbi _1q511ejb"]),
style: {
"--_t7lu6v": (0, _runtime.ix)("calc(-1 * ".concat("var(--ds-border-width-outline, 2px)", ")"))
}
}, 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.default.createElement(_primitives.Flex, {
gap: "space.200",
justifyContent: "space-between",
xcss: flexStyles
}, /*#__PURE__*/_react.default.createElement(_primitives.Flex, {
justifyContent: "end"
}, /*#__PURE__*/_react.default.createElement(_closeButton.CloseButton, {
onClick: onClose,
testId: modalTestId
})), /*#__PURE__*/_react.default.createElement(_primitives.Flex, {
justifyContent: "start",
alignItems: "center"
}, children)) : children);
};
var _default = exports.default = ModalHeader;