function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }

function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }

function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }

function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }

function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }

function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }

function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }

function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }

function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }

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; }

/* Copyright (c) 2015-present, salesforce.com, inc. All rights reserved */

/* Licensed under BSD 3-Clause - see LICENSE.txt or git.io/sfdc-license */
// # Toast Component
// Implements the [Toast design pattern](https://lightningdesignsystem.com/components/toasts/) in React.
import React from 'react';
import PropTypes from 'prop-types';
import assign from 'lodash.assign';
import classNames from '../../utilities/class-names';
import Button from '../button';
import Icon from '../icon';
import checkProps from './check-props';
import { TOAST } from '../../utilities/constants';
import DOMElementFocus from '../../utilities/dom-element-focus';
import componentDoc from './component.json';
var propTypes = {
  /**
   * **Assistive text for accessibility**
   * This object is merged with the default props object on every render.
   * * `closeButton`: This is a visually hidden label for the close button.
   * * `error`: This is a visually hidden label to mark the toast as an error variant
   * * `info`: This is a visually hidden label to mark the toast as an info variant
   * * `success`: This is a visually hidden label to mark the toast as an success variant
   * * `warning`: This is a visually hidden label to mark the toast as an warning variant
   * _Tested with snapshot testing._
   */
  assistiveText: PropTypes.shape({
    closeButton: PropTypes.oneOfType([PropTypes.string, PropTypes.node])
  }),

  /**
   * CSS classes to be added to tag with `.slds-notify_toast`. Uses `classNames` [API](https://github.com/JedWatson/classnames).
   * _Tested with snapshot testing._
   */
  className: PropTypes.oneOfType([PropTypes.array, PropTypes.object, PropTypes.string]),

  /**
   * If duration exists, the Toast will disappear after that amount of time. Time in milliseconds. _Tested with Mocha testing._
   */
  duration: PropTypes.number,

  /**
   * **Text labels for internationalization**
   * This object is merged with the default props object on every render.
   * * `details`: Secondary text below heading
   * * `heading`: text within heading tag
   * * `headingLink`: Text of link that triggers `onClickHeadingLink`. Inline links should pass a keyed array of React components into `labels.heading`.
   *
   * _Tested with snapshot testing._
   */
  labels: PropTypes.shape({
    details: PropTypes.oneOfType([PropTypes.string, PropTypes.node]),
    heading: PropTypes.oneOfType([PropTypes.string, PropTypes.node]),
    headingLink: PropTypes.oneOfType([PropTypes.string, PropTypes.node])
  }),

  /**
   * Triggered by link. _Tested with Mocha testing._
   */
  onClickHeadingLink: PropTypes.func,

  /**
   * Icon of type `~/components/icon`. This icon will be cloned and additional props appended. The default icons are:
   * * info variant: `utility:info`
   * * error variant: `utility:error`
   * * success variant: `utility:success`
   * * warning variant: `utility:warning`
   *
   * _Tested with snapshot testing._
   */
  icon: PropTypes.node,

  /**
   * Triggered by close button. _Tested with Mocha testing._
   */
  onRequestClose: PropTypes.func,

  /**
   * Custom styles to be passed to the component. _Tested with Mocha testing._
   */
  style: PropTypes.object,

  /**
   * The type of Toast. _Tested with snapshot testing._
   */
  variant: PropTypes.oneOf(['error', 'info', 'success', 'warning']).isRequired
};
var defaultProps = {
  assistiveText: {
    closeButton: 'Close',
    error: 'error',
    info: 'info',
    success: 'success',
    warning: 'warning'
  },
  variant: 'info'
};
/**
 * Toast serves as a feedback & confirmation mechanism after the user takes an action. View [banner guidelines](https://www.lightningdesignsystem.com/guidelines/messaging/components/banners/).
 */

