@momentum-ui/react-collaboration
Version:
Cisco Momentum UI Framework for React Collaboration Applications
52 lines • 3.65 kB
JavaScript
var __assign = (this && this.__assign) || function () {
__assign = Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
var __rest = (this && this.__rest) || function (s, e) {
var t = {};
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
t[p] = s[p];
if (s != null && typeof Object.getOwnPropertySymbols === "function")
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
t[p[i]] = s[p[i]];
}
return t;
};
import React, { forwardRef } from 'react';
import classnames from 'classnames';
import { FocusScope } from '@react-aria/focus';
import ModalArrow from '../ModalArrow';
import { ARROW_ID, DEFAULTS, STYLE } from './ModalContainer.constants';
import './ModalContainer.style.scss';
import { getArrowOrientation } from './ModalContainer.utils';
var ModalContainer = function (props, ref) {
var _a = props.arrowId, arrowId = _a === void 0 ? ARROW_ID : _a, _b = props.showArrow, showArrow = _b === void 0 ? DEFAULTS.SHOW_ARROW : _b, placement = props.placement, children = props.children, _c = props.elevation, elevation = _c === void 0 ? DEFAULTS.ELEVATION : _c, _d = props.isPadded, isPadded = _d === void 0 ? DEFAULTS.IS_PADDED : _d, _e = props.round, round = _e === void 0 ? DEFAULTS.ROUND : _e, _f = props.color, color = _f === void 0 ? DEFAULTS.COLOR : _f, _g = props.role, role = _g === void 0 ? DEFAULTS.ROLE : _g, _h = props.ariaModal, ariaModal = _h === void 0 ? true : _h, id = props.id, className = props.className, style = props.style, focusLockProps = props.focusLockProps, otherProps = __rest(props, ["arrowId", "showArrow", "placement", "children", "elevation", "isPadded", "round", "color", "role", "ariaModal", "id", "className", "style", "focusLockProps"]);
var arrowOrientation = getArrowOrientation(placement);
// aria-modal should only be on dialogs (https://w3c.github.io/aria/#aria-modal)
var roleProps = ['dialog', 'alertdialog'].includes(role) ? { 'aria-modal': ariaModal } : {};
var content = (React.createElement("div", __assign({ ref: ref, role: role }, roleProps, { className: classnames(className, STYLE.wrapper), id: id, style: style, "data-placement": placement, "data-arrow-orientation": arrowOrientation, "data-color": color, "data-elevation": elevation, "data-padded": isPadded, "data-round": round,
// Allow the "no focused element" state to have the focus set to the dialog instead of trying to set it to the body
tabIndex: -1, "data-exclude-focus": true }, otherProps),
children,
/*arrow has to be wrapped in HTML element to allow Popover to style it*/
showArrow && (React.createElement("div", { id: arrowId, "data-popper-arrow": true, className: classnames(STYLE.arrowWrapper) },
React.createElement(ModalArrow, { placement: placement, color: color })))));
if (!focusLockProps) {
return content;
}
return (
// eslint-disable-next-line jsx-a11y/no-autofocus
React.createElement(FocusScope, __assign({ contain: true, autoFocus: true }, focusLockProps), content));
};
var _ModalContainer = forwardRef(ModalContainer);
_ModalContainer.displayName = 'ModalContainer';
export default _ModalContainer;
//# sourceMappingURL=ModalContainer.js.map