@primer/components 0.0.0-2021109205720 → 0.0.0-2021109214331
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 +5 -3
- package/dist/browser.esm.js +178 -178
- package/dist/browser.esm.js.map +1 -1
- package/dist/browser.umd.js +179 -179
- package/dist/browser.umd.js.map +1 -1
- package/lib/Overlay.js +7 -1
- package/lib/Portal/Portal.js +3 -2
- package/lib/hooks/useAnchoredPosition.js +3 -2
- package/lib/hooks/useCombinedRefs.d.ts +2 -2
- package/lib/hooks/useCombinedRefs.js +4 -6
- package/lib/hooks/useResizeObserver.js +2 -2
- package/lib/utils/useIsomorphicLayoutEffect.d.ts +3 -0
- package/lib/utils/useIsomorphicLayoutEffect.js +12 -0
- package/lib-esm/Overlay.js +6 -1
- package/lib-esm/Portal/Portal.js +2 -1
- package/lib-esm/hooks/useAnchoredPosition.js +2 -1
- package/lib-esm/hooks/useCombinedRefs.d.ts +2 -2
- package/lib-esm/hooks/useCombinedRefs.js +3 -2
- package/lib-esm/hooks/useResizeObserver.js +2 -2
- package/lib-esm/utils/useIsomorphicLayoutEffect.d.ts +3 -0
- package/lib-esm/utils/useIsomorphicLayoutEffect.js +3 -0
- package/package.json +1 -1
package/lib/Overlay.js
CHANGED
@@ -11,6 +11,8 @@ var _react = _interopRequireWildcard(require("react"));
|
|
11
11
|
|
12
12
|
var _constants = require("./constants");
|
13
13
|
|
14
|
+
var _useIsomorphicLayoutEffect = _interopRequireDefault(require("./utils/useIsomorphicLayoutEffect"));
|
15
|
+
|
14
16
|
var _hooks = require("./hooks");
|
15
17
|
|
16
18
|
var _Portal = _interopRequireDefault(require("./Portal"));
|
@@ -116,6 +118,7 @@ const Overlay = /*#__PURE__*/_react.default.forwardRef(({
|
|
116
118
|
preventFocusOnOpen,
|
117
119
|
...rest
|
118
120
|
}, forwardedRef) => {
|
121
|
+
debugger;
|
119
122
|
const overlayRef = (0, _react.useRef)(null);
|
120
123
|
const combinedRef = (0, _useCombinedRefs.useCombinedRefs)(overlayRef, forwardedRef);
|
121
124
|
const {
|
@@ -135,13 +138,16 @@ const Overlay = /*#__PURE__*/_react.default.forwardRef(({
|
|
135
138
|
(0, _react.useEffect)(() => {
|
136
139
|
var _combinedRef$current;
|
137
140
|
|
141
|
+
debugger;
|
142
|
+
|
138
143
|
if (height === 'initial' && (_combinedRef$current = combinedRef.current) !== null && _combinedRef$current !== void 0 && _combinedRef$current.clientHeight) {
|
139
144
|
combinedRef.current.style.height = `${combinedRef.current.clientHeight}px`;
|
140
145
|
}
|
141
146
|
}, [height, combinedRef]);
|
142
|
-
(0,
|
147
|
+
(0, _useIsomorphicLayoutEffect.default)(() => {
|
143
148
|
var _overlayRef$current;
|
144
149
|
|
150
|
+
debugger;
|
145
151
|
const {
|
146
152
|
x,
|
147
153
|
y
|
package/lib/Portal/Portal.js
CHANGED
@@ -10,6 +10,8 @@ var _react = _interopRequireDefault(require("react"));
|
|
10
10
|
|
11
11
|
var _reactDom = require("react-dom");
|
12
12
|
|
13
|
+
var _useIsomorphicLayoutEffect = _interopRequireDefault(require("../utils/useIsomorphicLayoutEffect"));
|
14
|
+
|
13
15
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
14
16
|
|
15
17
|
const PRIMER_PORTAL_ROOT_ID = '__primerPortalRoot__';
|
@@ -72,7 +74,7 @@ const Portal = ({
|
|
72
74
|
|
73
75
|
const elementRef = _react.default.useRef(hostElement);
|
74
76
|
|
75
|
-
|
77
|
+
(0, _useIsomorphicLayoutEffect.default)(() => {
|
76
78
|
let containerName = _containerName;
|
77
79
|
|
78
80
|
if (containerName === undefined) {
|
@@ -93,7 +95,6 @@ const Portal = ({
|
|
93
95
|
parentElement.removeChild(element);
|
94
96
|
}; // eslint-disable-next-line react-hooks/exhaustive-deps
|
95
97
|
}, [elementRef]);
|
96
|
-
|
97
98
|
return /*#__PURE__*/(0, _reactDom.createPortal)(children, elementRef.current);
|
98
99
|
};
|
99
100
|
|
@@ -13,6 +13,8 @@ var _useProvidedRefOrCreate = require("./useProvidedRefOrCreate");
|
|
13
13
|
|
14
14
|
var _useResizeObserver = require("./useResizeObserver");
|
15
15
|
|
16
|
+
var _useIsomorphicLayoutEffect = _interopRequireDefault(require("../utils/useIsomorphicLayoutEffect"));
|
17
|
+
|
16
18
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
17
19
|
|
18
20
|
/**
|
@@ -39,8 +41,7 @@ function useAnchoredPosition(settings, dependencies = []) {
|
|
39
41
|
}, // eslint-disable-next-line react-hooks/exhaustive-deps
|
40
42
|
[floatingElementRef, anchorElementRef, ...dependencies]);
|
41
43
|
|
42
|
-
|
43
|
-
|
44
|
+
(0, _useIsomorphicLayoutEffect.default)(updatePosition, [updatePosition]);
|
44
45
|
(0, _useResizeObserver.useResizeObserver)(updatePosition);
|
45
46
|
return {
|
46
47
|
floatingElementRef,
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import
|
1
|
+
import { ForwardedRef } from 'react';
|
2
2
|
/**
|
3
3
|
* Creates a ref by combining multiple constituent refs. The ref returned by this hook
|
4
4
|
* should be passed as the ref for the element that needs to be shared. This is
|
@@ -7,4 +7,4 @@ import React, { ForwardedRef } from 'react';
|
|
7
7
|
* though, as it breaks encapsulation.
|
8
8
|
* @param refs
|
9
9
|
*/
|
10
|
-
export declare function useCombinedRefs<T>(...refs: (ForwardedRef<T> | null | undefined)[]):
|
10
|
+
export declare function useCombinedRefs<T>(...refs: (ForwardedRef<T> | null | undefined)[]): import("react").MutableRefObject<T | null>;
|
@@ -5,11 +5,11 @@ Object.defineProperty(exports, "__esModule", {
|
|
5
5
|
});
|
6
6
|
exports.useCombinedRefs = useCombinedRefs;
|
7
7
|
|
8
|
-
var _react =
|
8
|
+
var _react = require("react");
|
9
9
|
|
10
|
-
|
10
|
+
var _useIsomorphicLayoutEffect = _interopRequireDefault(require("../utils/useIsomorphicLayoutEffect"));
|
11
11
|
|
12
|
-
function
|
12
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
13
13
|
|
14
14
|
/**
|
15
15
|
* Creates a ref by combining multiple constituent refs. The ref returned by this hook
|
@@ -21,8 +21,7 @@ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj &&
|
|
21
21
|
*/
|
22
22
|
function useCombinedRefs(...refs) {
|
23
23
|
const combinedRef = (0, _react.useRef)(null);
|
24
|
-
|
25
|
-
_react.default.useLayoutEffect(() => {
|
24
|
+
(0, _useIsomorphicLayoutEffect.default)(() => {
|
26
25
|
function setRefs(current = null) {
|
27
26
|
for (const ref of refs) {
|
28
27
|
if (!ref) {
|
@@ -44,6 +43,5 @@ function useCombinedRefs(...refs) {
|
|
44
43
|
setRefs(combinedRef.current);
|
45
44
|
}; // eslint-disable-next-line react-hooks/exhaustive-deps
|
46
45
|
}, [...refs, combinedRef.current]);
|
47
|
-
|
48
46
|
return combinedRef;
|
49
47
|
}
|
@@ -5,12 +5,12 @@ Object.defineProperty(exports, "__esModule", {
|
|
5
5
|
});
|
6
6
|
exports.useResizeObserver = useResizeObserver;
|
7
7
|
|
8
|
-
var
|
8
|
+
var _useIsomorphicLayoutEffect = _interopRequireDefault(require("../utils/useIsomorphicLayoutEffect"));
|
9
9
|
|
10
10
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
11
11
|
|
12
12
|
function useResizeObserver(callback) {
|
13
|
-
|
13
|
+
(0, _useIsomorphicLayoutEffect.default)(() => {
|
14
14
|
const observer = new window.ResizeObserver(() => callback());
|
15
15
|
observer.observe(document.documentElement);
|
16
16
|
return () => {
|
@@ -0,0 +1,12 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.default = void 0;
|
7
|
+
|
8
|
+
var _react = require("react");
|
9
|
+
|
10
|
+
const useIsomorphicLayoutEffect = typeof window !== 'undefined' && typeof window.document !== 'undefined' && typeof window.document.createElement !== 'undefined' ? _react.useLayoutEffect : _react.useEffect;
|
11
|
+
var _default = useIsomorphicLayoutEffect;
|
12
|
+
exports.default = _default;
|
package/lib-esm/Overlay.js
CHANGED
@@ -1,8 +1,9 @@
|
|
1
1
|
function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
2
2
|
|
3
3
|
import styled from 'styled-components';
|
4
|
-
import React, { useEffect,
|
4
|
+
import React, { useEffect, useRef } from 'react';
|
5
5
|
import { get, COMMON } from './constants';
|
6
|
+
import useLayoutEffect from './utils/useIsomorphicLayoutEffect';
|
6
7
|
import { useOverlay } from './hooks';
|
7
8
|
import Portal from './Portal';
|
8
9
|
import sx from './sx';
|
@@ -95,6 +96,7 @@ const Overlay = /*#__PURE__*/React.forwardRef(({
|
|
95
96
|
preventFocusOnOpen,
|
96
97
|
...rest
|
97
98
|
}, forwardedRef) => {
|
99
|
+
debugger;
|
98
100
|
const overlayRef = useRef(null);
|
99
101
|
const combinedRef = useCombinedRefs(overlayRef, forwardedRef);
|
100
102
|
const {
|
@@ -114,6 +116,8 @@ const Overlay = /*#__PURE__*/React.forwardRef(({
|
|
114
116
|
useEffect(() => {
|
115
117
|
var _combinedRef$current;
|
116
118
|
|
119
|
+
debugger;
|
120
|
+
|
117
121
|
if (height === 'initial' && (_combinedRef$current = combinedRef.current) !== null && _combinedRef$current !== void 0 && _combinedRef$current.clientHeight) {
|
118
122
|
combinedRef.current.style.height = `${combinedRef.current.clientHeight}px`;
|
119
123
|
}
|
@@ -121,6 +125,7 @@ const Overlay = /*#__PURE__*/React.forwardRef(({
|
|
121
125
|
useLayoutEffect(() => {
|
122
126
|
var _overlayRef$current;
|
123
127
|
|
128
|
+
debugger;
|
124
129
|
const {
|
125
130
|
x,
|
126
131
|
y
|
package/lib-esm/Portal/Portal.js
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
import React from 'react';
|
2
2
|
import { createPortal } from 'react-dom';
|
3
|
+
import useLayoutEffect from '../utils/useIsomorphicLayoutEffect';
|
3
4
|
const PRIMER_PORTAL_ROOT_ID = '__primerPortalRoot__';
|
4
5
|
const DEFAULT_PORTAL_CONTAINER_NAME = '__default__';
|
5
6
|
const portalRootRegistry = {};
|
@@ -57,7 +58,7 @@ export const Portal = ({
|
|
57
58
|
hostElement.style.position = 'relative';
|
58
59
|
hostElement.style.zIndex = '1';
|
59
60
|
const elementRef = React.useRef(hostElement);
|
60
|
-
|
61
|
+
useLayoutEffect(() => {
|
61
62
|
let containerName = _containerName;
|
62
63
|
|
63
64
|
if (containerName === undefined) {
|
@@ -2,6 +2,7 @@ import React from 'react';
|
|
2
2
|
import { getAnchoredPosition } from '../behaviors/anchoredPosition';
|
3
3
|
import { useProvidedRefOrCreate } from './useProvidedRefOrCreate';
|
4
4
|
import { useResizeObserver } from './useResizeObserver';
|
5
|
+
import useLayoutEffect from '../utils/useIsomorphicLayoutEffect';
|
5
6
|
|
6
7
|
/**
|
7
8
|
* Calculates the top and left values for an absolutely-positioned floating element
|
@@ -24,7 +25,7 @@ export function useAnchoredPosition(settings, dependencies = []) {
|
|
24
25
|
}
|
25
26
|
}, // eslint-disable-next-line react-hooks/exhaustive-deps
|
26
27
|
[floatingElementRef, anchorElementRef, ...dependencies]);
|
27
|
-
|
28
|
+
useLayoutEffect(updatePosition, [updatePosition]);
|
28
29
|
useResizeObserver(updatePosition);
|
29
30
|
return {
|
30
31
|
floatingElementRef,
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import
|
1
|
+
import { ForwardedRef } from 'react';
|
2
2
|
/**
|
3
3
|
* Creates a ref by combining multiple constituent refs. The ref returned by this hook
|
4
4
|
* should be passed as the ref for the element that needs to be shared. This is
|
@@ -7,4 +7,4 @@ import React, { ForwardedRef } from 'react';
|
|
7
7
|
* though, as it breaks encapsulation.
|
8
8
|
* @param refs
|
9
9
|
*/
|
10
|
-
export declare function useCombinedRefs<T>(...refs: (ForwardedRef<T> | null | undefined)[]):
|
10
|
+
export declare function useCombinedRefs<T>(...refs: (ForwardedRef<T> | null | undefined)[]): import("react").MutableRefObject<T | null>;
|
@@ -1,4 +1,5 @@
|
|
1
|
-
import
|
1
|
+
import { useRef } from 'react';
|
2
|
+
import useLayoutEffect from '../utils/useIsomorphicLayoutEffect';
|
2
3
|
/**
|
3
4
|
* Creates a ref by combining multiple constituent refs. The ref returned by this hook
|
4
5
|
* should be passed as the ref for the element that needs to be shared. This is
|
@@ -10,7 +11,7 @@ import React, { useRef } from 'react';
|
|
10
11
|
|
11
12
|
export function useCombinedRefs(...refs) {
|
12
13
|
const combinedRef = useRef(null);
|
13
|
-
|
14
|
+
useLayoutEffect(() => {
|
14
15
|
function setRefs(current = null) {
|
15
16
|
for (const ref of refs) {
|
16
17
|
if (!ref) {
|
@@ -1,6 +1,6 @@
|
|
1
|
-
import
|
1
|
+
import useLayoutEffect from '../utils/useIsomorphicLayoutEffect';
|
2
2
|
export function useResizeObserver(callback) {
|
3
|
-
|
3
|
+
useLayoutEffect(() => {
|
4
4
|
const observer = new window.ResizeObserver(() => callback());
|
5
5
|
observer.observe(document.documentElement);
|
6
6
|
return () => {
|
@@ -0,0 +1,3 @@
|
|
1
|
+
import { useEffect, useLayoutEffect } from 'react';
|
2
|
+
const useIsomorphicLayoutEffect = typeof window !== 'undefined' && typeof window.document !== 'undefined' && typeof window.document.createElement !== 'undefined' ? useLayoutEffect : useEffect;
|
3
|
+
export default useIsomorphicLayoutEffect;
|