@cerberus-design/react 0.13.1-next-394d7c4 → 0.13.1-next-8e40fb6
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/build/legacy/_tsup-dts-rollup.d.cts +13 -14
- package/build/legacy/components/Portal.cjs +2 -6
- package/build/legacy/components/Portal.cjs.map +1 -1
- package/build/legacy/context/confirm-modal.cjs +22 -25
- package/build/legacy/context/confirm-modal.cjs.map +1 -1
- package/build/legacy/context/cta-modal.cjs +20 -23
- package/build/legacy/context/cta-modal.cjs.map +1 -1
- package/build/legacy/context/notification-center.cjs +10 -13
- package/build/legacy/context/notification-center.cjs.map +1 -1
- package/build/legacy/context/prompt-modal.cjs +29 -32
- package/build/legacy/context/prompt-modal.cjs.map +1 -1
- package/build/legacy/hooks/useRootColors.cjs +21 -6
- package/build/legacy/hooks/useRootColors.cjs.map +1 -1
- package/build/legacy/index.cjs +106 -94
- package/build/legacy/index.cjs.map +1 -1
- package/build/modern/_tsup-dts-rollup.d.ts +13 -14
- package/build/modern/{chunk-B3LRHIEG.js → chunk-3XGLNXJJ.js} +2 -2
- package/build/modern/{chunk-S6JWPDB4.js → chunk-FBSESDWJ.js} +2 -2
- package/build/modern/{chunk-FHS7VVGN.js → chunk-GRUXP3NG.js} +2 -2
- package/build/modern/chunk-IQJDVFPP.js +10 -0
- package/build/modern/chunk-IQJDVFPP.js.map +1 -0
- package/build/modern/chunk-RMVJK26W.js +39 -0
- package/build/modern/chunk-RMVJK26W.js.map +1 -0
- package/build/modern/{chunk-SRPSJGNI.js → chunk-WFJWCZ7E.js} +2 -2
- package/build/modern/components/Portal.js +1 -2
- package/build/modern/context/confirm-modal.js +2 -2
- package/build/modern/context/cta-modal.js +2 -2
- package/build/modern/context/notification-center.js +2 -2
- package/build/modern/context/prompt-modal.js +2 -2
- package/build/modern/hooks/useRootColors.js +1 -1
- package/build/modern/index.js +6 -6
- package/package.json +3 -3
- package/src/components/Portal.tsx +6 -19
- package/src/hooks/useRootColors.ts +36 -12
- package/build/modern/chunk-K2PSHGS7.js +0 -11
- package/build/modern/chunk-K2PSHGS7.js.map +0 -1
- package/build/modern/chunk-RO4AJOVX.js +0 -24
- package/build/modern/chunk-RO4AJOVX.js.map +0 -1
- /package/build/modern/{chunk-B3LRHIEG.js.map → chunk-3XGLNXJJ.js.map} +0 -0
- /package/build/modern/{chunk-S6JWPDB4.js.map → chunk-FBSESDWJ.js.map} +0 -0
- /package/build/modern/{chunk-FHS7VVGN.js.map → chunk-GRUXP3NG.js.map} +0 -0
- /package/build/modern/{chunk-SRPSJGNI.js.map → chunk-WFJWCZ7E.js.map} +0 -0
|
@@ -99,12 +99,12 @@ import { PointerSensor } from '@dnd-kit/core';
|
|
|
99
99
|
import { PointerSensorOptions } from '@dnd-kit/core';
|
|
100
100
|
import { PointerSensorProps } from '@dnd-kit/core';
|
|
101
101
|
import { pointerWithin } from '@dnd-kit/core';
|
|
102
|
+
import { PortalProps as PortalProps_2 } from '@ark-ui/react';
|
|
102
103
|
import type { Pretty } from '@cerberus/styled-system/types';
|
|
103
104
|
import { ProgressBarVariantProps } from '@cerberus/styled-system/recipes';
|
|
104
105
|
import { PropsWithChildren } from 'react';
|
|
105
106
|
import { radio } from '@cerberus/styled-system/recipes';
|
|
106
107
|
import { ReactNode } from 'react';
|
|
107
|
-
import { ReactPortal } from 'react';
|
|
108
108
|
import type { RecipeVariantProps } from '@cerberus/styled-system/types';
|
|
109
109
|
import { rectIntersection } from '@dnd-kit/core';
|
|
110
110
|
import { RefAttributes } from 'react';
|
|
@@ -1920,7 +1920,7 @@ export { pointerWithin }
|
|
|
1920
1920
|
* )
|
|
1921
1921
|
* }
|
|
1922
1922
|
*/
|
|
1923
|
-
declare
|
|
1923
|
+
declare const Portal: (props: PropsWithChildren<PortalProps_2>) => JSX_2.Element;
|
|
1924
1924
|
export { Portal }
|
|
1925
1925
|
export { Portal as Portal_alias_1 }
|
|
1926
1926
|
|
|
@@ -1928,17 +1928,7 @@ export { Portal as Portal_alias_1 }
|
|
|
1928
1928
|
* This module is the Portal component.
|
|
1929
1929
|
* @module
|
|
1930
1930
|
*/
|
|
1931
|
-
declare
|
|
1932
|
-
/**
|
|
1933
|
-
* The root container to render the children into.
|
|
1934
|
-
* @default document.body
|
|
1935
|
-
*/
|
|
1936
|
-
container?: Element | DocumentFragment;
|
|
1937
|
-
/**
|
|
1938
|
-
* An optional key to use for the Portal component.
|
|
1939
|
-
*/
|
|
1940
|
-
key?: null | string;
|
|
1941
|
-
}
|
|
1931
|
+
declare type PortalProps = PortalProps_2;
|
|
1942
1932
|
export { PortalProps }
|
|
1943
1933
|
export { PortalProps as PortalProps_alias_1 }
|
|
1944
1934
|
|
|
@@ -2101,7 +2091,16 @@ export { rectIntersection }
|
|
|
2101
2091
|
* This module provides a hook to get Cerberus colors from the document root.
|
|
2102
2092
|
* @module useRootColors
|
|
2103
2093
|
*/
|
|
2104
|
-
declare
|
|
2094
|
+
declare interface RootColorsResult {
|
|
2095
|
+
/**
|
|
2096
|
+
* A record of Cerberus colors where the key is the token name provided and the value is the color hex.
|
|
2097
|
+
*/
|
|
2098
|
+
colors: Record<string, string>;
|
|
2099
|
+
/**
|
|
2100
|
+
* A function to refetch the Cerberus colors from the document root. Useful when you need the latest colors after a theme/mode change.
|
|
2101
|
+
*/
|
|
2102
|
+
refetch: () => Promise<void>;
|
|
2103
|
+
}
|
|
2105
2104
|
export { RootColorsResult }
|
|
2106
2105
|
export { RootColorsResult as RootColorsResult_alias_1 }
|
|
2107
2106
|
|
|
@@ -3,7 +3,7 @@ import {
|
|
|
3
3
|
} from "./chunk-SXIXDXG3.js";
|
|
4
4
|
import {
|
|
5
5
|
Portal
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-IQJDVFPP.js";
|
|
7
7
|
import {
|
|
8
8
|
Notification
|
|
9
9
|
} from "./chunk-7SGPJM66.js";
|
|
@@ -159,4 +159,4 @@ export {
|
|
|
159
159
|
NotificationCenter,
|
|
160
160
|
useNotificationCenter
|
|
161
161
|
};
|
|
162
|
-
//# sourceMappingURL=chunk-
|
|
162
|
+
//# sourceMappingURL=chunk-3XGLNXJJ.js.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
Portal
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-IQJDVFPP.js";
|
|
4
4
|
import {
|
|
5
5
|
ModalDescription
|
|
6
6
|
} from "./chunk-Q7BRMIBR.js";
|
|
@@ -240,4 +240,4 @@ export {
|
|
|
240
240
|
PromptModal,
|
|
241
241
|
usePromptModal
|
|
242
242
|
};
|
|
243
|
-
//# sourceMappingURL=chunk-
|
|
243
|
+
//# sourceMappingURL=chunk-FBSESDWJ.js.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
Portal
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-IQJDVFPP.js";
|
|
4
4
|
import {
|
|
5
5
|
ModalDescription
|
|
6
6
|
} from "./chunk-Q7BRMIBR.js";
|
|
@@ -170,4 +170,4 @@ export {
|
|
|
170
170
|
ConfirmModal,
|
|
171
171
|
useConfirmModal
|
|
172
172
|
};
|
|
173
|
-
//# sourceMappingURL=chunk-
|
|
173
|
+
//# sourceMappingURL=chunk-GRUXP3NG.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/components/Portal.tsx"],"sourcesContent":["import {\n Portal as ArkPortal,\n type PortalProps as ArkPortalProps,\n} from '@ark-ui/react'\n\n/**\n * This module is the Portal component.\n * @module\n */\n\nexport type PortalProps = ArkPortalProps\n\n/**\n * The Portal component is used to render children into a DOM node that exists outside the DOM hierarchy of the parent component.\n * @see https://cerberus.digitalu.design/react/portal\n * @definition [React Portal Docs](https://react.dev/reference/react-dom/createPortal)\n * @example\n * ```tsx\n * 'use client'\n *\n * import { Portal } from '@cerberus/react'\n *\n * function SomeFeatureWithinSSRPage() {\n * return (\n * <Portal>\n * <div>Portal Content outside of the React VDom tree</div>\n * </Portal>\n * )\n * }\n */\nexport const Portal = ArkPortal\n"],"mappings":";AAAA;AAAA,EACE,UAAU;AAAA,OAEL;AA2BA,IAAM,SAAS;","names":[]}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
// src/hooks/useRootColors.ts
|
|
2
|
+
import { useCallback, useEffect, useMemo, useReducer } from "react";
|
|
3
|
+
function useRootColors(colors = []) {
|
|
4
|
+
const [state, dispatch] = useReducer(rootColorsReducer, {});
|
|
5
|
+
const handleRefetch = useCallback(() => {
|
|
6
|
+
return new Promise((resolve) => {
|
|
7
|
+
dispatch(formatColors(colors));
|
|
8
|
+
resolve();
|
|
9
|
+
});
|
|
10
|
+
}, []);
|
|
11
|
+
useEffect(() => {
|
|
12
|
+
if (Object.keys(state).length === colors.length) return;
|
|
13
|
+
dispatch(formatColors(colors));
|
|
14
|
+
console.log("updating colors in root hook");
|
|
15
|
+
}, [colors]);
|
|
16
|
+
return useMemo(
|
|
17
|
+
() => ({ colors: state, refetch: handleRefetch }),
|
|
18
|
+
[state, handleRefetch]
|
|
19
|
+
);
|
|
20
|
+
}
|
|
21
|
+
function formatColors(colors) {
|
|
22
|
+
const rootStyles = getComputedStyle(document.body);
|
|
23
|
+
return colors.reduce(
|
|
24
|
+
(acc, color) => {
|
|
25
|
+
const formattedColor = color.replace(/([a-z])([A-Z])/g, "$1-$2").toLowerCase().replaceAll(".", "-");
|
|
26
|
+
acc[color] = rootStyles.getPropertyValue(`--cerberus-colors-${formattedColor}`).trim();
|
|
27
|
+
return acc;
|
|
28
|
+
},
|
|
29
|
+
{}
|
|
30
|
+
);
|
|
31
|
+
}
|
|
32
|
+
function rootColorsReducer(state, action) {
|
|
33
|
+
return { ...state, ...action };
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export {
|
|
37
|
+
useRootColors
|
|
38
|
+
};
|
|
39
|
+
//# sourceMappingURL=chunk-RMVJK26W.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/hooks/useRootColors.ts"],"sourcesContent":["'use client'\n\nimport { useCallback, useEffect, useMemo, useReducer } from 'react'\n\n/**\n * This module provides a hook to get Cerberus colors from the document root.\n * @module useRootColors\n */\n\nexport interface RootColorsResult {\n /**\n * A record of Cerberus colors where the key is the token name provided and the value is the color hex.\n */\n colors: Record<string, string>\n /**\n * A function to refetch the Cerberus colors from the document root. Useful when you need the latest colors after a theme/mode change.\n */\n refetch: () => Promise<void>\n}\n\n/**\n * This hook returns a record of Cerberus colors from the document root.\n * This is useful when you are working with a component that uses the `<canvas>`\n * element.\n * @param colors - An array of Cerberus tokens to get from the document root (i.e. `['dataViz.diverging.50', 'dataViz.diverging.200']`).\n * @returns A record of Cerberus colors where the key is the token name provided and the value is the color hex.\n */\nexport function useRootColors(colors: string[] = []): RootColorsResult {\n const [state, dispatch] = useReducer(rootColorsReducer, {})\n\n const handleRefetch = useCallback(() => {\n return new Promise<void>((resolve) => {\n dispatch(formatColors(colors))\n resolve()\n })\n }, [])\n\n useEffect(() => {\n if (Object.keys(state).length === colors.length) return\n dispatch(formatColors(colors))\n console.log('updating colors in root hook')\n }, [colors])\n\n // reducer is already memoized\n return useMemo(\n () => ({ colors: state, refetch: handleRefetch }),\n [state, handleRefetch],\n )\n}\n\nfunction formatColors(colors: string[]): Record<string, string> {\n const rootStyles = getComputedStyle(document.body)\n return colors.reduce(\n (acc, color) => {\n const formattedColor = color\n .replace(/([a-z])([A-Z])/g, '$1-$2')\n .toLowerCase()\n .replaceAll('.', '-')\n acc[color] = rootStyles\n .getPropertyValue(`--cerberus-colors-${formattedColor}`)\n .trim()\n return acc\n },\n {} as Record<string, string>,\n )\n}\n\nfunction rootColorsReducer(\n state: Record<string, string>,\n action: Record<string, string>,\n): Record<string, string> {\n return { ...state, ...action }\n}\n"],"mappings":";AAEA,SAAS,aAAa,WAAW,SAAS,kBAAkB;AAyBrD,SAAS,cAAc,SAAmB,CAAC,GAAqB;AACrE,QAAM,CAAC,OAAO,QAAQ,IAAI,WAAW,mBAAmB,CAAC,CAAC;AAE1D,QAAM,gBAAgB,YAAY,MAAM;AACtC,WAAO,IAAI,QAAc,CAAC,YAAY;AACpC,eAAS,aAAa,MAAM,CAAC;AAC7B,cAAQ;AAAA,IACV,CAAC;AAAA,EACH,GAAG,CAAC,CAAC;AAEL,YAAU,MAAM;AACd,QAAI,OAAO,KAAK,KAAK,EAAE,WAAW,OAAO,OAAQ;AACjD,aAAS,aAAa,MAAM,CAAC;AAC7B,YAAQ,IAAI,8BAA8B;AAAA,EAC5C,GAAG,CAAC,MAAM,CAAC;AAGX,SAAO;AAAA,IACL,OAAO,EAAE,QAAQ,OAAO,SAAS,cAAc;AAAA,IAC/C,CAAC,OAAO,aAAa;AAAA,EACvB;AACF;AAEA,SAAS,aAAa,QAA0C;AAC9D,QAAM,aAAa,iBAAiB,SAAS,IAAI;AACjD,SAAO,OAAO;AAAA,IACZ,CAAC,KAAK,UAAU;AACd,YAAM,iBAAiB,MACpB,QAAQ,mBAAmB,OAAO,EAClC,YAAY,EACZ,WAAW,KAAK,GAAG;AACtB,UAAI,KAAK,IAAI,WACV,iBAAiB,qBAAqB,cAAc,EAAE,EACtD,KAAK;AACR,aAAO;AAAA,IACT;AAAA,IACA,CAAC;AAAA,EACH;AACF;AAEA,SAAS,kBACP,OACA,QACwB;AACxB,SAAO,EAAE,GAAG,OAAO,GAAG,OAAO;AAC/B;","names":[]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
Portal
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-IQJDVFPP.js";
|
|
4
4
|
import {
|
|
5
5
|
ModalDescription
|
|
6
6
|
} from "./chunk-Q7BRMIBR.js";
|
|
@@ -152,4 +152,4 @@ export {
|
|
|
152
152
|
CTAModal,
|
|
153
153
|
useCTAModal
|
|
154
154
|
};
|
|
155
|
-
//# sourceMappingURL=chunk-
|
|
155
|
+
//# sourceMappingURL=chunk-WFJWCZ7E.js.map
|
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
import {
|
|
3
3
|
ConfirmModal,
|
|
4
4
|
useConfirmModal
|
|
5
|
-
} from "../chunk-
|
|
6
|
-
import "../chunk-
|
|
5
|
+
} from "../chunk-GRUXP3NG.js";
|
|
6
|
+
import "../chunk-IQJDVFPP.js";
|
|
7
7
|
import "../chunk-Q7BRMIBR.js";
|
|
8
8
|
import "../chunk-XY6WL55R.js";
|
|
9
9
|
import "../chunk-2UXE5PDG.js";
|
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
import {
|
|
3
3
|
CTAModal,
|
|
4
4
|
useCTAModal
|
|
5
|
-
} from "../chunk-
|
|
6
|
-
import "../chunk-
|
|
5
|
+
} from "../chunk-WFJWCZ7E.js";
|
|
6
|
+
import "../chunk-IQJDVFPP.js";
|
|
7
7
|
import "../chunk-Q7BRMIBR.js";
|
|
8
8
|
import "../chunk-XY6WL55R.js";
|
|
9
9
|
import "../chunk-2UXE5PDG.js";
|
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
import {
|
|
3
3
|
NotificationCenter,
|
|
4
4
|
useNotificationCenter
|
|
5
|
-
} from "../chunk-
|
|
5
|
+
} from "../chunk-3XGLNXJJ.js";
|
|
6
6
|
import "../chunk-SXIXDXG3.js";
|
|
7
|
-
import "../chunk-
|
|
7
|
+
import "../chunk-IQJDVFPP.js";
|
|
8
8
|
import "../chunk-7SGPJM66.js";
|
|
9
9
|
import "../chunk-XEW6TJJ4.js";
|
|
10
10
|
import "../chunk-EXGKZGML.js";
|
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
import {
|
|
3
3
|
PromptModal,
|
|
4
4
|
usePromptModal
|
|
5
|
-
} from "../chunk-
|
|
6
|
-
import "../chunk-
|
|
5
|
+
} from "../chunk-FBSESDWJ.js";
|
|
6
|
+
import "../chunk-IQJDVFPP.js";
|
|
7
7
|
import "../chunk-Q7BRMIBR.js";
|
|
8
8
|
import "../chunk-XY6WL55R.js";
|
|
9
9
|
import "../chunk-2UXE5PDG.js";
|
package/build/modern/index.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import {
|
|
2
2
|
NotificationCenter,
|
|
3
3
|
useNotificationCenter
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-3XGLNXJJ.js";
|
|
5
5
|
import {
|
|
6
6
|
PromptModal,
|
|
7
7
|
usePromptModal
|
|
8
|
-
} from "./chunk-
|
|
8
|
+
} from "./chunk-FBSESDWJ.js";
|
|
9
9
|
import {
|
|
10
10
|
ThemeProvider,
|
|
11
11
|
useThemeContext
|
|
@@ -22,11 +22,11 @@ import {
|
|
|
22
22
|
import {
|
|
23
23
|
ConfirmModal,
|
|
24
24
|
useConfirmModal
|
|
25
|
-
} from "./chunk-
|
|
25
|
+
} from "./chunk-GRUXP3NG.js";
|
|
26
26
|
import {
|
|
27
27
|
CTAModal,
|
|
28
28
|
useCTAModal
|
|
29
|
-
} from "./chunk-
|
|
29
|
+
} from "./chunk-WFJWCZ7E.js";
|
|
30
30
|
import {
|
|
31
31
|
TabList
|
|
32
32
|
} from "./chunk-UKPF7JOB.js";
|
|
@@ -57,7 +57,7 @@ import {
|
|
|
57
57
|
} from "./chunk-SXIXDXG3.js";
|
|
58
58
|
import {
|
|
59
59
|
Portal
|
|
60
|
-
} from "./chunk-
|
|
60
|
+
} from "./chunk-IQJDVFPP.js";
|
|
61
61
|
import {
|
|
62
62
|
Radio
|
|
63
63
|
} from "./chunk-FTPZHG6J.js";
|
|
@@ -171,7 +171,7 @@ import {
|
|
|
171
171
|
} from "./chunk-KGQG5JGW.js";
|
|
172
172
|
import {
|
|
173
173
|
useRootColors
|
|
174
|
-
} from "./chunk-
|
|
174
|
+
} from "./chunk-RMVJK26W.js";
|
|
175
175
|
import {
|
|
176
176
|
MODE_KEY,
|
|
177
177
|
THEME_KEY,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cerberus-design/react",
|
|
3
|
-
"version": "0.13.1-next-
|
|
3
|
+
"version": "0.13.1-next-8e40fb6",
|
|
4
4
|
"description": "The Cerberus Design React component library.",
|
|
5
5
|
"browserslist": "> 0.25%, not dead",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -26,8 +26,8 @@
|
|
|
26
26
|
"react": "^18",
|
|
27
27
|
"react-dom": "^18",
|
|
28
28
|
"tsup": "^8.1.0",
|
|
29
|
-
"@cerberus-design/
|
|
30
|
-
"@cerberus-design/
|
|
29
|
+
"@cerberus-design/configs": "0.0.0",
|
|
30
|
+
"@cerberus-design/styled-system": "0.13.1-next-8e40fb6"
|
|
31
31
|
},
|
|
32
32
|
"publishConfig": {
|
|
33
33
|
"access": "public"
|
|
@@ -1,24 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import {
|
|
2
|
+
Portal as ArkPortal,
|
|
3
|
+
type PortalProps as ArkPortalProps,
|
|
4
|
+
} from '@ark-ui/react'
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* This module is the Portal component.
|
|
8
8
|
* @module
|
|
9
9
|
*/
|
|
10
10
|
|
|
11
|
-
export
|
|
12
|
-
/**
|
|
13
|
-
* The root container to render the children into.
|
|
14
|
-
* @default document.body
|
|
15
|
-
*/
|
|
16
|
-
container?: Element | DocumentFragment
|
|
17
|
-
/**
|
|
18
|
-
* An optional key to use for the Portal component.
|
|
19
|
-
*/
|
|
20
|
-
key?: null | string
|
|
21
|
-
}
|
|
11
|
+
export type PortalProps = ArkPortalProps
|
|
22
12
|
|
|
23
13
|
/**
|
|
24
14
|
* The Portal component is used to render children into a DOM node that exists outside the DOM hierarchy of the parent component.
|
|
@@ -38,7 +28,4 @@ export interface PortalProps {
|
|
|
38
28
|
* )
|
|
39
29
|
* }
|
|
40
30
|
*/
|
|
41
|
-
export
|
|
42
|
-
const container = props.container || document.body
|
|
43
|
-
return createPortal(props.children, container, props.key)
|
|
44
|
-
}
|
|
31
|
+
export const Portal = ArkPortal
|
|
@@ -1,13 +1,22 @@
|
|
|
1
1
|
'use client'
|
|
2
2
|
|
|
3
|
-
import { useEffect, useReducer } from 'react'
|
|
3
|
+
import { useCallback, useEffect, useMemo, useReducer } from 'react'
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* This module provides a hook to get Cerberus colors from the document root.
|
|
7
7
|
* @module useRootColors
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
|
-
export
|
|
10
|
+
export interface RootColorsResult {
|
|
11
|
+
/**
|
|
12
|
+
* A record of Cerberus colors where the key is the token name provided and the value is the color hex.
|
|
13
|
+
*/
|
|
14
|
+
colors: Record<string, string>
|
|
15
|
+
/**
|
|
16
|
+
* A function to refetch the Cerberus colors from the document root. Useful when you need the latest colors after a theme/mode change.
|
|
17
|
+
*/
|
|
18
|
+
refetch: () => Promise<void>
|
|
19
|
+
}
|
|
11
20
|
|
|
12
21
|
/**
|
|
13
22
|
* This hook returns a record of Cerberus colors from the document root.
|
|
@@ -19,26 +28,41 @@ export type RootColorsResult = Record<string, string>
|
|
|
19
28
|
export function useRootColors(colors: string[] = []): RootColorsResult {
|
|
20
29
|
const [state, dispatch] = useReducer(rootColorsReducer, {})
|
|
21
30
|
|
|
31
|
+
const handleRefetch = useCallback(() => {
|
|
32
|
+
return new Promise<void>((resolve) => {
|
|
33
|
+
dispatch(formatColors(colors))
|
|
34
|
+
resolve()
|
|
35
|
+
})
|
|
36
|
+
}, [])
|
|
37
|
+
|
|
22
38
|
useEffect(() => {
|
|
23
39
|
if (Object.keys(state).length === colors.length) return
|
|
40
|
+
dispatch(formatColors(colors))
|
|
41
|
+
console.log('updating colors in root hook')
|
|
42
|
+
}, [colors])
|
|
43
|
+
|
|
44
|
+
// reducer is already memoized
|
|
45
|
+
return useMemo(
|
|
46
|
+
() => ({ colors: state, refetch: handleRefetch }),
|
|
47
|
+
[state, handleRefetch],
|
|
48
|
+
)
|
|
49
|
+
}
|
|
24
50
|
|
|
25
|
-
|
|
26
|
-
|
|
51
|
+
function formatColors(colors: string[]): Record<string, string> {
|
|
52
|
+
const rootStyles = getComputedStyle(document.body)
|
|
53
|
+
return colors.reduce(
|
|
54
|
+
(acc, color) => {
|
|
27
55
|
const formattedColor = color
|
|
28
56
|
.replace(/([a-z])([A-Z])/g, '$1-$2')
|
|
29
57
|
.toLowerCase()
|
|
30
58
|
.replaceAll('.', '-')
|
|
31
|
-
acc[color
|
|
59
|
+
acc[color] = rootStyles
|
|
32
60
|
.getPropertyValue(`--cerberus-colors-${formattedColor}`)
|
|
33
61
|
.trim()
|
|
34
62
|
return acc
|
|
35
|
-
},
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
}, [colors])
|
|
39
|
-
|
|
40
|
-
// reducer is already memoized
|
|
41
|
-
return state
|
|
63
|
+
},
|
|
64
|
+
{} as Record<string, string>,
|
|
65
|
+
)
|
|
42
66
|
}
|
|
43
67
|
|
|
44
68
|
function rootColorsReducer(
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
// src/components/Portal.tsx
|
|
2
|
-
import { createPortal } from "react-dom";
|
|
3
|
-
function Portal(props) {
|
|
4
|
-
const container = props.container || document.body;
|
|
5
|
-
return createPortal(props.children, container, props.key);
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
export {
|
|
9
|
-
Portal
|
|
10
|
-
};
|
|
11
|
-
//# sourceMappingURL=chunk-K2PSHGS7.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/components/Portal.tsx"],"sourcesContent":["'use client'\n\nimport type { PropsWithChildren } from 'react'\nimport { createPortal } from 'react-dom'\n\n/**\n * This module is the Portal component.\n * @module\n */\n\nexport interface PortalProps {\n /**\n * The root container to render the children into.\n * @default document.body\n */\n container?: Element | DocumentFragment\n /**\n * An optional key to use for the Portal component.\n */\n key?: null | string\n}\n\n/**\n * The Portal component is used to render children into a DOM node that exists outside the DOM hierarchy of the parent component.\n * @see https://cerberus.digitalu.design/react/portal\n * @definition [React Portal Docs](https://react.dev/reference/react-dom/createPortal)\n * @example\n * ```tsx\n * 'use client'\n *\n * import { Portal } from '@cerberus/react'\n *\n * function SomeFeatureWithinSSRPage() {\n * return (\n * <Portal>\n * <div>Portal Content outside of the React VDom tree</div>\n * </Portal>\n * )\n * }\n */\nexport function Portal(props: PropsWithChildren<PortalProps>) {\n const container = props.container || document.body\n return createPortal(props.children, container, props.key)\n}\n"],"mappings":";AAGA,SAAS,oBAAoB;AAqCtB,SAAS,OAAO,OAAuC;AAC5D,QAAM,YAAY,MAAM,aAAa,SAAS;AAC9C,SAAO,aAAa,MAAM,UAAU,WAAW,MAAM,GAAG;AAC1D;","names":[]}
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
// src/hooks/useRootColors.ts
|
|
2
|
-
import { useEffect, useReducer } from "react";
|
|
3
|
-
function useRootColors(colors = []) {
|
|
4
|
-
const [state, dispatch] = useReducer(rootColorsReducer, {});
|
|
5
|
-
useEffect(() => {
|
|
6
|
-
if (Object.keys(state).length === colors.length) return;
|
|
7
|
-
const rootStyles = getComputedStyle(document.body);
|
|
8
|
-
const rootColors = colors.reduce((acc, color) => {
|
|
9
|
-
const formattedColor = color.replace(/([a-z])([A-Z])/g, "$1-$2").toLowerCase().replaceAll(".", "-");
|
|
10
|
-
acc[color] = rootStyles.getPropertyValue(`--cerberus-colors-${formattedColor}`).trim();
|
|
11
|
-
return acc;
|
|
12
|
-
}, {});
|
|
13
|
-
dispatch(rootColors);
|
|
14
|
-
}, [colors]);
|
|
15
|
-
return state;
|
|
16
|
-
}
|
|
17
|
-
function rootColorsReducer(state, action) {
|
|
18
|
-
return { ...state, ...action };
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export {
|
|
22
|
-
useRootColors
|
|
23
|
-
};
|
|
24
|
-
//# sourceMappingURL=chunk-RO4AJOVX.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/hooks/useRootColors.ts"],"sourcesContent":["'use client'\n\nimport { useEffect, useReducer } from 'react'\n\n/**\n * This module provides a hook to get Cerberus colors from the document root.\n * @module useRootColors\n */\n\nexport type RootColorsResult = Record<string, string>\n\n/**\n * This hook returns a record of Cerberus colors from the document root.\n * This is useful when you are working with a component that uses the `<canvas>`\n * element.\n * @param colors - An array of Cerberus tokens to get from the document root (i.e. `['dataViz.diverging.50', 'dataViz.diverging.200']`).\n * @returns A record of Cerberus colors where the key is the token name provided and the value is the color hex.\n */\nexport function useRootColors(colors: string[] = []): RootColorsResult {\n const [state, dispatch] = useReducer(rootColorsReducer, {})\n\n useEffect(() => {\n if (Object.keys(state).length === colors.length) return\n\n const rootStyles = getComputedStyle(document.body)\n const rootColors = colors.reduce((acc, color) => {\n const formattedColor = color\n .replace(/([a-z])([A-Z])/g, '$1-$2')\n .toLowerCase()\n .replaceAll('.', '-')\n acc[color as keyof typeof acc] = rootStyles\n .getPropertyValue(`--cerberus-colors-${formattedColor}`)\n .trim()\n return acc\n }, {} as RootColorsResult)\n\n dispatch(rootColors)\n }, [colors])\n\n // reducer is already memoized\n return state\n}\n\nfunction rootColorsReducer(\n state: Record<string, string>,\n action: Record<string, string>,\n): Record<string, string> {\n return { ...state, ...action }\n}\n"],"mappings":";AAEA,SAAS,WAAW,kBAAkB;AAgB/B,SAAS,cAAc,SAAmB,CAAC,GAAqB;AACrE,QAAM,CAAC,OAAO,QAAQ,IAAI,WAAW,mBAAmB,CAAC,CAAC;AAE1D,YAAU,MAAM;AACd,QAAI,OAAO,KAAK,KAAK,EAAE,WAAW,OAAO,OAAQ;AAEjD,UAAM,aAAa,iBAAiB,SAAS,IAAI;AACjD,UAAM,aAAa,OAAO,OAAO,CAAC,KAAK,UAAU;AAC/C,YAAM,iBAAiB,MACpB,QAAQ,mBAAmB,OAAO,EAClC,YAAY,EACZ,WAAW,KAAK,GAAG;AACtB,UAAI,KAAyB,IAAI,WAC9B,iBAAiB,qBAAqB,cAAc,EAAE,EACtD,KAAK;AACR,aAAO;AAAA,IACT,GAAG,CAAC,CAAqB;AAEzB,aAAS,UAAU;AAAA,EACrB,GAAG,CAAC,MAAM,CAAC;AAGX,SAAO;AACT;AAEA,SAAS,kBACP,OACA,QACwB;AACxB,SAAO,EAAE,GAAG,OAAO,GAAG,OAAO;AAC/B;","names":[]}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|