@primer/components 0.0.0-20219421304 → 0.0.0-202194215436

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 (66) hide show
  1. package/CHANGELOG.md +4 -8
  2. package/dist/browser.esm.js +768 -714
  3. package/dist/browser.esm.js.map +1 -1
  4. package/dist/browser.umd.js +409 -355
  5. package/dist/browser.umd.js.map +1 -1
  6. package/lib/ActionList/List.d.ts +1 -1
  7. package/lib/Token/LabelToken.d.ts +14 -0
  8. package/lib/Token/LabelToken.js +141 -0
  9. package/lib/Token/Token.d.ts +14 -0
  10. package/lib/Token/Token.js +76 -0
  11. package/lib/Token/TokenBase.d.ts +16 -0
  12. package/lib/Token/TokenBase.js +91 -0
  13. package/lib/Token/TokenProfile.d.ts +7 -0
  14. package/lib/Token/TokenProfile.js +50 -0
  15. package/lib/Token/_RemoveTokenButton.d.ts +9 -0
  16. package/lib/Token/_RemoveTokenButton.js +73 -0
  17. package/lib/Token/index.d.ts +3 -0
  18. package/lib/Token/index.js +31 -0
  19. package/lib/index.d.ts +1 -0
  20. package/lib/index.js +20 -0
  21. package/lib/sx.js +15 -0
  22. package/lib/theme-preval.js +5677 -0
  23. package/lib/theme.js +11 -0
  24. package/lib/utils/deprecate.js +100 -0
  25. package/lib/utils/isNumeric.js +11 -0
  26. package/lib/utils/iterateFocusableElements.js +113 -0
  27. package/lib/utils/ssr.js +19 -0
  28. package/lib/utils/test-deprecations.js +23 -0
  29. package/lib/utils/test-helpers.js +9 -0
  30. package/lib/utils/test-matchers.js +119 -0
  31. package/lib/utils/testing.js +273 -0
  32. package/lib/utils/theme.js +68 -0
  33. package/lib/utils/types.js +1 -0
  34. package/lib/utils/uniqueId.js +12 -0
  35. package/lib/utils/userAgent.js +15 -0
  36. package/lib-esm/ActionList/List.d.ts +1 -1
  37. package/lib-esm/Token/LabelToken.d.ts +14 -0
  38. package/lib-esm/Token/LabelToken.js +121 -0
  39. package/lib-esm/Token/Token.d.ts +14 -0
  40. package/lib-esm/Token/Token.js +57 -0
  41. package/lib-esm/Token/TokenBase.d.ts +16 -0
  42. package/lib-esm/Token/TokenBase.js +71 -0
  43. package/lib-esm/Token/TokenProfile.d.ts +7 -0
  44. package/lib-esm/Token/TokenProfile.js +29 -0
  45. package/lib-esm/Token/_RemoveTokenButton.d.ts +9 -0
  46. package/lib-esm/Token/_RemoveTokenButton.js +55 -0
  47. package/lib-esm/Token/index.d.ts +3 -0
  48. package/lib-esm/Token/index.js +3 -0
  49. package/lib-esm/index.d.ts +1 -0
  50. package/lib-esm/index.js +1 -0
  51. package/lib-esm/sx.js +5 -0
  52. package/lib-esm/theme-preval.js +5677 -0
  53. package/lib-esm/theme.js +2 -0
  54. package/lib-esm/utils/deprecate.js +91 -0
  55. package/lib-esm/utils/isNumeric.js +4 -0
  56. package/lib-esm/utils/iterateFocusableElements.js +102 -0
  57. package/lib-esm/utils/ssr.js +1 -0
  58. package/lib-esm/utils/test-deprecations.js +17 -0
  59. package/lib-esm/utils/test-helpers.js +7 -0
  60. package/lib-esm/utils/test-matchers.js +110 -0
  61. package/lib-esm/utils/testing.js +222 -0
  62. package/lib-esm/utils/theme.js +66 -0
  63. package/lib-esm/utils/types.js +1 -0
  64. package/lib-esm/utils/uniqueId.js +5 -0
  65. package/lib-esm/utils/userAgent.js +8 -0
  66. package/package.json +4 -2
