bento-charts 2.1.0 → 2.1.1
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.
|
@@ -3,11 +3,12 @@ import { ChartTheme, LngDictionary, TranslationObject } from './types/chartTypes
|
|
|
3
3
|
export declare function useChartTheme(): ChartTheme;
|
|
4
4
|
export declare function useChartTranslation(): LngDictionary;
|
|
5
5
|
export declare function useChartThreshold(): number;
|
|
6
|
-
declare const ChartConfigProvider: ({ theme, Lng, translationMap, children, globalThreshold
|
|
7
|
-
|
|
6
|
+
declare const ChartConfigProvider: ({ theme, Lng, translationMap, children, globalThreshold }: ChartConfigProviderProps) => import("react/jsx-runtime").JSX.Element | null;
|
|
7
|
+
type ChartConfigProviderProps = {
|
|
8
|
+
theme?: ChartTheme;
|
|
8
9
|
Lng: string;
|
|
9
|
-
translationMap?: TranslationObject
|
|
10
|
+
translationMap?: TranslationObject;
|
|
10
11
|
children: React.ReactElement;
|
|
11
|
-
globalThreshold?: number
|
|
12
|
-
}
|
|
12
|
+
globalThreshold?: number;
|
|
13
|
+
};
|
|
13
14
|
export default ChartConfigProvider;
|
|
@@ -12,29 +12,37 @@ var __assign = (this && this.__assign) || function () {
|
|
|
12
12
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
13
13
|
import React, { useContext } from 'react';
|
|
14
14
|
import { DEFAULT_CHART_THEME, defaultTranslationObject } from './constants/chartConstants';
|
|
15
|
-
var
|
|
15
|
+
var DEFAULT_CONTEXT = {
|
|
16
|
+
theme: DEFAULT_CHART_THEME,
|
|
17
|
+
translation: defaultTranslationObject.en,
|
|
18
|
+
threshold: 0,
|
|
19
|
+
};
|
|
20
|
+
var ChartContext = React.createContext(DEFAULT_CONTEXT);
|
|
16
21
|
export function useChartTheme() {
|
|
17
|
-
return useContext(
|
|
22
|
+
return useContext(ChartContext).theme;
|
|
18
23
|
}
|
|
19
|
-
var ChartTranslationContext = React.createContext(defaultTranslationObject.en);
|
|
20
24
|
export function useChartTranslation() {
|
|
21
|
-
return useContext(
|
|
25
|
+
return useContext(ChartContext).translation;
|
|
22
26
|
}
|
|
23
|
-
var ChartThresholdContext = React.createContext(0);
|
|
24
27
|
export function useChartThreshold() {
|
|
25
|
-
return useContext(
|
|
28
|
+
return useContext(ChartContext).threshold;
|
|
26
29
|
}
|
|
27
|
-
// TODO: reduce number of contexts
|
|
28
30
|
var ChartConfigProvider = function (_a) {
|
|
29
|
-
var
|
|
31
|
+
var theme = _a.theme, Lng = _a.Lng, translationMap = _a.translationMap, children = _a.children, globalThreshold = _a.globalThreshold;
|
|
30
32
|
var lang = 'en';
|
|
31
33
|
try {
|
|
32
34
|
lang = Lng;
|
|
33
35
|
}
|
|
34
36
|
catch (e) {
|
|
35
37
|
console.error('Lng is not a supported language');
|
|
38
|
+
return null;
|
|
36
39
|
}
|
|
37
|
-
|
|
40
|
+
var contextValue = {
|
|
41
|
+
theme: theme !== null && theme !== void 0 ? theme : DEFAULT_CONTEXT.theme,
|
|
42
|
+
translation: translationMap ? translationMap[lang] : defaultTranslationObject[lang],
|
|
43
|
+
threshold: globalThreshold !== null && globalThreshold !== void 0 ? globalThreshold : DEFAULT_CONTEXT.threshold,
|
|
44
|
+
};
|
|
45
|
+
return _jsx(ChartContext.Provider, __assign({ value: contextValue }, { children: children }));
|
|
38
46
|
};
|
|
39
47
|
export default ChartConfigProvider;
|
|
40
48
|
//# sourceMappingURL=ChartConfigProvider.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ChartConfigProvider.js","sourceRoot":"","sources":["../src/ChartConfigProvider.tsx"],"names":[],"mappings":";;;;;;;;;;;;AAAA,OAAO,KAAK,EAAE,EAAE,UAAU,EAAE,MAAM,OAAO,CAAC;AAE1C,OAAO,EAAE,mBAAmB,EAAE,wBAAwB,EAAE,MAAM,4BAA4B,CAAC;
|
|
1
|
+
{"version":3,"file":"ChartConfigProvider.js","sourceRoot":"","sources":["../src/ChartConfigProvider.tsx"],"names":[],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AAC;IACF,OAAO,KAAC,YAAY,CAAC,QAAQ,aAAC,KAAK,EAAE,YAAY,gBAAG,QAAQ,IAAyB,CAAC;AACxF,CAAC,CAAC;AAUF,eAAe,mBAAmB,CAAC"}
|
package/package.json
CHANGED
|
@@ -3,49 +3,54 @@ import React, { useContext } from 'react';
|
|
|
3
3
|
import { DEFAULT_CHART_THEME, defaultTranslationObject } from './constants/chartConstants';
|
|
4
4
|
import { ChartTheme, LngDictionary, SupportedLng, TranslationObject } from './types/chartTypes';
|
|
5
5
|
|
|
6
|
-
|
|
6
|
+
type ChartContextType = {
|
|
7
|
+
theme: ChartTheme;
|
|
8
|
+
translation: LngDictionary;
|
|
9
|
+
threshold: number;
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
const DEFAULT_CONTEXT: ChartContextType = {
|
|
13
|
+
theme: DEFAULT_CHART_THEME,
|
|
14
|
+
translation: defaultTranslationObject.en,
|
|
15
|
+
threshold: 0,
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
const ChartContext = React.createContext<ChartContextType>(DEFAULT_CONTEXT);
|
|
19
|
+
|
|
7
20
|
export function useChartTheme() {
|
|
8
|
-
return useContext(
|
|
21
|
+
return useContext(ChartContext).theme;
|
|
9
22
|
}
|
|
10
23
|
|
|
11
|
-
const ChartTranslationContext = React.createContext<LngDictionary>(defaultTranslationObject.en);
|
|
12
24
|
export function useChartTranslation() {
|
|
13
|
-
return useContext(
|
|
25
|
+
return useContext(ChartContext).translation;
|
|
14
26
|
}
|
|
15
27
|
|
|
16
|
-
const ChartThresholdContext = React.createContext<number>(0);
|
|
17
|
-
|
|
18
28
|
export function useChartThreshold() {
|
|
19
|
-
return useContext(
|
|
29
|
+
return useContext(ChartContext).threshold;
|
|
20
30
|
}
|
|
21
31
|
|
|
22
|
-
|
|
23
|
-
const ChartConfigProvider = ({
|
|
24
|
-
theme = DEFAULT_CHART_THEME,
|
|
25
|
-
Lng,
|
|
26
|
-
translationMap,
|
|
27
|
-
children,
|
|
28
|
-
globalThreshold = 0,
|
|
29
|
-
}: {
|
|
30
|
-
theme?: ChartTheme;
|
|
31
|
-
Lng: string;
|
|
32
|
-
translationMap?: TranslationObject;
|
|
33
|
-
children: React.ReactElement;
|
|
34
|
-
globalThreshold?: number;
|
|
35
|
-
}) => {
|
|
32
|
+
const ChartConfigProvider = ({ theme, Lng, translationMap, children, globalThreshold }: ChartConfigProviderProps) => {
|
|
36
33
|
let lang: SupportedLng = 'en';
|
|
37
34
|
try {
|
|
38
35
|
lang = Lng as SupportedLng;
|
|
39
36
|
} catch (e) {
|
|
40
37
|
console.error('Lng is not a supported language');
|
|
38
|
+
return null;
|
|
41
39
|
}
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
40
|
+
const contextValue = {
|
|
41
|
+
theme: theme ?? DEFAULT_CONTEXT.theme,
|
|
42
|
+
translation: translationMap ? translationMap[lang] : defaultTranslationObject[lang],
|
|
43
|
+
threshold: globalThreshold ?? DEFAULT_CONTEXT.threshold,
|
|
44
|
+
};
|
|
45
|
+
return <ChartContext.Provider value={contextValue}>{children}</ChartContext.Provider>;
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
type ChartConfigProviderProps = {
|
|
49
|
+
theme?: ChartTheme;
|
|
50
|
+
Lng: string;
|
|
51
|
+
translationMap?: TranslationObject;
|
|
52
|
+
children: React.ReactElement;
|
|
53
|
+
globalThreshold?: number;
|
|
49
54
|
};
|
|
50
55
|
|
|
51
56
|
export default ChartConfigProvider;
|