@instructure/ui-popover 8.25.1-snapshot-7 → 8.25.1-snapshot-10

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/CHANGELOG.md CHANGED
@@ -3,7 +3,7 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
- ## [8.25.1-snapshot-7](https://github.com/instructure/instructure-ui/compare/v8.25.0...v8.25.1-snapshot-7) (2022-06-13)
6
+ ## [8.25.1-snapshot-10](https://github.com/instructure/instructure-ui/compare/v8.25.0...v8.25.1-snapshot-10) (2022-06-20)
7
7
 
8
8
  **Note:** Version bump only for package @instructure/ui-popover
9
9
 
@@ -1,4 +1,4 @@
1
- var _dec, _dec2, _dec3, _class, _class2;
1
+ var _dec, _dec2, _dec3, _class;
2
2
 
3
3
  /*
4
4
  * The MIT License (MIT)
@@ -44,160 +44,35 @@ tags: overlay, portal, dialog
44
44
  @tsProps
45
45
  **/
46
46
 
47
- let Popover = (_dec = withDeterministicId(), _dec2 = textDirectionContextConsumer(), _dec3 = testable(), _dec(_class = _dec2(_class = _dec3(_class = (_class2 = class Popover extends Component {
48
- constructor(props) {
49
- var _this;
47
+ let Popover = (_dec = withDeterministicId(), _dec2 = textDirectionContextConsumer(), _dec3 = testable(), _dec(_class = _dec2(_class = _dec3(_class = class Popover extends Component {
48
+ static displayName = "Popover";
49
+ static componentId = 'Popover';
50
+ static allowedProps = allowedProps;
51
+ static propTypes = propTypes;
52
+ static defaultProps = {
53
+ defaultIsShowingContent: false,
54
+ placement: 'bottom center',
55
+ stacking: 'topmost',
56
+ shadow: 'resting',
57
+ offsetX: 0,
58
+ offsetY: 0,
59
+ color: 'primary',
60
+ on: ['hover', 'focus'],
61
+ withArrow: true,
62
+ constrain: 'window',
63
+ insertAt: 'bottom',
64
+ shouldAlignArrow: false,
65
+ shouldTrackPosition: true,
66
+ shouldRenderOffscreen: false,
67
+ shouldContainFocus: false,
68
+ shouldReturnFocus: true,
69
+ shouldCloseOnDocumentClick: true,
70
+ shouldFocusContentOnTriggerBlur: false,
71
+ shouldCloseOnEscape: true
72
+ };
50
73
 
74
+ constructor(props) {
51
75
  super(props);
52
- _this = this;
53
- this._handleMouseOver = void 0;
54
- this._handleMouseOut = void 0;
55
- this._id = void 0;
56
- this._raf = [];
57
- this._trigger = null;
58
- this._view = null;
59
- this._dialog = null;
60
- this._contentElement = null;
61
- this._focusRegion = void 0;
62
- this.mouseOutTimeout = void 0;
63
- this.ref = null;
64
-
65
- this.handleRef = el => {
66
- const elementRef = this.props.elementRef;
67
- this.ref = el;
68
-
69
- if (typeof elementRef === 'function') {
70
- elementRef(el);
71
- }
72
- };
73
-
74
- this.show = event => {
75
- var _this$props$onShowCon, _this$props;
76
-
77
- if (typeof this.props.isShowingContent === 'undefined') {
78
- this.setState({
79
- isShowingContent: true
80
- });
81
- }
82
-
83
- (_this$props$onShowCon = (_this$props = this.props).onShowContent) === null || _this$props$onShowCon === void 0 ? void 0 : _this$props$onShowCon.call(_this$props, event);
84
- };
85
-
86
- this.hide = function (event) {
87
- let documentClick = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : false;
88
- const _this$props2 = _this.props,
89
- onHideContent = _this$props2.onHideContent,
90
- isShowingContent = _this$props2.isShowingContent;
91
-
92
- if (typeof isShowingContent === 'undefined') {
93
- // uncontrolled, set state, fire callbacks
94
- _this.setState(_ref => {
95
- let isShowingContent = _ref.isShowingContent;
96
-
97
- if (isShowingContent) {
98
- onHideContent === null || onHideContent === void 0 ? void 0 : onHideContent(event, {
99
- documentClick
100
- });
101
- }
102
-
103
- return {
104
- isShowingContent: false
105
- };
106
- });
107
- } else if (isShowingContent) {
108
- // controlled, fire callback
109
- onHideContent === null || onHideContent === void 0 ? void 0 : onHideContent(event, {
110
- documentClick
111
- });
112
- }
113
- };
114
-
115
- this.toggle = event => {
116
- if (this.shown) {
117
- this.hide(event);
118
- } else {
119
- this.show(event);
120
- }
121
- };
122
-
123
- this.handleDialogDismiss = (event, documentClick) => {
124
- if (!this.props.shouldReturnFocus && this.props.shouldFocusContentOnTriggerBlur) {
125
- const trigger = findDOMNode(this._trigger);
126
-
127
- if (trigger && typeof trigger.focus === 'function') {
128
- ;
129
- trigger.focus();
130
- }
131
- }
132
-
133
- this.hide(event, documentClick);
134
- };
135
-
136
- this.handleDialogBlur = event => {
137
- if (event.keyCode === keycode.codes.tab && event.shiftKey && this.props.shouldFocusContentOnTriggerBlur) {
138
- return;
139
- }
140
-
141
- this.hide(event);
142
- };
143
-
144
- this.handleTriggerKeyDown = event => {
145
- if (!this.props.shouldFocusContentOnTriggerBlur) {
146
- return;
147
- }
148
-
149
- if (event.keyCode === keycode.codes.tab && !event.shiftKey) {
150
- event.preventDefault();
151
-
152
- this._raf.push(requestAnimationFrame(() => {
153
- this._dialog && this._dialog.focus();
154
- }));
155
- }
156
- };
157
-
158
- this.handleTriggerKeyUp = event => {
159
- if (event.keyCode === keycode.codes.esc && this.shown && this.isTooltip) {
160
- // if popover is tooltip, it is managing its own focus region so we need
161
- // to prevent esc keyup event from reaching FocusRegionManager
162
- event.preventDefault();
163
- this.hide(event);
164
- }
165
- };
166
-
167
- this.handleTriggerBlur = event => {
168
- const on = this.props.on;
169
-
170
- if (on && on.indexOf('focus') > -1) {
171
- this._raf.push(requestAnimationFrame(() => {
172
- if (!containsActiveElement(this._view)) {
173
- this.hide(event);
174
- }
175
- }));
176
- }
177
- };
178
-
179
- this.handlePositioned = position => {
180
- var _this$props$onPositio, _this$props3;
181
-
182
- const placement = position.placement;
183
- this.setState({
184
- placement,
185
- ...this.computeOffsets(placement)
186
- });
187
- (_this$props$onPositio = (_this$props3 = this.props).onPositioned) === null || _this$props$onPositio === void 0 ? void 0 : _this$props$onPositio.call(_this$props3, position);
188
- };
189
-
190
- this.handlePositionChanged = position => {
191
- var _this$props$onPositio2, _this$props4;
192
-
193
- const placement = position.placement;
194
- this.setState({
195
- placement,
196
- ...this.computeOffsets(placement)
197
- });
198
- (_this$props$onPositio2 = (_this$props4 = this.props).onPositionChanged) === null || _this$props$onPositio2 === void 0 ? void 0 : _this$props$onPositio2.call(_this$props4, position);
199
- };
200
-
201
76
  this.state = {
202
77
  placement: props.placement,
203
78
  offsetX: props.offsetX,
@@ -218,6 +93,26 @@ let Popover = (_dec = withDeterministicId(), _dec2 = textDirectionContextConsume
218
93
  });
219
94
  }
220
95
 
96
+ _handleMouseOver;
97
+ _handleMouseOut;
98
+ _id;
99
+ _raf = [];
100
+ _trigger = null;
101
+ _view = null;
102
+ _dialog = null;
103
+ _contentElement = null;
104
+ _focusRegion;
105
+ mouseOutTimeout;
106
+ ref = null;
107
+ handleRef = el => {
108
+ const elementRef = this.props.elementRef;
109
+ this.ref = el;
110
+
111
+ if (typeof elementRef === 'function') {
112
+ elementRef(el);
113
+ }
114
+ };
115
+
221
116
  get isTooltip() {
222
117
  return this.props.shouldRenderOffscreen && !this.props.shouldReturnFocus && !this.props.shouldContainFocus && !this.props.shouldFocusContentOnTriggerBlur;
223
118
  }
@@ -282,19 +177,19 @@ let Popover = (_dec = withDeterministicId(), _dec2 = textDirectionContextConsume
282
177
  }
283
178
 
284
179
  computeOffsets(placement) {
285
- let _this$props5 = this.props,
286
- offsetX = _this$props5.offsetX,
287
- offsetY = _this$props5.offsetY;
180
+ let _this$props = this.props,
181
+ offsetX = _this$props.offsetX,
182
+ offsetY = _this$props.offsetY;
288
183
 
289
184
  if (this.props.shouldAlignArrow && this._view) {
290
185
  const secondaryPlacement = parsePlacement(placement)[1]; // arrowSize and arrowBorderWidth are component theme variables
291
186
  // declared in ContextView's styles.js
292
187
 
293
- const _ref2 = this._view.props.styles,
294
- _ref2$arrowSize = _ref2.arrowSize,
295
- arrowSize = _ref2$arrowSize === void 0 ? 0 : _ref2$arrowSize,
296
- _ref2$arrowBorderWidt = _ref2.arrowBorderWidth,
297
- arrowBorderWidth = _ref2$arrowBorderWidt === void 0 ? 0 : _ref2$arrowBorderWidt;
188
+ const _ref = this._view.props.styles,
189
+ _ref$arrowSize = _ref.arrowSize,
190
+ arrowSize = _ref$arrowSize === void 0 ? 0 : _ref$arrowSize,
191
+ _ref$arrowBorderWidth = _ref.arrowBorderWidth,
192
+ arrowBorderWidth = _ref$arrowBorderWidth === void 0 ? 0 : _ref$arrowBorderWidth;
298
193
  const offsetAmount = (px(arrowSize) + px(arrowBorderWidth)) * 2;
299
194
 
300
195
  if (secondaryPlacement === 'start') {
@@ -350,6 +245,128 @@ let Popover = (_dec = withDeterministicId(), _dec2 = textDirectionContextConsume
350
245
  return this.props.defaultFocusElement;
351
246
  }
352
247
 
248
+ show = event => {
249
+ var _this$props$onShowCon, _this$props2;
250
+
251
+ if (typeof this.props.isShowingContent === 'undefined') {
252
+ this.setState({
253
+ isShowingContent: true
254
+ });
255
+ }
256
+
257
+ (_this$props$onShowCon = (_this$props2 = this.props).onShowContent) === null || _this$props$onShowCon === void 0 ? void 0 : _this$props$onShowCon.call(_this$props2, event);
258
+ };
259
+ hide = (() => {
260
+ var _this = this;
261
+
262
+ return function (event) {
263
+ let documentClick = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : false;
264
+ const _this$props3 = _this.props,
265
+ onHideContent = _this$props3.onHideContent,
266
+ isShowingContent = _this$props3.isShowingContent;
267
+
268
+ if (typeof isShowingContent === 'undefined') {
269
+ // uncontrolled, set state, fire callbacks
270
+ _this.setState(_ref2 => {
271
+ let isShowingContent = _ref2.isShowingContent;
272
+
273
+ if (isShowingContent) {
274
+ onHideContent === null || onHideContent === void 0 ? void 0 : onHideContent(event, {
275
+ documentClick
276
+ });
277
+ }
278
+
279
+ return {
280
+ isShowingContent: false
281
+ };
282
+ });
283
+ } else if (isShowingContent) {
284
+ // controlled, fire callback
285
+ onHideContent === null || onHideContent === void 0 ? void 0 : onHideContent(event, {
286
+ documentClick
287
+ });
288
+ }
289
+ };
290
+ })();
291
+ toggle = event => {
292
+ if (this.shown) {
293
+ this.hide(event);
294
+ } else {
295
+ this.show(event);
296
+ }
297
+ };
298
+ handleDialogDismiss = (event, documentClick) => {
299
+ if (!this.props.shouldReturnFocus && this.props.shouldFocusContentOnTriggerBlur) {
300
+ const trigger = findDOMNode(this._trigger);
301
+
302
+ if (trigger && typeof trigger.focus === 'function') {
303
+ ;
304
+ trigger.focus();
305
+ }
306
+ }
307
+
308
+ this.hide(event, documentClick);
309
+ };
310
+ handleDialogBlur = event => {
311
+ if (event.keyCode === keycode.codes.tab && event.shiftKey && this.props.shouldFocusContentOnTriggerBlur) {
312
+ return;
313
+ }
314
+
315
+ this.hide(event);
316
+ };
317
+ handleTriggerKeyDown = event => {
318
+ if (!this.props.shouldFocusContentOnTriggerBlur) {
319
+ return;
320
+ }
321
+
322
+ if (event.keyCode === keycode.codes.tab && !event.shiftKey) {
323
+ event.preventDefault();
324
+
325
+ this._raf.push(requestAnimationFrame(() => {
326
+ this._dialog && this._dialog.focus();
327
+ }));
328
+ }
329
+ };
330
+ handleTriggerKeyUp = event => {
331
+ if (event.keyCode === keycode.codes.esc && this.shown && this.isTooltip) {
332
+ // if popover is tooltip, it is managing its own focus region so we need
333
+ // to prevent esc keyup event from reaching FocusRegionManager
334
+ event.preventDefault();
335
+ this.hide(event);
336
+ }
337
+ };
338
+ handleTriggerBlur = event => {
339
+ const on = this.props.on;
340
+
341
+ if (on && on.indexOf('focus') > -1) {
342
+ this._raf.push(requestAnimationFrame(() => {
343
+ if (!containsActiveElement(this._view)) {
344
+ this.hide(event);
345
+ }
346
+ }));
347
+ }
348
+ };
349
+ handlePositioned = position => {
350
+ var _this$props$onPositio, _this$props4;
351
+
352
+ const placement = position.placement;
353
+ this.setState({
354
+ placement,
355
+ ...this.computeOffsets(placement)
356
+ });
357
+ (_this$props$onPositio = (_this$props4 = this.props).onPositioned) === null || _this$props$onPositio === void 0 ? void 0 : _this$props$onPositio.call(_this$props4, position);
358
+ };
359
+ handlePositionChanged = position => {
360
+ var _this$props$onPositio2, _this$props5;
361
+
362
+ const placement = position.placement;
363
+ this.setState({
364
+ placement,
365
+ ...this.computeOffsets(placement)
366
+ });
367
+ (_this$props$onPositio2 = (_this$props5 = this.props).onPositionChanged) === null || _this$props$onPositio2 === void 0 ? void 0 : _this$props$onPositio2.call(_this$props5, position);
368
+ };
369
+
353
370
  renderTrigger() {
354
371
  let trigger = callRenderProp(this.props.renderTrigger);
355
372
 
@@ -494,26 +511,6 @@ let Popover = (_dec = withDeterministicId(), _dec2 = textDirectionContextConsume
494
511
  }
495
512
  }
496
513
 
497
- }, _class2.displayName = "Popover", _class2.componentId = 'Popover', _class2.allowedProps = allowedProps, _class2.propTypes = propTypes, _class2.defaultProps = {
498
- defaultIsShowingContent: false,
499
- placement: 'bottom center',
500
- stacking: 'topmost',
501
- shadow: 'resting',
502
- offsetX: 0,
503
- offsetY: 0,
504
- color: 'primary',
505
- on: ['hover', 'focus'],
506
- withArrow: true,
507
- constrain: 'window',
508
- insertAt: 'bottom',
509
- shouldAlignArrow: false,
510
- shouldTrackPosition: true,
511
- shouldRenderOffscreen: false,
512
- shouldContainFocus: false,
513
- shouldReturnFocus: true,
514
- shouldCloseOnDocumentClick: true,
515
- shouldFocusContentOnTriggerBlur: false,
516
- shouldCloseOnEscape: true
517
- }, _class2)) || _class) || _class) || _class);
514
+ }) || _class) || _class) || _class);
518
515
  export default Popover;
519
516
  export { Popover };