@cerberus-design/react 0.13.1-next-8c8a5ee → 0.13.1-next-394d7c4
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 +19 -0
- package/build/legacy/hooks/useRootColors.cjs +49 -0
- package/build/legacy/hooks/useRootColors.cjs.map +1 -0
- package/build/legacy/index.cjs +22 -0
- package/build/legacy/index.cjs.map +1 -1
- package/build/modern/_tsup-dts-rollup.d.ts +19 -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-RO4AJOVX.js +24 -0
- package/build/modern/chunk-RO4AJOVX.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 +3 -3
- package/src/hooks/useRootColors.ts +49 -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,14 @@ 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 type RootColorsResult = Record<string, string>;
|
|
2105
|
+
export { RootColorsResult }
|
|
2106
|
+
export { RootColorsResult as RootColorsResult_alias_1 }
|
|
2107
|
+
|
|
2100
2108
|
export { ScreenReaderInstructions }
|
|
2101
2109
|
|
|
2102
2110
|
/**
|
|
@@ -3010,6 +3018,17 @@ declare function usePromptModal(): PromptModalValue;
|
|
|
3010
3018
|
export { usePromptModal }
|
|
3011
3019
|
export { usePromptModal as usePromptModal_alias_1 }
|
|
3012
3020
|
|
|
3021
|
+
/**
|
|
3022
|
+
* This hook returns a record of Cerberus colors from the document root.
|
|
3023
|
+
* This is useful when you are working with a component that uses the `<canvas>`
|
|
3024
|
+
* element.
|
|
3025
|
+
* @param colors - An array of Cerberus tokens to get from the document root (i.e. `['dataViz.diverging.50', 'dataViz.diverging.200']`).
|
|
3026
|
+
* @returns A record of Cerberus colors where the key is the token name provided and the value is the color hex.
|
|
3027
|
+
*/
|
|
3028
|
+
declare function useRootColors(colors?: string[]): RootColorsResult;
|
|
3029
|
+
export { useRootColors }
|
|
3030
|
+
export { useRootColors as useRootColors_alias_1 }
|
|
3031
|
+
|
|
3013
3032
|
export { useSensor }
|
|
3014
3033
|
|
|
3015
3034
|
export { useSensors }
|
|
@@ -0,0 +1,49 @@
|
|
|
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
|
+
(0, import_react.useEffect)(() => {
|
|
31
|
+
if (Object.keys(state).length === colors.length) return;
|
|
32
|
+
const rootStyles = getComputedStyle(document.body);
|
|
33
|
+
const rootColors = colors.reduce((acc, color) => {
|
|
34
|
+
const formattedColor = color.replace(/([a-z])([A-Z])/g, "$1-$2").toLowerCase().replaceAll(".", "-");
|
|
35
|
+
acc[color] = rootStyles.getPropertyValue(`--cerberus-colors-${formattedColor}`).trim();
|
|
36
|
+
return acc;
|
|
37
|
+
}, {});
|
|
38
|
+
dispatch(rootColors);
|
|
39
|
+
}, [colors]);
|
|
40
|
+
return state;
|
|
41
|
+
}
|
|
42
|
+
function rootColorsReducer(state, action) {
|
|
43
|
+
return { ...state, ...action };
|
|
44
|
+
}
|
|
45
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
46
|
+
0 && (module.exports = {
|
|
47
|
+
useRootColors
|
|
48
|
+
});
|
|
49
|
+
//# sourceMappingURL=useRootColors.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
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":";;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,mBAAsC;AAgB/B,SAAS,cAAc,SAAmB,CAAC,GAAqB;AACrE,QAAM,CAAC,OAAO,QAAQ,QAAI,yBAAW,mBAAmB,CAAC,CAAC;AAE1D,8BAAU,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":[]}
|
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,26 @@ 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
|
+
(0, import_react25.useEffect)(() => {
|
|
3129
|
+
if (Object.keys(state).length === colors.length) return;
|
|
3130
|
+
const rootStyles = getComputedStyle(document.body);
|
|
3131
|
+
const rootColors = colors.reduce((acc, color) => {
|
|
3132
|
+
const formattedColor = color.replace(/([a-z])([A-Z])/g, "$1-$2").toLowerCase().replaceAll(".", "-");
|
|
3133
|
+
acc[color] = rootStyles.getPropertyValue(`--cerberus-colors-${formattedColor}`).trim();
|
|
3134
|
+
return acc;
|
|
3135
|
+
}, {});
|
|
3136
|
+
dispatch(rootColors);
|
|
3137
|
+
}, [colors]);
|
|
3138
|
+
return state;
|
|
3139
|
+
}
|
|
3140
|
+
function rootColorsReducer(state, action) {
|
|
3141
|
+
return { ...state, ...action };
|
|
3142
|
+
}
|
|
3143
|
+
|
|
3123
3144
|
// src/utils/index.ts
|
|
3124
3145
|
function formatNotifyCount(count) {
|
|
3125
3146
|
if (count > 99) return "99+";
|
|
@@ -3216,6 +3237,7 @@ __reExport(src_exports, require("@dnd-kit/core"), module.exports);
|
|
|
3216
3237
|
useNavMenuContext,
|
|
3217
3238
|
useNotificationCenter,
|
|
3218
3239
|
usePromptModal,
|
|
3240
|
+
useRootColors,
|
|
3219
3241
|
useTabsContext,
|
|
3220
3242
|
useTabsKeyboardNavigation,
|
|
3221
3243
|
useTheme,
|