@primer/components 0.0.0-202110417386 → 0.0.0-202110871242

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.
Files changed (34) hide show
  1. package/CHANGELOG.md +5 -3
  2. package/dist/browser.esm.js +176 -176
  3. package/dist/browser.esm.js.map +1 -1
  4. package/dist/browser.umd.js +187 -187
  5. package/dist/browser.umd.js.map +1 -1
  6. package/lib/Overlay.js +3 -1
  7. package/lib/Portal/Portal.js +3 -2
  8. package/lib/hooks/useAnchoredPosition.js +3 -2
  9. package/lib/hooks/useCombinedRefs.d.ts +2 -2
  10. package/lib/hooks/useCombinedRefs.js +3 -7
  11. package/lib/hooks/useResizeObserver.js +2 -4
  12. package/lib/utils/useIsomorphicLayoutEffect.d.ts +2 -0
  13. package/lib/utils/useIsomorphicLayoutEffect.js +14 -0
  14. package/lib-esm/Overlay.js +2 -1
  15. package/lib-esm/Portal/Portal.js +2 -1
  16. package/lib-esm/hooks/useAnchoredPosition.js +2 -1
  17. package/lib-esm/hooks/useCombinedRefs.d.ts +2 -2
  18. package/lib-esm/hooks/useCombinedRefs.js +3 -2
  19. package/lib-esm/hooks/useResizeObserver.js +2 -2
  20. package/lib-esm/utils/useIsomorphicLayoutEffect.d.ts +2 -0
  21. package/lib-esm/utils/useIsomorphicLayoutEffect.js +4 -0
  22. package/package.json +1 -1
  23. package/lib/NewLabel/NewLabel.d.ts +0 -11
  24. package/lib/NewLabel/NewLabel.js +0 -134
  25. package/lib/NewLabel/NewStateLabel.d.ts +0 -10
  26. package/lib/NewLabel/NewStateLabel.js +0 -49
  27. package/lib/NewLabel/_newLabelStyleUtils.d.ts +0 -3
  28. package/lib/NewLabel/_newLabelStyleUtils.js +0 -40
  29. package/lib-esm/NewLabel/NewLabel.d.ts +0 -11
  30. package/lib-esm/NewLabel/NewLabel.js +0 -115
  31. package/lib-esm/NewLabel/NewStateLabel.d.ts +0 -10
  32. package/lib-esm/NewLabel/NewStateLabel.js +0 -36
  33. package/lib-esm/NewLabel/_newLabelStyleUtils.d.ts +0 -3
  34. package/lib-esm/NewLabel/_newLabelStyleUtils.js +0 -30
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) {
@@ -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 = 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) {
@@ -44,6 +41,5 @@ function useCombinedRefs(...refs) {
44
41
  setRefs(combinedRef.current);
45
42
  }; // eslint-disable-next-line react-hooks/exhaustive-deps
46
43
  }, [...refs, combinedRef.current]);
47
-
48
44
  return combinedRef;
49
45
  }
