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,256 @@
|
|
|
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 { useTokens } from '../../design-tokens/JFSThemeProvider'
|
|
5
|
+
import { EMPTY_MODES } from '../../utils/react-utils'
|
|
6
|
+
import DonutChart, { type DonutChartSegmentData } from '../DonutChart/DonutChart'
|
|
7
|
+
import MetricLegendItem from '../MetricLegendItem/MetricLegendItem'
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* One row of the `DonutChartSummary`. Each item drives BOTH a donut
|
|
11
|
+
* segment and the matching legend row, so the segment and indicator
|
|
12
|
+
* always share the same color by construction.
|
|
13
|
+
*/
|
|
14
|
+
export type DonutChartSummaryItem = {
|
|
15
|
+
/** Stable React key. Falls back to the item label / index. */
|
|
16
|
+
key?: React.Key
|
|
17
|
+
/** The descriptive label rendered next to the indicator dot. */
|
|
18
|
+
label?: React.ReactNode
|
|
19
|
+
/**
|
|
20
|
+
* The data point — drives the segment's angular share. Same
|
|
21
|
+
* semantics as `DonutChartSegmentData.value`. When the legend's
|
|
22
|
+
* right-side text is shown, the resolution order is:
|
|
23
|
+
* `displayValue` → `formatValue(value)` → hide.
|
|
24
|
+
*/
|
|
25
|
+
value: number
|
|
26
|
+
/**
|
|
27
|
+
* Optional override for the legend row's right-side text. Falls
|
|
28
|
+
* back to `formatValue(value)` if a parent-level `formatValue` is
|
|
29
|
+
* provided; otherwise the value slot is hidden (matches the Figma
|
|
30
|
+
* `data` boolean toggle on `MetricLegendItem`). Pass `null` or
|
|
31
|
+
* `false` to explicitly hide on a per-item basis.
|
|
32
|
+
*/
|
|
33
|
+
displayValue?: React.ReactNode
|
|
34
|
+
/**
|
|
35
|
+
* Hard-override the shared color used for both the donut segment
|
|
36
|
+
* and the legend indicator. Bypasses `dataViz/bg` token resolution.
|
|
37
|
+
*/
|
|
38
|
+
color?: string
|
|
39
|
+
/**
|
|
40
|
+
* Per-item design token mode overrides. Merged on top of parent
|
|
41
|
+
* `modes` and the per-index `Appearance / DataViz` defaults
|
|
42
|
+
* (`Senary`, `Primary`, `Secondary`, `Tertiary`, `Quaternary`,
|
|
43
|
+
* `Quinary`, then cycles).
|
|
44
|
+
*/
|
|
45
|
+
modes?: Record<string, any>
|
|
46
|
+
/** Accessibility label for the segment + legend row pairing. */
|
|
47
|
+
accessibilityLabel?: string
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export type DonutChartSummaryProps = {
|
|
51
|
+
/**
|
|
52
|
+
* Data-driven rows. Each entry produces a donut segment AND a
|
|
53
|
+
* matching `MetricLegendItem` — the count of legend rows is locked
|
|
54
|
+
* in step with the count of donut segments by construction.
|
|
55
|
+
*/
|
|
56
|
+
items?: DonutChartSummaryItem[]
|
|
57
|
+
/**
|
|
58
|
+
* Optional formatter applied to each item's numeric `value` when
|
|
59
|
+
* the item does not provide an explicit `displayValue`. Useful for
|
|
60
|
+
* the common "format every weight the same way" case
|
|
61
|
+
* (e.g. `(v) => `${v}%``).
|
|
62
|
+
*/
|
|
63
|
+
formatValue?: (value: number) => React.ReactNode
|
|
64
|
+
/** Center value text inside the donut (large/bold). */
|
|
65
|
+
centerValue?: React.ReactNode
|
|
66
|
+
/** Center label text inside the donut (smaller, beneath the value). */
|
|
67
|
+
centerLabel?: React.ReactNode
|
|
68
|
+
/**
|
|
69
|
+
* Slot for fully-custom donut center content. When provided it
|
|
70
|
+
* replaces the default `centerValue`/`centerLabel` text wrap.
|
|
71
|
+
*/
|
|
72
|
+
donutCenter?: React.ReactNode
|
|
73
|
+
/** Outer donut diameter in px. Defaults to 194 (Figma reference). */
|
|
74
|
+
donutSize?: number
|
|
75
|
+
/** Donut ring stroke width in px. Defaults to ~18% of `donutSize`. */
|
|
76
|
+
donutStrokeWidth?: number
|
|
77
|
+
/**
|
|
78
|
+
* Visual gap between adjacent donut segments expressed in degrees
|
|
79
|
+
* of arc. Defaults to 0 (segments touch).
|
|
80
|
+
*/
|
|
81
|
+
donutGap?: number
|
|
82
|
+
/** Design token modes for theming (e.g. `{ 'Color Mode': 'Light' }`). */
|
|
83
|
+
modes?: Record<string, any>
|
|
84
|
+
/** Override outer container styles. */
|
|
85
|
+
style?: StyleProp<ViewStyle>
|
|
86
|
+
/** Override the legend container styles. */
|
|
87
|
+
legendStyle?: StyleProp<ViewStyle>
|
|
88
|
+
/** Accessibility label announced for the whole summary. */
|
|
89
|
+
accessibilityLabel?: string
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
const DEFAULT_APPEARANCE_CYCLE = [
|
|
93
|
+
'Senary',
|
|
94
|
+
'Primary',
|
|
95
|
+
'Secondary',
|
|
96
|
+
'Tertiary',
|
|
97
|
+
'Quaternary',
|
|
98
|
+
'Quinary',
|
|
99
|
+
] as const
|
|
100
|
+
|
|
101
|
+
const DEFAULT_ITEMS: DonutChartSummaryItem[] = [
|
|
102
|
+
{ label: 'Equity', value: 40, displayValue: '40%' },
|
|
103
|
+
{ label: 'Recommended coverage', value: 25, displayValue: '25%' },
|
|
104
|
+
{ label: 'Additional benefits', value: 20, displayValue: '20%' },
|
|
105
|
+
{ label: 'Cost analysis', value: 15, displayValue: '15%' },
|
|
106
|
+
]
|
|
107
|
+
|
|
108
|
+
const defaultAppearanceFor = (index: number) =>
|
|
109
|
+
DEFAULT_APPEARANCE_CYCLE[index % DEFAULT_APPEARANCE_CYCLE.length]
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* Resolve the shared color for an item. Honors any explicit `color`
|
|
113
|
+
* override, then falls back to `dataViz/bg` for the merged mode set,
|
|
114
|
+
* then to the Figma reference purple.
|
|
115
|
+
*/
|
|
116
|
+
function resolveItemColor(
|
|
117
|
+
parentModes: Record<string, any>,
|
|
118
|
+
item: DonutChartSummaryItem,
|
|
119
|
+
index: number
|
|
120
|
+
): string {
|
|
121
|
+
if (item.color) return item.color
|
|
122
|
+
const itemModes = {
|
|
123
|
+
...parentModes,
|
|
124
|
+
'Appearance / DataViz': defaultAppearanceFor(index),
|
|
125
|
+
...(item.modes || {}),
|
|
126
|
+
}
|
|
127
|
+
return (
|
|
128
|
+
(getVariableByName('dataViz/bg', itemModes) as string | null) ?? '#5d00b5'
|
|
129
|
+
)
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* `DonutChartSummary` pairs a `DonutChart` with a vertical list of
|
|
134
|
+
* `MetricLegendItem` rows. The component takes a single `items` array,
|
|
135
|
+
* so the number of legend rows is locked in step with the number of
|
|
136
|
+
* donut segments by construction — every segment has exactly one
|
|
137
|
+
* legend row, and they share the same color through the same
|
|
138
|
+
* `Appearance / DataViz` cascade as the standalone `DonutChart`.
|
|
139
|
+
*
|
|
140
|
+
* The default 4-item layout receives per-index `Appearance / DataViz`
|
|
141
|
+
* defaults (item 1 → `Senary`, 2 → `Primary`, 3 → `Secondary`, 4 →
|
|
142
|
+
* `Tertiary`, then cycles). Override `modes` per item to remix, or set
|
|
143
|
+
* `Emphasis / DataViz` on the parent `modes` to dim or brighten the
|
|
144
|
+
* whole component at once.
|
|
145
|
+
*
|
|
146
|
+
* @component
|
|
147
|
+
* @param {DonutChartSummaryProps} props
|
|
148
|
+
*/
|
|
149
|
+
function DonutChartSummary({
|
|
150
|
+
items,
|
|
151
|
+
formatValue,
|
|
152
|
+
centerValue = '₹51,230',
|
|
153
|
+
centerLabel = 'Total invested',
|
|
154
|
+
donutCenter,
|
|
155
|
+
donutSize = 194,
|
|
156
|
+
donutStrokeWidth,
|
|
157
|
+
donutGap = 0,
|
|
158
|
+
modes: propModes = EMPTY_MODES,
|
|
159
|
+
style,
|
|
160
|
+
legendStyle,
|
|
161
|
+
accessibilityLabel,
|
|
162
|
+
}: DonutChartSummaryProps) {
|
|
163
|
+
const { modes: globalModes } = useTokens()
|
|
164
|
+
const modes = { ...globalModes, ...propModes }
|
|
165
|
+
|
|
166
|
+
const gap =
|
|
167
|
+
(getVariableByName('donutChartSummary/gap', modes) as number | null) ?? 16
|
|
168
|
+
const legendGap =
|
|
169
|
+
(getVariableByName('donutChartSummary/legend/gap', modes) as
|
|
170
|
+
| number
|
|
171
|
+
| null) ?? 8
|
|
172
|
+
|
|
173
|
+
const resolvedItems = items && items.length > 0 ? items : DEFAULT_ITEMS
|
|
174
|
+
|
|
175
|
+
const segments: DonutChartSegmentData[] = resolvedItems.map(
|
|
176
|
+
(item, index) => ({
|
|
177
|
+
key: item.key ?? `segment-${index}`,
|
|
178
|
+
value: item.value,
|
|
179
|
+
color: resolveItemColor(modes, item, index),
|
|
180
|
+
accessibilityLabel: item.accessibilityLabel,
|
|
181
|
+
})
|
|
182
|
+
)
|
|
183
|
+
|
|
184
|
+
const showCustomCenter = donutCenter !== undefined && donutCenter !== null
|
|
185
|
+
|
|
186
|
+
return (
|
|
187
|
+
<View
|
|
188
|
+
accessibilityRole="summary"
|
|
189
|
+
accessibilityLabel={accessibilityLabel}
|
|
190
|
+
style={[
|
|
191
|
+
{
|
|
192
|
+
width: '100%',
|
|
193
|
+
alignItems: 'center',
|
|
194
|
+
gap,
|
|
195
|
+
},
|
|
196
|
+
style,
|
|
197
|
+
]}
|
|
198
|
+
>
|
|
199
|
+
<DonutChart
|
|
200
|
+
size={donutSize}
|
|
201
|
+
{...(donutStrokeWidth !== undefined && {
|
|
202
|
+
strokeWidth: donutStrokeWidth,
|
|
203
|
+
})}
|
|
204
|
+
gap={donutGap}
|
|
205
|
+
segments={segments}
|
|
206
|
+
modes={modes}
|
|
207
|
+
{...(!showCustomCenter && {
|
|
208
|
+
value: centerValue,
|
|
209
|
+
label: centerLabel,
|
|
210
|
+
})}
|
|
211
|
+
>
|
|
212
|
+
{showCustomCenter ? donutCenter : null}
|
|
213
|
+
</DonutChart>
|
|
214
|
+
|
|
215
|
+
<View
|
|
216
|
+
style={[
|
|
217
|
+
{
|
|
218
|
+
width: '100%',
|
|
219
|
+
gap: legendGap,
|
|
220
|
+
},
|
|
221
|
+
legendStyle,
|
|
222
|
+
]}
|
|
223
|
+
>
|
|
224
|
+
{resolvedItems.map((item, index) => (
|
|
225
|
+
<MetricLegendItem
|
|
226
|
+
key={item.key ?? `legend-${index}`}
|
|
227
|
+
label={item.label}
|
|
228
|
+
value={resolveLegendValue(item, formatValue)}
|
|
229
|
+
indicatorColor={resolveItemColor(modes, item, index)}
|
|
230
|
+
modes={modes}
|
|
231
|
+
/>
|
|
232
|
+
))}
|
|
233
|
+
</View>
|
|
234
|
+
</View>
|
|
235
|
+
)
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
/**
|
|
239
|
+
* Resolve what to render in the legend row's right-side slot. The
|
|
240
|
+
* order of precedence is:
|
|
241
|
+
* 1. `item.displayValue` if explicitly provided (including `null` /
|
|
242
|
+
* `false`, which the underlying `MetricLegendItem` treats as
|
|
243
|
+
* "hide the value slot").
|
|
244
|
+
* 2. `formatValue(item.value)` when a parent-level formatter exists.
|
|
245
|
+
* 3. `undefined` — the value slot is hidden.
|
|
246
|
+
*/
|
|
247
|
+
function resolveLegendValue(
|
|
248
|
+
item: DonutChartSummaryItem,
|
|
249
|
+
formatValue: ((value: number) => React.ReactNode) | undefined
|
|
250
|
+
): React.ReactNode {
|
|
251
|
+
if (item.displayValue !== undefined) return item.displayValue
|
|
252
|
+
if (formatValue) return formatValue(item.value)
|
|
253
|
+
return undefined
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
export default DonutChartSummary
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import React from 'react'
|
|
2
|
-
import { View, Text, type StyleProp, type ViewStyle, type TextStyle
|
|
2
|
+
import { View, Text, type StyleProp, type ViewStyle, type TextStyle } from 'react-native'
|
|
3
3
|
import { getVariableByName } from '../../design-tokens/figma-variables-resolver'
|
|
4
4
|
import { EMPTY_MODES } from '../../utils/react-utils'
|
|
5
5
|
import MoneyValue from '../MoneyValue/MoneyValue'
|
|
6
|
+
import LinearProgress from '../LinearProgress/LinearProgress'
|
|
6
7
|
|
|
7
8
|
type LinearMeterLabelProps = {
|
|
8
9
|
children: React.ReactNode
|
|
@@ -57,14 +58,6 @@ const LinearMeter = ({
|
|
|
57
58
|
...rest
|
|
58
59
|
}: LinearMeterProps) => {
|
|
59
60
|
const gap = getVariableByName('linearMeter/gap', modes)
|
|
60
|
-
// Track tokens
|
|
61
|
-
const trackBg = getVariableByName('linearMeter/track/background', modes)
|
|
62
|
-
const trackHeight = getVariableByName('linearMeter/track/height', modes)
|
|
63
|
-
const trackRadius = getVariableByName('linearMeter/track/radius', modes)
|
|
64
|
-
|
|
65
|
-
// Indicator tokens
|
|
66
|
-
const indicatorBg = getVariableByName('linearMeter/indicator/background', modes)
|
|
67
|
-
const indicatorRadius = getVariableByName('linearMeter/indicator/radius', modes)
|
|
68
61
|
|
|
69
62
|
// Wrap tokens
|
|
70
63
|
const wrapGap = getVariableByName('linearMeter/wrap/gap', modes)
|
|
@@ -94,10 +87,6 @@ const LinearMeter = ({
|
|
|
94
87
|
|
|
95
88
|
const content = children ? childrenWithModes : defaultContent
|
|
96
89
|
|
|
97
|
-
// Calculate width percentage
|
|
98
|
-
const clampedValue = Math.min(Math.max(value, 0), 1)
|
|
99
|
-
const widthPercent = `${clampedValue * 100}%`
|
|
100
|
-
|
|
101
90
|
return (
|
|
102
91
|
<View
|
|
103
92
|
style={[
|
|
@@ -110,32 +99,13 @@ const LinearMeter = ({
|
|
|
110
99
|
]}
|
|
111
100
|
{...rest}
|
|
112
101
|
>
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
borderRadius: trackRadius,
|
|
121
|
-
overflow: 'hidden', // Ensure indicator stays inside
|
|
122
|
-
},
|
|
123
|
-
trackStyle,
|
|
124
|
-
]}
|
|
125
|
-
>
|
|
126
|
-
{/* Indicator */}
|
|
127
|
-
<View
|
|
128
|
-
style={[
|
|
129
|
-
{
|
|
130
|
-
width: widthPercent as DimensionValue,
|
|
131
|
-
height: '100%',
|
|
132
|
-
backgroundColor: indicatorBg,
|
|
133
|
-
borderRadius: indicatorRadius,
|
|
134
|
-
},
|
|
135
|
-
indicatorStyle,
|
|
136
|
-
]}
|
|
137
|
-
/>
|
|
138
|
-
</View>
|
|
102
|
+
<LinearProgress
|
|
103
|
+
value={value}
|
|
104
|
+
modes={modes}
|
|
105
|
+
style={{ flex: 1 }}
|
|
106
|
+
trackStyle={trackStyle}
|
|
107
|
+
indicatorStyle={indicatorStyle}
|
|
108
|
+
/>
|
|
139
109
|
|
|
140
110
|
{/* Right Slot Wrapper */}
|
|
141
111
|
<View
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import React from 'react'
|
|
2
|
+
import {
|
|
3
|
+
View,
|
|
4
|
+
type StyleProp,
|
|
5
|
+
type ViewStyle,
|
|
6
|
+
type DimensionValue,
|
|
7
|
+
} from 'react-native'
|
|
8
|
+
import { getVariableByName } from '../../design-tokens/figma-variables-resolver'
|
|
9
|
+
import { EMPTY_MODES } from '../../utils/react-utils'
|
|
10
|
+
|
|
11
|
+
export type LinearProgressProps = {
|
|
12
|
+
/** Progress value between 0 and 1. Values are clamped. */
|
|
13
|
+
value?: number
|
|
14
|
+
/** Design token modes for theming */
|
|
15
|
+
modes?: Record<string, any>
|
|
16
|
+
/** Override container styles (the track wrapper) */
|
|
17
|
+
style?: StyleProp<ViewStyle>
|
|
18
|
+
/** Override the track styles */
|
|
19
|
+
trackStyle?: StyleProp<ViewStyle>
|
|
20
|
+
/** Override the indicator styles */
|
|
21
|
+
indicatorStyle?: StyleProp<ViewStyle>
|
|
22
|
+
} & Omit<React.ComponentProps<typeof View>, 'style'>
|
|
23
|
+
|
|
24
|
+
const LinearProgress = ({
|
|
25
|
+
value = 0,
|
|
26
|
+
modes = EMPTY_MODES,
|
|
27
|
+
style,
|
|
28
|
+
trackStyle,
|
|
29
|
+
indicatorStyle,
|
|
30
|
+
...rest
|
|
31
|
+
}: LinearProgressProps) => {
|
|
32
|
+
// The track and the progress indicator are intentionally rendered at
|
|
33
|
+
// different emphasis levels by default: the track sits in the
|
|
34
|
+
// background as a low-emphasis surface, while the progress indicator
|
|
35
|
+
// is the high-emphasis foreground. Defaults are placed *before* the
|
|
36
|
+
// user-provided modes spread, so callers can still override
|
|
37
|
+
// `Emphasis / DataViz` (or any other mode) via the `modes` prop.
|
|
38
|
+
const trackModes = { 'Emphasis': 'Low', ...modes }
|
|
39
|
+
const progressModes = { 'Emphasis': 'High', ...modes }
|
|
40
|
+
|
|
41
|
+
const trackHeight =
|
|
42
|
+
(getVariableByName('linearProgress/track/height', trackModes) as number | null) ?? 8
|
|
43
|
+
const trackRadius =
|
|
44
|
+
(getVariableByName('linearProgress/track/radius', trackModes) as number | null) ?? 999
|
|
45
|
+
const trackBg =
|
|
46
|
+
(getVariableByName('linearProgress/track/background', trackModes) as string | null) ??
|
|
47
|
+
'#ede7ff'
|
|
48
|
+
|
|
49
|
+
const indicatorHeight =
|
|
50
|
+
(getVariableByName('linearProgress/indicator/height', progressModes) as number | null) ?? 8
|
|
51
|
+
const indicatorRadius =
|
|
52
|
+
(getVariableByName('linearProgress/indicator/radius', progressModes) as number | null) ?? 999
|
|
53
|
+
const indicatorBg =
|
|
54
|
+
(getVariableByName('linearProgress/indicator/background', progressModes) as string | null) ??
|
|
55
|
+
'#5d00b5'
|
|
56
|
+
|
|
57
|
+
const clampedValue = Math.min(Math.max(value, 0), 1)
|
|
58
|
+
const widthPercent = `${clampedValue * 100}%` as DimensionValue
|
|
59
|
+
|
|
60
|
+
return (
|
|
61
|
+
<View
|
|
62
|
+
style={[
|
|
63
|
+
{
|
|
64
|
+
height: trackHeight,
|
|
65
|
+
backgroundColor: trackBg,
|
|
66
|
+
borderRadius: trackRadius,
|
|
67
|
+
overflow: 'hidden',
|
|
68
|
+
width: '100%',
|
|
69
|
+
},
|
|
70
|
+
style,
|
|
71
|
+
trackStyle,
|
|
72
|
+
]}
|
|
73
|
+
accessibilityRole="progressbar"
|
|
74
|
+
accessibilityValue={{ min: 0, max: 1, now: clampedValue }}
|
|
75
|
+
{...rest}
|
|
76
|
+
>
|
|
77
|
+
<View
|
|
78
|
+
style={[
|
|
79
|
+
{
|
|
80
|
+
width: widthPercent,
|
|
81
|
+
height: indicatorHeight,
|
|
82
|
+
backgroundColor: indicatorBg,
|
|
83
|
+
borderRadius: indicatorRadius,
|
|
84
|
+
},
|
|
85
|
+
indicatorStyle,
|
|
86
|
+
]}
|
|
87
|
+
/>
|
|
88
|
+
</View>
|
|
89
|
+
)
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
export default LinearProgress
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
import React from 'react'
|
|
2
|
+
import {
|
|
3
|
+
View,
|
|
4
|
+
Text,
|
|
5
|
+
type StyleProp,
|
|
6
|
+
type ViewStyle,
|
|
7
|
+
type TextStyle,
|
|
8
|
+
} from 'react-native'
|
|
9
|
+
import { getVariableByName } from '../../design-tokens/figma-variables-resolver'
|
|
10
|
+
import { EMPTY_MODES } from '../../utils/react-utils'
|
|
11
|
+
|
|
12
|
+
export type MetricLegendItemProps = {
|
|
13
|
+
/** The label text on the left (after the indicator). */
|
|
14
|
+
label?: React.ReactNode
|
|
15
|
+
/**
|
|
16
|
+
* The value text shown on the right. When `undefined` or `null`, the
|
|
17
|
+
* value slot is hidden — matching the Figma `data` boolean toggle.
|
|
18
|
+
*/
|
|
19
|
+
value?: React.ReactNode
|
|
20
|
+
/**
|
|
21
|
+
* Override the indicator dot color. Falls back to the
|
|
22
|
+
* `metricLegendItem/indicator/bg` design token.
|
|
23
|
+
*/
|
|
24
|
+
indicatorColor?: string
|
|
25
|
+
/** Design token modes for theming (e.g. `{ 'Color Mode': 'Light' }`). */
|
|
26
|
+
modes?: Record<string, any>
|
|
27
|
+
/** Override container styles. */
|
|
28
|
+
style?: StyleProp<ViewStyle>
|
|
29
|
+
/** Override the indicator (dot) styles. */
|
|
30
|
+
indicatorStyle?: StyleProp<ViewStyle>
|
|
31
|
+
/** Override the label text styles. */
|
|
32
|
+
labelStyle?: StyleProp<TextStyle>
|
|
33
|
+
/** Override the value text styles. */
|
|
34
|
+
valueStyle?: StyleProp<TextStyle>
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* MetricLegendItem renders a horizontal row consisting of a small colored
|
|
39
|
+
* indicator dot, a label and an optional value. It is used in chart legends
|
|
40
|
+
* and similar metric callouts.
|
|
41
|
+
*
|
|
42
|
+
* @component
|
|
43
|
+
* @param {MetricLegendItemProps} props
|
|
44
|
+
*/
|
|
45
|
+
function MetricLegendItem({
|
|
46
|
+
label = 'Current (4 months)',
|
|
47
|
+
value,
|
|
48
|
+
indicatorColor,
|
|
49
|
+
modes = EMPTY_MODES,
|
|
50
|
+
style,
|
|
51
|
+
indicatorStyle,
|
|
52
|
+
labelStyle,
|
|
53
|
+
valueStyle,
|
|
54
|
+
}: MetricLegendItemProps) {
|
|
55
|
+
const gap = (getVariableByName('metricLegendItem/gap', modes) as number | null) ?? 4
|
|
56
|
+
const textWrapGap =
|
|
57
|
+
(getVariableByName('metricLegendItem/textWrap/gap', modes) as number | null) ?? 4
|
|
58
|
+
|
|
59
|
+
const indicatorSize =
|
|
60
|
+
(getVariableByName('metricLegendItem/indicator/size', modes) as number | null) ?? 8
|
|
61
|
+
const indicatorRadius =
|
|
62
|
+
(getVariableByName('metricLegendItem/indicator/radius', modes) as number | null) ?? 999
|
|
63
|
+
const indicatorBg =
|
|
64
|
+
indicatorColor ??
|
|
65
|
+
(getVariableByName('metricLegendItem/indicator/bg', modes) as string | null) ??
|
|
66
|
+
'#f7ab21'
|
|
67
|
+
|
|
68
|
+
const labelColor =
|
|
69
|
+
(getVariableByName('metricLegendItem/label/color', modes) as string | null) ?? '#000000'
|
|
70
|
+
const labelFontFamily =
|
|
71
|
+
(getVariableByName('metricLegendItem/label/fontFamily', modes) as string | null) ??
|
|
72
|
+
'JioType Var'
|
|
73
|
+
const labelFontSize =
|
|
74
|
+
(getVariableByName('metricLegendItem/label/fontSize', modes) as number | null) ?? 12
|
|
75
|
+
const labelLineHeight =
|
|
76
|
+
(getVariableByName('metricLegendItem/label/lineHeight', modes) as number | null) ?? 16
|
|
77
|
+
const labelFontWeightRaw =
|
|
78
|
+
getVariableByName('metricLegendItem/label/fontWeight', modes) ?? 400
|
|
79
|
+
const labelFontWeight = String(labelFontWeightRaw) as TextStyle['fontWeight']
|
|
80
|
+
|
|
81
|
+
const valueColor =
|
|
82
|
+
(getVariableByName('metricLegendItem/value/color', modes) as string | null) ?? '#000000'
|
|
83
|
+
const valueFontFamily =
|
|
84
|
+
(getVariableByName('metricLegendItem/value/fontFamily', modes) as string | null) ??
|
|
85
|
+
'JioType Var'
|
|
86
|
+
const valueFontSize =
|
|
87
|
+
(getVariableByName('metricLegendItem/value/fontSize', modes) as number | null) ?? 12
|
|
88
|
+
const valueLineHeight =
|
|
89
|
+
(getVariableByName('metricLegendItem/value/lineHeight', modes) as number | null) ?? 16
|
|
90
|
+
const valueFontWeightRaw =
|
|
91
|
+
getVariableByName('metricLegendItem/value/fontWeight', modes) ?? 500
|
|
92
|
+
const valueFontWeight = String(valueFontWeightRaw) as TextStyle['fontWeight']
|
|
93
|
+
|
|
94
|
+
const showValue = value !== undefined && value !== null && value !== false
|
|
95
|
+
|
|
96
|
+
return (
|
|
97
|
+
<View
|
|
98
|
+
style={[
|
|
99
|
+
{
|
|
100
|
+
flexDirection: 'row',
|
|
101
|
+
alignItems: 'center',
|
|
102
|
+
gap,
|
|
103
|
+
},
|
|
104
|
+
style,
|
|
105
|
+
]}
|
|
106
|
+
accessibilityRole="text"
|
|
107
|
+
>
|
|
108
|
+
<View
|
|
109
|
+
style={[
|
|
110
|
+
{
|
|
111
|
+
width: indicatorSize,
|
|
112
|
+
height: indicatorSize,
|
|
113
|
+
borderRadius: indicatorRadius,
|
|
114
|
+
backgroundColor: indicatorBg,
|
|
115
|
+
},
|
|
116
|
+
indicatorStyle,
|
|
117
|
+
]}
|
|
118
|
+
/>
|
|
119
|
+
|
|
120
|
+
<View
|
|
121
|
+
style={{
|
|
122
|
+
flex: 1,
|
|
123
|
+
flexDirection: 'row',
|
|
124
|
+
alignItems: 'center',
|
|
125
|
+
gap: textWrapGap,
|
|
126
|
+
minWidth: 0,
|
|
127
|
+
}}
|
|
128
|
+
>
|
|
129
|
+
<Text
|
|
130
|
+
style={[
|
|
131
|
+
{
|
|
132
|
+
flex: 1,
|
|
133
|
+
color: labelColor,
|
|
134
|
+
fontFamily: labelFontFamily,
|
|
135
|
+
fontSize: labelFontSize,
|
|
136
|
+
lineHeight: labelLineHeight,
|
|
137
|
+
fontWeight: labelFontWeight,
|
|
138
|
+
},
|
|
139
|
+
labelStyle,
|
|
140
|
+
]}
|
|
141
|
+
>
|
|
142
|
+
{label}
|
|
143
|
+
</Text>
|
|
144
|
+
|
|
145
|
+
{showValue && (
|
|
146
|
+
<Text
|
|
147
|
+
style={[
|
|
148
|
+
{
|
|
149
|
+
color: valueColor,
|
|
150
|
+
fontFamily: valueFontFamily,
|
|
151
|
+
fontSize: valueFontSize,
|
|
152
|
+
lineHeight: valueLineHeight,
|
|
153
|
+
fontWeight: valueFontWeight,
|
|
154
|
+
},
|
|
155
|
+
valueStyle,
|
|
156
|
+
]}
|
|
157
|
+
numberOfLines={1}
|
|
158
|
+
>
|
|
159
|
+
{value}
|
|
160
|
+
</Text>
|
|
161
|
+
)}
|
|
162
|
+
</View>
|
|
163
|
+
</View>
|
|
164
|
+
)
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
export default MetricLegendItem
|