@targetprocess/popover 12.19.2-alpha.3 → 12.19.2-alpha.5
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/Popover.tsx +12 -3
- package/PopoverContainer.tsx +9 -1
- package/StatlessPopover.tsx +2 -0
- package/dist/Popover.d.ts +1 -0
- package/dist/PopoverContainer.d.ts +3 -0
- package/dist/StatlessPopover.d.ts +1 -0
- package/dist/popover.es.js +27 -7
- package/dist/popover.js +46 -25
- package/package.json +2 -2
package/Popover.tsx
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React from 'react'
|
|
1
|
+
import React, {createRef} from 'react'
|
|
2
2
|
import PropTypes from 'prop-types'
|
|
3
3
|
import {PopoverPosition} from './PopoverPosition'
|
|
4
4
|
import {PopoverBody} from './PopoverBody'
|
|
@@ -148,21 +148,30 @@ export class Popover extends React.Component<PopoverProps, PopoverState> {
|
|
|
148
148
|
}
|
|
149
149
|
}
|
|
150
150
|
|
|
151
|
+
childrenRef = createRef<HTMLElement>()
|
|
152
|
+
|
|
151
153
|
render() {
|
|
152
154
|
const isOpen = typeof this.props.isOpen === 'undefined' ? this.state.isOpen : this.props.isOpen
|
|
153
155
|
const children =
|
|
154
156
|
typeof this.props.children === 'function'
|
|
155
|
-
? this.props.children({isOpen, setOpened: this.setOpened})
|
|
157
|
+
? this.props.children({isOpen, setOpened: this.setOpened, ref: this.childrenRef})
|
|
156
158
|
: this.props.children
|
|
159
|
+
const childrenWithRef = React.Children.map(children, child =>
|
|
160
|
+
React.cloneElement(child, {ref: this.childrenRef})
|
|
161
|
+
)
|
|
157
162
|
|
|
158
163
|
return (
|
|
159
164
|
<StatelessPopover
|
|
160
165
|
{...this.props}
|
|
161
166
|
onOuterAction={this.onOuterAction}
|
|
167
|
+
onEscapeAction={() => {
|
|
168
|
+
this.setOpened(false)
|
|
169
|
+
this.childrenRef.current?.focus()
|
|
170
|
+
}}
|
|
162
171
|
isOpen={isOpen}
|
|
163
172
|
role={this.props.role}
|
|
164
173
|
>
|
|
165
|
-
{
|
|
174
|
+
{childrenWithRef}
|
|
166
175
|
</StatelessPopover>
|
|
167
176
|
)
|
|
168
177
|
}
|
package/PopoverContainer.tsx
CHANGED
|
@@ -19,6 +19,7 @@ type PopoverContainerProps = {
|
|
|
19
19
|
showTip?: boolean
|
|
20
20
|
zIndex: number
|
|
21
21
|
role?: 'tooltip' | 'dialog'
|
|
22
|
+
onEscapeAction: () => void
|
|
22
23
|
}
|
|
23
24
|
|
|
24
25
|
type PopoverContainerState = {
|
|
@@ -88,7 +89,8 @@ export class PopoverContainer extends React.Component<
|
|
|
88
89
|
containerElement: PropTypes.object,
|
|
89
90
|
className: PropTypes.string,
|
|
90
91
|
trackScroll: PropTypes.bool,
|
|
91
|
-
role: PropTypes.oneOf(['tooltip', 'dialog'])
|
|
92
|
+
role: PropTypes.oneOf(['tooltip', 'dialog']),
|
|
93
|
+
onEscapeAction: PropTypes.func
|
|
92
94
|
}
|
|
93
95
|
|
|
94
96
|
static defaultProps = {
|
|
@@ -200,6 +202,11 @@ export class PopoverContainer extends React.Component<
|
|
|
200
202
|
|
|
201
203
|
return null
|
|
202
204
|
}
|
|
205
|
+
handleKeyDown = event => {
|
|
206
|
+
if (event.key === 'Escape') {
|
|
207
|
+
this.props.onEscapeAction()
|
|
208
|
+
}
|
|
209
|
+
}
|
|
203
210
|
|
|
204
211
|
render() {
|
|
205
212
|
const getPopoverPosition =
|
|
@@ -263,6 +270,7 @@ export class PopoverContainer extends React.Component<
|
|
|
263
270
|
className={this.props.className}
|
|
264
271
|
role={this.props.role}
|
|
265
272
|
tabIndex={0}
|
|
273
|
+
onKeyDown={this.handleKeyDown}
|
|
266
274
|
>
|
|
267
275
|
{this.props.children}
|
|
268
276
|
</div>
|
package/StatlessPopover.tsx
CHANGED
|
@@ -18,6 +18,7 @@ export type StatelessPopoverProps = {
|
|
|
18
18
|
onOuterAction?: (evt: Event) => void
|
|
19
19
|
trackScroll?: boolean
|
|
20
20
|
role?: 'tooltip' | 'dialog'
|
|
21
|
+
onEscapeAction: () => void
|
|
21
22
|
}
|
|
22
23
|
|
|
23
24
|
export class StatelessPopover extends React.Component<StatelessPopoverProps> {
|
|
@@ -42,6 +43,7 @@ export class StatelessPopover extends React.Component<StatelessPopoverProps> {
|
|
|
42
43
|
zIndex={props.zIndex}
|
|
43
44
|
trackScroll={props.trackScroll}
|
|
44
45
|
role={this.props.role}
|
|
46
|
+
onEscapeAction={this.props.onEscapeAction}
|
|
45
47
|
>
|
|
46
48
|
{props.body}
|
|
47
49
|
</PopoverContainer>
|
package/dist/Popover.d.ts
CHANGED
|
@@ -12,6 +12,7 @@ declare type PopoverContainerProps = {
|
|
|
12
12
|
showTip?: boolean;
|
|
13
13
|
zIndex: number;
|
|
14
14
|
role?: 'tooltip' | 'dialog';
|
|
15
|
+
onEscapeAction: () => void;
|
|
15
16
|
};
|
|
16
17
|
declare type PopoverContainerState = {
|
|
17
18
|
adjusted: boolean;
|
|
@@ -28,6 +29,7 @@ export declare class PopoverContainer extends React.Component<PopoverContainerPr
|
|
|
28
29
|
className: PropTypes.Requireable<string>;
|
|
29
30
|
trackScroll: PropTypes.Requireable<boolean>;
|
|
30
31
|
role: PropTypes.Requireable<string>;
|
|
32
|
+
onEscapeAction: PropTypes.Requireable<(...args: any[]) => any>;
|
|
31
33
|
};
|
|
32
34
|
static defaultProps: {
|
|
33
35
|
trackScroll: boolean;
|
|
@@ -42,6 +44,7 @@ export declare class PopoverContainer extends React.Component<PopoverContainerPr
|
|
|
42
44
|
componentDidUpdate(previousProps: any): void;
|
|
43
45
|
componentWillUnmount(): void;
|
|
44
46
|
getPopoverTipPosition: (popoverPosition: any, containerPosition: any) => "top" | "bottom" | "right" | "left";
|
|
47
|
+
handleKeyDown: (event: any) => void;
|
|
45
48
|
render(): JSX.Element;
|
|
46
49
|
}
|
|
47
50
|
export {};
|
|
@@ -13,6 +13,7 @@ export declare type StatelessPopoverProps = {
|
|
|
13
13
|
onOuterAction?: (evt: Event) => void;
|
|
14
14
|
trackScroll?: boolean;
|
|
15
15
|
role?: 'tooltip' | 'dialog';
|
|
16
|
+
onEscapeAction: () => void;
|
|
16
17
|
};
|
|
17
18
|
export declare class StatelessPopover extends React.Component<StatelessPopoverProps> {
|
|
18
19
|
renderPortalContent({ props, container, positioningTarget }: {
|
package/dist/popover.es.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React from 'react';
|
|
1
|
+
import React, { createRef } from 'react';
|
|
2
2
|
import { SpaceXS } from '@targetprocess/global-constants';
|
|
3
3
|
import classNames from 'classnames';
|
|
4
4
|
import ReactDOM from 'react-dom';
|
|
@@ -205,8 +205,8 @@ function styleInject(css, ref) {
|
|
|
205
205
|
}
|
|
206
206
|
}
|
|
207
207
|
|
|
208
|
-
var css = ".popover-body-container__popover__12-19-2-alpha-
|
|
209
|
-
var styles = {"popover-body-container":"popover-body-container__popover__12-19-2-alpha-
|
|
208
|
+
var css = ".popover-body-container__popover__12-19-2-alpha-5 {\r\n -webkit-box-shadow: var(--BoxShadowL, 0 4px 16px 0 rgba(0, 0, 0, 0.12));\r\n box-shadow: var(--BoxShadowL, 0 4px 16px 0 rgba(0, 0, 0, 0.12));\r\n border-radius: var(--BorderRadiusL, 4px);\r\n border: 1px solid var(--HighlightBlockBorderColor, rgba(64, 66, 73, 0.1));\r\n background: var(--BackgroundDefault, #FFFFFF);\r\n z-index: var(--ZIndexModal, 10001);\r\n -webkit-box-sizing: border-box;\r\n box-sizing: border-box;\r\n}\r\n\r\n.popover-body__popover__12-19-2-alpha-5 {\r\n -webkit-box-sizing: border-box;\r\n box-sizing: border-box;\r\n padding: var(--SpaceSM, 12px);\r\n font-size: var(--FontSizeDefault, 13px);\r\n color: var(--FontColorDefault, #000000);\r\n}\r\n\r\n.popover-body--no-padding__popover__12-19-2-alpha-5 {\r\n padding: 0;\r\n }\r\n\r\n.popover-tip__popover__12-19-2-alpha-5 {\r\n position: absolute;\r\n pointer-events: none;\r\n z-index: calc(var(--ZIndexModal, 10001) + 1);\r\n overflow: hidden;\r\n display: -webkit-box;\r\n display: -ms-flexbox;\r\n display: flex;\r\n -webkit-box-align: center;\r\n -ms-flex-align: center;\r\n align-items: center;\r\n -webkit-box-pack: center;\r\n -ms-flex-pack: center;\r\n justify-content: center;\r\n}\r\n\r\n.popover-tip__popover__12-19-2-alpha-5:before {\r\n content: '';\r\n position: absolute;\r\n display: block;\r\n -webkit-box-sizing: border-box;\r\n box-sizing: border-box;\r\n background-color: var(--BackgroundDefault, #FFFFFF);\r\n border: 1px solid var(--HighlightBlockBorderColor, rgba(64, 66, 73, 0.1));\r\n /*\r\n geometry FTW\r\n\r\n 2*$popoverTipSize\r\n _______ _______\r\n | /|\\ |\r\n | / | \\ | $popoverTipSize\r\n | / | \\ |\r\n |/______|______\\|\r\n since tip is rotated 45 degrees, its width and height is a\r\n diagonal of a square with side=$popoverTipSize, thus diagonal\r\n is sqrt(2) * $popoverTipSize.\r\n sqrt(2) ~= 1.414, 1.4 used here to prevent too much rounding\r\n */\r\n width: 11.2px;\r\n height: 11.2px;\r\n -webkit-transform: rotate(45deg);\r\n transform: rotate(45deg);\r\n }\r\n\r\n.popover-tip--bottom__popover__12-19-2-alpha-5,\r\n .popover-tip--top__popover__12-19-2-alpha-5 {\r\n width: 100%;\r\n border-top: 1px var(--BackgroundDefault, #FFFFFF);\r\n border-bottom: 1px var(--BackgroundDefault, #FFFFFF);\r\n height: 9px;\r\n }\r\n\r\n.popover-tip--left__popover__12-19-2-alpha-5,\r\n .popover-tip--right__popover__12-19-2-alpha-5 {\r\n border-left: 1px var(--BackgroundDefault, #FFFFFF);\r\n border-right: 1px var(--BackgroundDefault, #FFFFFF);\r\n height: 100%;\r\n width: 9px;\r\n }\r\n\r\n/*\r\n To determine tip position, we need to rotate it\r\n along the \"tip\" point, after that, the \"tip\" point\r\n can be placed with exactly 50% offset from the origin\r\n so that it is centered.\r\n */\r\n\r\n.popover-tip--bottom__popover__12-19-2-alpha-5:before {\r\n -webkit-transform-origin: left top;\r\n transform-origin: left top;\r\n left: 50%;\r\n top: 0;\r\n }\r\n\r\n.popover-tip--top__popover__12-19-2-alpha-5:before {\r\n -webkit-transform-origin: right bottom;\r\n transform-origin: right bottom;\r\n right: 50%;\r\n bottom: 0;\r\n }\r\n\r\n.popover-tip--left__popover__12-19-2-alpha-5:before {\r\n -webkit-transform-origin: right top;\r\n transform-origin: right top;\r\n right: 0;\r\n top: 50%;\r\n }\r\n\r\n.popover-tip--right__popover__12-19-2-alpha-5:before {\r\n -webkit-transform-origin: left bottom;\r\n transform-origin: left bottom;\r\n left: 0;\r\n bottom: 50%;\r\n }\r\n";
|
|
209
|
+
var styles = {"popover-body-container":"popover-body-container__popover__12-19-2-alpha-5","popover-body":"popover-body__popover__12-19-2-alpha-5","popover-body--no-padding":"popover-body--no-padding__popover__12-19-2-alpha-5","popover-tip":"popover-tip__popover__12-19-2-alpha-5","popover-tip--bottom":"popover-tip--bottom__popover__12-19-2-alpha-5","popover-tip--top":"popover-tip--top__popover__12-19-2-alpha-5","popover-tip--left":"popover-tip--left__popover__12-19-2-alpha-5","popover-tip--right":"popover-tip--right__popover__12-19-2-alpha-5"};
|
|
210
210
|
styleInject(css);
|
|
211
211
|
|
|
212
212
|
var PopoverBody = function PopoverBody(_ref) {
|
|
@@ -323,6 +323,11 @@ var PopoverContainer = /*#__PURE__*/function (_React$Component) {
|
|
|
323
323
|
}
|
|
324
324
|
return null;
|
|
325
325
|
};
|
|
326
|
+
_this.handleKeyDown = function (event) {
|
|
327
|
+
if (event.key === 'Escape') {
|
|
328
|
+
_this.props.onEscapeAction();
|
|
329
|
+
}
|
|
330
|
+
};
|
|
326
331
|
return _this;
|
|
327
332
|
}
|
|
328
333
|
_createClass(PopoverContainer, [{
|
|
@@ -435,7 +440,8 @@ var PopoverContainer = /*#__PURE__*/function (_React$Component) {
|
|
|
435
440
|
}, position),
|
|
436
441
|
className: this.props.className,
|
|
437
442
|
role: this.props.role,
|
|
438
|
-
tabIndex: 0
|
|
443
|
+
tabIndex: 0,
|
|
444
|
+
onKeyDown: this.handleKeyDown
|
|
439
445
|
}, this.props.children));
|
|
440
446
|
}
|
|
441
447
|
}]);
|
|
@@ -570,7 +576,8 @@ var StatelessPopover = /*#__PURE__*/function (_React$Component) {
|
|
|
570
576
|
showTip: props.showTip,
|
|
571
577
|
zIndex: props.zIndex,
|
|
572
578
|
trackScroll: props.trackScroll,
|
|
573
|
-
role: this.props.role
|
|
579
|
+
role: this.props.role,
|
|
580
|
+
onEscapeAction: this.props.onEscapeAction
|
|
574
581
|
}, props.body);
|
|
575
582
|
if (!props.inline) {
|
|
576
583
|
return ReactDOM.createPortal(popoverContent, container);
|
|
@@ -634,21 +641,34 @@ var Popover = /*#__PURE__*/function (_React$Component) {
|
|
|
634
641
|
_this.props.onOuterAction(event);
|
|
635
642
|
}
|
|
636
643
|
};
|
|
644
|
+
_this.childrenRef = createRef();
|
|
637
645
|
return _this;
|
|
638
646
|
}
|
|
639
647
|
_createClass(Popover, [{
|
|
640
648
|
key: "render",
|
|
641
649
|
value: function render() {
|
|
650
|
+
var _this2 = this;
|
|
642
651
|
var isOpen = typeof this.props.isOpen === 'undefined' ? this.state.isOpen : this.props.isOpen;
|
|
643
652
|
var children = typeof this.props.children === 'function' ? this.props.children({
|
|
644
653
|
isOpen: isOpen,
|
|
645
|
-
setOpened: this.setOpened
|
|
654
|
+
setOpened: this.setOpened,
|
|
655
|
+
ref: this.childrenRef
|
|
646
656
|
}) : this.props.children;
|
|
657
|
+
var childrenWithRef = React.Children.map(children, function (child) {
|
|
658
|
+
return React.cloneElement(child, {
|
|
659
|
+
ref: _this2.childrenRef
|
|
660
|
+
});
|
|
661
|
+
});
|
|
647
662
|
return React.createElement(StatelessPopover, Object.assign({}, this.props, {
|
|
648
663
|
onOuterAction: this.onOuterAction,
|
|
664
|
+
onEscapeAction: function onEscapeAction() {
|
|
665
|
+
var _a;
|
|
666
|
+
_this2.setOpened(false);
|
|
667
|
+
(_a = _this2.childrenRef.current) === null || _a === void 0 ? void 0 : _a.focus();
|
|
668
|
+
},
|
|
649
669
|
isOpen: isOpen,
|
|
650
670
|
role: this.props.role
|
|
651
|
-
}),
|
|
671
|
+
}), childrenWithRef);
|
|
652
672
|
}
|
|
653
673
|
}]);
|
|
654
674
|
return Popover;
|
package/dist/popover.js
CHANGED
|
@@ -4,7 +4,8 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
4
4
|
|
|
5
5
|
function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
|
|
6
6
|
|
|
7
|
-
var React =
|
|
7
|
+
var React = require('react');
|
|
8
|
+
var React__default = _interopDefault(React);
|
|
8
9
|
var globalConstants = require('@targetprocess/global-constants');
|
|
9
10
|
var classNames = _interopDefault(require('classnames'));
|
|
10
11
|
var ReactDOM = _interopDefault(require('react-dom'));
|
|
@@ -211,8 +212,8 @@ function styleInject(css, ref) {
|
|
|
211
212
|
}
|
|
212
213
|
}
|
|
213
214
|
|
|
214
|
-
var css = ".popover-body-container__popover__12-19-2-alpha-
|
|
215
|
-
var styles = {"popover-body-container":"popover-body-container__popover__12-19-2-alpha-
|
|
215
|
+
var css = ".popover-body-container__popover__12-19-2-alpha-5 {\r\n -webkit-box-shadow: var(--BoxShadowL, 0 4px 16px 0 rgba(0, 0, 0, 0.12));\r\n box-shadow: var(--BoxShadowL, 0 4px 16px 0 rgba(0, 0, 0, 0.12));\r\n border-radius: var(--BorderRadiusL, 4px);\r\n border: 1px solid var(--HighlightBlockBorderColor, rgba(64, 66, 73, 0.1));\r\n background: var(--BackgroundDefault, #FFFFFF);\r\n z-index: var(--ZIndexModal, 10001);\r\n -webkit-box-sizing: border-box;\r\n box-sizing: border-box;\r\n}\r\n\r\n.popover-body__popover__12-19-2-alpha-5 {\r\n -webkit-box-sizing: border-box;\r\n box-sizing: border-box;\r\n padding: var(--SpaceSM, 12px);\r\n font-size: var(--FontSizeDefault, 13px);\r\n color: var(--FontColorDefault, #000000);\r\n}\r\n\r\n.popover-body--no-padding__popover__12-19-2-alpha-5 {\r\n padding: 0;\r\n }\r\n\r\n.popover-tip__popover__12-19-2-alpha-5 {\r\n position: absolute;\r\n pointer-events: none;\r\n z-index: calc(var(--ZIndexModal, 10001) + 1);\r\n overflow: hidden;\r\n display: -webkit-box;\r\n display: -ms-flexbox;\r\n display: flex;\r\n -webkit-box-align: center;\r\n -ms-flex-align: center;\r\n align-items: center;\r\n -webkit-box-pack: center;\r\n -ms-flex-pack: center;\r\n justify-content: center;\r\n}\r\n\r\n.popover-tip__popover__12-19-2-alpha-5:before {\r\n content: '';\r\n position: absolute;\r\n display: block;\r\n -webkit-box-sizing: border-box;\r\n box-sizing: border-box;\r\n background-color: var(--BackgroundDefault, #FFFFFF);\r\n border: 1px solid var(--HighlightBlockBorderColor, rgba(64, 66, 73, 0.1));\r\n /*\r\n geometry FTW\r\n\r\n 2*$popoverTipSize\r\n _______ _______\r\n | /|\\ |\r\n | / | \\ | $popoverTipSize\r\n | / | \\ |\r\n |/______|______\\|\r\n since tip is rotated 45 degrees, its width and height is a\r\n diagonal of a square with side=$popoverTipSize, thus diagonal\r\n is sqrt(2) * $popoverTipSize.\r\n sqrt(2) ~= 1.414, 1.4 used here to prevent too much rounding\r\n */\r\n width: 11.2px;\r\n height: 11.2px;\r\n -webkit-transform: rotate(45deg);\r\n transform: rotate(45deg);\r\n }\r\n\r\n.popover-tip--bottom__popover__12-19-2-alpha-5,\r\n .popover-tip--top__popover__12-19-2-alpha-5 {\r\n width: 100%;\r\n border-top: 1px var(--BackgroundDefault, #FFFFFF);\r\n border-bottom: 1px var(--BackgroundDefault, #FFFFFF);\r\n height: 9px;\r\n }\r\n\r\n.popover-tip--left__popover__12-19-2-alpha-5,\r\n .popover-tip--right__popover__12-19-2-alpha-5 {\r\n border-left: 1px var(--BackgroundDefault, #FFFFFF);\r\n border-right: 1px var(--BackgroundDefault, #FFFFFF);\r\n height: 100%;\r\n width: 9px;\r\n }\r\n\r\n/*\r\n To determine tip position, we need to rotate it\r\n along the \"tip\" point, after that, the \"tip\" point\r\n can be placed with exactly 50% offset from the origin\r\n so that it is centered.\r\n */\r\n\r\n.popover-tip--bottom__popover__12-19-2-alpha-5:before {\r\n -webkit-transform-origin: left top;\r\n transform-origin: left top;\r\n left: 50%;\r\n top: 0;\r\n }\r\n\r\n.popover-tip--top__popover__12-19-2-alpha-5:before {\r\n -webkit-transform-origin: right bottom;\r\n transform-origin: right bottom;\r\n right: 50%;\r\n bottom: 0;\r\n }\r\n\r\n.popover-tip--left__popover__12-19-2-alpha-5:before {\r\n -webkit-transform-origin: right top;\r\n transform-origin: right top;\r\n right: 0;\r\n top: 50%;\r\n }\r\n\r\n.popover-tip--right__popover__12-19-2-alpha-5:before {\r\n -webkit-transform-origin: left bottom;\r\n transform-origin: left bottom;\r\n left: 0;\r\n bottom: 50%;\r\n }\r\n";
|
|
216
|
+
var styles = {"popover-body-container":"popover-body-container__popover__12-19-2-alpha-5","popover-body":"popover-body__popover__12-19-2-alpha-5","popover-body--no-padding":"popover-body--no-padding__popover__12-19-2-alpha-5","popover-tip":"popover-tip__popover__12-19-2-alpha-5","popover-tip--bottom":"popover-tip--bottom__popover__12-19-2-alpha-5","popover-tip--top":"popover-tip--top__popover__12-19-2-alpha-5","popover-tip--left":"popover-tip--left__popover__12-19-2-alpha-5","popover-tip--right":"popover-tip--right__popover__12-19-2-alpha-5"};
|
|
216
217
|
styleInject(css);
|
|
217
218
|
|
|
218
219
|
var PopoverBody = function PopoverBody(_ref) {
|
|
@@ -220,9 +221,9 @@ var PopoverBody = function PopoverBody(_ref) {
|
|
|
220
221
|
className = _ref.className,
|
|
221
222
|
classNameBody = _ref.classNameBody,
|
|
222
223
|
noPadding = _ref.noPadding;
|
|
223
|
-
return
|
|
224
|
+
return React__default.createElement("div", {
|
|
224
225
|
className: classNames(className, styles['popover-body-container'])
|
|
225
|
-
},
|
|
226
|
+
}, React__default.createElement("div", {
|
|
226
227
|
className: classNames(classNameBody, styles['popover-body'], noPadding && styles['popover-body--no-padding'])
|
|
227
228
|
}, children));
|
|
228
229
|
};
|
|
@@ -302,7 +303,7 @@ var PopoverContainer = /*#__PURE__*/function (_React$Component) {
|
|
|
302
303
|
_classCallCheck(this, PopoverContainer);
|
|
303
304
|
_this = _possibleConstructorReturn(this, _getPrototypeOf(PopoverContainer).apply(this, arguments));
|
|
304
305
|
_this.mounted = false;
|
|
305
|
-
_this.popoverContentRef =
|
|
306
|
+
_this.popoverContentRef = React__default.createRef();
|
|
306
307
|
_this.state = {
|
|
307
308
|
adjusted: false,
|
|
308
309
|
positionX: 0,
|
|
@@ -329,6 +330,11 @@ var PopoverContainer = /*#__PURE__*/function (_React$Component) {
|
|
|
329
330
|
}
|
|
330
331
|
return null;
|
|
331
332
|
};
|
|
333
|
+
_this.handleKeyDown = function (event) {
|
|
334
|
+
if (event.key === 'Escape') {
|
|
335
|
+
_this.props.onEscapeAction();
|
|
336
|
+
}
|
|
337
|
+
};
|
|
332
338
|
return _this;
|
|
333
339
|
}
|
|
334
340
|
_createClass(PopoverContainer, [{
|
|
@@ -414,7 +420,7 @@ var PopoverContainer = /*#__PURE__*/function (_React$Component) {
|
|
|
414
420
|
};
|
|
415
421
|
var tipPosition = this.getPopoverTipPosition(position, containerPosition);
|
|
416
422
|
// FIXME: position.top cast to number, because value may be not a number
|
|
417
|
-
return
|
|
423
|
+
return React__default.createElement("div", {
|
|
418
424
|
style: _extends({
|
|
419
425
|
position: 'absolute'
|
|
420
426
|
}, containerPosition, {
|
|
@@ -424,7 +430,7 @@ var PopoverContainer = /*#__PURE__*/function (_React$Component) {
|
|
|
424
430
|
transitionProperty: 'opacity',
|
|
425
431
|
opacity: this.state.adjusted ? 1 : 0
|
|
426
432
|
})
|
|
427
|
-
}, this.props.showTip && tipPosition &&
|
|
433
|
+
}, this.props.showTip && tipPosition && React__default.createElement("div", {
|
|
428
434
|
className: classNames(styles['popover-tip'], styles["popover-tip--".concat(tipPosition)], 'popover-tip'),
|
|
429
435
|
style: {
|
|
430
436
|
top: tipPosition === 'bottom' && position.top - 8,
|
|
@@ -432,7 +438,7 @@ var PopoverContainer = /*#__PURE__*/function (_React$Component) {
|
|
|
432
438
|
left: tipPosition === 'right' && position.left - 8,
|
|
433
439
|
right: tipPosition === 'left' && position.right - 8
|
|
434
440
|
}
|
|
435
|
-
}),
|
|
441
|
+
}), React__default.createElement("div", {
|
|
436
442
|
ref: this.popoverContentRef,
|
|
437
443
|
"aria-modal": "true",
|
|
438
444
|
style: _extends({
|
|
@@ -441,12 +447,13 @@ var PopoverContainer = /*#__PURE__*/function (_React$Component) {
|
|
|
441
447
|
}, position),
|
|
442
448
|
className: this.props.className,
|
|
443
449
|
role: this.props.role,
|
|
444
|
-
tabIndex: 0
|
|
450
|
+
tabIndex: 0,
|
|
451
|
+
onKeyDown: this.handleKeyDown
|
|
445
452
|
}, this.props.children));
|
|
446
453
|
}
|
|
447
454
|
}]);
|
|
448
455
|
return PopoverContainer;
|
|
449
|
-
}(
|
|
456
|
+
}(React__default.Component);
|
|
450
457
|
PopoverContainer.defaultProps = {
|
|
451
458
|
trackScroll: true
|
|
452
459
|
};
|
|
@@ -460,7 +467,7 @@ var PositioningTarget = /*#__PURE__*/function (_React$Component) {
|
|
|
460
467
|
_this.state = {
|
|
461
468
|
target: null
|
|
462
469
|
};
|
|
463
|
-
_this.targetRef =
|
|
470
|
+
_this.targetRef = React__default.createRef();
|
|
464
471
|
return _this;
|
|
465
472
|
}
|
|
466
473
|
_createClass(PositioningTarget, [{
|
|
@@ -473,13 +480,13 @@ var PositioningTarget = /*#__PURE__*/function (_React$Component) {
|
|
|
473
480
|
}, {
|
|
474
481
|
key: "render",
|
|
475
482
|
value: function render() {
|
|
476
|
-
return
|
|
483
|
+
return React__default.createElement("div", {
|
|
477
484
|
ref: this.targetRef
|
|
478
485
|
}, this.props.children(this.state.target));
|
|
479
486
|
}
|
|
480
487
|
}]);
|
|
481
488
|
return PositioningTarget;
|
|
482
|
-
}(
|
|
489
|
+
}(React__default.Component);
|
|
483
490
|
|
|
484
491
|
var BodyDomNode = /*#__PURE__*/function (_React$Component) {
|
|
485
492
|
_inherits(BodyDomNode, _React$Component);
|
|
@@ -544,7 +551,7 @@ var BodyDomNode = /*#__PURE__*/function (_React$Component) {
|
|
|
544
551
|
}
|
|
545
552
|
}]);
|
|
546
553
|
return BodyDomNode;
|
|
547
|
-
}(
|
|
554
|
+
}(React__default.Component);
|
|
548
555
|
BodyDomNode.defaultProps = {
|
|
549
556
|
containerElement: document.body
|
|
550
557
|
};
|
|
@@ -566,7 +573,7 @@ var StatelessPopover = /*#__PURE__*/function (_React$Component) {
|
|
|
566
573
|
var props = _ref.props,
|
|
567
574
|
container = _ref.container,
|
|
568
575
|
positioningTarget = _ref.positioningTarget;
|
|
569
|
-
var popoverContent =
|
|
576
|
+
var popoverContent = React__default.createElement(PopoverContainer, {
|
|
570
577
|
key: "popover-portal",
|
|
571
578
|
getPopoverPosition: this.props.getPopoverPosition,
|
|
572
579
|
relativeToParent: props.inline,
|
|
@@ -576,7 +583,8 @@ var StatelessPopover = /*#__PURE__*/function (_React$Component) {
|
|
|
576
583
|
showTip: props.showTip,
|
|
577
584
|
zIndex: props.zIndex,
|
|
578
585
|
trackScroll: props.trackScroll,
|
|
579
|
-
role: this.props.role
|
|
586
|
+
role: this.props.role,
|
|
587
|
+
onEscapeAction: this.props.onEscapeAction
|
|
580
588
|
}, props.body);
|
|
581
589
|
if (!props.inline) {
|
|
582
590
|
return ReactDOM.createPortal(popoverContent, container);
|
|
@@ -593,7 +601,7 @@ var StatelessPopover = /*#__PURE__*/function (_React$Component) {
|
|
|
593
601
|
return this.props.inline ? this.renderPortalContent({
|
|
594
602
|
props: this.props,
|
|
595
603
|
positioningTarget: positioningTarget
|
|
596
|
-
}) :
|
|
604
|
+
}) : React__default.createElement(BodyDomNode, {
|
|
597
605
|
onOuterAction: this.props.onOuterAction,
|
|
598
606
|
outerActionEvents: this.props.outerActionEvents,
|
|
599
607
|
positioningTarget: positioningTarget,
|
|
@@ -610,13 +618,13 @@ var StatelessPopover = /*#__PURE__*/function (_React$Component) {
|
|
|
610
618
|
key: "render",
|
|
611
619
|
value: function render() {
|
|
612
620
|
var _this3 = this;
|
|
613
|
-
return
|
|
614
|
-
return positioningTarget ?
|
|
621
|
+
return React__default.createElement(PositioningTarget, null, function (positioningTarget) {
|
|
622
|
+
return positioningTarget ? React__default.createElement(React__default.Fragment, null, _this3.props.children, _this3.renderPortal(positioningTarget)) : null;
|
|
615
623
|
});
|
|
616
624
|
}
|
|
617
625
|
}]);
|
|
618
626
|
return StatelessPopover;
|
|
619
|
-
}(
|
|
627
|
+
}(React__default.Component);
|
|
620
628
|
|
|
621
629
|
var Popover = /*#__PURE__*/function (_React$Component) {
|
|
622
630
|
_inherits(Popover, _React$Component);
|
|
@@ -640,25 +648,38 @@ var Popover = /*#__PURE__*/function (_React$Component) {
|
|
|
640
648
|
_this.props.onOuterAction(event);
|
|
641
649
|
}
|
|
642
650
|
};
|
|
651
|
+
_this.childrenRef = React.createRef();
|
|
643
652
|
return _this;
|
|
644
653
|
}
|
|
645
654
|
_createClass(Popover, [{
|
|
646
655
|
key: "render",
|
|
647
656
|
value: function render() {
|
|
657
|
+
var _this2 = this;
|
|
648
658
|
var isOpen = typeof this.props.isOpen === 'undefined' ? this.state.isOpen : this.props.isOpen;
|
|
649
659
|
var children = typeof this.props.children === 'function' ? this.props.children({
|
|
650
660
|
isOpen: isOpen,
|
|
651
|
-
setOpened: this.setOpened
|
|
661
|
+
setOpened: this.setOpened,
|
|
662
|
+
ref: this.childrenRef
|
|
652
663
|
}) : this.props.children;
|
|
653
|
-
|
|
664
|
+
var childrenWithRef = React__default.Children.map(children, function (child) {
|
|
665
|
+
return React__default.cloneElement(child, {
|
|
666
|
+
ref: _this2.childrenRef
|
|
667
|
+
});
|
|
668
|
+
});
|
|
669
|
+
return React__default.createElement(StatelessPopover, Object.assign({}, this.props, {
|
|
654
670
|
onOuterAction: this.onOuterAction,
|
|
671
|
+
onEscapeAction: function onEscapeAction() {
|
|
672
|
+
var _a;
|
|
673
|
+
_this2.setOpened(false);
|
|
674
|
+
(_a = _this2.childrenRef.current) === null || _a === void 0 ? void 0 : _a.focus();
|
|
675
|
+
},
|
|
655
676
|
isOpen: isOpen,
|
|
656
677
|
role: this.props.role
|
|
657
|
-
}),
|
|
678
|
+
}), childrenWithRef);
|
|
658
679
|
}
|
|
659
680
|
}]);
|
|
660
681
|
return Popover;
|
|
661
|
-
}(
|
|
682
|
+
}(React__default.Component);
|
|
662
683
|
Popover.Body = PopoverBody;
|
|
663
684
|
Popover.Position = PopoverPosition;
|
|
664
685
|
Popover.defaultProps = {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@targetprocess/popover",
|
|
3
|
-
"version": "12.19.2-alpha.
|
|
3
|
+
"version": "12.19.2-alpha.5",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/popover.js",
|
|
6
6
|
"module": "dist/popover.es.js",
|
|
@@ -21,5 +21,5 @@
|
|
|
21
21
|
"publishConfig": {
|
|
22
22
|
"access": "public"
|
|
23
23
|
},
|
|
24
|
-
"gitHead": "
|
|
24
|
+
"gitHead": "9728be04f184b73370b50f68df8b5b18d7ecddab"
|
|
25
25
|
}
|