@primer/components 0.0.0-2021104225742 → 0.0.0-20211086336

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/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 = 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, _react.useLayoutEffect)(() => {
144
+ (0, _useIsomorphicLayoutEffect.useIsomorphicLayoutEffect)(() => {
143
145
  var _overlayRef$current;
144
146
 
145
147
  const {
@@ -10,6 +10,8 @@ var _react = _interopRequireDefault(require("react"));
10
10
 
11
11
  var _reactDom = require("react-dom");
12
12
 
13
+ var _useIsomorphicLayoutEffect = 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
- _react.default.useLayoutEffect(() => {
77
+ (0, _useIsomorphicLayoutEffect.useIsomorphicLayoutEffect)(() => {
76
78
  let containerName = _containerName;
77
79
 
78
80
  if (containerName === undefined) {
@@ -91,9 +93,8 @@ const Portal = ({
91
93
  onMount === null || onMount === void 0 ? void 0 : onMount();
92
94
  return () => {
93
95
  parentElement.removeChild(element);
94
- }; // eslint-disable-next-line react-hooks/exhaustive-deps
96
+ };
95
97
  }, [elementRef]);
96
-
97
98
  return /*#__PURE__*/(0, _reactDom.createPortal)(children, elementRef.current);
98
99
  };
99
100
 
package/lib/Truncate.d.ts CHANGED
@@ -1,10 +1,11 @@
1
1
  import { MaxWidthProps } from 'styled-system';
2
+ import { SystemCommonProps, SystemTypographyProps } from './constants';
2
3
  import { SxProp } from './sx';
3
4
  import { ComponentProps } from './utils/types';
4
5
  declare const Truncate: import("styled-components").StyledComponent<"div", any, {
5
6
  title: string;
6
7
  inline?: boolean | undefined;
7
8
  expandable?: boolean | undefined;
8
- } & MaxWidthProps<Required<import("styled-system").Theme<import("styled-system").TLengthStyledSystem>>, import("csstype").Property.MaxWidth<import("styled-system").TLengthStyledSystem>> & SxProp, never>;
9
+ } & MaxWidthProps<Required<import("styled-system").Theme<import("styled-system").TLengthStyledSystem>>, import("csstype").Property.MaxWidth<import("styled-system").TLengthStyledSystem>> & SystemTypographyProps & SystemCommonProps & SxProp, never>;
9
10
  export declare type TruncateProps = ComponentProps<typeof Truncate>;
10
11
  export default Truncate;
package/lib/Truncate.js CHANGED
@@ -9,6 +9,8 @@ var _styledComponents = _interopRequireDefault(require("styled-components"));
9
9
 
10
10
  var _styledSystem = require("styled-system");
11
11
 
12
+ var _constants = require("./constants");
13
+
12
14
  var _sx = _interopRequireDefault(require("./sx"));
13
15
 
14
16
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
@@ -16,7 +18,7 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
16
18
  const Truncate = _styledComponents.default.div.withConfig({
17
19
  displayName: "Truncate",
18
20
  componentId: "sc-1074h1l-0"
19
- })(["display:", ";overflow:hidden;text-overflow:ellipsis;vertical-align:", ";white-space:nowrap;", " ", " ", ";"], props => props.inline ? 'inline-block' : 'inherit', props => props.inline ? 'top' : 'initial', _styledSystem.maxWidth, props => props.expandable ? `&:hover { max-width: 10000px; }` : '', _sx.default);
21
+ })(["", " ", " display:", ";overflow:hidden;text-overflow:ellipsis;vertical-align:", ";white-space:nowrap;", " ", " ", ";"], _constants.TYPOGRAPHY, _constants.COMMON, props => props.inline ? 'inline-block' : 'inherit', props => props.inline ? 'top' : 'initial', _styledSystem.maxWidth, props => props.expandable ? `&:hover { max-width: 10000px; }` : '', _sx.default);
20
22
 
21
23
  Truncate.defaultProps = {
22
24
  expandable: false,
@@ -13,6 +13,8 @@ var _useProvidedRefOrCreate = require("./useProvidedRefOrCreate");
13
13
 
14
14
  var _useResizeObserver = require("./useResizeObserver");
15
15
 
16
+ var _useIsomorphicLayoutEffect = 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
- _react.default.useLayoutEffect(updatePosition, [updatePosition]);
43
-
44
+ (0, _useIsomorphicLayoutEffect.useIsomorphicLayoutEffect)(updatePosition, [updatePosition]);
44
45
  (0, _useResizeObserver.useResizeObserver)(updatePosition);
45
46
  return {
46
47
  floatingElementRef,
@@ -1,4 +1,4 @@
1
- import React, { ForwardedRef } from 'react';
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)[]): React.MutableRefObject<T | null>;
10
+ export declare function useCombinedRefs<T>(...refs: (ForwardedRef<T> | null | undefined)[]): import("react").MutableRefObject<T | null>;
@@ -5,11 +5,9 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.useCombinedRefs = useCombinedRefs;
7
7
 
8
- var _react = _interopRequireWildcard(require("react"));
8
+ var _react = require("react");
9
9
 
10
- function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
11
-
12
- function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
10
+ var _useIsomorphicLayoutEffect = require("../utils/useIsomorphicLayoutEffect");
13
11
 
14
12
  /**
15
13
  * Creates a ref by combining multiple constituent refs. The ref returned by this hook
@@ -21,8 +19,7 @@ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj &&
21
19
  */
22
20
  function useCombinedRefs(...refs) {
23
21
  const combinedRef = (0, _react.useRef)(null);
24
-
25
- _react.default.useLayoutEffect(() => {
22
+ (0, _useIsomorphicLayoutEffect.useIsomorphicLayoutEffect)(() => {
26
23
  function setRefs(current = null) {
27
24
  for (const ref of refs) {
28
25
  if (!ref) {
@@ -40,10 +37,8 @@ function useCombinedRefs(...refs) {
40
37
  setRefs(combinedRef.current);
41
38
  return () => {
42
39
  // ensure the refs get updated on unmount
43
- // eslint-disable-next-line react-hooks/exhaustive-deps
44
40
  setRefs(combinedRef.current);
45
- }; // eslint-disable-next-line react-hooks/exhaustive-deps
41
+ };
46
42
  }, [...refs, combinedRef.current]);
47
-
48
43
  return combinedRef;
49
44
  }
@@ -5,12 +5,10 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.useResizeObserver = useResizeObserver;
7
7
 
8
- var _react = _interopRequireDefault(require("react"));
9
-
10
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
8
+ var _useIsomorphicLayoutEffect = require("../utils/useIsomorphicLayoutEffect");
11
9
 
12
10
  function useResizeObserver(callback) {
13
- _react.default.useLayoutEffect(() => {
11
+ (0, _useIsomorphicLayoutEffect.useIsomorphicLayoutEffect)(() => {
14
12
  const observer = new window.ResizeObserver(() => callback());
15
13
  observer.observe(document.documentElement);
16
14
  return () => {
@@ -0,0 +1,2 @@
1
+ import { useEffect } from 'react';
2
+ export declare const useIsomorphicLayoutEffect: typeof useEffect;
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.useIsomorphicLayoutEffect = void 0;
7
+
8
+ var _react = require("react");
9
+
10
+ const useIsomorphicLayoutEffect = () => {
11
+ return typeof window !== 'undefined' ? _react.useLayoutEffect : _react.useEffect;
12
+ };
13
+
14
+ exports.useIsomorphicLayoutEffect = useIsomorphicLayoutEffect;
@@ -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, useLayoutEffect, useRef } from 'react';
4
+ import React, { useEffect, useRef } from 'react';
5
5
  import { get, COMMON } from './constants';
6
+ import { useIsomorphicLayoutEffect as useLayoutEffect } from './utils/useIsomorphicLayoutEffect';
6
7
  import { useOverlay } from './hooks';
7
8
  import Portal from './Portal';
8
9
  import sx from './sx';
@@ -1,5 +1,6 @@
1
1
  import React from 'react';
2
2
  import { createPortal } from 'react-dom';
3
+ import { useIsomorphicLayoutEffect as 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
- React.useLayoutEffect(() => {
61
+ useLayoutEffect(() => {
61
62
  let containerName = _containerName;
62
63
 
63
64
  if (containerName === undefined) {
@@ -76,7 +77,7 @@ export const Portal = ({
76
77
  onMount === null || onMount === void 0 ? void 0 : onMount();
77
78
  return () => {
78
79
  parentElement.removeChild(element);
79
- }; // eslint-disable-next-line react-hooks/exhaustive-deps
80
+ };
80
81
  }, [elementRef]);
81
82
  return /*#__PURE__*/createPortal(children, elementRef.current);
82
83
  };
@@ -1,10 +1,11 @@
1
1
  import { MaxWidthProps } from 'styled-system';
2
+ import { SystemCommonProps, SystemTypographyProps } from './constants';
2
3
  import { SxProp } from './sx';
3
4
  import { ComponentProps } from './utils/types';
4
5
  declare const Truncate: import("styled-components").StyledComponent<"div", any, {
5
6
  title: string;
6
7
  inline?: boolean | undefined;
7
8
  expandable?: boolean | undefined;
8
- } & MaxWidthProps<Required<import("styled-system").Theme<import("styled-system").TLengthStyledSystem>>, import("csstype").Property.MaxWidth<import("styled-system").TLengthStyledSystem>> & SxProp, never>;
9
+ } & MaxWidthProps<Required<import("styled-system").Theme<import("styled-system").TLengthStyledSystem>>, import("csstype").Property.MaxWidth<import("styled-system").TLengthStyledSystem>> & SystemTypographyProps & SystemCommonProps & SxProp, never>;
9
10
  export declare type TruncateProps = ComponentProps<typeof Truncate>;
10
11
  export default Truncate;
@@ -1,10 +1,11 @@
1
1
  import styled from 'styled-components';
2
2
  import { maxWidth } from 'styled-system';
3
+ import { COMMON, TYPOGRAPHY } from './constants';
3
4
  import sx from './sx';
4
5
  const Truncate = styled.div.withConfig({
5
6
  displayName: "Truncate",
6
7
  componentId: "sc-1074h1l-0"
7
- })(["display:", ";overflow:hidden;text-overflow:ellipsis;vertical-align:", ";white-space:nowrap;", " ", " ", ";"], props => props.inline ? 'inline-block' : 'inherit', props => props.inline ? 'top' : 'initial', maxWidth, props => props.expandable ? `&:hover { max-width: 10000px; }` : '', sx);
8
+ })(["", " ", " display:", ";overflow:hidden;text-overflow:ellipsis;vertical-align:", ";white-space:nowrap;", " ", " ", ";"], TYPOGRAPHY, COMMON, props => props.inline ? 'inline-block' : 'inherit', props => props.inline ? 'top' : 'initial', maxWidth, props => props.expandable ? `&:hover { max-width: 10000px; }` : '', sx);
8
9
  Truncate.defaultProps = {
9
10
  expandable: false,
10
11
  inline: false,
@@ -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 { useIsomorphicLayoutEffect as 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
- React.useLayoutEffect(updatePosition, [updatePosition]);
28
+ useLayoutEffect(updatePosition, [updatePosition]);
28
29
  useResizeObserver(updatePosition);
29
30
  return {
30
31
  floatingElementRef,
@@ -1,4 +1,4 @@
1
- import React, { ForwardedRef } from 'react';
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)[]): React.MutableRefObject<T | null>;
10
+ export declare function useCombinedRefs<T>(...refs: (ForwardedRef<T> | null | undefined)[]): import("react").MutableRefObject<T | null>;
@@ -1,4 +1,5 @@
1
- import React, { useRef } from 'react';
1
+ import { useRef } from 'react';
2
+ import { useIsomorphicLayoutEffect as 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
- React.useLayoutEffect(() => {
14
+ useLayoutEffect(() => {
14
15
  function setRefs(current = null) {
15
16
  for (const ref of refs) {
16
17
  if (!ref) {
@@ -28,9 +29,8 @@ export function useCombinedRefs(...refs) {
28
29
  setRefs(combinedRef.current);
29
30
  return () => {
30
31
  // ensure the refs get updated on unmount
31
- // eslint-disable-next-line react-hooks/exhaustive-deps
32
32
  setRefs(combinedRef.current);
33
- }; // eslint-disable-next-line react-hooks/exhaustive-deps
33
+ };
34
34
  }, [...refs, combinedRef.current]);
35
35
  return combinedRef;
36
36
  }
@@ -1,6 +1,6 @@
1
- import React from 'react';
1
+ import { useIsomorphicLayoutEffect as useLayoutEffect } from '../utils/useIsomorphicLayoutEffect';
2
2
  export function useResizeObserver(callback) {
3
- React.useLayoutEffect(() => {
3
+ useLayoutEffect(() => {
4
4
  const observer = new window.ResizeObserver(() => callback());
5
5
  observer.observe(document.documentElement);
6
6
  return () => {
@@ -0,0 +1,2 @@
1
+ import { useEffect } from 'react';
2
+ export declare const useIsomorphicLayoutEffect: typeof useEffect;
@@ -0,0 +1,4 @@
1
+ import { useEffect, useLayoutEffect } from 'react';
2
+ export const useIsomorphicLayoutEffect = () => {
3
+ return typeof window !== 'undefined' ? useLayoutEffect : useEffect;
4
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@primer/components",
3
- "version": "0.0.0-2021104225742",
3
+ "version": "0.0.0-20211086336",
4
4
  "description": "Primer react components",
5
5
  "main": "lib/index.js",
6
6
  "module": "lib-esm/index.js",