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

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