reshaped 2.2.0 → 2.3.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/CHANGELOG.md +19 -12
- package/LICENSE-SOURCE.md +40 -0
- package/LICENSE.md +21 -37
- package/bin/clean.sh +1 -0
- package/bin/cli.js +1 -11
- package/bin/release-source.sh +7 -0
- package/bundle.css +1 -1
- package/bundle.js +10 -10
- package/cli/theming/definitions/base.d.ts +1 -1
- package/cli/theming/definitions/figma.d.ts +1 -1
- package/cli/theming/definitions/reshaped.d.ts +1 -1
- package/cli/theming/definitions/slate.d.ts +1 -1
- package/cli/theming/index.d.ts +4 -4
- package/cli/theming/index.js +7 -107
- package/components/Actionable/Actionable.js +14 -3
- package/components/Actionable/Actionable.module.css +1 -1
- package/components/Autocomplete/tests/Autocomplete.stories.js +27 -1
- package/components/Button/Button.js +2 -0
- package/components/Button/Button.module.css +1 -1
- package/components/Button/Button.types.d.ts +6 -0
- package/components/Button/ButtonGroup.d.ts +4 -0
- package/components/Button/ButtonGroup.js +9 -0
- package/components/Button/tests/Button.stories.d.ts +1 -0
- package/components/Button/tests/Button.stories.js +63 -0
- package/components/Checkbox/Checkbox.module.css +1 -1
- package/components/DropdownMenu/DropdownMenu.js +1 -1
- package/components/DropdownMenu/tests/DropdownMenu.stories.js +1 -0
- package/components/Overlay/Overlay.js +4 -4
- package/components/Radio/Radio.module.css +1 -1
- package/components/Select/Select.js +1 -1
- package/components/Slider/Slider.module.css +1 -1
- package/components/Switch/Switch.module.css +1 -1
- package/components/Tabs/Tabs.d.ts +1 -8
- package/components/Tabs/Tabs.module.css +1 -1
- package/components/Tabs/Tabs.types.d.ts +6 -7
- package/components/Tabs/TabsContext.d.ts +4 -0
- package/components/Tabs/TabsControlled.js +24 -1
- package/components/Tabs/TabsItem.d.ts +1 -8
- package/components/Tabs/TabsItem.js +22 -4
- package/components/Tabs/TabsList.js +30 -32
- package/components/Tabs/tests/Tabs.stories.d.ts +1 -0
- package/components/Tabs/tests/Tabs.stories.js +17 -0
- package/components/Toast/ToastContainer.js +1 -0
- package/components/Toast/ToastProvider.js +4 -0
- package/components/Toast/tests/Toast.stories.js +1 -0
- package/components/_private/Flyout/Flyout.types.d.ts +2 -0
- package/components/_private/Flyout/FlyoutContent.js +7 -3
- package/components/_private/Flyout/FlyoutControlled.js +8 -1
- package/components/_private/Flyout/tests/Flyout.stories.d.ts +1 -0
- package/components/_private/Flyout/tests/Flyout.stories.js +25 -0
- package/components/_private/Portal/Portal.d.ts +8 -4
- package/components/_private/Portal/Portal.js +23 -11
- package/components/_private/Portal/Portal.types.d.ts +7 -2
- package/components/_private/Portal/index.d.ts +1 -1
- package/components/_private/Portal/index.js +1 -1
- package/components/_private/Portal/tests/Portal.stories.js +11 -12
- package/config/next.d.ts +4 -5
- package/config/next.js +21 -7
- package/config/tailwind.d.ts +1 -1
- package/config/tailwind.js +3 -3
- package/hooks/_private/useFlyout.js +16 -13
- package/package.json +39 -31
- package/themes/_generator/tests/themes.stories.d.ts +6 -0
- package/themes/_generator/tests/themes.stories.js +32 -0
- package/{cli/theming → themes/_generator}/tokens/color/color.transforms.d.ts +1 -1
- package/{cli/theming → themes/_generator}/tokens/duration/duration.transforms.d.ts +1 -1
- package/{cli/theming → themes/_generator}/tokens/easing/easing.transforms.d.ts +1 -1
- package/{cli/theming → themes/_generator}/tokens/font/font.transforms.d.ts +1 -1
- package/{cli/theming → themes/_generator}/tokens/fontFamily/fontFamily.transforms.d.ts +1 -1
- package/{cli/theming → themes/_generator}/tokens/fontWeight/fontWeight.transforms.d.ts +1 -1
- package/{cli/theming → themes/_generator}/tokens/shadow/shadow.transforms.d.ts +1 -1
- package/{cli/theming → themes/_generator}/tokens/shadow/shadow.transforms.js +1 -1
- package/{cli/theming → themes/_generator}/tokens/unit/unit.transforms.d.ts +1 -1
- package/{cli/theming → themes/_generator}/tokens/viewport/viewport.transforms.d.ts +1 -1
- package/themes/_generator/transform.d.ts +7 -0
- package/themes/_generator/transform.js +57 -0
- package/{cli/theming → themes/_generator}/types.d.ts +3 -1
- package/{cli/theming → themes/_generator}/utilities/css.js +3 -1
- package/themes/_generator/utilities/generateBackgroundColors.d.ts +4 -0
- package/themes/_generator/utilities/generateBackgroundColors.js +54 -0
- package/themes/_generator/utilities/generateUnits.d.ts +4 -0
- package/themes/_generator/utilities/generateUnits.js +17 -0
- package/{cli/theming → themes/_generator}/utilities/mergeDeep.js +1 -3
- package/{cli/theming → themes/_generator}/utilities/resolveTokenReference.js +1 -3
- package/themes/index.d.ts +3 -0
- package/themes/index.js +5 -0
- package/types/config.d.ts +1 -1
- package/utilities/a11y.js +12 -3
- package/{cli/utilities → utilities}/color.d.ts +1 -1
- package/utilities/dom.d.ts +1 -0
- package/utilities/dom.js +9 -0
- package/cli/theming/definitions/minimal.d.ts +0 -3
- package/cli/theming/definitions/minimal.js +0 -80
- package/cli/utilities/tests/color.test.d.ts +0 -1
- package/cli/utilities/tests/color.test.js +0 -63
- package/styles/aspectRatio/index.test.d.ts +0 -1
- package/styles/aspectRatio/index.test.js +0 -24
- package/styles/bleed/index.test.d.ts +0 -1
- package/styles/bleed/index.test.js +0 -24
- package/styles/height/index.test.d.ts +0 -1
- package/styles/height/index.test.js +0 -27
- package/styles/inset/index.test.d.ts +0 -1
- package/styles/inset/index.test.js +0 -27
- package/styles/maxHeight/index.test.d.ts +0 -1
- package/styles/maxHeight/index.test.js +0 -27
- package/styles/maxWidth/index.test.d.ts +0 -1
- package/styles/maxWidth/index.test.js +0 -27
- package/styles/padding/index.test.d.ts +0 -1
- package/styles/padding/index.test.js +0 -24
- package/styles/position/index.test.d.ts +0 -1
- package/styles/position/index.test.js +0 -21
- package/styles/radius/index.test.d.ts +0 -1
- package/styles/radius/index.test.js +0 -24
- package/styles/width/index.test.d.ts +0 -1
- package/styles/width/index.test.js +0 -27
- package/themes/minimal/theme.css +0 -1
- package/utilities/testPresets.d.ts +0 -25
- package/utilities/testPresets.js +0 -76
- package/utilities/tests/Chain.test.d.ts +0 -1
- package/utilities/tests/Chain.test.js +0 -45
- /package/bin/{copy-release.sh → release-copy.sh} +0 -0
- /package/{cli/theming → themes/_generator}/tokens/color/color.transforms.js +0 -0
- /package/{cli/theming → themes/_generator}/tokens/color/color.types.d.ts +0 -0
- /package/{cli/theming → themes/_generator}/tokens/color/color.types.js +0 -0
- /package/{cli/theming → themes/_generator}/tokens/duration/duration.transforms.js +0 -0
- /package/{cli/theming → themes/_generator}/tokens/duration/duration.types.d.ts +0 -0
- /package/{cli/theming → themes/_generator}/tokens/duration/duration.types.js +0 -0
- /package/{cli/theming → themes/_generator}/tokens/easing/easing.transforms.js +0 -0
- /package/{cli/theming → themes/_generator}/tokens/easing/easing.types.d.ts +0 -0
- /package/{cli/theming → themes/_generator}/tokens/easing/easing.types.js +0 -0
- /package/{cli/theming → themes/_generator}/tokens/font/font.transforms.js +0 -0
- /package/{cli/theming → themes/_generator}/tokens/font/font.types.d.ts +0 -0
- /package/{cli/theming → themes/_generator}/tokens/font/font.types.js +0 -0
- /package/{cli/theming → themes/_generator}/tokens/fontFamily/fontFamily.transforms.js +0 -0
- /package/{cli/theming → themes/_generator}/tokens/fontFamily/fontFamily.types.d.ts +0 -0
- /package/{cli/theming → themes/_generator}/tokens/fontFamily/fontFamily.types.js +0 -0
- /package/{cli/theming → themes/_generator}/tokens/fontWeight/fontWeight.transforms.js +0 -0
- /package/{cli/theming → themes/_generator}/tokens/fontWeight/fontWeight.types.d.ts +0 -0
- /package/{cli/theming → themes/_generator}/tokens/fontWeight/fontWeight.types.js +0 -0
- /package/{cli/theming → themes/_generator}/tokens/shadow/shadow.types.d.ts +0 -0
- /package/{cli/theming → themes/_generator}/tokens/shadow/shadow.types.js +0 -0
- /package/{cli/theming → themes/_generator}/tokens/transforms.d.ts +0 -0
- /package/{cli/theming → themes/_generator}/tokens/transforms.js +0 -0
- /package/{cli/theming → themes/_generator}/tokens/types.d.ts +0 -0
- /package/{cli/theming → themes/_generator}/tokens/types.js +0 -0
- /package/{cli/theming → themes/_generator}/tokens/unit/unit.transforms.js +0 -0
- /package/{cli/theming → themes/_generator}/tokens/unit/unit.types.d.ts +0 -0
- /package/{cli/theming → themes/_generator}/tokens/unit/unit.types.js +0 -0
- /package/{cli/theming → themes/_generator}/tokens/viewport/viewport.transforms.js +0 -0
- /package/{cli/theming → themes/_generator}/tokens/viewport/viewport.types.d.ts +0 -0
- /package/{cli/theming → themes/_generator}/tokens/viewport/viewport.types.js +0 -0
- /package/{cli/theming → themes/_generator}/types.js +0 -0
- /package/{cli/theming → themes/_generator}/utilities/css.d.ts +0 -0
- /package/{cli/theming → themes/_generator}/utilities/mergeDeep.d.ts +0 -0
- /package/{cli/theming → themes/_generator}/utilities/mergeDefinitions.d.ts +0 -0
- /package/{cli/theming → themes/_generator}/utilities/mergeDefinitions.js +0 -0
- /package/{cli/theming → themes/_generator}/utilities/resolveTokenReference.d.ts +0 -0
- /package/{cli/utilities → utilities}/color.js +0 -0
- /package/{cli/utilities → utilities}/string.d.ts +0 -0
- /package/{cli/utilities → utilities}/string.js +0 -0
@@ -3,16 +3,15 @@ import Portal from "../index.js";
|
|
3
3
|
export default { title: "Utilities/Internal/Portal" };
|
4
4
|
export const base = () => {
|
5
5
|
const ref = React.useRef(null);
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
</div>);
|
6
|
+
const [mounted, setMounted] = React.useState(false);
|
7
|
+
React.useEffect(() => {
|
8
|
+
setMounted(true);
|
9
|
+
}, []);
|
10
|
+
return (<>
|
11
|
+
<div style={{ border: "2px solid #333", padding: 16 }}>
|
12
|
+
App
|
13
|
+
{mounted && <Portal targetRef={ref}>Ported to green</Portal>}
|
14
|
+
</div>
|
15
|
+
<div ref={ref} style={{ border: "2px solid green", padding: 16 }}/>
|
16
|
+
</>);
|
18
17
|
};
|
package/config/next.d.ts
CHANGED
@@ -1,5 +1,4 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
};
|
1
|
+
/**
|
2
|
+
* TODO: Work in progress
|
3
|
+
* Needs named exports support before we can use it
|
4
|
+
*/
|
package/config/next.js
CHANGED
@@ -1,8 +1,22 @@
|
|
1
1
|
"use strict";
|
2
|
-
|
3
|
-
|
4
|
-
exports
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
2
|
+
/**
|
3
|
+
* TODO: Work in progress
|
4
|
+
* Needs named exports support before we can use it
|
5
|
+
*/
|
6
|
+
// export const config = {
|
7
|
+
// modularizeImports: {
|
8
|
+
// reshaped: {
|
9
|
+
// transform: {
|
10
|
+
// // Utilities
|
11
|
+
// // classNames: "reshaped/utilities/classNames",
|
12
|
+
// // Hooks
|
13
|
+
// useToast: "reshaped/components/Toast",
|
14
|
+
// useFormControl: "reshaped/components/FormControl",
|
15
|
+
// useTheme: "reshaped/components/Theme",
|
16
|
+
// "use.*": "reshaped/hooks/{{ member }}",
|
17
|
+
// // Components
|
18
|
+
// "*": "reshaped/components/{{ member }}",
|
19
|
+
// },
|
20
|
+
// },
|
21
|
+
// },
|
22
|
+
// };
|
package/config/tailwind.d.ts
CHANGED
@@ -1,2 +1,2 @@
|
|
1
|
-
import { UserThemeDefinition } from "../
|
1
|
+
import { UserThemeDefinition } from "../themes/_generator/tokens/types";
|
2
2
|
export declare const getTheme: (theme?: UserThemeDefinition) => Record<"backgroundColor" | "textColor" | "borderColor" | "colors" | "borderRadius" | "spacing" | "boxShadow" | "screens", Record<string, string>>;
|
package/config/tailwind.js
CHANGED
@@ -6,9 +6,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.getTheme = void 0;
|
7
7
|
const reshaped_1 = __importDefault(require("../cli/theming/definitions/reshaped"));
|
8
8
|
const base_1 = __importDefault(require("../cli/theming/definitions/base"));
|
9
|
-
const string_1 = require("../
|
10
|
-
const color_1 = require("../
|
11
|
-
const mergeDefinitions_1 = __importDefault(require("../
|
9
|
+
const string_1 = require("../utilities/string");
|
10
|
+
const color_1 = require("../utilities/color");
|
11
|
+
const mergeDefinitions_1 = __importDefault(require("../themes/_generator/utilities/mergeDefinitions"));
|
12
12
|
const getTheme = (theme) => {
|
13
13
|
const config = {
|
14
14
|
backgroundColor: {},
|
@@ -1,7 +1,7 @@
|
|
1
1
|
import React from "react";
|
2
2
|
import useRTL from "../useRTL.js";
|
3
|
-
import { usePortal } from "../../components/_private/Portal/index.js";
|
4
3
|
import { onNextFrame } from "../../utilities/animation.js";
|
4
|
+
import { getClosestScrollableParent } from "../../utilities/dom.js";
|
5
5
|
const SCREEN_OFFSET = 16;
|
6
6
|
const topPos = ["top-start", "top", "top-end"];
|
7
7
|
const bottomPos = ["bottom-start", "bottom", "bottom-end"];
|
@@ -51,8 +51,8 @@ const fullyVisible = (bounds) => {
|
|
51
51
|
/**
|
52
52
|
* Calculate styles for the current position
|
53
53
|
*/
|
54
|
-
const calculatePosition = (originBounds, targetBounds, options) => {
|
55
|
-
const { position: passedPosition, rtl, width
|
54
|
+
const calculatePosition = (originBounds, targetBounds, parentOffset, options) => {
|
55
|
+
const { position: passedPosition, rtl, width } = options;
|
56
56
|
let left = 0;
|
57
57
|
let top = 0;
|
58
58
|
let position = passedPosition;
|
@@ -116,9 +116,8 @@ const calculatePosition = (originBounds, targetBounds, options) => {
|
|
116
116
|
if (top === undefined || left === undefined) {
|
117
117
|
throw Error(`[Reshaped, flyout]: ${position} position is not valid`);
|
118
118
|
}
|
119
|
-
|
120
|
-
|
121
|
-
left = Math.round(left + (isInsidePortal ? 0 : window.pageXOffset || 0));
|
119
|
+
top = Math.round(top + (window.scrollY || 0) - parentOffset.top);
|
120
|
+
left = Math.round(left + (window.scrollX || 0) - parentOffset.left);
|
122
121
|
let widthStyle = Math.ceil(targetBounds.width);
|
123
122
|
const height = Math.ceil(targetBounds.height);
|
124
123
|
if (width === "full") {
|
@@ -175,7 +174,13 @@ const flyout = (origin, target, options) => {
|
|
175
174
|
}
|
176
175
|
document.body.appendChild(targetClone);
|
177
176
|
const targetBounds = targetClone.getBoundingClientRect();
|
178
|
-
|
177
|
+
const scrollableParent = getClosestScrollableParent(origin);
|
178
|
+
const boundsDelta = scrollableParent.getBoundingClientRect();
|
179
|
+
const parentOffset = {
|
180
|
+
top: boundsDelta.top + document.documentElement.scrollTop - scrollableParent.scrollTop,
|
181
|
+
left: boundsDelta.left + document.documentElement.scrollLeft - scrollableParent.scrollLeft,
|
182
|
+
};
|
183
|
+
let calculated = calculatePosition(originBounds, targetBounds, parentOffset, options);
|
179
184
|
if (!fullyVisible(calculated.styles) && !forcePosition) {
|
180
185
|
const order = getPositionOrder(position);
|
181
186
|
const mobileOrder = order.filter((position) => position === "top" || position === "bottom");
|
@@ -183,7 +188,7 @@ const flyout = (origin, target, options) => {
|
|
183
188
|
const { fullWidth } = extraOptions;
|
184
189
|
testOrder.some((currentPosition) => {
|
185
190
|
const calculateOptions = Object.assign(Object.assign({}, options), { width: fullWidth ? "full" : options.width, position: currentPosition });
|
186
|
-
const tested = calculatePosition(originBounds, targetBounds, calculateOptions);
|
191
|
+
const tested = calculatePosition(originBounds, targetBounds, parentOffset, calculateOptions);
|
187
192
|
if (fullyVisible(tested.styles)) {
|
188
193
|
calculated = tested;
|
189
194
|
return true;
|
@@ -202,7 +207,8 @@ const flyout = (origin, target, options) => {
|
|
202
207
|
const flyoutReducer = (state, action) => {
|
203
208
|
switch (action.type) {
|
204
209
|
case "render":
|
205
|
-
|
210
|
+
// Disable events before it's positioned to avoid mouseleave getting triggered
|
211
|
+
return Object.assign(Object.assign({}, state), { status: "rendered", styles: { pointerEvents: "none" } });
|
206
212
|
case "position":
|
207
213
|
return Object.assign(Object.assign({}, state), { status: state.status === "visible" ? "visible" : "positioned", position: action.payload.position, styles: Object.assign(Object.assign({}, defaultStyles), action.payload.styles) });
|
208
214
|
case "show":
|
@@ -217,8 +223,6 @@ const flyoutReducer = (state, action) => {
|
|
217
223
|
};
|
218
224
|
const useFlyout = (originRef, targetRef, options) => {
|
219
225
|
const { position: defaultPosition = "bottom", forcePosition, width } = options;
|
220
|
-
const { scopeRef } = usePortal();
|
221
|
-
const isInsidePortal = !!(scopeRef === null || scopeRef === void 0 ? void 0 : scopeRef.current);
|
222
226
|
const [isRTL] = useRTL();
|
223
227
|
const [state, dispatch] = React.useReducer(flyoutReducer, {
|
224
228
|
position: defaultPosition,
|
@@ -245,10 +249,9 @@ const useFlyout = (originRef, targetRef, options) => {
|
|
245
249
|
position: defaultPosition,
|
246
250
|
forcePosition,
|
247
251
|
rtl: isRTL,
|
248
|
-
isInsidePortal,
|
249
252
|
});
|
250
253
|
dispatch({ type: "position", payload: nextFlyoutData });
|
251
|
-
}, [originRef, targetRef, defaultPosition, isRTL, forcePosition, width
|
254
|
+
}, [originRef, targetRef, defaultPosition, isRTL, forcePosition, width]);
|
252
255
|
React.useEffect(() => {
|
253
256
|
if (state.status === "rendered")
|
254
257
|
updatePosition();
|
package/package.json
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
{
|
2
2
|
"name": "reshaped",
|
3
3
|
"description": "Professionally crafted design system in React & Figma for building products of any scale and complexity",
|
4
|
-
"version": "2.
|
4
|
+
"version": "2.3.0",
|
5
5
|
"license": "SEE LICENSE IN LICENSE.md",
|
6
6
|
"email": "hello@reshaped.so",
|
7
7
|
"homepage": "https://reshaped.so",
|
@@ -65,8 +65,8 @@
|
|
65
65
|
"release:lib": "yarn build && yarn publish",
|
66
66
|
"release:beta": "yarn build && yarn publish --tag beta",
|
67
67
|
"release:test": "yarn build && yarn pack --filename reshaped-test.tgz",
|
68
|
-
"release:source": "
|
69
|
-
"release:copy": "sh ./bin/copy
|
68
|
+
"release:source": "sh ./bin/release-source.sh",
|
69
|
+
"release:copy": "sh ./bin/release-copy.sh",
|
70
70
|
"chromatic": "chromatic -b build:chromatic --project-token=$(cat .chromatic)",
|
71
71
|
"test:vrt": "yarn chromatic",
|
72
72
|
"test:unit": "jest --config tools/jest/jest.config.js",
|
@@ -79,53 +79,53 @@
|
|
79
79
|
"defaults and not IE 11"
|
80
80
|
],
|
81
81
|
"devDependencies": {
|
82
|
-
"@size-limit/preset-big-lib": "
|
83
|
-
"@storybook/addon-a11y": "7.
|
84
|
-
"@storybook/react": "7.
|
85
|
-
"@storybook/react-vite": "7.
|
86
|
-
"@testing-library/jest-dom": "
|
82
|
+
"@size-limit/preset-big-lib": "9.0.0",
|
83
|
+
"@storybook/addon-a11y": "7.4.0",
|
84
|
+
"@storybook/react": "7.4.0",
|
85
|
+
"@storybook/react-vite": "7.4.0",
|
86
|
+
"@testing-library/jest-dom": "6.1.3",
|
87
87
|
"@testing-library/react": "14.0.0",
|
88
88
|
"@testing-library/user-event": "14.4.3",
|
89
89
|
"@types/events": "3.0.0",
|
90
|
-
"@types/jest": "29.5.
|
91
|
-
"@types/node": "20.
|
92
|
-
"@types/react": "18.2.
|
90
|
+
"@types/jest": "29.5.4",
|
91
|
+
"@types/node": "20.6.0",
|
92
|
+
"@types/react": "18.2.21",
|
93
93
|
"@types/react-dom": "18.2.7",
|
94
|
-
"@typescript-eslint/eslint-plugin": "6.
|
95
|
-
"@typescript-eslint/parser": "6.
|
94
|
+
"@typescript-eslint/eslint-plugin": "6.6.0",
|
95
|
+
"@typescript-eslint/parser": "6.6.0",
|
96
96
|
"@vitejs/plugin-react": "4.0.4",
|
97
|
-
"chromatic": "
|
98
|
-
"eslint": "8.
|
97
|
+
"chromatic": "7.1.0",
|
98
|
+
"eslint": "8.49.0",
|
99
99
|
"eslint-config-airbnb-typescript": "17.1.0",
|
100
|
-
"eslint-config-prettier": "
|
101
|
-
"eslint-plugin-import": "2.28.
|
100
|
+
"eslint-config-prettier": "9.0.0",
|
101
|
+
"eslint-plugin-import": "2.28.1",
|
102
102
|
"eslint-plugin-jsx-a11y": "6.7.1",
|
103
103
|
"eslint-plugin-prettier": "5.0.0",
|
104
|
-
"eslint-plugin-react": "7.33.
|
104
|
+
"eslint-plugin-react": "7.33.2",
|
105
105
|
"eslint-plugin-react-hooks": "4.6.0",
|
106
106
|
"identity-obj-proxy": "3.0.0",
|
107
|
-
"jest": "29.6.
|
108
|
-
"jest-environment-jsdom": "29.6.
|
107
|
+
"jest": "29.6.4",
|
108
|
+
"jest-environment-jsdom": "29.6.4",
|
109
109
|
"jest-matchmedia-mock": "1.1.0",
|
110
|
-
"lefthook": "1.4.
|
111
|
-
"postcss": "8.4.
|
110
|
+
"lefthook": "1.4.10",
|
111
|
+
"postcss": "8.4.29",
|
112
112
|
"postcss-cli": "10.1.0",
|
113
113
|
"postcss-each": "1.1.0",
|
114
114
|
"postcss-import": "15.1.0",
|
115
115
|
"postcss-nested": "6.0.1",
|
116
|
-
"prettier": "3.0.
|
116
|
+
"prettier": "3.0.3",
|
117
117
|
"react": "18.2.0",
|
118
118
|
"react-dom": "18.2.0",
|
119
|
-
"resolve-tspaths": "0.8.
|
120
|
-
"size-limit": "
|
121
|
-
"storybook": "7.
|
122
|
-
"stylelint": "15.10.
|
119
|
+
"resolve-tspaths": "0.8.15",
|
120
|
+
"size-limit": "9.0.0",
|
121
|
+
"storybook": "7.4.0",
|
122
|
+
"stylelint": "15.10.3",
|
123
123
|
"stylelint-config-prettier": "9.0.5",
|
124
124
|
"stylelint-config-standard": "34.0.0",
|
125
125
|
"ts-jest": "29.1.1",
|
126
|
-
"typescript": "5.
|
127
|
-
"vite": "4.4.
|
128
|
-
"vite-tsconfig-paths": "4.2.
|
126
|
+
"typescript": "5.2.2",
|
127
|
+
"vite": "4.4.9",
|
128
|
+
"vite-tsconfig-paths": "4.2.1"
|
129
129
|
},
|
130
130
|
"peerDependencies": {
|
131
131
|
"postcss": "^8.0.0",
|
@@ -133,12 +133,15 @@
|
|
133
133
|
"react-dom": "^18.0.0"
|
134
134
|
},
|
135
135
|
"dependencies": {
|
136
|
-
"autoprefixer": "10.4.
|
136
|
+
"autoprefixer": "10.4.15",
|
137
137
|
"chalk": "4.1.2",
|
138
138
|
"commander": "11.0.0",
|
139
139
|
"cssnano": "6.0.1",
|
140
140
|
"postcss-custom-media": "8.0.2"
|
141
141
|
},
|
142
|
+
"resolutions": {
|
143
|
+
"jackspeak": "2.1.1"
|
144
|
+
},
|
142
145
|
"size-limit": [
|
143
146
|
{
|
144
147
|
"name": "JS",
|
@@ -149,6 +152,11 @@
|
|
149
152
|
"name": "CSS",
|
150
153
|
"path": "dist/bundle.css",
|
151
154
|
"webpack": false
|
155
|
+
},
|
156
|
+
{
|
157
|
+
"name": "JS Theming engine",
|
158
|
+
"path": "dist/themes/index.js",
|
159
|
+
"webpack": true
|
152
160
|
}
|
153
161
|
],
|
154
162
|
"engines": {
|
@@ -0,0 +1,32 @@
|
|
1
|
+
import React from "react";
|
2
|
+
import { Example } from "../../../utilities/storybook/index.js";
|
3
|
+
import Button from "../../../components/Button/index.js";
|
4
|
+
import Theme from "../../../components/Theme/index.js";
|
5
|
+
import { getThemeCSS } from "../../index.js";
|
6
|
+
export default { title: "Themes" };
|
7
|
+
const css = getThemeCSS("green", {
|
8
|
+
color: {
|
9
|
+
backgroundPrimary: { hex: "#1abc9c", hexDark: "#16a085" },
|
10
|
+
backgroundPrimaryHighlighted: { hex: "#16a085", hexDark: "#1abc9c" },
|
11
|
+
},
|
12
|
+
});
|
13
|
+
const css2 = getThemeCSS("peach", {
|
14
|
+
color: {
|
15
|
+
backgroundPrimary: { hex: "#ffbe76" },
|
16
|
+
backgroundPrimaryHighlighted: { hex: "#ffbe76" },
|
17
|
+
},
|
18
|
+
});
|
19
|
+
export const behavior = () => (<Example>
|
20
|
+
<Example.Item title="custom runtime theme">
|
21
|
+
<style>{css}</style>
|
22
|
+
<Theme name="green">
|
23
|
+
<Button color="primary">Primary button</Button>
|
24
|
+
</Theme>
|
25
|
+
</Example.Item>
|
26
|
+
<Example.Item title="on colors generation">
|
27
|
+
<style>{css2}</style>
|
28
|
+
<Theme name="peach">
|
29
|
+
<Button color="primary">Primary button</Button>
|
30
|
+
</Theme>
|
31
|
+
</Example.Item>
|
32
|
+
</Example>);
|
@@ -0,0 +1,7 @@
|
|
1
|
+
import type * as T from "./types";
|
2
|
+
import type { FullThemeDefinition } from "./tokens/types";
|
3
|
+
declare const transform: (name: string, definition: T.PartialDeep<FullThemeDefinition>, options: T.PrivateOptions) => {
|
4
|
+
variables: string;
|
5
|
+
media: string | undefined;
|
6
|
+
};
|
7
|
+
export default transform;
|
@@ -0,0 +1,57 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
3
|
+
if (k2 === undefined) k2 = k;
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
7
|
+
}
|
8
|
+
Object.defineProperty(o, k2, desc);
|
9
|
+
}) : (function(o, m, k, k2) {
|
10
|
+
if (k2 === undefined) k2 = k;
|
11
|
+
o[k2] = m[k];
|
12
|
+
}));
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
15
|
+
}) : function(o, v) {
|
16
|
+
o["default"] = v;
|
17
|
+
});
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
19
|
+
if (mod && mod.__esModule) return mod;
|
20
|
+
var result = {};
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
22
|
+
__setModuleDefault(result, mod);
|
23
|
+
return result;
|
24
|
+
};
|
25
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
26
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
27
|
+
};
|
28
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
29
|
+
const transforms = __importStar(require("./tokens/transforms"));
|
30
|
+
const css_1 = require("./utilities/css");
|
31
|
+
const generateBackgroundColors_1 = __importDefault(require("./utilities/generateBackgroundColors"));
|
32
|
+
const generateUnits_1 = __importDefault(require("./utilities/generateUnits"));
|
33
|
+
const transform = (name, definition, options) => {
|
34
|
+
const { isPrivate, isFragment, themeOptions } = options;
|
35
|
+
(0, generateBackgroundColors_1.default)(definition, themeOptions);
|
36
|
+
(0, generateUnits_1.default)(definition);
|
37
|
+
const transformedStorage = {
|
38
|
+
variable: [],
|
39
|
+
media: [],
|
40
|
+
};
|
41
|
+
Object.entries(definition).forEach(([tokenType, tokenValues]) => {
|
42
|
+
if (!tokenValues)
|
43
|
+
return;
|
44
|
+
const transform = transforms.css[tokenType];
|
45
|
+
Object.entries(tokenValues).forEach(([tokenName, token]) => {
|
46
|
+
const transformedTokens = transform(tokenName, token, definition);
|
47
|
+
transformedTokens.forEach((transformedToken) => {
|
48
|
+
transformedStorage[transformedToken.type].push(transformedToken);
|
49
|
+
});
|
50
|
+
});
|
51
|
+
});
|
52
|
+
return {
|
53
|
+
variables: (0, css_1.variablesTemplate)(name, transformedStorage.variable),
|
54
|
+
media: isPrivate && !isFragment ? (0, css_1.mediaTemplate)(transformedStorage.media) : undefined,
|
55
|
+
};
|
56
|
+
};
|
57
|
+
exports.default = transform;
|
@@ -5,10 +5,12 @@ export type PartialDeep<T> = T extends Primitive ? Partial<T> : {
|
|
5
5
|
};
|
6
6
|
export type PublicOptions = {
|
7
7
|
isPrivate?: boolean;
|
8
|
-
outputPath: string;
|
9
8
|
themeOptions?: ReshapedConfig["themeOptions"];
|
10
9
|
};
|
11
10
|
export type PrivateOptions = PublicOptions & {
|
12
11
|
isFragment?: boolean;
|
13
12
|
};
|
13
|
+
export type CLIOptions = PrivateOptions & {
|
14
|
+
outputPath: string;
|
15
|
+
};
|
14
16
|
export {};
|
@@ -1,7 +1,7 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
3
|
exports.mediaTemplate = exports.variablesTemplate = exports.createMedia = exports.createVariable = exports.getVariableName = void 0;
|
4
|
-
const string_1 = require("
|
4
|
+
const string_1 = require("../../../utilities/string");
|
5
5
|
const getVariableName = (tokenName, tokenType) => {
|
6
6
|
const value = ["rs", tokenType && (0, string_1.camelToKebab)(tokenType), (0, string_1.camelToKebab)(tokenName)]
|
7
7
|
.filter(Boolean)
|
@@ -35,6 +35,8 @@ const variablesTemplate = (themeName, tokens) => {
|
|
35
35
|
const selector = type === "root"
|
36
36
|
? `[data-rs-theme="${themeName}"][data-rs-color-mode="light"], [data-rs-theme="${themeName}"][data-rs-color-mode="dark"]`
|
37
37
|
: `[data-rs-theme="${themeName}"][data-rs-color-mode="${type}"]`;
|
38
|
+
if (!tokens.length)
|
39
|
+
return;
|
38
40
|
code += `
|
39
41
|
${selector} {
|
40
42
|
${tokens.map((token) => (0, exports.createVariable)(token)).join("\n")}
|
@@ -0,0 +1,4 @@
|
|
1
|
+
import type * as T from "../types";
|
2
|
+
import type { FullThemeDefinition } from "../tokens/types";
|
3
|
+
declare const generateBackgroundColors: (definition: T.PartialDeep<FullThemeDefinition>, themeOptions?: T.PublicOptions["themeOptions"]) => void;
|
4
|
+
export default generateBackgroundColors;
|
@@ -0,0 +1,54 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
const color_1 = require("../../../utilities/color");
|
4
|
+
const string_1 = require("../../../utilities/string");
|
5
|
+
const generateBackgroundColors = (definition, themeOptions) => {
|
6
|
+
if (!definition.color)
|
7
|
+
return;
|
8
|
+
Object.keys(definition.color).forEach((tokenName) => {
|
9
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
10
|
+
const bgToken = (_a = definition.color) === null || _a === void 0 ? void 0 : _a[tokenName];
|
11
|
+
const generatedForegroundName = `on${(0, string_1.capitalize)(tokenName)}`;
|
12
|
+
const generatedRGBName = `rgb${(0, string_1.capitalize)(tokenName)}`;
|
13
|
+
const generateOnColorsFor = [
|
14
|
+
"backgroundNeutral",
|
15
|
+
"backgroundPrimary",
|
16
|
+
"backgroundCritical",
|
17
|
+
"backgroundPositive",
|
18
|
+
...((themeOptions === null || themeOptions === void 0 ? void 0 : themeOptions.generateOnColorsFor) || []),
|
19
|
+
];
|
20
|
+
const needsDynamicForeground = generateOnColorsFor.includes(tokenName);
|
21
|
+
const needsRGB = tokenName.startsWith("background") ||
|
22
|
+
tokenName.endsWith("black") ||
|
23
|
+
tokenName.endsWith("white");
|
24
|
+
if (!bgToken)
|
25
|
+
return;
|
26
|
+
if (needsDynamicForeground) {
|
27
|
+
const hex = (0, color_1.getOnColor)({
|
28
|
+
bgHexColor: bgToken.hex,
|
29
|
+
mode: "light",
|
30
|
+
lightHexColor: (_c = (_b = definition === null || definition === void 0 ? void 0 : definition.color) === null || _b === void 0 ? void 0 : _b.white) === null || _c === void 0 ? void 0 : _c.hex,
|
31
|
+
darkHexColor: (_e = (_d = definition === null || definition === void 0 ? void 0 : definition.color) === null || _d === void 0 ? void 0 : _d.black) === null || _e === void 0 ? void 0 : _e.hex,
|
32
|
+
});
|
33
|
+
const hexDark = (0, color_1.getOnColor)({
|
34
|
+
bgHexColor: bgToken.hexDark || bgToken.hex,
|
35
|
+
mode: "dark",
|
36
|
+
lightHexColor: (_g = (_f = definition === null || definition === void 0 ? void 0 : definition.color) === null || _f === void 0 ? void 0 : _f.white) === null || _g === void 0 ? void 0 : _g.hex,
|
37
|
+
darkHexColor: (_j = (_h = definition === null || definition === void 0 ? void 0 : definition.color) === null || _h === void 0 ? void 0 : _h.black) === null || _j === void 0 ? void 0 : _j.hex,
|
38
|
+
});
|
39
|
+
// eslint-disable-next-line no-param-reassign
|
40
|
+
definition.color[generatedForegroundName] = {
|
41
|
+
hex,
|
42
|
+
hexDark: hex !== hexDark ? hexDark : undefined,
|
43
|
+
};
|
44
|
+
}
|
45
|
+
if (needsRGB) {
|
46
|
+
// eslint-disable-next-line no-param-reassign
|
47
|
+
definition.color[generatedRGBName] = {
|
48
|
+
hex: (0, color_1.hexToRgbString)(bgToken.hex),
|
49
|
+
hexDark: bgToken.hexDark && (0, color_1.hexToRgbString)(bgToken.hexDark),
|
50
|
+
};
|
51
|
+
}
|
52
|
+
});
|
53
|
+
};
|
54
|
+
exports.default = generateBackgroundColors;
|
@@ -0,0 +1,17 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
const generateUnits = (definition) => {
|
4
|
+
var _a, _b;
|
5
|
+
const baseValue = (_b = (_a = definition.unit) === null || _a === void 0 ? void 0 : _a.base) === null || _b === void 0 ? void 0 : _b.px;
|
6
|
+
// If base value hasn't changed, we don't need to regenerate tokens
|
7
|
+
if (!baseValue)
|
8
|
+
return;
|
9
|
+
for (let i = 1; i <= 10; i += 1) {
|
10
|
+
const generatedName = `x${i}`;
|
11
|
+
// eslint-disable-next-line no-param-reassign
|
12
|
+
definition.unit[generatedName] = {
|
13
|
+
px: baseValue * i,
|
14
|
+
};
|
15
|
+
}
|
16
|
+
};
|
17
|
+
exports.default = generateUnits;
|
@@ -1,5 +1,3 @@
|
|
1
|
-
"use strict";
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
3
1
|
const isObject = (item) => {
|
4
2
|
return item && typeof item === "object" && !Array.isArray(item);
|
5
3
|
};
|
@@ -21,4 +19,4 @@ const mergeDeep = (target, ...sources) => {
|
|
21
19
|
}
|
22
20
|
return mergeDeep(target, ...sources);
|
23
21
|
};
|
24
|
-
|
22
|
+
export default mergeDeep;
|
@@ -1,5 +1,3 @@
|
|
1
|
-
"use strict";
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
3
1
|
const resolveTokenReference = (theme, tokenType, ref) => {
|
4
2
|
const tokenGroup = theme[tokenType];
|
5
3
|
let referencedToken = null;
|
@@ -13,4 +11,4 @@ const resolveTokenReference = (theme, tokenType, ref) => {
|
|
13
11
|
throw new Error(`Referenced token not found for: ${ref}`);
|
14
12
|
return referencedToken;
|
15
13
|
};
|
16
|
-
|
14
|
+
export default resolveTokenReference;
|