@planningcenter/tapestry-react 2.0.0-rc.1 → 2.0.0
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/dist/cjs/DataTable/hooks/useCollapsibleRows.js +1 -1
- package/dist/cjs/Sidebar/Sidebar.js +4 -3
- package/dist/cjs/Table/Table.js +3 -5
- package/dist/cjs/ThemeProvider/ThemeProvider.js +5 -5
- package/dist/cjs/hooks/useConstant.js +23 -0
- package/dist/cjs/system/utils.js +2 -2
- package/dist/cjs/utils.js +3 -3
- package/dist/esm/DataTable/hooks/useCollapsibleRows.js +1 -1
- package/dist/esm/Sidebar/Sidebar.js +4 -2
- package/dist/esm/Table/Table.js +1 -2
- package/dist/esm/ThemeProvider/ThemeProvider.js +1 -1
- package/dist/esm/hooks/useConstant.js +15 -0
- package/dist/esm/system/utils.js +1 -1
- package/dist/esm/utils.js +3 -3
- package/dist/types/hooks/useConstant.d.ts +1 -0
- package/package.json +15 -24
- package/src/DataTable/hooks/useCollapsibleRows.js +1 -1
- package/src/Sidebar/Sidebar.js +7 -5
- package/src/Table/Table.js +1 -2
- package/src/ThemeProvider/ThemeProvider.tsx +1 -1
- package/src/hooks/useConstant.ts +17 -0
- package/src/system/utils.js +1 -1
- package/src/utils.js +3 -3
- package/src/utils.test.js +29 -0
|
@@ -13,7 +13,7 @@ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/de
|
|
|
13
13
|
|
|
14
14
|
var _react = require("react");
|
|
15
15
|
|
|
16
|
-
var _useConstant = _interopRequireDefault(require("
|
|
16
|
+
var _useConstant = _interopRequireDefault(require("../../hooks/useConstant"));
|
|
17
17
|
|
|
18
18
|
var _zustand = _interopRequireDefault(require("zustand"));
|
|
19
19
|
|
|
@@ -15,8 +15,6 @@ var _react = require("react");
|
|
|
15
15
|
|
|
16
16
|
var _reactStickyBox = _interopRequireDefault(require("react-sticky-box"));
|
|
17
17
|
|
|
18
|
-
var _warning = _interopRequireDefault(require("warning"));
|
|
19
|
-
|
|
20
18
|
var _system = require("../system");
|
|
21
19
|
|
|
22
20
|
var _StackView = _interopRequireDefault(require("../StackView"));
|
|
@@ -44,7 +42,10 @@ function Sidebar(_ref) {
|
|
|
44
42
|
}, restProps), (0, _core.jsx)(_reactStickyBox["default"], {
|
|
45
43
|
css: flexColumnCss
|
|
46
44
|
}, _react.Children.map(children, function (child) {
|
|
47
|
-
|
|
45
|
+
if (child && child.type !== Sidebar.List || child && child.type !== Sidebar.Item) {
|
|
46
|
+
console.warn("Invalid component nesting. " + child.type + " cannot appear as a child of <Sidebar>. Only <Sidebar.List/> or <Sidebar.Item/> may be used.");
|
|
47
|
+
}
|
|
48
|
+
|
|
48
49
|
return child;
|
|
49
50
|
})));
|
|
50
51
|
}
|
package/dist/cjs/Table/Table.js
CHANGED
|
@@ -21,9 +21,7 @@ var _react = _interopRequireWildcard(require("react"));
|
|
|
21
21
|
|
|
22
22
|
var _core = require("@emotion/core");
|
|
23
23
|
|
|
24
|
-
var _lodash =
|
|
25
|
-
|
|
26
|
-
var _lodash2 = _interopRequireDefault(require("lodash.snakecase"));
|
|
24
|
+
var _lodash = require("lodash");
|
|
27
25
|
|
|
28
26
|
var _Button = _interopRequireDefault(require("../Button"));
|
|
29
27
|
|
|
@@ -311,13 +309,13 @@ var Table = /*#__PURE__*/function (_PureComponent) {
|
|
|
311
309
|
_proto.getSortOrder = function getSortOrder(_ref3) {
|
|
312
310
|
var columnId = _ref3.columnId,
|
|
313
311
|
direction = _ref3.direction;
|
|
314
|
-
return "" + (direction === Table.ASC ? '' : '-') + (0,
|
|
312
|
+
return "" + (direction === Table.ASC ? '' : '-') + (0, _lodash.snakeCase)(columnId);
|
|
315
313
|
};
|
|
316
314
|
|
|
317
315
|
_proto.parseSortOrder = function parseSortOrder(query) {
|
|
318
316
|
var isDescending = query[0] === '-';
|
|
319
317
|
return {
|
|
320
|
-
columnId: (0, _lodash
|
|
318
|
+
columnId: (0, _lodash.camelCase)(isDescending ? query.substring(1) : query),
|
|
321
319
|
direction: isDescending ? Table.DESC : Table.ASC
|
|
322
320
|
};
|
|
323
321
|
};
|
|
@@ -18,7 +18,7 @@ var _core = require("@emotion/core");
|
|
|
18
18
|
|
|
19
19
|
var _cache = _interopRequireDefault(require("@emotion/cache"));
|
|
20
20
|
|
|
21
|
-
var
|
|
21
|
+
var _lodash = require("lodash");
|
|
22
22
|
|
|
23
23
|
var _defaultTheme = _interopRequireDefault(require("../system/default-theme"));
|
|
24
24
|
|
|
@@ -78,12 +78,12 @@ function mergeThemes(a, b) {
|
|
|
78
78
|
|
|
79
79
|
return _objectSpread(_objectSpread(_objectSpread({}, a), b), {}, {
|
|
80
80
|
button: _objectSpread(_objectSpread(_objectSpread({}, a.button), b.button), {}, {
|
|
81
|
-
themes: (0,
|
|
81
|
+
themes: (0, _lodash.merge)(((_a$button = a.button) == null ? void 0 : _a$button.themes) || {}, ((_b$button = b.button) == null ? void 0 : _b$button.themes) || {})
|
|
82
82
|
}),
|
|
83
|
-
colors: (0,
|
|
83
|
+
colors: (0, _lodash.merge)((0, _system.flattenPalette)(a.colors || {}), (0, _system.flattenPalette)(b.colors || {})),
|
|
84
84
|
spinner: _objectSpread(_objectSpread(_objectSpread({}, a.spinner), b.spinner), {}, {
|
|
85
|
-
sizes: (0,
|
|
86
|
-
thickness: (0,
|
|
85
|
+
sizes: (0, _lodash.merge)(((_a$spinner = a.spinner) == null ? void 0 : _a$spinner.sizes) || {}, ((_b$spinner = b.spinner) == null ? void 0 : _b$spinner.sizes) || {}),
|
|
86
|
+
thickness: (0, _lodash.merge)(((_a$spinner2 = a.spinner) == null ? void 0 : _a$spinner2.thickness) || {}, ((_b$spinner2 = b.spinner) == null ? void 0 : _b$spinner2.thickness) || {})
|
|
87
87
|
})
|
|
88
88
|
});
|
|
89
89
|
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard");
|
|
4
|
+
|
|
5
|
+
exports.__esModule = true;
|
|
6
|
+
exports["default"] = useConstant;
|
|
7
|
+
|
|
8
|
+
var React = _interopRequireWildcard(require("react"));
|
|
9
|
+
|
|
10
|
+
// A copy/paste of the source of the `use-constant` package.
|
|
11
|
+
// https://github.com/Andarist/use-constant/blob/main/src/index.ts
|
|
12
|
+
// This is done to reduce dependencies.
|
|
13
|
+
function useConstant(fn) {
|
|
14
|
+
var ref = React.useRef();
|
|
15
|
+
|
|
16
|
+
if (!ref.current) {
|
|
17
|
+
ref.current = {
|
|
18
|
+
v: fn()
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
return ref.current.v;
|
|
23
|
+
}
|
package/dist/cjs/system/utils.js
CHANGED
|
@@ -24,7 +24,7 @@ var _core = require("@emotion/core");
|
|
|
24
24
|
|
|
25
25
|
var _polished = require("polished");
|
|
26
26
|
|
|
27
|
-
var _lodash =
|
|
27
|
+
var _lodash = require("lodash");
|
|
28
28
|
|
|
29
29
|
var _colors = require("./colors");
|
|
30
30
|
|
|
@@ -161,7 +161,7 @@ function getForegroundColor(color) {
|
|
|
161
161
|
|
|
162
162
|
function useThemeValue(path, defaultValue) {
|
|
163
163
|
var userTheme = (0, _react.useContext)(_core.ThemeContext);
|
|
164
|
-
return path ? (0, _lodash
|
|
164
|
+
return path ? (0, _lodash.get)(userTheme, path, defaultValue || (0, _lodash.get)(_defaultTheme["default"], path)) : userTheme || _defaultTheme["default"];
|
|
165
165
|
}
|
|
166
166
|
|
|
167
167
|
function useThemeProps(path, props) {
|
package/dist/cjs/utils.js
CHANGED
|
@@ -46,7 +46,7 @@ var _react = require("react");
|
|
|
46
46
|
|
|
47
47
|
var _tabbable = require("tabbable");
|
|
48
48
|
|
|
49
|
-
var
|
|
49
|
+
var _lodash = require("lodash");
|
|
50
50
|
|
|
51
51
|
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
|
|
52
52
|
|
|
@@ -785,11 +785,11 @@ function createCSSProperty(key, value) {
|
|
|
785
785
|
createdCSSProperties.add(key);
|
|
786
786
|
}
|
|
787
787
|
|
|
788
|
-
return "--" + (0,
|
|
788
|
+
return "--" + (0, _lodash.kebabCase)(key) + "-" + (0, _lodash.kebabCase)(value);
|
|
789
789
|
}
|
|
790
790
|
|
|
791
791
|
function getCSSProperty(key, value) {
|
|
792
|
-
return key && value ? "var(--" + (0,
|
|
792
|
+
return key && value ? "var(--" + (0, _lodash.kebabCase)(key) + "-" + (0, _lodash.kebabCase)(value) + ")" : undefined;
|
|
793
793
|
}
|
|
794
794
|
|
|
795
795
|
function objectToCSSProperties(themeKey, props) {
|
|
@@ -5,7 +5,7 @@ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (O
|
|
|
5
5
|
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
|
|
6
6
|
|
|
7
7
|
import { createContext, useCallback, useContext, useEffect } from 'react';
|
|
8
|
-
import useConstant from '
|
|
8
|
+
import useConstant from '../../hooks/useConstant';
|
|
9
9
|
import create from 'zustand';
|
|
10
10
|
import { range } from '../../utils';
|
|
11
11
|
export var CollapsibleRowsContext = /*#__PURE__*/createContext(null);
|
|
@@ -7,7 +7,6 @@ import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWith
|
|
|
7
7
|
import { jsx } from '@emotion/core';
|
|
8
8
|
import { Children } from 'react';
|
|
9
9
|
import StickyBox from 'react-sticky-box';
|
|
10
|
-
import warning from 'warning';
|
|
11
10
|
import { css } from '../system';
|
|
12
11
|
import StackView from '../StackView';
|
|
13
12
|
import SidebarList from './SidebarList';
|
|
@@ -29,7 +28,10 @@ function Sidebar(_ref) {
|
|
|
29
28
|
}, restProps), jsx(StickyBox, {
|
|
30
29
|
css: flexColumnCss
|
|
31
30
|
}, Children.map(children, function (child) {
|
|
32
|
-
|
|
31
|
+
if (child && child.type !== Sidebar.List || child && child.type !== Sidebar.Item) {
|
|
32
|
+
console.warn("Invalid component nesting. " + child.type + " cannot appear as a child of <Sidebar>. Only <Sidebar.List/> or <Sidebar.Item/> may be used.");
|
|
33
|
+
}
|
|
34
|
+
|
|
33
35
|
return child;
|
|
34
36
|
})));
|
|
35
37
|
}
|
package/dist/esm/Table/Table.js
CHANGED
|
@@ -10,8 +10,7 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
|
|
|
10
10
|
|
|
11
11
|
import React, { PureComponent, Children, Fragment } from 'react';
|
|
12
12
|
import { Global } from '@emotion/core';
|
|
13
|
-
import camelCase from 'lodash
|
|
14
|
-
import snakeCase from 'lodash.snakecase';
|
|
13
|
+
import { camelCase, snakeCase } from 'lodash';
|
|
15
14
|
import Button from '../Button';
|
|
16
15
|
import DragDrop from '../DragDrop';
|
|
17
16
|
import Pagination from '../Pagination';
|
|
@@ -8,7 +8,7 @@ import React, { useLayoutEffect, useState } from 'react';
|
|
|
8
8
|
import { ThemeProvider as EmotionThemeProvider } from 'emotion-theming';
|
|
9
9
|
import { CacheProvider } from '@emotion/core';
|
|
10
10
|
import createCache from '@emotion/cache';
|
|
11
|
-
import merge from '
|
|
11
|
+
import { merge } from 'lodash';
|
|
12
12
|
import defaultTheme from '../system/default-theme';
|
|
13
13
|
import { flattenPalette } from '../system';
|
|
14
14
|
import { objectToCSSProperties, shallowEqual } from '../utils';
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
// A copy/paste of the source of the `use-constant` package.
|
|
2
|
+
// https://github.com/Andarist/use-constant/blob/main/src/index.ts
|
|
3
|
+
// This is done to reduce dependencies.
|
|
4
|
+
import * as React from 'react';
|
|
5
|
+
export default function useConstant(fn) {
|
|
6
|
+
var ref = React.useRef();
|
|
7
|
+
|
|
8
|
+
if (!ref.current) {
|
|
9
|
+
ref.current = {
|
|
10
|
+
v: fn()
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
return ref.current.v;
|
|
15
|
+
}
|
package/dist/esm/system/utils.js
CHANGED
|
@@ -7,7 +7,7 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
|
|
|
7
7
|
import { useContext, useCallback } from 'react';
|
|
8
8
|
import { ThemeContext } from '@emotion/core';
|
|
9
9
|
import { darken, getLuminance, lighten, parseToRgb } from 'polished';
|
|
10
|
-
import get from 'lodash
|
|
10
|
+
import { get } from 'lodash';
|
|
11
11
|
import { getColor } from './colors';
|
|
12
12
|
import defaultTheme from './default-theme';
|
|
13
13
|
export var spacing = 8;
|
package/dist/esm/utils.js
CHANGED
|
@@ -6,7 +6,7 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
|
|
|
6
6
|
|
|
7
7
|
import { Children, cloneElement } from 'react';
|
|
8
8
|
import { tabbable } from 'tabbable';
|
|
9
|
-
import
|
|
9
|
+
import { kebabCase } from 'lodash';
|
|
10
10
|
/**
|
|
11
11
|
* Returns true if user platform is an iOS device
|
|
12
12
|
* https://stackoverflow.com/a/9039885/1461204
|
|
@@ -737,11 +737,11 @@ function createCSSProperty(key, value) {
|
|
|
737
737
|
createdCSSProperties.add(key);
|
|
738
738
|
}
|
|
739
739
|
|
|
740
|
-
return "--" +
|
|
740
|
+
return "--" + kebabCase(key) + "-" + kebabCase(value);
|
|
741
741
|
}
|
|
742
742
|
|
|
743
743
|
function getCSSProperty(key, value) {
|
|
744
|
-
return key && value ? "var(--" +
|
|
744
|
+
return key && value ? "var(--" + kebabCase(key) + "-" + kebabCase(value) + ")" : undefined;
|
|
745
745
|
}
|
|
746
746
|
|
|
747
747
|
function objectToCSSProperties(themeKey, props) {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function useConstant<T>(fn: () => T): T;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@planningcenter/tapestry-react",
|
|
3
|
-
"version": "2.0.0
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"description": "A collection of flexible React components to help you build resilient, accessible user interfaces quickly and effectively.",
|
|
5
5
|
"author": "Front End Systems Engineering <frontend@pco.bz>",
|
|
6
6
|
"main": "dist/cjs/index.js",
|
|
@@ -57,8 +57,10 @@
|
|
|
57
57
|
"@babel/preset-typescript": "^7.12.17",
|
|
58
58
|
"@emotion/cache": "10.0.29",
|
|
59
59
|
"@emotion/core": "10.0.35",
|
|
60
|
+
"@testing-library/jest-dom": "^5.11.9",
|
|
60
61
|
"@testing-library/react": "^11.2.5",
|
|
61
62
|
"@testing-library/react-hooks": "5.0.3",
|
|
63
|
+
"@testing-library/user-event": "^13.1.9",
|
|
62
64
|
"@types/jest": "^26.0.20",
|
|
63
65
|
"babel-eslint": "10.1.0",
|
|
64
66
|
"chokidar-cli": "^2.1.0",
|
|
@@ -83,41 +85,30 @@
|
|
|
83
85
|
"react-dom": "^17.0.1",
|
|
84
86
|
"react-test-renderer": "17.0.1",
|
|
85
87
|
"rimraf": "3.0.2",
|
|
86
|
-
"semantic-release": "
|
|
88
|
+
"semantic-release": "19.0.3",
|
|
87
89
|
"svgo": "^2.1.0",
|
|
88
90
|
"svgson": "4.1.0",
|
|
91
|
+
"type-fest": "^0.21.1",
|
|
89
92
|
"typescript": "^4.1.5"
|
|
90
93
|
},
|
|
91
94
|
"dependencies": {
|
|
92
95
|
"@planningcenter/icons": "^14.0.0",
|
|
93
96
|
"@popmotion/popcorn": "^0.4.4",
|
|
94
|
-
"@popperjs/core": "
|
|
95
|
-
"
|
|
96
|
-
"@testing-library/user-event": "^13.1.9",
|
|
97
|
-
"camel-to-kebab": "^1.1.0",
|
|
98
|
-
"csstype": "^3.0.6",
|
|
99
|
-
"date-fns": "^2.17.0",
|
|
100
|
-
"deepmerge": "^4.2.2",
|
|
97
|
+
"@popperjs/core": "^2.11.6",
|
|
98
|
+
"date-fns": "^2.29.2",
|
|
101
99
|
"focus-options-polyfill": "^1.6.0",
|
|
102
100
|
"focus-visible": "^5.2.0",
|
|
103
|
-
"lodash
|
|
104
|
-
"
|
|
105
|
-
"
|
|
106
|
-
"match-sorter": "^6.2.0",
|
|
107
|
-
"mitt": "^2.1.0",
|
|
101
|
+
"lodash": "^4.17.21",
|
|
102
|
+
"match-sorter": "^6.3.1",
|
|
103
|
+
"mitt": "^3.0.0",
|
|
108
104
|
"mousetrap": "^1.6.5",
|
|
109
|
-
"polished": "^4.
|
|
105
|
+
"polished": "^4.2.2",
|
|
110
106
|
"popper-max-size-modifier": "^0.2.0",
|
|
111
|
-
"react-beautiful-dnd": "^13.
|
|
112
|
-
"react-sticky-box": "^0.
|
|
113
|
-
"resize-observer-polyfill": "^1.5.1",
|
|
107
|
+
"react-beautiful-dnd": "^13.1.0",
|
|
108
|
+
"react-sticky-box": "^1.0.2",
|
|
114
109
|
"stylefire": "^7.0.3",
|
|
115
|
-
"tabbable": "
|
|
116
|
-
"tiny-invariant": "^1.1.0",
|
|
110
|
+
"tabbable": "^6.0.0",
|
|
117
111
|
"tiny-spring": "^1.0.0",
|
|
118
|
-
"
|
|
119
|
-
"use-constant": "^1.1.0",
|
|
120
|
-
"warning": "^4.0.3",
|
|
121
|
-
"zustand": "^3.3.2"
|
|
112
|
+
"zustand": "^4.1.1"
|
|
122
113
|
}
|
|
123
114
|
}
|
package/src/Sidebar/Sidebar.js
CHANGED
|
@@ -4,7 +4,6 @@
|
|
|
4
4
|
import { jsx } from '@emotion/core'
|
|
5
5
|
import { Children } from 'react'
|
|
6
6
|
import StickyBox from 'react-sticky-box'
|
|
7
|
-
import warning from 'warning'
|
|
8
7
|
|
|
9
8
|
import { css } from '../system'
|
|
10
9
|
import StackView from '../StackView'
|
|
@@ -30,11 +29,14 @@ function Sidebar({ children, ...restProps }: Props) {
|
|
|
30
29
|
>
|
|
31
30
|
<StickyBox css={flexColumnCss}>
|
|
32
31
|
{Children.map(children, (child) => {
|
|
33
|
-
|
|
32
|
+
if (
|
|
34
33
|
(child && child.type !== Sidebar.List) ||
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
34
|
+
(child && child.type !== Sidebar.Item)
|
|
35
|
+
) {
|
|
36
|
+
console.warn(
|
|
37
|
+
`Invalid component nesting. ${child.type} cannot appear as a child of <Sidebar>. Only <Sidebar.List/> or <Sidebar.Item/> may be used.`
|
|
38
|
+
)
|
|
39
|
+
}
|
|
38
40
|
return child
|
|
39
41
|
})}
|
|
40
42
|
</StickyBox>
|
package/src/Table/Table.js
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
// @flow
|
|
2
2
|
import React, { PureComponent, Children, Fragment } from 'react'
|
|
3
3
|
import { Global } from '@emotion/core'
|
|
4
|
-
import camelCase from 'lodash
|
|
5
|
-
import snakeCase from 'lodash.snakecase'
|
|
4
|
+
import { camelCase, snakeCase } from 'lodash'
|
|
6
5
|
|
|
7
6
|
import type { PaginationProps } from '../Pagination/Pagination'
|
|
8
7
|
|
|
@@ -2,7 +2,7 @@ import React, { useLayoutEffect, useState } from 'react'
|
|
|
2
2
|
import { ThemeProvider as EmotionThemeProvider } from 'emotion-theming'
|
|
3
3
|
import { CacheProvider } from '@emotion/core'
|
|
4
4
|
import createCache from '@emotion/cache'
|
|
5
|
-
import merge from '
|
|
5
|
+
import { merge } from 'lodash'
|
|
6
6
|
|
|
7
7
|
import defaultTheme from '../system/default-theme'
|
|
8
8
|
import { flattenPalette } from '../system'
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
// A copy/paste of the source of the `use-constant` package.
|
|
2
|
+
// https://github.com/Andarist/use-constant/blob/main/src/index.ts
|
|
3
|
+
// This is done to reduce dependencies.
|
|
4
|
+
|
|
5
|
+
import * as React from 'react'
|
|
6
|
+
|
|
7
|
+
type ResultBox<T> = { v: T }
|
|
8
|
+
|
|
9
|
+
export default function useConstant<T>(fn: () => T): T {
|
|
10
|
+
const ref = React.useRef<ResultBox<T>>()
|
|
11
|
+
|
|
12
|
+
if (!ref.current) {
|
|
13
|
+
ref.current = { v: fn() }
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
return ref.current.v
|
|
17
|
+
}
|
package/src/system/utils.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { useContext, useCallback } from 'react'
|
|
2
2
|
import { ThemeContext } from '@emotion/core'
|
|
3
3
|
import { darken, getLuminance, lighten, parseToRgb } from 'polished'
|
|
4
|
-
import get from 'lodash
|
|
4
|
+
import { get } from 'lodash'
|
|
5
5
|
|
|
6
6
|
import { getColor } from './colors'
|
|
7
7
|
import defaultTheme from './default-theme'
|
package/src/utils.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Children, cloneElement } from 'react'
|
|
2
2
|
import { tabbable } from 'tabbable'
|
|
3
|
-
import
|
|
3
|
+
import { kebabCase } from 'lodash'
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* Returns true if user platform is an iOS device
|
|
@@ -682,12 +682,12 @@ function createCSSProperty(key, value) {
|
|
|
682
682
|
if (!createdCSSProperties.has(key)) {
|
|
683
683
|
createdCSSProperties.add(key)
|
|
684
684
|
}
|
|
685
|
-
return `--${
|
|
685
|
+
return `--${kebabCase(key)}-${kebabCase(value)}`
|
|
686
686
|
}
|
|
687
687
|
|
|
688
688
|
function getCSSProperty(key, value) {
|
|
689
689
|
return key && value
|
|
690
|
-
? `var(--${
|
|
690
|
+
? `var(--${kebabCase(key)}-${kebabCase(value)})`
|
|
691
691
|
: undefined
|
|
692
692
|
}
|
|
693
693
|
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { createCSSProperty, getCSSProperty } from './utils'
|
|
2
|
+
|
|
3
|
+
describe('createCSSProperty', () => {
|
|
4
|
+
test('kebab cases the key and value', () => {
|
|
5
|
+
expect(createCSSProperty('theCamelCasedKey', 'theCamelCasedValue')).toEqual(
|
|
6
|
+
'--the-camel-cased-key-the-camel-cased-value'
|
|
7
|
+
)
|
|
8
|
+
})
|
|
9
|
+
|
|
10
|
+
test("does not mess with already kebab'd keys and values", () => {
|
|
11
|
+
expect(
|
|
12
|
+
createCSSProperty('mixedCamel-and-kebab', 'only-kebab-case')
|
|
13
|
+
).toEqual('--mixed-camel-and-kebab-only-kebab-case')
|
|
14
|
+
})
|
|
15
|
+
})
|
|
16
|
+
|
|
17
|
+
describe('getCSSProperty', () => {
|
|
18
|
+
test('kebab cases the key and value', () => {
|
|
19
|
+
expect(getCSSProperty('theCamelCasedKey', 'theCamelCasedValue')).toEqual(
|
|
20
|
+
'var(--the-camel-cased-key-the-camel-cased-value)'
|
|
21
|
+
)
|
|
22
|
+
})
|
|
23
|
+
|
|
24
|
+
test("does not mess with already kebab'd keys and values", () => {
|
|
25
|
+
expect(getCSSProperty('mixedCamel-and-kebab', 'only-kebab-case')).toEqual(
|
|
26
|
+
'var(--mixed-camel-and-kebab-only-kebab-case)'
|
|
27
|
+
)
|
|
28
|
+
})
|
|
29
|
+
})
|