text: function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
  
  function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (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 = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
  
  function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
  
  function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
  
  function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
  
  /*
   * Licensed to Elasticsearch B.V. under one or more contributor
   * license agreements. See the NOTICE file distributed with
   * this work for additional information regarding copyright
   * ownership. Elasticsearch B.V. licenses this file to you under
   * the Apache License, Version 2.0 (the "License"); you may
   * not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   *
   *    http://www.apache.org/licenses/LICENSE-2.0
   *
   * Unless required by applicable law or agreed to in writing,
   * software distributed under the License is distributed on an
   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
   * KIND, either express or implied.  See the License for the
   * specific language governing permissions and limitations
   * under the License.
   */
  import React from 'react';
  import PropTypes from "prop-types";
  import classnames from 'classnames';
  import { keys } from '../../services';
  import { EuiButtonIcon } from '../button';
  import { EuiFocusTrap } from '../focus_trap';
  import { EuiI18n } from '../i18n';
  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, ["className", "children", "initialFocus", "onClose", "maxWidth", "style"]);
  
    var onKeyDown = function onKeyDown(event) {
      if (event.key === keys.ESCAPE) {
        event.preventDefault();
        event.stopPropagation();
        onClose(event);
      }
    };
  
    var newStyle;
    var widthClassName;
  
    if (maxWidth === true) {
      widthClassName = 'euiModal--maxWidth-default';
    } else if (maxWidth !== false) {
      var value = typeof maxWidth === 'number' ? "".concat(maxWidth, "px") : maxWidth;
      newStyle = _objectSpread({}, style, {
        maxWidth: value
      });
    }
  
    var classes = classnames('euiModal', widthClassName, className);
    return React.createElement(EuiFocusTrap, {
      initialFocus: initialFocus
    }, React.createElement("div", _extends({
      className: classes,
      onKeyDown: onKeyDown,
      tabIndex: 0,
      style: newStyle || style
    }, rest), React.createElement(EuiI18n, {
      token: "euiModal.closeModal",
      default: "Closes this modal window"
    }, function (closeModal) {
      return React.createElement(EuiButtonIcon, {
        iconType: "cross",
        onClick: onClose,
        className: "euiModal__closeIcon",
        color: "text",
        "aria-label": closeModal
      });
    }), React.createElement("div", {
      className: "euiModal__flex"
    }, children)));
  };
  EuiModal.propTypes = {
    className: PropTypes.string,
    children: PropTypes.node.isRequired,
    onClose: PropTypes.func.isRequired,
  
    /**
       * Sets the max-width of the modal.
       * Set to `true` to use the default (`euiBreakpoints 'm'`),
       * set to `false` to not restrict the width,
       * set to a number for a custom width in px,
       * set to a string for a custom width in custom measurement.
       */
    maxWidth: PropTypes.oneOfType([PropTypes.bool.isRequired, PropTypes.number.isRequired, PropTypes.string.isRequired]),
  
    /** specifies what element should initially have focus; Can be a DOM node, or a selector string (which will be passed to document.querySelector() to find the DOM node), or a function that returns a DOM node. */
    initialFocus: PropTypes.oneOfType([PropTypes.any.isRequired, PropTypes.func.isRequired, PropTypes.string.isRequired])
  };
  EuiModal.__docgenInfo = {
    "description": "",
    "methods": [],
    "displayName": "EuiModal",
    "props": {
      "maxWidth": {
        "defaultValue": {
          "value": "true",
          "computed": false
        },
        "type": {
          "name": "union",
          "value": [{
            "name": "bool"
          }, {
            "name": "number"
          }, {
            "name": "string"
          }]
        },
        "required": false,
        "description": "Sets the max-width of the modal.\nSet to `true` to use the default (`euiBreakpoints 'm'`),\nset to `false` to not restrict the width,\nset to a number for a custom width in px,\nset to a string for a custom width in custom measurement."
      },
      "className": {
        "type": {
          "name": "string"
        },
        "required": false,
        "description": ""
      },
      "children": {
        "type": {
          "name": "node"
        },
        "required": true,
        "description": ""
      },
      "onClose": {
        "type": {
          "name": "func"
        },
        "required": true,
        "description": ""
      },
      "initialFocus": {
        "type": {
          "name": "union",
          "value": [{
            "name": "any"
          }, {
            "name": "func"
          }, {
            "name": "string"
          }]
        },
        "required": false,
        "description": "specifies what element should initially have focus; Can be a DOM node, or a selector string (which will be passed to document.querySelector() to find the DOM node), or a function that returns a DOM node."
      }
    }
  };