@@ -0,0 +1,2 @@
1
+ import { theme } from './theme-preval';
2
+ export default theme;
@@ -0,0 +1,91 @@
1
+ import { useRef, useCallback } from 'react';
2
+
3
+ // eslint-disable-next-line @typescript-eslint/no-empty-function
4
+ const noop = () => {}; // eslint-disable-next-line import/no-mutable-exports
5
+
6
+
7
+ let deprecate = noop;
8
+
9
+ if (process.env.NODE_ENV !== 'production') {
10
+ deprecate = ({
11
+ name,
12
+ message,
13
+ version
14
+ }) => {
15
+ Deprecations.deprecate({
16
+ name,
17
+ message,
18
+ version
19
+ });
20
+ };
21
+ }
22
+
23
+ export { deprecate }; // eslint-disable-next-line import/no-mutable-exports
24
+
25
+ let useDeprecation = null;
26
+
27
+ if (process.env.NODE_ENV !== 'production') {
28
+ useDeprecation = ({
29
+ name,
30
+ message,
31
+ version
32
+ }) => {
33
+ const ref = useRef(false);
34
+ const logDeprecation = useCallback(() => {
35
+ if (!ref.current) {
36
+ ref.current = true;
37
+ deprecate({
38
+ name,
39
+ message,
40
+ version
41
+ });
42
+ }
43
+ }, [name, message, version]);
44
+ return logDeprecation;
45
+ };
46
+ } else {
47
+ useDeprecation = () => {
48
+ return noop;
49
+ };
50
+ }
51
+
52
+ export { useDeprecation };
53
+ export class Deprecations {
54
+ static instance = null;
55
+
56
+ static get() {
57
+ if (!Deprecations.instance) {
58
+ Deprecations.instance = new Deprecations();
59
+ }
60
+
61
+ return Deprecations.instance;
62
+ }
63
+
64
+ constructor() {
65
+ this.deprecations = [];
66
+ }
67
+
68
+ static deprecate({
69
+ name,
70
+ message,
71
+ version
72
+ }) {
73
+ const msg = `WARNING! ${name} is deprecated and will be removed in version ${version}. ${message}`; // eslint-disable-next-line no-console
74
+
75
+ console.warn(msg);
76
+ this.get().deprecations.push({
77
+ name,
78
+ message,
79
+ version
80
+ });
81
+ }
82
+
83
+ static getDeprecations() {
84
+ return this.get().deprecations;
85
+ }
86
+
87
+ static clearDeprecations() {
88
+ this.get().deprecations.length = 0;
89
+ }
90
+
91
+ }
@@ -0,0 +1,4 @@
1
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
2
+ export default function isNumeric(n) {
3
+ return !isNaN(parseFloat(n)) && isFinite(n);
4
+ }
@@ -0,0 +1,102 @@
1
+ /**
2
+ * Options to the focusable elements iterator
3
+ */
4
+
5
+ /**
6
+ * Returns an iterator over all of the focusable elements within `container`.
7
+ * Note: If `container` is itself focusable it will be included in the results.
8
+ * @param container The container over which to find focusable elements.
9
+ * @param reverse If true, iterate backwards through focusable elements.
10
+ */
11
+ export function* iterateFocusableElements(container, options = {}) {
12
+ var _options$strict, _options$onlyTabbable;
13
+
14
+ const strict = (_options$strict = options.strict) !== null && _options$strict !== void 0 ? _options$strict : false;
15
+ const acceptFn = ((_options$onlyTabbable = options.onlyTabbable) !== null && _options$onlyTabbable !== void 0 ? _options$onlyTabbable : false) ? isTabbable : isFocusable;
16
+ const walker = document.createTreeWalker(container, NodeFilter.SHOW_ELEMENT, {
17
+ acceptNode: node => node instanceof HTMLElement && acceptFn(node, strict) ? NodeFilter.FILTER_ACCEPT : NodeFilter.FILTER_SKIP
18
+ });
19
+ let nextNode = null; // Allow the container to participate
20
+
21
+ if (!options.reverse && acceptFn(container, strict)) {
22
+ yield container;
23
+ } // If iterating in reverse, continue traversing down into the last child until we reach
24
+ // a leaf DOM node
25
+
26
+
27
+ if (options.reverse) {
28
+ let lastChild = walker.lastChild();
29
+
30
+ while (lastChild) {
31
+ nextNode = lastChild;
32
+ lastChild = walker.lastChild();
33
+ }
34
+ } else {
35
+ nextNode = walker.firstChild();
36
+ }
37
+
38
+ while (nextNode instanceof HTMLElement) {
39
+ yield nextNode;
40
+ nextNode = options.reverse ? walker.previousNode() : walker.nextNode();
41
+ } // Allow the container to participate (in reverse)
42
+
43
+
44
+ if (options.reverse && acceptFn(container, strict)) {
45
+ yield container;
46
+ }
47
+
48
+ return undefined;
49
+ }
50
+ /**
51
+ * Determines whether the given element is focusable. If `strict` is true, we may
52
+ * perform additional checks that require a reflow (less performant).
53
+ * @param elem
54
+ * @param strict
55
+ */
56
+
57
+ export function isFocusable(elem, strict = false) {
58
+ // Certain conditions cause an element to never be focusable, even if they have tabindex="0"
59
+ const disabledAttrInert = ['BUTTON', 'INPUT', 'SELECT', 'TEXTAREA', 'OPTGROUP', 'OPTION', 'FIELDSET'].includes(elem.tagName) && elem.disabled;
60
+ const hiddenInert = elem.hidden;
61
+ const hiddenInputInert = elem instanceof HTMLInputElement && elem.type === 'hidden';
62
+
63
+ if (disabledAttrInert || hiddenInert || hiddenInputInert) {
64
+ return false;
65
+ } // Each of the conditions checked below require a reflow, thus are gated by the `strict`
66
+ // argument. If any are true, the element is not focusable, even if tabindex is set.
67
+
68
+
69
+ if (strict) {
70
+ const sizeInert = elem.offsetWidth === 0 || elem.offsetHeight === 0;
71
+ const visibilityInert = ['hidden', 'collapse'].includes(getComputedStyle(elem).visibility);
72
+ const clientRectsInert = elem.getClientRects().length === 0;
73
+
74
+ if (sizeInert || visibilityInert || clientRectsInert) {
75
+ return false;
76
+ }
77
+ } // Any element with `tabindex` explicitly set can be focusable, even if it's set to "-1"
78
+
79
+
80
+ if (elem.getAttribute('tabindex') != null) {
81
+ return true;
82
+ } // One last way `elem.tabIndex` can be wrong.
83
+
84
+
85
+ if (elem instanceof HTMLAnchorElement && elem.getAttribute('href') == null) {
86
+ return false;
87
+ }
88
+
89
+ return elem.tabIndex !== -1;
90
+ }
91
+ /**
92
+ * Determines whether the given element is tabbable. If `strict` is true, we may
93
+ * perform additional checks that require a reflow (less performant). This check
94
+ * ensures that the element is focusable and that its tabindex is not explicitly
95
+ * set to "-1" (which makes it focusable, but removes it from the tab order).
96
+ * @param elem
97
+ * @param strict
98
+ */
99
+
100
+ export function isTabbable(elem, strict = false) {
101
+ return isFocusable(elem, strict) && elem.getAttribute('tabindex') !== '-1';
102
+ }
@@ -0,0 +1 @@
1
+ export { SSRProvider, useSSRSafeId } from '@react-aria/ssr';
@@ -0,0 +1,17 @@
1
+ import semver from 'semver';
2
+ import { Deprecations } from './deprecate'; // eslint-disable-next-line @typescript-eslint/no-var-requires
3
+
4
+ const ourVersion = require('../../package.json').version;
5
+
6
+ beforeEach(() => {
7
+ Deprecations.clearDeprecations();
8
+ });
9
+ afterEach(() => {
10
+ const deprecations = Deprecations.getDeprecations();
11
+
12
+ for (const dep of deprecations) {
13
+ if (semver.gte(ourVersion, dep.version)) {
14
+ throw new Error(`Found a deprecation that should be removed in ${dep.version}`);
15
+ }
16
+ }
17
+ });
@@ -0,0 +1,7 @@
1
+ // JSDOM doesn't mock ResizeObserver
2
+ global.ResizeObserver = jest.fn().mockImplementation(() => {
3
+ return {
4
+ observe: jest.fn(),
5
+ disconnect: jest.fn()
6
+ };
7
+ });
@@ -0,0 +1,110 @@
1
+ import 'jest-styled-components';
2
+ import { styleSheetSerializer } from 'jest-styled-components/serializer';
3
+ import React from 'react';
4
+ import { getClasses, getComputedStyles, render } from './testing';
5
+ expect.addSnapshotSerializer(styleSheetSerializer);
6
+
7
+ const stringify = d => JSON.stringify(d, null, ' ');
8
+
9
+ expect.extend({
10
+ toMatchKeys(obj, values) {
11
+ return {
12
+ pass: Object.keys(values).every(key => this.equals(obj[key], values[key])),
13
+ message: () => `Expected ${stringify(obj)} to have matching keys: ${stringify(values)}`
14
+ };
15
+ },
16
+
17
+ toHaveClass(node, klass) {
18
+ const classes = getClasses(node);
19
+ const pass = classes.includes(klass);
20
+ return {
21
+ pass,
22
+ message: () => `expected ${stringify(classes)} to include: ${stringify(klass)}`
23
+ };
24
+ },
25
+
26
+ toHaveClasses(node, klasses, only = false) {
27
+ const classes = getClasses(node);
28
+ const pass = only ? this.equals(classes.sort(), klasses.sort()) : klasses.every(klass => classes.includes(klass));
29
+ return {
30
+ pass,
31
+ message: () => `expected ${stringify(classes)} to include: ${stringify(klasses)}`
32
+ };
33
+ },
34
+
35
+ toImplementSxBehavior(element) {
36
+ const mediaKey = '@media (max-width:123px)';
37
+ const sxPropValue = {
38
+ [mediaKey]: {
39
+ color: 'red.5'
40
+ }
41
+ };
42
+ const elem = /*#__PURE__*/React.cloneElement(element, {
43
+ sx: sxPropValue
44
+ });
45
+
46
+ function checkStylesDeep(rendered) {
47
+ const className = rendered.props.className;
48
+ const styles = getComputedStyles(className);
49
+ const mediaStyles = styles[mediaKey];
50
+
51
+ if (mediaStyles && mediaStyles.color) {
52
+ return true;
53
+ } else if (rendered.children) {
54
+ return rendered.children.some(child => checkStylesDeep(child));
55
+ } else {
56
+ return false;
57
+ }
58
+ }
59
+
60
+ return {
61
+ pass: checkStylesDeep(render(elem)),
62
+ message: () => 'sx prop values did not change styles of component nor of any sub-components'
63
+ };
64
+ },
65
+
66
+ toSetExports(mod, expectedExports) {
67
+ if (!Object.keys(expectedExports).includes('default')) {
68
+ return {
69
+ pass: false,
70
+ message: () => "You must specify the module's default export"
71
+ };
72
+ }
73
+
74
+ const seen = new Set();
75
+
76
+ for (const exp of Object.keys(expectedExports)) {
77
+ seen.add(exp);
78
+
79
+ if (mod[exp] !== expectedExports[exp]) {
80
+ if (!mod[exp] && !expectedExports[exp]) {
81
+ continue;
82
+ }
83
+
84
+ return {
85
+ pass: false,
86
+ message: () => `Module exported a different value from key '${exp}' than expected`
87
+ };
88
+ }
89
+ }
90
+
91
+ for (const exp of Object.keys(mod)) {
92
+ if (seen.has(exp)) {
93
+ continue;
94
+ }
95
+
96
+ if (mod[exp] !== expectedExports[exp]) {
97
+ return {
98
+ pass: false,
99
+ message: () => `Module exported an unexpected value from key '${exp}'`
100
+ };
101
+ }
102
+ }
103
+
104
+ return {
105
+ pass: true,
106
+ message: () => ''
107
+ };
108
+ }
109
+
110
+ });
@@ -0,0 +1,222 @@
1
+ import React from 'react';
2
+ import { promisify } from 'util';
3
+ import renderer from 'react-test-renderer';
4
+ import enzyme from 'enzyme';
5
+ import Adapter from '@wojtekmaj/enzyme-adapter-react-17';
6
+ import { ThemeProvider } from '..';
7
+ import { default as defaultTheme } from '../theme';
8
+ // eslint-disable-next-line @typescript-eslint/no-var-requires
9
+ const readFile = promisify(require('fs').readFile);
10
+ export const COMPONENT_DISPLAY_NAME_REGEX = /^[A-Z][A-Za-z]+(\.[A-Z][A-Za-z]+)*$/;
11
+ enzyme.configure({
12
+ adapter: new Adapter()
13
+ });
14
+ export function mount(component) {
15
+ return enzyme.mount(component);
16
+ }
17
+
18
+ /**
19
+ * Render the component (a React.createElement() or JSX expression)
20
+ * into its intermediate object representation with 'type',
21
+ * 'props', and 'children' keys
22
+ *
23
+ * The returned object can be matched with expect().toEqual(), e.g.
24
+ *
25
+ * ```js
26
+ * expect(render(<Foo />)).toEqual(render(<div foo='bar' />))
27
+ * ```
28
+ */
29
+ export function render(component, theme = defaultTheme) {
30
+ return renderer.create( /*#__PURE__*/React.createElement(ThemeProvider, {
31
+ theme: theme
32
+ }, component)).toJSON();
33
+ }
34
+ /**
35
+ * Render the component (a React.createElement() or JSX expression)
36
+ * using react-test-renderer and return the root node
37
+ * ```
38
+ */
39
+
40
+ export function renderRoot(component) {
41
+ return renderer.create(component).root;
42
+ }
43
+ /**
44
+ * Get the HTML class names rendered by the component instance
45
+ * as an array.
46
+ *
47
+ * ```js
48
+ * expect(renderClasses(<div className='a b' />))
49
+ * .toEqual(['a', 'b'])
50
+ * ```
51
+ */
52
+
53
+ export function renderClasses(component) {
54
+ const {
55
+ props: {
56
+ className
57
+ }
58
+ } = render(component);
59
+ return className ? className.trim().split(' ') : [];
60
+ }
61
+ /**
62
+ * Returns true if a node renders with a single class.
63
+ */
64
+
65
+ export function rendersClass(node, klass) {
66
+ return renderClasses(node).includes(klass);
67
+ }
68
+ export function px(value) {
69
+ return typeof value === 'number' ? `${value}px` : value;
70
+ }
71
+ export function percent(value) {
72
+ return typeof value === 'number' ? `${value}%` : value;
73
+ }
74
+ export function renderStyles(node) {
75
+ const {
76
+ props: {
77
+ className
78
+ }
79
+ } = render(node);
80
+ return getComputedStyles(className);
81
+ }
82
+ export function getComputedStyles(className) {
83
+ const div = document.createElement('div');
84
+ div.className = className;
85
+ const computed = {};
86
+
87
+ for (const sheet of document.styleSheets) {
88
+ // CSSRulesLists assumes every rule is a CSSRule, not a CSSStyleRule
89
+ for (const rule of sheet.cssRules) {
90
+ if (rule instanceof CSSMediaRule) {
91
+ readMedia(rule);
92
+ } else if (rule instanceof CSSStyleRule) {
93
+ readRule(rule, computed);
94
+ } else {// console.warn('rule.type =', rule.type)
95
+ }
96
+ }
97
+ }
98
+
99
+ return computed;
100
+
101
+ function matchesSafe(node, selector) {
102
+ if (!selector) {
103
+ return false;
104
+ }
105
+
106
+ try {
107
+ return node.matches(selector);
108
+ } catch (error) {
109
+ return false;
110
+ }
111
+ }
112
+
113
+ function readRule(rule, dest) {
114
+ if (matchesSafe(div, rule.selectorText)) {
115
+ const {
116
+ style
117
+ } = rule;
118
+
119
+ for (let i = 0; i < style.length; i++) {
120
+ const prop = style[i];
121
+ dest[prop] = style.getPropertyValue(prop);
122
+ }
123
+ } else {// console.warn('no match:', rule.selectorText)
124
+ }
125
+ }
126
+
127
+ function readMedia(mediaRule) {
128
+ const key = `@media ${mediaRule.media[0]}`; // const dest = computed[key] || (computed[key] = {})
129
+
130
+ const dest = {};
131
+
132
+ for (const rule of mediaRule.cssRules) {
133
+ if (rule instanceof CSSStyleRule) {
134
+ readRule(rule, dest);
135
+ }
136
+ } // Don't add media rule to computed styles
137
+ // if no styles were actually applied
138
+
139
+
140
+ if (Object.keys(dest).length > 0) {
141
+ computed[key] = dest;
142
+ }
143
+ }
144
+ }
145
+ /**
146
+ * This provides a layer of compatibility between the render() function from
147
+ * react-test-renderer and Enzyme's mount()
148
+ */
149
+
150
+ export function getProps(node) {
151
+ return typeof node.props === 'function' ? node.props() : node.props;
152
+ }
153
+ export function getClassName(node) {
154
+ return getProps(node).className;
155
+ }
156
+ export function getClasses(node) {
157
+ const className = getClassName(node);
158
+ return className ? className.trim().split(/ +/) : [];
159
+ }
160
+ export async function loadCSS(path) {
161
+ const css = await readFile(require.resolve(path), 'utf8');
162
+ const style = document.createElement('style');
163
+ style.setAttribute('data-path', path);
164
+ style.textContent = css;
165
+ document.head.appendChild(style);
166
+ return style;
167
+ }
168
+ export function unloadCSS(path) {
169
+ const style = document.querySelector(`style[data-path="${path}"]`);
170
+
171
+ if (style) {
172
+ style.remove();
173
+ return true;
174
+ }
175
+ } // If a component requires certain props or other conditions in order
176
+ // to render without errors, you can pass a `toRender` function that
177
+ // returns an element ready to be rendered.
178
+
179
+ export function behavesAsComponent({
180
+ Component,
181
+ toRender,
182
+ options
183
+ }) {
184
+ options = options || {};
185
+
186
+ const getElement = () => toRender ? toRender() : /*#__PURE__*/React.createElement(Component, null);
187
+
188
+ if (!options.skipSx) {
189
+ it('implements sx prop behavior', () => {
190
+ expect(getElement()).toImplementSxBehavior();
191
+ });
192
+ }
193
+
194
+ if (!options.skipAs) {
195
+ it('respects the as prop', () => {
196
+ const As = /*#__PURE__*/React.forwardRef((_props, ref) => /*#__PURE__*/React.createElement("div", {
197
+ className: "as-component",
198
+ ref: ref
199
+ }));
200
+ const elem = /*#__PURE__*/React.cloneElement(getElement(), {
201
+ as: As
202
+ });
203
+ expect(render(elem)).toEqual(render( /*#__PURE__*/React.createElement(As, null)));
204
+ });
205
+ }
206
+
207
+ it('sets a valid displayName', () => {
208
+ expect(Component.displayName).toMatch(COMPONENT_DISPLAY_NAME_REGEX);
209
+ });
210
+ it('renders consistently', () => {
211
+ expect(render(getElement())).toMatchSnapshot();
212
+ });
213
+ } // eslint-disable-next-line @typescript-eslint/no-explicit-any
214
+
215
+ export function checkExports(path, exports) {
216
+ it('has declared exports', () => {
217
+ // eslint-disable-next-line @typescript-eslint/no-var-requires
218
+ const mod = require(`../${path}`);
219
+
220
+ expect(mod).toSetExports(exports);
221
+ });
222
+ }
@@ -0,0 +1,66 @@
1
+ // Utility functions used in theme-preval.js
2
+ // This file needs to be a JavaScript file using CommonJS to be compatiable with preval
3
+ const isEmpty = require('lodash.isempty');
4
+
5
+ const isObject = require('lodash.isobject');
6
+
7
+ const chroma = require('chroma-js');
8
+
9
+ function fontStack(fonts) {
10
+ return fonts.map(font => font.includes(' ') ? `"${font}"` : font).join(', ');
11
+ } // The following functions are a temporary measure for splitting shadow values out from the colors object.
12
+ // Eventually, we will push these structural changes upstream to primer/primitives so this data manipulation
13
+ // will not be needed.
14
+
15
+
16
+ function isShadowValue(value) {
17
+ return typeof value === 'string' && /(inset\s|)([0-9.]+(\w*)\s){1,4}(rgb[a]?\(.*\)|\w+)/.test(value);
18
+ }
19
+
20
+ function isColorValue(value) {
21
+ return chroma.valid(value);
22
+ }
23
+
24
+ function filterObject(obj, predicate) {
25
+ if (Array.isArray(obj)) {
26
+ return obj.filter(predicate);
27
+ }
28
+
29
+ return Object.entries(obj).reduce((acc, [key, value]) => {
30
+ if (isObject(value)) {
31
+ const result = filterObject(value, predicate); // Don't include empty objects or arrays
32
+
33
+ if (!isEmpty(result)) {
34
+ acc[key] = result;
35
+ }
36
+ } else if (predicate(value)) {
37
+ acc[key] = value;
38
+ }
39
+
40
+ return acc;
41
+ }, {});
42
+ }
43
+
44
+ function partitionColors(colors) {
45
+ return {
46
+ colors: filterObject(colors, value => isColorValue(value)),
47
+ shadows: filterObject(colors, value => isShadowValue(value))
48
+ };
49
+ }
50
+
51
+ function omitScale(obj) {
52
+ const {
53
+ scale,
54
+ ...rest
55
+ } = obj;
56
+ return rest;
57
+ }
58
+
59
+ module.exports = {
60
+ fontStack,
61
+ isShadowValue,
62
+ isColorValue,
63
+ filterObject,
64
+ partitionColors,
65
+ omitScale
66
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,5 @@
1
+ // Note: uniqueId may be unsafe in SSR contexts if it is used create DOM IDs or otherwise cause a hydration warning. Use useSSRSafeId instead.
2
+ let idSeed = 10000;
3
+ export function uniqueId() {
4
+ return `__primer_id_${idSeed++}`;
5
+ }
@@ -0,0 +1,8 @@
1
+ let isMac = undefined;
2
+ export function isMacOS() {
3
+ if (isMac === undefined) {
4
+ isMac = /^mac/i.test(window.navigator.platform);
5
+ }
6
+
7
+ return isMac;
8
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@primer/components",
3
- "version": "0.0.0-20219421304",
3
+ "version": "0.0.0-202194215436",
4
4
  "description": "Primer react components",
5
5
  "main": "lib/index.js",
6
6
  "module": "lib-esm/index.js",
@@ -58,7 +58,8 @@
58
58
  "classnames": "2.3.1",
59
59
  "deepmerge": "4.2.2",
60
60
  "focus-visible": "5.2.0",
61
- "styled-system": "5.1.5"
61
+ "styled-system": "5.1.5",
62
+ "tinycolor2": "1.4.2"
62
63
  },
63
64
  "devDependencies": {
64
65
  "@babel/cli": "7.14.5",
@@ -90,6 +91,7 @@
90
91
  "@types/jest-axe": "3.5.3",
91
92
  "@types/lodash.isempty": "4.4.6",
92
93
  "@types/lodash.isobject": "3.0.6",
94
+ "@types/tinycolor2": "1.4.3",
93
95
  "@typescript-eslint/eslint-plugin": "4.31.2",
94
96
  "@typescript-eslint/parser": "4.26.1",
95
97
  "@wojtekmaj/enzyme-adapter-react-17": "0.6.3",