@instructure/ui-popover 11.6.0 → 11.6.1-snapshot-129
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 +38 -288
- package/es/Popover/{index.js → v1/index.js} +3 -3
- package/es/Popover/v2/index.js +499 -0
- package/es/Popover/v2/props.js +26 -0
- package/es/Popover/v2/styles.js +39 -0
- package/es/{index.js → exports/a.js} +1 -1
- package/{src/index.ts → es/exports/b.js} +1 -2
- package/lib/Popover/{index.js → v1/index.js} +5 -6
- package/lib/Popover/v2/index.js +514 -0
- package/lib/Popover/v2/props.js +31 -0
- package/lib/Popover/v2/styles.js +45 -0
- package/lib/{index.js → exports/a.js} +2 -2
- package/lib/exports/b.js +12 -0
- package/package.json +46 -24
- package/src/Popover/{index.tsx → v1/index.tsx} +5 -5
- package/src/Popover/v2/README.md +455 -0
- package/src/Popover/v2/index.tsx +645 -0
- package/src/Popover/v2/props.ts +354 -0
- package/src/Popover/v2/styles.ts +45 -0
- package/src/exports/a.ts +25 -0
- package/src/exports/b.ts +25 -0
- package/tsconfig.build.tsbuildinfo +1 -1
- package/types/Popover/v1/index.d.ts +83 -0
- package/types/Popover/v1/index.d.ts.map +1 -0
- package/types/Popover/v1/props.d.ts.map +1 -0
- package/types/Popover/v1/styles.d.ts.map +1 -0
- package/types/Popover/v1/theme.d.ts.map +1 -0
- package/types/Popover/v2/index.d.ts.map +1 -0
- package/types/Popover/v2/props.d.ts +225 -0
- package/types/Popover/v2/props.d.ts.map +1 -0
- package/types/Popover/v2/styles.d.ts +13 -0
- package/types/Popover/v2/styles.d.ts.map +1 -0
- package/types/exports/a.d.ts +3 -0
- package/types/exports/a.d.ts.map +1 -0
- package/types/exports/b.d.ts +3 -0
- package/types/exports/b.d.ts.map +1 -0
- package/types/Popover/index.d.ts.map +0 -1
- package/types/Popover/props.d.ts.map +0 -1
- package/types/Popover/styles.d.ts.map +0 -1
- package/types/Popover/theme.d.ts.map +0 -1
- package/types/index.d.ts +0 -3
- package/types/index.d.ts.map +0 -1
- /package/es/Popover/{props.js → v1/props.js} +0 -0
- /package/es/Popover/{styles.js → v1/styles.js} +0 -0
- /package/es/Popover/{theme.js → v1/theme.js} +0 -0
- /package/lib/Popover/{props.js → v1/props.js} +0 -0
- /package/lib/Popover/{styles.js → v1/styles.js} +0 -0
- /package/lib/Popover/{theme.js → v1/theme.js} +0 -0
- /package/src/Popover/{README.md → v1/README.md} +0 -0
- /package/src/Popover/{props.ts → v1/props.ts} +0 -0
- /package/src/Popover/{styles.ts → v1/styles.ts} +0 -0
- /package/src/Popover/{theme.ts → v1/theme.ts} +0 -0
- /package/types/Popover/{props.d.ts → v1/props.d.ts} +0 -0
- /package/types/Popover/{styles.d.ts → v1/styles.d.ts} +0 -0
- /package/types/Popover/{theme.d.ts → v1/theme.d.ts} +0 -0
- /package/types/Popover/{index.d.ts → v2/index.d.ts} +0 -0
|
@@ -0,0 +1,499 @@
|
|
|
1
|
+
var _dec, _dec2, _dec3, _class, _Popover;
|
|
2
|
+
/*
|
|
3
|
+
* The MIT License (MIT)
|
|
4
|
+
*
|
|
5
|
+
* Copyright (c) 2015 - present Instructure, Inc.
|
|
6
|
+
*
|
|
7
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
8
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
9
|
+
* in the Software without restriction, including without limitation the rights
|
|
10
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
11
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
12
|
+
* furnished to do so, subject to the following conditions:
|
|
13
|
+
*
|
|
14
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
15
|
+
* copies or substantial portions of the Software.
|
|
16
|
+
*
|
|
17
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
18
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
19
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
20
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
21
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
22
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
23
|
+
* SOFTWARE.
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
import { Component } from 'react';
|
|
27
|
+
import keycode from 'keycode';
|
|
28
|
+
import { Position, parsePlacement, mirrorHorizontalPlacement } from '@instructure/ui-position';
|
|
29
|
+
import { ContextView, View } from '@instructure/ui-view/latest';
|
|
30
|
+
import { Dialog } from '@instructure/ui-dialog';
|
|
31
|
+
import { textDirectionContextConsumer } from '@instructure/ui-i18n';
|
|
32
|
+
import { findDOMNode, containsActiveElement, requestAnimationFrame, handleMouseOverOut } from '@instructure/ui-dom-utils';
|
|
33
|
+
import { safeCloneElement, callRenderProp, withDeterministicId } from '@instructure/ui-react-utils';
|
|
34
|
+
import { createChainedFunction, shallowEqual, px, combineDataCid } from '@instructure/ui-utils';
|
|
35
|
+
import { logError as error } from '@instructure/console';
|
|
36
|
+
import { FocusRegion } from '@instructure/ui-a11y-utils';
|
|
37
|
+
import { withStyle } from '@instructure/emotion';
|
|
38
|
+
import generateStyle from "./styles.js";
|
|
39
|
+
import { allowedProps } from "./props.js";
|
|
40
|
+
import { jsx as _jsx, jsxs as _jsxs } from "@emotion/react/jsx-runtime";
|
|
41
|
+
/**
|
|
42
|
+
---
|
|
43
|
+
category: components
|
|
44
|
+
tags: overlay, portal, dialog
|
|
45
|
+
---
|
|
46
|
+
**/
|
|
47
|
+
let Popover = (_dec = withDeterministicId(), _dec2 = textDirectionContextConsumer(), _dec3 = withStyle(generateStyle), _dec(_class = _dec2(_class = _dec3(_class = (_Popover = class Popover extends Component {
|
|
48
|
+
constructor(props) {
|
|
49
|
+
super(props);
|
|
50
|
+
this._handleMouseOver = void 0;
|
|
51
|
+
this._handleMouseOut = void 0;
|
|
52
|
+
this._id = void 0;
|
|
53
|
+
this._raf = [];
|
|
54
|
+
this._trigger = null;
|
|
55
|
+
this._view = null;
|
|
56
|
+
this._dialog = null;
|
|
57
|
+
this._contentElement = null;
|
|
58
|
+
this._focusRegion = void 0;
|
|
59
|
+
// renderTrigger needs to be a variable because if it's a function it will
|
|
60
|
+
// recreate the trigger on each render which will trigger MouseOver events
|
|
61
|
+
// that will make the tooltip reappear and the trigger cannot accept
|
|
62
|
+
// onClick events (since the state change caused by MouseDown recreates it)
|
|
63
|
+
this._renderTrigger = void 0;
|
|
64
|
+
this._renderTriggerProp = void 0;
|
|
65
|
+
this.mouseOutTimeout = void 0;
|
|
66
|
+
this.ref = null;
|
|
67
|
+
this.handleRef = el => {
|
|
68
|
+
const elementRef = this.props.elementRef;
|
|
69
|
+
this.ref = el;
|
|
70
|
+
if (typeof elementRef === 'function') {
|
|
71
|
+
elementRef(el);
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
this.show = event => {
|
|
75
|
+
var _this$props$onShowCon, _this$props;
|
|
76
|
+
if (typeof this.props.isShowingContent === 'undefined') {
|
|
77
|
+
this.setState({
|
|
78
|
+
isShowingContent: true
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
(_this$props$onShowCon = (_this$props = this.props).onShowContent) === null || _this$props$onShowCon === void 0 ? void 0 : _this$props$onShowCon.call(_this$props, event);
|
|
82
|
+
};
|
|
83
|
+
this.hide = (event, documentClick = false) => {
|
|
84
|
+
const _this$props2 = this.props,
|
|
85
|
+
onHideContent = _this$props2.onHideContent,
|
|
86
|
+
isShowingContent = _this$props2.isShowingContent;
|
|
87
|
+
if (typeof isShowingContent === 'undefined') {
|
|
88
|
+
// uncontrolled, set state, fire callbacks
|
|
89
|
+
this.setState(({
|
|
90
|
+
isShowingContent
|
|
91
|
+
}) => {
|
|
92
|
+
if (isShowingContent) {
|
|
93
|
+
onHideContent === null || onHideContent === void 0 ? void 0 : onHideContent(event, {
|
|
94
|
+
documentClick
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
return {
|
|
98
|
+
isShowingContent: false
|
|
99
|
+
};
|
|
100
|
+
});
|
|
101
|
+
} else if (isShowingContent) {
|
|
102
|
+
// controlled, fire callback
|
|
103
|
+
onHideContent === null || onHideContent === void 0 ? void 0 : onHideContent(event, {
|
|
104
|
+
documentClick
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
};
|
|
108
|
+
this.toggle = event => {
|
|
109
|
+
if (this.shown) {
|
|
110
|
+
this.hide(event);
|
|
111
|
+
} else {
|
|
112
|
+
this.show(event);
|
|
113
|
+
}
|
|
114
|
+
};
|
|
115
|
+
this.handleDialogDismiss = (event, documentClick) => {
|
|
116
|
+
if (!this.props.shouldReturnFocus && this.props.shouldFocusContentOnTriggerBlur) {
|
|
117
|
+
const trigger = findDOMNode(this._trigger);
|
|
118
|
+
if (trigger && typeof trigger.focus === 'function') {
|
|
119
|
+
;
|
|
120
|
+
trigger.focus();
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
this.hide(event, documentClick);
|
|
124
|
+
};
|
|
125
|
+
this.handleDialogBlur = event => {
|
|
126
|
+
if (event.keyCode === keycode.codes.tab && event.shiftKey && this.props.shouldFocusContentOnTriggerBlur) {
|
|
127
|
+
return;
|
|
128
|
+
}
|
|
129
|
+
this.hide(event);
|
|
130
|
+
};
|
|
131
|
+
this.handleTriggerKeyDown = event => {
|
|
132
|
+
if (!this.props.shouldFocusContentOnTriggerBlur) {
|
|
133
|
+
return;
|
|
134
|
+
}
|
|
135
|
+
if (event.keyCode === keycode.codes.tab && !event.shiftKey) {
|
|
136
|
+
event.preventDefault();
|
|
137
|
+
this._raf.push(requestAnimationFrame(() => {
|
|
138
|
+
this._dialog && this._dialog.focus();
|
|
139
|
+
}));
|
|
140
|
+
}
|
|
141
|
+
};
|
|
142
|
+
this.handleTriggerKeyUp = event => {
|
|
143
|
+
if (event.keyCode === keycode.codes.esc && this.shown && this.isTooltip) {
|
|
144
|
+
// if popover is tooltip, it is managing its own focus region so we need
|
|
145
|
+
// to prevent esc keyup event from reaching FocusRegionManager
|
|
146
|
+
event.preventDefault();
|
|
147
|
+
this.hide(event);
|
|
148
|
+
}
|
|
149
|
+
};
|
|
150
|
+
this.handleTriggerBlur = event => {
|
|
151
|
+
const on = this.props.on;
|
|
152
|
+
if (on && on.indexOf('focus') > -1) {
|
|
153
|
+
this._raf.push(requestAnimationFrame(() => {
|
|
154
|
+
if (!containsActiveElement(this._view)) {
|
|
155
|
+
this.hide(event);
|
|
156
|
+
}
|
|
157
|
+
}));
|
|
158
|
+
}
|
|
159
|
+
};
|
|
160
|
+
this.handlePositioned = position => {
|
|
161
|
+
var _this$props$onPositio, _this$props3;
|
|
162
|
+
const placement = position.placement;
|
|
163
|
+
this.setState({
|
|
164
|
+
placement,
|
|
165
|
+
...this.computeOffsets(placement)
|
|
166
|
+
});
|
|
167
|
+
(_this$props$onPositio = (_this$props3 = this.props).onPositioned) === null || _this$props$onPositio === void 0 ? void 0 : _this$props$onPositio.call(_this$props3, position);
|
|
168
|
+
};
|
|
169
|
+
this.handlePositionChanged = position => {
|
|
170
|
+
var _this$props$onPositio2, _this$props4;
|
|
171
|
+
const placement = position.placement;
|
|
172
|
+
this.setState({
|
|
173
|
+
placement,
|
|
174
|
+
...this.computeOffsets(placement)
|
|
175
|
+
});
|
|
176
|
+
(_this$props$onPositio2 = (_this$props4 = this.props).onPositionChanged) === null || _this$props$onPositio2 === void 0 ? void 0 : _this$props$onPositio2.call(_this$props4, position);
|
|
177
|
+
};
|
|
178
|
+
this._renderTriggerProp = this.props.renderTrigger;
|
|
179
|
+
this._renderTrigger = callRenderProp(this.props.renderTrigger);
|
|
180
|
+
this.state = {
|
|
181
|
+
placement: props.placement,
|
|
182
|
+
offsetX: props.offsetX,
|
|
183
|
+
offsetY: props.offsetY,
|
|
184
|
+
isShowingContent: typeof props.isShowingContent === 'undefined' ? props.defaultIsShowingContent : void 0
|
|
185
|
+
};
|
|
186
|
+
this._id = this.props.id || props.deterministicId();
|
|
187
|
+
this._raf = [];
|
|
188
|
+
this._handleMouseOver = handleMouseOverOut.bind(null, event => {
|
|
189
|
+
this.show(event);
|
|
190
|
+
clearTimeout(this.mouseOutTimeout);
|
|
191
|
+
});
|
|
192
|
+
this._handleMouseOut = handleMouseOverOut.bind(null, event => {
|
|
193
|
+
// this is needed bc the trigger mouseOut fires before tooltip mouseOver
|
|
194
|
+
this.mouseOutTimeout = setTimeout(() => {
|
|
195
|
+
this.hide(event);
|
|
196
|
+
}, 1);
|
|
197
|
+
});
|
|
198
|
+
}
|
|
199
|
+
get isTooltip() {
|
|
200
|
+
return this.props.shouldRenderOffscreen && !this.props.shouldReturnFocus && !this.props.shouldContainFocus && !this.props.shouldFocusContentOnTriggerBlur;
|
|
201
|
+
}
|
|
202
|
+
componentDidMount() {
|
|
203
|
+
if (this.isTooltip) {
|
|
204
|
+
// if popover is being used as a tooltip with no focusable content
|
|
205
|
+
// manage its FocusRegion internally rather than registering it with
|
|
206
|
+
// the FocusRegionManager via Dialog
|
|
207
|
+
this._focusRegion = new FocusRegion(this._contentElement, {
|
|
208
|
+
shouldCloseOnEscape: this.props.shouldCloseOnEscape,
|
|
209
|
+
shouldCloseOnDocumentClick: false,
|
|
210
|
+
onDismiss: this.hide,
|
|
211
|
+
isTooltip: true
|
|
212
|
+
});
|
|
213
|
+
if (this.shown) {
|
|
214
|
+
this._focusRegion.activate();
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
componentWillUnmount() {
|
|
219
|
+
this._raf.forEach(request => request.cancel());
|
|
220
|
+
this._raf = [];
|
|
221
|
+
if (this._focusRegion) {
|
|
222
|
+
this._focusRegion.deactivate();
|
|
223
|
+
this._focusRegion.blur();
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
shouldComponentUpdate(nextProps, nextState) {
|
|
227
|
+
return !shallowEqual(this.props, nextProps) || !shallowEqual(this.state, nextState);
|
|
228
|
+
}
|
|
229
|
+
componentDidUpdate(prevProps, prevState) {
|
|
230
|
+
if (this._focusRegion && this.isTooltip) {
|
|
231
|
+
// if focus region exists, popover is acting as a tooltip
|
|
232
|
+
// so we manually activate and deactivate the region when showing/hiding
|
|
233
|
+
if (!prevProps.isShowingContent && this.props.isShowingContent || !prevState.isShowingContent && this.state.isShowingContent) {
|
|
234
|
+
// changed from hiding to showing
|
|
235
|
+
this._focusRegion.activate();
|
|
236
|
+
this._focusRegion.focus();
|
|
237
|
+
}
|
|
238
|
+
if (prevProps.isShowingContent && !this.props.isShowingContent || prevState.isShowingContent && !this.state.isShowingContent) {
|
|
239
|
+
// changed from showing to hiding
|
|
240
|
+
this._focusRegion.deactivate();
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
// since `offsetX`, `offsetY` and `placement` are saved into the state
|
|
245
|
+
// in the constructor and used from the state later,
|
|
246
|
+
// we need to update the state if these props change
|
|
247
|
+
if (this.props.offsetX !== prevProps.offsetX || this.props.offsetY !== prevProps.offsetY || this.props.placement !== prevProps.placement || this.props.shouldAlignArrow !== prevProps.shouldAlignArrow || this.props.withArrow !== prevProps.withArrow) {
|
|
248
|
+
this.setState({
|
|
249
|
+
...this.computeOffsets(this.placement)
|
|
250
|
+
});
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
/**
|
|
255
|
+
* Offsets the popover by the arrow size
|
|
256
|
+
*/
|
|
257
|
+
computeOffsets(placement) {
|
|
258
|
+
let _this$props5 = this.props,
|
|
259
|
+
offsetX = _this$props5.offsetX,
|
|
260
|
+
offsetY = _this$props5.offsetY;
|
|
261
|
+
if (this.props.shouldAlignArrow && this._view) {
|
|
262
|
+
const secondaryPlacement = parsePlacement(placement)[1];
|
|
263
|
+
|
|
264
|
+
// arrowSize and arrowBorderWidth are component theme variables
|
|
265
|
+
// declared in ContextView's styles.js
|
|
266
|
+
const _ref = this._view.props.styles,
|
|
267
|
+
_ref$arrowSize = _ref.arrowSize,
|
|
268
|
+
arrowSize = _ref$arrowSize === void 0 ? 0 : _ref$arrowSize,
|
|
269
|
+
_ref$arrowBorderWidth = _ref.arrowBorderWidth,
|
|
270
|
+
arrowBorderWidth = _ref$arrowBorderWidth === void 0 ? 0 : _ref$arrowBorderWidth;
|
|
271
|
+
const offsetAmount = (px(arrowSize) + px(arrowBorderWidth)) * 2;
|
|
272
|
+
if (secondaryPlacement === 'start') {
|
|
273
|
+
offsetX = offsetAmount;
|
|
274
|
+
} else if (secondaryPlacement === 'end') {
|
|
275
|
+
offsetX = -offsetAmount;
|
|
276
|
+
} else if (secondaryPlacement === 'top') {
|
|
277
|
+
offsetY = offsetAmount;
|
|
278
|
+
} else if (secondaryPlacement === 'bottom') {
|
|
279
|
+
offsetY = -offsetAmount;
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
return {
|
|
283
|
+
offsetX,
|
|
284
|
+
offsetY
|
|
285
|
+
};
|
|
286
|
+
}
|
|
287
|
+
get placement() {
|
|
288
|
+
let placement = this.props.placement;
|
|
289
|
+
const dir = this.props.dir;
|
|
290
|
+
const isRtl = dir === textDirectionContextConsumer.DIRECTION.rtl;
|
|
291
|
+
if (isRtl) {
|
|
292
|
+
placement = mirrorHorizontalPlacement(placement, ' ');
|
|
293
|
+
}
|
|
294
|
+
return !this.shown && this.props.shouldRenderOffscreen ? 'offscreen' : placement;
|
|
295
|
+
}
|
|
296
|
+
get positionProps() {
|
|
297
|
+
return {
|
|
298
|
+
offsetX: this.state.offsetX,
|
|
299
|
+
offsetY: this.state.offsetY,
|
|
300
|
+
shouldTrackPosition: this.props.shouldTrackPosition && this.shown,
|
|
301
|
+
insertAt: this.props.insertAt,
|
|
302
|
+
placement: this.placement,
|
|
303
|
+
constrain: this.props.constrain,
|
|
304
|
+
onPositioned: this.handlePositioned,
|
|
305
|
+
onPositionChanged: this.handlePositionChanged,
|
|
306
|
+
target: this.props.positionTarget,
|
|
307
|
+
containerDisplay: this.props.positionContainerDisplay,
|
|
308
|
+
mountNode: this.props.mountNode,
|
|
309
|
+
id: this._id
|
|
310
|
+
};
|
|
311
|
+
}
|
|
312
|
+
get shown() {
|
|
313
|
+
return typeof this.props.isShowingContent === 'undefined' ? this.state.isShowingContent : this.props.isShowingContent;
|
|
314
|
+
}
|
|
315
|
+
get defaultFocusElement() {
|
|
316
|
+
return this.props.defaultFocusElement;
|
|
317
|
+
}
|
|
318
|
+
renderTrigger() {
|
|
319
|
+
if (this._renderTriggerProp != this.props.renderTrigger) {
|
|
320
|
+
this._renderTriggerProp = this.props.renderTrigger;
|
|
321
|
+
this._renderTrigger = callRenderProp(this.props.renderTrigger);
|
|
322
|
+
}
|
|
323
|
+
let trigger = this._renderTrigger;
|
|
324
|
+
if (trigger) {
|
|
325
|
+
const on = this.props.on;
|
|
326
|
+
let onClick = void 0;
|
|
327
|
+
let onFocus = void 0;
|
|
328
|
+
let onMouseOut = void 0;
|
|
329
|
+
let onMouseOver = void 0;
|
|
330
|
+
let expanded;
|
|
331
|
+
if (on && on.indexOf('click') > -1) {
|
|
332
|
+
onClick = event => {
|
|
333
|
+
this.toggle(event);
|
|
334
|
+
};
|
|
335
|
+
}
|
|
336
|
+
if (on && on.indexOf('hover') > -1) {
|
|
337
|
+
error(!(on === 'hover'), '[Popover] Specifying only the `"hover"` trigger limits the visibility' + ' of the Popover to just mouse users. Consider also including the `"focus"` trigger ' + 'so that touch and keyboard only users can see the Popover content as well.');
|
|
338
|
+
onMouseOver = this._handleMouseOver;
|
|
339
|
+
onMouseOut = this._handleMouseOut;
|
|
340
|
+
}
|
|
341
|
+
if (on && on.indexOf('focus') > -1) {
|
|
342
|
+
onFocus = event => {
|
|
343
|
+
this.show(event);
|
|
344
|
+
};
|
|
345
|
+
}
|
|
346
|
+
if (this.props.shouldSetAriaExpanded) {
|
|
347
|
+
// only set aria-expanded if popover can contain focus
|
|
348
|
+
expanded = this.shown ? 'true' : 'false';
|
|
349
|
+
if ('aria-expanded' in this.props) {
|
|
350
|
+
// @ts-expect-error It is an escape hatch, in case someone
|
|
351
|
+
// wants to remove/override aria-expanded even when shouldSetAriaExpanded is set
|
|
352
|
+
expanded = this.props['aria-expanded'];
|
|
353
|
+
}
|
|
354
|
+
} else {
|
|
355
|
+
expanded = void 0;
|
|
356
|
+
}
|
|
357
|
+
trigger = safeCloneElement(trigger, {
|
|
358
|
+
ref: el => {
|
|
359
|
+
this._trigger = el;
|
|
360
|
+
},
|
|
361
|
+
'aria-expanded': expanded,
|
|
362
|
+
'data-popover-trigger': true,
|
|
363
|
+
onKeyDown: createChainedFunction(this.handleTriggerKeyDown, this.props.onKeyDown),
|
|
364
|
+
onKeyUp: createChainedFunction(this.handleTriggerKeyUp, this.props.onKeyUp),
|
|
365
|
+
onClick: createChainedFunction(onClick, this.props.onClick),
|
|
366
|
+
onBlur: createChainedFunction(this.handleTriggerBlur, this.props.onBlur),
|
|
367
|
+
onFocus: createChainedFunction(onFocus, this.props.onFocus),
|
|
368
|
+
onMouseOut: createChainedFunction(onMouseOut, this.props.onMouseOut),
|
|
369
|
+
onMouseOver: createChainedFunction(onMouseOver, this.props.onMouseOver)
|
|
370
|
+
});
|
|
371
|
+
}
|
|
372
|
+
return trigger;
|
|
373
|
+
}
|
|
374
|
+
renderContent() {
|
|
375
|
+
let content = callRenderProp(this.props.children);
|
|
376
|
+
if (this.shown && !this.isTooltip) {
|
|
377
|
+
// if popover is NOT being used as a tooltip, create a Dialog
|
|
378
|
+
// to manage the content FocusRegion, when showing
|
|
379
|
+
content = _jsx(Dialog, {
|
|
380
|
+
open: this.shown,
|
|
381
|
+
label: this.props.screenReaderLabel,
|
|
382
|
+
ref: el => {
|
|
383
|
+
this._dialog = el;
|
|
384
|
+
},
|
|
385
|
+
display: "block",
|
|
386
|
+
onBlur: this.handleDialogBlur,
|
|
387
|
+
onDismiss: this.handleDialogDismiss,
|
|
388
|
+
liveRegion: this.props.liveRegion,
|
|
389
|
+
defaultFocusElement: this.props.defaultFocusElement,
|
|
390
|
+
shouldContainFocus: this.props.shouldContainFocus,
|
|
391
|
+
shouldReturnFocus: this.props.shouldReturnFocus,
|
|
392
|
+
shouldFocusOnOpen: !this.props.shouldFocusContentOnTriggerBlur,
|
|
393
|
+
shouldCloseOnDocumentClick: this.props.shouldCloseOnDocumentClick,
|
|
394
|
+
shouldCloseOnEscape: this.props.shouldCloseOnEscape,
|
|
395
|
+
children: content
|
|
396
|
+
});
|
|
397
|
+
}
|
|
398
|
+
if (this.shown || this.props.shouldRenderOffscreen) {
|
|
399
|
+
const color = this.props.color;
|
|
400
|
+
let viewProps = {
|
|
401
|
+
// TODO: try to type `ref` better, LegacyRef<T> was not compatible
|
|
402
|
+
ref: c => this._view = c,
|
|
403
|
+
elementRef: el => {
|
|
404
|
+
var _this$props$contentRe, _this$props6;
|
|
405
|
+
this._contentElement = el;
|
|
406
|
+
(_this$props$contentRe = (_this$props6 = this.props).contentRef) === null || _this$props$contentRe === void 0 ? void 0 : _this$props$contentRe.call(_this$props6, el);
|
|
407
|
+
},
|
|
408
|
+
background: color,
|
|
409
|
+
stacking: this.props.stacking,
|
|
410
|
+
shadow: this.props.shadow,
|
|
411
|
+
display: 'block'
|
|
412
|
+
};
|
|
413
|
+
if (this.isTooltip) {
|
|
414
|
+
viewProps = {
|
|
415
|
+
...viewProps,
|
|
416
|
+
// Because of a11y reasons popovers should not be hidden when hovered over
|
|
417
|
+
onMouseOver: this._handleMouseOver,
|
|
418
|
+
onMouseOut: this._handleMouseOut
|
|
419
|
+
};
|
|
420
|
+
}
|
|
421
|
+
const placement = this.state.placement;
|
|
422
|
+
const styles = this.props.styles;
|
|
423
|
+
if (this.props.withArrow) {
|
|
424
|
+
viewProps = {
|
|
425
|
+
...viewProps,
|
|
426
|
+
// TODO: remove background override after contextview is updated
|
|
427
|
+
background: color === 'primary' ? 'default' : 'inverse',
|
|
428
|
+
placement: this.props.dir === textDirectionContextConsumer.DIRECTION.rtl ? mirrorHorizontalPlacement(placement, ' ') : placement
|
|
429
|
+
};
|
|
430
|
+
return _jsx(ContextView, {
|
|
431
|
+
...viewProps,
|
|
432
|
+
borderColor: styles === null || styles === void 0 ? void 0 : styles.borderColor,
|
|
433
|
+
children: content
|
|
434
|
+
});
|
|
435
|
+
} else {
|
|
436
|
+
viewProps = {
|
|
437
|
+
...viewProps,
|
|
438
|
+
borderWidth: this.props.borderWidth || 'small',
|
|
439
|
+
borderRadius: 'medium',
|
|
440
|
+
...(color === 'primary-inverse' && {
|
|
441
|
+
borderColor: 'transparent'
|
|
442
|
+
})
|
|
443
|
+
};
|
|
444
|
+
return _jsx(View, {
|
|
445
|
+
...viewProps,
|
|
446
|
+
borderColor: styles === null || styles === void 0 ? void 0 : styles.borderColor,
|
|
447
|
+
borderRadius: styles === null || styles === void 0 ? void 0 : styles.borderRadius,
|
|
448
|
+
children: content
|
|
449
|
+
});
|
|
450
|
+
}
|
|
451
|
+
} else {
|
|
452
|
+
return null;
|
|
453
|
+
}
|
|
454
|
+
}
|
|
455
|
+
render() {
|
|
456
|
+
const positionProps = this.positionProps;
|
|
457
|
+
if (this.props.positionTarget) {
|
|
458
|
+
return _jsxs("span", {
|
|
459
|
+
ref: this.handleRef,
|
|
460
|
+
children: [this.renderTrigger(), _jsx(Position, {
|
|
461
|
+
...positionProps,
|
|
462
|
+
"data-cid": combineDataCid('Popover', this.props),
|
|
463
|
+
children: this.renderContent()
|
|
464
|
+
})]
|
|
465
|
+
});
|
|
466
|
+
} else {
|
|
467
|
+
return _jsx(Position, {
|
|
468
|
+
"data-cid": combineDataCid('Popover', this.props),
|
|
469
|
+
...positionProps,
|
|
470
|
+
renderTarget: this.renderTrigger(),
|
|
471
|
+
elementRef: this.handleRef,
|
|
472
|
+
children: this.renderContent()
|
|
473
|
+
});
|
|
474
|
+
}
|
|
475
|
+
}
|
|
476
|
+
}, _Popover.displayName = "Popover", _Popover.componentId = 'Popover', _Popover.allowedProps = allowedProps, _Popover.defaultProps = {
|
|
477
|
+
defaultIsShowingContent: false,
|
|
478
|
+
placement: 'bottom center',
|
|
479
|
+
stacking: 'topmost',
|
|
480
|
+
shadow: 'above',
|
|
481
|
+
offsetX: 0,
|
|
482
|
+
offsetY: 0,
|
|
483
|
+
color: 'primary',
|
|
484
|
+
on: ['hover', 'focus'],
|
|
485
|
+
withArrow: true,
|
|
486
|
+
constrain: 'window',
|
|
487
|
+
insertAt: 'bottom',
|
|
488
|
+
shouldAlignArrow: false,
|
|
489
|
+
shouldTrackPosition: true,
|
|
490
|
+
shouldRenderOffscreen: false,
|
|
491
|
+
shouldContainFocus: false,
|
|
492
|
+
shouldReturnFocus: true,
|
|
493
|
+
shouldCloseOnDocumentClick: true,
|
|
494
|
+
shouldFocusContentOnTriggerBlur: false,
|
|
495
|
+
shouldCloseOnEscape: true,
|
|
496
|
+
shouldSetAriaExpanded: true
|
|
497
|
+
}, _Popover)) || _class) || _class) || _class);
|
|
498
|
+
export default Popover;
|
|
499
|
+
export { Popover };
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* The MIT License (MIT)
|
|
3
|
+
*
|
|
4
|
+
* Copyright (c) 2015 - present Instructure, Inc.
|
|
5
|
+
*
|
|
6
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
8
|
+
* in the Software without restriction, including without limitation the rights
|
|
9
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
11
|
+
* furnished to do so, subject to the following conditions:
|
|
12
|
+
*
|
|
13
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
14
|
+
* copies or substantial portions of the Software.
|
|
15
|
+
*
|
|
16
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
+
* SOFTWARE.
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
const allowedProps = ['isShowingContent', 'defaultIsShowingContent', 'on', 'withArrow', 'color', 'placement', 'shadow', 'stacking', 'contentRef', 'defaultFocusElement', 'screenReaderLabel', 'offsetX', 'offsetY', 'constrain', 'positionTarget', 'positionContainerDisplay', 'mountNode', 'insertAt', 'liveRegion', 'id', 'shouldAlignArrow', 'shouldTrackPosition', 'shouldRenderOffscreen', 'shouldContainFocus', 'shouldReturnFocus', 'shouldCloseOnDocumentClick', 'shouldCloseOnEscape', 'shouldFocusContentOnTriggerBlur', 'onShowContent', 'onHideContent', 'onPositioned', 'onPositionChanged', 'onClick', 'onFocus', 'onBlur', 'onKeyDown', 'onKeyUp', 'onMouseOver', 'onMouseOut', 'renderTrigger', 'children', 'elementRef', 'borderWidth', 'shouldSetAriaExpanded'];
|
|
26
|
+
export { allowedProps };
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* The MIT License (MIT)
|
|
3
|
+
*
|
|
4
|
+
* Copyright (c) 2015 - present Instructure, Inc.
|
|
5
|
+
*
|
|
6
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
8
|
+
* in the Software without restriction, including without limitation the rights
|
|
9
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
11
|
+
* furnished to do so, subject to the following conditions:
|
|
12
|
+
*
|
|
13
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
14
|
+
* copies or substantial portions of the Software.
|
|
15
|
+
*
|
|
16
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
+
* SOFTWARE.
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* ---
|
|
27
|
+
* private: true
|
|
28
|
+
* ---
|
|
29
|
+
* Generates the style object from the theme and provided additional information
|
|
30
|
+
* @param {Object} componentTheme The theme variable object.
|
|
31
|
+
* @return {Object} The final style object, which will be used in the component
|
|
32
|
+
*/
|
|
33
|
+
const generateStyle = componentTheme => {
|
|
34
|
+
return {
|
|
35
|
+
borderColor: componentTheme.borderColor,
|
|
36
|
+
borderRadius: componentTheme.borderRadius
|
|
37
|
+
};
|
|
38
|
+
};
|
|
39
|
+
export default generateStyle;
|
|
@@ -21,5 +21,4 @@
|
|
|
21
21
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
22
|
* SOFTWARE.
|
|
23
23
|
*/
|
|
24
|
-
export { Popover } from
|
|
25
|
-
export type { PopoverOwnProps, PopoverProps } from './Popover/props'
|
|
24
|
+
export { Popover } from "../Popover/v2/index.js";
|
|
@@ -10,8 +10,7 @@ var _keycode = _interopRequireDefault(require("keycode"));
|
|
|
10
10
|
var _Position = require("@instructure/ui-position/lib/Position");
|
|
11
11
|
var _parsePlacement = require("@instructure/ui-position/lib/parsePlacement.js");
|
|
12
12
|
var _mirrorHorizontalPlacement = require("@instructure/ui-position/lib/mirrorHorizontalPlacement.js");
|
|
13
|
-
var
|
|
14
|
-
var _View = require("@instructure/ui-view/lib/View");
|
|
13
|
+
var _v11_ = require("@instructure/ui-view/v11_6");
|
|
15
14
|
var _Dialog = require("@instructure/ui-dialog/lib/Dialog");
|
|
16
15
|
var _textDirectionContextConsumer = require("@instructure/ui-i18n/lib/textDirectionContextConsumer.js");
|
|
17
16
|
var _findDOMNode = require("@instructure/ui-dom-utils/lib/findDOMNode.js");
|
|
@@ -30,7 +29,7 @@ var _FocusRegion = require("@instructure/ui-a11y-utils/lib/FocusRegion.js");
|
|
|
30
29
|
var _emotion = require("@instructure/emotion");
|
|
31
30
|
var _styles = _interopRequireDefault(require("./styles"));
|
|
32
31
|
var _theme = _interopRequireDefault(require("./theme"));
|
|
33
|
-
var _props = require("
|
|
32
|
+
var _props = require("../v1/props");
|
|
34
33
|
var _jsxRuntime = require("@emotion/react/jsx-runtime");
|
|
35
34
|
var _dec, _dec2, _dec3, _class, _Popover;
|
|
36
35
|
/*
|
|
@@ -62,7 +61,7 @@ category: components
|
|
|
62
61
|
tags: overlay, portal, dialog
|
|
63
62
|
---
|
|
64
63
|
**/
|
|
65
|
-
let Popover = exports.Popover = (_dec = (0, _withDeterministicId.withDeterministicId)(), _dec2 = (0, _textDirectionContextConsumer.textDirectionContextConsumer)(), _dec3 = (0, _emotion.
|
|
64
|
+
let Popover = exports.Popover = (_dec = (0, _withDeterministicId.withDeterministicId)(), _dec2 = (0, _textDirectionContextConsumer.textDirectionContextConsumer)(), _dec3 = (0, _emotion.withStyleLegacy)(_styles.default, _theme.default), _dec(_class = _dec2(_class = _dec3(_class = (_Popover = class Popover extends _react.Component {
|
|
66
65
|
constructor(props) {
|
|
67
66
|
super(props);
|
|
68
67
|
this._handleMouseOver = void 0;
|
|
@@ -445,7 +444,7 @@ let Popover = exports.Popover = (_dec = (0, _withDeterministicId.withDeterminist
|
|
|
445
444
|
background: color === 'primary' ? 'default' : 'inverse',
|
|
446
445
|
placement: this.props.dir === _textDirectionContextConsumer.textDirectionContextConsumer.DIRECTION.rtl ? (0, _mirrorHorizontalPlacement.mirrorHorizontalPlacement)(placement, ' ') : placement
|
|
447
446
|
};
|
|
448
|
-
return (0, _jsxRuntime.jsx)(
|
|
447
|
+
return (0, _jsxRuntime.jsx)(_v11_.ContextView, {
|
|
449
448
|
...viewProps,
|
|
450
449
|
borderColor: styles === null || styles === void 0 ? void 0 : styles.borderColor,
|
|
451
450
|
children: content
|
|
@@ -459,7 +458,7 @@ let Popover = exports.Popover = (_dec = (0, _withDeterministicId.withDeterminist
|
|
|
459
458
|
borderColor: 'transparent'
|
|
460
459
|
})
|
|
461
460
|
};
|
|
462
|
-
return (0, _jsxRuntime.jsx)(
|
|
461
|
+
return (0, _jsxRuntime.jsx)(_v11_.View, {
|
|
463
462
|
...viewProps,
|
|
464
463
|
borderColor: styles === null || styles === void 0 ? void 0 : styles.borderColor,
|
|
465
464
|
children: content
|