@neo4j-ndl/react
Version:
React implementation of Neo4j Design System
56 lines • 2.05 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.n = void 0;
/**
*
* Copyright (c) "Neo4j"
* Neo4j Sweden AB [http://neo4j.com]
*
* This file is part of Neo4j.
*
* Neo4j is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
const ThemeProvider_1 = require("./ThemeProvider");
// eslint-disable-next-line @typescript-eslint/no-explicit-any
function defaultStringToJson(path, json = {}, theme) {
const parts = path.split('.');
let part;
while ((part = parts.shift())) {
if (typeof json[part] !== 'object') {
return json[part];
}
json = json[part];
// Specific for theme tokens
if (part === 'theme') {
json = json[theme];
}
}
}
const useN = (path, stringToJson = defaultStringToJson) => {
const { theme, tokens } = (0, ThemeProvider_1.useNeedleTheme)();
if (!tokens) {
console.error('design tokens not found, you need to set the design tokens in the NeedleThemeProvider');
return;
}
const value = stringToJson(path, tokens, theme);
if (!value) {
console.warn(`design token value "${path}" not found, are you sure the string path is correct?`);
}
return value;
};
// React will complain if we don't use the prefix "use" for
// holding the useNeedleTheme function call. "n" is a more
// convenient name for the function.
exports.n = useN;
//# sourceMappingURL=agnostic.js.map