@ssa-ui-kit/core 1.0.14 → 1.0.16

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ssa-ui-kit/core",
3
- "version": "1.0.14",
3
+ "version": "1.0.16",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "private": false,
@@ -15,9 +15,7 @@ const Indicator = ({
15
15
  const indicatorRef = useRef<HTMLDivElement>(null);
16
16
  const childrenRef = useRef<HTMLDivElement | null>(null);
17
17
  const [width, setWidth] = useState<number>(0);
18
- const [childrenData, setChildrenData] = useState<ChildrenDataProps | null>(
19
- {} || null,
20
- );
18
+ const [childrenData, setChildrenData] = useState<ChildrenDataProps>({});
21
19
  const { width: windowWidth } = useWindowSize();
22
20
  const theme = useTheme();
23
21
 
@@ -32,8 +30,17 @@ const Indicator = ({
32
30
  width: childrenRef.current.offsetWidth,
33
31
  right: childrenRef.current.offsetWidth + childrenRef.current.offsetLeft,
34
32
  };
35
- setWidth(refValue);
36
- setChildrenData(refData);
33
+ if (refValue !== width) {
34
+ setWidth(refValue);
35
+ }
36
+ if (
37
+ childrenData.top !== refData.top ||
38
+ childrenData.left !== refData.left ||
39
+ childrenData.width !== refData.width ||
40
+ childrenData.right !== refData.right
41
+ ) {
42
+ setChildrenData(refData);
43
+ }
37
44
  }
38
45
  }, [width, childrenRef.current, windowWidth]);
39
46
 
