Repository URL to install this package:
|
Version:
8.1.0-rc.5 ▾
|
"use strict";
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); }
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = void 0;
var _react = _interopRequireWildcard(require("react"));
var _propTypes = _interopRequireDefault(require("prop-types"));
var _classnames = _interopRequireDefault(require("classnames"));
var _Modal = _interopRequireDefault(require("../Modal"));
var _Button = _interopRequireDefault(require("../../../controls/Button/Button"));
var _ButtonLabel = _interopRequireDefault(require("../../../controls/Button/ButtonLabel"));
var _LoadingButton = _interopRequireDefault(require("../../../controls/Button/LoadingButton"));
var _Icon = _interopRequireDefault(require("../../../visuals/Icon/Icon"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function _getRequireWildcardCache() { return cache; }; return cache; }
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
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 _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; }
var Close = function Close(props) {
return /*#__PURE__*/_react["default"].createElement("svg", props, /*#__PURE__*/_react["default"].createElement("path", {
d: "M19 6.41L17.59 5 12 10.59 6.41 5 5 6.41 10.59 12 5 17.59 6.41 19 12 13.41 17.59 19 19 17.59 13.41 12z",
fill: "currentColor"
}));
};
Close.defaultProps = {
xmlns: "http://www.w3.org/2000/svg",
viewBox: "0 0 24 24"
};
var buttonShape = {
onClick: _propTypes["default"].func,
label: _propTypes["default"].string,
href: _propTypes["default"].string,
disabled: _propTypes["default"].bool,
loading: _propTypes["default"].bool,
autoFocus: _propTypes["default"].bool
};
var StandardModal = /*#__PURE__*/function (_Component) {
_inherits(StandardModal, _Component);
var _super = _createSuper(StandardModal);
function StandardModal(props) {
var _this;
_classCallCheck(this, StandardModal);
_this = _super.call(this, props);
_defineProperty(_assertThisInitialized(_this), "onKeyPress", function (event) {
var onExit = _this.props.onExit;
var enterPressed = event.key === 'Enter';
if (enterPressed) onExit();
});
_defineProperty(_assertThisInitialized(_this), "getScreenInnerWidth", function () {
var isSmallScreen = window.innerWidth < 640;
_this.setState({
verticalAlign: isSmallScreen ? 'bottom' : 'middle',
verticalBottomDialogOffset: isSmallScreen ? '5vw' : null
});
});
_defineProperty(_assertThisInitialized(_this), "renderFooter", function () {
var _this$props = _this.props,
primaryAction = _this$props.primaryAction,
secondaryAction = _this$props.secondaryAction,
tertiaryAction = _this$props.tertiaryAction,
hint = _this$props.hint;
var shouldRenderFooter = primaryAction || secondaryAction || tertiaryAction || hint;
if (shouldRenderFooter) {
return /*#__PURE__*/_react["default"].createElement("div", {
className: "StandardModal-footer"
}, tertiaryAction && /*#__PURE__*/_react["default"].createElement(_Button["default"], {
autoFocus: !!tertiaryAction.autoFocus,
onClick: tertiaryAction.onClick,
href: tertiaryAction.href,
variant: "linkBlue",
disabled: tertiaryAction.disabled,
inputButtonClass: tertiaryAction.loading ? 'loading' : null
}, /*#__PURE__*/_react["default"].createElement(_ButtonLabel["default"], null, tertiaryAction.label), /*#__PURE__*/_react["default"].createElement(_LoadingButton["default"], null)), !tertiaryAction && hint && /*#__PURE__*/_react["default"].createElement("div", {
className: "StandardModal-hint tiny--soft"
}, hint), /*#__PURE__*/_react["default"].createElement("div", {
className: "StandardModal-buttonWrapper"
}, secondaryAction && /*#__PURE__*/_react["default"].createElement(_Button["default"], {
autoFocus: !!secondaryAction.autoFocus,
onClick: secondaryAction.onClick,
href: secondaryAction.href,
variant: "whiteWithBorder",
disabled: secondaryAction.disabled,
inputButtonClass: secondaryAction.loading ? 'loading' : null
}, /*#__PURE__*/_react["default"].createElement(_ButtonLabel["default"], null, secondaryAction.label), /*#__PURE__*/_react["default"].createElement(_LoadingButton["default"], null)), primaryAction && /*#__PURE__*/_react["default"].createElement(_Button["default"], {
className: "StandardModal-primaryButton",
autoFocus: !!primaryAction.autoFocus,
onClick: primaryAction.onClick,
href: primaryAction.href,
variant: "blue",
disabled: primaryAction.disabled,
inputButtonClass: primaryAction.loading ? 'loading' : null
}, /*#__PURE__*/_react["default"].createElement(_ButtonLabel["default"], null, primaryAction.label), /*#__PURE__*/_react["default"].createElement(_LoadingButton["default"], null))));
}
return null;
});
_this.state = {
verticalAlign: window.innerWidth < 640 ? 'bottom' : 'middle'
};
return _this;
}
_createClass(StandardModal, [{
key: "componentDidMount",
value: function componentDidMount() {
window.addEventListener('resize', this.getScreenInnerWidth);
}
}, {
key: "componentWillUnmount",
value: function componentWillUnmount() {
window.addEventListener('resize', this.getScreenInnerWidth);
}
}, {
key: "render",
value: function render() {
var _this$props2 = this.props,
content = _this$props2.content,
title = _this$props2.title,
Image = _this$props2.Image,
onExit = _this$props2.onExit,
wide = _this$props2.wide;
var _this$state = this.state,
verticalAlign = _this$state.verticalAlign,
verticalBottomDialogOffset = _this$state.verticalBottomDialogOffset;
var classNames = (0, _classnames["default"])('StandardModal-container', {
'StandardModal-container--wide': wide
});
return /*#__PURE__*/_react["default"].createElement(_Modal["default"], _extends({}, this.props, {
variant: "ink",
verticalAlign: verticalAlign,
verticalBottomDialogOffset: verticalBottomDialogOffset
}), /*#__PURE__*/_react["default"].createElement("div", {
className: classNames
}, Image && /*#__PURE__*/_react["default"].createElement(Image, {
className: "StandardModal-image"
}), /*#__PURE__*/_react["default"].createElement("div", {
className: "StandardModal-header"
}, /*#__PURE__*/_react["default"].createElement("h2", {
className: "StandardModal-title"
}, title), !Image && /*#__PURE__*/_react["default"].createElement(_Icon["default"], {
className: "StandardModal-close",
icon: Close,
tabIndex: "0",
onKeyPress: this.onKeyPress,
onClick: onExit
})), /*#__PURE__*/_react["default"].createElement("div", {
className: "StandardModal-content body"
}, content), this.renderFooter()));
}
}]);
return StandardModal;
}(_react.Component);
_defineProperty(StandardModal, "propTypes", {
/** Modal contents displayed over underlay, no styling/wrapper provided */
content: _propTypes["default"].any.isRequired,
/** A11y-enabled modal title */
title: _propTypes["default"].string.isRequired,
/** Image to be used as part of the Modal Header, when this image is added, the close icon is not shown */
Image: _propTypes["default"].elementType,
/** Control whether to show the modal: this allows internal entering/exiting logic for transitions */
show: _propTypes["default"].bool.isRequired,
/** If provided, it is invoked for escape key or underlay click interactions. If omitted, the modal dialog does not respond to these interactions: you have to provide a way of closing it from the modal dialog content (an interaction that will toggle the `show` prop) . */
onExit: _propTypes["default"].func,
/** If providedm it is invoked as soon as the modal is an entered/opened state */
onEnter: _propTypes["default"].func,
/** The primary button of the modal */
primaryAction: _propTypes["default"].shape(buttonShape),
/** The secondary button of the modal */
secondaryAction: _propTypes["default"].shape(buttonShape),
/** The tertiary button of the modal. Will take precedence if both this and the hint are provided */
tertiaryAction: _propTypes["default"].shape(buttonShape),
/** A hint that will only be rendered if no tertiary button is provided */
hint: _propTypes["default"].string,
/** Allows the StandardModal to grow in width beyond the 640px limit */
wide: _propTypes["default"].bool
});
_defineProperty(StandardModal, "defaultProps", {
Image: undefined,
onExit: undefined,
onEnter: undefined,
primaryAction: undefined,
secondaryAction: undefined,
tertiaryAction: undefined,
hint: undefined,
wide: false
});
var _default = StandardModal;
exports["default"] = _default;