@progress/kendo-react-dialogs 4.13.0-dev.202111300702 → 4.13.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -25,69 +25,90 @@ var __assign = (this && this.__assign) || function () {
25
25
  };
26
26
  Object.defineProperty(exports, "__esModule", { value: true });
27
27
  var React = require("react");
28
- var react_dom_1 = require("react-dom");
28
+ var ReactDOM = require("react-dom");
29
29
  var PropTypes = require("prop-types");
30
30
  var DialogTitleBar_1 = require("./DialogTitleBar");
31
31
  var DialogActionsBar_1 = require("./DialogActionsBar");
32
32
  var kendo_react_common_1 = require("@progress/kendo-react-common");
33
33
  var kendo_react_common_2 = require("@progress/kendo-react-common");
34
34
  var package_metadata_1 = require("./package-metadata");
35
- // tslint:enable:max-line-length
35
+ var utils_1 = require("./utils");
36
+ var constants_1 = require("./constants");
36
37
  var Dialog = /** @class */ (function (_super) {
37
38
  __extends(Dialog, _super);
38
39
  function Dialog(props) {
39
40
  var _this = _super.call(this, props) || this;
41
+ _this._id = kendo_react_common_1.guid();
42
+ _this.titleId = _this.generateTitleId();
40
43
  /**
41
44
  * @hidden
42
45
  */
43
- _this.DialogRef = React.createRef();
44
- _this.titleId = _this.generateTitleId();
45
- _this.handleCloseDialog = function (event) {
46
+ _this.onCloseDialog = function (event) {
46
47
  event.preventDefault();
47
48
  kendo_react_common_1.dispatchEvent(_this.props.onClose, event, _this, undefined);
48
49
  };
49
- _this.handleKeyDown = function (event) {
50
+ /**
51
+ * @hidden
52
+ */
53
+ _this.onKeyDown = function (event) {
50
54
  if (event.keyCode === kendo_react_common_1.Keys.esc && _this.props.onClose) {
51
55
  event.preventDefault();
52
- _this.handleCloseDialog(event);
56
+ _this.onCloseDialog(event);
53
57
  }
54
- var kDialog = _this.DialogRef.current;
58
+ var kDialog = _this.element;
55
59
  if (kDialog && (event.keyCode === kendo_react_common_1.Keys.tab)) {
56
60
  var focusableElements = 'button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"])';
57
61
  var focusableContent = kDialog.querySelectorAll(focusableElements);
58
62
  var firstFocusableElement = focusableContent[0];
59
63
  var lastFocusableElement = focusableContent[focusableContent.length - 1];
64
+ var currentDocument = _this.getDocument();
60
65
  if (event.shiftKey) {
61
- if (document.activeElement === firstFocusableElement) {
66
+ if (currentDocument && currentDocument.activeElement === firstFocusableElement) {
62
67
  lastFocusableElement.focus();
63
68
  event.preventDefault();
64
69
  }
65
70
  }
66
71
  else {
67
- if (document.activeElement === lastFocusableElement) {
72
+ if (currentDocument && currentDocument.activeElement === lastFocusableElement) {
68
73
  firstFocusableElement.focus();
69
74
  event.preventDefault();
70
75
  }
71
76
  }
72
77
  }
73
78
  };
79
+ _this.getCurrentZIndex = function () {
80
+ if (!_this.state) {
81
+ return _this.context ? _this.context : constants_1.DEFAULT_DIALOGS_ZINDEX;
82
+ }
83
+ return _this.state.zIndex > (_this.context ? _this.context + constants_1.ZINDEX_DIALOGS_STEP : 0) ? _this.state.zIndex : _this.context + constants_1.ZINDEX_DIALOGS_STEP;
84
+ };
85
+ _this.getDocument = function () {
86
+ return _this.props.appendTo ? _this.props.appendTo.ownerDocument : document;
87
+ };
74
88
  kendo_react_common_2.validatePackage(package_metadata_1.packageMetadata);
89
+ _this.state = {
90
+ zIndex: utils_1.getMaxZIndex(_this.getCurrentZIndex(), _this.getDocument(), _this._id)
91
+ };
75
92
  return _this;
76
93
  }
77
94
  /**
78
95
  * @hidden
79
96
  */
80
97
  Dialog.prototype.componentDidMount = function () {
81
- if (this.DialogRef.current && this.props.autoFocus) {
82
- this.DialogRef.current.focus();
98
+ if (this.element) {
99
+ if (this.props.autoFocus) {
100
+ this.element.focus();
101
+ }
83
102
  }
84
103
  };
85
104
  /**
86
105
  * @hidden
87
106
  */
88
107
  Dialog.prototype.render = function () {
108
+ var _this = this;
109
+ var _a;
89
110
  var id = this.props.id !== undefined ? this.props.id : this.titleId;
90
- var _a = this.props, title = _a.title, width = _a.width, height = _a.height, children = _a.children, minWidth = _a.minWidth, dir = _a.dir, style = _a.style, contentStyle = _a.contentStyle;
111
+ var _b = this.props, title = _b.title, width = _b.width, height = _b.height, children = _b.children, minWidth = _b.minWidth, dir = _b.dir, style = _b.style, contentStyle = _b.contentStyle;
91
112
  var elementsArray = React.Children.toArray(children);
92
113
  var content = this.getContent(elementsArray);
93
114
  var actions = this.getActionBar(elementsArray);
@@ -95,14 +116,19 @@ var Dialog = /** @class */ (function (_super) {
95
116
  'aria-labelledby': id
96
117
  } : null;
97
118
  var closeIcon = this.props.closeIcon !== undefined ? this.props.closeIcon : true;
98
- var output = (React.createElement("div", { className: 'k-dialog-wrapper' + (this.props.className ? ' ' + this.props.className : ''), onKeyDown: this.handleKeyDown, tabIndex: 0, dir: dir, style: style, ref: this.DialogRef },
99
- React.createElement("div", { className: "k-overlay" }),
100
- React.createElement("div", __assign({}, aria, { className: "k-widget k-window k-dialog", role: "dialog", style: { width: width, height: height, minWidth: minWidth } }),
101
- this.props.title &&
102
- React.createElement(DialogTitleBar_1.DialogTitleBar, { closeIcon: closeIcon, onCloseButtonClick: this.handleCloseDialog, id: id }, title),
103
- React.createElement("div", { className: "k-window-content k-dialog-content", style: contentStyle }, content),
104
- actions)));
105
- return this.props.appendTo ? react_dom_1.createPortal(output, this.props.appendTo) : output;
119
+ var currentZIndex = this.getCurrentZIndex();
120
+ var dialogElement = (React.createElement(kendo_react_common_1.ZIndexContext.Provider, { value: currentZIndex },
121
+ React.createElement("div", __assign({}, (_a = {}, _a[constants_1.DATA_DIALOGS_ID] = this._id, _a), { className: 'k-dialog-wrapper' + (this.props.className ? ' ' + this.props.className : ''), onKeyDown: this.onKeyDown, tabIndex: 0, dir: dir, style: __assign({ zIndex: currentZIndex }, style), ref: (function (el) { return _this.element = el; }) }),
122
+ React.createElement("div", { className: "k-overlay" }),
123
+ React.createElement("div", __assign({}, aria, { className: "k-widget k-window k-dialog", role: "dialog", style: { width: width, height: height, minWidth: minWidth } }),
124
+ this.props.title &&
125
+ React.createElement(DialogTitleBar_1.DialogTitleBar, { closeIcon: closeIcon, onCloseButtonClick: this.onCloseDialog, id: id }, title),
126
+ React.createElement("div", { className: "k-window-content k-dialog-content", style: contentStyle }, content),
127
+ actions))));
128
+ if (kendo_react_common_1.canUseDOM) {
129
+ return ReactDOM.createPortal(dialogElement, this.props.appendTo || document.body);
130
+ }
131
+ return null;
106
132
  };
107
133
  Dialog.prototype.getActionBar = function (children) {
108
134
  return children.filter(function (child) { return child && child.type === DialogActionsBar_1.DialogActionsBar; });
@@ -113,7 +139,7 @@ var Dialog = /** @class */ (function (_super) {
113
139
  });
114
140
  };
115
141
  Dialog.prototype.generateTitleId = function () {
116
- return 'dialog-title' + kendo_react_common_1.guid();
142
+ return 'dialog-title' + this._id;
117
143
  };
118
144
  /**
119
145
  * @hidden
@@ -135,6 +161,10 @@ var Dialog = /** @class */ (function (_super) {
135
161
  Dialog.defaultProps = {
136
162
  autoFocus: false
137
163
  };
164
+ /**
165
+ * @hidden
166
+ */
167
+ Dialog.contextType = kendo_react_common_1.ZIndexContext;
138
168
  return Dialog;
139
169
  }(React.Component));
140
170
  exports.Dialog = Dialog;
@@ -0,0 +1,63 @@
1
+ /// <reference types="react" />
2
+ import { DialogCloseEvent } from './events';
3
+ /**
4
+ * Represents the props of the [KendoReact Dialog component]({% slug overview_dialog %}).
5
+ */
6
+ export interface DialogProps {
7
+ /**
8
+ * Focus the Dialog container automatically when mounted. By default the autoFocus is false.
9
+ */
10
+ autoFocus?: boolean;
11
+ /**
12
+ * Sets the title of the Dialog ([see example]({% slug title_dialog %})). If `title` is not specified, the Dialog does not render a **Close** button.
13
+ */
14
+ title?: string | React.ReactElement<any>;
15
+ /**
16
+ * Sets a class of the Dialog DOM element.
17
+ */
18
+ className?: string;
19
+ /**
20
+ * Specifies whether a close button should be rendered at the top corner of the dialog.
21
+ */
22
+ closeIcon?: boolean;
23
+ /**
24
+ * Specifies the width of the Dialog ([see example]({% slug dimensions_dialog %})).
25
+ */
26
+ width?: number | string;
27
+ /**
28
+ * Specifies the height of the Dialog ([see example]({% slug dimensions_dialog %})).
29
+ */
30
+ height?: number | string;
31
+ /**
32
+ * Specifies the minimum width of the Dialog.
33
+ */
34
+ minWidth?: number | string;
35
+ /**
36
+ * Fires when the **Close** button in the title is clicked or when the `Esc` button is pressed.
37
+ */
38
+ onClose?: (event: DialogCloseEvent) => void;
39
+ /**
40
+ * @hidden
41
+ */
42
+ children?: React.ReactNode;
43
+ /**
44
+ * Sets the `aria-labelledby` value.
45
+ */
46
+ id?: string;
47
+ /**
48
+ * Represents the `dir` HTML attribute.
49
+ */
50
+ dir?: string;
51
+ /**
52
+ * The styles that are applied to the Dialog.
53
+ */
54
+ style?: React.CSSProperties;
55
+ /**
56
+ * The styles that are applied to the content of the Dialog.
57
+ */
58
+ contentStyle?: React.CSSProperties;
59
+ /**
60
+ * Defines the container to which the Window will be appended. Defaults to its parent element.
61
+ */
62
+ appendTo?: any;
63
+ }
@@ -0,0 +1,4 @@
1
+ "use strict";
2
+ /* eslint-disable max-len */
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ // tslint:enable:max-line-length
@@ -11,13 +11,13 @@ interface WindowState {
11
11
  width: number;
12
12
  height: number;
13
13
  focused: boolean;
14
+ zIndex: number;
14
15
  }
15
16
  export declare class Window extends React.Component<WindowProps, WindowState> {
16
17
  /**
17
18
  * @hidden
18
19
  */
19
20
  static propTypes: {
20
- id: PropTypes.Requireable<string>;
21
21
  width: PropTypes.Requireable<string | number>;
22
22
  height: PropTypes.Requireable<string | number>;
23
23
  left: PropTypes.Requireable<string | number>;
@@ -35,6 +35,7 @@ export declare class Window extends React.Component<WindowProps, WindowState> {
35
35
  stage: PropTypes.Requireable<string>;
36
36
  className: PropTypes.Requireable<string>;
37
37
  style: PropTypes.Requireable<object>;
38
+ overlayStyle: PropTypes.Requireable<object>;
38
39
  };
39
40
  /**
40
41
  * @hidden
@@ -47,10 +48,18 @@ export declare class Window extends React.Component<WindowProps, WindowState> {
47
48
  modal: boolean;
48
49
  doubleClickStageChange: boolean;
49
50
  };
51
+ /**
52
+ * @hidden
53
+ */
54
+ static contextType: React.Context<number>;
55
+ /**
56
+ * **Deprecated.** Use `element` instead.
57
+ */
58
+ windowElement?: HTMLDivElement | null;
50
59
  /**
51
60
  * The Window element.
52
61
  */
53
- windowElement?: any;
62
+ element?: HTMLDivElement | null;
54
63
  /**
55
64
  * @hidden
56
65
  */
@@ -58,6 +67,8 @@ export declare class Window extends React.Component<WindowProps, WindowState> {
58
67
  draggable: Draggable | null;
59
68
  private windowCoordinatesState?;
60
69
  private offSetCoordinates?;
70
+ private _id;
71
+ private _blurTimeout?;
61
72
  constructor(props: WindowProps);
62
73
  /**
63
74
  * @hidden
@@ -71,6 +82,10 @@ export declare class Window extends React.Component<WindowProps, WindowState> {
71
82
  * @hidden
72
83
  */
73
84
  componentDidUpdate(): void;
85
+ /**
86
+ * @hidden
87
+ */
88
+ onKeyDown: (event: any) => void;
74
89
  /**
75
90
  * @hidden
76
91
  */
@@ -86,13 +101,20 @@ export declare class Window extends React.Component<WindowProps, WindowState> {
86
101
  /**
87
102
  * @hidden
88
103
  */
89
- render(): JSX.Element;
104
+ onFocus: () => void;
105
+ /**
106
+ * @hidden
107
+ */
108
+ onBlur: () => void;
109
+ /**
110
+ * @hidden
111
+ */
112
+ render(): React.ReactPortal;
90
113
  private readonly top;
91
114
  private readonly left;
92
115
  private readonly width;
93
116
  private readonly height;
94
117
  private readonly windowStage;
95
- private handleKeyDown;
96
118
  private getInitialTop;
97
119
  private getInitialLeft;
98
120
  private getInitialWidth;
@@ -107,6 +129,8 @@ export declare class Window extends React.Component<WindowProps, WindowState> {
107
129
  private handleBrowserWindowResize;
108
130
  private getActionBar;
109
131
  private getContent;
110
- private setZindex;
132
+ private getCurrentZIndex;
133
+ private getDocument;
134
+ private getWindow;
111
135
  }
112
136
  export {};