@@ -44,7 +51,7 @@ const Indicator = ({
44
51
  data-testid={`indicator-${position}`}
45
52
  ref={indicatorRef}
46
53
  css={
47
- childrenData && [
54
+ Object.keys(childrenData).length > 0 && [
48
55
  css`
49
56
  top: ${childrenData.top + 2}px;
50
57
  left: ${isRight ? '-6px' : '1px'};
@@ -25,7 +25,7 @@ export const ChartTooltip = ({
25
25
  pointData.legendValueRoundingDigits,
26
26
  )
27
27
  : getRoundedNumber(
28
- pointData.value,
28
+ pointData.mainValue,
29
29
  pointData.legendValueRoundingDigits,
30
30
  ),
31
31
  label: pointData.legendLabel || pointData.label,
@@ -31,6 +31,7 @@ export const useData = ({
31
31
  label: item.label,
32
32
  percentage: mainPercentage,
33
33
  mainId: Number(item.id),
34
+ mainValue: item.value,
34
35
  legendLabel: item.legendLabel,
35
36
  legendValue: item.legendValue,
36
37
  legendValueRoundingDigits: propOr<SegmentedDataItem, number>(
@@ -42,28 +43,31 @@ export const useData = ({
42
43
  };
43
44
  balanceDataForTheLegend.push(newMainItem);
44
45
  if (item.parts?.length) {
45
- item.parts?.forEach((part, partIndex) => {
46
- const partPercentage = (part.value * 100) / calculatedTotalAmount;
47
- balanceDataForTheGraph.push({
48
- value: item.value,
49
- label: item.label,
50
- percentage: mainPercentage,
51
- mainId: Number(item.id),
52
- legendLabel: item.legendLabel,
53
- legendValue: item.legendValue,
54
- legendValueRoundingDigits: propOr<SegmentedDataItem, number>(
55
- legendValueRoundingDigits,
56
- 'legendValueRoundingDigits',
57
- )(item),
58
- color: pieChartColorsLocal?.[itemIndex]?.[partIndex],
59
- id: `${itemIndex}${partIndex}`,
60
- partIndex,
61
- partLabel: part.label,
62
- partPercentage: Number(partPercentage),
63
- partValue: part.value,
64
- partLegendValue: part.legendValue,
46
+ item.parts
47
+ ?.filter((part) => !!part.value)
48
+ .forEach((part, partIndex) => {
49
+ const partPercentage = (part.value * 100) / calculatedTotalAmount;
50
+ balanceDataForTheGraph.push({
51
+ value: part.value,
52
+ label: item.label,
53
+ percentage: mainPercentage,
54
+ mainId: Number(item.id),
55
+ mainValue: item.value,
56
+ legendLabel: item.legendLabel,
57
+ legendValue: item.legendValue,
58
+ legendValueRoundingDigits: propOr<SegmentedDataItem, number>(
59
+ legendValueRoundingDigits,
60
+ 'legendValueRoundingDigits',
61
+ )(item),
62
+ color: pieChartColorsLocal?.[itemIndex]?.[partIndex],
63
+ id: `${itemIndex}${partIndex}`,
64
+ partIndex,
65
+ partLabel: part.label,
66
+ partPercentage: Number(partPercentage),
67
+ partValue: part.value,
68
+ partLegendValue: part.legendValue,
69
+ });
65
70
  });
66
- });
67
71
  } else {
68
72
  balanceDataForTheGraph.push(newMainItem);
69
73
  }
@@ -100,6 +100,89 @@ export const balanceData: SegmentedDataSet = [
100
100
  },
101
101
  ];
102
102
 
103
+ export const balanceDataNullable: SegmentedDataSet = [
104
+ {
105
+ id: 1,
106
+ value: 5843.37,
107
+ legendValue: 5843.37 / RATE.BTC,
108
+ legendLabel: 'BTC',
109
+ label: 'BTC',
110
+ legendValueRoundingDigits: 6,
111
+ parts: [
112
+ {
113
+ label: 'Option 1',
114
+ value: 5843.37,
115
+ legendValue: 5843.37 / RATE.BTC,
116
+ },
117
+ {
118
+ label: 'Option 2',
119
+ value: 0,
120
+ legendValue: 0,
121
+ },
122
+ ],
123
+ },
124
+ {
125
+ id: 2,
126
+ value: 5249.25,
127
+ legendValue: 5249.25 / RATE.ETH,
128
+ legendLabel: 'ETH',
129
+ label: 'ETH',
130
+ legendValueRoundingDigits: 2,
131
+ parts: [
132
+ {
133
+ label: 'Option 1',
134
+ value: 2800,
135
+ legendValue: 2800 / RATE.ETH,
136
+ },
137
+ {
138
+ label: 'Option 2',
139
+ value: 2449.25,
140
+ legendValue: 2449.25 / RATE.ETH,
141
+ },
142
+ ],
143
+ },
144
+ {
145
+ id: 3,
146
+ value: 3825.55,
147
+ legendValue: 3825.55 / RATE.FDUSD,
148
+ legendLabel: 'FDUSD',
149
+ label: 'FDUSD',
150
+ legendValueRoundingDigits: 2,
151
+ parts: [
152
+ {
153
+ label: 'Option 1',
154
+ value: 3825.55,
155
+ legendValue: 3825.55 / RATE.FDUSD,
156
+ },
157
+ {
158
+ label: 'Option 2',
159
+ value: 0,
160
+ legendValue: 0,
161
+ },
162
+ ],
163
+ },
164
+ {
165
+ id: 4,
166
+ value: 2818.83,
167
+ legendValue: 2818.83 / RATE.USDT,
168
+ label: 'Other',
169
+ legendLabel: 'USDT',
170
+ legendValueRoundingDigits: 0,
171
+ parts: [
172
+ {
173
+ label: 'Option 1',
174
+ value: 2818.83,
175
+ legendValue: 2818.83 / RATE.USDT,
176
+ },
177
+ {
178
+ label: 'Option 2',
179
+ value: 0,
180
+ legendValue: 0,
181
+ },
182
+ ],
183
+ },
184
+ ];
185
+
103
186
  export const balanceTotalAmount = balanceData
104
187
  .map((item) => Number(item.value))
105
188
  .reduce((acc, currentValue) => acc + currentValue, 0);