@ledgerhq/native-ui 0.22.9 → 0.23.0-next.0
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/lib/components/Cards/BannerCard/index.d.ts +1 -8
- package/lib/components/Cards/SideImageCard/index.d.ts +2 -16
- package/lib/components/Form/Input/BaseInput/index.d.ts +2 -66
- package/lib/components/Layout/Box/index.d.ts +1 -8
- package/lib/components/Layout/Flex/index.d.ts +1 -8
- package/lib/components/Layout/Modals/BaseModal/index.js +1 -1
- package/lib/components/index.d.ts +0 -2
- package/lib/components/index.js +0 -2
- package/package.json +21 -24
- package/lib/components/ChartCard/index.d.ts +0 -19
- package/lib/components/ChartCard/index.js +0 -25
- package/lib/components/chart/index.d.ts +0 -15
- package/lib/components/chart/index.js +0 -74
- package/lib/components/chart/types.d.ts +0 -6
- package/lib/components/chart/types.js +0 -1
|
@@ -13,14 +13,7 @@ type CloseProps = {
|
|
|
13
13
|
};
|
|
14
14
|
export declare const Container: import("styled-components").StyledComponent<typeof TouchableOpacity, import("styled-components").DefaultTheme, {}, never>;
|
|
15
15
|
export declare const CloseContainer: import("styled-components").StyledComponent<typeof TouchableOpacity, import("styled-components").DefaultTheme, {}, never>;
|
|
16
|
-
export declare const ChevronContainer: import("styled-components").StyledComponent<typeof import("react-native").View, import("styled-components").DefaultTheme, import("styled
|
|
17
|
-
columnGap?: string | number | undefined;
|
|
18
|
-
rowGap?: string | number | undefined;
|
|
19
|
-
color?: string | undefined;
|
|
20
|
-
display?: string | undefined;
|
|
21
|
-
position?: string | undefined;
|
|
22
|
-
maxHeight?: string | number | undefined;
|
|
23
|
-
}, never>;
|
|
16
|
+
export declare const ChevronContainer: import("styled-components").StyledComponent<typeof import("react-native").View, import("styled-components").DefaultTheme, import("../../styled").BaseStyledProps, never>;
|
|
24
17
|
export declare const CloseButton: ({ onPressDismiss }: CloseProps) => React.JSX.Element;
|
|
25
18
|
declare const BannerCard: (props: CardProps) => React.ReactElement;
|
|
26
19
|
export default BannerCard;
|
|
@@ -9,22 +9,8 @@ export type CardProps = TouchableOpacityProps & {
|
|
|
9
9
|
onPressDismiss?: () => void;
|
|
10
10
|
};
|
|
11
11
|
export declare const Base: import("styled-components").StyledComponent<typeof TouchableOpacity, import("styled-components").DefaultTheme, {}, never>;
|
|
12
|
-
export declare const Container: import("styled-components").StyledComponent<typeof import("react-native").View, import("styled-components").DefaultTheme, import("styled
|
|
13
|
-
|
|
14
|
-
rowGap?: string | number | undefined;
|
|
15
|
-
color?: string | undefined;
|
|
16
|
-
display?: string | undefined;
|
|
17
|
-
position?: string | undefined;
|
|
18
|
-
maxHeight?: string | number | undefined;
|
|
19
|
-
}, never>;
|
|
20
|
-
export declare const ImageContainer: import("styled-components").StyledComponent<typeof import("react-native").View, import("styled-components").DefaultTheme, import("styled-system").SpaceProps<Required<import("styled-system").Theme<import("styled-system").TLengthStyledSystem>>, string | number | symbol> & import("styled-system").FlexboxProps<Required<import("styled-system").Theme<import("styled-system").TLengthStyledSystem>>> & import("styled-system").PositionProps<Required<import("styled-system").Theme<import("styled-system").TLengthStyledSystem>>> & import("styled-system").ColorProps<Required<import("styled-system").Theme<import("styled-system").TLengthStyledSystem>>, string | number | symbol> & import("styled-system").LayoutProps<Required<import("styled-system").Theme<import("styled-system").TLengthStyledSystem>>> & import("styled-system").OverflowProps<Required<import("styled-system").Theme<import("styled-system").TLengthStyledSystem>>> & import("styled-system").BorderProps<Required<import("styled-system").Theme<import("styled-system").TLengthStyledSystem>>, import("csstype").Property.Border<import("styled-system").TLengthStyledSystem>> & import("styled-system").BackgroundProps<Required<import("styled-system").Theme<import("styled-system").TLengthStyledSystem>>, import("csstype").Property.Background<import("styled-system").TLengthStyledSystem>> & {
|
|
21
|
-
columnGap?: string | number | undefined;
|
|
22
|
-
rowGap?: string | number | undefined;
|
|
23
|
-
color?: string | undefined;
|
|
24
|
-
display?: string | undefined;
|
|
25
|
-
position?: string | undefined;
|
|
26
|
-
maxHeight?: string | number | undefined;
|
|
27
|
-
}, never>;
|
|
12
|
+
export declare const Container: import("styled-components").StyledComponent<typeof import("react-native").View, import("styled-components").DefaultTheme, import("../../styled").BaseStyledProps, never>;
|
|
13
|
+
export declare const ImageContainer: import("styled-components").StyledComponent<typeof import("react-native").View, import("styled-components").DefaultTheme, import("../../styled").BaseStyledProps, never>;
|
|
28
14
|
export declare const ImageContent: import("styled-components").StyledComponent<typeof Image, import("styled-components").DefaultTheme, {}, never>;
|
|
29
15
|
export declare const CloseContainer: import("styled-components").StyledComponent<typeof TouchableOpacity, import("styled-components").DefaultTheme, {}, never>;
|
|
30
16
|
export declare const CloseButton: (props: CardProps) => React.JSX.Element;
|
|
@@ -95,71 +95,7 @@ export declare const InputRenderRightContainer: import("styled-components").Styl
|
|
|
95
95
|
paddingLeft: string;
|
|
96
96
|
}, "alignItems" | "flexDirection" | "paddingLeft">;
|
|
97
97
|
declare function Input<T = string>(props: InputProps<T>, ref?: any): JSX.Element;
|
|
98
|
-
declare const _default: <T>(props:
|
|
99
|
-
|
|
100
|
-
* The value of the input.
|
|
101
|
-
*/
|
|
102
|
-
value: T;
|
|
103
|
-
/**
|
|
104
|
-
* A function that will render some content on the left side of the input.
|
|
105
|
-
*/
|
|
106
|
-
renderLeft?: React.ReactNode | ((props: InputProps<T>, ref: React.RefObject<{
|
|
107
|
-
clear: () => void;
|
|
108
|
-
}>) => React.ReactNode);
|
|
109
|
-
/**
|
|
110
|
-
* A function that will render some content on the right side of the input.
|
|
111
|
-
*/
|
|
112
|
-
renderRight?: React.ReactNode | ((props: InputProps<T>, ref: React.RefObject<{
|
|
113
|
-
clear: () => void;
|
|
114
|
-
}>) => React.ReactNode);
|
|
115
|
-
/**
|
|
116
|
-
* Triggered when the input value is updated.
|
|
117
|
-
*/
|
|
118
|
-
onChange?: ((value: T) => void) | undefined;
|
|
119
|
-
/**
|
|
120
|
-
* Same as onChange but preserves the native event passed as the callback argument.
|
|
121
|
-
*/
|
|
122
|
-
onChangeEvent?: ((e: import("react-native").NativeSyntheticEvent<import("react-native").TextInputChangeEventData>) => void) | undefined;
|
|
123
|
-
/**
|
|
124
|
-
* A function can be provided to serialize a value of any type to a string.
|
|
125
|
-
*
|
|
126
|
-
* This can be useful to wrap the `<BaseInput />` component (which expects a string)
|
|
127
|
-
* and create higher-level components that will automatically perform the input/output
|
|
128
|
-
* conversion to other types.
|
|
129
|
-
*
|
|
130
|
-
* *A serializer function should always be used in conjunction with a deserializer function.*
|
|
131
|
-
*/
|
|
132
|
-
serialize?: ((value: T) => string) | undefined;
|
|
133
|
-
/**
|
|
134
|
-
* A deserializer can be provided to convert the html input value from a string to any other type.
|
|
135
|
-
*
|
|
136
|
-
* *A deserializer function should always be used in conjunction with a serializer function.*
|
|
137
|
-
*/
|
|
138
|
-
deserialize?: ((value: string) => T) | undefined;
|
|
139
|
-
/**
|
|
140
|
-
* Additional style for the container element.
|
|
141
|
-
*/
|
|
142
|
-
containerStyle?: StyleProp<ViewStyle>;
|
|
143
|
-
/**
|
|
144
|
-
* Additional style for the input container element.
|
|
145
|
-
*/
|
|
146
|
-
inputContainerStyle?: (StyleProp<ViewStyle> & TextStyle) | undefined;
|
|
147
|
-
/**
|
|
148
|
-
* Additional style for the baseInput container element.
|
|
149
|
-
*/
|
|
150
|
-
baseInputContainerStyle?: TextStyle | undefined;
|
|
151
|
-
/**
|
|
152
|
-
* Additional style for the error container element.
|
|
153
|
-
*/
|
|
154
|
-
inputErrorContainerStyles?: StyleProp<ViewStyle>;
|
|
155
|
-
inputErrorColor?: string | undefined;
|
|
156
|
-
showErrorIcon?: boolean | undefined;
|
|
157
|
-
hasBorder?: boolean | undefined;
|
|
158
|
-
/**
|
|
159
|
-
* Optional text color parameter.
|
|
160
|
-
*/
|
|
161
|
-
color?: string | undefined;
|
|
162
|
-
} & {
|
|
163
|
-
ref?: React.ForwardedRef<TextInput> | undefined;
|
|
98
|
+
declare const _default: <T>(props: InputProps<T> & {
|
|
99
|
+
ref?: React.ForwardedRef<TextInput> | null;
|
|
164
100
|
}) => ReturnType<typeof Input>;
|
|
165
101
|
export default _default;
|
|
@@ -1,11 +1,4 @@
|
|
|
1
1
|
import { BaseStyledProps } from "../../styled";
|
|
2
2
|
export type BoxProps = BaseStyledProps;
|
|
3
|
-
declare const Box: import("styled-components").StyledComponent<typeof import("react-native").View, import("styled-components").DefaultTheme,
|
|
4
|
-
columnGap?: string | number | undefined;
|
|
5
|
-
rowGap?: string | number | undefined;
|
|
6
|
-
color?: string | undefined;
|
|
7
|
-
display?: string | undefined;
|
|
8
|
-
position?: string | undefined;
|
|
9
|
-
maxHeight?: string | number | undefined;
|
|
10
|
-
}, never>;
|
|
3
|
+
declare const Box: import("styled-components").StyledComponent<typeof import("react-native").View, import("styled-components").DefaultTheme, BaseStyledProps, never>;
|
|
11
4
|
export default Box;
|
|
@@ -1,12 +1,5 @@
|
|
|
1
1
|
import { BaseStyledProps } from "../../styled";
|
|
2
2
|
export type FlexBoxProps = BaseStyledProps;
|
|
3
3
|
export type Props = FlexBoxProps;
|
|
4
|
-
declare const FlexBox: import("styled-components").StyledComponent<typeof import("react-native").View, import("styled-components").DefaultTheme,
|
|
5
|
-
columnGap?: string | number | undefined;
|
|
6
|
-
rowGap?: string | number | undefined;
|
|
7
|
-
color?: string | undefined;
|
|
8
|
-
display?: string | undefined;
|
|
9
|
-
position?: string | undefined;
|
|
10
|
-
maxHeight?: string | number | undefined;
|
|
11
|
-
}, never>;
|
|
4
|
+
declare const FlexBox: import("styled-components").StyledComponent<typeof import("react-native").View, import("styled-components").DefaultTheme, BaseStyledProps, never>;
|
|
12
5
|
export default FlexBox;
|
|
@@ -73,7 +73,7 @@ export function ModalHeader({ Icon, iconColor, title, description, subtitle, })
|
|
|
73
73
|
export function ModalHeaderCloseButton({ onClose, }) {
|
|
74
74
|
const { colors } = useTheme();
|
|
75
75
|
return (React.createElement(CloseContainer, null,
|
|
76
|
-
React.createElement(ClosePressableExtendedBounds, { onPress: onClose },
|
|
76
|
+
React.createElement(ClosePressableExtendedBounds, { onPress: onClose, testID: "modal-close-button" },
|
|
77
77
|
React.createElement(Close, { color: colors.neutral.c100, size: "XS" }))));
|
|
78
78
|
}
|
|
79
79
|
export default function BaseModal(_a) {
|
package/lib/components/index.js
CHANGED
|
@@ -13,5 +13,3 @@ export * from "./Loader";
|
|
|
13
13
|
export { default as ProgressBar } from "./ProgressBar";
|
|
14
14
|
import * as Transitions_1 from "./transitions";
|
|
15
15
|
export { Transitions_1 as Transitions };
|
|
16
|
-
export { default as Chart } from "./chart";
|
|
17
|
-
export { default as ChartCard } from "./ChartCard";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ledgerhq/native-ui",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.23.0-next.0",
|
|
4
4
|
"description": "Ledger Live - Mobile UI",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -38,30 +38,29 @@
|
|
|
38
38
|
"dependencies": {
|
|
39
39
|
"color": "^4.0.0",
|
|
40
40
|
"react-native-modal": "^13.0.0",
|
|
41
|
-
"react-native-svg": "^13.11.0",
|
|
42
41
|
"rn-range-slider": "2.1.1",
|
|
43
42
|
"styled-system": "^5.1.5",
|
|
44
|
-
"
|
|
45
|
-
"@ledgerhq/
|
|
46
|
-
"@ledgerhq/icons-ui": "^0.6.4",
|
|
43
|
+
"@ledgerhq/crypto-icons-ui": "^1.2.0-next.0",
|
|
44
|
+
"@ledgerhq/icons-ui": "^0.7.0-next.0",
|
|
47
45
|
"@ledgerhq/ui-shared": "^0.2.1"
|
|
48
46
|
},
|
|
49
47
|
"peerDependencies": {
|
|
50
48
|
"react": ">=17",
|
|
51
49
|
"react-native": ">=0.64.0",
|
|
52
|
-
"react-native-reanimated": "
|
|
53
|
-
"styled-components": "^5.3.3"
|
|
50
|
+
"react-native-reanimated": "3.8.1",
|
|
51
|
+
"styled-components": "^5.3.3",
|
|
52
|
+
"react-native-svg": ">=12.1.1"
|
|
54
53
|
},
|
|
55
54
|
"devDependencies": {
|
|
56
|
-
"@babel/core": "^7.
|
|
55
|
+
"@babel/core": "^7.24.3",
|
|
57
56
|
"@babel/generator": "^7.17.2",
|
|
58
57
|
"@babel/plugin-proposal-class-properties": "^7.13.0",
|
|
59
58
|
"@babel/plugin-proposal-export-namespace-from": "^7.16.0",
|
|
60
59
|
"@babel/plugin-proposal-nullish-coalescing-operator": "^7.18.6",
|
|
61
60
|
"@babel/plugin-proposal-optional-chaining": "^7.21.0",
|
|
62
|
-
"@babel/plugin-transform-arrow-functions": "^7.
|
|
63
|
-
"@babel/plugin-transform-shorthand-properties": "^7.
|
|
64
|
-
"@babel/plugin-transform-template-literals": "^7.
|
|
61
|
+
"@babel/plugin-transform-arrow-functions": "^7.24.1",
|
|
62
|
+
"@babel/plugin-transform-shorthand-properties": "^7.24.1",
|
|
63
|
+
"@babel/plugin-transform-template-literals": "^7.24.1",
|
|
65
64
|
"@babel/preset-env": "^7.15.8",
|
|
66
65
|
"@babel/runtime": "^7.17.2",
|
|
67
66
|
"@emotion/core": "^11.0.0",
|
|
@@ -95,7 +94,6 @@
|
|
|
95
94
|
"@types/node": "^20.8.10",
|
|
96
95
|
"@types/prop-types": "^15.7.5",
|
|
97
96
|
"@types/react": "^18.2.21",
|
|
98
|
-
"@types/react-native": "0.72.5",
|
|
99
97
|
"@types/styled-components": "^5.1.3",
|
|
100
98
|
"@types/styled-components-react-native": "^5.1.3",
|
|
101
99
|
"@types/styled-system": "^5.1.13",
|
|
@@ -117,24 +115,25 @@
|
|
|
117
115
|
"expo-modules-core": "1.5.11",
|
|
118
116
|
"fs-extra": "^10.0.1",
|
|
119
117
|
"glob": "^7.2.0",
|
|
120
|
-
"metro": "^0.80.
|
|
121
|
-
"metro-config": "^0.80.
|
|
122
|
-
"metro-core": "^0.80.
|
|
118
|
+
"metro": "^0.80.5",
|
|
119
|
+
"metro-config": "^0.80.5",
|
|
120
|
+
"metro-core": "^0.80.5",
|
|
123
121
|
"metro-minify-uglify": "^0.76.8",
|
|
124
122
|
"metro-react-native-babel-preset": "^0.77.0",
|
|
125
123
|
"metro-react-native-babel-transformer": "^0.77.0",
|
|
126
|
-
"metro-resolver": "^0.80.
|
|
127
|
-
"metro-runtime": "^0.80.
|
|
128
|
-
"metro-source-map": "^0.80.
|
|
129
|
-
"metro-transform-worker": "^0.80.
|
|
124
|
+
"metro-resolver": "^0.80.5",
|
|
125
|
+
"metro-runtime": "^0.80.5",
|
|
126
|
+
"metro-source-map": "^0.80.5",
|
|
127
|
+
"metro-transform-worker": "^0.80.5",
|
|
130
128
|
"minimatch": "^5.1.0",
|
|
131
129
|
"prop-types": "^15.8.1",
|
|
132
130
|
"react": "^18.2.0",
|
|
133
131
|
"react-dom": "^18.2.0",
|
|
134
132
|
"react-is": "^18",
|
|
135
|
-
"react-native": "0.
|
|
136
|
-
"react-native-reanimated": "
|
|
133
|
+
"react-native": "0.73.6",
|
|
134
|
+
"react-native-reanimated": "3.8.1",
|
|
137
135
|
"react-native-safe-area-context": "^4.5.0",
|
|
136
|
+
"react-native-svg": "13.14.0",
|
|
138
137
|
"react-native-web": "~0.19.6",
|
|
139
138
|
"regenerator-runtime": "^0.14.0",
|
|
140
139
|
"rimraf": "^4.4.1",
|
|
@@ -146,10 +145,8 @@
|
|
|
146
145
|
"stylelint-config-styled-components": "^0.1.1",
|
|
147
146
|
"stylelint-processor-styled-components": "^1.10.0",
|
|
148
147
|
"util": "^0.12.5",
|
|
149
|
-
"victory": "^35.5.5",
|
|
150
148
|
"webpack": "^5.76.1",
|
|
151
|
-
"webpack-dev-server": "^4.12.0"
|
|
152
|
-
"@ledgerhq/metro-extra-config": "1.0.1"
|
|
149
|
+
"webpack-dev-server": "^4.12.0"
|
|
153
150
|
},
|
|
154
151
|
"scripts": {
|
|
155
152
|
"android": "expo start --android",
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import React from "react";
|
|
2
|
-
declare const ChartCard: ({ Header, Footer, range, isLoading, refreshChart, chartData, currencyColor, margin, xAxisFormatter, ranges, yAxisFormatter, valueFormatter, }: {
|
|
3
|
-
Header?: React.ReactNode;
|
|
4
|
-
Footer?: React.ReactNode;
|
|
5
|
-
range: string;
|
|
6
|
-
isLoading?: boolean | undefined;
|
|
7
|
-
refreshChart: (request: any) => void;
|
|
8
|
-
chartData: any;
|
|
9
|
-
currencyColor: string;
|
|
10
|
-
margin: number;
|
|
11
|
-
xAxisFormatter?: ((value: number) => string) | undefined;
|
|
12
|
-
ranges: {
|
|
13
|
-
label: string;
|
|
14
|
-
value: string;
|
|
15
|
-
}[];
|
|
16
|
-
yAxisFormatter: (value: number) => string;
|
|
17
|
-
valueFormatter: (value: number) => string;
|
|
18
|
-
}) => React.JSX.Element;
|
|
19
|
-
export default ChartCard;
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import React, { useCallback } from "react";
|
|
2
|
-
import { useTheme } from "styled-components/native";
|
|
3
|
-
import { Flex, GraphTabs, InfiniteLoader, Transitions } from "../index";
|
|
4
|
-
import Chart from "../chart";
|
|
5
|
-
const ChartCard = ({ Header, Footer, range, isLoading, refreshChart, chartData, currencyColor, margin = 0, xAxisFormatter, ranges, yAxisFormatter, valueFormatter, }) => {
|
|
6
|
-
const { colors } = useTheme();
|
|
7
|
-
const rangesLabels = ranges.map(({ label }) => label);
|
|
8
|
-
const activeRangeIndex = ranges.findIndex((r) => r.value === range);
|
|
9
|
-
const setRange = useCallback((index) => {
|
|
10
|
-
var _a;
|
|
11
|
-
if (isLoading)
|
|
12
|
-
return;
|
|
13
|
-
const newRange = (_a = ranges[index]) === null || _a === void 0 ? void 0 : _a.value;
|
|
14
|
-
if (range !== newRange)
|
|
15
|
-
refreshChart({ range: newRange });
|
|
16
|
-
}, [isLoading, range, ranges, refreshChart]);
|
|
17
|
-
return (React.createElement(Flex, { margin: margin, padding: 6, borderRadius: 2, bg: "neutral.c30" },
|
|
18
|
-
Header,
|
|
19
|
-
React.createElement(Flex, { mt: 6, height: 100, alignItems: "center", justifyContent: "center" }, chartData && chartData.length > 0 ? (React.createElement(Transitions.Fade, { status: "entering", duration: 400 },
|
|
20
|
-
React.createElement(Chart, { data: chartData, backgroundColor: colors.neutral.c30, color: currencyColor, valueKey: "value", xAxisFormatter: xAxisFormatter, yAxisFormatter: yAxisFormatter, valueFormatter: valueFormatter, disableTooltips: false }))) : (React.createElement(InfiniteLoader, { size: 32 }))),
|
|
21
|
-
React.createElement(Flex, { mt: 70 },
|
|
22
|
-
React.createElement(GraphTabs, { activeIndex: activeRangeIndex, activeBg: currencyColor, activeColor: "neutral.c30", onChange: setRange, labels: rangesLabels })),
|
|
23
|
-
Footer));
|
|
24
|
-
};
|
|
25
|
-
export default ChartCard;
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
/// <reference types="react" />
|
|
2
|
-
import type { Item } from "./types";
|
|
3
|
-
export type ChartProps = {
|
|
4
|
-
data: Array<Item>;
|
|
5
|
-
backgroundColor: string;
|
|
6
|
-
color: string;
|
|
7
|
-
valueKey?: string;
|
|
8
|
-
height?: number;
|
|
9
|
-
xAxisFormatter?: (timestamp: number) => string;
|
|
10
|
-
yAxisFormatter: (n: number) => string;
|
|
11
|
-
valueFormatter: (n: number) => string;
|
|
12
|
-
disableTooltips: boolean;
|
|
13
|
-
};
|
|
14
|
-
declare const Chart: ({ data, backgroundColor, color, yAxisFormatter, valueFormatter, valueKey, height, xAxisFormatter, disableTooltips, }: ChartProps) => JSX.Element;
|
|
15
|
-
export default Chart;
|
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
import React, { useMemo, useCallback } from "react";
|
|
2
|
-
import { useTheme } from "styled-components/native";
|
|
3
|
-
import { Defs, LinearGradient, Stop } from "react-native-svg";
|
|
4
|
-
import { VictoryLine, VictoryChart, VictoryAxis, VictoryArea, VictoryTooltip, VictoryVoronoiContainer, } from "victory-native";
|
|
5
|
-
import { Flex } from "../index";
|
|
6
|
-
import { hex } from "../../styles/helpers";
|
|
7
|
-
const sortByDate = (a, b) => {
|
|
8
|
-
if (a.date.getTime() < b.date.getTime())
|
|
9
|
-
return -1;
|
|
10
|
-
if (a.date.getTime() > b.date.getTime())
|
|
11
|
-
return 1;
|
|
12
|
-
return 0;
|
|
13
|
-
};
|
|
14
|
-
const Chart = ({ data, backgroundColor, color, yAxisFormatter, valueFormatter, valueKey = "value", height = 200,
|
|
15
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
16
|
-
xAxisFormatter = (timestamp) => `${new Date(timestamp).toLocaleDateString()}`, disableTooltips = false, }) => {
|
|
17
|
-
const theme = useTheme();
|
|
18
|
-
const sortData = useMemo(() => data.sort(sortByDate), [data]);
|
|
19
|
-
const labelFormatted = useCallback(({ datum }) => {
|
|
20
|
-
const valueFormatted = valueFormatter(datum[valueKey]);
|
|
21
|
-
return valueFormatted === "-" ? "0" : valueFormatted;
|
|
22
|
-
}, [valueKey, valueFormatter]);
|
|
23
|
-
const domainValues = useMemo(() => {
|
|
24
|
-
const counterValues = data.map((d) => d[valueKey]);
|
|
25
|
-
return {
|
|
26
|
-
min: Math.min(...counterValues) * 0.8,
|
|
27
|
-
max: Math.max(...counterValues) * 1.2, // 1.2 So the maximum value of the yAxis is a bit bigger than the max value displayed
|
|
28
|
-
};
|
|
29
|
-
}, [data, valueKey]);
|
|
30
|
-
const yAxisStyle = useMemo(() => ({
|
|
31
|
-
grid: {
|
|
32
|
-
stroke: theme.colors.neutral.c40,
|
|
33
|
-
strokeDasharray: "4 4",
|
|
34
|
-
},
|
|
35
|
-
axisLabel: { display: "none" },
|
|
36
|
-
axis: { display: "none" },
|
|
37
|
-
ticks: { display: "none" },
|
|
38
|
-
tickLabels: {
|
|
39
|
-
fill: theme.colors.neutral.c80,
|
|
40
|
-
fontSize: 12,
|
|
41
|
-
},
|
|
42
|
-
}), [theme]);
|
|
43
|
-
const xAxisStyle = useMemo(() => ({
|
|
44
|
-
axis: {
|
|
45
|
-
stroke: theme.colors.neutral.c40,
|
|
46
|
-
strokeDasharray: "4 4",
|
|
47
|
-
},
|
|
48
|
-
tickLabels: {
|
|
49
|
-
fill: theme.colors.neutral.c80,
|
|
50
|
-
fontSize: 12,
|
|
51
|
-
},
|
|
52
|
-
grid: { display: "none" },
|
|
53
|
-
}), [theme]);
|
|
54
|
-
return (React.createElement(Flex, { justifyContent: "center", alignItems: "center" },
|
|
55
|
-
React.createElement(VictoryChart, { scale: { x: "time" }, height: height, domainPadding: { y: 5 }, padding: { top: 30, left: 60, right: 35, bottom: 35 }, maxDomain: { y: domainValues.max }, minDomain: { y: domainValues.min }, containerComponent: React.createElement(VictoryVoronoiContainer
|
|
56
|
-
// @ts-expect-error disable this error for the sake of the monorepo
|
|
57
|
-
, {
|
|
58
|
-
// @ts-expect-error disable this error for the sake of the monorepo
|
|
59
|
-
disable: disableTooltips, voronoiBlacklist: ["victory-area"], labels: labelFormatted, labelComponent: React.createElement(VictoryTooltip, { centerOffset: { y: -10 }, renderInPortal: false, constrainToVisibleArea: true, style: {
|
|
60
|
-
fill: color,
|
|
61
|
-
}, flyoutPadding: 7, flyoutStyle: {
|
|
62
|
-
fill: backgroundColor,
|
|
63
|
-
stroke: color,
|
|
64
|
-
} }) }) },
|
|
65
|
-
React.createElement(VictoryAxis, { dependentAxis: true, crossAxis: true, tickFormat: yAxisFormatter, style: yAxisStyle }),
|
|
66
|
-
React.createElement(VictoryAxis, { crossAxis: false, tickFormat: xAxisFormatter, style: xAxisStyle }),
|
|
67
|
-
React.createElement(Defs, null,
|
|
68
|
-
React.createElement(LinearGradient, { id: "chartGradient", x1: "0.5", x2: "0.5", y1: "0", y2: "1" },
|
|
69
|
-
React.createElement(Stop, { stopColor: hex(color), stopOpacity: "0.15" }),
|
|
70
|
-
React.createElement(Stop, { offset: "1", stopColor: hex(theme.colors.neutral.c00), stopOpacity: "0" }))),
|
|
71
|
-
React.createElement(VictoryArea, { name: "victory-area", data: sortData, interpolation: "monotoneX", sortKey: "date", x: "date", y: valueKey, style: { data: { fill: `url(#chartGradient)` } }, standalone: false }),
|
|
72
|
-
React.createElement(VictoryLine, { data: sortData, interpolation: "monotoneX", x: "date", y: valueKey, style: { data: { stroke: color } } }))));
|
|
73
|
-
};
|
|
74
|
-
export default Chart;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|