jfs-components 0.0.71 → 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 (141) hide show
  1. package/CHANGELOG.md +60 -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/CardAdvisory/CardAdvisory.js +2 -2
  5. package/lib/commonjs/components/CardBankAccount/CardBankAccount.js +213 -0
  6. package/lib/commonjs/components/CardFinancialCondition/CardFinancialCondition.js +213 -0
  7. package/lib/commonjs/components/CardInsight/CardInsight.js +166 -0
  8. package/lib/commonjs/components/Carousel/Carousel.js +9 -7
  9. package/lib/commonjs/components/CheckboxGroup/CheckboxGroup.js +67 -0
  10. package/lib/commonjs/components/CheckboxItem/CheckboxItem.js +125 -0
  11. package/lib/commonjs/components/CircularProgressBar/CircularProgressBar.js +56 -9
  12. package/lib/commonjs/components/CoverageBarComparison/CoverageBarComparison.js +272 -0
  13. package/lib/commonjs/components/CoverageRing/CoverageRing.js +141 -0
  14. package/lib/commonjs/components/DonutChart/DonutChart.js +309 -0
  15. package/lib/commonjs/components/DonutChartSummary/DonutChartSummary.js +155 -0
  16. package/lib/commonjs/components/HoldingsCard/HoldingsCard.js +2 -2
  17. package/lib/commonjs/components/InstitutionBadge/InstitutionBadge.js +132 -0
  18. package/lib/commonjs/components/LinearMeter/LinearMeter.js +9 -28
  19. package/lib/commonjs/components/LinearProgress/LinearProgress.js +68 -0
  20. package/lib/commonjs/components/MetricLegendItem/MetricLegendItem.js +95 -0
  21. package/lib/commonjs/components/MonthlyStatusGrid/MonthlyStatusGrid.js +286 -0
  22. package/lib/commonjs/components/OTP/OTP.js +381 -37
  23. package/lib/commonjs/components/ProductOverview/ProductOverview.js +147 -0
  24. package/lib/commonjs/components/Radio/Radio.js +194 -0
  25. package/lib/commonjs/components/RadioButton/RadioButton.js +21 -188
  26. package/lib/commonjs/components/RangeTrack/RangeTrack.js +269 -0
  27. package/lib/commonjs/components/SavingsGoalSummary/SavingsGoalSummary.js +181 -0
  28. package/lib/commonjs/components/SegmentedTrack/SegmentedTrack.js +171 -0
  29. package/lib/commonjs/components/StatGroup/StatGroup.js +128 -0
  30. package/lib/commonjs/components/StatItem/StatItem.js +65 -35
  31. package/lib/commonjs/components/StrengthIndicator/StrengthIndicator.js +157 -0
  32. package/lib/commonjs/components/SummaryTile/SummaryTile.js +150 -0
  33. package/lib/commonjs/components/index.js +192 -1
  34. package/lib/commonjs/design-tokens/Coin Variables-variables-full.json +1 -1
  35. package/lib/commonjs/icons/registry.js +1 -1
  36. package/lib/commonjs/utils/index.js +7 -0
  37. package/lib/commonjs/utils/number-utils.js +57 -0
  38. package/lib/module/components/AccordionCheckbox/AccordionCheckbox.js +233 -0
  39. package/lib/module/components/BrandChip/BrandChip.js +143 -0
  40. package/lib/module/components/CardAdvisory/CardAdvisory.js +2 -2
  41. package/lib/module/components/CardBankAccount/CardBankAccount.js +208 -0
  42. package/lib/module/components/CardFinancialCondition/CardFinancialCondition.js +207 -0
  43. package/lib/module/components/CardInsight/CardInsight.js +161 -0
  44. package/lib/module/components/Carousel/Carousel.js +9 -7
  45. package/lib/module/components/CheckboxGroup/CheckboxGroup.js +62 -0
  46. package/lib/module/components/CheckboxItem/CheckboxItem.js +119 -0
  47. package/lib/module/components/CircularProgressBar/CircularProgressBar.js +56 -9
  48. package/lib/module/components/CoverageBarComparison/CoverageBarComparison.js +266 -0
  49. package/lib/module/components/CoverageRing/CoverageRing.js +136 -0
  50. package/lib/module/components/DonutChart/DonutChart.js +303 -0
  51. package/lib/module/components/DonutChartSummary/DonutChartSummary.js +150 -0
  52. package/lib/module/components/HoldingsCard/HoldingsCard.js +2 -2
  53. package/lib/module/components/InstitutionBadge/InstitutionBadge.js +127 -0
  54. package/lib/module/components/LinearMeter/LinearMeter.js +9 -28
  55. package/lib/module/components/LinearProgress/LinearProgress.js +63 -0
  56. package/lib/module/components/MetricLegendItem/MetricLegendItem.js +90 -0
  57. package/lib/module/components/MonthlyStatusGrid/MonthlyStatusGrid.js +281 -0
  58. package/lib/module/components/OTP/OTP.js +381 -38
  59. package/lib/module/components/ProductOverview/ProductOverview.js +142 -0
  60. package/lib/module/components/Radio/Radio.js +188 -0
  61. package/lib/module/components/RadioButton/RadioButton.js +20 -185
  62. package/lib/module/components/RangeTrack/RangeTrack.js +263 -0
  63. package/lib/module/components/SavingsGoalSummary/SavingsGoalSummary.js +175 -0
  64. package/lib/module/components/SegmentedTrack/SegmentedTrack.js +166 -0
  65. package/lib/module/components/StatGroup/StatGroup.js +123 -0
  66. package/lib/module/components/StatItem/StatItem.js +66 -36
  67. package/lib/module/components/StrengthIndicator/StrengthIndicator.js +152 -0
  68. package/lib/module/components/SummaryTile/SummaryTile.js +145 -0
  69. package/lib/module/components/index.js +28 -1
  70. package/lib/module/design-tokens/Coin Variables-variables-full.json +1 -1
  71. package/lib/module/icons/registry.js +1 -1
  72. package/lib/module/utils/index.js +2 -1
  73. package/lib/module/utils/number-utils.js +53 -0
  74. package/lib/typescript/src/components/AccordionCheckbox/AccordionCheckbox.d.ts +71 -0
  75. package/lib/typescript/src/components/BrandChip/BrandChip.d.ts +43 -0
  76. package/lib/typescript/src/components/CardBankAccount/CardBankAccount.d.ts +79 -0
  77. package/lib/typescript/src/components/CardFinancialCondition/CardFinancialCondition.d.ts +50 -0
  78. package/lib/typescript/src/components/CardInsight/CardInsight.d.ts +48 -0
  79. package/lib/typescript/src/components/CheckboxGroup/CheckboxGroup.d.ts +41 -0
  80. package/lib/typescript/src/components/CheckboxItem/CheckboxItem.d.ts +56 -0
  81. package/lib/typescript/src/components/CircularProgressBar/CircularProgressBar.d.ts +11 -1
  82. package/lib/typescript/src/components/CoverageBarComparison/CoverageBarComparison.d.ts +105 -0
  83. package/lib/typescript/src/components/CoverageRing/CoverageRing.d.ts +90 -0
  84. package/lib/typescript/src/components/DonutChart/DonutChart.d.ts +117 -0
  85. package/lib/typescript/src/components/DonutChartSummary/DonutChartSummary.d.ts +103 -0
  86. package/lib/typescript/src/components/InstitutionBadge/InstitutionBadge.d.ts +30 -0
  87. package/lib/typescript/src/components/LinearProgress/LinearProgress.d.ts +17 -0
  88. package/lib/typescript/src/components/MetricLegendItem/MetricLegendItem.d.ts +37 -0
  89. package/lib/typescript/src/components/MonthlyStatusGrid/MonthlyStatusGrid.d.ts +119 -0
  90. package/lib/typescript/src/components/OTP/OTP.d.ts +88 -2
  91. package/lib/typescript/src/components/ProductOverview/ProductOverview.d.ts +39 -0
  92. package/lib/typescript/src/components/Radio/Radio.d.ts +30 -0
  93. package/lib/typescript/src/components/RadioButton/RadioButton.d.ts +20 -28
  94. package/lib/typescript/src/components/RangeTrack/RangeTrack.d.ts +173 -0
  95. package/lib/typescript/src/components/SavingsGoalSummary/SavingsGoalSummary.d.ts +95 -0
  96. package/lib/typescript/src/components/SegmentedTrack/SegmentedTrack.d.ts +108 -0
  97. package/lib/typescript/src/components/StatGroup/StatGroup.d.ts +45 -0
  98. package/lib/typescript/src/components/StatItem/StatItem.d.ts +24 -7
  99. package/lib/typescript/src/components/StrengthIndicator/StrengthIndicator.d.ts +58 -0
  100. package/lib/typescript/src/components/SummaryTile/SummaryTile.d.ts +60 -0
  101. package/lib/typescript/src/components/index.d.ts +29 -2
  102. package/lib/typescript/src/icons/registry.d.ts +1 -1
  103. package/lib/typescript/src/utils/index.d.ts +1 -0
  104. package/lib/typescript/src/utils/number-utils.d.ts +29 -0
  105. package/package.json +1 -1
  106. package/src/components/AccordionCheckbox/AccordionCheckbox.tsx +323 -0
  107. package/src/components/BrandChip/BrandChip.tsx +235 -0
  108. package/src/components/CardAdvisory/CardAdvisory.tsx +2 -2
  109. package/src/components/CardBankAccount/CardBankAccount.tsx +295 -0
  110. package/src/components/CardFinancialCondition/CardFinancialCondition.tsx +366 -0
  111. package/src/components/CardInsight/CardInsight.tsx +239 -0
  112. package/src/components/Carousel/Carousel.tsx +14 -6
  113. package/src/components/CheckboxGroup/CheckboxGroup.tsx +86 -0
  114. package/src/components/CheckboxItem/CheckboxItem.tsx +174 -0
  115. package/src/components/CircularProgressBar/CircularProgressBar.tsx +74 -9
  116. package/src/components/CoverageBarComparison/CoverageBarComparison.tsx +378 -0
  117. package/src/components/CoverageRing/CoverageRing.tsx +225 -0
  118. package/src/components/DonutChart/DonutChart.tsx +503 -0
  119. package/src/components/DonutChartSummary/DonutChartSummary.tsx +256 -0
  120. package/src/components/HoldingsCard/HoldingsCard.tsx +2 -2
  121. package/src/components/InstitutionBadge/InstitutionBadge.tsx +216 -0
  122. package/src/components/LinearMeter/LinearMeter.tsx +9 -39
  123. package/src/components/LinearProgress/LinearProgress.tsx +92 -0
  124. package/src/components/MetricLegendItem/MetricLegendItem.tsx +167 -0
  125. package/src/components/MonthlyStatusGrid/MonthlyStatusGrid.tsx +438 -0
  126. package/src/components/OTP/OTP.tsx +476 -29
  127. package/src/components/ProductOverview/ProductOverview.tsx +236 -0
  128. package/src/components/Radio/Radio.tsx +227 -0
  129. package/src/components/RadioButton/RadioButton.tsx +23 -225
  130. package/src/components/RangeTrack/RangeTrack.tsx +394 -0
  131. package/src/components/SavingsGoalSummary/SavingsGoalSummary.tsx +269 -0
  132. package/src/components/SegmentedTrack/SegmentedTrack.tsx +268 -0
  133. package/src/components/StatGroup/StatGroup.tsx +169 -0
  134. package/src/components/StatItem/StatItem.tsx +117 -40
  135. package/src/components/StrengthIndicator/StrengthIndicator.tsx +205 -0
  136. package/src/components/SummaryTile/SummaryTile.tsx +251 -0
  137. package/src/components/index.ts +39 -2
  138. package/src/design-tokens/Coin Variables-variables-full.json +1 -1
  139. package/src/icons/registry.ts +1 -1
  140. package/src/utils/index.ts +1 -0
  141. package/src/utils/number-utils.ts +60 -0
