@targetprocess/popover 12.23.4-alpha.0 → 12.24.0
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 +14 -4
- package/PopoverContainer.tsx +16 -4
- package/__tests__/Popover.tests.tsx +21 -0
- package/dist/Popover.d.ts +1 -1
- package/dist/popover.es.js +94 -62
- package/dist/popover.js +116 -85
- package/package.json +3 -3
package/Popover.tsx
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/*********************************************************************
|
|
2
2
|
* © Copyright IBM Corp. 2024
|
|
3
3
|
*********************************************************************/
|
|
4
|
-
import React
|
|
4
|
+
import React from 'react'
|
|
5
5
|
import PropTypes from 'prop-types'
|
|
6
6
|
import {PopoverPosition} from './PopoverPosition'
|
|
7
7
|
import {PopoverBody} from './PopoverBody'
|
|
@@ -161,10 +161,10 @@ export class Popover extends React.Component<PopoverProps, PopoverState> {
|
|
|
161
161
|
if (this.props.onOuterAction) {
|
|
162
162
|
this.props.onOuterAction(event)
|
|
163
163
|
}
|
|
164
|
-
this.childrenRef
|
|
164
|
+
this.childrenRef?.focus()
|
|
165
165
|
}
|
|
166
166
|
|
|
167
|
-
childrenRef
|
|
167
|
+
childrenRef?: HTMLElement
|
|
168
168
|
|
|
169
169
|
render() {
|
|
170
170
|
const isOpen = typeof this.props.isOpen === 'undefined' ? this.state.isOpen : this.props.isOpen
|
|
@@ -173,8 +173,18 @@ export class Popover extends React.Component<PopoverProps, PopoverState> {
|
|
|
173
173
|
? this.props.children({isOpen, setOpened: this.setOpened, ref: this.childrenRef})
|
|
174
174
|
: this.props.children
|
|
175
175
|
const childrenWithRef = React.Children.map(children, child =>
|
|
176
|
-
React.cloneElement(child, {
|
|
176
|
+
React.cloneElement(child, {
|
|
177
|
+
ref: (current?: HTMLElement) => {
|
|
178
|
+
this.childrenRef = current
|
|
179
|
+
if (typeof child.ref === 'function') {
|
|
180
|
+
child.ref(current)
|
|
181
|
+
} else if (child.ref && child.ref.hasOwnProperty('current')) {
|
|
182
|
+
child.ref.current = current
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
})
|
|
177
186
|
)
|
|
187
|
+
this.childrenRef = null
|
|
178
188
|
|
|
179
189
|
return (
|
|
180
190
|
<StatelessPopover
|
package/PopoverContainer.tsx
CHANGED
|
@@ -131,10 +131,22 @@ export class PopoverContainer extends React.Component<
|
|
|
131
131
|
|
|
132
132
|
this.setState({
|
|
133
133
|
hostRect: {
|
|
134
|
-
top:
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
134
|
+
top:
|
|
135
|
+
this.props.relativeToParent || isNaN(positioningBoundingRect.top)
|
|
136
|
+
? 0
|
|
137
|
+
: positioningBoundingRect.top,
|
|
138
|
+
left:
|
|
139
|
+
this.props.relativeToParent || isNaN(positioningBoundingRect.left)
|
|
140
|
+
? 0
|
|
141
|
+
: positioningBoundingRect.left,
|
|
142
|
+
right:
|
|
143
|
+
this.props.relativeToParent || isNaN(positioningBoundingRect.right)
|
|
144
|
+
? 0
|
|
145
|
+
: positioningBoundingRect.right,
|
|
146
|
+
bottom:
|
|
147
|
+
this.props.relativeToParent || isNaN(positioningBoundingRect.bottom)
|
|
148
|
+
? 0
|
|
149
|
+
: positioningBoundingRect.bottom,
|
|
138
150
|
width: positioningBoundingRect.width,
|
|
139
151
|
height: positioningBoundingRect.height
|
|
140
152
|
},
|
|
@@ -13,6 +13,12 @@ jest.mock('focus-trap-react', () => ({
|
|
|
13
13
|
default: ({children}) => <div>{children}</div>
|
|
14
14
|
}))
|
|
15
15
|
|
|
16
|
+
const ComponentWithRef = React.forwardRef<HTMLElement>((prop, ref) => (
|
|
17
|
+
<div>
|
|
18
|
+
<span ref={ref}>Ref</span>
|
|
19
|
+
</div>
|
|
20
|
+
))
|
|
21
|
+
|
|
16
22
|
describe('Popover', () => {
|
|
17
23
|
beforeEach(() => {
|
|
18
24
|
cleanDocumentBody()
|
|
@@ -58,4 +64,19 @@ describe('Popover', () => {
|
|
|
58
64
|
expect(onOuterAction.mock.calls.length).toBe(1)
|
|
59
65
|
expect(onOuterAction.mock.calls[0][0].target).toBeDefined()
|
|
60
66
|
})
|
|
67
|
+
|
|
68
|
+
it('should keep ref in children', () => {
|
|
69
|
+
const ref1 = jest.fn()
|
|
70
|
+
const ref2 = jest.fn()
|
|
71
|
+
|
|
72
|
+
mount(
|
|
73
|
+
<Popover getPopoverPosition="bottomLeft">
|
|
74
|
+
<ComponentWithRef ref={ref1} />
|
|
75
|
+
<ComponentWithRef ref={ref2} />
|
|
76
|
+
</Popover>
|
|
77
|
+
)
|
|
78
|
+
|
|
79
|
+
expect(ref1).toBeCalled()
|
|
80
|
+
expect(ref2).toBeCalled()
|
|
81
|
+
})
|
|
61
82
|
})
|
package/dist/Popover.d.ts
CHANGED
|
@@ -133,6 +133,6 @@ export declare class Popover extends React.Component<PopoverProps, PopoverState>
|
|
|
133
133
|
setOpened: (isOpen: boolean) => void;
|
|
134
134
|
onOuterAction: (event: Event) => void;
|
|
135
135
|
onEscapeAction: (event: Event) => void;
|
|
136
|
-
childrenRef
|
|
136
|
+
childrenRef?: HTMLElement;
|
|
137
137
|
render(): JSX.Element;
|
|
138
138
|
}
|
package/dist/popover.es.js
CHANGED
|
@@ -1,76 +1,101 @@
|
|
|
1
|
-
import React
|
|
1
|
+
import React from 'react';
|
|
2
2
|
import { SpaceXS } from '@targetprocess/global-constants';
|
|
3
3
|
import classNames from 'classnames';
|
|
4
4
|
import ReactDOM from 'react-dom';
|
|
5
5
|
import FocusTrap from 'focus-trap-react';
|
|
6
6
|
|
|
7
|
-
function
|
|
8
|
-
if (
|
|
9
|
-
|
|
10
|
-
}
|
|
11
|
-
function _classCallCheck(a, n) {
|
|
12
|
-
if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function");
|
|
7
|
+
function _classCallCheck(instance, Constructor) {
|
|
8
|
+
if (!(instance instanceof Constructor)) {
|
|
9
|
+
throw new TypeError("Cannot call a class as a function");
|
|
10
|
+
}
|
|
13
11
|
}
|
|
14
|
-
function _defineProperties(
|
|
15
|
-
for (var
|
|
16
|
-
var
|
|
17
|
-
|
|
12
|
+
function _defineProperties(target, props) {
|
|
13
|
+
for (var i = 0; i < props.length; i++) {
|
|
14
|
+
var descriptor = props[i];
|
|
15
|
+
descriptor.enumerable = descriptor.enumerable || false;
|
|
16
|
+
descriptor.configurable = true;
|
|
17
|
+
if ("value" in descriptor) descriptor.writable = true;
|
|
18
|
+
Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor);
|
|
18
19
|
}
|
|
19
20
|
}
|
|
20
|
-
function _createClass(
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
21
|
+
function _createClass(Constructor, protoProps, staticProps) {
|
|
22
|
+
if (protoProps) _defineProperties(Constructor.prototype, protoProps);
|
|
23
|
+
if (staticProps) _defineProperties(Constructor, staticProps);
|
|
24
|
+
Object.defineProperty(Constructor, "prototype", {
|
|
25
|
+
writable: false
|
|
26
|
+
});
|
|
27
|
+
return Constructor;
|
|
24
28
|
}
|
|
25
29
|
function _extends() {
|
|
26
|
-
|
|
27
|
-
for (var
|
|
28
|
-
var
|
|
29
|
-
for (var
|
|
30
|
+
_extends = Object.assign ? Object.assign.bind() : function (target) {
|
|
31
|
+
for (var i = 1; i < arguments.length; i++) {
|
|
32
|
+
var source = arguments[i];
|
|
33
|
+
for (var key in source) {
|
|
34
|
+
if (Object.prototype.hasOwnProperty.call(source, key)) {
|
|
35
|
+
target[key] = source[key];
|
|
36
|
+
}
|
|
37
|
+
}
|
|
30
38
|
}
|
|
31
|
-
return
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
function _getPrototypeOf(t) {
|
|
35
|
-
return _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function (t) {
|
|
36
|
-
return t.__proto__ || Object.getPrototypeOf(t);
|
|
37
|
-
}, _getPrototypeOf(t);
|
|
39
|
+
return target;
|
|
40
|
+
};
|
|
41
|
+
return _extends.apply(this, arguments);
|
|
38
42
|
}
|
|
39
|
-
function _inherits(
|
|
40
|
-
if (
|
|
41
|
-
|
|
43
|
+
function _inherits(subClass, superClass) {
|
|
44
|
+
if (typeof superClass !== "function" && superClass !== null) {
|
|
45
|
+
throw new TypeError("Super expression must either be null or a function");
|
|
46
|
+
}
|
|
47
|
+
subClass.prototype = Object.create(superClass && superClass.prototype, {
|
|
42
48
|
constructor: {
|
|
43
|
-
value:
|
|
44
|
-
writable:
|
|
45
|
-
configurable:
|
|
49
|
+
value: subClass,
|
|
50
|
+
writable: true,
|
|
51
|
+
configurable: true
|
|
46
52
|
}
|
|
47
|
-
})
|
|
48
|
-
|
|
49
|
-
|
|
53
|
+
});
|
|
54
|
+
Object.defineProperty(subClass, "prototype", {
|
|
55
|
+
writable: false
|
|
56
|
+
});
|
|
57
|
+
if (superClass) _setPrototypeOf(subClass, superClass);
|
|
50
58
|
}
|
|
51
|
-
function
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
59
|
+
function _getPrototypeOf(o) {
|
|
60
|
+
_getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) {
|
|
61
|
+
return o.__proto__ || Object.getPrototypeOf(o);
|
|
62
|
+
};
|
|
63
|
+
return _getPrototypeOf(o);
|
|
64
|
+
}
|
|
65
|
+
function _setPrototypeOf(o, p) {
|
|
66
|
+
_setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) {
|
|
67
|
+
o.__proto__ = p;
|
|
68
|
+
return o;
|
|
69
|
+
};
|
|
70
|
+
return _setPrototypeOf(o, p);
|
|
55
71
|
}
|
|
56
|
-
function
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
}
|
|
72
|
+
function _assertThisInitialized(self) {
|
|
73
|
+
if (self === void 0) {
|
|
74
|
+
throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
|
|
75
|
+
}
|
|
76
|
+
return self;
|
|
77
|
+
}
|
|
78
|
+
function _possibleConstructorReturn(self, call) {
|
|
79
|
+
if (call && (typeof call === "object" || typeof call === "function")) {
|
|
80
|
+
return call;
|
|
81
|
+
} else if (call !== void 0) {
|
|
82
|
+
throw new TypeError("Derived constructors may only return object or undefined");
|
|
83
|
+
}
|
|
84
|
+
return _assertThisInitialized(self);
|
|
60
85
|
}
|
|
61
|
-
function _toPrimitive(
|
|
62
|
-
if ("object"
|
|
63
|
-
var
|
|
64
|
-
if (
|
|
65
|
-
var
|
|
66
|
-
if ("object"
|
|
86
|
+
function _toPrimitive(input, hint) {
|
|
87
|
+
if (typeof input !== "object" || input === null) return input;
|
|
88
|
+
var prim = input[Symbol.toPrimitive];
|
|
89
|
+
if (prim !== undefined) {
|
|
90
|
+
var res = prim.call(input, hint || "default");
|
|
91
|
+
if (typeof res !== "object") return res;
|
|
67
92
|
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
68
93
|
}
|
|
69
|
-
return ("string"
|
|
94
|
+
return (hint === "string" ? String : Number)(input);
|
|
70
95
|
}
|
|
71
|
-
function _toPropertyKey(
|
|
72
|
-
var
|
|
73
|
-
return "symbol"
|
|
96
|
+
function _toPropertyKey(arg) {
|
|
97
|
+
var key = _toPrimitive(arg, "string");
|
|
98
|
+
return typeof key === "symbol" ? key : String(key);
|
|
74
99
|
}
|
|
75
100
|
|
|
76
101
|
/*********************************************************************
|
|
@@ -184,8 +209,8 @@ function styleInject(css, ref) {
|
|
|
184
209
|
}
|
|
185
210
|
}
|
|
186
211
|
|
|
187
|
-
var css = "/*********************************************************************\n* © Copyright IBM Corp. 2024\n*********************************************************************/\n.popover-body-container__popover__12-
|
|
188
|
-
var styles = {"popover-body-container":"popover-body-container__popover__12-
|
|
212
|
+
var css = "/*********************************************************************\n* © Copyright IBM Corp. 2024\n*********************************************************************/\n.popover-body-container__popover__12-24-0 {\n -webkit-box-shadow: var(--BoxShadowL, 0 4px 16px 0 rgba(0, 0, 0, 0.12));\n box-shadow: var(--BoxShadowL, 0 4px 16px 0 rgba(0, 0, 0, 0.12));\n border-radius: var(--BorderRadiusL, 4px);\n border: 1px solid var(--HighlightBlockBorderColor, rgba(64, 66, 73, 0.1));\n background: var(--BackgroundDefault, #FFFFFF);\n z-index: var(--ZIndexModal, 10001);\n -webkit-box-sizing: border-box;\n box-sizing: border-box;\n}\n.popover-body__popover__12-24-0 {\n -webkit-box-sizing: border-box;\n box-sizing: border-box;\n padding: var(--SpaceSM, 12px);\n font-size: var(--FontSizeDefault, 13px);\n color: var(--FontColorDefault, #000000);\n}\n.popover-body--no-padding__popover__12-24-0 {\n padding: 0;\n }\n.popover-tip__popover__12-24-0 {\n position: absolute;\n pointer-events: none;\n z-index: calc(var(--ZIndexModal, 10001) + 1);\n overflow: hidden;\n display: -webkit-box;\n display: -ms-flexbox;\n display: flex;\n -webkit-box-align: center;\n -ms-flex-align: center;\n align-items: center;\n -webkit-box-pack: center;\n -ms-flex-pack: center;\n justify-content: center;\n}\n.popover-tip__popover__12-24-0:before {\n content: '';\n position: absolute;\n display: block;\n -webkit-box-sizing: border-box;\n box-sizing: border-box;\n background-color: var(--BackgroundDefault, #FFFFFF);\n border: 1px solid var(--HighlightBlockBorderColor, rgba(64, 66, 73, 0.1));\n /*\n geometry FTW\n\n 2*$popoverTipSize\n _______ _______\n | /|\\ |\n | / | \\ | $popoverTipSize\n | / | \\ |\n |/______|______\\|\n since tip is rotated 45 degrees, its width and height is a\n diagonal of a square with side=$popoverTipSize, thus diagonal\n is sqrt(2) * $popoverTipSize.\n sqrt(2) ~= 1.414, 1.4 used here to prevent too much rounding\n */\n width: 11.2px;\n height: 11.2px;\n -webkit-transform: rotate(45deg);\n transform: rotate(45deg);\n }\n.popover-tip--bottom__popover__12-24-0,\n .popover-tip--top__popover__12-24-0 {\n width: 100%;\n border-top: 1px var(--BackgroundDefault, #FFFFFF);\n border-bottom: 1px var(--BackgroundDefault, #FFFFFF);\n height: 9px;\n }\n.popover-tip--left__popover__12-24-0,\n .popover-tip--right__popover__12-24-0 {\n border-left: 1px var(--BackgroundDefault, #FFFFFF);\n border-right: 1px var(--BackgroundDefault, #FFFFFF);\n height: 100%;\n width: 9px;\n }\n/*\n To determine tip position, we need to rotate it\n along the \"tip\" point, after that, the \"tip\" point\n can be placed with exactly 50% offset from the origin\n so that it is centered.\n */\n.popover-tip--bottom__popover__12-24-0:before {\n -webkit-transform-origin: left top;\n transform-origin: left top;\n left: 50%;\n top: 0;\n }\n.popover-tip--top__popover__12-24-0:before {\n -webkit-transform-origin: right bottom;\n transform-origin: right bottom;\n right: 50%;\n bottom: 0;\n }\n.popover-tip--left__popover__12-24-0:before {\n -webkit-transform-origin: right top;\n transform-origin: right top;\n right: 0;\n top: 50%;\n }\n.popover-tip--right__popover__12-24-0:before {\n -webkit-transform-origin: left bottom;\n transform-origin: left bottom;\n left: 0;\n bottom: 50%;\n }\n";
|
|
213
|
+
var styles = {"popover-body-container":"popover-body-container__popover__12-24-0","popover-body":"popover-body__popover__12-24-0","popover-body--no-padding":"popover-body--no-padding__popover__12-24-0","popover-tip":"popover-tip__popover__12-24-0","popover-tip--bottom":"popover-tip--bottom__popover__12-24-0","popover-tip--top":"popover-tip--top__popover__12-24-0","popover-tip--left":"popover-tip--left__popover__12-24-0","popover-tip--right":"popover-tip--right__popover__12-24-0"};
|
|
189
214
|
styleInject(css);
|
|
190
215
|
|
|
191
216
|
/*********************************************************************
|
|
@@ -376,10 +401,10 @@ var PopoverContainer = /*#__PURE__*/function (_React$Component) {
|
|
|
376
401
|
var positioningBoundingRect = getCompositeRect(this.props.positioningTarget, this.props.containerElement);
|
|
377
402
|
this.setState({
|
|
378
403
|
hostRect: {
|
|
379
|
-
top: this.props.relativeToParent ? 0 : positioningBoundingRect.top,
|
|
380
|
-
left: this.props.relativeToParent ? 0 : positioningBoundingRect.left,
|
|
381
|
-
right: this.props.relativeToParent ? 0 : positioningBoundingRect.right,
|
|
382
|
-
bottom: this.props.relativeToParent ? 0 : positioningBoundingRect.bottom,
|
|
404
|
+
top: this.props.relativeToParent || isNaN(positioningBoundingRect.top) ? 0 : positioningBoundingRect.top,
|
|
405
|
+
left: this.props.relativeToParent || isNaN(positioningBoundingRect.left) ? 0 : positioningBoundingRect.left,
|
|
406
|
+
right: this.props.relativeToParent || isNaN(positioningBoundingRect.right) ? 0 : positioningBoundingRect.right,
|
|
407
|
+
bottom: this.props.relativeToParent || isNaN(positioningBoundingRect.bottom) ? 0 : positioningBoundingRect.bottom,
|
|
383
408
|
width: positioningBoundingRect.width,
|
|
384
409
|
height: positioningBoundingRect.height
|
|
385
410
|
},
|
|
@@ -701,9 +726,8 @@ var Popover = /*#__PURE__*/function (_React$Component) {
|
|
|
701
726
|
if (_this.props.onOuterAction) {
|
|
702
727
|
_this.props.onOuterAction(event);
|
|
703
728
|
}
|
|
704
|
-
(_a = _this.childrenRef
|
|
729
|
+
(_a = _this.childrenRef) === null || _a === void 0 ? void 0 : _a.focus();
|
|
705
730
|
};
|
|
706
|
-
_this.childrenRef = createRef();
|
|
707
731
|
return _this;
|
|
708
732
|
}
|
|
709
733
|
_createClass(Popover, [{
|
|
@@ -718,9 +742,17 @@ var Popover = /*#__PURE__*/function (_React$Component) {
|
|
|
718
742
|
}) : this.props.children;
|
|
719
743
|
var childrenWithRef = React.Children.map(children, function (child) {
|
|
720
744
|
return React.cloneElement(child, {
|
|
721
|
-
ref:
|
|
745
|
+
ref: function ref(current) {
|
|
746
|
+
_this2.childrenRef = current;
|
|
747
|
+
if (typeof child.ref === 'function') {
|
|
748
|
+
child.ref(current);
|
|
749
|
+
} else if (child.ref && child.ref.hasOwnProperty('current')) {
|
|
750
|
+
child.ref.current = current;
|
|
751
|
+
}
|
|
752
|
+
}
|
|
722
753
|
});
|
|
723
754
|
});
|
|
755
|
+
this.childrenRef = null;
|
|
724
756
|
return React.createElement(StatelessPopover, Object.assign({}, this.props, {
|
|
725
757
|
onOuterAction: this.onOuterAction,
|
|
726
758
|
onEscapeAction: this.onEscapeAction,
|
package/dist/popover.js
CHANGED
|
@@ -4,80 +4,104 @@ 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 = require('react');
|
|
8
|
-
var React__default = _interopDefault(React);
|
|
7
|
+
var React = _interopDefault(require('react'));
|
|
9
8
|
var globalConstants = require('@targetprocess/global-constants');
|
|
10
9
|
var classNames = _interopDefault(require('classnames'));
|
|
11
10
|
var ReactDOM = _interopDefault(require('react-dom'));
|
|
12
11
|
var FocusTrap = _interopDefault(require('focus-trap-react'));
|
|
13
12
|
|
|
14
|
-
function
|
|
15
|
-
if (
|
|
16
|
-
|
|
17
|
-
}
|
|
18
|
-
function _classCallCheck(a, n) {
|
|
19
|
-
if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function");
|
|
13
|
+
function _classCallCheck(instance, Constructor) {
|
|
14
|
+
if (!(instance instanceof Constructor)) {
|
|
15
|
+
throw new TypeError("Cannot call a class as a function");
|
|
16
|
+
}
|
|
20
17
|
}
|
|
21
|
-
function _defineProperties(
|
|
22
|
-
for (var
|
|
23
|
-
var
|
|
24
|
-
|
|
18
|
+
function _defineProperties(target, props) {
|
|
19
|
+
for (var i = 0; i < props.length; i++) {
|
|
20
|
+
var descriptor = props[i];
|
|
21
|
+
descriptor.enumerable = descriptor.enumerable || false;
|
|
22
|
+
descriptor.configurable = true;
|
|
23
|
+
if ("value" in descriptor) descriptor.writable = true;
|
|
24
|
+
Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor);
|
|
25
25
|
}
|
|
26
26
|
}
|
|
27
|
-
function _createClass(
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
27
|
+
function _createClass(Constructor, protoProps, staticProps) {
|
|
28
|
+
if (protoProps) _defineProperties(Constructor.prototype, protoProps);
|
|
29
|
+
if (staticProps) _defineProperties(Constructor, staticProps);
|
|
30
|
+
Object.defineProperty(Constructor, "prototype", {
|
|
31
|
+
writable: false
|
|
32
|
+
});
|
|
33
|
+
return Constructor;
|
|
31
34
|
}
|
|
32
35
|
function _extends() {
|
|
33
|
-
|
|
34
|
-
for (var
|
|
35
|
-
var
|
|
36
|
-
for (var
|
|
36
|
+
_extends = Object.assign ? Object.assign.bind() : function (target) {
|
|
37
|
+
for (var i = 1; i < arguments.length; i++) {
|
|
38
|
+
var source = arguments[i];
|
|
39
|
+
for (var key in source) {
|
|
40
|
+
if (Object.prototype.hasOwnProperty.call(source, key)) {
|
|
41
|
+
target[key] = source[key];
|
|
42
|
+
}
|
|
43
|
+
}
|
|
37
44
|
}
|
|
38
|
-
return
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
function _getPrototypeOf(t) {
|
|
42
|
-
return _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function (t) {
|
|
43
|
-
return t.__proto__ || Object.getPrototypeOf(t);
|
|
44
|
-
}, _getPrototypeOf(t);
|
|
45
|
+
return target;
|
|
46
|
+
};
|
|
47
|
+
return _extends.apply(this, arguments);
|
|
45
48
|
}
|
|
46
|
-
function _inherits(
|
|
47
|
-
if (
|
|
48
|
-
|
|
49
|
+
function _inherits(subClass, superClass) {
|
|
50
|
+
if (typeof superClass !== "function" && superClass !== null) {
|
|
51
|
+
throw new TypeError("Super expression must either be null or a function");
|
|
52
|
+
}
|
|
53
|
+
subClass.prototype = Object.create(superClass && superClass.prototype, {
|
|
49
54
|
constructor: {
|
|
50
|
-
value:
|
|
51
|
-
writable:
|
|
52
|
-
configurable:
|
|
55
|
+
value: subClass,
|
|
56
|
+
writable: true,
|
|
57
|
+
configurable: true
|
|
53
58
|
}
|
|
54
|
-
})
|
|
55
|
-
|
|
56
|
-
|
|
59
|
+
});
|
|
60
|
+
Object.defineProperty(subClass, "prototype", {
|
|
61
|
+
writable: false
|
|
62
|
+
});
|
|
63
|
+
if (superClass) _setPrototypeOf(subClass, superClass);
|
|
57
64
|
}
|
|
58
|
-
function
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
65
|
+
function _getPrototypeOf(o) {
|
|
66
|
+
_getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) {
|
|
67
|
+
return o.__proto__ || Object.getPrototypeOf(o);
|
|
68
|
+
};
|
|
69
|
+
return _getPrototypeOf(o);
|
|
70
|
+
}
|
|
71
|
+
function _setPrototypeOf(o, p) {
|
|
72
|
+
_setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) {
|
|
73
|
+
o.__proto__ = p;
|
|
74
|
+
return o;
|
|
75
|
+
};
|
|
76
|
+
return _setPrototypeOf(o, p);
|
|
62
77
|
}
|
|
63
|
-
function
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
}
|
|
78
|
+
function _assertThisInitialized(self) {
|
|
79
|
+
if (self === void 0) {
|
|
80
|
+
throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
|
|
81
|
+
}
|
|
82
|
+
return self;
|
|
83
|
+
}
|
|
84
|
+
function _possibleConstructorReturn(self, call) {
|
|
85
|
+
if (call && (typeof call === "object" || typeof call === "function")) {
|
|
86
|
+
return call;
|
|
87
|
+
} else if (call !== void 0) {
|
|
88
|
+
throw new TypeError("Derived constructors may only return object or undefined");
|
|
89
|
+
}
|
|
90
|
+
return _assertThisInitialized(self);
|
|
67
91
|
}
|
|
68
|
-
function _toPrimitive(
|
|
69
|
-
if ("object"
|
|
70
|
-
var
|
|
71
|
-
if (
|
|
72
|
-
var
|
|
73
|
-
if ("object"
|
|
92
|
+
function _toPrimitive(input, hint) {
|
|
93
|
+
if (typeof input !== "object" || input === null) return input;
|
|
94
|
+
var prim = input[Symbol.toPrimitive];
|
|
95
|
+
if (prim !== undefined) {
|
|
96
|
+
var res = prim.call(input, hint || "default");
|
|
97
|
+
if (typeof res !== "object") return res;
|
|
74
98
|
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
75
99
|
}
|
|
76
|
-
return ("string"
|
|
100
|
+
return (hint === "string" ? String : Number)(input);
|
|
77
101
|
}
|
|
78
|
-
function _toPropertyKey(
|
|
79
|
-
var
|
|
80
|
-
return "symbol"
|
|
102
|
+
function _toPropertyKey(arg) {
|
|
103
|
+
var key = _toPrimitive(arg, "string");
|
|
104
|
+
return typeof key === "symbol" ? key : String(key);
|
|
81
105
|
}
|
|
82
106
|
|
|
83
107
|
/*********************************************************************
|
|
@@ -191,8 +215,8 @@ function styleInject(css, ref) {
|
|
|
191
215
|
}
|
|
192
216
|
}
|
|
193
217
|
|
|
194
|
-
var css = "/*********************************************************************\n* © Copyright IBM Corp. 2024\n*********************************************************************/\n.popover-body-container__popover__12-
|
|
195
|
-
var styles = {"popover-body-container":"popover-body-container__popover__12-
|
|
218
|
+
var css = "/*********************************************************************\n* © Copyright IBM Corp. 2024\n*********************************************************************/\n.popover-body-container__popover__12-24-0 {\n -webkit-box-shadow: var(--BoxShadowL, 0 4px 16px 0 rgba(0, 0, 0, 0.12));\n box-shadow: var(--BoxShadowL, 0 4px 16px 0 rgba(0, 0, 0, 0.12));\n border-radius: var(--BorderRadiusL, 4px);\n border: 1px solid var(--HighlightBlockBorderColor, rgba(64, 66, 73, 0.1));\n background: var(--BackgroundDefault, #FFFFFF);\n z-index: var(--ZIndexModal, 10001);\n -webkit-box-sizing: border-box;\n box-sizing: border-box;\n}\n.popover-body__popover__12-24-0 {\n -webkit-box-sizing: border-box;\n box-sizing: border-box;\n padding: var(--SpaceSM, 12px);\n font-size: var(--FontSizeDefault, 13px);\n color: var(--FontColorDefault, #000000);\n}\n.popover-body--no-padding__popover__12-24-0 {\n padding: 0;\n }\n.popover-tip__popover__12-24-0 {\n position: absolute;\n pointer-events: none;\n z-index: calc(var(--ZIndexModal, 10001) + 1);\n overflow: hidden;\n display: -webkit-box;\n display: -ms-flexbox;\n display: flex;\n -webkit-box-align: center;\n -ms-flex-align: center;\n align-items: center;\n -webkit-box-pack: center;\n -ms-flex-pack: center;\n justify-content: center;\n}\n.popover-tip__popover__12-24-0:before {\n content: '';\n position: absolute;\n display: block;\n -webkit-box-sizing: border-box;\n box-sizing: border-box;\n background-color: var(--BackgroundDefault, #FFFFFF);\n border: 1px solid var(--HighlightBlockBorderColor, rgba(64, 66, 73, 0.1));\n /*\n geometry FTW\n\n 2*$popoverTipSize\n _______ _______\n | /|\\ |\n | / | \\ | $popoverTipSize\n | / | \\ |\n |/______|______\\|\n since tip is rotated 45 degrees, its width and height is a\n diagonal of a square with side=$popoverTipSize, thus diagonal\n is sqrt(2) * $popoverTipSize.\n sqrt(2) ~= 1.414, 1.4 used here to prevent too much rounding\n */\n width: 11.2px;\n height: 11.2px;\n -webkit-transform: rotate(45deg);\n transform: rotate(45deg);\n }\n.popover-tip--bottom__popover__12-24-0,\n .popover-tip--top__popover__12-24-0 {\n width: 100%;\n border-top: 1px var(--BackgroundDefault, #FFFFFF);\n border-bottom: 1px var(--BackgroundDefault, #FFFFFF);\n height: 9px;\n }\n.popover-tip--left__popover__12-24-0,\n .popover-tip--right__popover__12-24-0 {\n border-left: 1px var(--BackgroundDefault, #FFFFFF);\n border-right: 1px var(--BackgroundDefault, #FFFFFF);\n height: 100%;\n width: 9px;\n }\n/*\n To determine tip position, we need to rotate it\n along the \"tip\" point, after that, the \"tip\" point\n can be placed with exactly 50% offset from the origin\n so that it is centered.\n */\n.popover-tip--bottom__popover__12-24-0:before {\n -webkit-transform-origin: left top;\n transform-origin: left top;\n left: 50%;\n top: 0;\n }\n.popover-tip--top__popover__12-24-0:before {\n -webkit-transform-origin: right bottom;\n transform-origin: right bottom;\n right: 50%;\n bottom: 0;\n }\n.popover-tip--left__popover__12-24-0:before {\n -webkit-transform-origin: right top;\n transform-origin: right top;\n right: 0;\n top: 50%;\n }\n.popover-tip--right__popover__12-24-0:before {\n -webkit-transform-origin: left bottom;\n transform-origin: left bottom;\n left: 0;\n bottom: 50%;\n }\n";
|
|
219
|
+
var styles = {"popover-body-container":"popover-body-container__popover__12-24-0","popover-body":"popover-body__popover__12-24-0","popover-body--no-padding":"popover-body--no-padding__popover__12-24-0","popover-tip":"popover-tip__popover__12-24-0","popover-tip--bottom":"popover-tip--bottom__popover__12-24-0","popover-tip--top":"popover-tip--top__popover__12-24-0","popover-tip--left":"popover-tip--left__popover__12-24-0","popover-tip--right":"popover-tip--right__popover__12-24-0"};
|
|
196
220
|
styleInject(css);
|
|
197
221
|
|
|
198
222
|
/*********************************************************************
|
|
@@ -203,9 +227,9 @@ var PopoverBody = function PopoverBody(_ref) {
|
|
|
203
227
|
className = _ref.className,
|
|
204
228
|
classNameBody = _ref.classNameBody,
|
|
205
229
|
noPadding = _ref.noPadding;
|
|
206
|
-
return
|
|
230
|
+
return React.createElement("div", {
|
|
207
231
|
className: classNames(className, styles['popover-body-container'])
|
|
208
|
-
},
|
|
232
|
+
}, React.createElement("div", {
|
|
209
233
|
className: classNames(classNameBody, styles['popover-body'], noPadding && styles['popover-body--no-padding'])
|
|
210
234
|
}, children));
|
|
211
235
|
};
|
|
@@ -336,7 +360,7 @@ var PopoverContainer = /*#__PURE__*/function (_React$Component) {
|
|
|
336
360
|
_classCallCheck(this, PopoverContainer);
|
|
337
361
|
_this = _possibleConstructorReturn(this, _getPrototypeOf(PopoverContainer).apply(this, arguments));
|
|
338
362
|
_this.mounted = false;
|
|
339
|
-
_this.popoverContentRef =
|
|
363
|
+
_this.popoverContentRef = React.createRef();
|
|
340
364
|
_this.state = {
|
|
341
365
|
adjusted: false,
|
|
342
366
|
positionX: 0,
|
|
@@ -383,10 +407,10 @@ var PopoverContainer = /*#__PURE__*/function (_React$Component) {
|
|
|
383
407
|
var positioningBoundingRect = getCompositeRect(this.props.positioningTarget, this.props.containerElement);
|
|
384
408
|
this.setState({
|
|
385
409
|
hostRect: {
|
|
386
|
-
top: this.props.relativeToParent ? 0 : positioningBoundingRect.top,
|
|
387
|
-
left: this.props.relativeToParent ? 0 : positioningBoundingRect.left,
|
|
388
|
-
right: this.props.relativeToParent ? 0 : positioningBoundingRect.right,
|
|
389
|
-
bottom: this.props.relativeToParent ? 0 : positioningBoundingRect.bottom,
|
|
410
|
+
top: this.props.relativeToParent || isNaN(positioningBoundingRect.top) ? 0 : positioningBoundingRect.top,
|
|
411
|
+
left: this.props.relativeToParent || isNaN(positioningBoundingRect.left) ? 0 : positioningBoundingRect.left,
|
|
412
|
+
right: this.props.relativeToParent || isNaN(positioningBoundingRect.right) ? 0 : positioningBoundingRect.right,
|
|
413
|
+
bottom: this.props.relativeToParent || isNaN(positioningBoundingRect.bottom) ? 0 : positioningBoundingRect.bottom,
|
|
390
414
|
width: positioningBoundingRect.width,
|
|
391
415
|
height: positioningBoundingRect.height
|
|
392
416
|
},
|
|
@@ -458,7 +482,7 @@ var PopoverContainer = /*#__PURE__*/function (_React$Component) {
|
|
|
458
482
|
};
|
|
459
483
|
var tipPosition = this.getPopoverTipPosition(position, containerPosition);
|
|
460
484
|
// FIXME: position.top cast to number, because value may be not a number
|
|
461
|
-
return
|
|
485
|
+
return React.createElement("div", {
|
|
462
486
|
style: _extends({
|
|
463
487
|
position: 'absolute'
|
|
464
488
|
}, containerPosition, {
|
|
@@ -468,7 +492,7 @@ var PopoverContainer = /*#__PURE__*/function (_React$Component) {
|
|
|
468
492
|
transitionProperty: 'opacity',
|
|
469
493
|
opacity: this.state.adjusted ? 1 : 0
|
|
470
494
|
})
|
|
471
|
-
}, this.props.showTip && tipPosition &&
|
|
495
|
+
}, this.props.showTip && tipPosition && React.createElement("div", {
|
|
472
496
|
className: classNames(styles['popover-tip'], styles["popover-tip--".concat(tipPosition)], 'popover-tip', this.props.classNameTip),
|
|
473
497
|
style: {
|
|
474
498
|
top: tipPosition === 'bottom' && position.top - 8,
|
|
@@ -476,13 +500,13 @@ var PopoverContainer = /*#__PURE__*/function (_React$Component) {
|
|
|
476
500
|
left: tipPosition === 'right' && position.left - 8,
|
|
477
501
|
right: tipPosition === 'left' && position.right - 8
|
|
478
502
|
}
|
|
479
|
-
}), this.props.trapFocus &&
|
|
503
|
+
}), this.props.trapFocus && React.createElement(FocusTrap, {
|
|
480
504
|
focusTrapOptions: {
|
|
481
505
|
fallbackFocus: "#".concat(this.popoverContainerId),
|
|
482
506
|
clickOutsideDeactivates: true,
|
|
483
507
|
trapStack: window.__globalTrapStack
|
|
484
508
|
}
|
|
485
|
-
},
|
|
509
|
+
}, React.createElement("div", {
|
|
486
510
|
id: this.popoverContainerId,
|
|
487
511
|
ref: this.popoverContentRef,
|
|
488
512
|
style: _extends({
|
|
@@ -494,7 +518,7 @@ var PopoverContainer = /*#__PURE__*/function (_React$Component) {
|
|
|
494
518
|
role: this.props.role,
|
|
495
519
|
"aria-modal": this.props.trapFocus ? 'true' : 'false',
|
|
496
520
|
onKeyDown: this.handleKeyDown
|
|
497
|
-
}, this.props.children)), !this.props.trapFocus &&
|
|
521
|
+
}, this.props.children)), !this.props.trapFocus && React.createElement("div", {
|
|
498
522
|
id: this.popoverContainerId,
|
|
499
523
|
ref: this.popoverContentRef,
|
|
500
524
|
style: _extends({
|
|
@@ -510,7 +534,7 @@ var PopoverContainer = /*#__PURE__*/function (_React$Component) {
|
|
|
510
534
|
}
|
|
511
535
|
}]);
|
|
512
536
|
return PopoverContainer;
|
|
513
|
-
}(
|
|
537
|
+
}(React.Component);
|
|
514
538
|
PopoverContainer.defaultProps = {
|
|
515
539
|
trackScroll: true
|
|
516
540
|
};
|
|
@@ -524,7 +548,7 @@ var PositioningTarget = /*#__PURE__*/function (_React$Component) {
|
|
|
524
548
|
_this.state = {
|
|
525
549
|
target: null
|
|
526
550
|
};
|
|
527
|
-
_this.targetRef =
|
|
551
|
+
_this.targetRef = React.createRef();
|
|
528
552
|
return _this;
|
|
529
553
|
}
|
|
530
554
|
_createClass(PositioningTarget, [{
|
|
@@ -537,13 +561,13 @@ var PositioningTarget = /*#__PURE__*/function (_React$Component) {
|
|
|
537
561
|
}, {
|
|
538
562
|
key: "render",
|
|
539
563
|
value: function render() {
|
|
540
|
-
return
|
|
564
|
+
return React.createElement("div", {
|
|
541
565
|
ref: this.targetRef
|
|
542
566
|
}, this.props.children(this.state.target));
|
|
543
567
|
}
|
|
544
568
|
}]);
|
|
545
569
|
return PositioningTarget;
|
|
546
|
-
}(
|
|
570
|
+
}(React.Component);
|
|
547
571
|
|
|
548
572
|
var BodyDomNode = /*#__PURE__*/function (_React$Component) {
|
|
549
573
|
_inherits(BodyDomNode, _React$Component);
|
|
@@ -608,7 +632,7 @@ var BodyDomNode = /*#__PURE__*/function (_React$Component) {
|
|
|
608
632
|
}
|
|
609
633
|
}]);
|
|
610
634
|
return BodyDomNode;
|
|
611
|
-
}(
|
|
635
|
+
}(React.Component);
|
|
612
636
|
BodyDomNode.defaultProps = {
|
|
613
637
|
containerElement: document.body
|
|
614
638
|
};
|
|
@@ -630,7 +654,7 @@ var StatelessPopover = /*#__PURE__*/function (_React$Component) {
|
|
|
630
654
|
var props = _ref.props,
|
|
631
655
|
container = _ref.container,
|
|
632
656
|
positioningTarget = _ref.positioningTarget;
|
|
633
|
-
var popoverContent =
|
|
657
|
+
var popoverContent = React.createElement(PopoverContainer, {
|
|
634
658
|
key: "popover-portal",
|
|
635
659
|
getPopoverPosition: this.props.getPopoverPosition,
|
|
636
660
|
relativeToParent: props.inline,
|
|
@@ -655,7 +679,7 @@ var StatelessPopover = /*#__PURE__*/function (_React$Component) {
|
|
|
655
679
|
return null;
|
|
656
680
|
}
|
|
657
681
|
var containerElement = this.props.inline ? positioningTarget : this.getContainer();
|
|
658
|
-
return
|
|
682
|
+
return React.createElement(BodyDomNode, {
|
|
659
683
|
onOuterAction: this.props.onOuterAction,
|
|
660
684
|
outerActionEvents: this.props.outerActionEvents,
|
|
661
685
|
positioningTarget: positioningTarget,
|
|
@@ -672,13 +696,13 @@ var StatelessPopover = /*#__PURE__*/function (_React$Component) {
|
|
|
672
696
|
key: "render",
|
|
673
697
|
value: function render() {
|
|
674
698
|
var _this3 = this;
|
|
675
|
-
return
|
|
676
|
-
return positioningTarget ?
|
|
699
|
+
return React.createElement(PositioningTarget, null, function (positioningTarget) {
|
|
700
|
+
return positioningTarget ? React.createElement(React.Fragment, null, _this3.props.children, _this3.renderPortal(positioningTarget)) : null;
|
|
677
701
|
});
|
|
678
702
|
}
|
|
679
703
|
}]);
|
|
680
704
|
return StatelessPopover;
|
|
681
|
-
}(
|
|
705
|
+
}(React.Component);
|
|
682
706
|
|
|
683
707
|
var Popover = /*#__PURE__*/function (_React$Component) {
|
|
684
708
|
_inherits(Popover, _React$Component);
|
|
@@ -708,9 +732,8 @@ var Popover = /*#__PURE__*/function (_React$Component) {
|
|
|
708
732
|
if (_this.props.onOuterAction) {
|
|
709
733
|
_this.props.onOuterAction(event);
|
|
710
734
|
}
|
|
711
|
-
(_a = _this.childrenRef
|
|
735
|
+
(_a = _this.childrenRef) === null || _a === void 0 ? void 0 : _a.focus();
|
|
712
736
|
};
|
|
713
|
-
_this.childrenRef = React.createRef();
|
|
714
737
|
return _this;
|
|
715
738
|
}
|
|
716
739
|
_createClass(Popover, [{
|
|
@@ -723,12 +746,20 @@ var Popover = /*#__PURE__*/function (_React$Component) {
|
|
|
723
746
|
setOpened: this.setOpened,
|
|
724
747
|
ref: this.childrenRef
|
|
725
748
|
}) : this.props.children;
|
|
726
|
-
var childrenWithRef =
|
|
727
|
-
return
|
|
728
|
-
ref:
|
|
749
|
+
var childrenWithRef = React.Children.map(children, function (child) {
|
|
750
|
+
return React.cloneElement(child, {
|
|
751
|
+
ref: function ref(current) {
|
|
752
|
+
_this2.childrenRef = current;
|
|
753
|
+
if (typeof child.ref === 'function') {
|
|
754
|
+
child.ref(current);
|
|
755
|
+
} else if (child.ref && child.ref.hasOwnProperty('current')) {
|
|
756
|
+
child.ref.current = current;
|
|
757
|
+
}
|
|
758
|
+
}
|
|
729
759
|
});
|
|
730
760
|
});
|
|
731
|
-
|
|
761
|
+
this.childrenRef = null;
|
|
762
|
+
return React.createElement(StatelessPopover, Object.assign({}, this.props, {
|
|
732
763
|
onOuterAction: this.onOuterAction,
|
|
733
764
|
onEscapeAction: this.onEscapeAction,
|
|
734
765
|
isOpen: isOpen,
|
|
@@ -738,7 +769,7 @@ var Popover = /*#__PURE__*/function (_React$Component) {
|
|
|
738
769
|
}
|
|
739
770
|
}]);
|
|
740
771
|
return Popover;
|
|
741
|
-
}(
|
|
772
|
+
}(React.Component);
|
|
742
773
|
Popover.Body = PopoverBody;
|
|
743
774
|
Popover.Position = PopoverPosition;
|
|
744
775
|
Popover.defaultProps = {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@targetprocess/popover",
|
|
3
|
-
"version": "12.
|
|
3
|
+
"version": "12.24.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/popover.js",
|
|
6
6
|
"module": "dist/popover.es.js",
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
"prepack": "node -r ../../.ts-node.js ../../config/rollup.config.js ."
|
|
13
13
|
},
|
|
14
14
|
"dependencies": {
|
|
15
|
-
"@targetprocess/global-constants": "^12.
|
|
15
|
+
"@targetprocess/global-constants": "^12.24.0",
|
|
16
16
|
"classnames": "^2.2.5",
|
|
17
17
|
"focus-trap-react": "^10.3.0",
|
|
18
18
|
"prop-types": "^15.6.0",
|
|
@@ -22,5 +22,5 @@
|
|
|
22
22
|
"publishConfig": {
|
|
23
23
|
"access": "public"
|
|
24
24
|
},
|
|
25
|
-
"gitHead": "
|
|
25
|
+
"gitHead": "c079d436e88f2ce5f20f29ac1681a38ce7d1ef4a"
|
|
26
26
|
}
|