UNPKG

@elastic/eui

Version:

Elastic UI Component Library

74 lines (73 loc) 3.55 kB
import _extends from "@babel/runtime/helpers/extends"; import _defineProperty from "@babel/runtime/helpers/defineProperty"; import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties"; var _excluded = ["className", "children", "initialFocus", "onClose", "maxWidth", "style"]; function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; } function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; } /* * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one * or more contributor license agreements. Licensed under the Elastic License * 2.0 and the Server Side Public License, v 1; you may not use this file except * in compliance with, at your election, the Elastic License 2.0 or the Server * Side Public License, v 1. */ import React from 'react'; import classnames from 'classnames'; import { keys, useEuiTheme } from '../../services'; import { EuiButtonIcon } from '../button'; import { EuiFocusTrap } from '../focus_trap'; import { EuiOverlayMask } from '../overlay_mask'; import { EuiI18n } from '../i18n'; import { euiModalStyles } from './modal.styles'; import { jsx as ___EmotionJSX } from "@emotion/react"; export var EuiModal = function EuiModal(_ref) { var className = _ref.className, children = _ref.children, initialFocus = _ref.initialFocus, onClose = _ref.onClose, _ref$maxWidth = _ref.maxWidth, maxWidth = _ref$maxWidth === void 0 ? true : _ref$maxWidth, style = _ref.style, rest = _objectWithoutProperties(_ref, _excluded); var onKeyDown = function onKeyDown(event) { if (event.key === keys.ESCAPE) { event.preventDefault(); event.stopPropagation(); onClose(event); } }; var newStyle = style; if (typeof maxWidth !== 'boolean') { newStyle = _objectSpread(_objectSpread({}, newStyle), {}, { maxInlineSize: maxWidth }); } var classes = classnames('euiModal', className); var euiTheme = useEuiTheme(); var styles = euiModalStyles(euiTheme); var cssStyles = [styles.euiModal, maxWidth === true && styles.defaultMaxWidth]; var cssCloseIconStyles = [styles.euiModal__closeIcon]; return ___EmotionJSX(EuiOverlayMask, null, ___EmotionJSX(EuiFocusTrap, { initialFocus: initialFocus, scrollLock: true, preventScrollOnFocus: true }, ___EmotionJSX("div", _extends({ css: cssStyles, className: classes, onKeyDown: onKeyDown, tabIndex: 0, style: newStyle }, rest), ___EmotionJSX(EuiI18n, { token: "euiModal.closeModal", default: "Closes this modal window" }, function (closeModal) { return ___EmotionJSX(EuiButtonIcon, { iconType: "cross", onClick: onClose, css: cssCloseIconStyles, className: "euiModal__closeIcon", color: "text", "aria-label": closeModal }); }), children))); };