@cerberus-design/react 0.13.1-next-8c8a5ee → 0.13.1-next-b2ca1e0
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 +28 -0
- package/build/legacy/hooks/useRootColors.cjs +64 -0
- package/build/legacy/hooks/useRootColors.cjs.map +1 -0
- package/build/legacy/index.cjs +37 -0
- package/build/legacy/index.cjs.map +1 -1
- package/build/modern/_tsup-dts-rollup.d.ts +28 -0
- package/build/modern/{chunk-5KHGTLFM.js → chunk-B3LRHIEG.js} +6 -6
- package/build/modern/{chunk-4D6VIGNQ.js → chunk-FHS7VVGN.js} +6 -6
- package/build/modern/chunk-RMVJK26W.js +39 -0
- package/build/modern/chunk-RMVJK26W.js.map +1 -0
- package/build/modern/{chunk-MMHCX2RG.js → chunk-S6JWPDB4.js} +6 -6
- package/build/modern/{chunk-MXMVC3ZQ.js → chunk-SRPSJGNI.js} +9 -9
- package/build/modern/context/confirm-modal.js +3 -3
- package/build/modern/context/cta-modal.js +4 -4
- package/build/modern/context/notification-center.js +3 -3
- package/build/modern/context/prompt-modal.js +3 -3
- package/build/modern/hooks/useRootColors.js +8 -0
- package/build/modern/hooks/useRootColors.js.map +1 -0
- package/build/modern/index.js +37 -33
- package/build/modern/index.js.map +1 -1
- package/package.json +2 -2
- package/src/hooks/useRootColors.ts +73 -0
- package/src/index.ts +1 -0
- /package/build/modern/{chunk-5KHGTLFM.js.map → chunk-B3LRHIEG.js.map} +0 -0
- /package/build/modern/{chunk-4D6VIGNQ.js.map → chunk-FHS7VVGN.js.map} +0 -0
- /package/build/modern/{chunk-MMHCX2RG.js.map → chunk-S6JWPDB4.js.map} +0 -0
- /package/build/modern/{chunk-MXMVC3ZQ.js.map → chunk-SRPSJGNI.js.map} +0 -0
|
@@ -2097,6 +2097,23 @@ export { RadioRecipe as RadioRecipe_alias_1 }
|
|
|
2097
2097
|
|
|
2098
2098
|
export { rectIntersection }
|
|
2099
2099
|
|
|
2100
|
+
/**
|
|
2101
|
+
* This module provides a hook to get Cerberus colors from the document root.
|
|
2102
|
+
* @module useRootColors
|
|
2103
|
+
*/
|
|
2104
|
+
declare interface RootColorsResult {
|
|
2105
|
+
/**
|
|
2106
|
+
* A record of Cerberus colors where the key is the token name provided and the value is the color hex.
|
|
2107
|
+
*/
|
|
2108
|
+
colors: Record<string, string>;
|
|
2109
|
+
/**
|
|
2110
|
+
* A function to refetch the Cerberus colors from the document root. Useful when you need the latest colors after a theme/mode change.
|
|
2111
|
+
*/
|
|
2112
|
+
refetch: () => Promise<void>;
|
|
2113
|
+
}
|
|
2114
|
+
export { RootColorsResult }
|
|
2115
|
+
export { RootColorsResult as RootColorsResult_alias_1 }
|
|
2116
|
+
|
|
2100
2117
|
export { ScreenReaderInstructions }
|
|
2101
2118
|
|
|
2102
2119
|
/**
|
|
@@ -3010,6 +3027,17 @@ declare function usePromptModal(): PromptModalValue;
|
|
|
3010
3027
|
export { usePromptModal }
|
|
3011
3028
|
export { usePromptModal as usePromptModal_alias_1 }
|
|
3012
3029
|
|
|
3030
|
+
/**
|
|
3031
|
+
* This hook returns a record of Cerberus colors from the document root.
|
|
3032
|
+
* This is useful when you are working with a component that uses the `<canvas>`
|
|
3033
|
+
* element.
|
|
3034
|
+
* @param colors - An array of Cerberus tokens to get from the document root (i.e. `['dataViz.diverging.50', 'dataViz.diverging.200']`).
|
|
3035
|
+
* @returns A record of Cerberus colors where the key is the token name provided and the value is the color hex.
|
|
3036
|
+
*/
|
|
3037
|
+
declare function useRootColors(colors?: string[]): RootColorsResult;
|
|
3038
|
+
export { useRootColors }
|
|
3039
|
+
export { useRootColors as useRootColors_alias_1 }
|
|
3040
|
+
|
|
3013
3041
|
export { useSensor }
|
|
3014
3042
|
|
|
3015
3043
|
export { useSensors }
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
"use client";
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
20
|
+
|
|
21
|
+
// src/hooks/useRootColors.ts
|
|
22
|
+
var useRootColors_exports = {};
|
|
23
|
+
__export(useRootColors_exports, {
|
|
24
|
+
useRootColors: () => useRootColors
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(useRootColors_exports);
|
|
27
|
+
var import_react = require("react");
|
|
28
|
+
function useRootColors(colors = []) {
|
|
29
|
+
const [state, dispatch] = (0, import_react.useReducer)(rootColorsReducer, {});
|
|
30
|
+
const handleRefetch = (0, import_react.useCallback)(() => {
|
|
31
|
+
return new Promise((resolve) => {
|
|
32
|
+
dispatch(formatColors(colors));
|
|
33
|
+
resolve();
|
|
34
|
+
});
|
|
35
|
+
}, []);
|
|
36
|
+
(0, import_react.useEffect)(() => {
|
|
37
|
+
if (Object.keys(state).length === colors.length) return;
|
|
38
|
+
dispatch(formatColors(colors));
|
|
39
|
+
console.log("updating colors in root hook");
|
|
40
|
+
}, [colors]);
|
|
41
|
+
return (0, import_react.useMemo)(
|
|
42
|
+
() => ({ colors: state, refetch: handleRefetch }),
|
|
43
|
+
[state, handleRefetch]
|
|
44
|
+
);
|
|
45
|
+
}
|
|
46
|
+
function formatColors(colors) {
|
|
47
|
+
const rootStyles = getComputedStyle(document.body);
|
|
48
|
+
return colors.reduce(
|
|
49
|
+
(acc, color) => {
|
|
50
|
+
const formattedColor = color.replace(/([a-z])([A-Z])/g, "$1-$2").toLowerCase().replaceAll(".", "-");
|
|
51
|
+
acc[color] = rootStyles.getPropertyValue(`--cerberus-colors-${formattedColor}`).trim();
|
|
52
|
+
return acc;
|
|
53
|
+
},
|
|
54
|
+
{}
|
|
55
|
+
);
|
|
56
|
+
}
|
|
57
|
+
function rootColorsReducer(state, action) {
|
|
58
|
+
return { ...state, ...action };
|
|
59
|
+
}
|
|
60
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
61
|
+
0 && (module.exports = {
|
|
62
|
+
useRootColors
|
|
63
|
+
});
|
|
64
|
+
//# sourceMappingURL=useRootColors.cjs.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":";;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,mBAA4D;AAyBrD,SAAS,cAAc,SAAmB,CAAC,GAAqB;AACrE,QAAM,CAAC,OAAO,QAAQ,QAAI,yBAAW,mBAAmB,CAAC,CAAC;AAE1D,QAAM,oBAAgB,0BAAY,MAAM;AACtC,WAAO,IAAI,QAAc,CAAC,YAAY;AACpC,eAAS,aAAa,MAAM,CAAC;AAC7B,cAAQ;AAAA,IACV,CAAC;AAAA,EACH,GAAG,CAAC,CAAC;AAEL,8BAAU,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,aAAO;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":[]}
|
package/build/legacy/index.cjs
CHANGED
|
@@ -107,6 +107,7 @@ __export(src_exports, {
|
|
|
107
107
|
useNavMenuContext: () => useNavMenuContext,
|
|
108
108
|
useNotificationCenter: () => useNotificationCenter,
|
|
109
109
|
usePromptModal: () => usePromptModal,
|
|
110
|
+
useRootColors: () => useRootColors,
|
|
110
111
|
useTabsContext: () => useTabsContext,
|
|
111
112
|
useTabsKeyboardNavigation: () => useTabsKeyboardNavigation,
|
|
112
113
|
useTheme: () => useTheme,
|
|
@@ -3120,6 +3121,41 @@ function useToggle(options) {
|
|
|
3120
3121
|
return (0, import_react24.useMemo)(() => ({ checked, handleChange }), [checked, handleChange]);
|
|
3121
3122
|
}
|
|
3122
3123
|
|
|
3124
|
+
// src/hooks/useRootColors.ts
|
|
3125
|
+
var import_react25 = require("react");
|
|
3126
|
+
function useRootColors(colors = []) {
|
|
3127
|
+
const [state, dispatch] = (0, import_react25.useReducer)(rootColorsReducer, {});
|
|
3128
|
+
const handleRefetch = (0, import_react25.useCallback)(() => {
|
|
3129
|
+
return new Promise((resolve) => {
|
|
3130
|
+
dispatch(formatColors(colors));
|
|
3131
|
+
resolve();
|
|
3132
|
+
});
|
|
3133
|
+
}, []);
|
|
3134
|
+
(0, import_react25.useEffect)(() => {
|
|
3135
|
+
if (Object.keys(state).length === colors.length) return;
|
|
3136
|
+
dispatch(formatColors(colors));
|
|
3137
|
+
console.log("updating colors in root hook");
|
|
3138
|
+
}, [colors]);
|
|
3139
|
+
return (0, import_react25.useMemo)(
|
|
3140
|
+
() => ({ colors: state, refetch: handleRefetch }),
|
|
3141
|
+
[state, handleRefetch]
|
|
3142
|
+
);
|
|
3143
|
+
}
|
|
3144
|
+
function formatColors(colors) {
|
|
3145
|
+
const rootStyles = getComputedStyle(document.body);
|
|
3146
|
+
return colors.reduce(
|
|
3147
|
+
(acc, color) => {
|
|
3148
|
+
const formattedColor = color.replace(/([a-z])([A-Z])/g, "$1-$2").toLowerCase().replaceAll(".", "-");
|
|
3149
|
+
acc[color] = rootStyles.getPropertyValue(`--cerberus-colors-${formattedColor}`).trim();
|
|
3150
|
+
return acc;
|
|
3151
|
+
},
|
|
3152
|
+
{}
|
|
3153
|
+
);
|
|
3154
|
+
}
|
|
3155
|
+
function rootColorsReducer(state, action) {
|
|
3156
|
+
return { ...state, ...action };
|
|
3157
|
+
}
|
|
3158
|
+
|
|
3123
3159
|
// src/utils/index.ts
|
|
3124
3160
|
function formatNotifyCount(count) {
|
|
3125
3161
|
if (count > 99) return "99+";
|
|
@@ -3216,6 +3252,7 @@ __reExport(src_exports, require("@dnd-kit/core"), module.exports);
|
|
|
3216
3252
|
useNavMenuContext,
|
|
3217
3253
|
useNotificationCenter,
|
|
3218
3254
|
usePromptModal,
|
|
3255
|
+
useRootColors,
|
|
3219
3256
|
useTabsContext,
|
|
3220
3257
|
useTabsKeyboardNavigation,
|
|
3221
3258
|
useTheme,
|