jfs-components 0.0.72 → 0.0.73
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/CHANGELOG.md +11 -0
- package/lib/commonjs/components/AccordionCheckbox/AccordionCheckbox.js +239 -0
- package/lib/commonjs/components/BrandChip/BrandChip.js +149 -0
- package/lib/commonjs/components/CardBankAccount/CardBankAccount.js +213 -0
- package/lib/commonjs/components/CardInsight/CardInsight.js +166 -0
- package/lib/commonjs/components/CheckboxGroup/CheckboxGroup.js +67 -0
- package/lib/commonjs/components/CheckboxItem/CheckboxItem.js +125 -0
- package/lib/commonjs/components/CircularProgressBar/CircularProgressBar.js +56 -9
- package/lib/commonjs/components/CoverageBarComparison/CoverageBarComparison.js +272 -0
- package/lib/commonjs/components/CoverageRing/CoverageRing.js +141 -0
- package/lib/commonjs/components/DonutChart/DonutChart.js +309 -0
- package/lib/commonjs/components/DonutChartSummary/DonutChartSummary.js +155 -0
- package/lib/commonjs/components/LinearMeter/LinearMeter.js +9 -28
- package/lib/commonjs/components/LinearProgress/LinearProgress.js +68 -0
- package/lib/commonjs/components/MetricLegendItem/MetricLegendItem.js +95 -0
- package/lib/commonjs/components/MonthlyStatusGrid/MonthlyStatusGrid.js +286 -0
- package/lib/commonjs/components/OTP/OTP.js +381 -37
- package/lib/commonjs/components/ProductOverview/ProductOverview.js +147 -0
- package/lib/commonjs/components/RangeTrack/RangeTrack.js +269 -0
- package/lib/commonjs/components/SavingsGoalSummary/SavingsGoalSummary.js +181 -0
- package/lib/commonjs/components/SegmentedTrack/SegmentedTrack.js +171 -0
- package/lib/commonjs/components/StatGroup/StatGroup.js +128 -0
- package/lib/commonjs/components/StatItem/StatItem.js +65 -35
- package/lib/commonjs/components/StrengthIndicator/StrengthIndicator.js +157 -0
- package/lib/commonjs/components/SummaryTile/SummaryTile.js +150 -0
- package/lib/commonjs/components/index.js +171 -1
- package/lib/commonjs/design-tokens/Coin Variables-variables-full.json +1 -1
- package/lib/commonjs/icons/registry.js +1 -1
- package/lib/commonjs/utils/index.js +7 -0
- package/lib/commonjs/utils/number-utils.js +57 -0
- package/lib/module/components/AccordionCheckbox/AccordionCheckbox.js +233 -0
- package/lib/module/components/BrandChip/BrandChip.js +143 -0
- package/lib/module/components/CardBankAccount/CardBankAccount.js +208 -0
- package/lib/module/components/CardInsight/CardInsight.js +161 -0
- package/lib/module/components/CheckboxGroup/CheckboxGroup.js +62 -0
- package/lib/module/components/CheckboxItem/CheckboxItem.js +119 -0
- package/lib/module/components/CircularProgressBar/CircularProgressBar.js +56 -9
- package/lib/module/components/CoverageBarComparison/CoverageBarComparison.js +266 -0
- package/lib/module/components/CoverageRing/CoverageRing.js +136 -0
- package/lib/module/components/DonutChart/DonutChart.js +303 -0
- package/lib/module/components/DonutChartSummary/DonutChartSummary.js +150 -0
- package/lib/module/components/LinearMeter/LinearMeter.js +9 -28
- package/lib/module/components/LinearProgress/LinearProgress.js +63 -0
- package/lib/module/components/MetricLegendItem/MetricLegendItem.js +90 -0
- package/lib/module/components/MonthlyStatusGrid/MonthlyStatusGrid.js +281 -0
- package/lib/module/components/OTP/OTP.js +381 -38
- package/lib/module/components/ProductOverview/ProductOverview.js +142 -0
- package/lib/module/components/RangeTrack/RangeTrack.js +263 -0
- package/lib/module/components/SavingsGoalSummary/SavingsGoalSummary.js +175 -0
- package/lib/module/components/SegmentedTrack/SegmentedTrack.js +166 -0
- package/lib/module/components/StatGroup/StatGroup.js +123 -0
- package/lib/module/components/StatItem/StatItem.js +66 -36
- package/lib/module/components/StrengthIndicator/StrengthIndicator.js +152 -0
- package/lib/module/components/SummaryTile/SummaryTile.js +145 -0
- package/lib/module/components/index.js +21 -1
- package/lib/module/design-tokens/Coin Variables-variables-full.json +1 -1
- package/lib/module/icons/registry.js +1 -1
- package/lib/module/utils/index.js +2 -1
- package/lib/module/utils/number-utils.js +53 -0
- package/lib/typescript/src/components/AccordionCheckbox/AccordionCheckbox.d.ts +71 -0
- package/lib/typescript/src/components/BrandChip/BrandChip.d.ts +43 -0
- package/lib/typescript/src/components/CardBankAccount/CardBankAccount.d.ts +79 -0
- package/lib/typescript/src/components/CardInsight/CardInsight.d.ts +48 -0
- package/lib/typescript/src/components/CheckboxGroup/CheckboxGroup.d.ts +41 -0
- package/lib/typescript/src/components/CheckboxItem/CheckboxItem.d.ts +56 -0
- package/lib/typescript/src/components/CircularProgressBar/CircularProgressBar.d.ts +11 -1
- package/lib/typescript/src/components/CoverageBarComparison/CoverageBarComparison.d.ts +105 -0
- package/lib/typescript/src/components/CoverageRing/CoverageRing.d.ts +90 -0
- package/lib/typescript/src/components/DonutChart/DonutChart.d.ts +117 -0
- package/lib/typescript/src/components/DonutChartSummary/DonutChartSummary.d.ts +103 -0
- package/lib/typescript/src/components/LinearProgress/LinearProgress.d.ts +17 -0
- package/lib/typescript/src/components/MetricLegendItem/MetricLegendItem.d.ts +37 -0
- package/lib/typescript/src/components/MonthlyStatusGrid/MonthlyStatusGrid.d.ts +119 -0
- package/lib/typescript/src/components/OTP/OTP.d.ts +88 -2
- package/lib/typescript/src/components/ProductOverview/ProductOverview.d.ts +39 -0
- package/lib/typescript/src/components/RangeTrack/RangeTrack.d.ts +173 -0
- package/lib/typescript/src/components/SavingsGoalSummary/SavingsGoalSummary.d.ts +95 -0
- package/lib/typescript/src/components/SegmentedTrack/SegmentedTrack.d.ts +108 -0
- package/lib/typescript/src/components/StatGroup/StatGroup.d.ts +45 -0
- package/lib/typescript/src/components/StatItem/StatItem.d.ts +24 -7
- package/lib/typescript/src/components/StrengthIndicator/StrengthIndicator.d.ts +58 -0
- package/lib/typescript/src/components/SummaryTile/SummaryTile.d.ts +60 -0
- package/lib/typescript/src/components/index.d.ts +22 -2
- package/lib/typescript/src/icons/registry.d.ts +1 -1
- package/lib/typescript/src/utils/index.d.ts +1 -0
- package/lib/typescript/src/utils/number-utils.d.ts +29 -0
- package/package.json +1 -1
- package/src/components/AccordionCheckbox/AccordionCheckbox.tsx +323 -0
- package/src/components/BrandChip/BrandChip.tsx +235 -0
- package/src/components/CardBankAccount/CardBankAccount.tsx +295 -0
- package/src/components/CardInsight/CardInsight.tsx +239 -0
- package/src/components/CheckboxGroup/CheckboxGroup.tsx +86 -0
- package/src/components/CheckboxItem/CheckboxItem.tsx +174 -0
- package/src/components/CircularProgressBar/CircularProgressBar.tsx +74 -9
- package/src/components/CoverageBarComparison/CoverageBarComparison.tsx +378 -0
- package/src/components/CoverageRing/CoverageRing.tsx +225 -0
- package/src/components/DonutChart/DonutChart.tsx +503 -0
- package/src/components/DonutChartSummary/DonutChartSummary.tsx +256 -0
- package/src/components/LinearMeter/LinearMeter.tsx +9 -39
- package/src/components/LinearProgress/LinearProgress.tsx +92 -0
- package/src/components/MetricLegendItem/MetricLegendItem.tsx +167 -0
- package/src/components/MonthlyStatusGrid/MonthlyStatusGrid.tsx +438 -0
- package/src/components/OTP/OTP.tsx +476 -29
- package/src/components/ProductOverview/ProductOverview.tsx +236 -0
- package/src/components/RangeTrack/RangeTrack.tsx +394 -0
- package/src/components/SavingsGoalSummary/SavingsGoalSummary.tsx +269 -0
- package/src/components/SegmentedTrack/SegmentedTrack.tsx +268 -0
- package/src/components/StatGroup/StatGroup.tsx +169 -0
- package/src/components/StatItem/StatItem.tsx +117 -40
- package/src/components/StrengthIndicator/StrengthIndicator.tsx +205 -0
- package/src/components/SummaryTile/SummaryTile.tsx +251 -0
- package/src/components/index.ts +32 -2
- package/src/design-tokens/Coin Variables-variables-full.json +1 -1
- package/src/icons/registry.ts +1 -1
- package/src/utils/index.ts +1 -0
- package/src/utils/number-utils.ts +60 -0
|
@@ -0,0 +1,266 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
import React from 'react';
|
|
4
|
+
import { View, Text } from 'react-native';
|
|
5
|
+
import Svg, { Rect } from 'react-native-svg';
|
|
6
|
+
import { getVariableByName } from '../../design-tokens/figma-variables-resolver';
|
|
7
|
+
import { useTokens } from '../../design-tokens/JFSThemeProvider';
|
|
8
|
+
import { EMPTY_MODES } from '../../utils/react-utils';
|
|
9
|
+
import MetricLegendItem from '../MetricLegendItem/MetricLegendItem';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* One entry in the {@link CoverageBarComparisonProps.bars} array.
|
|
13
|
+
*
|
|
14
|
+
* Each entry carries **both** the bar's data and its legend label, so the
|
|
15
|
+
* number of bars is intrinsically equal to the number of legend items.
|
|
16
|
+
* There is no separate `legends` prop — that is by design.
|
|
17
|
+
*/
|
|
18
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
19
|
+
/**
|
|
20
|
+
* Default per-index `Emphasis / DataViz` modes applied when the caller does
|
|
21
|
+
* not provide its own override. Ascends Low → Medium → High so the natural
|
|
22
|
+
* "Current vs Recommended" two-bar story matches the Figma reference (left
|
|
23
|
+
* = lighter / Low, right = darker / High). Cycles for >3 bars.
|
|
24
|
+
*/
|
|
25
|
+
const DEFAULT_EMPHASIS_CYCLE = ['Low', 'Medium', 'High'];
|
|
26
|
+
function defaultEmphasisFor(index, total) {
|
|
27
|
+
if (total <= 1) {
|
|
28
|
+
return 'High';
|
|
29
|
+
}
|
|
30
|
+
if (total === 2) {
|
|
31
|
+
return index === 0 ? 'Low' : 'High';
|
|
32
|
+
}
|
|
33
|
+
return DEFAULT_EMPHASIS_CYCLE[index % DEFAULT_EMPHASIS_CYCLE.length];
|
|
34
|
+
}
|
|
35
|
+
const DEFAULT_BARS = [{
|
|
36
|
+
value: 40,
|
|
37
|
+
label: '₹1L (40%)',
|
|
38
|
+
legend: 'Current coverage'
|
|
39
|
+
}, {
|
|
40
|
+
value: 100,
|
|
41
|
+
label: '₹2.5L (100%)',
|
|
42
|
+
legend: 'Recommended coverage'
|
|
43
|
+
}];
|
|
44
|
+
const toNumber = (value, fallback) => {
|
|
45
|
+
if (typeof value === 'number') {
|
|
46
|
+
return Number.isFinite(value) ? value : fallback;
|
|
47
|
+
}
|
|
48
|
+
if (typeof value === 'string') {
|
|
49
|
+
const parsed = Number(value);
|
|
50
|
+
return Number.isFinite(parsed) ? parsed : fallback;
|
|
51
|
+
}
|
|
52
|
+
return fallback;
|
|
53
|
+
};
|
|
54
|
+
const toFontWeight = (value, fallback) => {
|
|
55
|
+
if (typeof value === 'number') {
|
|
56
|
+
return String(value);
|
|
57
|
+
}
|
|
58
|
+
if (typeof value === 'string') {
|
|
59
|
+
return value;
|
|
60
|
+
}
|
|
61
|
+
return fallback;
|
|
62
|
+
};
|
|
63
|
+
/**
|
|
64
|
+
* Bar shape rendered with `react-native-svg`. The wrapper measures its width
|
|
65
|
+
* via `onLayout` so the SVG can use concrete dimensions (RN SVG does not
|
|
66
|
+
* resolve percentage shape attributes when the parent SVG itself has a
|
|
67
|
+
* percentage `width`).
|
|
68
|
+
*/
|
|
69
|
+
function BarShape({
|
|
70
|
+
height,
|
|
71
|
+
color,
|
|
72
|
+
radius
|
|
73
|
+
}) {
|
|
74
|
+
const [width, setWidth] = React.useState(0);
|
|
75
|
+
const handleLayout = React.useCallback(event => {
|
|
76
|
+
const next = event.nativeEvent.layout.width;
|
|
77
|
+
setWidth(prev => prev === next ? prev : next);
|
|
78
|
+
}, []);
|
|
79
|
+
if (height <= 0) {
|
|
80
|
+
return /*#__PURE__*/_jsx(View, {
|
|
81
|
+
onLayout: handleLayout,
|
|
82
|
+
style: {
|
|
83
|
+
width: '100%',
|
|
84
|
+
height: 0
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
const safeRadius = Math.max(0, Math.min(radius, width / 2, height / 2));
|
|
89
|
+
return /*#__PURE__*/_jsx(View, {
|
|
90
|
+
onLayout: handleLayout,
|
|
91
|
+
style: {
|
|
92
|
+
width: '100%',
|
|
93
|
+
height,
|
|
94
|
+
minWidth: 1
|
|
95
|
+
},
|
|
96
|
+
children: width > 0 ? /*#__PURE__*/_jsx(Svg, {
|
|
97
|
+
width: width,
|
|
98
|
+
height: height,
|
|
99
|
+
children: /*#__PURE__*/_jsx(Rect, {
|
|
100
|
+
x: 0,
|
|
101
|
+
y: 0,
|
|
102
|
+
width: width,
|
|
103
|
+
height: height,
|
|
104
|
+
rx: safeRadius,
|
|
105
|
+
ry: safeRadius,
|
|
106
|
+
fill: color
|
|
107
|
+
})
|
|
108
|
+
}) : null
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* `CoverageBarComparison` renders a small vertical-bar chart that compares
|
|
114
|
+
* 2+ values side by side, with a legend row directly below where each item
|
|
115
|
+
* is intrinsically tied to one bar.
|
|
116
|
+
*
|
|
117
|
+
* Cohesiveness guarantees:
|
|
118
|
+
* - The legend row is **derived** from the same `bars` prop, so the count
|
|
119
|
+
* and order can never desynchronise from the chart.
|
|
120
|
+
* - Each bar's color, its tokenized `Emphasis / DataViz` mode and its
|
|
121
|
+
* legend indicator dot are the same value.
|
|
122
|
+
*
|
|
123
|
+
* Bars are drawn with `react-native-svg` (`<Rect>` with `rx`), and the
|
|
124
|
+
* fonts/spacing/colors are sourced from the Figma `valueBar/*` and
|
|
125
|
+
* `coverageBarComparison/*` tokens.
|
|
126
|
+
*
|
|
127
|
+
* @component
|
|
128
|
+
*/
|
|
129
|
+
function CoverageBarComparison({
|
|
130
|
+
bars = DEFAULT_BARS,
|
|
131
|
+
max,
|
|
132
|
+
height = 100,
|
|
133
|
+
legendGap = 12,
|
|
134
|
+
modes: propModes = EMPTY_MODES,
|
|
135
|
+
style,
|
|
136
|
+
chartStyle,
|
|
137
|
+
legendStyle,
|
|
138
|
+
labelStyle,
|
|
139
|
+
accessibilityLabel
|
|
140
|
+
}) {
|
|
141
|
+
const {
|
|
142
|
+
modes: globalModes
|
|
143
|
+
} = useTokens();
|
|
144
|
+
const modes = React.useMemo(() => ({
|
|
145
|
+
...globalModes,
|
|
146
|
+
...propModes
|
|
147
|
+
}), [globalModes, propModes]);
|
|
148
|
+
const wrapGap = toNumber(getVariableByName('coverageBarComparison/wrap/gap', modes), 6);
|
|
149
|
+
const valueBarGap = toNumber(getVariableByName('valueBar/gap', modes), 4);
|
|
150
|
+
const barRadius = toNumber(getVariableByName('valueBar/bar/radius', modes), 10);
|
|
151
|
+
const fontFamily = getVariableByName('valueBar/fontFamily', modes) ?? 'JioType Var';
|
|
152
|
+
const fontSize = toNumber(getVariableByName('valueBar/fontSize', modes), 12);
|
|
153
|
+
const lineHeight = toNumber(getVariableByName('valueBar/lineHeight', modes), 16);
|
|
154
|
+
const fontWeight = toFontWeight(getVariableByName('valueBar/fontWeight', modes), '700');
|
|
155
|
+
const foreground = getVariableByName('valueBar/foreground', modes) ?? '#000000';
|
|
156
|
+
const labelHeight = lineHeight;
|
|
157
|
+
const barAreaHeight = Math.max(0, height - labelHeight - valueBarGap);
|
|
158
|
+
const total = bars.length;
|
|
159
|
+
const computedMax = max ?? bars.reduce((acc, bar) => Math.max(acc, bar.value), 0);
|
|
160
|
+
const safeMax = computedMax > 0 ? computedMax : 1;
|
|
161
|
+
const resolvedBars = React.useMemo(() => bars.map((bar, index) => {
|
|
162
|
+
const barModes = {
|
|
163
|
+
...modes,
|
|
164
|
+
'Emphasis / DataViz': defaultEmphasisFor(index, total),
|
|
165
|
+
...(bar.modes || {})
|
|
166
|
+
};
|
|
167
|
+
const ratio = Math.max(0, Math.min(1, bar.value / safeMax));
|
|
168
|
+
const tokenColor = getVariableByName('valueBar/bar/background', barModes) ?? '#c9b7ff';
|
|
169
|
+
const bgColor = bar.color ?? tokenColor;
|
|
170
|
+
return {
|
|
171
|
+
original: bar,
|
|
172
|
+
index,
|
|
173
|
+
barModes,
|
|
174
|
+
ratio,
|
|
175
|
+
bgColor
|
|
176
|
+
};
|
|
177
|
+
}), [bars, modes, safeMax, total]);
|
|
178
|
+
const computedLabelStyle = {
|
|
179
|
+
color: foreground,
|
|
180
|
+
fontFamily,
|
|
181
|
+
fontSize,
|
|
182
|
+
lineHeight,
|
|
183
|
+
fontWeight,
|
|
184
|
+
textAlign: 'center'
|
|
185
|
+
};
|
|
186
|
+
const defaultAccessibilityLabel = accessibilityLabel ?? `Comparison of ${total} bar${total === 1 ? '' : 's'}: ` + bars.map((bar, i) => {
|
|
187
|
+
const legend = typeof bar.legend === 'string' ? bar.legend : `bar ${i + 1}`;
|
|
188
|
+
return `${legend} ${bar.value}`;
|
|
189
|
+
}).join(', ');
|
|
190
|
+
return /*#__PURE__*/_jsxs(View, {
|
|
191
|
+
accessibilityLabel: defaultAccessibilityLabel,
|
|
192
|
+
style: [{
|
|
193
|
+
width: '100%'
|
|
194
|
+
}, style],
|
|
195
|
+
children: [/*#__PURE__*/_jsx(View, {
|
|
196
|
+
accessibilityRole: "image",
|
|
197
|
+
style: [{
|
|
198
|
+
flexDirection: 'row',
|
|
199
|
+
alignItems: 'flex-end',
|
|
200
|
+
height,
|
|
201
|
+
gap: wrapGap,
|
|
202
|
+
width: '100%'
|
|
203
|
+
}, chartStyle],
|
|
204
|
+
children: resolvedBars.map(({
|
|
205
|
+
original,
|
|
206
|
+
index,
|
|
207
|
+
ratio,
|
|
208
|
+
bgColor
|
|
209
|
+
}) => {
|
|
210
|
+
const barHeightPx = Math.max(0, barAreaHeight * ratio);
|
|
211
|
+
const valueBarTotalHeight = labelHeight + valueBarGap + barHeightPx;
|
|
212
|
+
const hasLabel = original.label !== undefined && original.label !== null && original.label !== false;
|
|
213
|
+
return /*#__PURE__*/_jsxs(View, {
|
|
214
|
+
accessibilityLabel: original.accessibilityLabel,
|
|
215
|
+
style: {
|
|
216
|
+
flex: 1,
|
|
217
|
+
flexDirection: 'column',
|
|
218
|
+
alignItems: 'stretch',
|
|
219
|
+
justifyContent: 'flex-end',
|
|
220
|
+
height: valueBarTotalHeight,
|
|
221
|
+
gap: valueBarGap,
|
|
222
|
+
minWidth: 1
|
|
223
|
+
},
|
|
224
|
+
children: [hasLabel ? /*#__PURE__*/_jsx(Text, {
|
|
225
|
+
numberOfLines: 1,
|
|
226
|
+
style: [computedLabelStyle, labelStyle],
|
|
227
|
+
children: original.label
|
|
228
|
+
}) : null, /*#__PURE__*/_jsx(BarShape, {
|
|
229
|
+
height: barHeightPx,
|
|
230
|
+
color: bgColor,
|
|
231
|
+
radius: barRadius
|
|
232
|
+
})]
|
|
233
|
+
}, original.key ?? `bar-${index}`);
|
|
234
|
+
})
|
|
235
|
+
}), /*#__PURE__*/_jsx(View, {
|
|
236
|
+
style: [{
|
|
237
|
+
marginTop: legendGap,
|
|
238
|
+
flexDirection: 'row',
|
|
239
|
+
alignItems: 'center',
|
|
240
|
+
justifyContent: 'space-between',
|
|
241
|
+
width: '100%'
|
|
242
|
+
}, legendStyle],
|
|
243
|
+
children: resolvedBars.map(({
|
|
244
|
+
original,
|
|
245
|
+
index,
|
|
246
|
+
barModes,
|
|
247
|
+
bgColor
|
|
248
|
+
}) => {
|
|
249
|
+
const indicatorOverride = original.color ? bgColor : undefined;
|
|
250
|
+
return /*#__PURE__*/_jsx(MetricLegendItem, {
|
|
251
|
+
label: original.legend,
|
|
252
|
+
value: original.legendValue,
|
|
253
|
+
modes: barModes,
|
|
254
|
+
...(indicatorOverride !== undefined ? {
|
|
255
|
+
indicatorColor: indicatorOverride
|
|
256
|
+
} : {}),
|
|
257
|
+
style: {
|
|
258
|
+
flex: 1,
|
|
259
|
+
minWidth: 0
|
|
260
|
+
}
|
|
261
|
+
}, original.key ?? `legend-${index}`);
|
|
262
|
+
})
|
|
263
|
+
})]
|
|
264
|
+
});
|
|
265
|
+
}
|
|
266
|
+
export default CoverageBarComparison;
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
import React from 'react';
|
|
4
|
+
import { View } from 'react-native';
|
|
5
|
+
import { getVariableByName } from '../../design-tokens/figma-variables-resolver';
|
|
6
|
+
import { useTokens } from '../../design-tokens/JFSThemeProvider';
|
|
7
|
+
import { EMPTY_MODES, cloneChildrenWithModes } from '../../utils/react-utils';
|
|
8
|
+
import Button from '../Button/Button';
|
|
9
|
+
import CircularProgressBar from '../CircularProgressBar/CircularProgressBar';
|
|
10
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
11
|
+
const toNumber = (value, fallback) => {
|
|
12
|
+
if (typeof value === 'number') {
|
|
13
|
+
return Number.isFinite(value) ? value : fallback;
|
|
14
|
+
}
|
|
15
|
+
if (typeof value === 'string') {
|
|
16
|
+
const parsed = Number(value);
|
|
17
|
+
return Number.isFinite(parsed) ? parsed : fallback;
|
|
18
|
+
}
|
|
19
|
+
return fallback;
|
|
20
|
+
};
|
|
21
|
+
const clamp = (value, min, max) => Math.min(max, Math.max(min, value));
|
|
22
|
+
|
|
23
|
+
// The Figma "Coverage Ring" pairs a `circularProgressBar Size: M` ring with a
|
|
24
|
+
// `Button / Size: S` Secondary button. Locking these in as component defaults
|
|
25
|
+
// keeps the visual identical to the Figma reference when the caller supplies
|
|
26
|
+
// only their own brand/theme modes — caller modes are still merged on top so
|
|
27
|
+
// any of these can be overridden per-instance.
|
|
28
|
+
const COMPONENT_DEFAULT_MODES = Object.freeze({
|
|
29
|
+
'circularProgressBar Size': 'M',
|
|
30
|
+
'Button / Size': 'S'
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
// Match the Figma source: regardless of the overall AppearanceBrand/Emphasis
|
|
34
|
+
// the caller picks (used to colour the ring), the Coverage Ring CTA renders
|
|
35
|
+
// with the Secondary brand at Medium emphasis — which resolves to the
|
|
36
|
+
// pale-lavender background (`#dbcfff`) + deep-purple foreground (`#5d00b5`)
|
|
37
|
+
// shown in Figma. Mirrors the pattern used by `CardFinancialCondition.tsx`.
|
|
38
|
+
const BUTTON_FORCED_BRAND = Object.freeze({
|
|
39
|
+
AppearanceBrand: 'Secondary',
|
|
40
|
+
Emphasis: 'Medium'
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* `CoverageRing` renders a single-purpose insight: how many items out of a
|
|
45
|
+
* total have been covered (e.g. "4 of 7 benefits availed"), paired with a
|
|
46
|
+
* call-to-action button below the ring.
|
|
47
|
+
*
|
|
48
|
+
* It composes the existing {@link CircularProgressBar} (in its `M` size so
|
|
49
|
+
* there is room for a caption + value inside the ring) and {@link Button}
|
|
50
|
+
* (in its `S`, Secondary brand variant) — both driven by the same design
|
|
51
|
+
* tokens used by the rest of the design system.
|
|
52
|
+
*
|
|
53
|
+
* The ring fill is derived from `value / total`, so the percentage, the
|
|
54
|
+
* displayed `"{value} of {total}"` label and the support caption stay in
|
|
55
|
+
* sync automatically. There is no separate `progress` prop.
|
|
56
|
+
*
|
|
57
|
+
* @component
|
|
58
|
+
*/
|
|
59
|
+
function CoverageRing({
|
|
60
|
+
value = 4,
|
|
61
|
+
total = 7,
|
|
62
|
+
supportText = 'Benefits availed',
|
|
63
|
+
valueLabel,
|
|
64
|
+
actionLabel = 'Learn more',
|
|
65
|
+
onActionPress,
|
|
66
|
+
actionProps,
|
|
67
|
+
action,
|
|
68
|
+
children,
|
|
69
|
+
modes: propModes = EMPTY_MODES,
|
|
70
|
+
style,
|
|
71
|
+
supportTextStyle,
|
|
72
|
+
valueStyle,
|
|
73
|
+
accessibilityLabel,
|
|
74
|
+
...rest
|
|
75
|
+
}) {
|
|
76
|
+
const {
|
|
77
|
+
modes: globalModes
|
|
78
|
+
} = useTokens();
|
|
79
|
+
|
|
80
|
+
// Merge order matches the rest of the design system (see `Gauge.tsx`):
|
|
81
|
+
// 1. Component-level defaults — the lowest-priority safety net.
|
|
82
|
+
// 2. Global modes from `JFSThemeProvider` — app-wide theme.
|
|
83
|
+
// 3. Caller-supplied `propModes` — highest priority, overrides everything.
|
|
84
|
+
const modes = React.useMemo(() => ({
|
|
85
|
+
...COMPONENT_DEFAULT_MODES,
|
|
86
|
+
...globalModes,
|
|
87
|
+
...propModes
|
|
88
|
+
}), [propModes, globalModes]);
|
|
89
|
+
|
|
90
|
+
// Force the Secondary brand on the button only; the ring stays on whatever
|
|
91
|
+
// brand the caller selected. Done via a forcedModes layer so callers can't
|
|
92
|
+
// accidentally bring back a Primary-coloured CTA through their own modes.
|
|
93
|
+
const buttonModes = React.useMemo(() => ({
|
|
94
|
+
...modes,
|
|
95
|
+
...BUTTON_FORCED_BRAND
|
|
96
|
+
}), [modes]);
|
|
97
|
+
const safeTotal = total > 0 ? total : 0;
|
|
98
|
+
const clampedValue = clamp(value, 0, safeTotal);
|
|
99
|
+
const progressPercent = safeTotal > 0 ? clampedValue / safeTotal * 100 : 0;
|
|
100
|
+
const computedValueLabel = valueLabel ?? `${clampedValue} of ${safeTotal}`;
|
|
101
|
+
const gap = toNumber(getVariableByName('coverageRing/gap', modes), 16);
|
|
102
|
+
const containerStyle = {
|
|
103
|
+
alignItems: 'center',
|
|
104
|
+
gap
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
// Custom action slot resolution order: explicit `action` prop wins over
|
|
108
|
+
// `children`. We pass `modes` down via cloneChildrenWithModes so any
|
|
109
|
+
// token-driven child (e.g. a custom `<Button>`) inherits the parent theme.
|
|
110
|
+
const customAction = action ?? children;
|
|
111
|
+
const hasCustomAction = customAction !== undefined && customAction !== null;
|
|
112
|
+
const defaultAccessibilityLabel = accessibilityLabel ?? `${supportText}, ${computedValueLabel}`;
|
|
113
|
+
return /*#__PURE__*/_jsxs(View, {
|
|
114
|
+
accessibilityLabel: defaultAccessibilityLabel,
|
|
115
|
+
style: [containerStyle, style],
|
|
116
|
+
...rest,
|
|
117
|
+
children: [/*#__PURE__*/_jsx(CircularProgressBar, {
|
|
118
|
+
state: "Active",
|
|
119
|
+
value: progressPercent,
|
|
120
|
+
valueLabel: computedValueLabel,
|
|
121
|
+
supportText: supportText,
|
|
122
|
+
supportTextStyle: supportTextStyle,
|
|
123
|
+
valueStyle: valueStyle,
|
|
124
|
+
modes: modes,
|
|
125
|
+
accessibilityLabel: `${supportText}, ${computedValueLabel}`
|
|
126
|
+
}), hasCustomAction ? cloneChildrenWithModes(customAction, buttonModes) : /*#__PURE__*/_jsx(Button, {
|
|
127
|
+
label: actionLabel,
|
|
128
|
+
modes: buttonModes,
|
|
129
|
+
...(onActionPress !== undefined ? {
|
|
130
|
+
onPress: onActionPress
|
|
131
|
+
} : {}),
|
|
132
|
+
...actionProps
|
|
133
|
+
})]
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
export default CoverageRing;
|
|
@@ -0,0 +1,303 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
import React from 'react';
|
|
4
|
+
import { StyleSheet, Text, View } from 'react-native';
|
|
5
|
+
import Svg, { Circle } from 'react-native-svg';
|
|
6
|
+
import { getVariableByName } from '../../design-tokens/figma-variables-resolver';
|
|
7
|
+
import { useTokens } from '../../design-tokens/JFSThemeProvider';
|
|
8
|
+
import { EMPTY_MODES, flattenChildren } from '../../utils/react-utils';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Per-segment data definition for the data-driven `segments` prop.
|
|
12
|
+
*
|
|
13
|
+
* Each segment renders one arc on the donut ring. `value` controls the
|
|
14
|
+
* arc's angular share (its weight relative to the sum of all values).
|
|
15
|
+
* Use `modes` per segment to override the default `Appearance / DataViz`
|
|
16
|
+
* mode (the parent injects per-index defaults of `Senary`, `Primary`,
|
|
17
|
+
* `Secondary`, `Tertiary`, `Quaternary`, `Quinary`, then cycles).
|
|
18
|
+
*/
|
|
19
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
20
|
+
const DEFAULT_APPEARANCE_CYCLE = ['Senary', 'Primary', 'Secondary', 'Tertiary', 'Quaternary', 'Quinary'];
|
|
21
|
+
const DEFAULT_SEGMENTS = [{
|
|
22
|
+
value: 1
|
|
23
|
+
}, {
|
|
24
|
+
value: 1
|
|
25
|
+
}, {
|
|
26
|
+
value: 1
|
|
27
|
+
}, {
|
|
28
|
+
value: 1
|
|
29
|
+
}, {
|
|
30
|
+
value: 1
|
|
31
|
+
}, {
|
|
32
|
+
value: 1
|
|
33
|
+
}];
|
|
34
|
+
const STROKE_WIDTH_RATIO = 18 / 194;
|
|
35
|
+
const toNumber = (value, fallback) => {
|
|
36
|
+
if (typeof value === 'number') {
|
|
37
|
+
return Number.isFinite(value) ? value : fallback;
|
|
38
|
+
}
|
|
39
|
+
if (typeof value === 'string') {
|
|
40
|
+
const parsed = Number(value);
|
|
41
|
+
return Number.isFinite(parsed) ? parsed : fallback;
|
|
42
|
+
}
|
|
43
|
+
return fallback;
|
|
44
|
+
};
|
|
45
|
+
const toFontWeight = (value, fallback) => {
|
|
46
|
+
if (typeof value === 'number') {
|
|
47
|
+
return String(value);
|
|
48
|
+
}
|
|
49
|
+
if (typeof value === 'string') {
|
|
50
|
+
return value;
|
|
51
|
+
}
|
|
52
|
+
return fallback;
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Compute the default `Appearance / DataViz` mode for a segment at `index`.
|
|
57
|
+
* Cycles through {@link DEFAULT_APPEARANCE_CYCLE} so any number of segments
|
|
58
|
+
* gets a sensible default (Senary, Primary, Secondary, Tertiary,
|
|
59
|
+
* Quaternary, Quinary, then repeats).
|
|
60
|
+
*/
|
|
61
|
+
function defaultAppearanceFor(index) {
|
|
62
|
+
return DEFAULT_APPEARANCE_CYCLE[index % DEFAULT_APPEARANCE_CYCLE.length];
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Resolve a single segment's stroke color through the design tokens. Honors
|
|
67
|
+
* any explicit `color` override, then falls back to `dataViz/bg` for the
|
|
68
|
+
* supplied `modes`, then to the Figma reference purple.
|
|
69
|
+
*/
|
|
70
|
+
function resolveSegmentColor(color, modes) {
|
|
71
|
+
if (color) return color;
|
|
72
|
+
return getVariableByName('dataViz/bg', modes) ?? '#5d00b5';
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Coerce a slot child into a `DonutChartSegmentData` so the rendering path
|
|
77
|
+
* is uniform. Reads `value`, `color`, `modes` and `accessibilityLabel`
|
|
78
|
+
* from the child's props and ignores anything else.
|
|
79
|
+
*/
|
|
80
|
+
function segmentDataFromChild(child, fallbackKey) {
|
|
81
|
+
const props = child.props ?? {};
|
|
82
|
+
return {
|
|
83
|
+
key: child.key ?? fallbackKey,
|
|
84
|
+
value: toNumber(props.value, 1),
|
|
85
|
+
color: typeof props.color === 'string' ? props.color : undefined,
|
|
86
|
+
modes: props.modes,
|
|
87
|
+
accessibilityLabel: props.accessibilityLabel
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Inert helper used purely to author donut segments declaratively as
|
|
92
|
+
* `DonutChart.Segment` slot children. The parent reads its props and
|
|
93
|
+
* renders the actual SVG arcs — this component never renders anything by
|
|
94
|
+
* itself.
|
|
95
|
+
*/
|
|
96
|
+
function DonutChartSegment(_) {
|
|
97
|
+
return null;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* `DonutChart` renders a circular ring split into categorical segments.
|
|
102
|
+
* It is the segmented counterpart of `CircularProgressBar`: there is **no
|
|
103
|
+
* track background** behind the segments — the colored ring *is* the
|
|
104
|
+
* data, and each slice is a sibling category rather than a directional or
|
|
105
|
+
* temporal value.
|
|
106
|
+
*
|
|
107
|
+
* The default 6-segment layout receives per-index `Appearance / DataViz`
|
|
108
|
+
* defaults (segment 1 → `Senary`, 2 → `Primary`, 3 → `Secondary`, 4 →
|
|
109
|
+
* `Tertiary`, 5 → `Quaternary`, 6 → `Quinary`) so the wheel reads as one
|
|
110
|
+
* concept split into six color-coded categories. Override `modes` per
|
|
111
|
+
* segment to remix appearances, or set `Emphasis / DataViz` on the
|
|
112
|
+
* parent `modes` to dim or brighten the whole wheel at once.
|
|
113
|
+
*
|
|
114
|
+
* @component
|
|
115
|
+
* @param {DonutChartProps} props
|
|
116
|
+
*/
|
|
117
|
+
function DonutChart({
|
|
118
|
+
segments,
|
|
119
|
+
value,
|
|
120
|
+
label,
|
|
121
|
+
children,
|
|
122
|
+
size = 194,
|
|
123
|
+
strokeWidth: strokeWidthProp,
|
|
124
|
+
gap = 0,
|
|
125
|
+
modes: propModes = EMPTY_MODES,
|
|
126
|
+
style,
|
|
127
|
+
valueStyle,
|
|
128
|
+
labelStyle,
|
|
129
|
+
accessibilityLabel
|
|
130
|
+
}) {
|
|
131
|
+
const {
|
|
132
|
+
modes: globalModes
|
|
133
|
+
} = useTokens();
|
|
134
|
+
const modes = {
|
|
135
|
+
...globalModes,
|
|
136
|
+
...propModes
|
|
137
|
+
};
|
|
138
|
+
const strokeWidth = Math.max(1, toNumber(strokeWidthProp, Math.max(1, size * STROKE_WIDTH_RATIO)));
|
|
139
|
+
const radius = Math.max(0, (size - strokeWidth) / 2);
|
|
140
|
+
const center = size / 2;
|
|
141
|
+
const circumference = 2 * Math.PI * radius;
|
|
142
|
+
const gapLength = Math.max(0, gap) / 360 * circumference;
|
|
143
|
+
const slotChildren = flattenChildren(children).filter(child => /*#__PURE__*/React.isValidElement(child));
|
|
144
|
+
const slotSegmentChildren = slotChildren.filter(child => child.type === DonutChartSegment);
|
|
145
|
+
let resolvedSegments;
|
|
146
|
+
if (slotSegmentChildren.length > 0) {
|
|
147
|
+
resolvedSegments = slotSegmentChildren.map((child, index) => segmentDataFromChild(child, `segment-${index}`));
|
|
148
|
+
} else if (segments && segments.length > 0) {
|
|
149
|
+
resolvedSegments = segments;
|
|
150
|
+
} else {
|
|
151
|
+
resolvedSegments = DEFAULT_SEGMENTS;
|
|
152
|
+
}
|
|
153
|
+
const totalValue = resolvedSegments.reduce((sum, segment) => sum + Math.max(0, toNumber(segment.value, 0)), 0);
|
|
154
|
+
const hasData = totalValue > 0 && resolvedSegments.length > 0;
|
|
155
|
+
const arcs = hasData ? buildArcs({
|
|
156
|
+
segments: resolvedSegments,
|
|
157
|
+
totalValue,
|
|
158
|
+
circumference,
|
|
159
|
+
gapLength,
|
|
160
|
+
modes
|
|
161
|
+
}) : [];
|
|
162
|
+
const customCenterChildren = slotChildren.filter(child => child.type !== DonutChartSegment);
|
|
163
|
+
const hasChildrenSlot = customCenterChildren.length > 0;
|
|
164
|
+
const showValueLabel = !hasChildrenSlot && shouldRenderText(value);
|
|
165
|
+
const showLabel = !hasChildrenSlot && shouldRenderText(label);
|
|
166
|
+
const valueColor = getVariableByName('donutChart/value/color', modes) ?? getVariableByName('value/fg', modes) ?? '#000000';
|
|
167
|
+
const valueFontFamily = getVariableByName('donutChart/value/fontFamily', modes) ?? getVariableByName('value/fontFamily', modes) ?? 'JioType Var';
|
|
168
|
+
const valueFontSize = toNumber(getVariableByName('donutChart/value/fontSize', modes) ?? getVariableByName('value/fontSize', modes), 29);
|
|
169
|
+
const valueLineHeight = toNumber(getVariableByName('donutChart/value/lineHeight', modes) ?? getVariableByName('value/lineHeight', modes), 29);
|
|
170
|
+
const valueFontWeight = toFontWeight(getVariableByName('donutChart/value/fontWeight', modes) ?? getVariableByName('value/fontWeight', modes), '900');
|
|
171
|
+
const labelColor = getVariableByName('donutChart/label/color', modes) ?? getVariableByName('label/fg', modes) ?? '#000000';
|
|
172
|
+
const labelFontFamily = getVariableByName('donutChart/label/fontFamily', modes) ?? getVariableByName('label/fontFamily', modes) ?? 'JioType Var';
|
|
173
|
+
const labelFontSize = toNumber(getVariableByName('donutChart/label/fontSize', modes) ?? getVariableByName('label/fontSize', modes), 12);
|
|
174
|
+
const labelLineHeight = toNumber(getVariableByName('donutChart/label/lineHeight', modes) ?? getVariableByName('label/lineHeight', modes), 15.6);
|
|
175
|
+
const labelFontWeight = toFontWeight(getVariableByName('donutChart/label/fontWeight', modes) ?? getVariableByName('label/fontWeight', modes), '400');
|
|
176
|
+
const textWrapGap = toNumber(getVariableByName('donutChart/textWrap/gap', modes) ?? getVariableByName('textWrap/gap', modes), 7);
|
|
177
|
+
const containerStyle = {
|
|
178
|
+
alignItems: 'center',
|
|
179
|
+
height: size,
|
|
180
|
+
justifyContent: 'center',
|
|
181
|
+
position: 'relative',
|
|
182
|
+
width: size
|
|
183
|
+
};
|
|
184
|
+
return /*#__PURE__*/_jsxs(View, {
|
|
185
|
+
accessibilityRole: "image",
|
|
186
|
+
accessibilityLabel: accessibilityLabel,
|
|
187
|
+
style: [containerStyle, style],
|
|
188
|
+
children: [/*#__PURE__*/_jsx(Svg, {
|
|
189
|
+
width: size,
|
|
190
|
+
height: size,
|
|
191
|
+
viewBox: `0 0 ${size} ${size}`,
|
|
192
|
+
children: arcs.map(arc => /*#__PURE__*/_jsx(Circle, {
|
|
193
|
+
cx: center,
|
|
194
|
+
cy: center,
|
|
195
|
+
r: radius,
|
|
196
|
+
stroke: arc.color,
|
|
197
|
+
strokeWidth: strokeWidth,
|
|
198
|
+
fill: "none",
|
|
199
|
+
strokeDasharray: arc.dashArray,
|
|
200
|
+
strokeDashoffset: arc.dashOffset,
|
|
201
|
+
strokeLinecap: "butt",
|
|
202
|
+
rotation: "-90",
|
|
203
|
+
originX: center,
|
|
204
|
+
originY: center
|
|
205
|
+
}, arc.key))
|
|
206
|
+
}), hasChildrenSlot ? /*#__PURE__*/_jsx(View, {
|
|
207
|
+
pointerEvents: "box-none",
|
|
208
|
+
style: StyleSheet.absoluteFill,
|
|
209
|
+
children: /*#__PURE__*/_jsx(View, {
|
|
210
|
+
style: styles.centerSlot,
|
|
211
|
+
children: customCenterChildren
|
|
212
|
+
})
|
|
213
|
+
}) : showValueLabel || showLabel ? /*#__PURE__*/_jsxs(View, {
|
|
214
|
+
pointerEvents: "none",
|
|
215
|
+
style: [styles.centerSlot, {
|
|
216
|
+
gap: textWrapGap
|
|
217
|
+
}],
|
|
218
|
+
children: [showValueLabel ? /*#__PURE__*/_jsx(Text, {
|
|
219
|
+
style: [{
|
|
220
|
+
color: valueColor,
|
|
221
|
+
fontFamily: valueFontFamily,
|
|
222
|
+
fontSize: valueFontSize,
|
|
223
|
+
lineHeight: valueLineHeight,
|
|
224
|
+
fontWeight: valueFontWeight,
|
|
225
|
+
textAlign: 'center'
|
|
226
|
+
}, valueStyle],
|
|
227
|
+
numberOfLines: 1,
|
|
228
|
+
children: value
|
|
229
|
+
}) : null, showLabel ? /*#__PURE__*/_jsx(Text, {
|
|
230
|
+
style: [{
|
|
231
|
+
color: labelColor,
|
|
232
|
+
fontFamily: labelFontFamily,
|
|
233
|
+
fontSize: labelFontSize,
|
|
234
|
+
lineHeight: labelLineHeight,
|
|
235
|
+
fontWeight: labelFontWeight,
|
|
236
|
+
textAlign: 'center'
|
|
237
|
+
}, labelStyle],
|
|
238
|
+
numberOfLines: 1,
|
|
239
|
+
children: label
|
|
240
|
+
}) : null]
|
|
241
|
+
}) : null]
|
|
242
|
+
});
|
|
243
|
+
}
|
|
244
|
+
function shouldRenderText(node) {
|
|
245
|
+
return node !== undefined && node !== null && node !== false && node !== '';
|
|
246
|
+
}
|
|
247
|
+
/**
|
|
248
|
+
* Convert the resolved segment list into a list of stroke-dasharray /
|
|
249
|
+
* stroke-dashoffset descriptors that can be drawn as SVG `Circle`s. Each
|
|
250
|
+
* arc's length is its share of `circumference`, and its rotational offset
|
|
251
|
+
* is the cumulative offset of all preceding segments. Visual gaps are
|
|
252
|
+
* applied symmetrically — half a gap is shaved from each end of the arc
|
|
253
|
+
* so the visible separation between two segments equals one full `gap`.
|
|
254
|
+
*/
|
|
255
|
+
function buildArcs({
|
|
256
|
+
segments,
|
|
257
|
+
totalValue,
|
|
258
|
+
circumference,
|
|
259
|
+
gapLength,
|
|
260
|
+
modes
|
|
261
|
+
}) {
|
|
262
|
+
const arcs = [];
|
|
263
|
+
const halfGap = gapLength / 2;
|
|
264
|
+
let cumulativeOffset = 0;
|
|
265
|
+
segments.forEach((segment, index) => {
|
|
266
|
+
const safeValue = Math.max(0, toNumber(segment.value, 0));
|
|
267
|
+
if (safeValue <= 0) {
|
|
268
|
+
return;
|
|
269
|
+
}
|
|
270
|
+
const arcLength = safeValue / totalValue * circumference;
|
|
271
|
+
const drawnLength = Math.max(0, arcLength - gapLength);
|
|
272
|
+
const segmentModes = {
|
|
273
|
+
...modes,
|
|
274
|
+
'Appearance / DataViz': defaultAppearanceFor(index),
|
|
275
|
+
...(segment.modes || {})
|
|
276
|
+
};
|
|
277
|
+
const color = resolveSegmentColor(segment.color, segmentModes);
|
|
278
|
+
const dashArray = `${drawnLength} ${circumference - drawnLength}`;
|
|
279
|
+
const dashOffset = -cumulativeOffset - halfGap;
|
|
280
|
+
arcs.push({
|
|
281
|
+
key: segment.key ?? `segment-${index}`,
|
|
282
|
+
color,
|
|
283
|
+
dashArray,
|
|
284
|
+
dashOffset
|
|
285
|
+
});
|
|
286
|
+
cumulativeOffset += arcLength;
|
|
287
|
+
});
|
|
288
|
+
return arcs;
|
|
289
|
+
}
|
|
290
|
+
const styles = StyleSheet.create({
|
|
291
|
+
centerSlot: {
|
|
292
|
+
alignItems: 'center',
|
|
293
|
+
bottom: 0,
|
|
294
|
+
justifyContent: 'center',
|
|
295
|
+
left: 0,
|
|
296
|
+
position: 'absolute',
|
|
297
|
+
right: 0,
|
|
298
|
+
top: 0
|
|
299
|
+
}
|
|
300
|
+
});
|
|
301
|
+
DonutChart.Segment = DonutChartSegment;
|
|
302
|
+
export { DonutChartSegment };
|
|
303
|
+
export default DonutChart;
|