jfs-components 0.1.23 → 0.1.25
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/lib/commonjs/components/CardCTA/CardCTA.js +32 -25
- package/lib/commonjs/components/ChipSelect/ChipSelect.js +2 -1
- package/lib/commonjs/components/ListItem/ListItem.js +11 -4
- package/lib/commonjs/components/MetricData/MetricData.js +132 -0
- package/lib/commonjs/components/Rating/Rating.js +137 -0
- package/lib/commonjs/design-tokens/figma-modes.generated.js +2 -0
- package/lib/commonjs/icons/registry.js +1 -1
- package/lib/module/components/CardCTA/CardCTA.js +32 -25
- package/lib/module/components/ChipSelect/ChipSelect.js +2 -1
- package/lib/module/components/ListItem/ListItem.js +11 -4
- package/lib/module/components/MetricData/MetricData.js +127 -0
- package/lib/module/components/Rating/Rating.js +132 -0
- package/lib/module/design-tokens/figma-modes.generated.js +2 -0
- package/lib/module/icons/registry.js +1 -1
- package/lib/typescript/src/components/ChipSelect/ChipSelect.d.ts +6 -1
- package/lib/typescript/src/components/MetricData/MetricData.d.ts +53 -0
- package/lib/typescript/src/components/Rating/Rating.d.ts +30 -0
- package/lib/typescript/src/icons/registry.d.ts +1 -1
- package/package.json +1 -1
- package/src/components/CardCTA/CardCTA.tsx +30 -15
- package/src/components/ChipSelect/ChipSelect.tsx +7 -1
- package/src/components/ListItem/ListItem.tsx +11 -4
- package/src/components/MetricData/MetricData.tsx +185 -0
- package/src/components/Rating/Rating.tsx +174 -0
- package/src/design-tokens/figma-modes.generated.ts +2 -0
- package/src/icons/registry.ts +1 -1
|
@@ -230,22 +230,39 @@ function CardCTA({
|
|
|
230
230
|
zIndex: 1
|
|
231
231
|
};
|
|
232
232
|
|
|
233
|
-
// NOTE: rightWrap must
|
|
234
|
-
//
|
|
235
|
-
//
|
|
236
|
-
//
|
|
237
|
-
//
|
|
238
|
-
// the
|
|
239
|
-
//
|
|
240
|
-
// this because
|
|
241
|
-
//
|
|
242
|
-
//
|
|
243
|
-
//
|
|
244
|
-
//
|
|
233
|
+
// NOTE: rightWrap must implement the design's TRUE `2fr` column.
|
|
234
|
+
//
|
|
235
|
+
// History of this style — two Yoga pitfalls pull in opposite directions:
|
|
236
|
+
//
|
|
237
|
+
// 1. `flex: 2` (=> flexBasis: 0, flexShrink: 1): on Android, Yoga could
|
|
238
|
+
// shrink the wrapper below its padding+IconCapsule width when the left
|
|
239
|
+
// text was long, collapsing the padding and gluing the icon to the
|
|
240
|
+
// text. Browsers hide this because they honor `min-width: auto`; Yoga
|
|
241
|
+
// always treats min-width as 0 unless told otherwise.
|
|
242
|
+
// 2. The previous workaround, `flexBasis: 'auto'` + `flexGrow: 2`, fixed
|
|
243
|
+
// #1 but broke the column ratio: Yoga then sizes the wrapper to its
|
|
244
|
+
// content FIRST (icon + padding) and distributes only the leftover
|
|
245
|
+
// space 3:2. The icon width gets baked in on top of the 2fr share, so
|
|
246
|
+
// the right column ends up much wider than the design's 2fr and the
|
|
247
|
+
// body text wraps early with dead space to its right.
|
|
248
|
+
//
|
|
249
|
+
// Fundamental fix: keep the genuine fr-unit geometry (`flexBasis: 0`,
|
|
250
|
+
// grow 3:2, no shrink) and replace Yoga's missing `min-width: auto` with
|
|
251
|
+
// an explicit computed floor — the resolved IconCapsule size plus the
|
|
252
|
+
// wrapper's own horizontal padding. The column is exactly 2fr whenever
|
|
253
|
+
// space allows and can never collapse below its content.
|
|
254
|
+
const iconCapsuleModes = {
|
|
255
|
+
...modes,
|
|
256
|
+
'IconCapsule / Size': 'M',
|
|
257
|
+
Emphasis: 'Medium',
|
|
258
|
+
AppearanceBrand: 'Secondary'
|
|
259
|
+
};
|
|
260
|
+
const rightWrapMinWidth = ((0, _figmaVariablesResolver.getVariableByName)('iconCapsule/size', iconCapsuleModes) || 0) + (rightPaddingH || 0) * 2;
|
|
245
261
|
const rightWrapStyle = {
|
|
246
262
|
flexGrow: 2,
|
|
247
263
|
flexShrink: 0,
|
|
248
|
-
flexBasis:
|
|
264
|
+
flexBasis: 0,
|
|
265
|
+
minWidth: rightWrapMinWidth,
|
|
249
266
|
paddingHorizontal: rightPaddingH,
|
|
250
267
|
paddingVertical: rightPaddingV,
|
|
251
268
|
alignItems: 'flex-end',
|
|
@@ -499,19 +516,9 @@ function CardCTA({
|
|
|
499
516
|
})]
|
|
500
517
|
}), /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.View, {
|
|
501
518
|
style: rightWrapStyle,
|
|
502
|
-
children: iconSlot ? (0, _reactUtils.cloneChildrenWithModes)(iconSlot, {
|
|
503
|
-
...modes,
|
|
504
|
-
'IconCapsule / Size': 'M',
|
|
505
|
-
Emphasis: 'Medium',
|
|
506
|
-
AppearanceBrand: 'Secondary'
|
|
507
|
-
}) : /*#__PURE__*/(0, _jsxRuntime.jsx)(_IconCapsule.default, {
|
|
519
|
+
children: iconSlot ? (0, _reactUtils.cloneChildrenWithModes)(iconSlot, iconCapsuleModes) : /*#__PURE__*/(0, _jsxRuntime.jsx)(_IconCapsule.default, {
|
|
508
520
|
iconName: iconName,
|
|
509
|
-
modes:
|
|
510
|
-
...modes,
|
|
511
|
-
'IconCapsule / Size': 'M',
|
|
512
|
-
Emphasis: 'Medium',
|
|
513
|
-
AppearanceBrand: 'Secondary'
|
|
514
|
-
}
|
|
521
|
+
modes: iconCapsuleModes
|
|
515
522
|
})
|
|
516
523
|
})]
|
|
517
524
|
});
|
|
@@ -19,6 +19,7 @@ function ChipSelect({
|
|
|
19
19
|
label = 'Date',
|
|
20
20
|
active = false,
|
|
21
21
|
icon = 'ic_calendar_week',
|
|
22
|
+
showCloseIcon = true,
|
|
22
23
|
modes = _reactUtils.EMPTY_MODES,
|
|
23
24
|
style,
|
|
24
25
|
labelSlot,
|
|
@@ -92,7 +93,7 @@ function ChipSelect({
|
|
|
92
93
|
name: icon,
|
|
93
94
|
size: iconSize,
|
|
94
95
|
color: textColor
|
|
95
|
-
}), renderLabel(), active && /*#__PURE__*/(0, _jsxRuntime.jsx)(_Icon.default, {
|
|
96
|
+
}), renderLabel(), active && showCloseIcon && /*#__PURE__*/(0, _jsxRuntime.jsx)(_Icon.default, {
|
|
96
97
|
name: "ic_close",
|
|
97
98
|
size: iconSize,
|
|
98
99
|
color: textColor
|
|
@@ -255,13 +255,20 @@ function ListItemImpl({
|
|
|
255
255
|
const renderSupportContent = () => {
|
|
256
256
|
if (processedSupportSlot) return processedSupportSlot;
|
|
257
257
|
|
|
258
|
-
// Default support text
|
|
259
|
-
//
|
|
260
|
-
//
|
|
258
|
+
// Default support text — ONE `<Text>` hard-clamped to 2 lines via
|
|
259
|
+
// `numberOfLines={2}`, the only mechanism React Native actually enforces
|
|
260
|
+
// on iOS/Android (native has no `white-space: nowrap` equivalent, so any
|
|
261
|
+
// style-based trick cannot stop a too-wide word from wrapping).
|
|
262
|
+
//
|
|
263
|
+
// - vertical layout: line-broken on spaces so each word gets its own line
|
|
264
|
+
// ("Split Payments" → "Split" / "Payments"). If a word is still wider
|
|
265
|
+
// than the cell (or there are 3+ words), RN cuts it off at line 2 with
|
|
266
|
+
// a trailing ellipsis instead of ever spilling onto a third line.
|
|
267
|
+
// - horizontal layout: natural wrapping, same 2-line clamp.
|
|
261
268
|
const displayText = layout === 'Vertical' ? supportText.replace(/ /g, '\n') : supportText;
|
|
262
269
|
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.Text, {
|
|
263
270
|
style: layout === 'Vertical' ? [tokens.supportTextStyle, verticalSupportTextOverride] : tokens.supportTextStyle,
|
|
264
|
-
...(0, _reactUtils.resolveTruncation)(disableTruncation,
|
|
271
|
+
...(0, _reactUtils.resolveTruncation)(disableTruncation, 2, 'tail'),
|
|
265
272
|
children: displayText
|
|
266
273
|
});
|
|
267
274
|
};
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var _react = _interopRequireDefault(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 _Icon = _interopRequireDefault(require("../Icon/Icon"));
|
|
12
|
+
var _jsxRuntime = require("react/jsx-runtime");
|
|
13
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
14
|
+
const LINE_HEIGHT_RATIO = 1.2;
|
|
15
|
+
const ICON_SIZE = 18;
|
|
16
|
+
// Figma renders the value-row icon with no surrounding padding; the shared Icon
|
|
17
|
+
// component pulls padding from `icon/padding/*` tokens, so we zero it here.
|
|
18
|
+
const ICON_PADDING_RESET = {
|
|
19
|
+
paddingLeft: 0,
|
|
20
|
+
paddingRight: 0,
|
|
21
|
+
paddingTop: 0,
|
|
22
|
+
paddingBottom: 0
|
|
23
|
+
};
|
|
24
|
+
/**
|
|
25
|
+
* MetricData — a compact, centered metric block.
|
|
26
|
+
*
|
|
27
|
+
* Stacks a small `title`, a prominent `value` (with an optional leading
|
|
28
|
+
* `icon`), and a muted `caption`. Typography, colours, gaps and padding all
|
|
29
|
+
* resolve from the `metricdata/*` design tokens. `title`, `caption` and `icon`
|
|
30
|
+
* are optional; only `value` is shown by default.
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* ```tsx
|
|
34
|
+
* <MetricData title="Balance" value="₹1,20,000" caption="as of today" />
|
|
35
|
+
* <MetricData title="Cards" value="12" icon="ic_card" caption="active" />
|
|
36
|
+
* ```
|
|
37
|
+
*/
|
|
38
|
+
function MetricData({
|
|
39
|
+
title,
|
|
40
|
+
value,
|
|
41
|
+
caption,
|
|
42
|
+
icon,
|
|
43
|
+
modes = _reactUtils.EMPTY_MODES,
|
|
44
|
+
style,
|
|
45
|
+
titleStyle,
|
|
46
|
+
valueStyle,
|
|
47
|
+
captionStyle,
|
|
48
|
+
accessibilityLabel
|
|
49
|
+
}) {
|
|
50
|
+
const titleColor = (0, _figmaVariablesResolver.getVariableByName)('metricdata/title/color', modes) ?? '#000000';
|
|
51
|
+
const titleFontFamily = (0, _figmaVariablesResolver.getVariableByName)('metricdata/title/fontfamily', modes) ?? 'JioType Var';
|
|
52
|
+
const titleFontSize = (0, _figmaVariablesResolver.getVariableByName)('metricdata/title/fontsize', modes) ?? 12;
|
|
53
|
+
const titleFontWeight = String((0, _figmaVariablesResolver.getVariableByName)('metricdata/title/fontweight', modes) ?? 400);
|
|
54
|
+
const valueColor = (0, _figmaVariablesResolver.getVariableByName)('metricdata/value/color', modes) ?? '#000000';
|
|
55
|
+
const valueFontFamily = (0, _figmaVariablesResolver.getVariableByName)('metricdata/value/fontfamily', modes) ?? 'JioType Var';
|
|
56
|
+
const valueFontSize = (0, _figmaVariablesResolver.getVariableByName)('metricdata/value/fontsize', modes) ?? 20;
|
|
57
|
+
const valueFontWeight = String((0, _figmaVariablesResolver.getVariableByName)('metricdata/value/fontweight', modes) ?? 700);
|
|
58
|
+
const captionColor = (0, _figmaVariablesResolver.getVariableByName)('metricdata/caption/color', modes) ?? '#777777';
|
|
59
|
+
const captionFontFamily = (0, _figmaVariablesResolver.getVariableByName)('metricdata/caption/fontfamily', modes) ?? 'JioType Var';
|
|
60
|
+
const captionFontSize = (0, _figmaVariablesResolver.getVariableByName)('metricdata/caption/fontsize', modes) ?? 12;
|
|
61
|
+
const captionFontWeight = String((0, _figmaVariablesResolver.getVariableByName)('metricdata/caption/fontweight', modes) ?? 500);
|
|
62
|
+
const gap = (0, _figmaVariablesResolver.getVariableByName)('metricdata/gap', modes) ?? 4;
|
|
63
|
+
const valueWrapGap = (0, _figmaVariablesResolver.getVariableByName)('metricdata/valueWrap/gap', modes) ?? 4;
|
|
64
|
+
const paddingHorizontal = (0, _figmaVariablesResolver.getVariableByName)('metricdata/padding/horizontal', modes) ?? 10;
|
|
65
|
+
const paddingVertical = (0, _figmaVariablesResolver.getVariableByName)('metricdata/padding/vertical', modes) ?? 10;
|
|
66
|
+
const containerStyle = {
|
|
67
|
+
flexDirection: 'column',
|
|
68
|
+
alignItems: 'center',
|
|
69
|
+
justifyContent: 'center',
|
|
70
|
+
gap,
|
|
71
|
+
paddingHorizontal,
|
|
72
|
+
paddingVertical
|
|
73
|
+
};
|
|
74
|
+
const titleTextStyle = {
|
|
75
|
+
color: titleColor,
|
|
76
|
+
fontFamily: titleFontFamily,
|
|
77
|
+
fontSize: titleFontSize,
|
|
78
|
+
fontWeight: titleFontWeight,
|
|
79
|
+
lineHeight: titleFontSize * LINE_HEIGHT_RATIO,
|
|
80
|
+
textAlign: 'center'
|
|
81
|
+
};
|
|
82
|
+
const valueTextStyle = {
|
|
83
|
+
color: valueColor,
|
|
84
|
+
fontFamily: valueFontFamily,
|
|
85
|
+
fontSize: valueFontSize,
|
|
86
|
+
fontWeight: valueFontWeight,
|
|
87
|
+
lineHeight: valueFontSize * LINE_HEIGHT_RATIO,
|
|
88
|
+
textAlign: 'center'
|
|
89
|
+
};
|
|
90
|
+
const captionTextStyle = {
|
|
91
|
+
color: captionColor,
|
|
92
|
+
fontFamily: captionFontFamily,
|
|
93
|
+
fontSize: captionFontSize,
|
|
94
|
+
fontWeight: captionFontWeight,
|
|
95
|
+
lineHeight: captionFontSize * LINE_HEIGHT_RATIO,
|
|
96
|
+
textAlign: 'center'
|
|
97
|
+
};
|
|
98
|
+
const iconNode = icon == null ? null : typeof icon === 'string' ? /*#__PURE__*/(0, _jsxRuntime.jsx)(_Icon.default, {
|
|
99
|
+
iconName: icon,
|
|
100
|
+
size: ICON_SIZE,
|
|
101
|
+
color: valueColor,
|
|
102
|
+
modes: modes,
|
|
103
|
+
style: ICON_PADDING_RESET
|
|
104
|
+
}) : icon;
|
|
105
|
+
const resolvedLabel = accessibilityLabel ?? ([title, typeof value === 'string' ? value : undefined, caption].filter(Boolean).join(', ') || undefined);
|
|
106
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_reactNative.View, {
|
|
107
|
+
style: [containerStyle, style],
|
|
108
|
+
accessible: true,
|
|
109
|
+
...(resolvedLabel !== undefined ? {
|
|
110
|
+
accessibilityLabel: resolvedLabel
|
|
111
|
+
} : null),
|
|
112
|
+
children: [title !== undefined && title !== '' ? /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.Text, {
|
|
113
|
+
style: [titleTextStyle, titleStyle],
|
|
114
|
+
children: title
|
|
115
|
+
}) : null, /*#__PURE__*/(0, _jsxRuntime.jsxs)(_reactNative.View, {
|
|
116
|
+
style: {
|
|
117
|
+
flexDirection: 'row',
|
|
118
|
+
alignItems: 'center',
|
|
119
|
+
justifyContent: 'center',
|
|
120
|
+
gap: valueWrapGap
|
|
121
|
+
},
|
|
122
|
+
children: [iconNode, typeof value === 'string' ? /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.Text, {
|
|
123
|
+
style: [valueTextStyle, valueStyle],
|
|
124
|
+
children: value
|
|
125
|
+
}) : value]
|
|
126
|
+
}), caption !== undefined && caption !== '' ? /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.Text, {
|
|
127
|
+
style: [captionTextStyle, captionStyle],
|
|
128
|
+
children: caption
|
|
129
|
+
}) : null]
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
var _default = exports.default = /*#__PURE__*/_react.default.memo(MetricData);
|
|
@@ -0,0 +1,137 @@
|
|
|
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 _reactNativeSvg = _interopRequireWildcard(require("react-native-svg"));
|
|
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 _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); }
|
|
15
|
+
/**
|
|
16
|
+
* Star glyph taken directly from the Figma `Rating` component. Filled and empty
|
|
17
|
+
* stars share this shape and differ only by fill color, so a single path keeps
|
|
18
|
+
* the row perfectly aligned.
|
|
19
|
+
*/
|
|
20
|
+
const STAR_PATH = 'M40.7187 15.3334C40.4728 14.6159 40.0426 13.9805 39.4688 13.4885C38.8951 12.9965 38.1985 12.689 37.4403 12.566L28.3018 11.1721L24.2038 2.35741C23.8759 1.66044 23.3432 1.06596 22.6875 0.635476C22.0318 0.225491 21.2737 0 20.4951 0C19.7165 0 18.9583 0.225491 18.3027 0.635476C17.647 1.04546 17.1142 1.63994 16.7864 2.35741L12.6884 11.1721L3.4679 12.566C2.73026 12.689 2.01311 12.9965 1.43939 13.4885C0.865675 13.9805 0.435385 14.6159 0.189505 15.3334C-0.0358854 16.0304 -0.0563753 16.7889 0.107545 17.5063C0.271465 18.2238 0.640285 18.9003 1.15254 19.4333L7.89374 26.362L6.29552 36.1811C6.17258 36.9396 6.27503 37.7186 6.56189 38.4156C6.84875 39.1125 7.34051 39.7275 7.9757 40.1785C8.65187 40.691 9.49196 40.978 10.3525 40.9985C11.0697 40.9985 11.7664 40.8345 12.4015 40.486L20.5771 35.9761L28.7526 40.486C29.3673 40.8345 30.0844 41.019 30.8016 40.9985C31.6621 40.9985 32.4817 40.732 33.1784 40.24C33.7931 39.789 34.2849 39.1945 34.5922 38.4771C34.8791 37.7801 34.9815 37.0011 34.8586 36.2426L33.2604 26.4235L40.0016 19.4948C40.4933 18.9413 40.8007 18.2443 40.9441 17.5063C41.0671 16.7684 40.9851 16.0099 40.7187 15.3334Z';
|
|
21
|
+
const STAR_VIEWBOX = '0 0 41 41';
|
|
22
|
+
|
|
23
|
+
// Fallbacks mirror the Figma `Rating Star / Output` + `Rating Star State` tokens.
|
|
24
|
+
const DEFAULT_STAR_SIZE = 41;
|
|
25
|
+
const DEFAULT_GAP = 12;
|
|
26
|
+
const SELECTED_FALLBACK = '#5D00B5';
|
|
27
|
+
const IDLE_FALLBACK = '#F6F3FF';
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* `ratingStar/background` is state-driven: the same token resolves to the filled
|
|
31
|
+
* color when `Rating Star State = selected` and to the empty color when `idle`.
|
|
32
|
+
*/
|
|
33
|
+
const RATING_STATE_COLLECTION = 'Rating Star State';
|
|
34
|
+
const toNumber = (value, fallback) => {
|
|
35
|
+
const n = typeof value === 'string' ? Number(value) : value;
|
|
36
|
+
return typeof n === 'number' && Number.isFinite(n) ? n : fallback;
|
|
37
|
+
};
|
|
38
|
+
function Star({
|
|
39
|
+
width,
|
|
40
|
+
height,
|
|
41
|
+
color
|
|
42
|
+
}) {
|
|
43
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNativeSvg.default, {
|
|
44
|
+
width: width,
|
|
45
|
+
height: height,
|
|
46
|
+
viewBox: STAR_VIEWBOX,
|
|
47
|
+
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNativeSvg.Path, {
|
|
48
|
+
d: STAR_PATH,
|
|
49
|
+
fill: color
|
|
50
|
+
})
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
function Rating({
|
|
54
|
+
value = 0,
|
|
55
|
+
max = 5,
|
|
56
|
+
onChange,
|
|
57
|
+
readOnly = false,
|
|
58
|
+
starSize,
|
|
59
|
+
gap,
|
|
60
|
+
modes: propModes = _reactUtils.EMPTY_MODES,
|
|
61
|
+
style,
|
|
62
|
+
accessibilityLabel,
|
|
63
|
+
...rest
|
|
64
|
+
}) {
|
|
65
|
+
const {
|
|
66
|
+
modes: globalModes
|
|
67
|
+
} = (0, _JFSThemeProvider.useTokens)();
|
|
68
|
+
const modes = (0, _react.useMemo)(() => globalModes === _reactUtils.EMPTY_MODES && propModes === _reactUtils.EMPTY_MODES ? _reactUtils.EMPTY_MODES : {
|
|
69
|
+
...globalModes,
|
|
70
|
+
...propModes
|
|
71
|
+
}, [globalModes, propModes]);
|
|
72
|
+
const {
|
|
73
|
+
selectedColor,
|
|
74
|
+
idleColor,
|
|
75
|
+
starWidth,
|
|
76
|
+
starHeight,
|
|
77
|
+
resolvedGap
|
|
78
|
+
} = (0, _react.useMemo)(() => {
|
|
79
|
+
const selected = (0, _figmaVariablesResolver.getVariableByName)('ratingStar/background', {
|
|
80
|
+
...modes,
|
|
81
|
+
[RATING_STATE_COLLECTION]: 'selected'
|
|
82
|
+
});
|
|
83
|
+
const idle = (0, _figmaVariablesResolver.getVariableByName)('ratingStar/background', {
|
|
84
|
+
...modes,
|
|
85
|
+
[RATING_STATE_COLLECTION]: 'idle'
|
|
86
|
+
});
|
|
87
|
+
return {
|
|
88
|
+
selectedColor: selected ?? SELECTED_FALLBACK,
|
|
89
|
+
idleColor: idle ?? IDLE_FALLBACK,
|
|
90
|
+
starWidth: starSize ?? toNumber((0, _figmaVariablesResolver.getVariableByName)('ratingStar/width', modes), DEFAULT_STAR_SIZE),
|
|
91
|
+
starHeight: starSize ?? toNumber((0, _figmaVariablesResolver.getVariableByName)('ratingStar/height', modes), DEFAULT_STAR_SIZE),
|
|
92
|
+
resolvedGap: gap ?? toNumber((0, _figmaVariablesResolver.getVariableByName)('rating/gap', modes), DEFAULT_GAP)
|
|
93
|
+
};
|
|
94
|
+
}, [modes, starSize, gap]);
|
|
95
|
+
const total = Math.max(0, Math.round(max));
|
|
96
|
+
const filledCount = Math.max(0, Math.min(total, Math.round(value)));
|
|
97
|
+
const interactive = !readOnly && typeof onChange === 'function';
|
|
98
|
+
const label = accessibilityLabel ?? `${filledCount} of ${total} stars`;
|
|
99
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.View, {
|
|
100
|
+
...rest,
|
|
101
|
+
style: [{
|
|
102
|
+
flexDirection: 'row',
|
|
103
|
+
alignItems: 'center',
|
|
104
|
+
gap: resolvedGap
|
|
105
|
+
}, style],
|
|
106
|
+
accessibilityRole: interactive ? 'adjustable' : 'image',
|
|
107
|
+
accessibilityLabel: label,
|
|
108
|
+
accessibilityValue: interactive ? {
|
|
109
|
+
min: 0,
|
|
110
|
+
max: total,
|
|
111
|
+
now: filledCount
|
|
112
|
+
} : undefined,
|
|
113
|
+
children: Array.from({
|
|
114
|
+
length: total
|
|
115
|
+
}, (_, index) => {
|
|
116
|
+
const color = index < filledCount ? selectedColor : idleColor;
|
|
117
|
+
const star = /*#__PURE__*/(0, _jsxRuntime.jsx)(Star, {
|
|
118
|
+
width: starWidth,
|
|
119
|
+
height: starHeight,
|
|
120
|
+
color: color
|
|
121
|
+
});
|
|
122
|
+
if (!interactive) {
|
|
123
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_react.default.Fragment, {
|
|
124
|
+
children: star
|
|
125
|
+
}, index);
|
|
126
|
+
}
|
|
127
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.Pressable, {
|
|
128
|
+
onPress: () => onChange?.(index + 1),
|
|
129
|
+
accessibilityRole: "button",
|
|
130
|
+
accessibilityLabel: `Rate ${index + 1} of ${total} stars`,
|
|
131
|
+
hitSlop: 8,
|
|
132
|
+
children: star
|
|
133
|
+
}, index);
|
|
134
|
+
})
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
var _default = exports.default = /*#__PURE__*/_react.default.memo(Rating);
|
|
@@ -361,6 +361,7 @@ const FIGMA_COMPONENT_MODES = exports.FIGMA_COMPONENT_MODES = {
|
|
|
361
361
|
"MediaCard": ["Contrast Context"],
|
|
362
362
|
"MerchantProfile": ["Avatar Size", "Badge Size", "Color Mode", "context 10", "Context4", "Profile Card Appearance"],
|
|
363
363
|
"MessageField": ["Color Mode", "FormField States"],
|
|
364
|
+
"MetricData": ["AppearanceBrand", "Badge Size", "Color Mode", "context 10", "Context4", "Emphasis", "Profile Card Appearance"],
|
|
364
365
|
"MetricLegendItem": ["Appearance / DataViz", "Color Mode", "Emphasis / DataViz"],
|
|
365
366
|
"MoneyValue": ["Color Mode", "Context3"],
|
|
366
367
|
"MonthlyStatusGrid": ["Appearance / DataViz", "Calendar Glyph State", "Color Mode", "Emphasis / DataViz"],
|
|
@@ -379,6 +380,7 @@ const FIGMA_COMPONENT_MODES = exports.FIGMA_COMPONENT_MODES = {
|
|
|
379
380
|
"ProjectionMarker": ["Color Mode", "context 10", "Profile Card Appearance"],
|
|
380
381
|
"Radio": ["Color Mode"],
|
|
381
382
|
"RangeTrack": ["Appearance / DataViz", "Color Mode", "Emphasis / DataViz"],
|
|
383
|
+
"Rating": ["Color Mode", "Rating Star State"],
|
|
382
384
|
"RechargeCard": ["Avatar Size", "Badge Size", "Color Mode", "Context3", "Context4"],
|
|
383
385
|
"SavingsGoalSummary": ["Appearance / DataViz", "AppearanceBrand", "AppearanceSystem", "Color Mode", "Emphasis", "Emphasis / DataViz", "LinearProgress Size", "Semantic Intent"],
|
|
384
386
|
"Screen": ["Color Mode", "Page type"],
|