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.
Files changed (160) hide show
  1. package/CHANGELOG.md +19 -12
  2. package/LICENSE-SOURCE.md +40 -0
  3. package/LICENSE.md +21 -37
  4. package/bin/clean.sh +1 -0
  5. package/bin/cli.js +1 -11
  6. package/bin/release-source.sh +7 -0
  7. package/bundle.css +1 -1
  8. package/bundle.js +10 -10
  9. package/cli/theming/definitions/base.d.ts +1 -1
  10. package/cli/theming/definitions/figma.d.ts +1 -1
  11. package/cli/theming/definitions/reshaped.d.ts +1 -1
  12. package/cli/theming/definitions/slate.d.ts +1 -1
  13. package/cli/theming/index.d.ts +4 -4
  14. package/cli/theming/index.js +7 -107
  15. package/components/Actionable/Actionable.js +14 -3
  16. package/components/Actionable/Actionable.module.css +1 -1
  17. package/components/Autocomplete/tests/Autocomplete.stories.js +27 -1
  18. package/components/Button/Button.js +2 -0
  19. package/components/Button/Button.module.css +1 -1
  20. package/components/Button/Button.types.d.ts +6 -0
  21. package/components/Button/ButtonGroup.d.ts +4 -0
  22. package/components/Button/ButtonGroup.js +9 -0
  23. package/components/Button/tests/Button.stories.d.ts +1 -0
  24. package/components/Button/tests/Button.stories.js +63 -0
  25. package/components/Checkbox/Checkbox.module.css +1 -1
  26. package/components/DropdownMenu/DropdownMenu.js +1 -1
  27. package/components/DropdownMenu/tests/DropdownMenu.stories.js +1 -0
  28. package/components/Overlay/Overlay.js +4 -4
  29. package/components/Radio/Radio.module.css +1 -1
  30. package/components/Select/Select.js +1 -1
  31. package/components/Slider/Slider.module.css +1 -1
  32. package/components/Switch/Switch.module.css +1 -1
  33. package/components/Tabs/Tabs.d.ts +1 -8
  34. package/components/Tabs/Tabs.module.css +1 -1
  35. package/components/Tabs/Tabs.types.d.ts +6 -7
  36. package/components/Tabs/TabsContext.d.ts +4 -0
  37. package/components/Tabs/TabsControlled.js +24 -1
  38. package/components/Tabs/TabsItem.d.ts +1 -8
  39. package/components/Tabs/TabsItem.js +22 -4
  40. package/components/Tabs/TabsList.js +30 -32
  41. package/components/Tabs/tests/Tabs.stories.d.ts +1 -0
  42. package/components/Tabs/tests/Tabs.stories.js +17 -0
  43. package/components/Toast/ToastContainer.js +1 -0
  44. package/components/Toast/ToastProvider.js +4 -0
  45. package/components/Toast/tests/Toast.stories.js +1 -0
  46. package/components/_private/Flyout/Flyout.types.d.ts +2 -0
  47. package/components/_private/Flyout/FlyoutContent.js +7 -3
  48. package/components/_private/Flyout/FlyoutControlled.js +8 -1
  49. package/components/_private/Flyout/tests/Flyout.stories.d.ts +1 -0
  50. package/components/_private/Flyout/tests/Flyout.stories.js +25 -0
  51. package/components/_private/Portal/Portal.d.ts +8 -4
  52. package/components/_private/Portal/Portal.js +23 -11
  53. package/components/_private/Portal/Portal.types.d.ts +7 -2
  54. package/components/_private/Portal/index.d.ts +1 -1
  55. package/components/_private/Portal/index.js +1 -1
  56. package/components/_private/Portal/tests/Portal.stories.js +11 -12
  57. package/config/next.d.ts +4 -5
  58. package/config/next.js +21 -7
  59. package/config/tailwind.d.ts +1 -1
  60. package/config/tailwind.js +3 -3
  61. package/hooks/_private/useFlyout.js +16 -13
  62. package/package.json +39 -31
  63. package/themes/_generator/tests/themes.stories.d.ts +6 -0
  64. package/themes/_generator/tests/themes.stories.js +32 -0
  65. package/{cli/theming → themes/_generator}/tokens/color/color.transforms.d.ts +1 -1
  66. package/{cli/theming → themes/_generator}/tokens/duration/duration.transforms.d.ts +1 -1
  67. package/{cli/theming → themes/_generator}/tokens/easing/easing.transforms.d.ts +1 -1
  68. package/{cli/theming → themes/_generator}/tokens/font/font.transforms.d.ts +1 -1
  69. package/{cli/theming → themes/_generator}/tokens/fontFamily/fontFamily.transforms.d.ts +1 -1
  70. package/{cli/theming → themes/_generator}/tokens/fontWeight/fontWeight.transforms.d.ts +1 -1
  71. package/{cli/theming → themes/_generator}/tokens/shadow/shadow.transforms.d.ts +1 -1
  72. package/{cli/theming → themes/_generator}/tokens/shadow/shadow.transforms.js +1 -1
  73. package/{cli/theming → themes/_generator}/tokens/unit/unit.transforms.d.ts +1 -1
  74. package/{cli/theming → themes/_generator}/tokens/viewport/viewport.transforms.d.ts +1 -1
  75. package/themes/_generator/transform.d.ts +7 -0
  76. package/themes/_generator/transform.js +57 -0
  77. package/{cli/theming → themes/_generator}/types.d.ts +3 -1
  78. package/{cli/theming → themes/_generator}/utilities/css.js +3 -1
  79. package/themes/_generator/utilities/generateBackgroundColors.d.ts +4 -0
  80. package/themes/_generator/utilities/generateBackgroundColors.js +54 -0
  81. package/themes/_generator/utilities/generateUnits.d.ts +4 -0
  82. package/themes/_generator/utilities/generateUnits.js +17 -0
  83. package/{cli/theming → themes/_generator}/utilities/mergeDeep.js +1 -3
  84. package/{cli/theming → themes/_generator}/utilities/resolveTokenReference.js +1 -3
  85. package/themes/index.d.ts +3 -0
  86. package/themes/index.js +5 -0
  87. package/types/config.d.ts +1 -1
  88. package/utilities/a11y.js +12 -3
  89. package/{cli/utilities → utilities}/color.d.ts +1 -1
  90. package/utilities/dom.d.ts +1 -0
  91. package/utilities/dom.js +9 -0
  92. package/cli/theming/definitions/minimal.d.ts +0 -3
  93. package/cli/theming/definitions/minimal.js +0 -80
  94. package/cli/utilities/tests/color.test.d.ts +0 -1
  95. package/cli/utilities/tests/color.test.js +0 -63
  96. package/styles/aspectRatio/index.test.d.ts +0 -1
  97. package/styles/aspectRatio/index.test.js +0 -24
  98. package/styles/bleed/index.test.d.ts +0 -1
  99. package/styles/bleed/index.test.js +0 -24
  100. package/styles/height/index.test.d.ts +0 -1
  101. package/styles/height/index.test.js +0 -27
  102. package/styles/inset/index.test.d.ts +0 -1
  103. package/styles/inset/index.test.js +0 -27
  104. package/styles/maxHeight/index.test.d.ts +0 -1
  105. package/styles/maxHeight/index.test.js +0 -27
  106. package/styles/maxWidth/index.test.d.ts +0 -1
  107. package/styles/maxWidth/index.test.js +0 -27
  108. package/styles/padding/index.test.d.ts +0 -1
  109. package/styles/padding/index.test.js +0 -24
  110. package/styles/position/index.test.d.ts +0 -1
  111. package/styles/position/index.test.js +0 -21
  112. package/styles/radius/index.test.d.ts +0 -1
  113. package/styles/radius/index.test.js +0 -24
  114. package/styles/width/index.test.d.ts +0 -1
  115. package/styles/width/index.test.js +0 -27
  116. package/themes/minimal/theme.css +0 -1
  117. package/utilities/testPresets.d.ts +0 -25
  118. package/utilities/testPresets.js +0 -76
  119. package/utilities/tests/Chain.test.d.ts +0 -1
  120. package/utilities/tests/Chain.test.js +0 -45
  121. /package/bin/{copy-release.sh → release-copy.sh} +0 -0
  122. /package/{cli/theming → themes/_generator}/tokens/color/color.transforms.js +0 -0
  123. /package/{cli/theming → themes/_generator}/tokens/color/color.types.d.ts +0 -0
  124. /package/{cli/theming → themes/_generator}/tokens/color/color.types.js +0 -0
  125. /package/{cli/theming → themes/_generator}/tokens/duration/duration.transforms.js +0 -0
  126. /package/{cli/theming → themes/_generator}/tokens/duration/duration.types.d.ts +0 -0
  127. /package/{cli/theming → themes/_generator}/tokens/duration/duration.types.js +0 -0
  128. /package/{cli/theming → themes/_generator}/tokens/easing/easing.transforms.js +0 -0
  129. /package/{cli/theming → themes/_generator}/tokens/easing/easing.types.d.ts +0 -0
  130. /package/{cli/theming → themes/_generator}/tokens/easing/easing.types.js +0 -0
  131. /package/{cli/theming → themes/_generator}/tokens/font/font.transforms.js +0 -0
  132. /package/{cli/theming → themes/_generator}/tokens/font/font.types.d.ts +0 -0
  133. /package/{cli/theming → themes/_generator}/tokens/font/font.types.js +0 -0
  134. /package/{cli/theming → themes/_generator}/tokens/fontFamily/fontFamily.transforms.js +0 -0
  135. /package/{cli/theming → themes/_generator}/tokens/fontFamily/fontFamily.types.d.ts +0 -0
  136. /package/{cli/theming → themes/_generator}/tokens/fontFamily/fontFamily.types.js +0 -0
  137. /package/{cli/theming → themes/_generator}/tokens/fontWeight/fontWeight.transforms.js +0 -0
  138. /package/{cli/theming → themes/_generator}/tokens/fontWeight/fontWeight.types.d.ts +0 -0
  139. /package/{cli/theming → themes/_generator}/tokens/fontWeight/fontWeight.types.js +0 -0
  140. /package/{cli/theming → themes/_generator}/tokens/shadow/shadow.types.d.ts +0 -0
  141. /package/{cli/theming → themes/_generator}/tokens/shadow/shadow.types.js +0 -0
  142. /package/{cli/theming → themes/_generator}/tokens/transforms.d.ts +0 -0
  143. /package/{cli/theming → themes/_generator}/tokens/transforms.js +0 -0
  144. /package/{cli/theming → themes/_generator}/tokens/types.d.ts +0 -0
  145. /package/{cli/theming → themes/_generator}/tokens/types.js +0 -0
  146. /package/{cli/theming → themes/_generator}/tokens/unit/unit.transforms.js +0 -0
  147. /package/{cli/theming → themes/_generator}/tokens/unit/unit.types.d.ts +0 -0
  148. /package/{cli/theming → themes/_generator}/tokens/unit/unit.types.js +0 -0
  149. /package/{cli/theming → themes/_generator}/tokens/viewport/viewport.transforms.js +0 -0
  150. /package/{cli/theming → themes/_generator}/tokens/viewport/viewport.types.d.ts +0 -0
  151. /package/{cli/theming → themes/_generator}/tokens/viewport/viewport.types.js +0 -0
  152. /package/{cli/theming → themes/_generator}/types.js +0 -0
  153. /package/{cli/theming → themes/_generator}/utilities/css.d.ts +0 -0
  154. /package/{cli/theming → themes/_generator}/utilities/mergeDeep.d.ts +0 -0
  155. /package/{cli/theming → themes/_generator}/utilities/mergeDefinitions.d.ts +0 -0
  156. /package/{cli/theming → themes/_generator}/utilities/mergeDefinitions.js +0 -0
  157. /package/{cli/theming → themes/_generator}/utilities/resolveTokenReference.d.ts +0 -0
  158. /package/{cli/utilities → utilities}/color.js +0 -0
  159. /package/{cli/utilities → utilities}/string.d.ts +0 -0
  160. /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