var Toast = /*#__PURE__*/function (_React$Component) {
  _inherits(Toast, _React$Component);

  var _super = _createSuper(Toast);

  function Toast(props) {
    var _this;

    _classCallCheck(this, Toast);

    _this = _super.call(this, props);

    _defineProperty(_assertThisInitialized(_this), "onClose", function () {
      _this.clearTimeout();

      if (_this.props.onRequestClose) {
        _this.props.onRequestClose();
      }
    });

    _defineProperty(_assertThisInitialized(_this), "clearTimeout", function () {
      if (_this.timeout) {
        clearTimeout(_this.timeout);
        _this.timeout = null;
      }
    });

    _defineProperty(_assertThisInitialized(_this), "saveToastRef", function (toast) {
      _this.toast = toast;

      if (_this.state.isInitialRender) {
        DOMElementFocus.storeActiveElement();

        if (_this.toast) {
          _this.toast.focus();
        }

        _this.setState({
          isInitialRender: false
        });
      }
    });

    _this.state = {
      isInitialRender: true
    };
    _this.timeout = null;
    _this.toast = null; // `checkProps` issues warnings to developers about properties (similar to React's built in development tools)

    checkProps(TOAST, props, componentDoc);
    return _this;
  }

  _createClass(Toast, [{
    key: "componentDidMount",
    value: function componentDidMount() {
      var _this2 = this;

      if (this.props.duration) {
        this.timeout = setTimeout(function () {
          _this2.onClose();
        }, this.props.duration);
      }
    }
  }, {
    key: "componentWillUnmount",
    value: function componentWillUnmount() {
      this.clearTimeout();
      DOMElementFocus.returnFocusToStoredElement();
    }
  }, {
    key: "render",
    value: function render() {
      // Merge objects of strings with their default object
      var assistiveText = assign({}, defaultProps.assistiveText, this.props.assistiveText);
      var labels = assign({}, defaultProps.labels, this.props.labels);
      var heading = labels.heading || this.props.content; // eslint-disable-line react/prop-types

      var assistiveTextVariant = {
        info: assistiveText.info,
        success: assistiveText.success,
        warning: assistiveText.warning,
        error: assistiveText.error
      };
      var defaultIcons = {
        info: /*#__PURE__*/React.createElement(Icon, {
          category: "utility",
          name: "info"
        }),
        success: /*#__PURE__*/React.createElement(Icon, {
          category: "utility",
          name: "success"
        }),
        warning: /*#__PURE__*/React.createElement(Icon, {
          category: "utility",
          name: "warning"
        }),
        error: /*#__PURE__*/React.createElement(Icon, {
          category: "utility",
          name: "error"
        })
      };
      var icon = this.props.icon ? this.props.icon : defaultIcons[this.props.variant];
      var clonedIcon = /*#__PURE__*/React.cloneElement(icon, {
        containerClassName: 'slds-m-right_small slds-no-flex slds-align-top',
        inverse: true,
        size: 'small'
      });
      /* eslint-disable no-script-url */

      return /*#__PURE__*/React.createElement("div", {
        className: classNames('slds-notify slds-notify_toast', {
          'slds-theme_info': this.props.variant === 'info',
          'slds-theme_success': this.props.variant === 'success',
          'slds-theme_warning': this.props.variant === 'warning',
          'slds-theme_error': this.props.variant === 'error'
        }, this.props.className),
        ref: this.saveToastRef,
        role: "status",
        style: this.props.style,
        tabIndex: 0 // eslint-disable-line jsx-a11y/no-noninteractive-tabindex

      }, /*#__PURE__*/React.createElement("span", {
        className: "slds-assistive-text"
      }, assistiveTextVariant[this.props.variant]), clonedIcon, /*#__PURE__*/React.createElement("div", {
        className: "slds-notify__content"
      }, /*#__PURE__*/React.createElement("h2", {
        className: "slds-text-heading_small"
      }, heading, ' ', labels.headingLink ? /*#__PURE__*/React.createElement("a", {
        onClick: this.props.onClickHeadingLink,
        href: "javascript:void(0);"
      }, labels.headingLink) : null), labels.details ? /*#__PURE__*/React.createElement("p", null, labels.details) : null), /*#__PURE__*/React.createElement(Button, {
        assistiveText: {
          icon: assistiveText.closeButton
        },
        className: "slds-notify__close",
        iconCategory: "utility",
        iconName: "close",
        iconSize: "large",
        inverse: true,
        onClick: this.props.onRequestClose,
        title: assistiveText.closeButton,
        variant: "icon"
      }));
    }
  }]);

  return Toast;
}(React.Component);

Toast.defaultProps = defaultProps;
Toast.displayName = TOAST;
Toast.propTypes = propTypes;
export default Toast;
//# sourceMappingURL=index.js.map