@@ -0,0 +1,269 @@
1
+ import React, { useMemo } from 'react'
2
+ import {
3
+ View,
4
+ type StyleProp,
5
+ type ViewStyle,
6
+ type TextStyle,
7
+ } from 'react-native'
8
+ import { getVariableByName } from '../../design-tokens/figma-variables-resolver'
9
+ import { EMPTY_MODES, cloneChildrenWithModes } from '../../utils/react-utils'
10
+ import { formatIndianNumber } from '../../utils/number-utils'
11
+ import Title from '../Title/Title'
12
+ import LinearProgress from '../LinearProgress/LinearProgress'
13
+ import MetricLegendItem from '../MetricLegendItem/MetricLegendItem'
14
+
15
+ /**
16
+ * A single row in the savings-goal legend (current vs. target).
17
+ *
18
+ * `value` is a **numeric amount** (e.g. `240000`). It serves two purposes:
19
+ *
20
+ * 1. Display: rendered on the right side of the row using Indian numeric
21
+ * notation via {@link formatIndianNumber} and prefixed with `currency`
22
+ * (e.g. `240000` → `"₹2.4L"`).
23
+ * 2. Progress derivation: the bar fills to `current.value / target.value`
24
+ * automatically. There is no separate `progress` prop.
25
+ *
26
+ * Pass `value: undefined` to render a label-only row (the underlying
27
+ * {@link MetricLegendItem} hides the right slot in that case).
28
+ */
29
+ export type SavingsGoalSummaryItem = {
30
+ /** Label shown next to the indicator dot (e.g. "Current (4 months)"). */
31
+ label?: React.ReactNode
32
+ /**
33
+ * Numeric amount used for both display formatting and progress derivation.
34
+ * Use `undefined` to render a label-only row.
35
+ */
36
+ value?: number
37
+ /** Override the indicator dot colour. */
38
+ indicatorColor?: string
39
+ }
40
+
41
+ export type SavingsGoalSummaryProps = {
42
+ /**
43
+ * Currency symbol (e.g. `'₹'`, `'$'`) prefixed to every legend value.
44
+ * Defaults to `'₹'`. The symbol is rendered as part of the formatted
45
+ * string — this component does not use `MoneyValue`.
46
+ */
47
+ currency?: string
48
+ /**
49
+ * "Current" row in the legend. The indicator dot defaults to the
50
+ * `LinearProgress` indicator colour. Pass `null` to hide the row.
51
+ *
52
+ * `current.value` (numeric) drives both the displayed amount and — together
53
+ * with `target.value` — the progress bar fill.
54
+ */
55
+ current?: SavingsGoalSummaryItem | null
56
+ /**
57
+ * "Target" / recommended row in the legend. The indicator dot defaults to
58
+ * the `LinearProgress` track colour. Pass `null` to hide the row.
59
+ */
60
+ target?: SavingsGoalSummaryItem | null
61
+ /**
62
+ * Custom legend slot. When provided, replaces the default `current`/`target`
63
+ * rows entirely — pass any number of `MetricLegendItem`s (or any other
64
+ * nodes) to fully control the legend.
65
+ *
66
+ * Note: the progress bar is still derived from `current.value` / `target.value`,
67
+ * so pass them even when overriding the legend if you want a non-zero bar.
68
+ */
69
+ children?: React.ReactNode
70
+ /**
71
+ * Design token modes for theming. Defaults to `{ 'LinearProgress Size': 'L' }`
72
+ * which renders the thicker progress bar from the Figma reference. Caller
73
+ * modes are merged on top and can override every default key.
74
+ */
75
+ modes?: Record<string, any>
76
+ /** Override container styles. */
77
+ style?: StyleProp<ViewStyle>
78
+ /**
79
+ * Override styles for the auto-generated percentage text. Useful for
80
+ * tweaking colour or alignment; the value (e.g. `"50%"`) is always
81
+ * computed from `current` / `target` and cannot be replaced.
82
+ */
83
+ titleStyle?: StyleProp<TextStyle>
84
+ /** Override the inner legend container styles. */
85
+ legendStyle?: StyleProp<ViewStyle>
86
+ }
87
+
88
+ const DEFAULT_LEGEND_PADDING = 8
89
+
90
+ const DEFAULT_MODES: Readonly<Record<string, any>> = Object.freeze({
91
+ 'LinearProgress Size': 'L',
92
+ })
93
+
94
+ const DEFAULT_CURRENT: SavingsGoalSummaryItem = {
95
+ label: 'Current (4 months)',
96
+ value: 240000,
97
+ }
98
+
99
+ const DEFAULT_TARGET: SavingsGoalSummaryItem = {
100
+ label: 'Recommended (8 months)',
101
+ value: 480000,
102
+ }
103
+
104
+ /**
105
+ * `SavingsGoalSummary` visualises progress toward a savings goal as:
106
+ *
107
+ * 1. A `Title` showing the percentage — **computed automatically** from
108
+ * `current.value / target.value`. There is no `progress` prop; the
109
+ * component owns the calculation so the title, bar and legend are always
110
+ * in sync.
111
+ * 2. A `LinearProgress` bar driven by the same derived ratio.
112
+ * 3. A two-row legend comparing **current** vs. **target**, where each numeric
113
+ * `value` is auto-formatted with Indian notation
114
+ * ({@link formatIndianNumber}) and prefixed with the `currency` symbol.
115
+ *
116
+ * The component is intentionally narrow in scope — it is the body of a savings
117
+ * insight card. Wrap it in `CardInsight` (or any container of your choice) to
118
+ * add a heading, badge or footer.
119
+ *
120
+ * @component
121
+ * @param {SavingsGoalSummaryProps} props
122
+ */
123
+ function SavingsGoalSummary({
124
+ currency = '₹',
125
+ current = DEFAULT_CURRENT,
126
+ target = DEFAULT_TARGET,
127
+ children,
128
+ modes = EMPTY_MODES,
129
+ style,
130
+ titleStyle,
131
+ legendStyle,
132
+ }: SavingsGoalSummaryProps) {
133
+ // Merge caller modes on top of the defaults so callers can override
134
+ // (e.g. switch to `LinearProgress Size: M`) while still receiving the
135
+ // sensible component-level default.
136
+ const mergedModes = useMemo(
137
+ () => (modes === EMPTY_MODES ? DEFAULT_MODES : { ...DEFAULT_MODES, ...modes }),
138
+ [modes],
139
+ )
140
+
141
+ // Resolve the `LinearProgress` track / indicator colours so the legend
142
+ // dots automatically stay in sync with the progress bar without callers
143
+ // needing to plumb through `indicatorColor`.
144
+ //
145
+ // The token names AND the merge strategy must match `LinearProgress.tsx`
146
+ // exactly, otherwise the dot colours can drift from the bar:
147
+ // • Token aliases live in the `Emphasis` collection (modes High|Medium|Low),
148
+ // NOT `Emphasis / DataViz` — passing the wrong mode key would collapse
149
+ // both dots to the same default-mode colour.
150
+ // • Defaults are placed *before* `mergedModes` is spread, so callers can
151
+ // still override `Emphasis` via the `modes` prop (matches
152
+ // `LinearProgress`'s philosophy).
153
+ const indicatorColorFromTokens =
154
+ (getVariableByName('linearProgress/indicator/background', {
155
+ Emphasis: 'High',
156
+ ...mergedModes,
157
+ }) as string | null) ?? '#5d00b5'
158
+ const trackColorFromTokens =
159
+ (getVariableByName('linearProgress/track/background', {
160
+ Emphasis: 'Low',
161
+ ...mergedModes,
162
+ }) as string | null) ?? '#ede7ff'
163
+
164
+ // Single source of truth for the bar fill, the title percentage and the
165
+ // formatted legend amounts. There is intentionally no consumer-facing
166
+ // `progress` prop — the only way to change the bar is to change the
167
+ // numeric `current` / `target` values. This keeps the three views (title,
168
+ // bar, legend) impossible to desynchronise.
169
+ const resolvedProgress = useMemo(() => {
170
+ const cv = current?.value
171
+ const tv = target?.value
172
+ if (typeof cv !== 'number' || typeof tv !== 'number' || tv <= 0) {
173
+ return 0
174
+ }
175
+ return Math.min(Math.max(cv / tv, 0), 1)
176
+ }, [current, target])
177
+
178
+ const percentageLabel = `${Math.round(resolvedProgress * 100)}%`
179
+
180
+ const gap = (getVariableByName('savingsGoalSummary/gap', mergedModes) as number | null) ?? 23
181
+ const legendGap =
182
+ (getVariableByName('savingsGoalSummary/legend/gap', mergedModes) as number | null) ?? 16
183
+
184
+ const customLegend = children
185
+ ? cloneChildrenWithModes(children, mergedModes)
186
+ : null
187
+
188
+ const defaultLegend = !customLegend && (current || target) ? (
189
+ <>
190
+ {current && (
191
+ <MetricLegendItem
192
+ modes={mergedModes}
193
+ label={current.label}
194
+ value={formatLegendValue(current.value, currency)}
195
+ indicatorColor={current.indicatorColor ?? indicatorColorFromTokens}
196
+ />
197
+ )}
198
+ {target && (
199
+ <MetricLegendItem
200
+ modes={mergedModes}
201
+ label={target.label}
202
+ value={formatLegendValue(target.value, currency)}
203
+ indicatorColor={target.indicatorColor ?? trackColorFromTokens}
204
+ />
205
+ )}
206
+ </>
207
+ ) : null
208
+
209
+ const legendNode = customLegend ?? defaultLegend
210
+ const showLegend = legendNode != null
211
+
212
+ return (
213
+ <View
214
+ style={[
215
+ {
216
+ width: '100%',
217
+ gap,
218
+ alignItems: 'stretch',
219
+ },
220
+ style,
221
+ ]}
222
+ accessibilityLabel={`Savings goal progress, ${percentageLabel}`}
223
+ >
224
+ <Title
225
+ title={percentageLabel}
226
+ modes={mergedModes}
227
+ style={TITLE_CONTAINER_STYLE}
228
+ textStyle={titleStyle}
229
+ />
230
+
231
+ <LinearProgress value={resolvedProgress} modes={mergedModes} />
232
+
233
+ {showLegend && (
234
+ <View
235
+ style={[
236
+ {
237
+ width: '100%',
238
+ padding: DEFAULT_LEGEND_PADDING,
239
+ gap: legendGap,
240
+ alignItems: 'stretch',
241
+ },
242
+ legendStyle,
243
+ ]}
244
+ >
245
+ {legendNode}
246
+ </View>
247
+ )}
248
+ </View>
249
+ )
250
+ }
251
+
252
+ /**
253
+ * Format a single legend `value` for display. Returns `undefined` when the
254
+ * value is missing so the underlying {@link MetricLegendItem} hides the right
255
+ * slot (matches the Figma `data` toggle = off).
256
+ */
257
+ function formatLegendValue(value: number | undefined, currency: string): string | undefined {
258
+ if (typeof value !== 'number') return undefined
259
+ return formatIndianNumber(value, { prefix: currency })
260
+ }
261
+
262
+ // Neutralise the `Title` component's default page-level padding so it sits
263
+ // flush inside the summary card (the parent container owns spacing via `gap`).
264
+ const TITLE_CONTAINER_STYLE: ViewStyle = {
265
+ paddingHorizontal: 0,
266
+ paddingVertical: 0,
267
+ }
268
+
269
+ export default SavingsGoalSummary
@@ -0,0 +1,268 @@
1
+ import React from 'react'
2
+ import {
3
+ View,
4
+ type StyleProp,
5
+ type ViewStyle,
6
+ } from 'react-native'
7
+ import { getVariableByName } from '../../design-tokens/figma-variables-resolver'
8
+ import { useTokens } from '../../design-tokens/JFSThemeProvider'
9
+ import { EMPTY_MODES, flattenChildren } from '../../utils/react-utils'
10
+
11
+ /**
12
+ * Per-segment data definition for the data-driven `segments` prop.
13
+ *
14
+ * Use `value` for proportional widths (segments share width by their value
15
+ * relative to the sum). When `value` is omitted, segments share the row
16
+ * equally (`flex: 1`).
17
+ *
18
+ * Use `modes` to override the per-segment design-token mode — typically the
19
+ * `Appearance / DataViz` mode for color theming, or `Emphasis / DataViz` to
20
+ * change the emphasis level. The parent already injects per-index defaults
21
+ * (segment 0 = High, 1 = Medium, 2 = Low, then cycling) so callers only need
22
+ * to pass `modes` when they want a different result.
23
+ */
24
+ export type SegmentedTrackSegmentData = {
25
+ /** Stable React key. */
26
+ key?: React.Key
27
+ /**
28
+ * Optional explicit weight used for proportional width (`flex: value`).
29
+ * When omitted, the segment uses an equal share of the available row.
30
+ * Mixing values and undefined is supported — undefined falls back to 1.
31
+ */
32
+ value?: number
33
+ /**
34
+ * Hard-override the segment color. Bypasses `dataViz/bg` token resolution
35
+ * entirely.
36
+ */
37
+ color?: string
38
+ /**
39
+ * Per-segment design token mode overrides. Merged on top of the parent
40
+ * `modes` and the per-index Emphasis defaults.
41
+ */
42
+ modes?: Record<string, any>
43
+ /** Override individual segment styles. */
44
+ style?: StyleProp<ViewStyle>
45
+ /** Per-segment accessibility label. */
46
+ accessibilityLabel?: string
47
+ }
48
+
49
+ export type SegmentedTrackProps = {
50
+ /**
51
+ * Data-driven segment list. Used when no `children` slot is provided.
52
+ * Defaults to three equal segments which receive per-index Emphasis
53
+ * defaults (`High`, `Medium`, `Low`).
54
+ */
55
+ segments?: SegmentedTrackSegmentData[]
56
+ /**
57
+ * Slot for fully custom segment children. Each top-level child is treated
58
+ * as one segment. The parent injects per-index Emphasis defaults and the
59
+ * shared `modes`, while child-level `modes` overrides win.
60
+ */
61
+ children?: React.ReactNode
62
+ /** Design token modes for theming (e.g. `{ 'Color Mode': 'Light' }`). */
63
+ modes?: Record<string, any>
64
+ /** Override the container styles. */
65
+ style?: StyleProp<ViewStyle>
66
+ /** Style applied to every segment (data-driven mode only). */
67
+ segmentStyle?: StyleProp<ViewStyle>
68
+ /** Accessibility label announced for the whole distribution row. */
69
+ accessibilityLabel?: string
70
+ }
71
+
72
+ type SegmentedTrackSegmentProps = {
73
+ /**
74
+ * Optional explicit weight used for proportional width (`flex: value`).
75
+ * Defaults to 1 (equal share within the parent row).
76
+ */
77
+ value?: number | undefined
78
+ /**
79
+ * Hard-override the segment color. Bypasses `dataViz/bg` token resolution.
80
+ */
81
+ color?: string | undefined
82
+ /**
83
+ * Design token modes for the segment. Merged with parent `modes` and the
84
+ * per-index Emphasis defaults injected by the parent `SegmentedTrack`.
85
+ */
86
+ modes?: Record<string, any> | undefined
87
+ /** Override the segment styles. */
88
+ style?: StyleProp<ViewStyle> | undefined
89
+ /** Per-segment accessibility label. */
90
+ accessibilityLabel?: string | undefined
91
+ }
92
+
93
+ /**
94
+ * Default per-index Emphasis modes applied to every segment when the caller
95
+ * does not provide its own `Emphasis / DataViz` override. Cycles for >3
96
+ * segments so additional segments fall back to the same High/Medium/Low
97
+ * rotation.
98
+ */
99
+ const DEFAULT_EMPHASIS_CYCLE = ['High', 'Medium', 'Low'] as const
100
+
101
+ const DEFAULT_SEGMENTS: SegmentedTrackSegmentData[] = [
102
+ {},
103
+ {},
104
+ {},
105
+ ]
106
+
107
+ /**
108
+ * Compute the default `Emphasis / DataViz` mode for a segment at `index`.
109
+ * Cycles through {@link DEFAULT_EMPHASIS_CYCLE} so any number of segments
110
+ * gets a sensible default.
111
+ */
112
+ function defaultEmphasisFor(index: number) {
113
+ return DEFAULT_EMPHASIS_CYCLE[index % DEFAULT_EMPHASIS_CYCLE.length]
114
+ }
115
+
116
+ function SegmentedTrackSegment({
117
+ value = 1,
118
+ color,
119
+ modes = EMPTY_MODES,
120
+ style,
121
+ accessibilityLabel,
122
+ }: SegmentedTrackSegmentProps) {
123
+ const resolvedColor =
124
+ color ?? ((getVariableByName('dataViz/bg', modes) as string | null) ?? '#5d00b5')
125
+
126
+ return (
127
+ <View
128
+ accessibilityLabel={accessibilityLabel}
129
+ style={[
130
+ {
131
+ flex: value,
132
+ minWidth: 1,
133
+ height: '100%',
134
+ backgroundColor: resolvedColor,
135
+ },
136
+ style,
137
+ ]}
138
+ />
139
+ )
140
+ }
141
+
142
+ /**
143
+ * `SegmentedTrack` renders a horizontal pill-shaped row of categorical
144
+ * segments. Use it for distribution / share-of breakdowns where each
145
+ * segment is a sibling category (not a directional or temporal progress).
146
+ *
147
+ * Defaults to three equal segments tinted at descending Emphasis levels
148
+ * (`High`, `Medium`, `Low`) so the shape reads as a single concept split
149
+ * three ways. Consumers can either pass the data-driven `segments` prop or
150
+ * a fully custom `children` slot of `SegmentedTrack.Segment`s.
151
+ *
152
+ * Each segment resolves its color through the `dataViz/bg` token, which
153
+ * cascades through `Emphasis / DataViz` and `Appearance / DataViz`. Pass
154
+ * `modes` per segment (or override `Appearance / DataViz` at the parent
155
+ * level via `modes`) to retheme the row without touching colors directly.
156
+ *
157
+ * @component
158
+ * @param {SegmentedTrackProps} props
159
+ */
160
+ function SegmentedTrack({
161
+ segments,
162
+ children,
163
+ modes: propModes = EMPTY_MODES,
164
+ style,
165
+ segmentStyle,
166
+ accessibilityLabel,
167
+ }: SegmentedTrackProps) {
168
+ const { modes: globalModes } = useTokens()
169
+ const modes = { ...globalModes, ...propModes }
170
+
171
+ const trackHeight =
172
+ (getVariableByName('segmentedTrack/height', modes) as number | null) ?? 24
173
+ const trackRadius =
174
+ (getVariableByName('segmentedTrack/radius', modes) as number | null) ?? 999
175
+
176
+ const renderedSegments = renderSegments({
177
+ segments,
178
+ children,
179
+ modes,
180
+ segmentStyle,
181
+ })
182
+
183
+ return (
184
+ <View
185
+ accessibilityRole="image"
186
+ accessibilityLabel={accessibilityLabel}
187
+ style={[
188
+ {
189
+ flexDirection: 'row',
190
+ alignItems: 'stretch',
191
+ height: trackHeight,
192
+ borderRadius: trackRadius,
193
+ overflow: 'hidden',
194
+ width: '100%',
195
+ backgroundColor: 'transparent',
196
+ },
197
+ style,
198
+ ]}
199
+ >
200
+ {renderedSegments}
201
+ </View>
202
+ )
203
+ }
204
+
205
+ /**
206
+ * Build the slot children. When the caller passes JSX `children`, every
207
+ * top-level element is treated as one segment and receives merged `modes`
208
+ * (parent + per-index Emphasis default + the child's own `modes` taking
209
+ * priority). Otherwise the data-driven `segments` array is rendered.
210
+ */
211
+ function renderSegments({
212
+ segments,
213
+ children,
214
+ modes,
215
+ segmentStyle,
216
+ }: {
217
+ segments: SegmentedTrackSegmentData[] | undefined
218
+ children: React.ReactNode | undefined
219
+ modes: Record<string, any>
220
+ segmentStyle: StyleProp<ViewStyle> | undefined
221
+ }): React.ReactNode[] {
222
+ if (children !== undefined && children !== null) {
223
+ const flat = flattenChildren(children)
224
+ return flat.map((child, index) => {
225
+ if (!React.isValidElement(child)) {
226
+ return child
227
+ }
228
+ const childProps = (child.props as any) ?? {}
229
+ const childModes = childProps.modes
230
+ const mergedModes = {
231
+ ...modes,
232
+ 'Emphasis / DataViz': defaultEmphasisFor(index),
233
+ ...(childModes || {}),
234
+ }
235
+ return React.cloneElement(child, {
236
+ ...childProps,
237
+ modes: mergedModes,
238
+ key: child.key ?? `segment-${index}`,
239
+ })
240
+ })
241
+ }
242
+
243
+ const list = segments && segments.length > 0 ? segments : DEFAULT_SEGMENTS
244
+ return list.map((segment, index) => {
245
+ const segmentModes = {
246
+ ...modes,
247
+ 'Emphasis / DataViz': defaultEmphasisFor(index),
248
+ ...(segment.modes || {}),
249
+ }
250
+ return (
251
+ <SegmentedTrackSegment
252
+ key={segment.key ?? `segment-${index}`}
253
+ value={segment.value ?? 1}
254
+ color={segment.color}
255
+ modes={segmentModes}
256
+ style={[segmentStyle, segment.style]}
257
+ accessibilityLabel={segment.accessibilityLabel}
258
+ />
259
+ )
260
+ })
261
+ }
262
+
263
+ SegmentedTrack.Segment = SegmentedTrackSegment
264
+
265
+ export { SegmentedTrackSegment }
266
+ export type { SegmentedTrackSegmentProps }
267
+
268
+ export default SegmentedTrack
@@ -0,0 +1,169 @@
1
+ import React from 'react'
2
+ import { View, type StyleProp, type ViewStyle } from 'react-native'
3
+ import { getVariableByName } from '../../design-tokens/figma-variables-resolver'
4
+ import {
5
+ EMPTY_MODES,
6
+ cloneChildrenWithModes,
7
+ flattenChildren,
8
+ } from '../../utils/react-utils'
9
+ import StatItem from '../StatItem/StatItem'
10
+ import Divider from '../Divider/Divider'
11
+
12
+ export type StatGroupItem = {
13
+ /** Stable key for the item. Falls back to the label / index. */
14
+ key?: React.Key
15
+ /** The descriptive label shown beneath the value. */
16
+ label?: string
17
+ /** The prominent value shown above the label. */
18
+ value?: string
19
+ }
20
+
21
+ export type StatGroupProps = {
22
+ /**
23
+ * Array of stat items. Each item is rendered as a centered `StatItem`
24
+ * (`labelPosition="Bottom"`) with vertical dividers between them.
25
+ *
26
+ * Ignored when a `children` slot is provided.
27
+ */
28
+ items?: StatGroupItem[]
29
+ /**
30
+ * Custom slot content. When provided, the `items` prop is ignored. Each
31
+ * top-level child is wrapped to take an equal share of the available width
32
+ * and a vertical `Divider` is auto-inserted between siblings — matching the
33
+ * Figma `slot` behaviour. `modes` are propagated to all children.
34
+ */
35
+ children?: React.ReactNode
36
+ /** Design token modes for theming (e.g. `{ 'Color Mode': 'Light' }`). */
37
+ modes?: Record<string, any>
38
+ /** Override container styles. */
39
+ style?: StyleProp<ViewStyle>
40
+ }
41
+
42
+ const DEFAULT_ITEMS: StatGroupItem[] = [
43
+ { label: 'Updates', value: 'Daily' },
44
+ { label: 'Data range', value: '24 months' },
45
+ { label: 'Validity', value: '24 months' },
46
+ { label: 'Stored for', value: '1 month' },
47
+ ]
48
+
49
+ /**
50
+ * StatGroup renders a card-style container holding a horizontal row of
51
+ * `StatItem`s separated by vertical dividers. It is typically used to surface
52
+ * 3–5 short metrics (e.g. validity, data range, storage) at a glance.
53
+ *
54
+ * Pass `items` for the simple data-driven case, or use the `children` slot
55
+ * for full control over the row contents (the component still auto-inserts
56
+ * vertical dividers between top-level children).
57
+ *
58
+ * @component
59
+ * @param {StatGroupProps} props
60
+ */
61
+ function StatGroup({
62
+ items,
63
+ children,
64
+ modes = EMPTY_MODES,
65
+ style,
66
+ }: StatGroupProps) {
67
+ const background =
68
+ (getVariableByName('statGroup/background', modes) as string | null) ?? '#ffffff'
69
+ const strokeColor =
70
+ (getVariableByName('statGroup/stroke/color', modes) as string | null) ?? '#ebebed'
71
+ const strokeSize =
72
+ (getVariableByName('statGroup/stroke/size', modes) as number | null) ?? 1
73
+ const radius =
74
+ (getVariableByName('statGroup/radius', modes) as number | null) ?? 12
75
+ const paddingTop =
76
+ (getVariableByName('statGroup/padding/top', modes) as number | null) ?? 16
77
+ const paddingRight =
78
+ (getVariableByName('statGroup/padding/right', modes) as number | null) ?? 0
79
+ const paddingBottom =
80
+ (getVariableByName('statGroup/padding/bottom', modes) as number | null) ?? 12
81
+ const paddingLeft =
82
+ (getVariableByName('statGroup/padding/left', modes) as number | null) ?? 0
83
+
84
+ const containerStyle: ViewStyle = {
85
+ backgroundColor: background,
86
+ borderColor: strokeColor,
87
+ borderWidth: strokeSize,
88
+ borderStyle: 'solid',
89
+ borderRadius: radius,
90
+ paddingTop,
91
+ paddingRight,
92
+ paddingBottom,
93
+ paddingLeft,
94
+ overflow: 'hidden',
95
+ }
96
+
97
+ const slotChildren = renderSlotChildren({ items, children, modes })
98
+
99
+ return (
100
+ <View style={[containerStyle, style]} accessibilityRole="summary">
101
+ <View
102
+ style={{
103
+ flexDirection: 'row',
104
+ alignItems: 'stretch',
105
+ width: '100%',
106
+ }}
107
+ >
108
+ {slotChildren}
109
+ </View>
110
+ </View>
111
+ )
112
+ }
113
+
114
+ /**
115
+ * Build the row of items: render either the supplied children or the
116
+ * `items` array, wrap each entry so it grows equally, and inject a vertical
117
+ * `Divider` between siblings.
118
+ */
119
+ function renderSlotChildren({
120
+ items,
121
+ children,
122
+ modes,
123
+ }: {
124
+ items?: StatGroupItem[]
125
+ children?: React.ReactNode
126
+ modes: Record<string, any>
127
+ }): React.ReactNode[] {
128
+ let nodes: React.ReactNode[]
129
+
130
+ if (children !== undefined && children !== null) {
131
+ const cloned = cloneChildrenWithModes(children, modes)
132
+ nodes = flattenChildren(cloned)
133
+ } else {
134
+ const list = items && items.length > 0 ? items : DEFAULT_ITEMS
135
+ nodes = list.map((item, index) => (
136
+ <StatItem
137
+ key={item.key ?? `${item.label ?? 'item'}-${index}`}
138
+ label={item.label}
139
+ value={item.value}
140
+ labelPosition="Bottom"
141
+ modes={modes}
142
+ />
143
+ ))
144
+ }
145
+
146
+ const result: React.ReactNode[] = []
147
+ nodes.forEach((node, index) => {
148
+ if (index > 0) {
149
+ result.push(
150
+ <Divider
151
+ key={`divider-${index}`}
152
+ direction="vertical"
153
+ modes={modes}
154
+ />
155
+ )
156
+ }
157
+ result.push(
158
+ <View
159
+ key={`slot-${index}`}
160
+ style={{ flex: 1, minWidth: 0, alignSelf: 'center' }}
161
+ >
162
+ {node}
163
+ </View>
164
+ )
165
+ })
166
+ return result
167
+ }
168
+
169
+ export default StatGroup