@primer/components 31.2.0-rc.5ccefd7d → 31.2.0-rc.b718ff50
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/docs/src/@primer/gatsby-theme-doctocat/components/hero.js +1 -3
- package/docs/src/@primer/gatsby-theme-doctocat/components/live-preview-wrapper.js +1 -1
- package/lib/Overlay.js +3 -1
- package/lib/Portal/Portal.js +3 -2
- package/lib/__tests__/AnchoredOverlay.test.js +4 -2
- package/lib/__tests__/TextInputWithTokens.test.js +1 -10
- 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/stories/Token.stories.js +19 -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/__tests__/AnchoredOverlay.test.js +4 -2
- package/lib-esm/__tests__/TextInputWithTokens.test.js +1 -10
- 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/stories/Token.stories.js +14 -1
- package/lib-esm/utils/useIsomorphicLayoutEffect.d.ts +3 -0
- package/lib-esm/utils/useIsomorphicLayoutEffect.js +3 -0
- package/migrating.md +1 -1
- package/package.json +2 -2
- package/script/build +2 -0
- package/src/Overlay.tsx +2 -1
- package/src/Portal/Portal.tsx +2 -1
- package/src/__tests__/AnchoredOverlay.test.tsx +2 -2
- package/src/__tests__/TextInputWithTokens.test.tsx +0 -10
- package/src/__tests__/__snapshots__/AnchoredOverlay.test.tsx.snap +35 -135
- package/src/hooks/useAnchoredPosition.ts +2 -1
- package/src/hooks/useCombinedRefs.ts +3 -3
- package/src/hooks/useResizeObserver.ts +2 -2
- package/src/stories/Token.stories.tsx +12 -1
- package/src/utils/useIsomorphicLayoutEffect.ts +10 -0
- package/stats.html +1 -1
@@ -9,9 +9,7 @@ export default function Hero() {
|
|
9
9
|
<ThemeProvider colorMode="night" nightScheme="dark_dimmed">
|
10
10
|
<Box bg="canvas.default" py={6}>
|
11
11
|
<Container>
|
12
|
-
<Heading color
|
13
|
-
Primer React
|
14
|
-
</Heading>
|
12
|
+
<Heading sx={{color: 'accent.fg', fontSize: 7, lineHeight: 'condensed', pb: 3, m: 0}}>Primer React</Heading>
|
15
13
|
<Text as="p" fontFamily="mono" mt={0} mb={2} color="fg.default" fontSize={2}>
|
16
14
|
v{version}
|
17
15
|
</Text>
|
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
|
|
@@ -152,9 +152,11 @@ describe('AnchoredOverlay', () => {
|
|
152
152
|
expect(mockCloseCallback).toHaveBeenCalledWith('escape');
|
153
153
|
});
|
154
154
|
it('should render consistently when open', () => {
|
155
|
-
const
|
155
|
+
const {
|
156
|
+
container
|
157
|
+
} = (0, _react2.render)( /*#__PURE__*/_react.default.createElement(AnchoredOverlayTestComponent, {
|
156
158
|
initiallyOpen: true
|
157
159
|
}));
|
158
|
-
expect(
|
160
|
+
expect(container).toMatchSnapshot();
|
159
161
|
});
|
160
162
|
});
|
@@ -58,16 +58,7 @@ const LabelledTextInputWithTokens = ({
|
|
58
58
|
tokens: tokens,
|
59
59
|
onTokenRemove: onTokenRemove,
|
60
60
|
id: "tokenInput"
|
61
|
-
}, rest)));
|
62
|
-
// it('should have no axe violations', async () => {
|
63
|
-
// const onRemoveMock = jest.fn()
|
64
|
-
// const {container} = HTMLRender(<LabelledTextInputWithTokens tokens={mockTokens} onTokenRemove={onRemoveMock} />)
|
65
|
-
// const results = await axe(container)
|
66
|
-
// expect(results).toHaveNoViolations()
|
67
|
-
// cleanup()
|
68
|
-
// })
|
69
|
-
// })
|
70
|
-
|
61
|
+
}, rest)));
|
71
62
|
|
72
63
|
jest.useFakeTimers();
|
73
64
|
describe('TextInputWithTokens', () => {
|
@@ -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 () => {
|
@@ -3,7 +3,7 @@
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
4
4
|
value: true
|
5
5
|
});
|
6
|
-
exports.WithOnRemoveFn = exports.Interactive = exports.DefaultToken = exports.default = void 0;
|
6
|
+
exports.WithOnRemoveFn = exports.WithLeadingVisual = exports.Interactive = exports.DefaultToken = exports.default = void 0;
|
7
7
|
|
8
8
|
var _react = _interopRequireDefault(require("react"));
|
9
9
|
|
@@ -19,6 +19,8 @@ var _Token = _interopRequireDefault(require("../Token/Token"));
|
|
19
19
|
|
20
20
|
var _Text = _interopRequireDefault(require("../Text"));
|
21
21
|
|
22
|
+
var _octiconsReact = require("@primer/octicons-react");
|
23
|
+
|
22
24
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
23
25
|
|
24
26
|
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); }
|
@@ -36,7 +38,7 @@ var _default = {
|
|
36
38
|
}]
|
37
39
|
};
|
38
40
|
exports.default = _default;
|
39
|
-
const excludedControlKeys = ['id', 'as', 'tabIndex', 'onRemove'];
|
41
|
+
const excludedControlKeys = ['id', 'as', 'tabIndex', 'onRemove', 'leadingVisual'];
|
40
42
|
|
41
43
|
const SingleExampleContainer = ({
|
42
44
|
children,
|
@@ -115,6 +117,21 @@ Interactive.parameters = {
|
|
115
117
|
}
|
116
118
|
};
|
117
119
|
|
120
|
+
const WithLeadingVisual = args => {
|
121
|
+
return /*#__PURE__*/_react.default.createElement(ExampleCollectionContainer, null, /*#__PURE__*/_react.default.createElement(_Token.default, _extends({}, args, {
|
122
|
+
leadingVisual: () => /*#__PURE__*/_react.default.createElement(_octiconsReact.GitBranchIcon, null)
|
123
|
+
})));
|
124
|
+
};
|
125
|
+
|
126
|
+
exports.WithLeadingVisual = WithLeadingVisual;
|
127
|
+
WithLeadingVisual.displayName = "WithLeadingVisual";
|
128
|
+
WithLeadingVisual.storyName = 'with leadingVisual';
|
129
|
+
WithLeadingVisual.parameters = {
|
130
|
+
controls: {
|
131
|
+
exclude: [...excludedControlKeys, 'hideRemoveButton']
|
132
|
+
}
|
133
|
+
};
|
134
|
+
|
118
135
|
const WithOnRemoveFn = args => {
|
119
136
|
return /*#__PURE__*/_react.default.createElement(ExampleCollectionContainer, null, /*#__PURE__*/_react.default.createElement(SingleExampleContainer, {
|
120
137
|
label: "w/ onRemove passed"
|
@@ -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) {
|
@@ -126,9 +126,11 @@ describe('AnchoredOverlay', () => {
|
|
126
126
|
expect(mockCloseCallback).toHaveBeenCalledWith('escape');
|
127
127
|
});
|
128
128
|
it('should render consistently when open', () => {
|
129
|
-
const
|
129
|
+
const {
|
130
|
+
container
|
131
|
+
} = HTMLRender( /*#__PURE__*/React.createElement(AnchoredOverlayTestComponent, {
|
130
132
|
initiallyOpen: true
|
131
133
|
}));
|
132
|
-
expect(
|
134
|
+
expect(container).toMatchSnapshot();
|
133
135
|
});
|
134
136
|
});
|
@@ -46,16 +46,7 @@ const LabelledTextInputWithTokens = ({
|
|
46
46
|
tokens: tokens,
|
47
47
|
onTokenRemove: onTokenRemove,
|
48
48
|
id: "tokenInput"
|
49
|
-
}, rest)));
|
50
|
-
// it('should have no axe violations', async () => {
|
51
|
-
// const onRemoveMock = jest.fn()
|
52
|
-
// const {container} = HTMLRender(<LabelledTextInputWithTokens tokens={mockTokens} onTokenRemove={onRemoveMock} />)
|
53
|
-
// const results = await axe(container)
|
54
|
-
// expect(results).toHaveNoViolations()
|
55
|
-
// cleanup()
|
56
|
-
// })
|
57
|
-
// })
|
58
|
-
|
49
|
+
}, rest)));
|
59
50
|
|
60
51
|
jest.useFakeTimers();
|
61
52
|
describe('TextInputWithTokens', () => {
|
@@ -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 () => {
|
@@ -7,6 +7,7 @@ import { BaseStyles, ThemeProvider } from '..';
|
|
7
7
|
import Box from '../Box';
|
8
8
|
import Token from '../Token/Token';
|
9
9
|
import Text from '../Text';
|
10
|
+
import { GitBranchIcon } from '@primer/octicons-react';
|
10
11
|
export default {
|
11
12
|
title: 'Tokens/Default',
|
12
13
|
component: Token,
|
@@ -19,7 +20,7 @@ export default {
|
|
19
20
|
return /*#__PURE__*/React.createElement(ThemeProvider, null, /*#__PURE__*/React.createElement(BaseStyles, null, /*#__PURE__*/React.createElement(Story, null)));
|
20
21
|
}]
|
21
22
|
};
|
22
|
-
const excludedControlKeys = ['id', 'as', 'tabIndex', 'onRemove'];
|
23
|
+
const excludedControlKeys = ['id', 'as', 'tabIndex', 'onRemove', 'leadingVisual'];
|
23
24
|
|
24
25
|
const SingleExampleContainer = ({
|
25
26
|
children,
|
@@ -91,6 +92,18 @@ Interactive.parameters = {
|
|
91
92
|
exclude: [...excludedControlKeys, 'hideRemoveButton', 'text']
|
92
93
|
}
|
93
94
|
};
|
95
|
+
export const WithLeadingVisual = args => {
|
96
|
+
return /*#__PURE__*/React.createElement(ExampleCollectionContainer, null, /*#__PURE__*/React.createElement(Token, _extends({}, args, {
|
97
|
+
leadingVisual: () => /*#__PURE__*/React.createElement(GitBranchIcon, null)
|
98
|
+
})));
|
99
|
+
};
|
100
|
+
WithLeadingVisual.displayName = "WithLeadingVisual";
|
101
|
+
WithLeadingVisual.storyName = 'with leadingVisual';
|
102
|
+
WithLeadingVisual.parameters = {
|
103
|
+
controls: {
|
104
|
+
exclude: [...excludedControlKeys, 'hideRemoveButton']
|
105
|
+
}
|
106
|
+
};
|
94
107
|
export const WithOnRemoveFn = args => {
|
95
108
|
return /*#__PURE__*/React.createElement(ExampleCollectionContainer, null, /*#__PURE__*/React.createElement(SingleExampleContainer, {
|
96
109
|
label: "w/ onRemove passed"
|
@@ -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/migrating.md
CHANGED
@@ -110,7 +110,7 @@ There are two ways to change the theme of @primer/components components:
|
|
110
110
|
|
111
111
|
export default () => (
|
112
112
|
<ThemeProvider theme={theme}>
|
113
|
-
<Block color
|
113
|
+
<Block sx={{color: 'bodytext', p: 4}}>
|
114
114
|
<Text fontSize={4}>Hello, world!</Text>
|
115
115
|
</Block>
|
116
116
|
</ThemeProvider>
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@primer/components",
|
3
|
-
"version": "31.2.0-rc.
|
3
|
+
"version": "31.2.0-rc.b718ff50",
|
4
4
|
"description": "Primer react components",
|
5
5
|
"main": "lib/index.js",
|
6
6
|
"module": "lib-esm/index.js",
|
@@ -15,7 +15,7 @@
|
|
15
15
|
"start": "concurrently npm:start:*",
|
16
16
|
"start:docs": "cd docs && npm run develop",
|
17
17
|
"start:storybook": "start-storybook -p 6006",
|
18
|
-
"lint": "eslint '**/*.{js,ts,tsx,md,mdx}'",
|
18
|
+
"lint": "eslint '**/*.{js,ts,tsx,md,mdx}' --max-warnings=0",
|
19
19
|
"lint:fix": "npm run lint -- --fix",
|
20
20
|
"test": "jest",
|
21
21
|
"test:update": "npm run test -- --updateSnapshot",
|
package/script/build
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
|
@@ -144,7 +144,7 @@ describe('AnchoredOverlay', () => {
|
|
144
144
|
})
|
145
145
|
|
146
146
|
it('should render consistently when open', () => {
|
147
|
-
const
|
148
|
-
expect(
|
147
|
+
const {container} = HTMLRender(<AnchoredOverlayTestComponent initiallyOpen={true} />)
|
148
|
+
expect(container).toMatchSnapshot()
|
149
149
|
})
|
150
150
|
})
|
@@ -29,16 +29,6 @@ const LabelledTextInputWithTokens: React.FC<TextInputWithTokensProps> = ({onToke
|
|
29
29
|
</>
|
30
30
|
)
|
31
31
|
|
32
|
-
// describe('axe test', () => {
|
33
|
-
// it('should have no axe violations', async () => {
|
34
|
-
// const onRemoveMock = jest.fn()
|
35
|
-
// const {container} = HTMLRender(<LabelledTextInputWithTokens tokens={mockTokens} onTokenRemove={onRemoveMock} />)
|
36
|
-
// const results = await axe(container)
|
37
|
-
// expect(results).toHaveNoViolations()
|
38
|
-
// cleanup()
|
39
|
-
// })
|
40
|
-
// })
|
41
|
-
|
42
32
|
jest.useFakeTimers()
|
43
33
|
|
44
34
|
describe('TextInputWithTokens', () => {
|