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.
Files changed (116) hide show
  1. package/CHANGELOG.md +11 -0
  2. package/lib/commonjs/components/AccordionCheckbox/AccordionCheckbox.js +239 -0
  3. package/lib/commonjs/components/BrandChip/BrandChip.js +149 -0
  4. package/lib/commonjs/components/CardBankAccount/CardBankAccount.js +213 -0
  5. package/lib/commonjs/components/CardInsight/CardInsight.js +166 -0
  6. package/lib/commonjs/components/CheckboxGroup/CheckboxGroup.js +67 -0
  7. package/lib/commonjs/components/CheckboxItem/CheckboxItem.js +125 -0
  8. package/lib/commonjs/components/CircularProgressBar/CircularProgressBar.js +56 -9
  9. package/lib/commonjs/components/CoverageBarComparison/CoverageBarComparison.js +272 -0
  10. package/lib/commonjs/components/CoverageRing/CoverageRing.js +141 -0
  11. package/lib/commonjs/components/DonutChart/DonutChart.js +309 -0
  12. package/lib/commonjs/components/DonutChartSummary/DonutChartSummary.js +155 -0
  13. package/lib/commonjs/components/LinearMeter/LinearMeter.js +9 -28
  14. package/lib/commonjs/components/LinearProgress/LinearProgress.js +68 -0
  15. package/lib/commonjs/components/MetricLegendItem/MetricLegendItem.js +95 -0
  16. package/lib/commonjs/components/MonthlyStatusGrid/MonthlyStatusGrid.js +286 -0
  17. package/lib/commonjs/components/OTP/OTP.js +381 -37
  18. package/lib/commonjs/components/ProductOverview/ProductOverview.js +147 -0
  19. package/lib/commonjs/components/RangeTrack/RangeTrack.js +269 -0
  20. package/lib/commonjs/components/SavingsGoalSummary/SavingsGoalSummary.js +181 -0
  21. package/lib/commonjs/components/SegmentedTrack/SegmentedTrack.js +171 -0
  22. package/lib/commonjs/components/StatGroup/StatGroup.js +128 -0
  23. package/lib/commonjs/components/StatItem/StatItem.js +65 -35
  24. package/lib/commonjs/components/StrengthIndicator/StrengthIndicator.js +157 -0
  25. package/lib/commonjs/components/SummaryTile/SummaryTile.js +150 -0
  26. package/lib/commonjs/components/index.js +171 -1
  27. package/lib/commonjs/design-tokens/Coin Variables-variables-full.json +1 -1
  28. package/lib/commonjs/icons/registry.js +1 -1
  29. package/lib/commonjs/utils/index.js +7 -0
  30. package/lib/commonjs/utils/number-utils.js +57 -0
  31. package/lib/module/components/AccordionCheckbox/AccordionCheckbox.js +233 -0
  32. package/lib/module/components/BrandChip/BrandChip.js +143 -0
  33. package/lib/module/components/CardBankAccount/CardBankAccount.js +208 -0
  34. package/lib/module/components/CardInsight/CardInsight.js +161 -0
  35. package/lib/module/components/CheckboxGroup/CheckboxGroup.js +62 -0
  36. package/lib/module/components/CheckboxItem/CheckboxItem.js +119 -0
  37. package/lib/module/components/CircularProgressBar/CircularProgressBar.js +56 -9
  38. package/lib/module/components/CoverageBarComparison/CoverageBarComparison.js +266 -0
  39. package/lib/module/components/CoverageRing/CoverageRing.js +136 -0
  40. package/lib/module/components/DonutChart/DonutChart.js +303 -0
  41. package/lib/module/components/DonutChartSummary/DonutChartSummary.js +150 -0
  42. package/lib/module/components/LinearMeter/LinearMeter.js +9 -28
  43. package/lib/module/components/LinearProgress/LinearProgress.js +63 -0
  44. package/lib/module/components/MetricLegendItem/MetricLegendItem.js +90 -0
  45. package/lib/module/components/MonthlyStatusGrid/MonthlyStatusGrid.js +281 -0
  46. package/lib/module/components/OTP/OTP.js +381 -38
  47. package/lib/module/components/ProductOverview/ProductOverview.js +142 -0
  48. package/lib/module/components/RangeTrack/RangeTrack.js +263 -0
  49. package/lib/module/components/SavingsGoalSummary/SavingsGoalSummary.js +175 -0
  50. package/lib/module/components/SegmentedTrack/SegmentedTrack.js +166 -0
  51. package/lib/module/components/StatGroup/StatGroup.js +123 -0
  52. package/lib/module/components/StatItem/StatItem.js +66 -36
  53. package/lib/module/components/StrengthIndicator/StrengthIndicator.js +152 -0
  54. package/lib/module/components/SummaryTile/SummaryTile.js +145 -0
  55. package/lib/module/components/index.js +21 -1
  56. package/lib/module/design-tokens/Coin Variables-variables-full.json +1 -1
  57. package/lib/module/icons/registry.js +1 -1
  58. package/lib/module/utils/index.js +2 -1
  59. package/lib/module/utils/number-utils.js +53 -0
  60. package/lib/typescript/src/components/AccordionCheckbox/AccordionCheckbox.d.ts +71 -0
  61. package/lib/typescript/src/components/BrandChip/BrandChip.d.ts +43 -0
  62. package/lib/typescript/src/components/CardBankAccount/CardBankAccount.d.ts +79 -0
  63. package/lib/typescript/src/components/CardInsight/CardInsight.d.ts +48 -0
  64. package/lib/typescript/src/components/CheckboxGroup/CheckboxGroup.d.ts +41 -0
  65. package/lib/typescript/src/components/CheckboxItem/CheckboxItem.d.ts +56 -0
  66. package/lib/typescript/src/components/CircularProgressBar/CircularProgressBar.d.ts +11 -1
  67. package/lib/typescript/src/components/CoverageBarComparison/CoverageBarComparison.d.ts +105 -0
  68. package/lib/typescript/src/components/CoverageRing/CoverageRing.d.ts +90 -0
  69. package/lib/typescript/src/components/DonutChart/DonutChart.d.ts +117 -0
  70. package/lib/typescript/src/components/DonutChartSummary/DonutChartSummary.d.ts +103 -0
  71. package/lib/typescript/src/components/LinearProgress/LinearProgress.d.ts +17 -0
  72. package/lib/typescript/src/components/MetricLegendItem/MetricLegendItem.d.ts +37 -0
  73. package/lib/typescript/src/components/MonthlyStatusGrid/MonthlyStatusGrid.d.ts +119 -0
  74. package/lib/typescript/src/components/OTP/OTP.d.ts +88 -2
  75. package/lib/typescript/src/components/ProductOverview/ProductOverview.d.ts +39 -0
  76. package/lib/typescript/src/components/RangeTrack/RangeTrack.d.ts +173 -0
  77. package/lib/typescript/src/components/SavingsGoalSummary/SavingsGoalSummary.d.ts +95 -0
  78. package/lib/typescript/src/components/SegmentedTrack/SegmentedTrack.d.ts +108 -0
  79. package/lib/typescript/src/components/StatGroup/StatGroup.d.ts +45 -0
  80. package/lib/typescript/src/components/StatItem/StatItem.d.ts +24 -7
  81. package/lib/typescript/src/components/StrengthIndicator/StrengthIndicator.d.ts +58 -0
  82. package/lib/typescript/src/components/SummaryTile/SummaryTile.d.ts +60 -0
  83. package/lib/typescript/src/components/index.d.ts +22 -2
  84. package/lib/typescript/src/icons/registry.d.ts +1 -1
  85. package/lib/typescript/src/utils/index.d.ts +1 -0
  86. package/lib/typescript/src/utils/number-utils.d.ts +29 -0
  87. package/package.json +1 -1
  88. package/src/components/AccordionCheckbox/AccordionCheckbox.tsx +323 -0
  89. package/src/components/BrandChip/BrandChip.tsx +235 -0
  90. package/src/components/CardBankAccount/CardBankAccount.tsx +295 -0
  91. package/src/components/CardInsight/CardInsight.tsx +239 -0
  92. package/src/components/CheckboxGroup/CheckboxGroup.tsx +86 -0
  93. package/src/components/CheckboxItem/CheckboxItem.tsx +174 -0
  94. package/src/components/CircularProgressBar/CircularProgressBar.tsx +74 -9
  95. package/src/components/CoverageBarComparison/CoverageBarComparison.tsx +378 -0
  96. package/src/components/CoverageRing/CoverageRing.tsx +225 -0
  97. package/src/components/DonutChart/DonutChart.tsx +503 -0
  98. package/src/components/DonutChartSummary/DonutChartSummary.tsx +256 -0
  99. package/src/components/LinearMeter/LinearMeter.tsx +9 -39
  100. package/src/components/LinearProgress/LinearProgress.tsx +92 -0
  101. package/src/components/MetricLegendItem/MetricLegendItem.tsx +167 -0
  102. package/src/components/MonthlyStatusGrid/MonthlyStatusGrid.tsx +438 -0
  103. package/src/components/OTP/OTP.tsx +476 -29
  104. package/src/components/ProductOverview/ProductOverview.tsx +236 -0
  105. package/src/components/RangeTrack/RangeTrack.tsx +394 -0
  106. package/src/components/SavingsGoalSummary/SavingsGoalSummary.tsx +269 -0
  107. package/src/components/SegmentedTrack/SegmentedTrack.tsx +268 -0
  108. package/src/components/StatGroup/StatGroup.tsx +169 -0
  109. package/src/components/StatItem/StatItem.tsx +117 -40
  110. package/src/components/StrengthIndicator/StrengthIndicator.tsx +205 -0
  111. package/src/components/SummaryTile/SummaryTile.tsx +251 -0
  112. package/src/components/index.ts +32 -2
  113. package/src/design-tokens/Coin Variables-variables-full.json +1 -1
  114. package/src/icons/registry.ts +1 -1
  115. package/src/utils/index.ts +1 -0
  116. package/src/utils/number-utils.ts +60 -0
