@atlaskit/portal 4.2.12 → 4.3.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/CHANGELOG.md +16 -0
- package/README.md +4 -2
- package/dist/cjs/index.js +0 -3
- package/dist/cjs/internal/components/internal-portal.js +4 -7
- package/dist/cjs/internal/hooks/use-is-subsequent-render.js +3 -9
- package/dist/cjs/internal/hooks/use-portal-event.js +0 -6
- package/dist/cjs/internal/utils/portal-custom-event.js +3 -5
- package/dist/cjs/internal/utils/portal-dom-utils.js +6 -17
- package/dist/cjs/portal.js +2 -8
- package/dist/cjs/version.json +1 -1
- package/dist/es2019/internal/components/internal-portal.js +3 -2
- package/dist/es2019/internal/hooks/use-is-subsequent-render.js +0 -2
- package/dist/es2019/internal/hooks/use-portal-event.js +0 -2
- package/dist/es2019/internal/utils/portal-custom-event.js +3 -5
- package/dist/es2019/internal/utils/portal-dom-utils.js +7 -11
- package/dist/es2019/version.json +1 -1
- package/dist/esm/internal/components/internal-portal.js +4 -3
- package/dist/esm/internal/hooks/use-is-subsequent-render.js +3 -6
- package/dist/esm/internal/hooks/use-portal-event.js +0 -2
- package/dist/esm/internal/utils/portal-custom-event.js +3 -5
- package/dist/esm/internal/utils/portal-dom-utils.js +7 -11
- package/dist/esm/portal.js +2 -2
- package/dist/esm/version.json +1 -1
- package/package.json +22 -23
- package/report.api.md +33 -23
- package/dist/types-ts4.0/constants.d.ts +0 -2
- package/dist/types-ts4.0/entry-points/types.d.ts +0 -1
- package/dist/types-ts4.0/index.d.ts +0 -3
- package/dist/types-ts4.0/internal/components/internal-portal.d.ts +0 -7
- package/dist/types-ts4.0/internal/constants.d.ts +0 -3
- package/dist/types-ts4.0/internal/hooks/use-is-subsequent-render.d.ts +0 -2
- package/dist/types-ts4.0/internal/hooks/use-portal-event.d.ts +0 -2
- package/dist/types-ts4.0/internal/types.d.ts +0 -24
- package/dist/types-ts4.0/internal/utils/portal-custom-event.d.ts +0 -6
- package/dist/types-ts4.0/internal/utils/portal-dom-utils.d.ts +0 -17
- package/dist/types-ts4.0/portal.d.ts +0 -3
- package/dist/types-ts4.0/types.d.ts +0 -13
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,21 @@
|
|
|
1
1
|
# @atlaskit/portal
|
|
2
2
|
|
|
3
|
+
## 4.3.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [`56507598609`](https://bitbucket.org/atlassian/atlassian-frontend/commits/56507598609) - Skip minor dependency bump
|
|
8
|
+
|
|
9
|
+
### Patch Changes
|
|
10
|
+
|
|
11
|
+
- Updated dependencies
|
|
12
|
+
|
|
13
|
+
## 4.2.13
|
|
14
|
+
|
|
15
|
+
### Patch Changes
|
|
16
|
+
|
|
17
|
+
- [`4ba10567310`](https://bitbucket.org/atlassian/atlassian-frontend/commits/4ba10567310) - Internal changes.
|
|
18
|
+
|
|
3
19
|
## 4.2.12
|
|
4
20
|
|
|
5
21
|
### Patch Changes
|
package/README.md
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
# Portal
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
A wrapper for rendering components in React portals.
|
|
4
4
|
|
|
5
5
|
## Installation
|
|
6
6
|
|
|
7
|
+
```sh
|
|
7
8
|
yarn add @atlaskit/portal
|
|
9
|
+
```
|
|
8
10
|
|
|
9
11
|
## Usage
|
|
10
12
|
|
|
11
|
-
|
|
13
|
+
[View documentation](https://atlassian.design/components/portal/).
|
package/dist/cjs/index.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
5
4
|
Object.defineProperty(exports, "__esModule", {
|
|
6
5
|
value: true
|
|
7
6
|
});
|
|
@@ -23,7 +22,5 @@ Object.defineProperty(exports, "default", {
|
|
|
23
22
|
return _portal.default;
|
|
24
23
|
}
|
|
25
24
|
});
|
|
26
|
-
|
|
27
25
|
var _portal = _interopRequireDefault(require("./portal"));
|
|
28
|
-
|
|
29
26
|
var _constants = require("./constants");
|
|
@@ -4,23 +4,20 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = InternalPortal;
|
|
7
|
-
|
|
8
7
|
var _react = require("react");
|
|
9
|
-
|
|
10
8
|
var _reactDom = require("react-dom");
|
|
11
|
-
|
|
12
9
|
var _portalDomUtils = require("../utils/portal-dom-utils");
|
|
13
|
-
|
|
14
10
|
function InternalPortal(props) {
|
|
15
11
|
var zIndex = props.zIndex,
|
|
16
|
-
|
|
12
|
+
children = props.children;
|
|
17
13
|
var container = (0, _react.useMemo)(function () {
|
|
18
14
|
return (0, _portalDomUtils.createContainer)(zIndex);
|
|
19
|
-
}, [zIndex]);
|
|
15
|
+
}, [zIndex]);
|
|
16
|
+
|
|
17
|
+
// This is in the render method instead of useEffect so that
|
|
20
18
|
// the portal will be added to the DOM before the children render.
|
|
21
19
|
// For any further changes, ensure that the container does not have a
|
|
22
20
|
// parent besides the portal parent.
|
|
23
|
-
|
|
24
21
|
(0, _portalDomUtils.appendPortalContainerIfNotAppended)(container);
|
|
25
22
|
(0, _react.useEffect)(function () {
|
|
26
23
|
return function () {
|
|
@@ -1,27 +1,21 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
5
4
|
Object.defineProperty(exports, "__esModule", {
|
|
6
5
|
value: true
|
|
7
6
|
});
|
|
8
7
|
exports.default = void 0;
|
|
9
|
-
|
|
10
8
|
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
11
|
-
|
|
12
9
|
var _react = require("react");
|
|
13
|
-
|
|
14
10
|
var useIsSubsequentRender = function useIsSubsequentRender() {
|
|
15
11
|
var _useState = (0, _react.useState)(false),
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
12
|
+
_useState2 = (0, _slicedToArray2.default)(_useState, 2),
|
|
13
|
+
isSubsequentRender = _useState2[0],
|
|
14
|
+
setIsSubsequentRender = _useState2[1];
|
|
20
15
|
(0, _react.useEffect)(function () {
|
|
21
16
|
setIsSubsequentRender(true);
|
|
22
17
|
}, []);
|
|
23
18
|
return isSubsequentRender;
|
|
24
19
|
};
|
|
25
|
-
|
|
26
20
|
var _default = useIsSubsequentRender;
|
|
27
21
|
exports.default = _default;
|
|
@@ -1,18 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
5
4
|
Object.defineProperty(exports, "__esModule", {
|
|
6
5
|
value: true
|
|
7
6
|
});
|
|
8
7
|
exports.default = void 0;
|
|
9
|
-
|
|
10
8
|
var _react = require("react");
|
|
11
|
-
|
|
12
9
|
var _constants = require("../../constants");
|
|
13
|
-
|
|
14
10
|
var _portalCustomEvent = _interopRequireDefault(require("../utils/portal-custom-event"));
|
|
15
|
-
|
|
16
11
|
var useFirePortalEvent = function useFirePortalEvent(zIndex) {
|
|
17
12
|
var zIndexNumber = Number(zIndex);
|
|
18
13
|
(0, _react.useEffect)(function () {
|
|
@@ -22,6 +17,5 @@ var useFirePortalEvent = function useFirePortalEvent(zIndex) {
|
|
|
22
17
|
};
|
|
23
18
|
}, [zIndexNumber]);
|
|
24
19
|
};
|
|
25
|
-
|
|
26
20
|
var _default = useFirePortalEvent;
|
|
27
21
|
exports.default = _default;
|
|
@@ -15,23 +15,22 @@ var zIndexToName = {
|
|
|
15
15
|
700: 'spotlight',
|
|
16
16
|
800: 'tooltip'
|
|
17
17
|
};
|
|
18
|
+
|
|
18
19
|
/**
|
|
19
20
|
* return layer name in Atlassian design system corresponding to given z-index
|
|
20
21
|
* @param {number} zIndex - z-index value for which layer name is needed
|
|
21
22
|
* @returns {LayerName | null} - The layer name for given z-index. If layer name is not found then null is returned
|
|
22
23
|
*/
|
|
23
|
-
|
|
24
24
|
var getLayerName = function getLayerName(zIndex) {
|
|
25
25
|
return zIndexToName.hasOwnProperty(zIndex) ? zIndexToName[zIndex] : null;
|
|
26
26
|
};
|
|
27
|
+
|
|
27
28
|
/**
|
|
28
29
|
* Creates a PortalEvent object with given eventName, given zIndex and corresponding layer
|
|
29
30
|
* @param {string} eventName - either of Mount or Unmount event name
|
|
30
31
|
* @param {number} zIndex - z-index value which will be included in the event to be dispatched
|
|
31
32
|
* @returns {PortalEvent} - The newly created PortalEvent object
|
|
32
33
|
*/
|
|
33
|
-
|
|
34
|
-
|
|
35
34
|
var getEvent = function getEvent(eventName, zIndex) {
|
|
36
35
|
var detail = {
|
|
37
36
|
layer: getLayerName(Number(zIndex)),
|
|
@@ -41,13 +40,12 @@ var getEvent = function getEvent(eventName, zIndex) {
|
|
|
41
40
|
detail: detail
|
|
42
41
|
});
|
|
43
42
|
};
|
|
43
|
+
|
|
44
44
|
/**
|
|
45
45
|
* Dispatches a custom event on window with given eventName, given zIndex and corresponding layer
|
|
46
46
|
* @param {string} eventName - either of Mount or Unmount event name
|
|
47
47
|
* @param {number} zIndex - z-index value which will be included in the event to be dispatched
|
|
48
48
|
*/
|
|
49
|
-
|
|
50
|
-
|
|
51
49
|
function firePortalEvent(eventName, zIndex) {
|
|
52
50
|
var event = getEvent(eventName, zIndex);
|
|
53
51
|
window.dispatchEvent(event);
|
|
@@ -4,9 +4,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.removePortalContainer = exports.createContainer = exports.appendPortalContainerIfNotAppended = void 0;
|
|
7
|
-
|
|
8
7
|
var _constants = require("../constants");
|
|
9
|
-
|
|
10
8
|
/**
|
|
11
9
|
* Creates a new portal container element with provided z-index and class name 'atlaskit-portal',
|
|
12
10
|
* it is not be attached to any DOM node at this stage.
|
|
@@ -19,59 +17,50 @@ var createContainer = function createContainer(zIndex) {
|
|
|
19
17
|
container.style.zIndex = "".concat(zIndex);
|
|
20
18
|
return container;
|
|
21
19
|
};
|
|
20
|
+
|
|
22
21
|
/**
|
|
23
22
|
* Returns document body element
|
|
24
23
|
* @return {number} - The document body element
|
|
25
24
|
*/
|
|
26
|
-
|
|
27
|
-
|
|
28
25
|
exports.createContainer = createContainer;
|
|
29
|
-
|
|
30
26
|
var getBody = function getBody() {
|
|
31
27
|
return document.body;
|
|
32
28
|
};
|
|
29
|
+
|
|
33
30
|
/**
|
|
34
31
|
* Returns portal parent container. If no container exists already then it creates a new container with class name 'atlaskit-portal-container'
|
|
35
32
|
* @return {Element} - The portal parent container div element
|
|
36
33
|
*/
|
|
37
|
-
|
|
38
|
-
|
|
39
34
|
var getPortalParent = function getPortalParent() {
|
|
40
35
|
var parentElement = document.querySelector(_constants.portalParentSelector);
|
|
41
|
-
|
|
42
36
|
if (!parentElement) {
|
|
43
37
|
var parent = document.createElement('div');
|
|
44
|
-
parent.className = _constants.portalParentClassName;
|
|
38
|
+
parent.className = _constants.portalParentClassName;
|
|
39
|
+
// we are setting display to flex because we want each portal to create a new stacking context
|
|
45
40
|
// See https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Positioning/Understanding_z_index/The_stacking_context
|
|
46
|
-
|
|
47
41
|
parent.style.display = 'flex';
|
|
48
42
|
getBody().appendChild(parent);
|
|
49
43
|
return parent;
|
|
50
44
|
}
|
|
51
|
-
|
|
52
45
|
return parentElement;
|
|
53
46
|
};
|
|
47
|
+
|
|
54
48
|
/**
|
|
55
49
|
* Removes portal container from portal parent container
|
|
56
50
|
* @param {HTMLDivElement | undefined} container - portal container to be removed from portal parent container
|
|
57
51
|
*/
|
|
58
|
-
|
|
59
|
-
|
|
60
52
|
var removePortalContainer = function removePortalContainer(container) {
|
|
61
53
|
getPortalParent().removeChild(container);
|
|
62
54
|
};
|
|
55
|
+
|
|
63
56
|
/**
|
|
64
57
|
* Appends portal container to portal parent container if it hasn't already been done
|
|
65
58
|
* @param {HTMLDivElement | undefined} container - portal container to be added to portal parent container
|
|
66
59
|
*/
|
|
67
|
-
|
|
68
|
-
|
|
69
60
|
exports.removePortalContainer = removePortalContainer;
|
|
70
|
-
|
|
71
61
|
var appendPortalContainerIfNotAppended = function appendPortalContainerIfNotAppended(container) {
|
|
72
62
|
if (!container.parentElement) {
|
|
73
63
|
getPortalParent().appendChild(container);
|
|
74
64
|
}
|
|
75
65
|
};
|
|
76
|
-
|
|
77
66
|
exports.appendPortalContainerIfNotAppended = appendPortalContainerIfNotAppended;
|
package/dist/cjs/portal.js
CHANGED
|
@@ -1,24 +1,18 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
5
4
|
Object.defineProperty(exports, "__esModule", {
|
|
6
5
|
value: true
|
|
7
6
|
});
|
|
8
7
|
exports.default = Portal;
|
|
9
|
-
|
|
10
8
|
var _react = _interopRequireDefault(require("react"));
|
|
11
|
-
|
|
12
9
|
var _internalPortal = _interopRequireDefault(require("./internal/components/internal-portal"));
|
|
13
|
-
|
|
14
10
|
var _useIsSubsequentRender = _interopRequireDefault(require("./internal/hooks/use-is-subsequent-render"));
|
|
15
|
-
|
|
16
11
|
var _usePortalEvent = _interopRequireDefault(require("./internal/hooks/use-portal-event"));
|
|
17
|
-
|
|
18
12
|
function Portal(props) {
|
|
19
13
|
var _props$zIndex = props.zIndex,
|
|
20
|
-
|
|
21
|
-
|
|
14
|
+
zIndex = _props$zIndex === void 0 ? 0 : _props$zIndex,
|
|
15
|
+
children = props.children;
|
|
22
16
|
var isSubsequentRender = (0, _useIsSubsequentRender.default)();
|
|
23
17
|
(0, _usePortalEvent.default)(zIndex);
|
|
24
18
|
return isSubsequentRender ? /*#__PURE__*/_react.default.createElement(_internalPortal.default, {
|
package/dist/cjs/version.json
CHANGED
|
@@ -6,11 +6,12 @@ export default function InternalPortal(props) {
|
|
|
6
6
|
zIndex,
|
|
7
7
|
children
|
|
8
8
|
} = props;
|
|
9
|
-
const container = useMemo(() => createContainer(zIndex), [zIndex]);
|
|
9
|
+
const container = useMemo(() => createContainer(zIndex), [zIndex]);
|
|
10
|
+
|
|
11
|
+
// This is in the render method instead of useEffect so that
|
|
10
12
|
// the portal will be added to the DOM before the children render.
|
|
11
13
|
// For any further changes, ensure that the container does not have a
|
|
12
14
|
// parent besides the portal parent.
|
|
13
|
-
|
|
14
15
|
appendPortalContainerIfNotAppended(container);
|
|
15
16
|
useEffect(() => {
|
|
16
17
|
return () => {
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { useEffect, useState } from 'react';
|
|
2
|
-
|
|
3
2
|
const useIsSubsequentRender = () => {
|
|
4
3
|
const [isSubsequentRender, setIsSubsequentRender] = useState(false);
|
|
5
4
|
useEffect(() => {
|
|
@@ -7,5 +6,4 @@ const useIsSubsequentRender = () => {
|
|
|
7
6
|
}, []);
|
|
8
7
|
return isSubsequentRender;
|
|
9
8
|
};
|
|
10
|
-
|
|
11
9
|
export default useIsSubsequentRender;
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { useEffect } from 'react';
|
|
2
2
|
import { PORTAL_MOUNT_EVENT, PORTAL_UNMOUNT_EVENT } from '../../constants';
|
|
3
3
|
import firePortalEvent from '../utils/portal-custom-event';
|
|
4
|
-
|
|
5
4
|
const useFirePortalEvent = zIndex => {
|
|
6
5
|
const zIndexNumber = Number(zIndex);
|
|
7
6
|
useEffect(() => {
|
|
@@ -11,5 +10,4 @@ const useFirePortalEvent = zIndex => {
|
|
|
11
10
|
};
|
|
12
11
|
}, [zIndexNumber]);
|
|
13
12
|
};
|
|
14
|
-
|
|
15
13
|
export default useFirePortalEvent;
|
|
@@ -9,23 +9,22 @@ const zIndexToName = {
|
|
|
9
9
|
700: 'spotlight',
|
|
10
10
|
800: 'tooltip'
|
|
11
11
|
};
|
|
12
|
+
|
|
12
13
|
/**
|
|
13
14
|
* return layer name in Atlassian design system corresponding to given z-index
|
|
14
15
|
* @param {number} zIndex - z-index value for which layer name is needed
|
|
15
16
|
* @returns {LayerName | null} - The layer name for given z-index. If layer name is not found then null is returned
|
|
16
17
|
*/
|
|
17
|
-
|
|
18
18
|
const getLayerName = zIndex => {
|
|
19
19
|
return zIndexToName.hasOwnProperty(zIndex) ? zIndexToName[zIndex] : null;
|
|
20
20
|
};
|
|
21
|
+
|
|
21
22
|
/**
|
|
22
23
|
* Creates a PortalEvent object with given eventName, given zIndex and corresponding layer
|
|
23
24
|
* @param {string} eventName - either of Mount or Unmount event name
|
|
24
25
|
* @param {number} zIndex - z-index value which will be included in the event to be dispatched
|
|
25
26
|
* @returns {PortalEvent} - The newly created PortalEvent object
|
|
26
27
|
*/
|
|
27
|
-
|
|
28
|
-
|
|
29
28
|
const getEvent = (eventName, zIndex) => {
|
|
30
29
|
const detail = {
|
|
31
30
|
layer: getLayerName(Number(zIndex)),
|
|
@@ -35,13 +34,12 @@ const getEvent = (eventName, zIndex) => {
|
|
|
35
34
|
detail
|
|
36
35
|
});
|
|
37
36
|
};
|
|
37
|
+
|
|
38
38
|
/**
|
|
39
39
|
* Dispatches a custom event on window with given eventName, given zIndex and corresponding layer
|
|
40
40
|
* @param {string} eventName - either of Mount or Unmount event name
|
|
41
41
|
* @param {number} zIndex - z-index value which will be included in the event to be dispatched
|
|
42
42
|
*/
|
|
43
|
-
|
|
44
|
-
|
|
45
43
|
export default function firePortalEvent(eventName, zIndex) {
|
|
46
44
|
const event = getEvent(eventName, zIndex);
|
|
47
45
|
window.dispatchEvent(event);
|
|
@@ -1,60 +1,56 @@
|
|
|
1
1
|
import { portalClassName, portalParentClassName, portalParentSelector } from '../constants';
|
|
2
|
+
|
|
2
3
|
/**
|
|
3
4
|
* Creates a new portal container element with provided z-index and class name 'atlaskit-portal',
|
|
4
5
|
* it is not be attached to any DOM node at this stage.
|
|
5
6
|
* @param {number | string} zIndex - the z-index value of the newly created portal container element
|
|
6
7
|
* @return {number} - The newly created container element
|
|
7
8
|
*/
|
|
8
|
-
|
|
9
9
|
export const createContainer = zIndex => {
|
|
10
10
|
const container = document.createElement('div');
|
|
11
11
|
container.className = portalClassName;
|
|
12
12
|
container.style.zIndex = `${zIndex}`;
|
|
13
13
|
return container;
|
|
14
14
|
};
|
|
15
|
+
|
|
15
16
|
/**
|
|
16
17
|
* Returns document body element
|
|
17
18
|
* @return {number} - The document body element
|
|
18
19
|
*/
|
|
19
|
-
|
|
20
20
|
const getBody = () => {
|
|
21
21
|
return document.body;
|
|
22
22
|
};
|
|
23
|
+
|
|
23
24
|
/**
|
|
24
25
|
* Returns portal parent container. If no container exists already then it creates a new container with class name 'atlaskit-portal-container'
|
|
25
26
|
* @return {Element} - The portal parent container div element
|
|
26
27
|
*/
|
|
27
|
-
|
|
28
|
-
|
|
29
28
|
const getPortalParent = () => {
|
|
30
29
|
const parentElement = document.querySelector(portalParentSelector);
|
|
31
|
-
|
|
32
30
|
if (!parentElement) {
|
|
33
31
|
const parent = document.createElement('div');
|
|
34
|
-
parent.className = portalParentClassName;
|
|
32
|
+
parent.className = portalParentClassName;
|
|
33
|
+
// we are setting display to flex because we want each portal to create a new stacking context
|
|
35
34
|
// See https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Positioning/Understanding_z_index/The_stacking_context
|
|
36
|
-
|
|
37
35
|
parent.style.display = 'flex';
|
|
38
36
|
getBody().appendChild(parent);
|
|
39
37
|
return parent;
|
|
40
38
|
}
|
|
41
|
-
|
|
42
39
|
return parentElement;
|
|
43
40
|
};
|
|
41
|
+
|
|
44
42
|
/**
|
|
45
43
|
* Removes portal container from portal parent container
|
|
46
44
|
* @param {HTMLDivElement | undefined} container - portal container to be removed from portal parent container
|
|
47
45
|
*/
|
|
48
|
-
|
|
49
|
-
|
|
50
46
|
export const removePortalContainer = container => {
|
|
51
47
|
getPortalParent().removeChild(container);
|
|
52
48
|
};
|
|
49
|
+
|
|
53
50
|
/**
|
|
54
51
|
* Appends portal container to portal parent container if it hasn't already been done
|
|
55
52
|
* @param {HTMLDivElement | undefined} container - portal container to be added to portal parent container
|
|
56
53
|
*/
|
|
57
|
-
|
|
58
54
|
export const appendPortalContainerIfNotAppended = container => {
|
|
59
55
|
if (!container.parentElement) {
|
|
60
56
|
getPortalParent().appendChild(container);
|
package/dist/es2019/version.json
CHANGED
|
@@ -3,14 +3,15 @@ import { createPortal } from 'react-dom';
|
|
|
3
3
|
import { appendPortalContainerIfNotAppended, createContainer, removePortalContainer } from '../utils/portal-dom-utils';
|
|
4
4
|
export default function InternalPortal(props) {
|
|
5
5
|
var zIndex = props.zIndex,
|
|
6
|
-
|
|
6
|
+
children = props.children;
|
|
7
7
|
var container = useMemo(function () {
|
|
8
8
|
return createContainer(zIndex);
|
|
9
|
-
}, [zIndex]);
|
|
9
|
+
}, [zIndex]);
|
|
10
|
+
|
|
11
|
+
// This is in the render method instead of useEffect so that
|
|
10
12
|
// the portal will be added to the DOM before the children render.
|
|
11
13
|
// For any further changes, ensure that the container does not have a
|
|
12
14
|
// parent besides the portal parent.
|
|
13
|
-
|
|
14
15
|
appendPortalContainerIfNotAppended(container);
|
|
15
16
|
useEffect(function () {
|
|
16
17
|
return function () {
|
|
@@ -1,16 +1,13 @@
|
|
|
1
1
|
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
2
2
|
import { useEffect, useState } from 'react';
|
|
3
|
-
|
|
4
3
|
var useIsSubsequentRender = function useIsSubsequentRender() {
|
|
5
4
|
var _useState = useState(false),
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
5
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
6
|
+
isSubsequentRender = _useState2[0],
|
|
7
|
+
setIsSubsequentRender = _useState2[1];
|
|
10
8
|
useEffect(function () {
|
|
11
9
|
setIsSubsequentRender(true);
|
|
12
10
|
}, []);
|
|
13
11
|
return isSubsequentRender;
|
|
14
12
|
};
|
|
15
|
-
|
|
16
13
|
export default useIsSubsequentRender;
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { useEffect } from 'react';
|
|
2
2
|
import { PORTAL_MOUNT_EVENT, PORTAL_UNMOUNT_EVENT } from '../../constants';
|
|
3
3
|
import firePortalEvent from '../utils/portal-custom-event';
|
|
4
|
-
|
|
5
4
|
var useFirePortalEvent = function useFirePortalEvent(zIndex) {
|
|
6
5
|
var zIndexNumber = Number(zIndex);
|
|
7
6
|
useEffect(function () {
|
|
@@ -11,5 +10,4 @@ var useFirePortalEvent = function useFirePortalEvent(zIndex) {
|
|
|
11
10
|
};
|
|
12
11
|
}, [zIndexNumber]);
|
|
13
12
|
};
|
|
14
|
-
|
|
15
13
|
export default useFirePortalEvent;
|
|
@@ -9,23 +9,22 @@ var zIndexToName = {
|
|
|
9
9
|
700: 'spotlight',
|
|
10
10
|
800: 'tooltip'
|
|
11
11
|
};
|
|
12
|
+
|
|
12
13
|
/**
|
|
13
14
|
* return layer name in Atlassian design system corresponding to given z-index
|
|
14
15
|
* @param {number} zIndex - z-index value for which layer name is needed
|
|
15
16
|
* @returns {LayerName | null} - The layer name for given z-index. If layer name is not found then null is returned
|
|
16
17
|
*/
|
|
17
|
-
|
|
18
18
|
var getLayerName = function getLayerName(zIndex) {
|
|
19
19
|
return zIndexToName.hasOwnProperty(zIndex) ? zIndexToName[zIndex] : null;
|
|
20
20
|
};
|
|
21
|
+
|
|
21
22
|
/**
|
|
22
23
|
* Creates a PortalEvent object with given eventName, given zIndex and corresponding layer
|
|
23
24
|
* @param {string} eventName - either of Mount or Unmount event name
|
|
24
25
|
* @param {number} zIndex - z-index value which will be included in the event to be dispatched
|
|
25
26
|
* @returns {PortalEvent} - The newly created PortalEvent object
|
|
26
27
|
*/
|
|
27
|
-
|
|
28
|
-
|
|
29
28
|
var getEvent = function getEvent(eventName, zIndex) {
|
|
30
29
|
var detail = {
|
|
31
30
|
layer: getLayerName(Number(zIndex)),
|
|
@@ -35,13 +34,12 @@ var getEvent = function getEvent(eventName, zIndex) {
|
|
|
35
34
|
detail: detail
|
|
36
35
|
});
|
|
37
36
|
};
|
|
37
|
+
|
|
38
38
|
/**
|
|
39
39
|
* Dispatches a custom event on window with given eventName, given zIndex and corresponding layer
|
|
40
40
|
* @param {string} eventName - either of Mount or Unmount event name
|
|
41
41
|
* @param {number} zIndex - z-index value which will be included in the event to be dispatched
|
|
42
42
|
*/
|
|
43
|
-
|
|
44
|
-
|
|
45
43
|
export default function firePortalEvent(eventName, zIndex) {
|
|
46
44
|
var event = getEvent(eventName, zIndex);
|
|
47
45
|
window.dispatchEvent(event);
|
|
@@ -1,60 +1,56 @@
|
|
|
1
1
|
import { portalClassName, portalParentClassName, portalParentSelector } from '../constants';
|
|
2
|
+
|
|
2
3
|
/**
|
|
3
4
|
* Creates a new portal container element with provided z-index and class name 'atlaskit-portal',
|
|
4
5
|
* it is not be attached to any DOM node at this stage.
|
|
5
6
|
* @param {number | string} zIndex - the z-index value of the newly created portal container element
|
|
6
7
|
* @return {number} - The newly created container element
|
|
7
8
|
*/
|
|
8
|
-
|
|
9
9
|
export var createContainer = function createContainer(zIndex) {
|
|
10
10
|
var container = document.createElement('div');
|
|
11
11
|
container.className = portalClassName;
|
|
12
12
|
container.style.zIndex = "".concat(zIndex);
|
|
13
13
|
return container;
|
|
14
14
|
};
|
|
15
|
+
|
|
15
16
|
/**
|
|
16
17
|
* Returns document body element
|
|
17
18
|
* @return {number} - The document body element
|
|
18
19
|
*/
|
|
19
|
-
|
|
20
20
|
var getBody = function getBody() {
|
|
21
21
|
return document.body;
|
|
22
22
|
};
|
|
23
|
+
|
|
23
24
|
/**
|
|
24
25
|
* Returns portal parent container. If no container exists already then it creates a new container with class name 'atlaskit-portal-container'
|
|
25
26
|
* @return {Element} - The portal parent container div element
|
|
26
27
|
*/
|
|
27
|
-
|
|
28
|
-
|
|
29
28
|
var getPortalParent = function getPortalParent() {
|
|
30
29
|
var parentElement = document.querySelector(portalParentSelector);
|
|
31
|
-
|
|
32
30
|
if (!parentElement) {
|
|
33
31
|
var parent = document.createElement('div');
|
|
34
|
-
parent.className = portalParentClassName;
|
|
32
|
+
parent.className = portalParentClassName;
|
|
33
|
+
// we are setting display to flex because we want each portal to create a new stacking context
|
|
35
34
|
// See https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Positioning/Understanding_z_index/The_stacking_context
|
|
36
|
-
|
|
37
35
|
parent.style.display = 'flex';
|
|
38
36
|
getBody().appendChild(parent);
|
|
39
37
|
return parent;
|
|
40
38
|
}
|
|
41
|
-
|
|
42
39
|
return parentElement;
|
|
43
40
|
};
|
|
41
|
+
|
|
44
42
|
/**
|
|
45
43
|
* Removes portal container from portal parent container
|
|
46
44
|
* @param {HTMLDivElement | undefined} container - portal container to be removed from portal parent container
|
|
47
45
|
*/
|
|
48
|
-
|
|
49
|
-
|
|
50
46
|
export var removePortalContainer = function removePortalContainer(container) {
|
|
51
47
|
getPortalParent().removeChild(container);
|
|
52
48
|
};
|
|
49
|
+
|
|
53
50
|
/**
|
|
54
51
|
* Appends portal container to portal parent container if it hasn't already been done
|
|
55
52
|
* @param {HTMLDivElement | undefined} container - portal container to be added to portal parent container
|
|
56
53
|
*/
|
|
57
|
-
|
|
58
54
|
export var appendPortalContainerIfNotAppended = function appendPortalContainerIfNotAppended(container) {
|
|
59
55
|
if (!container.parentElement) {
|
|
60
56
|
getPortalParent().appendChild(container);
|
package/dist/esm/portal.js
CHANGED
|
@@ -4,8 +4,8 @@ import useIsSubsequentRender from './internal/hooks/use-is-subsequent-render';
|
|
|
4
4
|
import useFirePortalEvent from './internal/hooks/use-portal-event';
|
|
5
5
|
export default function Portal(props) {
|
|
6
6
|
var _props$zIndex = props.zIndex,
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
zIndex = _props$zIndex === void 0 ? 0 : _props$zIndex,
|
|
8
|
+
children = props.children;
|
|
9
9
|
var isSubsequentRender = useIsSubsequentRender();
|
|
10
10
|
useFirePortalEvent(zIndex);
|
|
11
11
|
return isSubsequentRender ? /*#__PURE__*/React.createElement(InternalPortal, {
|
package/dist/esm/version.json
CHANGED
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaskit/portal",
|
|
3
|
-
"version": "4.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "4.3.0",
|
|
4
|
+
"description": "A wrapper for rendering components in React portals.",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"registry": "https://registry.npmjs.org/"
|
|
7
7
|
},
|
|
@@ -12,23 +12,14 @@
|
|
|
12
12
|
"module": "dist/esm/index.js",
|
|
13
13
|
"module:es2019": "dist/es2019/index.js",
|
|
14
14
|
"types": "dist/types/index.d.ts",
|
|
15
|
-
"typesVersions": {
|
|
16
|
-
">=4.0 <4.5": {
|
|
17
|
-
"*": [
|
|
18
|
-
"dist/types-ts4.0/*",
|
|
19
|
-
"dist/types-ts4.0/index.d.ts"
|
|
20
|
-
]
|
|
21
|
-
}
|
|
22
|
-
},
|
|
23
15
|
"sideEffects": false,
|
|
24
16
|
"atlaskit:src": "src/index.tsx",
|
|
25
17
|
"atlassian": {
|
|
26
|
-
"disableProductCI": true,
|
|
27
18
|
"team": "Design System Team",
|
|
28
19
|
"releaseModel": "scheduled",
|
|
29
20
|
"website": {
|
|
30
21
|
"name": "Portal",
|
|
31
|
-
"category": "
|
|
22
|
+
"category": "Libraries"
|
|
32
23
|
}
|
|
33
24
|
},
|
|
34
25
|
"af:exports": {
|
|
@@ -36,7 +27,7 @@
|
|
|
36
27
|
".": "./src/index.tsx"
|
|
37
28
|
},
|
|
38
29
|
"dependencies": {
|
|
39
|
-
"@atlaskit/theme": "^12.
|
|
30
|
+
"@atlaskit/theme": "^12.5.0",
|
|
40
31
|
"@babel/runtime": "^7.0.0"
|
|
41
32
|
},
|
|
42
33
|
"peerDependencies": {
|
|
@@ -44,18 +35,24 @@
|
|
|
44
35
|
"react-dom": "^16.8.0"
|
|
45
36
|
},
|
|
46
37
|
"devDependencies": {
|
|
47
|
-
"@atlaskit/
|
|
38
|
+
"@atlaskit/banner": "^12.1.0",
|
|
39
|
+
"@atlaskit/button": "^16.7.0",
|
|
40
|
+
"@atlaskit/code": "^14.6.0",
|
|
48
41
|
"@atlaskit/docs": "*",
|
|
49
|
-
"@atlaskit/flag": "^
|
|
50
|
-
"@atlaskit/icon": "^21.
|
|
51
|
-
"@atlaskit/
|
|
52
|
-
"@atlaskit/
|
|
53
|
-
"@atlaskit/
|
|
42
|
+
"@atlaskit/flag": "^15.2.0",
|
|
43
|
+
"@atlaskit/icon": "^21.12.0",
|
|
44
|
+
"@atlaskit/image": "^1.1.0",
|
|
45
|
+
"@atlaskit/inline-dialog": "^13.6.0",
|
|
46
|
+
"@atlaskit/modal-dialog": "^12.5.0",
|
|
47
|
+
"@atlaskit/onboarding": "^10.8.0",
|
|
48
|
+
"@atlaskit/section-message": "^6.4.0",
|
|
54
49
|
"@atlaskit/ssr": "*",
|
|
55
|
-
"@atlaskit/
|
|
50
|
+
"@atlaskit/tokens": "^1.3.0",
|
|
51
|
+
"@atlaskit/tooltip": "^17.8.0",
|
|
56
52
|
"@atlaskit/visual-regression": "*",
|
|
57
53
|
"@atlaskit/webdriver-runner": "*",
|
|
58
54
|
"@atlassian/atlassian-frontend-prettier-config-1.0.1": "npm:@atlassian/atlassian-frontend-prettier-config@1.0.1",
|
|
55
|
+
"@emotion/react": "^11.7.1",
|
|
59
56
|
"@testing-library/react": "^12.1.5",
|
|
60
57
|
"bind-event-listener": "^2.1.1",
|
|
61
58
|
"enzyme": "^3.10.0",
|
|
@@ -77,8 +74,10 @@
|
|
|
77
74
|
"design-system": "v1",
|
|
78
75
|
"ui-components": "lite-mode",
|
|
79
76
|
"analytics": "analytics-next",
|
|
80
|
-
"design-tokens":
|
|
81
|
-
|
|
77
|
+
"design-tokens": [
|
|
78
|
+
"color",
|
|
79
|
+
"spacing"
|
|
80
|
+
],
|
|
82
81
|
"deprecation": "no-deprecated-imports",
|
|
83
82
|
"styling": [
|
|
84
83
|
"static",
|
|
@@ -86,6 +85,6 @@
|
|
|
86
85
|
]
|
|
87
86
|
}
|
|
88
87
|
},
|
|
89
|
-
"homepage": "https://
|
|
88
|
+
"homepage": "https://atlassian.design/components/portal/",
|
|
90
89
|
"prettier": "@atlassian/atlassian-frontend-prettier-config-1.0.1"
|
|
91
90
|
}
|
package/report.api.md
CHANGED
|
@@ -1,8 +1,17 @@
|
|
|
1
|
-
|
|
1
|
+
<!-- API Report Version: 2.3 -->
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
## API Report File for "@atlaskit/portal"
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
> Do not edit this file. This report is auto-generated using [API Extractor](https://api-extractor.com/).
|
|
6
|
+
> [Learn more about API reports](https://hello.atlassian.net/wiki/spaces/UR/pages/1825484529/Package+API+Reports)
|
|
7
|
+
|
|
8
|
+
### Table of contents
|
|
9
|
+
|
|
10
|
+
- [Main Entry Types](#main-entry-types)
|
|
11
|
+
|
|
12
|
+
### Main Entry Types
|
|
13
|
+
|
|
14
|
+
<!--SECTION START: Main Entry Types-->
|
|
6
15
|
|
|
7
16
|
```ts
|
|
8
17
|
/// <reference types="react" />
|
|
@@ -10,38 +19,39 @@
|
|
|
10
19
|
import type { Layers } from '@atlaskit/theme/types';
|
|
11
20
|
import { default as React_2 } from 'react';
|
|
12
21
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
*/
|
|
16
|
-
declare type LayerName = keyof Layers;
|
|
22
|
+
// @public
|
|
23
|
+
type LayerName = keyof Layers;
|
|
17
24
|
|
|
18
|
-
|
|
25
|
+
// @public (undocumented)
|
|
26
|
+
function Portal(props: PortalProps): JSX.Element | null;
|
|
19
27
|
export default Portal;
|
|
20
28
|
|
|
21
|
-
|
|
29
|
+
// @public (undocumented)
|
|
30
|
+
export const PORTAL_MOUNT_EVENT = 'akPortalMount';
|
|
22
31
|
|
|
23
|
-
|
|
32
|
+
// @public (undocumented)
|
|
33
|
+
export const PORTAL_UNMOUNT_EVENT = 'akPortalUnmount';
|
|
24
34
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
*/
|
|
28
|
-
export declare type PortalEvent = CustomEvent<PortalEventDetail>;
|
|
35
|
+
// @public
|
|
36
|
+
export type PortalEvent = CustomEvent<PortalEventDetail>;
|
|
29
37
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
declare interface PortalEventDetail {
|
|
38
|
+
// @public
|
|
39
|
+
interface PortalEventDetail {
|
|
40
|
+
// (undocumented)
|
|
34
41
|
layer: LayerName | null;
|
|
42
|
+
// (undocumented)
|
|
35
43
|
zIndex: number;
|
|
36
44
|
}
|
|
37
45
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
export declare interface PortalProps {
|
|
46
|
+
// @public
|
|
47
|
+
export interface PortalProps {
|
|
48
|
+
// (undocumented)
|
|
42
49
|
children: React_2.ReactNode;
|
|
50
|
+
// (undocumented)
|
|
43
51
|
zIndex?: number | string;
|
|
44
52
|
}
|
|
45
53
|
|
|
46
|
-
|
|
54
|
+
// (No @packageDocumentation comment for this package)
|
|
47
55
|
```
|
|
56
|
+
|
|
57
|
+
<!--SECTION END: Main Entry Types-->
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export type { PortalEvent, PortalProps } from '../types';
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import type { Layers } from '@atlaskit/theme/types';
|
|
2
|
-
/**
|
|
3
|
-
* Named layers of all z-index used in the Atlassian Design System.
|
|
4
|
-
*/
|
|
5
|
-
export declare type LayerName = keyof Layers;
|
|
6
|
-
/**
|
|
7
|
-
* Creates a new type by reversing the key and values of the passed type
|
|
8
|
-
* @param {T} T - the generic type to be reversed. Each members of it should be a Record in key-value form
|
|
9
|
-
* @returns - The reversed type
|
|
10
|
-
*/
|
|
11
|
-
declare type ReverseMap<T extends Record<keyof T, T[keyof T]>> = {
|
|
12
|
-
[P in T[keyof T]]: {
|
|
13
|
-
[K in keyof T]: T[K] extends P ? K : never;
|
|
14
|
-
}[keyof T];
|
|
15
|
-
};
|
|
16
|
-
export declare type ReversedLayers = ReverseMap<Layers>;
|
|
17
|
-
/**
|
|
18
|
-
* Interface for event to be fired on Atlassian Portal component mount and unmount
|
|
19
|
-
*/
|
|
20
|
-
export interface PortalEventDetail {
|
|
21
|
-
layer: LayerName | null;
|
|
22
|
-
zIndex: number;
|
|
23
|
-
}
|
|
24
|
-
export {};
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Dispatches a custom event on window with given eventName, given zIndex and corresponding layer
|
|
3
|
-
* @param {string} eventName - either of Mount or Unmount event name
|
|
4
|
-
* @param {number} zIndex - z-index value which will be included in the event to be dispatched
|
|
5
|
-
*/
|
|
6
|
-
export default function firePortalEvent(eventName: string, zIndex: number): void;
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Creates a new portal container element with provided z-index and class name 'atlaskit-portal',
|
|
3
|
-
* it is not be attached to any DOM node at this stage.
|
|
4
|
-
* @param {number | string} zIndex - the z-index value of the newly created portal container element
|
|
5
|
-
* @return {number} - The newly created container element
|
|
6
|
-
*/
|
|
7
|
-
export declare const createContainer: (zIndex: number | string) => HTMLDivElement;
|
|
8
|
-
/**
|
|
9
|
-
* Removes portal container from portal parent container
|
|
10
|
-
* @param {HTMLDivElement | undefined} container - portal container to be removed from portal parent container
|
|
11
|
-
*/
|
|
12
|
-
export declare const removePortalContainer: (container: HTMLDivElement) => void;
|
|
13
|
-
/**
|
|
14
|
-
* Appends portal container to portal parent container if it hasn't already been done
|
|
15
|
-
* @param {HTMLDivElement | undefined} container - portal container to be added to portal parent container
|
|
16
|
-
*/
|
|
17
|
-
export declare const appendPortalContainerIfNotAppended: (container: HTMLDivElement) => void;
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { PortalEventDetail } from './internal/types';
|
|
3
|
-
/**
|
|
4
|
-
* Interface for props to be passed in Atlassian Portal component
|
|
5
|
-
*/
|
|
6
|
-
export interface PortalProps {
|
|
7
|
-
children: React.ReactNode;
|
|
8
|
-
zIndex?: number | string;
|
|
9
|
-
}
|
|
10
|
-
/**
|
|
11
|
-
* Custom event object that will be fired when Atlassian Portal component is mounted and unmounted
|
|
12
|
-
*/
|
|
13
|
-
export declare type PortalEvent = CustomEvent<PortalEventDetail>;
|