@khanacademy/wonder-blocks-popover 2.0.5 → 2.0.7
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 +23 -0
- package/dist/components/popover-content.js.flow +4 -4
- package/dist/components/popover-dialog.js.flow +2 -2
- package/dist/components/popover.js.flow +2 -2
- package/dist/es/index.js +135 -197
- package/dist/index.js +135 -197
- package/package.json +8 -8
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,28 @@
|
|
|
1
1
|
# @khanacademy/wonder-blocks-popover
|
|
2
2
|
|
|
3
|
+
## 2.0.7
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- @khanacademy/wonder-blocks-icon@2.0.7
|
|
8
|
+
- @khanacademy/wonder-blocks-icon-button@4.0.7
|
|
9
|
+
- @khanacademy/wonder-blocks-modal@4.0.7
|
|
10
|
+
- @khanacademy/wonder-blocks-tooltip@2.0.7
|
|
11
|
+
- @khanacademy/wonder-blocks-typography@2.0.7
|
|
12
|
+
|
|
13
|
+
## 2.0.6
|
|
14
|
+
|
|
15
|
+
### Patch Changes
|
|
16
|
+
|
|
17
|
+
- c20f48f3: Don't transpile classes when building bundles
|
|
18
|
+
- Updated dependencies [c20f48f3]
|
|
19
|
+
- @khanacademy/wonder-blocks-core@5.0.4
|
|
20
|
+
- @khanacademy/wonder-blocks-icon@2.0.6
|
|
21
|
+
- @khanacademy/wonder-blocks-icon-button@4.0.6
|
|
22
|
+
- @khanacademy/wonder-blocks-modal@4.0.6
|
|
23
|
+
- @khanacademy/wonder-blocks-tooltip@2.0.6
|
|
24
|
+
- @khanacademy/wonder-blocks-typography@2.0.6
|
|
25
|
+
|
|
3
26
|
## 2.0.5
|
|
4
27
|
|
|
5
28
|
### Patch Changes
|
|
@@ -60,16 +60,16 @@ declare type Props = {|
|
|
|
60
60
|
*/
|
|
61
61
|
icon?:
|
|
62
62
|
| string
|
|
63
|
-
| React.Element<
|
|
64
|
-
| React.Element<
|
|
63
|
+
| React.Element<"img">
|
|
64
|
+
| React.Element<"svg">,
|
|
65
65
|
|
|
66
66
|
/**
|
|
67
67
|
* Decorate the popover with a full-bleed illustration. It cannot be used at
|
|
68
68
|
* the same time with icon.
|
|
69
69
|
*/
|
|
70
70
|
image?:
|
|
71
|
-
| React.Element<
|
|
72
|
-
| React.Element<
|
|
71
|
+
| React.Element<"img">
|
|
72
|
+
| React.Element<"svg">,
|
|
73
73
|
|
|
74
74
|
/**
|
|
75
75
|
* When true, changes the popover dialog background to blue; otherwise, the
|
|
@@ -20,8 +20,8 @@ declare type Props = {|
|
|
|
20
20
|
* The content to render inside the dialog.
|
|
21
21
|
*/
|
|
22
22
|
children:
|
|
23
|
-
| React.Element<
|
|
24
|
-
| React.Element<
|
|
23
|
+
| React.Element<typeof PopoverContent>
|
|
24
|
+
| React.Element<typeof PopoverContentCore>,
|
|
25
25
|
|
|
26
26
|
/**
|
|
27
27
|
* The unique identifier to give to the popover content.
|
|
@@ -10,8 +10,8 @@ import type { Placement } from "@khanacademy/wonder-blocks-tooltip";
|
|
|
10
10
|
import PopoverContent from "./popover-content";
|
|
11
11
|
import PopoverContentCore from "./popover-content-core";
|
|
12
12
|
declare type PopoverContents =
|
|
13
|
-
| React.Element<
|
|
14
|
-
| React.Element<
|
|
13
|
+
| React.Element<typeof PopoverContent>
|
|
14
|
+
| React.Element<typeof PopoverContentCore>;
|
|
15
15
|
declare type Props = {|
|
|
16
16
|
...AriaProps,
|
|
17
17
|
...{|
|
package/dist/es/index.js
CHANGED
|
@@ -25,39 +25,20 @@ function _extends() {
|
|
|
25
25
|
return _extends.apply(this, arguments);
|
|
26
26
|
}
|
|
27
27
|
|
|
28
|
-
function _setPrototypeOf(o, p) {
|
|
29
|
-
_setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) {
|
|
30
|
-
o.__proto__ = p;
|
|
31
|
-
return o;
|
|
32
|
-
};
|
|
33
|
-
return _setPrototypeOf(o, p);
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
function _inheritsLoose(subClass, superClass) {
|
|
37
|
-
subClass.prototype = Object.create(superClass.prototype);
|
|
38
|
-
subClass.prototype.constructor = subClass;
|
|
39
|
-
_setPrototypeOf(subClass, superClass);
|
|
40
|
-
}
|
|
41
|
-
|
|
42
28
|
const defaultContext = {
|
|
43
29
|
close: undefined,
|
|
44
30
|
placement: "top"
|
|
45
31
|
};
|
|
46
32
|
var PopoverContext = React.createContext(defaultContext);
|
|
47
33
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
function PopoverAnchor() {
|
|
51
|
-
return _React$Component.apply(this, arguments) || this;
|
|
52
|
-
}
|
|
53
|
-
var _proto = PopoverAnchor.prototype;
|
|
54
|
-
_proto.componentDidMount = function componentDidMount() {
|
|
34
|
+
class PopoverAnchor extends React.Component {
|
|
35
|
+
componentDidMount() {
|
|
55
36
|
const anchorNode = ReactDOM.findDOMNode(this);
|
|
56
37
|
if (anchorNode) {
|
|
57
38
|
this.props.anchorRef(anchorNode);
|
|
58
39
|
}
|
|
59
|
-
}
|
|
60
|
-
|
|
40
|
+
}
|
|
41
|
+
render() {
|
|
61
42
|
const {
|
|
62
43
|
children,
|
|
63
44
|
id,
|
|
@@ -84,22 +65,16 @@ let PopoverAnchor = function (_React$Component) {
|
|
|
84
65
|
} : onClick
|
|
85
66
|
}));
|
|
86
67
|
}
|
|
87
|
-
};
|
|
88
|
-
return PopoverAnchor;
|
|
89
|
-
}(React.Component);
|
|
90
|
-
|
|
91
|
-
let PopoverDialog = function (_React$Component) {
|
|
92
|
-
_inheritsLoose(PopoverDialog, _React$Component);
|
|
93
|
-
function PopoverDialog() {
|
|
94
|
-
return _React$Component.apply(this, arguments) || this;
|
|
95
68
|
}
|
|
96
|
-
|
|
97
|
-
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
class PopoverDialog extends React.Component {
|
|
72
|
+
componentDidUpdate(prevProps) {
|
|
98
73
|
if (prevProps.placement !== this.props.placement) {
|
|
99
74
|
this.props.onUpdate(this.props.placement);
|
|
100
75
|
}
|
|
101
|
-
}
|
|
102
|
-
|
|
76
|
+
}
|
|
77
|
+
render() {
|
|
103
78
|
const {
|
|
104
79
|
placement,
|
|
105
80
|
children,
|
|
@@ -126,9 +101,8 @@ let PopoverDialog = function (_React$Component) {
|
|
|
126
101
|
placement: placement,
|
|
127
102
|
offset: tailOffset
|
|
128
103
|
})));
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
}(React.Component);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
132
106
|
const styles$2 = StyleSheet.create({
|
|
133
107
|
hide: {
|
|
134
108
|
pointerEvents: "none",
|
|
@@ -155,13 +129,11 @@ function findFocusableNodes(root) {
|
|
|
155
129
|
return Array.from(root.querySelectorAll(FOCUSABLE_ELEMENTS));
|
|
156
130
|
}
|
|
157
131
|
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
_this.setInitialFocusableElement = node => {
|
|
164
|
-
const firstFocusableElement = _this.maybeGetInitialFocusElement(node) || _this.maybeGetFirstFocusableElement(node) || node;
|
|
132
|
+
class InitialFocus extends React.Component {
|
|
133
|
+
constructor(...args) {
|
|
134
|
+
super(...args);
|
|
135
|
+
this.setInitialFocusableElement = node => {
|
|
136
|
+
const firstFocusableElement = this.maybeGetInitialFocusElement(node) || this.maybeGetFirstFocusableElement(node) || node;
|
|
165
137
|
if (firstFocusableElement === node) {
|
|
166
138
|
node.tabIndex = -1;
|
|
167
139
|
}
|
|
@@ -169,17 +141,15 @@ let InitialFocus = function (_React$Component) {
|
|
|
169
141
|
firstFocusableElement.focus();
|
|
170
142
|
}, 0);
|
|
171
143
|
};
|
|
172
|
-
return _this;
|
|
173
144
|
}
|
|
174
|
-
|
|
175
|
-
_proto.componentDidMount = function componentDidMount() {
|
|
145
|
+
componentDidMount() {
|
|
176
146
|
const node = ReactDOM.findDOMNode(this);
|
|
177
147
|
if (!node) {
|
|
178
148
|
return;
|
|
179
149
|
}
|
|
180
150
|
this.setInitialFocusableElement(node);
|
|
181
|
-
}
|
|
182
|
-
|
|
151
|
+
}
|
|
152
|
+
maybeGetInitialFocusElement(node) {
|
|
183
153
|
const {
|
|
184
154
|
initialFocusId
|
|
185
155
|
} = this.props;
|
|
@@ -187,45 +157,42 @@ let InitialFocus = function (_React$Component) {
|
|
|
187
157
|
return null;
|
|
188
158
|
}
|
|
189
159
|
return node.querySelector(`#${initialFocusId}`);
|
|
190
|
-
}
|
|
191
|
-
|
|
160
|
+
}
|
|
161
|
+
maybeGetFirstFocusableElement(node) {
|
|
192
162
|
const focusableElements = findFocusableNodes(node);
|
|
193
163
|
if (!focusableElements.length) {
|
|
194
164
|
return null;
|
|
195
165
|
}
|
|
196
166
|
return focusableElements[0];
|
|
197
|
-
}
|
|
198
|
-
|
|
167
|
+
}
|
|
168
|
+
render() {
|
|
199
169
|
return this.props.children;
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
}(React.Component);
|
|
170
|
+
}
|
|
171
|
+
}
|
|
203
172
|
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
_this.focusableElementsInPopover = [];
|
|
212
|
-
_this.addEventListeners = () => {
|
|
173
|
+
class FocusManager extends React.Component {
|
|
174
|
+
constructor(...args) {
|
|
175
|
+
super(...args);
|
|
176
|
+
this.nextElementAfterPopover = void 0;
|
|
177
|
+
this.rootNode = void 0;
|
|
178
|
+
this.focusableElementsInPopover = [];
|
|
179
|
+
this.addEventListeners = () => {
|
|
213
180
|
const {
|
|
214
181
|
anchorElement
|
|
215
|
-
} =
|
|
182
|
+
} = this.props;
|
|
216
183
|
if (anchorElement) {
|
|
217
|
-
anchorElement.addEventListener("keydown",
|
|
184
|
+
anchorElement.addEventListener("keydown", this.handleKeydownPreviousFocusableElement, true);
|
|
218
185
|
}
|
|
219
|
-
|
|
220
|
-
if (
|
|
221
|
-
|
|
186
|
+
this.nextElementAfterPopover = this.getNextFocusableElement();
|
|
187
|
+
if (this.nextElementAfterPopover) {
|
|
188
|
+
this.nextElementAfterPopover.addEventListener("keydown", this.handleKeydownNextFocusableElement, true);
|
|
222
189
|
}
|
|
223
190
|
};
|
|
224
|
-
|
|
191
|
+
this.getNextFocusableElement = () => {
|
|
225
192
|
const {
|
|
226
193
|
anchorElement
|
|
227
|
-
} =
|
|
228
|
-
if (!anchorElement ||
|
|
194
|
+
} = this.props;
|
|
195
|
+
if (!anchorElement || this.nextElementAfterPopover) {
|
|
229
196
|
return;
|
|
230
197
|
}
|
|
231
198
|
const focusableElements = findFocusableNodes(document);
|
|
@@ -236,7 +203,7 @@ let FocusManager = function (_React$Component) {
|
|
|
236
203
|
}
|
|
237
204
|
return;
|
|
238
205
|
};
|
|
239
|
-
|
|
206
|
+
this.getComponentRootNode = node => {
|
|
240
207
|
if (!node) {
|
|
241
208
|
return;
|
|
242
209
|
}
|
|
@@ -244,42 +211,40 @@ let FocusManager = function (_React$Component) {
|
|
|
244
211
|
if (!rootNode) {
|
|
245
212
|
throw new Error("Assertion error: root node should exist after mount");
|
|
246
213
|
}
|
|
247
|
-
|
|
248
|
-
|
|
214
|
+
this.rootNode = rootNode;
|
|
215
|
+
this.focusableElementsInPopover = findFocusableNodes(this.rootNode);
|
|
249
216
|
};
|
|
250
|
-
|
|
251
|
-
if (
|
|
252
|
-
|
|
217
|
+
this.handleFocusPreviousFocusableElement = () => {
|
|
218
|
+
if (this.props.anchorElement) {
|
|
219
|
+
this.props.anchorElement.focus();
|
|
253
220
|
}
|
|
254
221
|
};
|
|
255
|
-
|
|
256
|
-
if (
|
|
257
|
-
|
|
222
|
+
this.handleFocusNextFocusableElement = () => {
|
|
223
|
+
if (this.nextElementAfterPopover) {
|
|
224
|
+
this.nextElementAfterPopover.focus();
|
|
258
225
|
}
|
|
259
226
|
};
|
|
260
|
-
|
|
227
|
+
this.handleKeydownPreviousFocusableElement = e => {
|
|
261
228
|
if (e.key === "Tab" && !e.shiftKey) {
|
|
262
229
|
e.preventDefault();
|
|
263
|
-
|
|
230
|
+
this.focusableElementsInPopover[0].focus();
|
|
264
231
|
}
|
|
265
232
|
};
|
|
266
|
-
|
|
233
|
+
this.handleKeydownNextFocusableElement = e => {
|
|
267
234
|
if (e.key === "Tab" && e.shiftKey) {
|
|
268
235
|
e.preventDefault();
|
|
269
|
-
const lastElementIndex =
|
|
270
|
-
|
|
236
|
+
const lastElementIndex = this.focusableElementsInPopover.length - 1;
|
|
237
|
+
this.focusableElementsInPopover[lastElementIndex].focus();
|
|
271
238
|
}
|
|
272
239
|
};
|
|
273
|
-
return _this;
|
|
274
240
|
}
|
|
275
|
-
|
|
276
|
-
_proto.componentDidMount = function componentDidMount() {
|
|
241
|
+
componentDidMount() {
|
|
277
242
|
this.addEventListeners();
|
|
278
|
-
}
|
|
279
|
-
|
|
243
|
+
}
|
|
244
|
+
componentDidUpdate() {
|
|
280
245
|
this.addEventListeners();
|
|
281
|
-
}
|
|
282
|
-
|
|
246
|
+
}
|
|
247
|
+
componentWillUnmount() {
|
|
283
248
|
const {
|
|
284
249
|
anchorElement
|
|
285
250
|
} = this.props;
|
|
@@ -290,8 +255,8 @@ let FocusManager = function (_React$Component) {
|
|
|
290
255
|
if (this.nextElementAfterPopover) {
|
|
291
256
|
this.nextElementAfterPopover.removeEventListener("keydown", this.handleKeydownNextFocusableElement, true);
|
|
292
257
|
}
|
|
293
|
-
}
|
|
294
|
-
|
|
258
|
+
}
|
|
259
|
+
render() {
|
|
295
260
|
const {
|
|
296
261
|
children
|
|
297
262
|
} = this.props;
|
|
@@ -312,103 +277,94 @@ let FocusManager = function (_React$Component) {
|
|
|
312
277
|
position: "fixed"
|
|
313
278
|
}
|
|
314
279
|
}));
|
|
315
|
-
}
|
|
316
|
-
|
|
317
|
-
}(React.Component);
|
|
280
|
+
}
|
|
281
|
+
}
|
|
318
282
|
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
_this = _React$Component.call.apply(_React$Component, [this].concat(args)) || this;
|
|
324
|
-
_this.state = {
|
|
283
|
+
class PopoverEventListener extends React.Component {
|
|
284
|
+
constructor(...args) {
|
|
285
|
+
super(...args);
|
|
286
|
+
this.state = {
|
|
325
287
|
isFirstClick: true
|
|
326
288
|
};
|
|
327
|
-
|
|
289
|
+
this._handleKeyup = e => {
|
|
328
290
|
if (e.key === "Escape") {
|
|
329
291
|
e.preventDefault();
|
|
330
292
|
e.stopPropagation();
|
|
331
|
-
|
|
293
|
+
this.props.onClose();
|
|
332
294
|
}
|
|
333
295
|
};
|
|
334
|
-
|
|
296
|
+
this._handleClick = e => {
|
|
335
297
|
var _this$props$contentRe;
|
|
336
|
-
if (
|
|
337
|
-
|
|
298
|
+
if (this.state.isFirstClick) {
|
|
299
|
+
this.setState({
|
|
338
300
|
isFirstClick: false
|
|
339
301
|
});
|
|
340
302
|
return;
|
|
341
303
|
}
|
|
342
|
-
const node = ReactDOM.findDOMNode((_this$props$contentRe =
|
|
304
|
+
const node = ReactDOM.findDOMNode((_this$props$contentRe = this.props.contentRef) == null ? void 0 : _this$props$contentRe.current);
|
|
343
305
|
if (node && !node.contains(e.target)) {
|
|
344
306
|
e.preventDefault();
|
|
345
307
|
e.stopPropagation();
|
|
346
|
-
|
|
308
|
+
this.props.onClose();
|
|
347
309
|
}
|
|
348
310
|
};
|
|
349
|
-
return _this;
|
|
350
311
|
}
|
|
351
|
-
|
|
352
|
-
_proto.componentDidMount = function componentDidMount() {
|
|
312
|
+
componentDidMount() {
|
|
353
313
|
window.addEventListener("keyup", this._handleKeyup);
|
|
354
314
|
window.addEventListener("click", this._handleClick);
|
|
355
|
-
}
|
|
356
|
-
|
|
315
|
+
}
|
|
316
|
+
componentWillUnmount() {
|
|
357
317
|
window.removeEventListener("keyup", this._handleKeyup);
|
|
358
318
|
window.removeEventListener("click", this._handleClick);
|
|
359
|
-
}
|
|
360
|
-
|
|
319
|
+
}
|
|
320
|
+
render() {
|
|
361
321
|
return null;
|
|
362
|
-
}
|
|
363
|
-
|
|
364
|
-
}(React.Component);
|
|
322
|
+
}
|
|
323
|
+
}
|
|
365
324
|
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
_this.state = {
|
|
372
|
-
opened: !!_this.props.opened,
|
|
325
|
+
class Popover extends React.Component {
|
|
326
|
+
constructor(...args) {
|
|
327
|
+
super(...args);
|
|
328
|
+
this.state = {
|
|
329
|
+
opened: !!this.props.opened,
|
|
373
330
|
anchorElement: null,
|
|
374
|
-
placement:
|
|
331
|
+
placement: this.props.placement
|
|
375
332
|
};
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
333
|
+
this.contentRef = React.createRef();
|
|
334
|
+
this.handleClose = () => {
|
|
335
|
+
this.setState({
|
|
379
336
|
opened: false
|
|
380
337
|
}, () => {
|
|
381
|
-
_this
|
|
338
|
+
var _this$props$onClose, _this$props;
|
|
339
|
+
(_this$props$onClose = (_this$props = this.props).onClose) == null ? void 0 : _this$props$onClose.call(_this$props);
|
|
382
340
|
});
|
|
383
341
|
};
|
|
384
|
-
|
|
385
|
-
if (
|
|
386
|
-
|
|
342
|
+
this.handleOpen = () => {
|
|
343
|
+
if (this.props.dismissEnabled && this.state.opened) {
|
|
344
|
+
this.setState({
|
|
387
345
|
opened: false
|
|
388
346
|
});
|
|
389
347
|
} else {
|
|
390
|
-
|
|
348
|
+
this.setState({
|
|
391
349
|
opened: true
|
|
392
350
|
});
|
|
393
351
|
}
|
|
394
352
|
};
|
|
395
|
-
|
|
353
|
+
this.updateRef = ref => {
|
|
396
354
|
const actualRef = ref && ReactDOM.findDOMNode(ref);
|
|
397
|
-
if (actualRef &&
|
|
398
|
-
|
|
355
|
+
if (actualRef && this.state.anchorElement !== actualRef) {
|
|
356
|
+
this.setState({
|
|
399
357
|
anchorElement: actualRef
|
|
400
358
|
});
|
|
401
359
|
}
|
|
402
360
|
};
|
|
403
|
-
return _this;
|
|
404
361
|
}
|
|
405
|
-
|
|
362
|
+
static getDerivedStateFromProps(props, state) {
|
|
406
363
|
return {
|
|
407
364
|
opened: typeof props.opened === "boolean" ? props.opened : state.opened
|
|
408
365
|
};
|
|
409
|
-
}
|
|
410
|
-
|
|
411
|
-
_proto.renderContent = function renderContent() {
|
|
366
|
+
}
|
|
367
|
+
renderContent() {
|
|
412
368
|
const {
|
|
413
369
|
content
|
|
414
370
|
} = this.props;
|
|
@@ -418,8 +374,8 @@ let Popover = function (_React$Component) {
|
|
|
418
374
|
return React.cloneElement(popoverContents, {
|
|
419
375
|
ref: this.contentRef
|
|
420
376
|
});
|
|
421
|
-
}
|
|
422
|
-
|
|
377
|
+
}
|
|
378
|
+
renderPopper(uniqueId) {
|
|
423
379
|
const {
|
|
424
380
|
initialFocusId,
|
|
425
381
|
placement
|
|
@@ -440,11 +396,11 @@ let Popover = function (_React$Component) {
|
|
|
440
396
|
placement
|
|
441
397
|
})
|
|
442
398
|
}), this.renderContent())));
|
|
443
|
-
}
|
|
444
|
-
|
|
399
|
+
}
|
|
400
|
+
getHost() {
|
|
445
401
|
return maybeGetPortalMountedModalHostElement(this.state.anchorElement) || document.body;
|
|
446
|
-
}
|
|
447
|
-
|
|
402
|
+
}
|
|
403
|
+
render() {
|
|
448
404
|
const {
|
|
449
405
|
children,
|
|
450
406
|
dismissEnabled,
|
|
@@ -473,20 +429,14 @@ let Popover = function (_React$Component) {
|
|
|
473
429
|
onClose: this.handleClose,
|
|
474
430
|
contentRef: this.contentRef
|
|
475
431
|
}));
|
|
476
|
-
}
|
|
477
|
-
|
|
478
|
-
}(React.Component);
|
|
432
|
+
}
|
|
433
|
+
}
|
|
479
434
|
Popover.defaultProps = {
|
|
480
435
|
placement: "top"
|
|
481
436
|
};
|
|
482
437
|
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
function CloseButton() {
|
|
486
|
-
return _React$Component.apply(this, arguments) || this;
|
|
487
|
-
}
|
|
488
|
-
var _proto = CloseButton.prototype;
|
|
489
|
-
_proto.render = function render() {
|
|
438
|
+
class CloseButton extends React.Component {
|
|
439
|
+
render() {
|
|
490
440
|
const {
|
|
491
441
|
light,
|
|
492
442
|
"aria-label": ariaLabel,
|
|
@@ -506,21 +456,15 @@ let CloseButton = function (_React$Component) {
|
|
|
506
456
|
testId: testId
|
|
507
457
|
});
|
|
508
458
|
});
|
|
509
|
-
}
|
|
510
|
-
|
|
511
|
-
}(React.Component);
|
|
459
|
+
}
|
|
460
|
+
}
|
|
512
461
|
CloseButton.defaultProps = {
|
|
513
462
|
light: true,
|
|
514
463
|
"aria-label": "Close Popover"
|
|
515
464
|
};
|
|
516
465
|
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
function PopoverContentCore() {
|
|
520
|
-
return _React$Component.apply(this, arguments) || this;
|
|
521
|
-
}
|
|
522
|
-
var _proto = PopoverContentCore.prototype;
|
|
523
|
-
_proto.render = function render() {
|
|
466
|
+
class PopoverContentCore extends React.Component {
|
|
467
|
+
render() {
|
|
524
468
|
const {
|
|
525
469
|
children,
|
|
526
470
|
closeButtonLight,
|
|
@@ -539,9 +483,8 @@ let PopoverContentCore = function (_React$Component) {
|
|
|
539
483
|
style: styles$1.closeButton,
|
|
540
484
|
testId: `${testId || "popover"}-close-btn`
|
|
541
485
|
}), children);
|
|
542
|
-
}
|
|
543
|
-
|
|
544
|
-
}(React.Component);
|
|
486
|
+
}
|
|
487
|
+
}
|
|
545
488
|
PopoverContentCore.defaultProps = {
|
|
546
489
|
color: "white",
|
|
547
490
|
closeButtonLight: false,
|
|
@@ -576,17 +519,15 @@ const styles$1 = StyleSheet.create({
|
|
|
576
519
|
});
|
|
577
520
|
|
|
578
521
|
const StyledImage = addStyle("img");
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
_this = _React$Component.call.apply(_React$Component, [this].concat(args)) || this;
|
|
584
|
-
_this.maybeRenderImage = ({
|
|
522
|
+
class PopoverContent extends React.Component {
|
|
523
|
+
constructor(...args) {
|
|
524
|
+
super(...args);
|
|
525
|
+
this.maybeRenderImage = ({
|
|
585
526
|
placement
|
|
586
527
|
}) => {
|
|
587
528
|
const {
|
|
588
529
|
image
|
|
589
|
-
} =
|
|
530
|
+
} = this.props;
|
|
590
531
|
if (!image) {
|
|
591
532
|
return null;
|
|
592
533
|
}
|
|
@@ -594,10 +535,10 @@ let PopoverContent = function (_React$Component) {
|
|
|
594
535
|
style: [styles.image, placement === "bottom" && styles.imageToBottom]
|
|
595
536
|
}, image);
|
|
596
537
|
};
|
|
597
|
-
|
|
538
|
+
this.maybeRenderIcon = () => {
|
|
598
539
|
const {
|
|
599
540
|
icon
|
|
600
|
-
} =
|
|
541
|
+
} = this.props;
|
|
601
542
|
if (!icon) {
|
|
602
543
|
return null;
|
|
603
544
|
}
|
|
@@ -608,10 +549,10 @@ let PopoverContent = function (_React$Component) {
|
|
|
608
549
|
style: styles.icon
|
|
609
550
|
}));
|
|
610
551
|
};
|
|
611
|
-
|
|
552
|
+
this.maybeRenderActions = close => {
|
|
612
553
|
const {
|
|
613
554
|
actions
|
|
614
|
-
} =
|
|
555
|
+
} = this.props;
|
|
615
556
|
if (!actions) {
|
|
616
557
|
return null;
|
|
617
558
|
}
|
|
@@ -621,10 +562,8 @@ let PopoverContent = function (_React$Component) {
|
|
|
621
562
|
close: close
|
|
622
563
|
}) : actions);
|
|
623
564
|
};
|
|
624
|
-
return _this;
|
|
625
565
|
}
|
|
626
|
-
|
|
627
|
-
_proto.componentDidMount = function componentDidMount() {
|
|
566
|
+
componentDidMount() {
|
|
628
567
|
const {
|
|
629
568
|
icon,
|
|
630
569
|
image
|
|
@@ -632,15 +571,15 @@ let PopoverContent = function (_React$Component) {
|
|
|
632
571
|
if (image && icon) {
|
|
633
572
|
throw new Error("'image' and 'icon' cannot be used at the same time. You can fix this by either removing 'image' or 'icon' from your instance.");
|
|
634
573
|
}
|
|
635
|
-
}
|
|
636
|
-
|
|
574
|
+
}
|
|
575
|
+
validateProps({
|
|
637
576
|
placement
|
|
638
577
|
}) {
|
|
639
578
|
if (this.props.image && (placement === "left" || placement === "right")) {
|
|
640
579
|
throw new Error("'image' can only be vertically placed. You can fix this by either changing `placement` to `top` or `bottom` or removing the `image` prop inside `content`.");
|
|
641
580
|
}
|
|
642
|
-
}
|
|
643
|
-
|
|
581
|
+
}
|
|
582
|
+
render() {
|
|
644
583
|
const {
|
|
645
584
|
closeButtonLabel,
|
|
646
585
|
closeButtonVisible,
|
|
@@ -677,9 +616,8 @@ let PopoverContent = function (_React$Component) {
|
|
|
677
616
|
style: styles.title
|
|
678
617
|
}, title), React.createElement(Body, null, content))), this.maybeRenderActions(close));
|
|
679
618
|
});
|
|
680
|
-
}
|
|
681
|
-
|
|
682
|
-
}(React.Component);
|
|
619
|
+
}
|
|
620
|
+
}
|
|
683
621
|
PopoverContent.defaultProps = {
|
|
684
622
|
closeButtonVisible: false
|
|
685
623
|
};
|
package/dist/index.js
CHANGED
|
@@ -55,39 +55,20 @@ function _extends() {
|
|
|
55
55
|
return _extends.apply(this, arguments);
|
|
56
56
|
}
|
|
57
57
|
|
|
58
|
-
function _setPrototypeOf(o, p) {
|
|
59
|
-
_setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) {
|
|
60
|
-
o.__proto__ = p;
|
|
61
|
-
return o;
|
|
62
|
-
};
|
|
63
|
-
return _setPrototypeOf(o, p);
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
function _inheritsLoose(subClass, superClass) {
|
|
67
|
-
subClass.prototype = Object.create(superClass.prototype);
|
|
68
|
-
subClass.prototype.constructor = subClass;
|
|
69
|
-
_setPrototypeOf(subClass, superClass);
|
|
70
|
-
}
|
|
71
|
-
|
|
72
58
|
const defaultContext = {
|
|
73
59
|
close: undefined,
|
|
74
60
|
placement: "top"
|
|
75
61
|
};
|
|
76
62
|
var PopoverContext = React__namespace.createContext(defaultContext);
|
|
77
63
|
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
function PopoverAnchor() {
|
|
81
|
-
return _React$Component.apply(this, arguments) || this;
|
|
82
|
-
}
|
|
83
|
-
var _proto = PopoverAnchor.prototype;
|
|
84
|
-
_proto.componentDidMount = function componentDidMount() {
|
|
64
|
+
class PopoverAnchor extends React__namespace.Component {
|
|
65
|
+
componentDidMount() {
|
|
85
66
|
const anchorNode = ReactDOM__namespace.findDOMNode(this);
|
|
86
67
|
if (anchorNode) {
|
|
87
68
|
this.props.anchorRef(anchorNode);
|
|
88
69
|
}
|
|
89
|
-
}
|
|
90
|
-
|
|
70
|
+
}
|
|
71
|
+
render() {
|
|
91
72
|
const {
|
|
92
73
|
children,
|
|
93
74
|
id,
|
|
@@ -114,22 +95,16 @@ let PopoverAnchor = function (_React$Component) {
|
|
|
114
95
|
} : onClick
|
|
115
96
|
}));
|
|
116
97
|
}
|
|
117
|
-
};
|
|
118
|
-
return PopoverAnchor;
|
|
119
|
-
}(React__namespace.Component);
|
|
120
|
-
|
|
121
|
-
let PopoverDialog = function (_React$Component) {
|
|
122
|
-
_inheritsLoose(PopoverDialog, _React$Component);
|
|
123
|
-
function PopoverDialog() {
|
|
124
|
-
return _React$Component.apply(this, arguments) || this;
|
|
125
98
|
}
|
|
126
|
-
|
|
127
|
-
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
class PopoverDialog extends React__namespace.Component {
|
|
102
|
+
componentDidUpdate(prevProps) {
|
|
128
103
|
if (prevProps.placement !== this.props.placement) {
|
|
129
104
|
this.props.onUpdate(this.props.placement);
|
|
130
105
|
}
|
|
131
|
-
}
|
|
132
|
-
|
|
106
|
+
}
|
|
107
|
+
render() {
|
|
133
108
|
const {
|
|
134
109
|
placement,
|
|
135
110
|
children,
|
|
@@ -156,9 +131,8 @@ let PopoverDialog = function (_React$Component) {
|
|
|
156
131
|
placement: placement,
|
|
157
132
|
offset: tailOffset
|
|
158
133
|
})));
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
}(React__namespace.Component);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
162
136
|
const styles$2 = aphrodite.StyleSheet.create({
|
|
163
137
|
hide: {
|
|
164
138
|
pointerEvents: "none",
|
|
@@ -185,13 +159,11 @@ function findFocusableNodes(root) {
|
|
|
185
159
|
return Array.from(root.querySelectorAll(FOCUSABLE_ELEMENTS));
|
|
186
160
|
}
|
|
187
161
|
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
_this.setInitialFocusableElement = node => {
|
|
194
|
-
const firstFocusableElement = _this.maybeGetInitialFocusElement(node) || _this.maybeGetFirstFocusableElement(node) || node;
|
|
162
|
+
class InitialFocus extends React__namespace.Component {
|
|
163
|
+
constructor(...args) {
|
|
164
|
+
super(...args);
|
|
165
|
+
this.setInitialFocusableElement = node => {
|
|
166
|
+
const firstFocusableElement = this.maybeGetInitialFocusElement(node) || this.maybeGetFirstFocusableElement(node) || node;
|
|
195
167
|
if (firstFocusableElement === node) {
|
|
196
168
|
node.tabIndex = -1;
|
|
197
169
|
}
|
|
@@ -199,17 +171,15 @@ let InitialFocus = function (_React$Component) {
|
|
|
199
171
|
firstFocusableElement.focus();
|
|
200
172
|
}, 0);
|
|
201
173
|
};
|
|
202
|
-
return _this;
|
|
203
174
|
}
|
|
204
|
-
|
|
205
|
-
_proto.componentDidMount = function componentDidMount() {
|
|
175
|
+
componentDidMount() {
|
|
206
176
|
const node = ReactDOM__namespace.findDOMNode(this);
|
|
207
177
|
if (!node) {
|
|
208
178
|
return;
|
|
209
179
|
}
|
|
210
180
|
this.setInitialFocusableElement(node);
|
|
211
|
-
}
|
|
212
|
-
|
|
181
|
+
}
|
|
182
|
+
maybeGetInitialFocusElement(node) {
|
|
213
183
|
const {
|
|
214
184
|
initialFocusId
|
|
215
185
|
} = this.props;
|
|
@@ -217,45 +187,42 @@ let InitialFocus = function (_React$Component) {
|
|
|
217
187
|
return null;
|
|
218
188
|
}
|
|
219
189
|
return node.querySelector(`#${initialFocusId}`);
|
|
220
|
-
}
|
|
221
|
-
|
|
190
|
+
}
|
|
191
|
+
maybeGetFirstFocusableElement(node) {
|
|
222
192
|
const focusableElements = findFocusableNodes(node);
|
|
223
193
|
if (!focusableElements.length) {
|
|
224
194
|
return null;
|
|
225
195
|
}
|
|
226
196
|
return focusableElements[0];
|
|
227
|
-
}
|
|
228
|
-
|
|
197
|
+
}
|
|
198
|
+
render() {
|
|
229
199
|
return this.props.children;
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
}(React__namespace.Component);
|
|
200
|
+
}
|
|
201
|
+
}
|
|
233
202
|
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
_this.focusableElementsInPopover = [];
|
|
242
|
-
_this.addEventListeners = () => {
|
|
203
|
+
class FocusManager extends React__namespace.Component {
|
|
204
|
+
constructor(...args) {
|
|
205
|
+
super(...args);
|
|
206
|
+
this.nextElementAfterPopover = void 0;
|
|
207
|
+
this.rootNode = void 0;
|
|
208
|
+
this.focusableElementsInPopover = [];
|
|
209
|
+
this.addEventListeners = () => {
|
|
243
210
|
const {
|
|
244
211
|
anchorElement
|
|
245
|
-
} =
|
|
212
|
+
} = this.props;
|
|
246
213
|
if (anchorElement) {
|
|
247
|
-
anchorElement.addEventListener("keydown",
|
|
214
|
+
anchorElement.addEventListener("keydown", this.handleKeydownPreviousFocusableElement, true);
|
|
248
215
|
}
|
|
249
|
-
|
|
250
|
-
if (
|
|
251
|
-
|
|
216
|
+
this.nextElementAfterPopover = this.getNextFocusableElement();
|
|
217
|
+
if (this.nextElementAfterPopover) {
|
|
218
|
+
this.nextElementAfterPopover.addEventListener("keydown", this.handleKeydownNextFocusableElement, true);
|
|
252
219
|
}
|
|
253
220
|
};
|
|
254
|
-
|
|
221
|
+
this.getNextFocusableElement = () => {
|
|
255
222
|
const {
|
|
256
223
|
anchorElement
|
|
257
|
-
} =
|
|
258
|
-
if (!anchorElement ||
|
|
224
|
+
} = this.props;
|
|
225
|
+
if (!anchorElement || this.nextElementAfterPopover) {
|
|
259
226
|
return;
|
|
260
227
|
}
|
|
261
228
|
const focusableElements = findFocusableNodes(document);
|
|
@@ -266,7 +233,7 @@ let FocusManager = function (_React$Component) {
|
|
|
266
233
|
}
|
|
267
234
|
return;
|
|
268
235
|
};
|
|
269
|
-
|
|
236
|
+
this.getComponentRootNode = node => {
|
|
270
237
|
if (!node) {
|
|
271
238
|
return;
|
|
272
239
|
}
|
|
@@ -274,42 +241,40 @@ let FocusManager = function (_React$Component) {
|
|
|
274
241
|
if (!rootNode) {
|
|
275
242
|
throw new Error("Assertion error: root node should exist after mount");
|
|
276
243
|
}
|
|
277
|
-
|
|
278
|
-
|
|
244
|
+
this.rootNode = rootNode;
|
|
245
|
+
this.focusableElementsInPopover = findFocusableNodes(this.rootNode);
|
|
279
246
|
};
|
|
280
|
-
|
|
281
|
-
if (
|
|
282
|
-
|
|
247
|
+
this.handleFocusPreviousFocusableElement = () => {
|
|
248
|
+
if (this.props.anchorElement) {
|
|
249
|
+
this.props.anchorElement.focus();
|
|
283
250
|
}
|
|
284
251
|
};
|
|
285
|
-
|
|
286
|
-
if (
|
|
287
|
-
|
|
252
|
+
this.handleFocusNextFocusableElement = () => {
|
|
253
|
+
if (this.nextElementAfterPopover) {
|
|
254
|
+
this.nextElementAfterPopover.focus();
|
|
288
255
|
}
|
|
289
256
|
};
|
|
290
|
-
|
|
257
|
+
this.handleKeydownPreviousFocusableElement = e => {
|
|
291
258
|
if (e.key === "Tab" && !e.shiftKey) {
|
|
292
259
|
e.preventDefault();
|
|
293
|
-
|
|
260
|
+
this.focusableElementsInPopover[0].focus();
|
|
294
261
|
}
|
|
295
262
|
};
|
|
296
|
-
|
|
263
|
+
this.handleKeydownNextFocusableElement = e => {
|
|
297
264
|
if (e.key === "Tab" && e.shiftKey) {
|
|
298
265
|
e.preventDefault();
|
|
299
|
-
const lastElementIndex =
|
|
300
|
-
|
|
266
|
+
const lastElementIndex = this.focusableElementsInPopover.length - 1;
|
|
267
|
+
this.focusableElementsInPopover[lastElementIndex].focus();
|
|
301
268
|
}
|
|
302
269
|
};
|
|
303
|
-
return _this;
|
|
304
270
|
}
|
|
305
|
-
|
|
306
|
-
_proto.componentDidMount = function componentDidMount() {
|
|
271
|
+
componentDidMount() {
|
|
307
272
|
this.addEventListeners();
|
|
308
|
-
}
|
|
309
|
-
|
|
273
|
+
}
|
|
274
|
+
componentDidUpdate() {
|
|
310
275
|
this.addEventListeners();
|
|
311
|
-
}
|
|
312
|
-
|
|
276
|
+
}
|
|
277
|
+
componentWillUnmount() {
|
|
313
278
|
const {
|
|
314
279
|
anchorElement
|
|
315
280
|
} = this.props;
|
|
@@ -320,8 +285,8 @@ let FocusManager = function (_React$Component) {
|
|
|
320
285
|
if (this.nextElementAfterPopover) {
|
|
321
286
|
this.nextElementAfterPopover.removeEventListener("keydown", this.handleKeydownNextFocusableElement, true);
|
|
322
287
|
}
|
|
323
|
-
}
|
|
324
|
-
|
|
288
|
+
}
|
|
289
|
+
render() {
|
|
325
290
|
const {
|
|
326
291
|
children
|
|
327
292
|
} = this.props;
|
|
@@ -342,103 +307,94 @@ let FocusManager = function (_React$Component) {
|
|
|
342
307
|
position: "fixed"
|
|
343
308
|
}
|
|
344
309
|
}));
|
|
345
|
-
}
|
|
346
|
-
|
|
347
|
-
}(React__namespace.Component);
|
|
310
|
+
}
|
|
311
|
+
}
|
|
348
312
|
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
_this = _React$Component.call.apply(_React$Component, [this].concat(args)) || this;
|
|
354
|
-
_this.state = {
|
|
313
|
+
class PopoverEventListener extends React__namespace.Component {
|
|
314
|
+
constructor(...args) {
|
|
315
|
+
super(...args);
|
|
316
|
+
this.state = {
|
|
355
317
|
isFirstClick: true
|
|
356
318
|
};
|
|
357
|
-
|
|
319
|
+
this._handleKeyup = e => {
|
|
358
320
|
if (e.key === "Escape") {
|
|
359
321
|
e.preventDefault();
|
|
360
322
|
e.stopPropagation();
|
|
361
|
-
|
|
323
|
+
this.props.onClose();
|
|
362
324
|
}
|
|
363
325
|
};
|
|
364
|
-
|
|
326
|
+
this._handleClick = e => {
|
|
365
327
|
var _this$props$contentRe;
|
|
366
|
-
if (
|
|
367
|
-
|
|
328
|
+
if (this.state.isFirstClick) {
|
|
329
|
+
this.setState({
|
|
368
330
|
isFirstClick: false
|
|
369
331
|
});
|
|
370
332
|
return;
|
|
371
333
|
}
|
|
372
|
-
const node = ReactDOM__namespace.findDOMNode((_this$props$contentRe =
|
|
334
|
+
const node = ReactDOM__namespace.findDOMNode((_this$props$contentRe = this.props.contentRef) == null ? void 0 : _this$props$contentRe.current);
|
|
373
335
|
if (node && !node.contains(e.target)) {
|
|
374
336
|
e.preventDefault();
|
|
375
337
|
e.stopPropagation();
|
|
376
|
-
|
|
338
|
+
this.props.onClose();
|
|
377
339
|
}
|
|
378
340
|
};
|
|
379
|
-
return _this;
|
|
380
341
|
}
|
|
381
|
-
|
|
382
|
-
_proto.componentDidMount = function componentDidMount() {
|
|
342
|
+
componentDidMount() {
|
|
383
343
|
window.addEventListener("keyup", this._handleKeyup);
|
|
384
344
|
window.addEventListener("click", this._handleClick);
|
|
385
|
-
}
|
|
386
|
-
|
|
345
|
+
}
|
|
346
|
+
componentWillUnmount() {
|
|
387
347
|
window.removeEventListener("keyup", this._handleKeyup);
|
|
388
348
|
window.removeEventListener("click", this._handleClick);
|
|
389
|
-
}
|
|
390
|
-
|
|
349
|
+
}
|
|
350
|
+
render() {
|
|
391
351
|
return null;
|
|
392
|
-
}
|
|
393
|
-
|
|
394
|
-
}(React__namespace.Component);
|
|
352
|
+
}
|
|
353
|
+
}
|
|
395
354
|
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
_this.state = {
|
|
402
|
-
opened: !!_this.props.opened,
|
|
355
|
+
class Popover extends React__namespace.Component {
|
|
356
|
+
constructor(...args) {
|
|
357
|
+
super(...args);
|
|
358
|
+
this.state = {
|
|
359
|
+
opened: !!this.props.opened,
|
|
403
360
|
anchorElement: null,
|
|
404
|
-
placement:
|
|
361
|
+
placement: this.props.placement
|
|
405
362
|
};
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
363
|
+
this.contentRef = React__namespace.createRef();
|
|
364
|
+
this.handleClose = () => {
|
|
365
|
+
this.setState({
|
|
409
366
|
opened: false
|
|
410
367
|
}, () => {
|
|
411
|
-
_this
|
|
368
|
+
var _this$props$onClose, _this$props;
|
|
369
|
+
(_this$props$onClose = (_this$props = this.props).onClose) == null ? void 0 : _this$props$onClose.call(_this$props);
|
|
412
370
|
});
|
|
413
371
|
};
|
|
414
|
-
|
|
415
|
-
if (
|
|
416
|
-
|
|
372
|
+
this.handleOpen = () => {
|
|
373
|
+
if (this.props.dismissEnabled && this.state.opened) {
|
|
374
|
+
this.setState({
|
|
417
375
|
opened: false
|
|
418
376
|
});
|
|
419
377
|
} else {
|
|
420
|
-
|
|
378
|
+
this.setState({
|
|
421
379
|
opened: true
|
|
422
380
|
});
|
|
423
381
|
}
|
|
424
382
|
};
|
|
425
|
-
|
|
383
|
+
this.updateRef = ref => {
|
|
426
384
|
const actualRef = ref && ReactDOM__namespace.findDOMNode(ref);
|
|
427
|
-
if (actualRef &&
|
|
428
|
-
|
|
385
|
+
if (actualRef && this.state.anchorElement !== actualRef) {
|
|
386
|
+
this.setState({
|
|
429
387
|
anchorElement: actualRef
|
|
430
388
|
});
|
|
431
389
|
}
|
|
432
390
|
};
|
|
433
|
-
return _this;
|
|
434
391
|
}
|
|
435
|
-
|
|
392
|
+
static getDerivedStateFromProps(props, state) {
|
|
436
393
|
return {
|
|
437
394
|
opened: typeof props.opened === "boolean" ? props.opened : state.opened
|
|
438
395
|
};
|
|
439
|
-
}
|
|
440
|
-
|
|
441
|
-
_proto.renderContent = function renderContent() {
|
|
396
|
+
}
|
|
397
|
+
renderContent() {
|
|
442
398
|
const {
|
|
443
399
|
content
|
|
444
400
|
} = this.props;
|
|
@@ -448,8 +404,8 @@ let Popover = function (_React$Component) {
|
|
|
448
404
|
return React__namespace.cloneElement(popoverContents, {
|
|
449
405
|
ref: this.contentRef
|
|
450
406
|
});
|
|
451
|
-
}
|
|
452
|
-
|
|
407
|
+
}
|
|
408
|
+
renderPopper(uniqueId) {
|
|
453
409
|
const {
|
|
454
410
|
initialFocusId,
|
|
455
411
|
placement
|
|
@@ -470,11 +426,11 @@ let Popover = function (_React$Component) {
|
|
|
470
426
|
placement
|
|
471
427
|
})
|
|
472
428
|
}), this.renderContent())));
|
|
473
|
-
}
|
|
474
|
-
|
|
429
|
+
}
|
|
430
|
+
getHost() {
|
|
475
431
|
return wonderBlocksModal.maybeGetPortalMountedModalHostElement(this.state.anchorElement) || document.body;
|
|
476
|
-
}
|
|
477
|
-
|
|
432
|
+
}
|
|
433
|
+
render() {
|
|
478
434
|
const {
|
|
479
435
|
children,
|
|
480
436
|
dismissEnabled,
|
|
@@ -503,20 +459,14 @@ let Popover = function (_React$Component) {
|
|
|
503
459
|
onClose: this.handleClose,
|
|
504
460
|
contentRef: this.contentRef
|
|
505
461
|
}));
|
|
506
|
-
}
|
|
507
|
-
|
|
508
|
-
}(React__namespace.Component);
|
|
462
|
+
}
|
|
463
|
+
}
|
|
509
464
|
Popover.defaultProps = {
|
|
510
465
|
placement: "top"
|
|
511
466
|
};
|
|
512
467
|
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
function CloseButton() {
|
|
516
|
-
return _React$Component.apply(this, arguments) || this;
|
|
517
|
-
}
|
|
518
|
-
var _proto = CloseButton.prototype;
|
|
519
|
-
_proto.render = function render() {
|
|
468
|
+
class CloseButton extends React__namespace.Component {
|
|
469
|
+
render() {
|
|
520
470
|
const {
|
|
521
471
|
light,
|
|
522
472
|
"aria-label": ariaLabel,
|
|
@@ -536,21 +486,15 @@ let CloseButton = function (_React$Component) {
|
|
|
536
486
|
testId: testId
|
|
537
487
|
});
|
|
538
488
|
});
|
|
539
|
-
}
|
|
540
|
-
|
|
541
|
-
}(React__namespace.Component);
|
|
489
|
+
}
|
|
490
|
+
}
|
|
542
491
|
CloseButton.defaultProps = {
|
|
543
492
|
light: true,
|
|
544
493
|
"aria-label": "Close Popover"
|
|
545
494
|
};
|
|
546
495
|
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
function PopoverContentCore() {
|
|
550
|
-
return _React$Component.apply(this, arguments) || this;
|
|
551
|
-
}
|
|
552
|
-
var _proto = PopoverContentCore.prototype;
|
|
553
|
-
_proto.render = function render() {
|
|
496
|
+
class PopoverContentCore extends React__namespace.Component {
|
|
497
|
+
render() {
|
|
554
498
|
const {
|
|
555
499
|
children,
|
|
556
500
|
closeButtonLight,
|
|
@@ -569,9 +513,8 @@ let PopoverContentCore = function (_React$Component) {
|
|
|
569
513
|
style: styles$1.closeButton,
|
|
570
514
|
testId: `${testId || "popover"}-close-btn`
|
|
571
515
|
}), children);
|
|
572
|
-
}
|
|
573
|
-
|
|
574
|
-
}(React__namespace.Component);
|
|
516
|
+
}
|
|
517
|
+
}
|
|
575
518
|
PopoverContentCore.defaultProps = {
|
|
576
519
|
color: "white",
|
|
577
520
|
closeButtonLight: false,
|
|
@@ -606,17 +549,15 @@ const styles$1 = aphrodite.StyleSheet.create({
|
|
|
606
549
|
});
|
|
607
550
|
|
|
608
551
|
const StyledImage = wonderBlocksCore.addStyle("img");
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
_this = _React$Component.call.apply(_React$Component, [this].concat(args)) || this;
|
|
614
|
-
_this.maybeRenderImage = ({
|
|
552
|
+
class PopoverContent extends React__namespace.Component {
|
|
553
|
+
constructor(...args) {
|
|
554
|
+
super(...args);
|
|
555
|
+
this.maybeRenderImage = ({
|
|
615
556
|
placement
|
|
616
557
|
}) => {
|
|
617
558
|
const {
|
|
618
559
|
image
|
|
619
|
-
} =
|
|
560
|
+
} = this.props;
|
|
620
561
|
if (!image) {
|
|
621
562
|
return null;
|
|
622
563
|
}
|
|
@@ -624,10 +565,10 @@ let PopoverContent = function (_React$Component) {
|
|
|
624
565
|
style: [styles.image, placement === "bottom" && styles.imageToBottom]
|
|
625
566
|
}, image);
|
|
626
567
|
};
|
|
627
|
-
|
|
568
|
+
this.maybeRenderIcon = () => {
|
|
628
569
|
const {
|
|
629
570
|
icon
|
|
630
|
-
} =
|
|
571
|
+
} = this.props;
|
|
631
572
|
if (!icon) {
|
|
632
573
|
return null;
|
|
633
574
|
}
|
|
@@ -638,10 +579,10 @@ let PopoverContent = function (_React$Component) {
|
|
|
638
579
|
style: styles.icon
|
|
639
580
|
}));
|
|
640
581
|
};
|
|
641
|
-
|
|
582
|
+
this.maybeRenderActions = close => {
|
|
642
583
|
const {
|
|
643
584
|
actions
|
|
644
|
-
} =
|
|
585
|
+
} = this.props;
|
|
645
586
|
if (!actions) {
|
|
646
587
|
return null;
|
|
647
588
|
}
|
|
@@ -651,10 +592,8 @@ let PopoverContent = function (_React$Component) {
|
|
|
651
592
|
close: close
|
|
652
593
|
}) : actions);
|
|
653
594
|
};
|
|
654
|
-
return _this;
|
|
655
595
|
}
|
|
656
|
-
|
|
657
|
-
_proto.componentDidMount = function componentDidMount() {
|
|
596
|
+
componentDidMount() {
|
|
658
597
|
const {
|
|
659
598
|
icon,
|
|
660
599
|
image
|
|
@@ -662,15 +601,15 @@ let PopoverContent = function (_React$Component) {
|
|
|
662
601
|
if (image && icon) {
|
|
663
602
|
throw new Error("'image' and 'icon' cannot be used at the same time. You can fix this by either removing 'image' or 'icon' from your instance.");
|
|
664
603
|
}
|
|
665
|
-
}
|
|
666
|
-
|
|
604
|
+
}
|
|
605
|
+
validateProps({
|
|
667
606
|
placement
|
|
668
607
|
}) {
|
|
669
608
|
if (this.props.image && (placement === "left" || placement === "right")) {
|
|
670
609
|
throw new Error("'image' can only be vertically placed. You can fix this by either changing `placement` to `top` or `bottom` or removing the `image` prop inside `content`.");
|
|
671
610
|
}
|
|
672
|
-
}
|
|
673
|
-
|
|
611
|
+
}
|
|
612
|
+
render() {
|
|
674
613
|
const {
|
|
675
614
|
closeButtonLabel,
|
|
676
615
|
closeButtonVisible,
|
|
@@ -707,9 +646,8 @@ let PopoverContent = function (_React$Component) {
|
|
|
707
646
|
style: styles.title
|
|
708
647
|
}, title), React__namespace.createElement(wonderBlocksTypography.Body, null, content))), this.maybeRenderActions(close));
|
|
709
648
|
});
|
|
710
|
-
}
|
|
711
|
-
|
|
712
|
-
}(React__namespace.Component);
|
|
649
|
+
}
|
|
650
|
+
}
|
|
713
651
|
PopoverContent.defaultProps = {
|
|
714
652
|
closeButtonVisible: false
|
|
715
653
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@khanacademy/wonder-blocks-popover",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.7",
|
|
4
4
|
"design": "v1",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -17,13 +17,13 @@
|
|
|
17
17
|
"dependencies": {
|
|
18
18
|
"@babel/runtime": "^7.18.6",
|
|
19
19
|
"@khanacademy/wonder-blocks-color": "^2.0.1",
|
|
20
|
-
"@khanacademy/wonder-blocks-core": "^5.0.
|
|
21
|
-
"@khanacademy/wonder-blocks-icon": "^2.0.
|
|
22
|
-
"@khanacademy/wonder-blocks-icon-button": "^4.0.
|
|
23
|
-
"@khanacademy/wonder-blocks-modal": "^4.0.
|
|
20
|
+
"@khanacademy/wonder-blocks-core": "^5.0.4",
|
|
21
|
+
"@khanacademy/wonder-blocks-icon": "^2.0.7",
|
|
22
|
+
"@khanacademy/wonder-blocks-icon-button": "^4.0.7",
|
|
23
|
+
"@khanacademy/wonder-blocks-modal": "^4.0.7",
|
|
24
24
|
"@khanacademy/wonder-blocks-spacing": "^4.0.1",
|
|
25
|
-
"@khanacademy/wonder-blocks-tooltip": "^2.0.
|
|
26
|
-
"@khanacademy/wonder-blocks-typography": "^2.0.
|
|
25
|
+
"@khanacademy/wonder-blocks-tooltip": "^2.0.7",
|
|
26
|
+
"@khanacademy/wonder-blocks-typography": "^2.0.7"
|
|
27
27
|
},
|
|
28
28
|
"peerDependencies": {
|
|
29
29
|
"@popperjs/core": "^2.10.1",
|
|
@@ -33,6 +33,6 @@
|
|
|
33
33
|
"react-popper": "^2.0.0"
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {
|
|
36
|
-
"wb-dev-build-settings": "^0.9.
|
|
36
|
+
"wb-dev-build-settings": "^0.9.6"
|
|
37
37
|
}
|
|
38
38
|
}
|