@@ -0,0 +1,269 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ var _react = _interopRequireWildcard(require("react"));
8
+ var _reactNative = require("react-native");
9
+ var _figmaVariablesResolver = require("../../design-tokens/figma-variables-resolver");
10
+ var _JFSThemeProvider = require("../../design-tokens/JFSThemeProvider");
11
+ var _reactUtils = require("../../utils/react-utils");
12
+ var _MetricLegendItem = _interopRequireDefault(require("../MetricLegendItem/MetricLegendItem"));
13
+ var _SegmentedTrack = _interopRequireDefault(require("../SegmentedTrack/SegmentedTrack"));
14
+ var _Tabs = _interopRequireDefault(require("../Tabs/Tabs"));
15
+ var _TabItem = _interopRequireDefault(require("../Tabs/TabItem"));
16
+ var _jsxRuntime = require("react/jsx-runtime");
17
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
18
+ function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
19
+ /**
20
+ * One row of data inside a `RangeTrack` tab.
21
+ *
22
+ * Each item drives BOTH a `SegmentedTrack` segment and the matching
23
+ * `MetricLegendItem` row, so the segment color and legend indicator
24
+ * always share the same color by construction (same `Emphasis / DataViz`
25
+ * cascade as the standalone `SegmentedTrack`).
26
+ */
27
+
28
+ /**
29
+ * One tab inside a `RangeTrack`. Each tab carries its own `items`
30
+ * array, which is the single source of truth for both the
31
+ * `SegmentedTrack` segments AND the `MetricLegendItem` legend rows
32
+ * rendered for that tab.
33
+ */
34
+
35
+ const DEFAULT_EMPHASIS_CYCLE = ['High', 'Medium', 'Low'];
36
+ const DEFAULT_TABS = [{
37
+ label: 'Tab item',
38
+ items: [{
39
+ label: 'Large cap',
40
+ value: 1,
41
+ displayValue: '25%'
42
+ }, {
43
+ label: 'Mid cap',
44
+ value: 1,
45
+ displayValue: '25%'
46
+ }, {
47
+ label: 'Small cap',
48
+ value: 1,
49
+ displayValue: '25%'
50
+ }]
51
+ }, {
52
+ label: 'Tab item',
53
+ items: [{
54
+ label: 'Large cap',
55
+ value: 1,
56
+ displayValue: '25%'
57
+ }, {
58
+ label: 'Mid cap',
59
+ value: 1,
60
+ displayValue: '25%'
61
+ }, {
62
+ label: 'Small cap',
63
+ value: 1,
64
+ displayValue: '25%'
65
+ }]
66
+ }, {
67
+ label: 'Tab item',
68
+ items: [{
69
+ label: 'Large cap',
70
+ value: 1,
71
+ displayValue: '25%'
72
+ }, {
73
+ label: 'Mid cap',
74
+ value: 1,
75
+ displayValue: '25%'
76
+ }, {
77
+ label: 'Small cap',
78
+ value: 1,
79
+ displayValue: '25%'
80
+ }]
81
+ }];
82
+ const defaultEmphasisFor = index => DEFAULT_EMPHASIS_CYCLE[index % DEFAULT_EMPHASIS_CYCLE.length];
83
+
84
+ /**
85
+ * Resolve the shared color for an item. Honors any explicit `color`
86
+ * override, then falls back to `dataViz/bg` for the merged mode set,
87
+ * then to the Figma reference value.
88
+ *
89
+ * Mirrors the cascade used by `SegmentedTrack` (per-index `Emphasis /
90
+ * DataViz` defaults of `High` → `Medium` → `Low`, cycling) so the
91
+ * pre-computed color we pass to both the segment and the legend
92
+ * indicator matches what the `SegmentedTrack` would have computed on
93
+ * its own. This is what keeps segments and legend rows in sync by
94
+ * construction.
95
+ */
96
+ function resolveItemColor(parentModes, item, index) {
97
+ if (item.color) return item.color;
98
+ const itemModes = {
99
+ ...parentModes,
100
+ 'Emphasis / DataViz': defaultEmphasisFor(index),
101
+ ...(item.modes || {})
102
+ };
103
+ return (0, _figmaVariablesResolver.getVariableByName)('dataViz/bg', itemModes) ?? '#cea15a';
104
+ }
105
+
106
+ /**
107
+ * Resolve what to render in the legend row's right-side slot. The
108
+ * order of precedence is:
109
+ * 1. `item.displayValue` if explicitly provided (including `null` /
110
+ * `false`, which the underlying `MetricLegendItem` treats as
111
+ * "hide the value slot").
112
+ * 2. `formatValue(item.value)` when a parent-level formatter exists.
113
+ * 3. `undefined` — the value slot is hidden.
114
+ */
115
+ function resolveLegendValue(item, formatValue) {
116
+ if (item.displayValue !== undefined) return item.displayValue;
117
+ if (formatValue) return formatValue(item.value);
118
+ return undefined;
119
+ }
120
+
121
+ /**
122
+ * `RangeTrack` pairs a tab row with a `SegmentedTrack` and a vertical
123
+ * stack of `MetricLegendItem` rows. Each tab carries its own `items`
124
+ * array which is the **single source of truth** for both the segments
125
+ * and the legend rows of that tab — every segment has exactly one
126
+ * legend row and they share the same color through the same
127
+ * `Emphasis / DataViz` cascade as the standalone `SegmentedTrack`.
128
+ *
129
+ * Switching tabs swaps the segments and the legend together so the
130
+ * two visualizations can never drift out of sync.
131
+ *
132
+ * The default 3-item layout per tab receives per-index
133
+ * `Emphasis / DataViz` defaults (item 1 → `High`, 2 → `Medium`, 3 →
134
+ * `Low`, then cycles). Override `Appearance / DataViz` on the parent
135
+ * `modes` to retheme the whole component, or set `modes` per item to
136
+ * remix.
137
+ *
138
+ * The component supports both **controlled** and **uncontrolled**
139
+ * tab selection — pass `activeTabIndex` + `onTabChange` for the
140
+ * controlled mode, or omit them and the component will manage the
141
+ * selection internally starting from `defaultActiveTabIndex`.
142
+ *
143
+ * @component
144
+ * @param {RangeTrackProps} props
145
+ *
146
+ * @example
147
+ * ```tsx
148
+ * <RangeTrack
149
+ * tabs={[
150
+ * {
151
+ * label: 'Sectoral',
152
+ * items: [
153
+ * { label: 'Large cap', value: 50, displayValue: '50%' },
154
+ * { label: 'Mid cap', value: 30, displayValue: '30%' },
155
+ * { label: 'Small cap', value: 20, displayValue: '20%' },
156
+ * ],
157
+ * },
158
+ * {
159
+ * label: 'Geography',
160
+ * items: [
161
+ * { label: 'India', value: 70, displayValue: '70%' },
162
+ * { label: 'US', value: 20, displayValue: '20%' },
163
+ * { label: 'Other', value: 10, displayValue: '10%' },
164
+ * ],
165
+ * },
166
+ * ]}
167
+ * />
168
+ * ```
169
+ */
170
+ function RangeTrack({
171
+ tabs,
172
+ formatValue,
173
+ activeTabIndex,
174
+ defaultActiveTabIndex = 0,
175
+ onTabChange,
176
+ scrollableTabs = false,
177
+ modes: propModes = _reactUtils.EMPTY_MODES,
178
+ style,
179
+ tabsStyle,
180
+ trackStyle,
181
+ legendStyle,
182
+ accessibilityLabel
183
+ }) {
184
+ const {
185
+ modes: globalModes
186
+ } = (0, _JFSThemeProvider.useTokens)();
187
+ const modes = {
188
+ ...globalModes,
189
+ ...propModes
190
+ };
191
+ const resolvedTabs = tabs && tabs.length > 0 ? tabs : DEFAULT_TABS;
192
+ const [internalIndex, setInternalIndex] = (0, _react.useState)(() => clampIndex(defaultActiveTabIndex, resolvedTabs.length));
193
+ const isControlled = activeTabIndex !== undefined;
194
+ const rawIndex = isControlled ? activeTabIndex : internalIndex;
195
+ const safeIndex = clampIndex(rawIndex, resolvedTabs.length);
196
+ const handleTabPress = (0, _react.useCallback)(index => {
197
+ const nextTab = resolvedTabs[index];
198
+ if (!nextTab) return;
199
+ if (!isControlled) setInternalIndex(index);
200
+ onTabChange?.(index, nextTab);
201
+ }, [isControlled, onTabChange, resolvedTabs]);
202
+ const containerGap = (0, _figmaVariablesResolver.getVariableByName)('rangeTrack/gap', modes) ?? 28;
203
+ // Vertical gap between legend rows is not exposed as its own token —
204
+ // the Figma design uses 8px between rows, mirroring the
205
+ // `donutChartSummary/legend/gap` default. Keep the value in step
206
+ // with `DonutChartSummary` so the two summary components feel
207
+ // cohesive when stacked.
208
+ const legendRowGap = 8;
209
+ const activeTab = resolvedTabs[safeIndex];
210
+ const activeItems = activeTab?.items ?? [];
211
+ const segments = activeItems.map((item, index) => ({
212
+ key: item.key ?? `segment-${index}`,
213
+ value: item.value,
214
+ color: resolveItemColor(modes, item, index),
215
+ accessibilityLabel: item.accessibilityLabel
216
+ }));
217
+ return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_reactNative.View, {
218
+ accessibilityRole: "summary",
219
+ accessibilityLabel: accessibilityLabel,
220
+ style: [{
221
+ width: '100%',
222
+ flexDirection: 'column',
223
+ alignItems: 'flex-start',
224
+ gap: containerGap
225
+ }, style],
226
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_Tabs.default, {
227
+ modes: modes,
228
+ scrollable: scrollableTabs,
229
+ style: tabsStyle,
230
+ children: resolvedTabs.map((tab, index) => /*#__PURE__*/(0, _jsxRuntime.jsx)(_TabItem.default, {
231
+ label: tab.label,
232
+ active: index === safeIndex,
233
+ onPress: () => handleTabPress(index),
234
+ accessibilityLabel: tab.accessibilityLabel ?? tab.label
235
+ }, tab.key ?? tab.label ?? `tab-${index}`))
236
+ }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_SegmentedTrack.default, {
237
+ modes: modes,
238
+ segments: segments,
239
+ style: trackStyle,
240
+ accessibilityLabel: activeTab?.accessibilityLabel ?? activeTab?.label
241
+ }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.View, {
242
+ style: [{
243
+ width: '100%',
244
+ flexDirection: 'column',
245
+ alignItems: 'flex-start',
246
+ gap: legendRowGap
247
+ }, legendStyle],
248
+ children: activeItems.map((item, index) => /*#__PURE__*/(0, _jsxRuntime.jsx)(_MetricLegendItem.default, {
249
+ label: item.label,
250
+ value: resolveLegendValue(item, formatValue),
251
+ indicatorColor: resolveItemColor(modes, item, index),
252
+ modes: modes
253
+ }, item.key ?? `legend-${index}`))
254
+ })]
255
+ });
256
+ }
257
+
258
+ /**
259
+ * Clamp a tab index into `[0, length)`. Negative or out-of-bounds
260
+ * values fall back to `0` to avoid rendering an undefined tab.
261
+ */
262
+ function clampIndex(index, length) {
263
+ if (length <= 0) return 0;
264
+ if (!Number.isFinite(index)) return 0;
265
+ if (index < 0) return 0;
266
+ if (index >= length) return length - 1;
267
+ return Math.floor(index);
268
+ }
269
+ var _default = exports.default = RangeTrack;
@@ -0,0 +1,181 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ var _react = _interopRequireWildcard(require("react"));
8
+ var _reactNative = require("react-native");
9
+ var _figmaVariablesResolver = require("../../design-tokens/figma-variables-resolver");
10
+ var _reactUtils = require("../../utils/react-utils");
11
+ var _numberUtils = require("../../utils/number-utils");
12
+ var _Title = _interopRequireDefault(require("../Title/Title"));
13
+ var _LinearProgress = _interopRequireDefault(require("../LinearProgress/LinearProgress"));
14
+ var _MetricLegendItem = _interopRequireDefault(require("../MetricLegendItem/MetricLegendItem"));
15
+ var _jsxRuntime = require("react/jsx-runtime");
16
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
17
+ function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
18
+ /**
19
+ * A single row in the savings-goal legend (current vs. target).
20
+ *
21
+ * `value` is a **numeric amount** (e.g. `240000`). It serves two purposes:
22
+ *
23
+ * 1. Display: rendered on the right side of the row using Indian numeric
24
+ * notation via {@link formatIndianNumber} and prefixed with `currency`
25
+ * (e.g. `240000` → `"₹2.4L"`).
26
+ * 2. Progress derivation: the bar fills to `current.value / target.value`
27
+ * automatically. There is no separate `progress` prop.
28
+ *
29
+ * Pass `value: undefined` to render a label-only row (the underlying
30
+ * {@link MetricLegendItem} hides the right slot in that case).
31
+ */
32
+
33
+ const DEFAULT_LEGEND_PADDING = 8;
34
+ const DEFAULT_MODES = Object.freeze({
35
+ 'LinearProgress Size': 'L'
36
+ });
37
+ const DEFAULT_CURRENT = {
38
+ label: 'Current (4 months)',
39
+ value: 240000
40
+ };
41
+ const DEFAULT_TARGET = {
42
+ label: 'Recommended (8 months)',
43
+ value: 480000
44
+ };
45
+
46
+ /**
47
+ * `SavingsGoalSummary` visualises progress toward a savings goal as:
48
+ *
49
+ * 1. A `Title` showing the percentage — **computed automatically** from
50
+ * `current.value / target.value`. There is no `progress` prop; the
51
+ * component owns the calculation so the title, bar and legend are always
52
+ * in sync.
53
+ * 2. A `LinearProgress` bar driven by the same derived ratio.
54
+ * 3. A two-row legend comparing **current** vs. **target**, where each numeric
55
+ * `value` is auto-formatted with Indian notation
56
+ * ({@link formatIndianNumber}) and prefixed with the `currency` symbol.
57
+ *
58
+ * The component is intentionally narrow in scope — it is the body of a savings
59
+ * insight card. Wrap it in `CardInsight` (or any container of your choice) to
60
+ * add a heading, badge or footer.
61
+ *
62
+ * @component
63
+ * @param {SavingsGoalSummaryProps} props
64
+ */
65
+ function SavingsGoalSummary({
66
+ currency = '₹',
67
+ current = DEFAULT_CURRENT,
68
+ target = DEFAULT_TARGET,
69
+ children,
70
+ modes = _reactUtils.EMPTY_MODES,
71
+ style,
72
+ titleStyle,
73
+ legendStyle
74
+ }) {
75
+ // Merge caller modes on top of the defaults so callers can override
76
+ // (e.g. switch to `LinearProgress Size: M`) while still receiving the
77
+ // sensible component-level default.
78
+ const mergedModes = (0, _react.useMemo)(() => modes === _reactUtils.EMPTY_MODES ? DEFAULT_MODES : {
79
+ ...DEFAULT_MODES,
80
+ ...modes
81
+ }, [modes]);
82
+
83
+ // Resolve the `LinearProgress` track / indicator colours so the legend
84
+ // dots automatically stay in sync with the progress bar without callers
85
+ // needing to plumb through `indicatorColor`.
86
+ //
87
+ // The token names AND the merge strategy must match `LinearProgress.tsx`
88
+ // exactly, otherwise the dot colours can drift from the bar:
89
+ // • Token aliases live in the `Emphasis` collection (modes High|Medium|Low),
90
+ // NOT `Emphasis / DataViz` — passing the wrong mode key would collapse
91
+ // both dots to the same default-mode colour.
92
+ // • Defaults are placed *before* `mergedModes` is spread, so callers can
93
+ // still override `Emphasis` via the `modes` prop (matches
94
+ // `LinearProgress`'s philosophy).
95
+ const indicatorColorFromTokens = (0, _figmaVariablesResolver.getVariableByName)('linearProgress/indicator/background', {
96
+ Emphasis: 'High',
97
+ ...mergedModes
98
+ }) ?? '#5d00b5';
99
+ const trackColorFromTokens = (0, _figmaVariablesResolver.getVariableByName)('linearProgress/track/background', {
100
+ Emphasis: 'Low',
101
+ ...mergedModes
102
+ }) ?? '#ede7ff';
103
+
104
+ // Single source of truth for the bar fill, the title percentage and the
105
+ // formatted legend amounts. There is intentionally no consumer-facing
106
+ // `progress` prop — the only way to change the bar is to change the
107
+ // numeric `current` / `target` values. This keeps the three views (title,
108
+ // bar, legend) impossible to desynchronise.
109
+ const resolvedProgress = (0, _react.useMemo)(() => {
110
+ const cv = current?.value;
111
+ const tv = target?.value;
112
+ if (typeof cv !== 'number' || typeof tv !== 'number' || tv <= 0) {
113
+ return 0;
114
+ }
115
+ return Math.min(Math.max(cv / tv, 0), 1);
116
+ }, [current, target]);
117
+ const percentageLabel = `${Math.round(resolvedProgress * 100)}%`;
118
+ const gap = (0, _figmaVariablesResolver.getVariableByName)('savingsGoalSummary/gap', mergedModes) ?? 23;
119
+ const legendGap = (0, _figmaVariablesResolver.getVariableByName)('savingsGoalSummary/legend/gap', mergedModes) ?? 16;
120
+ const customLegend = children ? (0, _reactUtils.cloneChildrenWithModes)(children, mergedModes) : null;
121
+ const defaultLegend = !customLegend && (current || target) ? /*#__PURE__*/(0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
122
+ children: [current && /*#__PURE__*/(0, _jsxRuntime.jsx)(_MetricLegendItem.default, {
123
+ modes: mergedModes,
124
+ label: current.label,
125
+ value: formatLegendValue(current.value, currency),
126
+ indicatorColor: current.indicatorColor ?? indicatorColorFromTokens
127
+ }), target && /*#__PURE__*/(0, _jsxRuntime.jsx)(_MetricLegendItem.default, {
128
+ modes: mergedModes,
129
+ label: target.label,
130
+ value: formatLegendValue(target.value, currency),
131
+ indicatorColor: target.indicatorColor ?? trackColorFromTokens
132
+ })]
133
+ }) : null;
134
+ const legendNode = customLegend ?? defaultLegend;
135
+ const showLegend = legendNode != null;
136
+ return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_reactNative.View, {
137
+ style: [{
138
+ width: '100%',
139
+ gap,
140
+ alignItems: 'stretch'
141
+ }, style],
142
+ accessibilityLabel: `Savings goal progress, ${percentageLabel}`,
143
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_Title.default, {
144
+ title: percentageLabel,
145
+ modes: mergedModes,
146
+ style: TITLE_CONTAINER_STYLE,
147
+ textStyle: titleStyle
148
+ }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_LinearProgress.default, {
149
+ value: resolvedProgress,
150
+ modes: mergedModes
151
+ }), showLegend && /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.View, {
152
+ style: [{
153
+ width: '100%',
154
+ padding: DEFAULT_LEGEND_PADDING,
155
+ gap: legendGap,
156
+ alignItems: 'stretch'
157
+ }, legendStyle],
158
+ children: legendNode
159
+ })]
160
+ });
161
+ }
162
+
163
+ /**
164
+ * Format a single legend `value` for display. Returns `undefined` when the
165
+ * value is missing so the underlying {@link MetricLegendItem} hides the right
166
+ * slot (matches the Figma `data` toggle = off).
167
+ */
168
+ function formatLegendValue(value, currency) {
169
+ if (typeof value !== 'number') return undefined;
170
+ return (0, _numberUtils.formatIndianNumber)(value, {
171
+ prefix: currency
172
+ });
173
+ }
174
+
175
+ // Neutralise the `Title` component's default page-level padding so it sits
176
+ // flush inside the summary card (the parent container owns spacing via `gap`).
177
+ const TITLE_CONTAINER_STYLE = {
178
+ paddingHorizontal: 0,
179
+ paddingVertical: 0
180
+ };
181
+ var _default = exports.default = SavingsGoalSummary;
@@ -0,0 +1,171 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.SegmentedTrackSegment = SegmentedTrackSegment;
7
+ exports.default = void 0;
8
+ var _react = _interopRequireDefault(require("react"));
9
+ var _reactNative = require("react-native");
10
+ var _figmaVariablesResolver = require("../../design-tokens/figma-variables-resolver");
11
+ var _JFSThemeProvider = require("../../design-tokens/JFSThemeProvider");
12
+ var _reactUtils = require("../../utils/react-utils");
13
+ var _jsxRuntime = require("react/jsx-runtime");
14
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
15
+ /**
16
+ * Per-segment data definition for the data-driven `segments` prop.
17
+ *
18
+ * Use `value` for proportional widths (segments share width by their value
19
+ * relative to the sum). When `value` is omitted, segments share the row
20
+ * equally (`flex: 1`).
21
+ *
22
+ * Use `modes` to override the per-segment design-token mode — typically the
23
+ * `Appearance / DataViz` mode for color theming, or `Emphasis / DataViz` to
24
+ * change the emphasis level. The parent already injects per-index defaults
25
+ * (segment 0 = High, 1 = Medium, 2 = Low, then cycling) so callers only need
26
+ * to pass `modes` when they want a different result.
27
+ */
28
+
29
+ /**
30
+ * Default per-index Emphasis modes applied to every segment when the caller
31
+ * does not provide its own `Emphasis / DataViz` override. Cycles for >3
32
+ * segments so additional segments fall back to the same High/Medium/Low
33
+ * rotation.
34
+ */
35
+ const DEFAULT_EMPHASIS_CYCLE = ['High', 'Medium', 'Low'];
36
+ const DEFAULT_SEGMENTS = [{}, {}, {}];
37
+
38
+ /**
39
+ * Compute the default `Emphasis / DataViz` mode for a segment at `index`.
40
+ * Cycles through {@link DEFAULT_EMPHASIS_CYCLE} so any number of segments
41
+ * gets a sensible default.
42
+ */
43
+ function defaultEmphasisFor(index) {
44
+ return DEFAULT_EMPHASIS_CYCLE[index % DEFAULT_EMPHASIS_CYCLE.length];
45
+ }
46
+ function SegmentedTrackSegment({
47
+ value = 1,
48
+ color,
49
+ modes = _reactUtils.EMPTY_MODES,
50
+ style,
51
+ accessibilityLabel
52
+ }) {
53
+ const resolvedColor = color ?? (0, _figmaVariablesResolver.getVariableByName)('dataViz/bg', modes) ?? '#5d00b5';
54
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.View, {
55
+ accessibilityLabel: accessibilityLabel,
56
+ style: [{
57
+ flex: value,
58
+ minWidth: 1,
59
+ height: '100%',
60
+ backgroundColor: resolvedColor
61
+ }, style]
62
+ });
63
+ }
64
+
65
+ /**
66
+ * `SegmentedTrack` renders a horizontal pill-shaped row of categorical
67
+ * segments. Use it for distribution / share-of breakdowns where each
68
+ * segment is a sibling category (not a directional or temporal progress).
69
+ *
70
+ * Defaults to three equal segments tinted at descending Emphasis levels
71
+ * (`High`, `Medium`, `Low`) so the shape reads as a single concept split
72
+ * three ways. Consumers can either pass the data-driven `segments` prop or
73
+ * a fully custom `children` slot of `SegmentedTrack.Segment`s.
74
+ *
75
+ * Each segment resolves its color through the `dataViz/bg` token, which
76
+ * cascades through `Emphasis / DataViz` and `Appearance / DataViz`. Pass
77
+ * `modes` per segment (or override `Appearance / DataViz` at the parent
78
+ * level via `modes`) to retheme the row without touching colors directly.
79
+ *
80
+ * @component
81
+ * @param {SegmentedTrackProps} props
82
+ */
83
+ function SegmentedTrack({
84
+ segments,
85
+ children,
86
+ modes: propModes = _reactUtils.EMPTY_MODES,
87
+ style,
88
+ segmentStyle,
89
+ accessibilityLabel
90
+ }) {
91
+ const {
92
+ modes: globalModes
93
+ } = (0, _JFSThemeProvider.useTokens)();
94
+ const modes = {
95
+ ...globalModes,
96
+ ...propModes
97
+ };
98
+ const trackHeight = (0, _figmaVariablesResolver.getVariableByName)('segmentedTrack/height', modes) ?? 24;
99
+ const trackRadius = (0, _figmaVariablesResolver.getVariableByName)('segmentedTrack/radius', modes) ?? 999;
100
+ const renderedSegments = renderSegments({
101
+ segments,
102
+ children,
103
+ modes,
104
+ segmentStyle
105
+ });
106
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.View, {
107
+ accessibilityRole: "image",
108
+ accessibilityLabel: accessibilityLabel,
109
+ style: [{
110
+ flexDirection: 'row',
111
+ alignItems: 'stretch',
112
+ height: trackHeight,
113
+ borderRadius: trackRadius,
114
+ overflow: 'hidden',
115
+ width: '100%',
116
+ backgroundColor: 'transparent'
117
+ }, style],
118
+ children: renderedSegments
119
+ });
120
+ }
121
+
122
+ /**
123
+ * Build the slot children. When the caller passes JSX `children`, every
124
+ * top-level element is treated as one segment and receives merged `modes`
125
+ * (parent + per-index Emphasis default + the child's own `modes` taking
126
+ * priority). Otherwise the data-driven `segments` array is rendered.
127
+ */
128
+ function renderSegments({
129
+ segments,
130
+ children,
131
+ modes,
132
+ segmentStyle
133
+ }) {
134
+ if (children !== undefined && children !== null) {
135
+ const flat = (0, _reactUtils.flattenChildren)(children);
136
+ return flat.map((child, index) => {
137
+ if (! /*#__PURE__*/_react.default.isValidElement(child)) {
138
+ return child;
139
+ }
140
+ const childProps = child.props ?? {};
141
+ const childModes = childProps.modes;
142
+ const mergedModes = {
143
+ ...modes,
144
+ 'Emphasis / DataViz': defaultEmphasisFor(index),
145
+ ...(childModes || {})
146
+ };
147
+ return /*#__PURE__*/_react.default.cloneElement(child, {
148
+ ...childProps,
149
+ modes: mergedModes,
150
+ key: child.key ?? `segment-${index}`
151
+ });
152
+ });
153
+ }
154
+ const list = segments && segments.length > 0 ? segments : DEFAULT_SEGMENTS;
155
+ return list.map((segment, index) => {
156
+ const segmentModes = {
157
+ ...modes,
158
+ 'Emphasis / DataViz': defaultEmphasisFor(index),
159
+ ...(segment.modes || {})
160
+ };
161
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)(SegmentedTrackSegment, {
162
+ value: segment.value ?? 1,
163
+ color: segment.color,
164
+ modes: segmentModes,
165
+ style: [segmentStyle, segment.style],
166
+ accessibilityLabel: segment.accessibilityLabel
167
+ }, segment.key ?? `segment-${index}`);
168
+ });
169
+ }
170
+ SegmentedTrack.Segment = SegmentedTrackSegment;
171
+ var _default = exports.default = SegmentedTrack;