1 | "use strict";
|
2 | var __extends = (this && this.__extends) || (function () {
|
3 | var extendStatics = Object.setPrototypeOf ||
|
4 | ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
5 | function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
|
6 | return function (d, b) {
|
7 | extendStatics(d, b);
|
8 | function __() { this.constructor = d; }
|
9 | d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
10 | };
|
11 | })();
|
12 | var __assign = (this && this.__assign) || Object.assign || function(t) {
|
13 | for (var s, i = 1, n = arguments.length; i < n; i++) {
|
14 | s = arguments[i];
|
15 | for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
16 | t[p] = s[p];
|
17 | }
|
18 | return t;
|
19 | };
|
20 | Object.defineProperty(exports, "__esModule", { value: true });
|
21 | var react_malibu_1 = require("@heroku/react-malibu");
|
22 | var classnames = require("classnames");
|
23 | var React = require("react");
|
24 | var react_transition_group_1 = require("react-transition-group");
|
25 | var simple_react_modal_1 = require("simple-react-modal");
|
26 | var HKButton_1 = require("./HKButton");
|
27 | var Type;
|
28 | (function (Type) {
|
29 | Type["Actionable"] = "actionable";
|
30 | Type["Destructive"] = "destructive";
|
31 | Type["Presentation"] = "presentation";
|
32 | })(Type = exports.Type || (exports.Type = {}));
|
33 |
|
34 |
|
35 |
|
36 |
|
37 |
|
38 |
|
39 |
|
40 |
|
41 |
|
42 |
|
43 |
|
44 |
|
45 |
|
46 |
|
47 |
|
48 |
|
49 |
|
50 |
|
51 | var HKModal = (function (_super) {
|
52 | __extends(HKModal, _super);
|
53 | function HKModal() {
|
54 | var _this = _super !== null && _super.apply(this, arguments) || this;
|
55 | _this.state = {
|
56 | isClosing: false,
|
57 | isShowing: false,
|
58 | };
|
59 | _this.handleClose = function (e) {
|
60 | _this.props.onDismiss('cancel');
|
61 | };
|
62 | _this.handleButtonClick = function (e) {
|
63 | _this.props.onDismiss(e.currentTarget.value);
|
64 | };
|
65 | _this.handleExited = function (node) {
|
66 | node.addEventListener('transitionend', function () {
|
67 | _this.setState({ isShowing: false });
|
68 | }, false);
|
69 | };
|
70 | return _this;
|
71 | }
|
72 | HKModal.getDerivedStateFromProps = function (props, state) {
|
73 | if (props.show) {
|
74 |
|
75 | return { isShowing: true, isClosing: false };
|
76 | }
|
77 | else {
|
78 |
|
79 |
|
80 |
|
81 |
|
82 | return { isClosing: true };
|
83 | }
|
84 | };
|
85 | HKModal.prototype.render = function () {
|
86 | var _this = this;
|
87 | var duration = 250;
|
88 | var _a = this.props, children = _a.children, onDismiss = _a.onDismiss, header = _a.header, buttons = _a.buttons, isFlyout = _a.isFlyout, type = _a.type;
|
89 | var _b = this.state, isShowing = _b.isShowing, isClosing = _b.isClosing;
|
90 | var fadeTransition = {
|
91 | transition: "background " + duration + "ms ease-in-out, opacity " + duration + "ms ease-in-out",
|
92 | };
|
93 | var fadeStyles = {
|
94 | entered: { background: 'rgba(0, 0, 0, .2)', opacity: 1 },
|
95 | entering: { background: 'rgba(0, 0, 0, 0)', opacity: 0 },
|
96 | exited: { background: 'rgba(0, 0, 0, 0)', opacity: 0 },
|
97 | exiting: { background: 'rgba(0, 0, 0, .2)', opacity: 1 },
|
98 | };
|
99 | var innerTransition = isFlyout ? {
|
100 | transform: 'translateX(100%)',
|
101 | transition: "transform " + duration + "ms cubic-bezier(0,1,0.5,1)",
|
102 | } : {};
|
103 | var innerStyles = isFlyout ? {
|
104 | entered: { transform: 'translateX(0)', width: '350px' },
|
105 | entering: { transform: 'translateX(100%)', width: '350px' },
|
106 | exited: { transform: 'translateX(100%)', width: '350px' },
|
107 | exiting: { transform: 'translateX(0)', width: '350px' },
|
108 | } : {};
|
109 | var dismissElem = onDismiss && (React.createElement("div", { className: classnames('right-1 absolute pointer', { 'top-1': !header }), onClick: this.handleClose },
|
110 | React.createElement(react_malibu_1.MalibuIcon, { name: 'delete-16', fillClass: 'dark-gray', size: 16, extraClasses: 'icon malibu-icon h1 w1 fill-dark-gray o-50 hover-o-100 h-100 v-mid' })));
|
111 | var modalParentClass = {
|
112 | 'items-center justify-center': !isFlyout,
|
113 | };
|
114 | var modalClass = {
|
115 | 'fixed right-0 w7 h-100 flex flex-column': isFlyout,
|
116 | 'w-100 mw7 center br1': !isFlyout,
|
117 | };
|
118 | var modalChildrenClass = {
|
119 | 'flex-auto': isFlyout,
|
120 | };
|
121 | var footer = (buttons || []).map(function (b) { return (React.createElement(HKButton_1.default, { key: b.value, value: b.value, type: b.type, disabled: b.disabled, onClick: _this.handleButtonClick, className: classnames('ml1', b.classNames) }, b.text)); });
|
122 |
|
123 | return (React.createElement(react_transition_group_1.Transition, { in: !isClosing, timeout: 0, onExited: this.handleExited }, function (state) { return (React.createElement(simple_react_modal_1.default, { containerStyle: __assign({}, innerTransition, innerStyles[state]), containerClassName: classnames('bg-white shadow-outer-1 relative', modalClass), style: __assign({ bottom: 0, left: 0, position: 'fixed', right: 0, top: 0, zIndex: 9999 }, fadeTransition, fadeStyles[state]), className: classnames('flex flex-column', modalParentClass), closeOnOuterClick: true, show: isShowing, onClose: _this.handleClose },
|
124 | React.createElement("div", { className: classnames('hk-modal-header f4 flex items-center justify-center br--top br2', { 'bg-near-white bb b--light-silver pa4': header, 'red': type === 'destructive' }) },
|
125 | header,
|
126 | dismissElem),
|
127 | React.createElement("div", { className: classnames(modalChildrenClass) }, children),
|
128 | buttons && React.createElement("div", { className: 'bt b--light-silver w-100 pa3 tr' }, footer))); }));
|
129 | };
|
130 | HKModal.defaultProps = {
|
131 | isFlyout: false,
|
132 | };
|
133 | return HKModal;
|
134 | }(React.Component));
|
135 | exports.default = HKModal;
|
136 |
|
\ | No newline at end of file |