- return (<div style={{ border: "2px solid #333", padding: 16 }}>
7
- App
8
- <Portal scopeRef={ref}>
9
- <div ref={ref} style={{ border: "2px solid green", padding: 16 }}>
10
- Portal scope
11
- <div style={{ border: "2px solid red", padding: 16 }}>
12
- Stays in red
13
- <Portal>Ported to green</Portal>
14
- </div>
15
- </div>
16
- </Portal>
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
- export declare const config: {
2
- modularizeImports: {
3
- reshaped: string[][];
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
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.config = void 0;
4
- exports.config = {
5
- modularizeImports: {
6
- reshaped: [[""]],
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
+ // };
@@ -1,2 +1,2 @@
1
- import { UserThemeDefinition } from "../cli/theming/tokens/types";
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>>;
@@ -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("../cli/utilities/string");
10
- const color_1 = require("../cli/utilities/color");
11
- const mergeDefinitions_1 = __importDefault(require("../cli/theming/utilities/mergeDefinitions"));
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, isInsidePortal } = options;
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
- // When rendered inside portal, we don't need to accommodate for the page scroll
120
- top = Math.round(top + (isInsidePortal ? 0 : window.pageYOffset || 0));
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
- let calculated = calculatePosition(originBounds, targetBounds, options);
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
- return Object.assign(Object.assign({}, state), { status: "rendered" });
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, isInsidePortal]);
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.2.0",
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": "git archive -o reshaped-source-v$(jq -r .version package.json).zip HEAD . ':!.chromatic'",
69
- "release:copy": "sh ./bin/copy-release.sh",
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": "8.2.6",
83
- "@storybook/addon-a11y": "7.1.1",
84
- "@storybook/react": "7.1.1",
85
- "@storybook/react-vite": "7.1.1",
86
- "@testing-library/jest-dom": "5.17.0",
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.3",
91
- "@types/node": "20.4.8",
92
- "@types/react": "18.2.18",
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.2.1",
95
- "@typescript-eslint/parser": "6.2.1",
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": "6.20.0",
98
- "eslint": "8.46.0",
97
+ "chromatic": "7.1.0",
98
+ "eslint": "8.49.0",
99
99
  "eslint-config-airbnb-typescript": "17.1.0",
100
- "eslint-config-prettier": "8.10.0",
101
- "eslint-plugin-import": "2.28.0",
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.1",
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.2",
108
- "jest-environment-jsdom": "29.6.2",
107
+ "jest": "29.6.4",
108
+ "jest-environment-jsdom": "29.6.4",
109
109
  "jest-matchmedia-mock": "1.1.0",
110
- "lefthook": "1.4.8",
111
- "postcss": "8.4.27",
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.1",
116
+ "prettier": "3.0.3",
117
117
  "react": "18.2.0",
118
118
  "react-dom": "18.2.0",
119
- "resolve-tspaths": "0.8.14",
120
- "size-limit": "8.2.6",
121
- "storybook": "7.1.1",
122
- "stylelint": "15.10.2",
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.1.6",
127
- "vite": "4.4.8",
128
- "vite-tsconfig-paths": "4.2.0"
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.14",
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,6 @@
1
+ import React from "react";
2
+ declare const _default: {
3
+ title: string;
4
+ };
5
+ export default _default;
6
+ export declare const behavior: () => React.JSX.Element;
@@ -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>);
@@ -1,4 +1,4 @@
1
1
  import type * as T from "./color.types";
2
- import { Transformer } from "../types";
2
+ import type { Transformer } from "../types";
3
3
  declare const transformedToken: Transformer<T.Token>;
4
4
  export default transformedToken;
@@ -1,4 +1,4 @@
1
1
  import type * as T from "./duration.types";
2
- import { Transformer } from "../types";
2
+ import type { Transformer } from "../types";
3
3
  declare const transformedToken: Transformer<T.Token>;
4
4
  export default transformedToken;
@@ -1,4 +1,4 @@
1
1
  import type * as T from "./easing.types";
2
- import { Transformer } from "../types";
2
+ import type { Transformer } from "../types";
3
3
  declare const transformedToken: Transformer<T.Token>;
4
4
  export default transformedToken;
@@ -1,4 +1,4 @@
1
1
  import type * as T from "./font.types";
2
- import { Transformer } from "../types";
2
+ import type { Transformer } from "../types";
3
3
  declare const transformedToken: Transformer<T.Token>;
4
4
  export default transformedToken;
@@ -1,4 +1,4 @@
1
1
  import type * as T from "./fontFamily.types";
2
- import { Transformer } from "../types";
2
+ import type { Transformer } from "../types";
3
3
  declare const transformedToken: Transformer<T.Token>;
4
4
  export default transformedToken;
@@ -1,4 +1,4 @@
1
1
  import type * as T from "./fontWeight.types";
2
- import { Transformer } from "../types";
2
+ import type { Transformer } from "../types";
3
3
  declare const transformedToken: Transformer<T.Token>;
4
4
  export default transformedToken;
@@ -1,4 +1,4 @@
1
1
  import type * as T from "./shadow.types";
2
- import { Transformer } from "../types";
2
+ import type { Transformer } from "../types";
3
3
  declare const transformedToken: Transformer<T.Token>;
4
4
  export default transformedToken;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- const color_1 = require("../../../utilities/color");
3
+ const color_1 = require("../../../../utilities/color");
4
4
  const transformedToken = (name, token, theme) => [
5
5
  {
6
6
  name,
@@ -1,4 +1,4 @@
1
1
  import type * as T from "./unit.types";
2
- import { Transformer } from "../types";
2
+ import type { Transformer } from "../types";
3
3
  declare const transformedToken: Transformer<T.Token>;
4
4
  export default transformedToken;
@@ -1,4 +1,4 @@
1
1
  import type * as T from "./viewport.types";
2
- import { Transformer } from "../types";
2
+ import type { Transformer } from "../types";
3
3
  declare const transformedToken: Transformer<T.Token>;
4
4
  export default transformedToken;
@@ -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("../../utilities/string");
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,4 @@
1
+ import type * as T from "../types";
2
+ import type { FullThemeDefinition } from "../tokens/types";
3
+ declare const generateUnits: (definition: T.PartialDeep<FullThemeDefinition>) => void;
4
+ export default generateUnits;
@@ -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
- exports.default = mergeDeep;
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
- exports.default = resolveTokenReference;
14
+ export default resolveTokenReference;
@@ -0,0 +1,3 @@
1
+ import type * as T from "./_generator/types";
2
+ import type { FullThemeDefinition } from "./_generator/tokens/types";
3
+ export declare const getThemeCSS: (name: string, definition: T.PartialDeep<FullThemeDefinition>) => string;