@atlaskit/popup 1.15.1 → 1.16.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 +10 -0
- package/dist/cjs/compositional/popup.js +165 -0
- package/dist/cjs/entry-points/experimental/compositional.js +24 -0
- package/dist/cjs/popup.js +2 -28
- package/dist/cjs/use-get-memoized-merged-trigger-ref.js +39 -0
- package/dist/es2019/compositional/popup.js +144 -0
- package/dist/es2019/entry-points/experimental/compositional.js +1 -0
- package/dist/es2019/popup.js +2 -24
- package/dist/es2019/use-get-memoized-merged-trigger-ref.js +28 -0
- package/dist/esm/compositional/popup.js +155 -0
- package/dist/esm/entry-points/experimental/compositional.js +1 -0
- package/dist/esm/popup.js +2 -28
- package/dist/esm/use-get-memoized-merged-trigger-ref.js +33 -0
- package/dist/types/compositional/popup.d.ts +49 -0
- package/dist/types/entry-points/experimental/compositional.d.ts +2 -0
- package/dist/types/use-get-memoized-merged-trigger-ref.d.ts +2 -0
- package/dist/types-ts4.5/compositional/popup.d.ts +49 -0
- package/dist/types-ts4.5/entry-points/experimental/compositional.d.ts +2 -0
- package/dist/types-ts4.5/use-get-memoized-merged-trigger-ref.d.ts +2 -0
- package/experimental/package.json +15 -0
- package/package.json +7 -4
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
# @atlaskit/popup
|
|
2
2
|
|
|
3
|
+
## 1.16.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [#95249](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/95249)
|
|
8
|
+
[`039491355ada`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/039491355ada) -
|
|
9
|
+
Adds new entry points for an alternate experimental Popup API using composable components. The
|
|
10
|
+
new exports are prefixed with UNSAFE should only be used after agreement with the Design System
|
|
11
|
+
team.
|
|
12
|
+
|
|
3
13
|
## 1.15.1
|
|
4
14
|
|
|
5
15
|
### Patch Changes
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
var _typeof = require("@babel/runtime/helpers/typeof");
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.PopupTrigger = exports.PopupContent = exports.Popup = void 0;
|
|
9
|
+
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
10
|
+
var _react = _interopRequireWildcard(require("react"));
|
|
11
|
+
var _tinyInvariant = _interopRequireDefault(require("tiny-invariant"));
|
|
12
|
+
var _noop = _interopRequireDefault(require("@atlaskit/ds-lib/noop"));
|
|
13
|
+
var _layering = require("@atlaskit/layering");
|
|
14
|
+
var _popper = require("@atlaskit/popper");
|
|
15
|
+
var _portal = _interopRequireDefault(require("@atlaskit/portal"));
|
|
16
|
+
var _constants = require("@atlaskit/theme/constants");
|
|
17
|
+
var _popperWrapper = _interopRequireDefault(require("../popper-wrapper"));
|
|
18
|
+
var _useGetMemoizedMergedTriggerRef = require("../use-get-memoized-merged-trigger-ref");
|
|
19
|
+
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
|
|
20
|
+
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
21
|
+
var IsOpenContext = /*#__PURE__*/(0, _react.createContext)(false);
|
|
22
|
+
var IdContext = /*#__PURE__*/(0, _react.createContext)(undefined);
|
|
23
|
+
var TriggerRefContext = /*#__PURE__*/(0, _react.createContext)(null);
|
|
24
|
+
var SetTriggerRefContext = /*#__PURE__*/(0, _react.createContext)(_noop.default);
|
|
25
|
+
var EnsureIsInsidePopupContext = /*#__PURE__*/(0, _react.createContext)(false);
|
|
26
|
+
|
|
27
|
+
// Used to ensure popup sub-components are used within a Popup
|
|
28
|
+
// and provide a useful error message if not.
|
|
29
|
+
var useEnsureIsInsidePopup = function useEnsureIsInsidePopup() {
|
|
30
|
+
var context = (0, _react.useContext)(EnsureIsInsidePopupContext);
|
|
31
|
+
(0, _tinyInvariant.default)(context, 'PopupTrigger and PopupContent components must be used within a Popup');
|
|
32
|
+
};
|
|
33
|
+
/**
|
|
34
|
+
* __Popup__
|
|
35
|
+
*
|
|
36
|
+
* Popup is a composable component that provides the context for the trigger and content components.
|
|
37
|
+
*
|
|
38
|
+
* Usage example:
|
|
39
|
+
* ```jsx
|
|
40
|
+
* <Popup>
|
|
41
|
+
* <PopupTrigger>
|
|
42
|
+
* {(props) => (
|
|
43
|
+
* <button type="button" {...props}>Click me</button>
|
|
44
|
+
* )}
|
|
45
|
+
* </PopupTrigger>
|
|
46
|
+
* <PopupContent>
|
|
47
|
+
* {(props) => <div>Hello world</div>}
|
|
48
|
+
* </PopupContent>
|
|
49
|
+
* </Popup>
|
|
50
|
+
* ```
|
|
51
|
+
*/
|
|
52
|
+
var Popup = exports.Popup = function Popup(_ref) {
|
|
53
|
+
var children = _ref.children,
|
|
54
|
+
id = _ref.id,
|
|
55
|
+
_ref$isOpen = _ref.isOpen,
|
|
56
|
+
isOpen = _ref$isOpen === void 0 ? false : _ref$isOpen;
|
|
57
|
+
var _useState = (0, _react.useState)(null),
|
|
58
|
+
_useState2 = (0, _slicedToArray2.default)(_useState, 2),
|
|
59
|
+
triggerRef = _useState2[0],
|
|
60
|
+
setTriggerRef = _useState2[1];
|
|
61
|
+
return /*#__PURE__*/_react.default.createElement(EnsureIsInsidePopupContext.Provider, {
|
|
62
|
+
value: true
|
|
63
|
+
}, /*#__PURE__*/_react.default.createElement(IdContext.Provider, {
|
|
64
|
+
value: id
|
|
65
|
+
}, /*#__PURE__*/_react.default.createElement(TriggerRefContext.Provider, {
|
|
66
|
+
value: triggerRef
|
|
67
|
+
}, /*#__PURE__*/_react.default.createElement(SetTriggerRefContext.Provider, {
|
|
68
|
+
value: setTriggerRef
|
|
69
|
+
}, /*#__PURE__*/_react.default.createElement(IsOpenContext.Provider, {
|
|
70
|
+
value: isOpen
|
|
71
|
+
}, /*#__PURE__*/_react.default.createElement(_popper.Manager, null, children))))));
|
|
72
|
+
};
|
|
73
|
+
/**
|
|
74
|
+
* __Popup trigger__
|
|
75
|
+
*
|
|
76
|
+
* Popup trigger is the component that renders the trigger for the popup.
|
|
77
|
+
*
|
|
78
|
+
* It must be a child of the Popup component.
|
|
79
|
+
*/
|
|
80
|
+
var PopupTrigger = exports.PopupTrigger = function PopupTrigger(_ref2) {
|
|
81
|
+
var children = _ref2.children;
|
|
82
|
+
useEnsureIsInsidePopup();
|
|
83
|
+
var isOpen = (0, _react.useContext)(IsOpenContext);
|
|
84
|
+
var id = (0, _react.useContext)(IdContext);
|
|
85
|
+
var setTriggerRef = (0, _react.useContext)(SetTriggerRefContext);
|
|
86
|
+
var getMergedTriggerRef = (0, _useGetMemoizedMergedTriggerRef.useGetMemoizedMergedTriggerRef)();
|
|
87
|
+
return /*#__PURE__*/_react.default.createElement(_popper.Reference, null, function (_ref3) {
|
|
88
|
+
var ref = _ref3.ref;
|
|
89
|
+
return children({
|
|
90
|
+
ref: getMergedTriggerRef(ref, setTriggerRef, isOpen),
|
|
91
|
+
'aria-controls': id,
|
|
92
|
+
'aria-expanded': isOpen,
|
|
93
|
+
'aria-haspopup': true
|
|
94
|
+
});
|
|
95
|
+
});
|
|
96
|
+
};
|
|
97
|
+
var defaultLayer = _constants.layers.layer();
|
|
98
|
+
/**
|
|
99
|
+
* __Popup content__
|
|
100
|
+
*
|
|
101
|
+
* Popup content is the component that renders the content of the popup.
|
|
102
|
+
*
|
|
103
|
+
* It must be a child of the Popup component.
|
|
104
|
+
*/
|
|
105
|
+
var PopupContent = exports.PopupContent = function PopupContent(_ref4) {
|
|
106
|
+
var children = _ref4.children,
|
|
107
|
+
boundary = _ref4.boundary,
|
|
108
|
+
offset = _ref4.offset,
|
|
109
|
+
strategy = _ref4.strategy,
|
|
110
|
+
onClose = _ref4.onClose,
|
|
111
|
+
testId = _ref4.testId,
|
|
112
|
+
_ref4$rootBoundary = _ref4.rootBoundary,
|
|
113
|
+
rootBoundary = _ref4$rootBoundary === void 0 ? 'viewport' : _ref4$rootBoundary,
|
|
114
|
+
_ref4$shouldFlip = _ref4.shouldFlip,
|
|
115
|
+
shouldFlip = _ref4$shouldFlip === void 0 ? true : _ref4$shouldFlip,
|
|
116
|
+
_ref4$placement = _ref4.placement,
|
|
117
|
+
placement = _ref4$placement === void 0 ? 'auto' : _ref4$placement,
|
|
118
|
+
fallbackPlacements = _ref4.fallbackPlacements,
|
|
119
|
+
popupComponent = _ref4.popupComponent,
|
|
120
|
+
_ref4$autoFocus = _ref4.autoFocus,
|
|
121
|
+
autoFocus = _ref4$autoFocus === void 0 ? true : _ref4$autoFocus,
|
|
122
|
+
_ref4$zIndex = _ref4.zIndex,
|
|
123
|
+
zIndex = _ref4$zIndex === void 0 ? defaultLayer : _ref4$zIndex,
|
|
124
|
+
_ref4$shouldUseCaptur = _ref4.shouldUseCaptureOnOutsideClick,
|
|
125
|
+
shouldUseCaptureOnOutsideClick = _ref4$shouldUseCaptur === void 0 ? false : _ref4$shouldUseCaptur,
|
|
126
|
+
_ref4$shouldRenderToP = _ref4.shouldRenderToParent,
|
|
127
|
+
shouldRenderToParent = _ref4$shouldRenderToP === void 0 ? false : _ref4$shouldRenderToP,
|
|
128
|
+
_ref4$shouldDisableFo = _ref4.shouldDisableFocusLock,
|
|
129
|
+
shouldDisableFocusLock = _ref4$shouldDisableFo === void 0 ? false : _ref4$shouldDisableFo;
|
|
130
|
+
useEnsureIsInsidePopup();
|
|
131
|
+
var isOpen = (0, _react.useContext)(IsOpenContext);
|
|
132
|
+
var id = (0, _react.useContext)(IdContext);
|
|
133
|
+
var triggerRef = (0, _react.useContext)(TriggerRefContext);
|
|
134
|
+
if (!isOpen) {
|
|
135
|
+
return null;
|
|
136
|
+
}
|
|
137
|
+
var popperWrapper = /*#__PURE__*/_react.default.createElement(_layering.UNSAFE_LAYERING, {
|
|
138
|
+
isDisabled: false
|
|
139
|
+
}, /*#__PURE__*/_react.default.createElement(_popperWrapper.default, {
|
|
140
|
+
content: children,
|
|
141
|
+
isOpen: isOpen,
|
|
142
|
+
placement: placement,
|
|
143
|
+
fallbackPlacements: fallbackPlacements,
|
|
144
|
+
boundary: boundary,
|
|
145
|
+
rootBoundary: rootBoundary,
|
|
146
|
+
shouldFlip: shouldFlip,
|
|
147
|
+
offset: offset,
|
|
148
|
+
popupComponent: popupComponent,
|
|
149
|
+
id: id,
|
|
150
|
+
testId: testId,
|
|
151
|
+
onClose: onClose,
|
|
152
|
+
autoFocus: autoFocus,
|
|
153
|
+
shouldUseCaptureOnOutsideClick: shouldUseCaptureOnOutsideClick,
|
|
154
|
+
shouldRenderToParent: shouldRenderToParent,
|
|
155
|
+
shouldDisableFocusLock: shouldDisableFocusLock,
|
|
156
|
+
triggerRef: triggerRef,
|
|
157
|
+
strategy: strategy
|
|
158
|
+
}));
|
|
159
|
+
if (shouldRenderToParent) {
|
|
160
|
+
return popperWrapper;
|
|
161
|
+
}
|
|
162
|
+
return /*#__PURE__*/_react.default.createElement(_portal.default, {
|
|
163
|
+
zIndex: zIndex
|
|
164
|
+
}, popperWrapper);
|
|
165
|
+
};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
Object.defineProperty(exports, "Popup", {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: function get() {
|
|
9
|
+
return _popup.Popup;
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
Object.defineProperty(exports, "PopupContent", {
|
|
13
|
+
enumerable: true,
|
|
14
|
+
get: function get() {
|
|
15
|
+
return _popup.PopupContent;
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
Object.defineProperty(exports, "PopupTrigger", {
|
|
19
|
+
enumerable: true,
|
|
20
|
+
get: function get() {
|
|
21
|
+
return _popup.PopupTrigger;
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
var _popup = require("../../compositional/popup");
|
package/dist/cjs/popup.js
CHANGED
|
@@ -8,12 +8,12 @@ exports.default = exports.Popup = void 0;
|
|
|
8
8
|
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
9
9
|
var _react = require("react");
|
|
10
10
|
var _react2 = require("@emotion/react");
|
|
11
|
-
var _memoizeOne = _interopRequireDefault(require("memoize-one"));
|
|
12
11
|
var _layering = require("@atlaskit/layering");
|
|
13
12
|
var _popper = require("@atlaskit/popper");
|
|
14
13
|
var _portal = _interopRequireDefault(require("@atlaskit/portal"));
|
|
15
14
|
var _constants = require("@atlaskit/theme/constants");
|
|
16
15
|
var _popperWrapper = _interopRequireDefault(require("./popper-wrapper"));
|
|
16
|
+
var _useGetMemoizedMergedTriggerRef = require("./use-get-memoized-merged-trigger-ref");
|
|
17
17
|
/* eslint-disable @repo/internal/react/require-jsdoc */
|
|
18
18
|
/** @jsx jsx */
|
|
19
19
|
|
|
@@ -50,33 +50,7 @@ var Popup = exports.Popup = /*#__PURE__*/(0, _react.memo)(function (_ref) {
|
|
|
50
50
|
_useState2 = (0, _slicedToArray2.default)(_useState, 2),
|
|
51
51
|
triggerRef = _useState2[0],
|
|
52
52
|
setTriggerRef = _useState2[1];
|
|
53
|
-
|
|
54
|
-
/*
|
|
55
|
-
* Get a memoized functional ref for use within this Popup's Trigger.
|
|
56
|
-
* This is still very volatile to change as `prop.isOpen` will regularly change, but it's better than nothing.
|
|
57
|
-
* This is memoized within our component as to not be shared across all Popup instances, just this one.
|
|
58
|
-
*
|
|
59
|
-
* This is complex because the inputs are split across three different scopes:
|
|
60
|
-
* - `props.isOpen`
|
|
61
|
-
* - `useState.setTriggerRef`
|
|
62
|
-
* - `renderProps.ref`
|
|
63
|
-
*/
|
|
64
|
-
var _useState3 = (0, _react.useState)(function () {
|
|
65
|
-
return (0, _memoizeOne.default)(function (ref, setTriggerRef, isOpen) {
|
|
66
|
-
return function (node) {
|
|
67
|
-
if (node && isOpen) {
|
|
68
|
-
if (typeof ref === 'function') {
|
|
69
|
-
ref(node);
|
|
70
|
-
} else if (ref) {
|
|
71
|
-
ref.current = node;
|
|
72
|
-
}
|
|
73
|
-
setTriggerRef(node);
|
|
74
|
-
}
|
|
75
|
-
};
|
|
76
|
-
});
|
|
77
|
-
}),
|
|
78
|
-
_useState4 = (0, _slicedToArray2.default)(_useState3, 1),
|
|
79
|
-
getMergedTriggerRef = _useState4[0];
|
|
53
|
+
var getMergedTriggerRef = (0, _useGetMemoizedMergedTriggerRef.useGetMemoizedMergedTriggerRef)();
|
|
80
54
|
var renderPopperWrapper = (0, _react2.jsx)(_layering.UNSAFE_LAYERING, {
|
|
81
55
|
isDisabled: false
|
|
82
56
|
}, (0, _react2.jsx)(_popperWrapper.default, {
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.useGetMemoizedMergedTriggerRef = void 0;
|
|
8
|
+
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
9
|
+
var _react = require("react");
|
|
10
|
+
var _memoizeOne = _interopRequireDefault(require("memoize-one"));
|
|
11
|
+
/*
|
|
12
|
+
* Get a memoized functional ref for use within a Popup's Trigger.
|
|
13
|
+
* This is still very volatile to change as `prop.isOpen` will regularly change, but it's better than nothing.
|
|
14
|
+
* This is memoized within a component as to not be shared across all Popup instances.
|
|
15
|
+
*
|
|
16
|
+
* This is complex because the inputs are split across three different scopes:
|
|
17
|
+
* - `props.isOpen`
|
|
18
|
+
* - `useState.setTriggerRef`
|
|
19
|
+
* - `renderProps.ref`
|
|
20
|
+
*/
|
|
21
|
+
var useGetMemoizedMergedTriggerRef = exports.useGetMemoizedMergedTriggerRef = function useGetMemoizedMergedTriggerRef() {
|
|
22
|
+
var _useState = (0, _react.useState)(function () {
|
|
23
|
+
return (0, _memoizeOne.default)(function (ref, setTriggerRef, isOpen) {
|
|
24
|
+
return function (node) {
|
|
25
|
+
if (node && isOpen) {
|
|
26
|
+
if (typeof ref === 'function') {
|
|
27
|
+
ref(node);
|
|
28
|
+
} else if (ref) {
|
|
29
|
+
ref.current = node;
|
|
30
|
+
}
|
|
31
|
+
setTriggerRef(node);
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
});
|
|
35
|
+
}),
|
|
36
|
+
_useState2 = (0, _slicedToArray2.default)(_useState, 1),
|
|
37
|
+
getMemoizedMergedTriggerRef = _useState2[0];
|
|
38
|
+
return getMemoizedMergedTriggerRef;
|
|
39
|
+
};
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
import React, { createContext, useContext, useState } from 'react';
|
|
2
|
+
import invariant from 'tiny-invariant';
|
|
3
|
+
import noop from '@atlaskit/ds-lib/noop';
|
|
4
|
+
import { UNSAFE_LAYERING } from '@atlaskit/layering';
|
|
5
|
+
import { Manager, Reference } from '@atlaskit/popper';
|
|
6
|
+
import Portal from '@atlaskit/portal';
|
|
7
|
+
import { layers } from '@atlaskit/theme/constants';
|
|
8
|
+
import PopperWrapper from '../popper-wrapper';
|
|
9
|
+
import { useGetMemoizedMergedTriggerRef } from '../use-get-memoized-merged-trigger-ref';
|
|
10
|
+
const IsOpenContext = /*#__PURE__*/createContext(false);
|
|
11
|
+
const IdContext = /*#__PURE__*/createContext(undefined);
|
|
12
|
+
const TriggerRefContext = /*#__PURE__*/createContext(null);
|
|
13
|
+
const SetTriggerRefContext = /*#__PURE__*/createContext(noop);
|
|
14
|
+
const EnsureIsInsidePopupContext = /*#__PURE__*/createContext(false);
|
|
15
|
+
|
|
16
|
+
// Used to ensure popup sub-components are used within a Popup
|
|
17
|
+
// and provide a useful error message if not.
|
|
18
|
+
const useEnsureIsInsidePopup = () => {
|
|
19
|
+
const context = useContext(EnsureIsInsidePopupContext);
|
|
20
|
+
invariant(context, 'PopupTrigger and PopupContent components must be used within a Popup');
|
|
21
|
+
};
|
|
22
|
+
/**
|
|
23
|
+
* __Popup__
|
|
24
|
+
*
|
|
25
|
+
* Popup is a composable component that provides the context for the trigger and content components.
|
|
26
|
+
*
|
|
27
|
+
* Usage example:
|
|
28
|
+
* ```jsx
|
|
29
|
+
* <Popup>
|
|
30
|
+
* <PopupTrigger>
|
|
31
|
+
* {(props) => (
|
|
32
|
+
* <button type="button" {...props}>Click me</button>
|
|
33
|
+
* )}
|
|
34
|
+
* </PopupTrigger>
|
|
35
|
+
* <PopupContent>
|
|
36
|
+
* {(props) => <div>Hello world</div>}
|
|
37
|
+
* </PopupContent>
|
|
38
|
+
* </Popup>
|
|
39
|
+
* ```
|
|
40
|
+
*/
|
|
41
|
+
export const Popup = ({
|
|
42
|
+
children,
|
|
43
|
+
id,
|
|
44
|
+
isOpen = false
|
|
45
|
+
}) => {
|
|
46
|
+
const [triggerRef, setTriggerRef] = useState(null);
|
|
47
|
+
return /*#__PURE__*/React.createElement(EnsureIsInsidePopupContext.Provider, {
|
|
48
|
+
value: true
|
|
49
|
+
}, /*#__PURE__*/React.createElement(IdContext.Provider, {
|
|
50
|
+
value: id
|
|
51
|
+
}, /*#__PURE__*/React.createElement(TriggerRefContext.Provider, {
|
|
52
|
+
value: triggerRef
|
|
53
|
+
}, /*#__PURE__*/React.createElement(SetTriggerRefContext.Provider, {
|
|
54
|
+
value: setTriggerRef
|
|
55
|
+
}, /*#__PURE__*/React.createElement(IsOpenContext.Provider, {
|
|
56
|
+
value: isOpen
|
|
57
|
+
}, /*#__PURE__*/React.createElement(Manager, null, children))))));
|
|
58
|
+
};
|
|
59
|
+
/**
|
|
60
|
+
* __Popup trigger__
|
|
61
|
+
*
|
|
62
|
+
* Popup trigger is the component that renders the trigger for the popup.
|
|
63
|
+
*
|
|
64
|
+
* It must be a child of the Popup component.
|
|
65
|
+
*/
|
|
66
|
+
export const PopupTrigger = ({
|
|
67
|
+
children
|
|
68
|
+
}) => {
|
|
69
|
+
useEnsureIsInsidePopup();
|
|
70
|
+
const isOpen = useContext(IsOpenContext);
|
|
71
|
+
const id = useContext(IdContext);
|
|
72
|
+
const setTriggerRef = useContext(SetTriggerRefContext);
|
|
73
|
+
const getMergedTriggerRef = useGetMemoizedMergedTriggerRef();
|
|
74
|
+
return /*#__PURE__*/React.createElement(Reference, null, ({
|
|
75
|
+
ref
|
|
76
|
+
}) => children({
|
|
77
|
+
ref: getMergedTriggerRef(ref, setTriggerRef, isOpen),
|
|
78
|
+
'aria-controls': id,
|
|
79
|
+
'aria-expanded': isOpen,
|
|
80
|
+
'aria-haspopup': true
|
|
81
|
+
}));
|
|
82
|
+
};
|
|
83
|
+
const defaultLayer = layers.layer();
|
|
84
|
+
/**
|
|
85
|
+
* __Popup content__
|
|
86
|
+
*
|
|
87
|
+
* Popup content is the component that renders the content of the popup.
|
|
88
|
+
*
|
|
89
|
+
* It must be a child of the Popup component.
|
|
90
|
+
*/
|
|
91
|
+
export const PopupContent = ({
|
|
92
|
+
children,
|
|
93
|
+
boundary,
|
|
94
|
+
offset,
|
|
95
|
+
strategy,
|
|
96
|
+
onClose,
|
|
97
|
+
testId,
|
|
98
|
+
rootBoundary = 'viewport',
|
|
99
|
+
shouldFlip = true,
|
|
100
|
+
placement = 'auto',
|
|
101
|
+
fallbackPlacements,
|
|
102
|
+
popupComponent,
|
|
103
|
+
autoFocus = true,
|
|
104
|
+
zIndex = defaultLayer,
|
|
105
|
+
shouldUseCaptureOnOutsideClick = false,
|
|
106
|
+
shouldRenderToParent = false,
|
|
107
|
+
shouldDisableFocusLock = false
|
|
108
|
+
}) => {
|
|
109
|
+
useEnsureIsInsidePopup();
|
|
110
|
+
const isOpen = useContext(IsOpenContext);
|
|
111
|
+
const id = useContext(IdContext);
|
|
112
|
+
const triggerRef = useContext(TriggerRefContext);
|
|
113
|
+
if (!isOpen) {
|
|
114
|
+
return null;
|
|
115
|
+
}
|
|
116
|
+
const popperWrapper = /*#__PURE__*/React.createElement(UNSAFE_LAYERING, {
|
|
117
|
+
isDisabled: false
|
|
118
|
+
}, /*#__PURE__*/React.createElement(PopperWrapper, {
|
|
119
|
+
content: children,
|
|
120
|
+
isOpen: isOpen,
|
|
121
|
+
placement: placement,
|
|
122
|
+
fallbackPlacements: fallbackPlacements,
|
|
123
|
+
boundary: boundary,
|
|
124
|
+
rootBoundary: rootBoundary,
|
|
125
|
+
shouldFlip: shouldFlip,
|
|
126
|
+
offset: offset,
|
|
127
|
+
popupComponent: popupComponent,
|
|
128
|
+
id: id,
|
|
129
|
+
testId: testId,
|
|
130
|
+
onClose: onClose,
|
|
131
|
+
autoFocus: autoFocus,
|
|
132
|
+
shouldUseCaptureOnOutsideClick: shouldUseCaptureOnOutsideClick,
|
|
133
|
+
shouldRenderToParent: shouldRenderToParent,
|
|
134
|
+
shouldDisableFocusLock: shouldDisableFocusLock,
|
|
135
|
+
triggerRef: triggerRef,
|
|
136
|
+
strategy: strategy
|
|
137
|
+
}));
|
|
138
|
+
if (shouldRenderToParent) {
|
|
139
|
+
return popperWrapper;
|
|
140
|
+
}
|
|
141
|
+
return /*#__PURE__*/React.createElement(Portal, {
|
|
142
|
+
zIndex: zIndex
|
|
143
|
+
}, popperWrapper);
|
|
144
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { Popup, PopupContent, PopupTrigger } from '../../compositional/popup';
|
package/dist/es2019/popup.js
CHANGED
|
@@ -2,12 +2,12 @@
|
|
|
2
2
|
/** @jsx jsx */
|
|
3
3
|
import { memo, useState } from 'react';
|
|
4
4
|
import { jsx } from '@emotion/react';
|
|
5
|
-
import memoizeOne from 'memoize-one';
|
|
6
5
|
import { UNSAFE_LAYERING } from '@atlaskit/layering';
|
|
7
6
|
import { Manager, Reference } from '@atlaskit/popper';
|
|
8
7
|
import Portal from '@atlaskit/portal';
|
|
9
8
|
import { layers } from '@atlaskit/theme/constants';
|
|
10
9
|
import PopperWrapper from './popper-wrapper';
|
|
10
|
+
import { useGetMemoizedMergedTriggerRef } from './use-get-memoized-merged-trigger-ref';
|
|
11
11
|
const defaultLayer = layers.layer();
|
|
12
12
|
export const Popup = /*#__PURE__*/memo(({
|
|
13
13
|
isOpen,
|
|
@@ -31,29 +31,7 @@ export const Popup = /*#__PURE__*/memo(({
|
|
|
31
31
|
strategy
|
|
32
32
|
}) => {
|
|
33
33
|
const [triggerRef, setTriggerRef] = useState(null);
|
|
34
|
-
|
|
35
|
-
/*
|
|
36
|
-
* Get a memoized functional ref for use within this Popup's Trigger.
|
|
37
|
-
* This is still very volatile to change as `prop.isOpen` will regularly change, but it's better than nothing.
|
|
38
|
-
* This is memoized within our component as to not be shared across all Popup instances, just this one.
|
|
39
|
-
*
|
|
40
|
-
* This is complex because the inputs are split across three different scopes:
|
|
41
|
-
* - `props.isOpen`
|
|
42
|
-
* - `useState.setTriggerRef`
|
|
43
|
-
* - `renderProps.ref`
|
|
44
|
-
*/
|
|
45
|
-
const [getMergedTriggerRef] = useState(() => memoizeOne((ref, setTriggerRef, isOpen) => {
|
|
46
|
-
return node => {
|
|
47
|
-
if (node && isOpen) {
|
|
48
|
-
if (typeof ref === 'function') {
|
|
49
|
-
ref(node);
|
|
50
|
-
} else if (ref) {
|
|
51
|
-
ref.current = node;
|
|
52
|
-
}
|
|
53
|
-
setTriggerRef(node);
|
|
54
|
-
}
|
|
55
|
-
};
|
|
56
|
-
}));
|
|
34
|
+
const getMergedTriggerRef = useGetMemoizedMergedTriggerRef();
|
|
57
35
|
const renderPopperWrapper = jsx(UNSAFE_LAYERING, {
|
|
58
36
|
isDisabled: false
|
|
59
37
|
}, jsx(PopperWrapper, {
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { useState } from 'react';
|
|
2
|
+
import memoizeOne from 'memoize-one';
|
|
3
|
+
|
|
4
|
+
/*
|
|
5
|
+
* Get a memoized functional ref for use within a Popup's Trigger.
|
|
6
|
+
* This is still very volatile to change as `prop.isOpen` will regularly change, but it's better than nothing.
|
|
7
|
+
* This is memoized within a component as to not be shared across all Popup instances.
|
|
8
|
+
*
|
|
9
|
+
* This is complex because the inputs are split across three different scopes:
|
|
10
|
+
* - `props.isOpen`
|
|
11
|
+
* - `useState.setTriggerRef`
|
|
12
|
+
* - `renderProps.ref`
|
|
13
|
+
*/
|
|
14
|
+
export const useGetMemoizedMergedTriggerRef = () => {
|
|
15
|
+
const [getMemoizedMergedTriggerRef] = useState(() => memoizeOne((ref, setTriggerRef, isOpen) => {
|
|
16
|
+
return node => {
|
|
17
|
+
if (node && isOpen) {
|
|
18
|
+
if (typeof ref === 'function') {
|
|
19
|
+
ref(node);
|
|
20
|
+
} else if (ref) {
|
|
21
|
+
ref.current = node;
|
|
22
|
+
}
|
|
23
|
+
setTriggerRef(node);
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
}));
|
|
27
|
+
return getMemoizedMergedTriggerRef;
|
|
28
|
+
};
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
2
|
+
import React, { createContext, useContext, useState } from 'react';
|
|
3
|
+
import invariant from 'tiny-invariant';
|
|
4
|
+
import noop from '@atlaskit/ds-lib/noop';
|
|
5
|
+
import { UNSAFE_LAYERING } from '@atlaskit/layering';
|
|
6
|
+
import { Manager, Reference } from '@atlaskit/popper';
|
|
7
|
+
import Portal from '@atlaskit/portal';
|
|
8
|
+
import { layers } from '@atlaskit/theme/constants';
|
|
9
|
+
import PopperWrapper from '../popper-wrapper';
|
|
10
|
+
import { useGetMemoizedMergedTriggerRef } from '../use-get-memoized-merged-trigger-ref';
|
|
11
|
+
var IsOpenContext = /*#__PURE__*/createContext(false);
|
|
12
|
+
var IdContext = /*#__PURE__*/createContext(undefined);
|
|
13
|
+
var TriggerRefContext = /*#__PURE__*/createContext(null);
|
|
14
|
+
var SetTriggerRefContext = /*#__PURE__*/createContext(noop);
|
|
15
|
+
var EnsureIsInsidePopupContext = /*#__PURE__*/createContext(false);
|
|
16
|
+
|
|
17
|
+
// Used to ensure popup sub-components are used within a Popup
|
|
18
|
+
// and provide a useful error message if not.
|
|
19
|
+
var useEnsureIsInsidePopup = function useEnsureIsInsidePopup() {
|
|
20
|
+
var context = useContext(EnsureIsInsidePopupContext);
|
|
21
|
+
invariant(context, 'PopupTrigger and PopupContent components must be used within a Popup');
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* __Popup__
|
|
25
|
+
*
|
|
26
|
+
* Popup is a composable component that provides the context for the trigger and content components.
|
|
27
|
+
*
|
|
28
|
+
* Usage example:
|
|
29
|
+
* ```jsx
|
|
30
|
+
* <Popup>
|
|
31
|
+
* <PopupTrigger>
|
|
32
|
+
* {(props) => (
|
|
33
|
+
* <button type="button" {...props}>Click me</button>
|
|
34
|
+
* )}
|
|
35
|
+
* </PopupTrigger>
|
|
36
|
+
* <PopupContent>
|
|
37
|
+
* {(props) => <div>Hello world</div>}
|
|
38
|
+
* </PopupContent>
|
|
39
|
+
* </Popup>
|
|
40
|
+
* ```
|
|
41
|
+
*/
|
|
42
|
+
export var Popup = function Popup(_ref) {
|
|
43
|
+
var children = _ref.children,
|
|
44
|
+
id = _ref.id,
|
|
45
|
+
_ref$isOpen = _ref.isOpen,
|
|
46
|
+
isOpen = _ref$isOpen === void 0 ? false : _ref$isOpen;
|
|
47
|
+
var _useState = useState(null),
|
|
48
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
49
|
+
triggerRef = _useState2[0],
|
|
50
|
+
setTriggerRef = _useState2[1];
|
|
51
|
+
return /*#__PURE__*/React.createElement(EnsureIsInsidePopupContext.Provider, {
|
|
52
|
+
value: true
|
|
53
|
+
}, /*#__PURE__*/React.createElement(IdContext.Provider, {
|
|
54
|
+
value: id
|
|
55
|
+
}, /*#__PURE__*/React.createElement(TriggerRefContext.Provider, {
|
|
56
|
+
value: triggerRef
|
|
57
|
+
}, /*#__PURE__*/React.createElement(SetTriggerRefContext.Provider, {
|
|
58
|
+
value: setTriggerRef
|
|
59
|
+
}, /*#__PURE__*/React.createElement(IsOpenContext.Provider, {
|
|
60
|
+
value: isOpen
|
|
61
|
+
}, /*#__PURE__*/React.createElement(Manager, null, children))))));
|
|
62
|
+
};
|
|
63
|
+
/**
|
|
64
|
+
* __Popup trigger__
|
|
65
|
+
*
|
|
66
|
+
* Popup trigger is the component that renders the trigger for the popup.
|
|
67
|
+
*
|
|
68
|
+
* It must be a child of the Popup component.
|
|
69
|
+
*/
|
|
70
|
+
export var PopupTrigger = function PopupTrigger(_ref2) {
|
|
71
|
+
var children = _ref2.children;
|
|
72
|
+
useEnsureIsInsidePopup();
|
|
73
|
+
var isOpen = useContext(IsOpenContext);
|
|
74
|
+
var id = useContext(IdContext);
|
|
75
|
+
var setTriggerRef = useContext(SetTriggerRefContext);
|
|
76
|
+
var getMergedTriggerRef = useGetMemoizedMergedTriggerRef();
|
|
77
|
+
return /*#__PURE__*/React.createElement(Reference, null, function (_ref3) {
|
|
78
|
+
var ref = _ref3.ref;
|
|
79
|
+
return children({
|
|
80
|
+
ref: getMergedTriggerRef(ref, setTriggerRef, isOpen),
|
|
81
|
+
'aria-controls': id,
|
|
82
|
+
'aria-expanded': isOpen,
|
|
83
|
+
'aria-haspopup': true
|
|
84
|
+
});
|
|
85
|
+
});
|
|
86
|
+
};
|
|
87
|
+
var defaultLayer = layers.layer();
|
|
88
|
+
/**
|
|
89
|
+
* __Popup content__
|
|
90
|
+
*
|
|
91
|
+
* Popup content is the component that renders the content of the popup.
|
|
92
|
+
*
|
|
93
|
+
* It must be a child of the Popup component.
|
|
94
|
+
*/
|
|
95
|
+
export var PopupContent = function PopupContent(_ref4) {
|
|
96
|
+
var children = _ref4.children,
|
|
97
|
+
boundary = _ref4.boundary,
|
|
98
|
+
offset = _ref4.offset,
|
|
99
|
+
strategy = _ref4.strategy,
|
|
100
|
+
onClose = _ref4.onClose,
|
|
101
|
+
testId = _ref4.testId,
|
|
102
|
+
_ref4$rootBoundary = _ref4.rootBoundary,
|
|
103
|
+
rootBoundary = _ref4$rootBoundary === void 0 ? 'viewport' : _ref4$rootBoundary,
|
|
104
|
+
_ref4$shouldFlip = _ref4.shouldFlip,
|
|
105
|
+
shouldFlip = _ref4$shouldFlip === void 0 ? true : _ref4$shouldFlip,
|
|
106
|
+
_ref4$placement = _ref4.placement,
|
|
107
|
+
placement = _ref4$placement === void 0 ? 'auto' : _ref4$placement,
|
|
108
|
+
fallbackPlacements = _ref4.fallbackPlacements,
|
|
109
|
+
popupComponent = _ref4.popupComponent,
|
|
110
|
+
_ref4$autoFocus = _ref4.autoFocus,
|
|
111
|
+
autoFocus = _ref4$autoFocus === void 0 ? true : _ref4$autoFocus,
|
|
112
|
+
_ref4$zIndex = _ref4.zIndex,
|
|
113
|
+
zIndex = _ref4$zIndex === void 0 ? defaultLayer : _ref4$zIndex,
|
|
114
|
+
_ref4$shouldUseCaptur = _ref4.shouldUseCaptureOnOutsideClick,
|
|
115
|
+
shouldUseCaptureOnOutsideClick = _ref4$shouldUseCaptur === void 0 ? false : _ref4$shouldUseCaptur,
|
|
116
|
+
_ref4$shouldRenderToP = _ref4.shouldRenderToParent,
|
|
117
|
+
shouldRenderToParent = _ref4$shouldRenderToP === void 0 ? false : _ref4$shouldRenderToP,
|
|
118
|
+
_ref4$shouldDisableFo = _ref4.shouldDisableFocusLock,
|
|
119
|
+
shouldDisableFocusLock = _ref4$shouldDisableFo === void 0 ? false : _ref4$shouldDisableFo;
|
|
120
|
+
useEnsureIsInsidePopup();
|
|
121
|
+
var isOpen = useContext(IsOpenContext);
|
|
122
|
+
var id = useContext(IdContext);
|
|
123
|
+
var triggerRef = useContext(TriggerRefContext);
|
|
124
|
+
if (!isOpen) {
|
|
125
|
+
return null;
|
|
126
|
+
}
|
|
127
|
+
var popperWrapper = /*#__PURE__*/React.createElement(UNSAFE_LAYERING, {
|
|
128
|
+
isDisabled: false
|
|
129
|
+
}, /*#__PURE__*/React.createElement(PopperWrapper, {
|
|
130
|
+
content: children,
|
|
131
|
+
isOpen: isOpen,
|
|
132
|
+
placement: placement,
|
|
133
|
+
fallbackPlacements: fallbackPlacements,
|
|
134
|
+
boundary: boundary,
|
|
135
|
+
rootBoundary: rootBoundary,
|
|
136
|
+
shouldFlip: shouldFlip,
|
|
137
|
+
offset: offset,
|
|
138
|
+
popupComponent: popupComponent,
|
|
139
|
+
id: id,
|
|
140
|
+
testId: testId,
|
|
141
|
+
onClose: onClose,
|
|
142
|
+
autoFocus: autoFocus,
|
|
143
|
+
shouldUseCaptureOnOutsideClick: shouldUseCaptureOnOutsideClick,
|
|
144
|
+
shouldRenderToParent: shouldRenderToParent,
|
|
145
|
+
shouldDisableFocusLock: shouldDisableFocusLock,
|
|
146
|
+
triggerRef: triggerRef,
|
|
147
|
+
strategy: strategy
|
|
148
|
+
}));
|
|
149
|
+
if (shouldRenderToParent) {
|
|
150
|
+
return popperWrapper;
|
|
151
|
+
}
|
|
152
|
+
return /*#__PURE__*/React.createElement(Portal, {
|
|
153
|
+
zIndex: zIndex
|
|
154
|
+
}, popperWrapper);
|
|
155
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { Popup, PopupContent, PopupTrigger } from '../../compositional/popup';
|
package/dist/esm/popup.js
CHANGED
|
@@ -3,12 +3,12 @@ import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
|
3
3
|
/** @jsx jsx */
|
|
4
4
|
import { memo, useState } from 'react';
|
|
5
5
|
import { jsx } from '@emotion/react';
|
|
6
|
-
import memoizeOne from 'memoize-one';
|
|
7
6
|
import { UNSAFE_LAYERING } from '@atlaskit/layering';
|
|
8
7
|
import { Manager, Reference } from '@atlaskit/popper';
|
|
9
8
|
import Portal from '@atlaskit/portal';
|
|
10
9
|
import { layers } from '@atlaskit/theme/constants';
|
|
11
10
|
import PopperWrapper from './popper-wrapper';
|
|
11
|
+
import { useGetMemoizedMergedTriggerRef } from './use-get-memoized-merged-trigger-ref';
|
|
12
12
|
var defaultLayer = layers.layer();
|
|
13
13
|
export var Popup = /*#__PURE__*/memo(function (_ref) {
|
|
14
14
|
var isOpen = _ref.isOpen,
|
|
@@ -42,33 +42,7 @@ export var Popup = /*#__PURE__*/memo(function (_ref) {
|
|
|
42
42
|
_useState2 = _slicedToArray(_useState, 2),
|
|
43
43
|
triggerRef = _useState2[0],
|
|
44
44
|
setTriggerRef = _useState2[1];
|
|
45
|
-
|
|
46
|
-
/*
|
|
47
|
-
* Get a memoized functional ref for use within this Popup's Trigger.
|
|
48
|
-
* This is still very volatile to change as `prop.isOpen` will regularly change, but it's better than nothing.
|
|
49
|
-
* This is memoized within our component as to not be shared across all Popup instances, just this one.
|
|
50
|
-
*
|
|
51
|
-
* This is complex because the inputs are split across three different scopes:
|
|
52
|
-
* - `props.isOpen`
|
|
53
|
-
* - `useState.setTriggerRef`
|
|
54
|
-
* - `renderProps.ref`
|
|
55
|
-
*/
|
|
56
|
-
var _useState3 = useState(function () {
|
|
57
|
-
return memoizeOne(function (ref, setTriggerRef, isOpen) {
|
|
58
|
-
return function (node) {
|
|
59
|
-
if (node && isOpen) {
|
|
60
|
-
if (typeof ref === 'function') {
|
|
61
|
-
ref(node);
|
|
62
|
-
} else if (ref) {
|
|
63
|
-
ref.current = node;
|
|
64
|
-
}
|
|
65
|
-
setTriggerRef(node);
|
|
66
|
-
}
|
|
67
|
-
};
|
|
68
|
-
});
|
|
69
|
-
}),
|
|
70
|
-
_useState4 = _slicedToArray(_useState3, 1),
|
|
71
|
-
getMergedTriggerRef = _useState4[0];
|
|
45
|
+
var getMergedTriggerRef = useGetMemoizedMergedTriggerRef();
|
|
72
46
|
var renderPopperWrapper = jsx(UNSAFE_LAYERING, {
|
|
73
47
|
isDisabled: false
|
|
74
48
|
}, jsx(PopperWrapper, {
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
2
|
+
import { useState } from 'react';
|
|
3
|
+
import memoizeOne from 'memoize-one';
|
|
4
|
+
|
|
5
|
+
/*
|
|
6
|
+
* Get a memoized functional ref for use within a Popup's Trigger.
|
|
7
|
+
* This is still very volatile to change as `prop.isOpen` will regularly change, but it's better than nothing.
|
|
8
|
+
* This is memoized within a component as to not be shared across all Popup instances.
|
|
9
|
+
*
|
|
10
|
+
* This is complex because the inputs are split across three different scopes:
|
|
11
|
+
* - `props.isOpen`
|
|
12
|
+
* - `useState.setTriggerRef`
|
|
13
|
+
* - `renderProps.ref`
|
|
14
|
+
*/
|
|
15
|
+
export var useGetMemoizedMergedTriggerRef = function useGetMemoizedMergedTriggerRef() {
|
|
16
|
+
var _useState = useState(function () {
|
|
17
|
+
return memoizeOne(function (ref, setTriggerRef, isOpen) {
|
|
18
|
+
return function (node) {
|
|
19
|
+
if (node && isOpen) {
|
|
20
|
+
if (typeof ref === 'function') {
|
|
21
|
+
ref(node);
|
|
22
|
+
} else if (ref) {
|
|
23
|
+
ref.current = node;
|
|
24
|
+
}
|
|
25
|
+
setTriggerRef(node);
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
});
|
|
29
|
+
}),
|
|
30
|
+
_useState2 = _slicedToArray(_useState, 1),
|
|
31
|
+
getMemoizedMergedTriggerRef = _useState2[0];
|
|
32
|
+
return getMemoizedMergedTriggerRef;
|
|
33
|
+
};
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { type ContentProps, type PopupProps as LegacyPopupProps, type TriggerProps } from '../types';
|
|
3
|
+
export type PopupProps = {
|
|
4
|
+
children: React.ReactNode;
|
|
5
|
+
isOpen?: boolean;
|
|
6
|
+
id?: string;
|
|
7
|
+
};
|
|
8
|
+
/**
|
|
9
|
+
* __Popup__
|
|
10
|
+
*
|
|
11
|
+
* Popup is a composable component that provides the context for the trigger and content components.
|
|
12
|
+
*
|
|
13
|
+
* Usage example:
|
|
14
|
+
* ```jsx
|
|
15
|
+
* <Popup>
|
|
16
|
+
* <PopupTrigger>
|
|
17
|
+
* {(props) => (
|
|
18
|
+
* <button type="button" {...props}>Click me</button>
|
|
19
|
+
* )}
|
|
20
|
+
* </PopupTrigger>
|
|
21
|
+
* <PopupContent>
|
|
22
|
+
* {(props) => <div>Hello world</div>}
|
|
23
|
+
* </PopupContent>
|
|
24
|
+
* </Popup>
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
export declare const Popup: ({ children, id, isOpen }: PopupProps) => JSX.Element;
|
|
28
|
+
export type PopupTriggerProps = {
|
|
29
|
+
children: (props: TriggerProps) => React.ReactNode;
|
|
30
|
+
};
|
|
31
|
+
/**
|
|
32
|
+
* __Popup trigger__
|
|
33
|
+
*
|
|
34
|
+
* Popup trigger is the component that renders the trigger for the popup.
|
|
35
|
+
*
|
|
36
|
+
* It must be a child of the Popup component.
|
|
37
|
+
*/
|
|
38
|
+
export declare const PopupTrigger: ({ children }: PopupTriggerProps) => JSX.Element;
|
|
39
|
+
export type PopupContentProps = Pick<LegacyPopupProps, 'boundary' | 'offset' | 'strategy' | 'onClose' | 'testId' | 'placement' | 'fallbackPlacements' | 'popupComponent' | 'shouldFlip' | 'rootBoundary' | 'autoFocus' | 'shouldUseCaptureOnOutsideClick' | 'shouldRenderToParent' | 'shouldDisableFocusLock' | 'zIndex'> & {
|
|
40
|
+
children: (props: ContentProps) => React.ReactNode;
|
|
41
|
+
};
|
|
42
|
+
/**
|
|
43
|
+
* __Popup content__
|
|
44
|
+
*
|
|
45
|
+
* Popup content is the component that renders the content of the popup.
|
|
46
|
+
*
|
|
47
|
+
* It must be a child of the Popup component.
|
|
48
|
+
*/
|
|
49
|
+
export declare const PopupContent: ({ children, boundary, offset, strategy, onClose, testId, rootBoundary, shouldFlip, placement, fallbackPlacements, popupComponent, autoFocus, zIndex, shouldUseCaptureOnOutsideClick, shouldRenderToParent, shouldDisableFocusLock, }: PopupContentProps) => JSX.Element | null;
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { Dispatch, SetStateAction } from 'react';
|
|
2
|
+
export declare const useGetMemoizedMergedTriggerRef: () => import("memoize-one").MemoizedFn<(ref: React.RefCallback<HTMLElement> | React.MutableRefObject<HTMLElement> | null, setTriggerRef: Dispatch<SetStateAction<HTMLElement | null>>, isOpen: boolean) => (node: HTMLElement | null) => void>;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { type ContentProps, type PopupProps as LegacyPopupProps, type TriggerProps } from '../types';
|
|
3
|
+
export type PopupProps = {
|
|
4
|
+
children: React.ReactNode;
|
|
5
|
+
isOpen?: boolean;
|
|
6
|
+
id?: string;
|
|
7
|
+
};
|
|
8
|
+
/**
|
|
9
|
+
* __Popup__
|
|
10
|
+
*
|
|
11
|
+
* Popup is a composable component that provides the context for the trigger and content components.
|
|
12
|
+
*
|
|
13
|
+
* Usage example:
|
|
14
|
+
* ```jsx
|
|
15
|
+
* <Popup>
|
|
16
|
+
* <PopupTrigger>
|
|
17
|
+
* {(props) => (
|
|
18
|
+
* <button type="button" {...props}>Click me</button>
|
|
19
|
+
* )}
|
|
20
|
+
* </PopupTrigger>
|
|
21
|
+
* <PopupContent>
|
|
22
|
+
* {(props) => <div>Hello world</div>}
|
|
23
|
+
* </PopupContent>
|
|
24
|
+
* </Popup>
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
export declare const Popup: ({ children, id, isOpen }: PopupProps) => JSX.Element;
|
|
28
|
+
export type PopupTriggerProps = {
|
|
29
|
+
children: (props: TriggerProps) => React.ReactNode;
|
|
30
|
+
};
|
|
31
|
+
/**
|
|
32
|
+
* __Popup trigger__
|
|
33
|
+
*
|
|
34
|
+
* Popup trigger is the component that renders the trigger for the popup.
|
|
35
|
+
*
|
|
36
|
+
* It must be a child of the Popup component.
|
|
37
|
+
*/
|
|
38
|
+
export declare const PopupTrigger: ({ children }: PopupTriggerProps) => JSX.Element;
|
|
39
|
+
export type PopupContentProps = Pick<LegacyPopupProps, 'boundary' | 'offset' | 'strategy' | 'onClose' | 'testId' | 'placement' | 'fallbackPlacements' | 'popupComponent' | 'shouldFlip' | 'rootBoundary' | 'autoFocus' | 'shouldUseCaptureOnOutsideClick' | 'shouldRenderToParent' | 'shouldDisableFocusLock' | 'zIndex'> & {
|
|
40
|
+
children: (props: ContentProps) => React.ReactNode;
|
|
41
|
+
};
|
|
42
|
+
/**
|
|
43
|
+
* __Popup content__
|
|
44
|
+
*
|
|
45
|
+
* Popup content is the component that renders the content of the popup.
|
|
46
|
+
*
|
|
47
|
+
* It must be a child of the Popup component.
|
|
48
|
+
*/
|
|
49
|
+
export declare const PopupContent: ({ children, boundary, offset, strategy, onClose, testId, rootBoundary, shouldFlip, placement, fallbackPlacements, popupComponent, autoFocus, zIndex, shouldUseCaptureOnOutsideClick, shouldRenderToParent, shouldDisableFocusLock, }: PopupContentProps) => JSX.Element | null;
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { Dispatch, SetStateAction } from 'react';
|
|
2
|
+
export declare const useGetMemoizedMergedTriggerRef: () => import("memoize-one").MemoizedFn<(ref: React.RefCallback<HTMLElement> | React.MutableRefObject<HTMLElement> | null, setTriggerRef: Dispatch<SetStateAction<HTMLElement | null>>, isOpen: boolean) => (node: HTMLElement | null) => void>;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@atlaskit/popup/experimental",
|
|
3
|
+
"main": "../dist/cjs/entry-points/experimental/compositional.js",
|
|
4
|
+
"module": "../dist/esm/entry-points/experimental/compositional.js",
|
|
5
|
+
"module:es2019": "../dist/es2019/entry-points/experimental/compositional.js",
|
|
6
|
+
"sideEffects": false,
|
|
7
|
+
"types": "../dist/types/entry-points/experimental/compositional.d.ts",
|
|
8
|
+
"typesVersions": {
|
|
9
|
+
">=4.5 <5.4": {
|
|
10
|
+
"*": [
|
|
11
|
+
"../dist/types-ts4.5/entry-points/experimental/compositional.d.ts"
|
|
12
|
+
]
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaskit/popup",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.16.0",
|
|
4
4
|
"description": "A popup displays brief content in an overlay.",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"registry": "https://registry.npmjs.org/"
|
|
@@ -24,7 +24,8 @@
|
|
|
24
24
|
"atlaskit:src": "src/index.tsx",
|
|
25
25
|
"af:exports": {
|
|
26
26
|
".": "./src/index.tsx",
|
|
27
|
-
"./types": "./src/types.tsx"
|
|
27
|
+
"./types": "./src/types.tsx",
|
|
28
|
+
"./experimental": "./src/entry-points/experimental/compositional.tsx"
|
|
28
29
|
},
|
|
29
30
|
"atlassian": {
|
|
30
31
|
"team": "Design System Team",
|
|
@@ -45,12 +46,13 @@
|
|
|
45
46
|
"@atlaskit/popper": "^5.5.0",
|
|
46
47
|
"@atlaskit/portal": "^4.4.0",
|
|
47
48
|
"@atlaskit/theme": "^12.7.0",
|
|
48
|
-
"@atlaskit/tokens": "^1.
|
|
49
|
+
"@atlaskit/tokens": "^1.45.0",
|
|
49
50
|
"@babel/runtime": "^7.0.0",
|
|
50
51
|
"@emotion/react": "^11.7.1",
|
|
51
52
|
"bind-event-listener": "^3.0.0",
|
|
52
53
|
"focus-trap": "^2.4.5",
|
|
53
|
-
"memoize-one": "^6.0.0"
|
|
54
|
+
"memoize-one": "^6.0.0",
|
|
55
|
+
"tiny-invariant": "^1.2.0"
|
|
54
56
|
},
|
|
55
57
|
"peerDependencies": {
|
|
56
58
|
"react": "^16.8.0 || ^17.0.0 || ~18.2.0",
|
|
@@ -68,6 +70,7 @@
|
|
|
68
70
|
"@atlassian/feature-flags-test-utils": "*",
|
|
69
71
|
"@testing-library/dom": "^8.17.1",
|
|
70
72
|
"@testing-library/react": "^12.1.5",
|
|
73
|
+
"@testing-library/user-event": "^14.4.3",
|
|
71
74
|
"ast-types": "^0.13.3",
|
|
72
75
|
"jscodeshift": "^0.13.0",
|
|
73
76
|
"raf-stub": "^2.0.1",
|