@primer/components 31.2.0-rc.50908ce9 → 31.2.0-rc.85bcb6e0
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 +3 -1
- 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 +3 -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 +2 -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/src/Overlay.tsx +2 -1
- package/src/Portal/Portal.tsx +2 -1
- package/src/hooks/useAnchoredPosition.ts +2 -1
- package/src/hooks/useCombinedRefs.ts +3 -3
- package/src/hooks/useResizeObserver.ts +2 -2
- package/src/utils/useIsomorphicLayoutEffect.ts +10 -0
- package/stats.html +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"));
|
@@ -139,7 +141,7 @@ const Overlay = /*#__PURE__*/_react.default.forwardRef(({
|
|
139
141
|
combinedRef.current.style.height = `${combinedRef.current.clientHeight}px`;
|
140
142
|
}
|
141
143
|
}, [height, combinedRef]);
|
142
|
-
(0,
|
144
|
+
(0, _useIsomorphicLayoutEffect.default)(() => {
|
143
145
|
var _overlayRef$current;
|
144
146
|
|
145
147
|
const {
|
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';
|
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;
|
package/package.json
CHANGED
package/src/Overlay.tsx
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
import styled from 'styled-components'
|
2
|
-
import React, {ReactElement, useEffect,
|
2
|
+
import React, {ReactElement, useEffect, useRef} from 'react'
|
3
3
|
import {get, COMMON, SystemPositionProps, SystemCommonProps} from './constants'
|
4
4
|
import {ComponentProps} from './utils/types'
|
5
|
+
import useLayoutEffect from './utils/useIsomorphicLayoutEffect'
|
5
6
|
import {useOverlay, TouchOrMouseEvent} from './hooks'
|
6
7
|
import Portal from './Portal'
|
7
8
|
import sx, {SxProp} from './sx'
|
package/src/Portal/Portal.tsx
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
|
|
4
5
|
const PRIMER_PORTAL_ROOT_ID = '__primerPortalRoot__'
|
5
6
|
const DEFAULT_PORTAL_CONTAINER_NAME = '__default__'
|
@@ -69,7 +70,7 @@ export const Portal: React.FC<PortalProps> = ({children, onMount, containerName:
|
|
69
70
|
hostElement.style.zIndex = '1'
|
70
71
|
const elementRef = React.useRef(hostElement)
|
71
72
|
|
72
|
-
|
73
|
+
useLayoutEffect(() => {
|
73
74
|
let containerName = _containerName
|
74
75
|
if (containerName === undefined) {
|
75
76
|
containerName = DEFAULT_PORTAL_CONTAINER_NAME
|
@@ -2,6 +2,7 @@ import React from 'react'
|
|
2
2
|
import {PositionSettings, getAnchoredPosition, AnchorPosition} 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
|
export interface AnchoredPositionHookSettings extends Partial<PositionSettings> {
|
7
8
|
floatingElementRef?: React.RefObject<Element>
|
@@ -41,7 +42,7 @@ export function useAnchoredPosition(
|
|
41
42
|
[floatingElementRef, anchorElementRef, ...dependencies]
|
42
43
|
)
|
43
44
|
|
44
|
-
|
45
|
+
useLayoutEffect(updatePosition, [updatePosition])
|
45
46
|
|
46
47
|
useResizeObserver(updatePosition)
|
47
48
|
|
@@ -1,4 +1,5 @@
|
|
1
|
-
import
|
1
|
+
import {ForwardedRef, useRef} from 'react'
|
2
|
+
import useLayoutEffect from '../utils/useIsomorphicLayoutEffect'
|
2
3
|
|
3
4
|
/**
|
4
5
|
* Creates a ref by combining multiple constituent refs. The ref returned by this hook
|
@@ -11,7 +12,7 @@ import React, {ForwardedRef, useRef} from 'react'
|
|
11
12
|
export function useCombinedRefs<T>(...refs: (ForwardedRef<T> | null | undefined)[]) {
|
12
13
|
const combinedRef = useRef<T | null>(null)
|
13
14
|
|
14
|
-
|
15
|
+
useLayoutEffect(() => {
|
15
16
|
function setRefs(current: T | null = null) {
|
16
17
|
for (const ref of refs) {
|
17
18
|
if (!ref) {
|
@@ -32,7 +33,6 @@ export function useCombinedRefs<T>(...refs: (ForwardedRef<T> | null | undefined)
|
|
32
33
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
33
34
|
setRefs(combinedRef.current)
|
34
35
|
}
|
35
|
-
|
36
36
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
37
37
|
}, [...refs, combinedRef.current])
|
38
38
|
|
@@ -1,7 +1,7 @@
|
|
1
|
-
import
|
1
|
+
import useLayoutEffect from '../utils/useIsomorphicLayoutEffect'
|
2
2
|
|
3
3
|
export function useResizeObserver(callback: () => void) {
|
4
|
-
|
4
|
+
useLayoutEffect(() => {
|
5
5
|
const observer = new window.ResizeObserver(() => callback())
|
6
6
|
observer.observe(document.documentElement)
|
7
7
|
return () => {
|
@@ -0,0 +1,10 @@
|
|
1
|
+
import {useEffect, useLayoutEffect} from 'react'
|
2
|
+
|
3
|
+
const useIsomorphicLayoutEffect =
|
4
|
+
typeof window !== 'undefined' &&
|
5
|
+
typeof window.document !== 'undefined' &&
|
6
|
+
typeof window.document.createElement !== 'undefined'
|
7
|
+
? useLayoutEffect
|
8
|
+
: useEffect
|
9
|
+
|
10
|
+
export default useIsomorphicLayoutEffect
|