@@ -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) {
@@ -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) {
@@ -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-202110417386",
3
+ "version": "0.0.0-202110871242",
4
4
  "description": "Primer react components",
5
5
  "main": "lib/index.js",
6
6
  "module": "lib-esm/index.js",
@@ -1,11 +0,0 @@
1
- import React from 'react';
2
- import { LabelSizeKeys } from './_newLabelStyleUtils';
3
- export declare type LabelColorOptions = 'default' | 'primary' | 'secondary' | 'accent' | 'success' | 'attention' | 'severe' | 'danger' | 'done' | 'sponsors';
4
- interface Props {
5
- color?: LabelColorOptions;
6
- size?: LabelSizeKeys;
7
- filled?: boolean;
8
- leadingVisual?: React.ComponentType<any>;
9
- }
10
- declare const NewLabel: React.FC<Props>;
11
- export default NewLabel;
@@ -1,134 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
7
-
8
- var _react = _interopRequireDefault(require("react"));
9
-
10
- var _styledComponents = _interopRequireWildcard(require("styled-components"));
11
-
12
- var _constants = require("../constants");
13
-
14
- var _newLabelStyleUtils = require("./_newLabelStyleUtils");
15
-
16
- 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); }
17
-
18
- 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; }
19
-
20
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
21
-
22
- const labelColorMap = {
23
- default: {
24
- borderColor: (0, _constants.get)('colors.border.default')
25
- },
26
- primary: {
27
- borderColor: (0, _constants.get)('colors.fg.default')
28
- },
29
- secondary: {
30
- borderColor: (0, _constants.get)('colors.border.muted'),
31
- textColor: (0, _constants.get)('colors.fg.muted')
32
- },
33
- accent: {
34
- borderColor: (0, _constants.get)('colors.accent.emphasis'),
35
- textColor: (0, _constants.get)('colors.accent.fg')
36
- },
37
- success: {
38
- borderColor: (0, _constants.get)('colors.success.emphasis'),
39
- textColor: (0, _constants.get)('colors.success.fg')
40
- },
41
- attention: {
42
- borderColor: (0, _constants.get)('colors.attention.emphasis'),
43
- textColor: (0, _constants.get)('colors.attention.fg')
44
- },
45
- severe: {
46
- borderColor: (0, _constants.get)('colors.severe.emphasis'),
47
- textColor: (0, _constants.get)('colors.severe.fg')
48
- },
49
- danger: {
50
- borderColor: (0, _constants.get)('colors.danger.emphasis'),
51
- textColor: (0, _constants.get)('colors.danger.fg')
52
- },
53
- done: {
54
- borderColor: (0, _constants.get)('colors.done.fg'),
55
- textColor: (0, _constants.get)('colors.done.emphasis')
56
- },
57
- sponsors: {
58
- borderColor: (0, _constants.get)('colors.sponsors.fg'),
59
- textColor: (0, _constants.get)('colors.sponsors.emphasis')
60
- }
61
- };
62
- const filledLabelColorMap = {
63
- default: {
64
- bgColor: (0, _constants.get)('colors.neutral.muted')
65
- },
66
- primary: {
67
- bgColor: (0, _constants.get)('colors.neutral.emphasis'),
68
- textColor: (0, _constants.get)('colors.fg.onEmphasis')
69
- },
70
- secondary: {
71
- bgColor: (0, _constants.get)('colors.neutral.subtle'),
72
- textColor: (0, _constants.get)('colors.fg.muted')
73
- },
74
- accent: {
75
- bgColor: (0, _constants.get)('colors.accent.emphasis'),
76
- textColor: (0, _constants.get)('colors.fg.onEmphasis')
77
- },
78
- success: {
79
- bgColor: (0, _constants.get)('colors.success.emphasis'),
80
- textColor: (0, _constants.get)('colors.fg.onEmphasis')
81
- },
82
- attention: {
83
- bgColor: (0, _constants.get)('colors.attention.emphasis'),
84
- textColor: (0, _constants.get)('colors.fg.onEmphasis')
85
- },
86
- severe: {
87
- bgColor: (0, _constants.get)('colors.severe.emphasis'),
88
- textColor: (0, _constants.get)('colors.fg.onEmphasis')
89
- },
90
- danger: {
91
- bgColor: (0, _constants.get)('colors.danger.emphasis'),
92
- textColor: (0, _constants.get)('colors.fg.onEmphasis')
93
- },
94
- done: {
95
- bgColor: (0, _constants.get)('colors.done.fg'),
96
- textColor: (0, _constants.get)('colors.fg.onEmphasis')
97
- },
98
- sponsors: {
99
- bgColor: (0, _constants.get)('colors.sponsors.fg'),
100
- textColor: (0, _constants.get)('colors.fg.onEmphasis')
101
- }
102
- };
103
- const LeadingVisualContainer = (0, _styledComponents.default)('span').withConfig({
104
- displayName: "NewLabel__LeadingVisualContainer",
105
- componentId: "sc-6osasq-0"
106
- })(["flex-shrink:0;line-height:0;margin-right:", ";"], (0, _constants.get)('space.1'));
107
-
108
- const LabelContainer = _styledComponents.default.span.withConfig({
109
- displayName: "NewLabel__LabelContainer",
110
- componentId: "sc-6osasq-1"
111
- })(["align-items:center;border-width:1px;border-radius:999px;border-style:solid;display:inline-flex;font-weight:", ";line-height:1;white-space:nowrap;", ";", ""], (0, _constants.get)('fontWeights.bold'), _newLabelStyleUtils.labelVariants, ({
112
- color = 'default',
113
- filled
114
- }) => {
115
- if (filled) {
116
- return (0, _styledComponents.css)(["background-color:", ";border-color:transparent;color:", ";"], filledLabelColorMap[color].bgColor, filledLabelColorMap[color].textColor);
117
- } else {
118
- return (0, _styledComponents.css)(["background-color:transparent;border-color:", ";color:", ";"], labelColorMap[color].borderColor, labelColorMap[color].textColor);
119
- }
120
- });
121
-
122
- const NewLabel = ({
123
- children,
124
- leadingVisual: LeadingVisual,
125
- ...other
126
- }) => /*#__PURE__*/_react.default.createElement(LabelContainer, other, LeadingVisual && /*#__PURE__*/_react.default.createElement(LeadingVisualContainer, null, /*#__PURE__*/_react.default.createElement(LeadingVisual, null)), children);
127
-
128
- NewLabel.displayName = "NewLabel";
129
- NewLabel.defaultProps = {
130
- size: 'md',
131
- color: 'default'
132
- };
133
- var _default = NewLabel;
134
- exports.default = _default;
@@ -1,10 +0,0 @@
1
- import React from 'react';
2
- import { LabelSizeKeys } from './_newLabelStyleUtils';
3
- declare type Statuses = 'issueClosed' | 'pullClosed' | 'pullMerged' | 'issueOpened' | 'pullOpened' | 'draft';
4
- interface Props {
5
- status: Statuses;
6
- size?: LabelSizeKeys;
7
- leadingVisual?: React.ComponentType<any>;
8
- }
9
- declare const NewStateLabel: React.FC<Props>;
10
- export default NewStateLabel;
@@ -1,49 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
7
-
8
- var _react = _interopRequireDefault(require("react"));
9
-
10
- var _octiconsReact = require("@primer/octicons-react");
11
-
12
- var _NewLabel = _interopRequireDefault(require("./NewLabel"));
13
-
14
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
15
-
16
- 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); }
17
-
18
- const colorMap = {
19
- issueClosed: 'done',
20
- pullClosed: 'done',
21
- pullMerged: 'done',
22
- issueOpened: 'success',
23
- pullOpened: 'success',
24
- draft: 'primary'
25
- };
26
- const octiconMap = {
27
- issueOpened: _octiconsReact.IssueOpenedIcon,
28
- pullOpened: _octiconsReact.GitPullRequestIcon,
29
- issueClosed: _octiconsReact.IssueClosedIcon,
30
- pullClosed: _octiconsReact.GitPullRequestIcon,
31
- pullMerged: _octiconsReact.GitMergeIcon,
32
- draft: _octiconsReact.GitPullRequestIcon
33
- };
34
-
35
- const NewStateLabel = ({
36
- status,
37
- ...rest
38
- }) => /*#__PURE__*/_react.default.createElement(_NewLabel.default, _extends({
39
- filled: true,
40
- color: colorMap[status],
41
- leadingVisual: octiconMap[status]
42
- }, rest));
43
-
44
- NewStateLabel.displayName = "NewStateLabel";
45
- NewStateLabel.defaultProps = {
46
- size: 'lg'
47
- };
48
- var _default = NewStateLabel;
49
- exports.default = _default;
@@ -1,3 +0,0 @@
1
- export declare type LabelSizeKeys = 'sm' | 'md' | 'lg';
2
- export declare const badgeSizes: Record<LabelSizeKeys, number>;
3
- export declare const labelVariants: (...args: any[]) => any;
@@ -1,40 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.labelVariants = exports.badgeSizes = void 0;
7
-
8
- var _styledSystem = require("styled-system");
9
-
10
- // TODO: consider moving to Primitives
11
- const badgeSizes = {
12
- sm: 20,
13
- md: 24,
14
- lg: 32
15
- };
16
- exports.badgeSizes = badgeSizes;
17
- const labelVariants = (0, _styledSystem.variant)({
18
- prop: 'size',
19
- variants: {
20
- sm: {
21
- fontSize: 0,
22
- height: `${badgeSizes.sm}px`,
23
- paddingLeft: 2,
24
- paddingRight: 2
25
- },
26
- md: {
27
- fontSize: 0,
28
- height: `${badgeSizes.md}px`,
29
- paddingLeft: 2,
30
- paddingRight: 2
31
- },
32
- lg: {
33
- fontSize: 1,
34
- height: `${badgeSizes.lg}px`,
35
- paddingLeft: 3,
36
- paddingRight: 3
37
- }
38
- }
39
- });
40
- exports.labelVariants = labelVariants;
@@ -1,11 +0,0 @@
1
- import React from 'react';
2
- import { LabelSizeKeys } from './_newLabelStyleUtils';
3
- export declare type LabelColorOptions = 'default' | 'primary' | 'secondary' | 'accent' | 'success' | 'attention' | 'severe' | 'danger' | 'done' | 'sponsors';
4
- interface Props {
5
- color?: LabelColorOptions;
6
- size?: LabelSizeKeys;
7
- filled?: boolean;
8
- leadingVisual?: React.ComponentType<any>;
9
- }
10
- declare const NewLabel: React.FC<Props>;
11
- export default NewLabel;
@@ -1,115 +0,0 @@
1
- import React from 'react';
2
- import styled, { css } from 'styled-components';
3
- import { get } from '../constants';
4
- import { labelVariants } from './_newLabelStyleUtils';
5
- const labelColorMap = {
6
- default: {
7
- borderColor: get('colors.border.default')
8
- },
9
- primary: {
10
- borderColor: get('colors.fg.default')
11
- },
12
- secondary: {
13
- borderColor: get('colors.border.muted'),
14
- textColor: get('colors.fg.muted')
15
- },
16
- accent: {
17
- borderColor: get('colors.accent.emphasis'),
18
- textColor: get('colors.accent.fg')
19
- },
20
- success: {
21
- borderColor: get('colors.success.emphasis'),
22
- textColor: get('colors.success.fg')
23
- },
24
- attention: {
25
- borderColor: get('colors.attention.emphasis'),
26
- textColor: get('colors.attention.fg')
27
- },
28
- severe: {
29
- borderColor: get('colors.severe.emphasis'),
30
- textColor: get('colors.severe.fg')
31
- },
32
- danger: {
33
- borderColor: get('colors.danger.emphasis'),
34
- textColor: get('colors.danger.fg')
35
- },
36
- done: {
37
- borderColor: get('colors.done.fg'),
38
- textColor: get('colors.done.emphasis')
39
- },
40
- sponsors: {
41
- borderColor: get('colors.sponsors.fg'),
42
- textColor: get('colors.sponsors.emphasis')
43
- }
44
- };
45
- const filledLabelColorMap = {
46
- default: {
47
- bgColor: get('colors.neutral.muted')
48
- },
49
- primary: {
50
- bgColor: get('colors.neutral.emphasis'),
51
- textColor: get('colors.fg.onEmphasis')
52
- },
53
- secondary: {
54
- bgColor: get('colors.neutral.subtle'),
55
- textColor: get('colors.fg.muted')
56
- },
57
- accent: {
58
- bgColor: get('colors.accent.emphasis'),
59
- textColor: get('colors.fg.onEmphasis')
60
- },
61
- success: {
62
- bgColor: get('colors.success.emphasis'),
63
- textColor: get('colors.fg.onEmphasis')
64
- },
65
- attention: {
66
- bgColor: get('colors.attention.emphasis'),
67
- textColor: get('colors.fg.onEmphasis')
68
- },
69
- severe: {
70
- bgColor: get('colors.severe.emphasis'),
71
- textColor: get('colors.fg.onEmphasis')
72
- },
73
- danger: {
74
- bgColor: get('colors.danger.emphasis'),
75
- textColor: get('colors.fg.onEmphasis')
76
- },
77
- done: {
78
- bgColor: get('colors.done.fg'),
79
- textColor: get('colors.fg.onEmphasis')
80
- },
81
- sponsors: {
82
- bgColor: get('colors.sponsors.fg'),
83
- textColor: get('colors.fg.onEmphasis')
84
- }
85
- };
86
- const LeadingVisualContainer = styled('span').withConfig({
87
- displayName: "NewLabel__LeadingVisualContainer",
88
- componentId: "sc-6osasq-0"
89
- })(["flex-shrink:0;line-height:0;margin-right:", ";"], get('space.1'));
90
- const LabelContainer = styled.span.withConfig({
91
- displayName: "NewLabel__LabelContainer",
92
- componentId: "sc-6osasq-1"
93
- })(["align-items:center;border-width:1px;border-radius:999px;border-style:solid;display:inline-flex;font-weight:", ";line-height:1;white-space:nowrap;", ";", ""], get('fontWeights.bold'), labelVariants, ({
94
- color = 'default',
95
- filled
96
- }) => {
97
- if (filled) {
98
- return css(["background-color:", ";border-color:transparent;color:", ";"], filledLabelColorMap[color].bgColor, filledLabelColorMap[color].textColor);
99
- } else {
100
- return css(["background-color:transparent;border-color:", ";color:", ";"], labelColorMap[color].borderColor, labelColorMap[color].textColor);
101
- }
102
- });
103
-
104
- const NewLabel = ({
105
- children,
106
- leadingVisual: LeadingVisual,
107
- ...other
108
- }) => /*#__PURE__*/React.createElement(LabelContainer, other, LeadingVisual && /*#__PURE__*/React.createElement(LeadingVisualContainer, null, /*#__PURE__*/React.createElement(LeadingVisual, null)), children);
109
-
110
- NewLabel.displayName = "NewLabel";
111
- NewLabel.defaultProps = {
112
- size: 'md',
113
- color: 'default'
114
- };
115
- export default NewLabel;
@@ -1,10 +0,0 @@
1
- import React from 'react';
2
- import { LabelSizeKeys } from './_newLabelStyleUtils';
3
- declare type Statuses = 'issueClosed' | 'pullClosed' | 'pullMerged' | 'issueOpened' | 'pullOpened' | 'draft';
4
- interface Props {
5
- status: Statuses;
6
- size?: LabelSizeKeys;
7
- leadingVisual?: React.ComponentType<any>;
8
- }
9
- declare const NewStateLabel: React.FC<Props>;
10
- export default NewStateLabel;