@progress/kendo-react-popup 4.14.0-dev.202201140931 → 4.14.1-dev.202201181415

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.
package/dist/es/Popup.js CHANGED
@@ -1,16 +1,3 @@
1
- var __extends = (this && this.__extends) || (function () {
2
- var extendStatics = function (d, b) {
3
- 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 extendStatics(d, b);
7
- };
8
- return function (d, b) {
9
- extendStatics(d, b);
10
- function __() { this.constructor = d; }
11
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
12
- };
13
- })();
14
1
  var __assign = (this && this.__assign) || function () {
15
2
  __assign = Object.assign || function(t) {
16
3
  for (var s, i = 1, n = arguments.length; i < n; i++) {
@@ -23,372 +10,25 @@ var __assign = (this && this.__assign) || function () {
23
10
  return __assign.apply(this, arguments);
24
11
  };
25
12
  import * as React from 'react';
26
- import * as ReactDOM from 'react-dom';
27
- import * as PropTypes from 'prop-types';
28
- import { slide } from './animation';
29
- import { classNames, canUseDOM, ZIndexContext, validatePackage } from '@progress/kendo-react-common';
30
- import { AlignPoint, alignElement, domUtils, positionElement } from '@progress/kendo-popup-common';
31
- import { CollisionType, throttle, FRAME_DURATION } from './util';
32
- import { packageMetadata } from './package-metadata';
33
- var DEFAULT_POPUP_ZINDEX = 100;
34
- var ZINDEX_POPUP_STEP = 1;
35
- function isEquivalent(a, b) {
36
- if (a === b) {
37
- return true;
38
- }
39
- if (!!a !== !!b) {
40
- return false;
41
- }
42
- var aProps = Object.getOwnPropertyNames(a);
43
- var bProps = Object.getOwnPropertyNames(b);
44
- if (aProps.length !== bProps.length) {
45
- return false;
46
- }
47
- for (var i = 0; i < aProps.length; i++) {
48
- var propName = aProps[i];
49
- if (a[propName] !== b[propName]) {
50
- return false;
51
- }
52
- }
53
- return true;
54
- }
55
- var DEFAULT_OFFSET = {
56
- left: -1000,
57
- top: 0
58
- };
59
- var Status;
60
- (function (Status) {
61
- Status["hiding"] = "hiding";
62
- Status["hidden"] = "hidden";
63
- Status["showing"] = "showing";
64
- Status["shown"] = "shown";
65
- Status["reposition"] = "reposition";
66
- })(Status || (Status = {}));
67
- var ANIMATION_CONTAINER = 'k-animation-container';
68
- var ANIMATION_CONTAINER_SHOWN = 'k-animation-container-shown';
69
- var ANIMATION_CONTAINER_RELATIVE = 'k-animation-container-relative';
70
- var ANIMATION_CONTAINER_CHILD = 'k-child-animation-container';
71
- var K_POPUP = 'k-popup';
13
+ import { PopupWithoutContext } from './PopupWithoutContext';
72
14
  /**
73
- * @hidden
15
+ * The PopupPropsContext. It allows to configure the Popup props from a wrapper component.
16
+ *
17
+ * @example
18
+ * ```jsx-no-run
19
+ * <PopupPropsContext.Provider value={props => ({ ...props, appendTo: document.querySelector('myPopupsContainer') })}>
20
+ * <DropDownList />
21
+ * <Editor />
22
+ * </PopupPropsContext.Provider>
23
+ * ```
74
24
  */
75
- var Popup = /** @class */ (function (_super) {
76
- __extends(Popup, _super);
77
- function Popup(props) {
78
- var _this = _super.call(this, props) || this;
79
- /**
80
- * @hidden
81
- */
82
- _this.state = { current: Status.hidden, previous: Status.hidden, props: {} };
83
- _this._popup = null;
84
- _this.show = function (popup) {
85
- _this.setPosition(popup);
86
- _this.animate(popup.firstChild, 'enter', _this.onOpened);
87
- _this.setState({ current: Status.shown, previous: _this.state.current });
88
- };
89
- _this.setPosition = function (popup) {
90
- var _a = _this.props, anchorAlign = _a.anchorAlign, popupAlign = _a.popupAlign, collision = _a.collision, offset = _a.offset, anchor = _a.anchor, margin = _a.margin, scale = _a.scale, positionMode = _a.positionMode;
91
- popup.style.top = '0px';
92
- popup.style.left = '-10000px';
93
- var alignedOffset = alignElement({
94
- anchor: anchor,
95
- element: popup,
96
- elementAlign: popupAlign,
97
- anchorAlign: anchorAlign,
98
- offset: offset,
99
- margin: margin,
100
- positionMode: positionMode,
101
- scale: scale
102
- });
103
- var position = positionElement({
104
- anchor: anchor,
105
- anchorAlign: anchorAlign,
106
- collisions: collision,
107
- element: popup,
108
- currentLocation: alignedOffset,
109
- elementAlign: popupAlign,
110
- margin: _this.props.margin
111
- });
112
- popup.style.top = position.offset.top + 'px';
113
- popup.style.left = position.offset.left + 'px';
114
- _this._flipped = position.flipped;
115
- };
116
- _this.onOpened = function () {
117
- var element = _this._popup;
118
- if (!element) {
119
- return;
120
- }
121
- if (_this.props.show) {
122
- element.classList.add(ANIMATION_CONTAINER_SHOWN);
123
- }
124
- _this.attachRepositionHandlers(element);
125
- if (_this.props.onOpen) {
126
- _this.props.onOpen.call(undefined, { target: _this });
127
- }
128
- };
129
- _this.animate = function (element, type, callback) {
130
- slide(element, _this._flipped ? 'up' : 'down', _this.animationDuration[type], type, callback);
131
- };
132
- _this.onClosing = function (popup) {
133
- if (!_this.props.show) {
134
- popup.classList.remove(ANIMATION_CONTAINER_SHOWN);
135
- }
136
- _this.detachRepositionHandlers();
137
- };
138
- _this.onClosed = function () {
139
- if (_this.state.current === Status.hiding && _this.state.previous === Status.shown) {
140
- _this.setState({ current: Status.hidden, previous: _this.state.current });
141
- }
142
- if (_this.props.onClose) {
143
- _this.props.onClose.call(undefined, { target: _this });
144
- }
145
- };
146
- _this.getCurrentZIndex = function () {
147
- return _this.context ? _this.context + ZINDEX_POPUP_STEP : DEFAULT_POPUP_ZINDEX;
148
- };
149
- validatePackage(packageMetadata);
150
- _this.reposition = throttle(_this.reposition.bind(_this), FRAME_DURATION);
151
- return _this;
152
- }
153
- /**
154
- * @hidden
155
- */
156
- Popup.getDerivedStateFromProps = function (props, state) {
157
- var show = props.show, anchor = props.anchor, anchorAlign = props.anchorAlign, appendTo = props.appendTo, collision = props.collision, popupAlign = props.popupAlign, className = props.className, popupClass = props.popupClass, style = props.style, offset = props.offset, contentKey = props.contentKey;
158
- var nextState = __assign({}, state, { props: {
159
- show: show, anchor: anchor, anchorAlign: anchorAlign, appendTo: appendTo, collision: collision, popupAlign: popupAlign, className: className, popupClass: popupClass, style: style, offset: offset, contentKey: contentKey
160
- } });
161
- if (props.show) {
162
- if (state.current === Status.hidden || state.current === Status.hiding) {
163
- return __assign({}, nextState, { current: Status.showing, previous: state.current });
164
- }
165
- if (state.current === Status.showing) {
166
- return __assign({}, nextState, { current: Status.shown, previous: state.current });
167
- }
168
- if (state.current === Status.shown &&
169
- (!isEquivalent(offset, state.props.offset) ||
170
- !isEquivalent(anchorAlign, state.props.anchorAlign) ||
171
- !isEquivalent(appendTo, state.props.appendTo) ||
172
- !isEquivalent(collision, state.props.collision) ||
173
- !isEquivalent(popupAlign, state.props.popupAlign) ||
174
- !isEquivalent(style, state.props.style) ||
175
- anchor !== state.props.anchor ||
176
- popupClass !== state.props.popupClass ||
177
- className !== state.props.className)) {
178
- return __assign({}, nextState, { current: Status.reposition, previous: state.current });
179
- }
180
- return nextState;
181
- }
182
- if (state.current === Status.hiding || state.current === Status.hidden) {
183
- return __assign({}, nextState, { current: Status.hidden, previous: state.current });
184
- }
185
- return __assign({}, nextState, { current: Status.hiding, previous: state.current });
186
- };
187
- /**
188
- * @hidden
189
- */
190
- Popup.prototype.componentDidUpdate = function (prevProps) {
191
- if (this.state.current === Status.showing && this._popup) {
192
- this.show(this._popup);
193
- }
194
- else if (this.state.current === Status.hiding && this._popup) {
195
- this.onClosing(this._popup);
196
- this.animate(this._popup.firstChild, 'exit', this.onClosed);
197
- }
198
- else if (this.state.current === Status.reposition && this.state.previous === Status.shown) {
199
- this.setState({ current: Status.shown, previous: this.state.current });
200
- }
201
- else if (this.state.current === Status.shown &&
202
- prevProps.contentKey !== this.props.contentKey && this._popup) {
203
- this.setPosition(this._popup);
204
- }
205
- };
206
- /**
207
- * @hidden
208
- */
209
- Popup.prototype.componentDidMount = function () {
210
- if (this.state.current === Status.showing && this._popup) {
211
- this.show(this._popup);
212
- }
213
- };
214
- /**
215
- * @hidden
216
- */
217
- Popup.prototype.componentWillUnmount = function () {
218
- this.detachRepositionHandlers();
219
- };
220
- /**
221
- * @hidden
222
- */
223
- Popup.prototype.render = function () {
224
- var _this = this;
225
- var _a = this.props, children = _a.children, className = _a.className, popupClass = _a.popupClass, show = _a.show, id = _a.id, positionMode = _a.positionMode;
226
- var appendTo = this.props.appendTo ?
227
- this.props.appendTo :
228
- canUseDOM ?
229
- (this.props.anchor && this.props.anchor.ownerDocument ? this.props.anchor.ownerDocument.body : document.body)
230
- : undefined;
231
- if (this.state.current === Status.reposition && this.state.previous === Status.shown && this._popup) {
232
- this.setPosition(this._popup);
233
- }
234
- var style = Object.assign({}, { position: positionMode }, this.props.style || {});
235
- var closing = this.state.current === Status.hiding;
236
- if ((show || closing) && appendTo) {
237
- var currentZIndex = this.getCurrentZIndex();
238
- var popupElement = (React.createElement(ZIndexContext.Provider, { value: currentZIndex },
239
- React.createElement("div", { className: classNames(ANIMATION_CONTAINER, ANIMATION_CONTAINER_RELATIVE, className), id: id, ref: function (e) { return _this._popup = e; }, style: __assign({ zIndex: currentZIndex }, style) },
240
- React.createElement("div", { className: classNames(popupClass, K_POPUP, ANIMATION_CONTAINER_CHILD), style: { transitionDelay: '0ms' } }, children))));
241
- return ReactDOM.createPortal(popupElement, appendTo);
242
- }
243
- return null;
244
- };
245
- Object.defineProperty(Popup.prototype, "animationDuration", {
246
- get: function () {
247
- var animate = this.props.animate;
248
- var enter = 0;
249
- var exit = 0;
250
- if (animate) {
251
- if (animate === true) {
252
- enter = exit = 300;
253
- }
254
- else {
255
- enter = animate.openDuration || 0;
256
- exit = animate.closeDuration || 0;
257
- }
258
- }
259
- return { enter: enter, exit: exit };
260
- },
261
- enumerable: true,
262
- configurable: true
263
- });
264
- Popup.prototype.attachRepositionHandlers = function (element) {
265
- var _this = this;
266
- this.detachRepositionHandlers();
267
- this._scrollableParents = domUtils.scrollableParents(this.props.anchor || element);
268
- this._scrollableParents.map(function (p) { return p.addEventListener('scroll', _this.reposition); });
269
- window.addEventListener('resize', this.reposition);
270
- };
271
- Popup.prototype.detachRepositionHandlers = function () {
272
- var _this = this;
273
- if (this._scrollableParents) {
274
- this._scrollableParents.map(function (p) { return p.removeEventListener('scroll', _this.reposition); });
275
- this._scrollableParents = undefined;
276
- }
277
- window.removeEventListener('resize', this.reposition);
278
- };
279
- Popup.prototype.reposition = function () {
280
- this.setState({ current: Status.reposition, previous: this.state.current });
281
- };
282
- /**
283
- * @hidden
284
- */
285
- Popup.propTypes = {
286
- anchor: function (props) {
287
- var anchor = props.anchor;
288
- if (anchor && typeof anchor.nodeType !== 'number') {
289
- return new Error('Invalid prop `anchor` supplied to `Kendo React Popup`. Validation failed.');
290
- }
291
- return null;
292
- },
293
- appendTo: function (props) {
294
- var element = props.appendTo;
295
- if (element && typeof element.nodeType !== 'number') {
296
- return new Error('Invalid prop `appendTo` supplied to `Kendo React Popup`. Validation failed.');
297
- }
298
- return null;
299
- },
300
- className: PropTypes.string,
301
- id: PropTypes.string,
302
- popupClass: PropTypes.string,
303
- collision: PropTypes.shape({
304
- horizontal: PropTypes.oneOf([
305
- CollisionType.fit,
306
- CollisionType.flip
307
- ]),
308
- vertical: PropTypes.oneOf([
309
- CollisionType.fit,
310
- CollisionType.flip
311
- ])
312
- }),
313
- anchorAlign: PropTypes.shape({
314
- horizontal: PropTypes.oneOf([
315
- AlignPoint.left,
316
- AlignPoint.center,
317
- AlignPoint.right
318
- ]),
319
- vertical: PropTypes.oneOf([
320
- AlignPoint.top,
321
- AlignPoint.center,
322
- AlignPoint.bottom
323
- ])
324
- }),
325
- popupAlign: PropTypes.shape({
326
- horizontal: PropTypes.oneOf([
327
- AlignPoint.left,
328
- AlignPoint.center,
329
- AlignPoint.right
330
- ]),
331
- vertical: PropTypes.oneOf([
332
- AlignPoint.top,
333
- AlignPoint.center,
334
- AlignPoint.bottom
335
- ])
336
- }),
337
- offset: PropTypes.shape({
338
- left: PropTypes.number,
339
- top: PropTypes.number
340
- }),
341
- children: PropTypes.oneOfType([
342
- PropTypes.element,
343
- PropTypes.node
344
- ]),
345
- show: PropTypes.bool,
346
- animate: PropTypes.oneOfType([
347
- PropTypes.bool,
348
- PropTypes.shape({
349
- openDuration: PropTypes.number,
350
- closeDuration: PropTypes.number
351
- })
352
- ]),
353
- margin: PropTypes.shape({
354
- horizontal: PropTypes.number,
355
- vertical: PropTypes.number
356
- }),
357
- positionMode: PropTypes.oneOf([
358
- 'fixed',
359
- 'absolute'
360
- ]),
361
- scale: PropTypes.number
362
- };
363
- /**
364
- * @hidden
365
- */
366
- Popup.defaultProps = {
367
- collision: {
368
- horizontal: CollisionType.fit,
369
- vertical: CollisionType.flip
370
- },
371
- anchorAlign: {
372
- horizontal: AlignPoint.left,
373
- vertical: AlignPoint.bottom
374
- },
375
- popupAlign: {
376
- horizontal: AlignPoint.left,
377
- vertical: AlignPoint.top
378
- },
379
- offset: DEFAULT_OFFSET,
380
- animate: true,
381
- show: false,
382
- margin: {
383
- horizontal: 0,
384
- vertical: 0
385
- },
386
- positionMode: 'absolute'
387
- };
388
- /**
389
- * @hidden
390
- */
391
- Popup.contextType = ZIndexContext;
392
- return Popup;
393
- }(React.Component));
394
- export { Popup };
25
+ export var PopupPropsContext = React.createContext(function (props) { return props; });
26
+ /**
27
+ * The KendoReact Popup component.
28
+ */
29
+ export var Popup = React.forwardRef(function (props, ref) {
30
+ var contextPropsCallback = React.useContext(PopupPropsContext);
31
+ var popupProps = contextPropsCallback.call(undefined, props);
32
+ return (React.createElement(PopupWithoutContext, __assign({ ref: ref }, popupProps)));
33
+ });
34
+ Popup.displayName = 'Popup';
@@ -0,0 +1,174 @@
1
+ import * as React from 'react';
2
+ import * as PropTypes from 'prop-types';
3
+ import { Offset } from './models/Offset';
4
+ import { PopupProps } from './models/PopupProps';
5
+ import { Align } from './models/Align';
6
+ import { Collision } from './models/Collision';
7
+ declare enum Status {
8
+ hiding = "hiding",
9
+ hidden = "hidden",
10
+ showing = "showing",
11
+ shown = "shown",
12
+ reposition = "reposition"
13
+ }
14
+ /**
15
+ * @hidden
16
+ */
17
+ export interface PopupState {
18
+ current: Status;
19
+ previous: Status;
20
+ props: {
21
+ show?: boolean;
22
+ anchor?: HTMLElement;
23
+ anchorAlign?: Align;
24
+ appendTo?: HTMLElement;
25
+ collision?: Collision;
26
+ popupAlign?: Align;
27
+ className?: string | Array<string>;
28
+ popupClass?: string | Array<string>;
29
+ style?: React.CSSProperties;
30
+ offset?: Offset;
31
+ contentKey?: any;
32
+ };
33
+ }
34
+ /**
35
+ * @hidden
36
+ */
37
+ export declare class PopupWithoutContext extends React.Component<PopupProps, PopupState> {
38
+ /**
39
+ * @hidden
40
+ */
41
+ static propTypes: {
42
+ anchor: (props: PopupProps) => Error;
43
+ appendTo: (props: PopupProps) => Error;
44
+ className: PropTypes.Requireable<string | object>;
45
+ id: PropTypes.Requireable<string>;
46
+ popupClass: PropTypes.Requireable<string | object>;
47
+ collision: PropTypes.Requireable<PropTypes.InferProps<{
48
+ horizontal: PropTypes.Requireable<string>;
49
+ vertical: PropTypes.Requireable<string>;
50
+ }>>;
51
+ anchorAlign: PropTypes.Requireable<PropTypes.InferProps<{
52
+ horizontal: PropTypes.Requireable<string>;
53
+ vertical: PropTypes.Requireable<string>;
54
+ }>>;
55
+ popupAlign: PropTypes.Requireable<PropTypes.InferProps<{
56
+ horizontal: PropTypes.Requireable<string>;
57
+ vertical: PropTypes.Requireable<string>;
58
+ }>>;
59
+ offset: PropTypes.Requireable<PropTypes.InferProps<{
60
+ left: PropTypes.Requireable<number>;
61
+ top: PropTypes.Requireable<number>;
62
+ }>>;
63
+ children: PropTypes.Requireable<PropTypes.ReactNodeLike>;
64
+ show: PropTypes.Requireable<boolean>;
65
+ animate: PropTypes.Requireable<boolean | PropTypes.InferProps<{
66
+ openDuration: PropTypes.Requireable<number>;
67
+ closeDuration: PropTypes.Requireable<number>;
68
+ }>>;
69
+ margin: PropTypes.Requireable<PropTypes.InferProps<{
70
+ horizontal: PropTypes.Requireable<number>;
71
+ vertical: PropTypes.Requireable<number>;
72
+ }>>;
73
+ positionMode: PropTypes.Requireable<string>;
74
+ scale: PropTypes.Requireable<number>;
75
+ style: PropTypes.Requireable<object>;
76
+ onClose: PropTypes.Requireable<(...args: any[]) => any>;
77
+ onPosition: PropTypes.Requireable<(...args: any[]) => any>;
78
+ onOpen: PropTypes.Requireable<(...args: any[]) => any>;
79
+ };
80
+ /**
81
+ * @hidden
82
+ */
83
+ static defaultProps: {
84
+ collision: {
85
+ horizontal: string;
86
+ vertical: string;
87
+ };
88
+ anchorAlign: {
89
+ horizontal: string;
90
+ vertical: string;
91
+ };
92
+ popupAlign: {
93
+ horizontal: string;
94
+ vertical: string;
95
+ };
96
+ offset: {
97
+ left: number;
98
+ top: number;
99
+ };
100
+ animate: boolean;
101
+ show: boolean;
102
+ margin: {
103
+ horizontal: number;
104
+ vertical: number;
105
+ };
106
+ positionMode: string;
107
+ };
108
+ /**
109
+ * @hidden
110
+ */
111
+ static contextType: React.Context<number>;
112
+ /**
113
+ * @hidden
114
+ */
115
+ static displayName: string;
116
+ /**
117
+ * @hidden
118
+ */
119
+ readonly state: PopupState;
120
+ private _collisions;
121
+ private _scrollableParents;
122
+ private _popup;
123
+ constructor(props: PopupProps);
124
+ /**
125
+ * @hidden
126
+ */
127
+ static getDerivedStateFromProps(props: PopupProps, state: PopupState): {
128
+ props: {
129
+ show: boolean;
130
+ anchor: HTMLElement;
131
+ anchorAlign: Align;
132
+ appendTo: HTMLElement;
133
+ collision: Collision;
134
+ popupAlign: Align;
135
+ className: string | string[];
136
+ popupClass: string | string[] | {
137
+ [key: string]: boolean;
138
+ };
139
+ style: React.CSSProperties;
140
+ offset: Offset;
141
+ contentKey: any;
142
+ };
143
+ current: Status;
144
+ previous: Status;
145
+ };
146
+ /**
147
+ * @hidden
148
+ */
149
+ componentDidUpdate(prevProps: PopupProps): void;
150
+ /**
151
+ * @hidden
152
+ */
153
+ componentDidMount(): void;
154
+ /**
155
+ * @hidden
156
+ */
157
+ componentWillUnmount(): void;
158
+ /**
159
+ * @hidden
160
+ */
161
+ render(): React.ReactPortal;
162
+ private show;
163
+ private setPosition;
164
+ private onOpened;
165
+ private animate;
166
+ private onClosing;
167
+ private onClosed;
168
+ private readonly animationDuration;
169
+ private attachRepositionHandlers;
170
+ private detachRepositionHandlers;
171
+ private reposition;
172
+ private getCurrentZIndex;
173
+ }
174
+ export {};