bento-charts
Version:
Charts library for Bento-platform
42 lines • 1.74 kB
JavaScript
import { jsx as _jsx } from "react/jsx-runtime";
import { createContext, useContext } from 'react';
import { DEFAULT_CHART_THEME, defaultTranslationObject } from './constants/chartConstants';
var DEFAULT_CONTEXT = {
theme: DEFAULT_CHART_THEME,
translation: defaultTranslationObject.en,
threshold: 0,
maxLabelChars: 14,
};
var ChartContext = createContext(DEFAULT_CONTEXT);
export function useChartTheme() {
return useContext(ChartContext).theme;
}
export function useChartTranslation() {
return useContext(ChartContext).translation;
}
export function useChartThreshold() {
return useContext(ChartContext).threshold;
}
export function useChartMaxLabelChars() {
return useContext(ChartContext).maxLabelChars;
}
var ChartConfigProvider = function (_a) {
var theme = _a.theme, Lng = _a.Lng, translationMap = _a.translationMap, children = _a.children, globalThreshold = _a.globalThreshold, maxLabelChars = _a.maxLabelChars;
var lang = 'en';
try {
lang = Lng;
}
catch (e) {
console.error('Lng is not a supported language', e);
return null;
}
var contextValue = {
theme: theme !== null && theme !== void 0 ? theme : DEFAULT_CONTEXT.theme,
translation: translationMap ? translationMap[lang] : defaultTranslationObject[lang],
threshold: globalThreshold !== null && globalThreshold !== void 0 ? globalThreshold : DEFAULT_CONTEXT.threshold,
maxLabelChars: maxLabelChars !== null && maxLabelChars !== void 0 ? maxLabelChars : DEFAULT_CONTEXT.maxLabelChars,
};
return _jsx(ChartContext.Provider, { value: contextValue, children: children });
};
export default ChartConfigProvider;
//# sourceMappingURL=ChartConfigProvider.js.map