Skip to content

Commit 8022a00

Browse files
author
rzp-slash[bot]
committed
fix: resolve PR review comments for InfoGroup native implementation [resolved by agent]
Co-authored-by: admin <admin>
1 parent 77ab55d commit 8022a00

3 files changed

Lines changed: 32 additions & 19 deletions

File tree

packages/blade/src/components/InfoGroup/InfoGroup.native.tsx

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ const _InfoItemValue = (
226226
ref={ref as never}
227227
display="flex"
228228
flexDirection="row"
229-
alignItems="flex-start"
229+
alignItems="center"
230230
// Horizontal: `flex={1}` grows the value to fill the row beside the fixed label column.
231231
// Vertical: the value sits BELOW the label inside a flex COLUMN, where `flex={1}` would
232232
// (wrongly) grow it along the vertical axis; instead stretch it to the full cell width so
@@ -400,7 +400,8 @@ const InfoItem = assignWithoutSideEffects(React.forwardRef(_InfoItem), {
400400
* column count with an equal-width wrapping flex layout (each cell gets width `100 / N %`).
401401
*
402402
* We only need to handle the two shapes InfoGroup actually uses:
403-
* - `repeat(N, ...)` / `repeat(min(N, ...), ...)` -> N (web default is `repeat(min(4, count), 1fr)`)
403+
* - `repeat(N, ...)` / `repeat(min(N, M), ...)` / `repeat(max(N, M), ...)` -> N or min/max(N, M)
404+
* (web default is `repeat(min(4, count), 1fr)`)
404405
* - an explicit track list, e.g. `1fr`, `1fr 1fr`, `50% 50%` -> number of tracks
405406
* - undefined / unrecognized -> `min(4, childCount)` (mirrors the web default)
406407
*/
@@ -413,13 +414,26 @@ const getVerticalColumnCount = (
413414
const template = String(gridTemplateColumns ?? '').trim();
414415
if (!template) return fallback;
415416

416-
// `repeat(N, ...)` / `repeat(min(N, ...), ...)` -> the leading integer is the column count.
417-
const repeatMatch = /repeat\(\s*(?:min|max|minmax)?\(?\s*(\d+)/i.exec(template);
418-
if (repeatMatch) {
419-
const parsed = parseInt(repeatMatch[1], 10);
417+
// `repeat(N, ...)` -> N is the column count.
418+
// `repeat(min(N, M), ...)` -> Math.min(N, M) is the column count.
419+
// `repeat(max(N, M), ...)` -> Math.max(N, M) is the column count.
420+
// `repeat(minmax(N, M), ...)` -> N is a reasonable default (the min track count).
421+
const simpleRepeatMatch = /repeat\(\s*(\d+)/i.exec(template);
422+
if (simpleRepeatMatch) {
423+
const parsed = parseInt(simpleRepeatMatch[1], 10);
420424
return parsed > 0 ? parsed : fallback;
421425
}
422426

427+
const minRepeatMatch = /repeat\(\s*min\(\s*(\d+)\s*,\s*(\d+)/i.exec(template);
428+
if (minRepeatMatch) {
429+
return Math.min(parseInt(minRepeatMatch[1], 10), parseInt(minRepeatMatch[2], 10));
430+
}
431+
432+
const maxRepeatMatch = /repeat\(\s*max\(\s*(\d+)\s*,\s*(\d+)/i.exec(template);
433+
if (maxRepeatMatch) {
434+
return Math.max(parseInt(maxRepeatMatch[1], 10), parseInt(maxRepeatMatch[2], 10));
435+
}
436+
423437
// Explicit track list -> number of whitespace-separated tracks.
424438
const tracks = template.split(/\s+/).filter(Boolean).length;
425439
return tracks > 0 ? tracks : fallback;
@@ -506,7 +520,9 @@ const _InfoGroup = (
506520
{!isHorizontal
507521
? React.Children.map(children, (child, index) => {
508522
if (!React.isValidElement(child)) return child;
509-
const isLastColumn = index % verticalColumnCount === verticalColumnCount - 1;
523+
const isLastColumn =
524+
index % verticalColumnCount === verticalColumnCount - 1 ||
525+
index === childCount - 1;
510526
const isLastRow = Math.floor(index / verticalColumnCount) === verticalRowCount - 1;
511527
return (
512528
<BaseBox

packages/blade/src/components/InfoGroup/__tests__/InfoGroup.native.test.tsx

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,7 @@ describe('<InfoGroup /> (native)', () => {
5555
});
5656

5757
it('should render InfoGroup with gridTemplateColumns prop without crashing (prop is ignored on native)', () => {
58-
// gridTemplateColumns is a web-only CSS prop; on native it resolves to `never`.
59-
// We cast it here to verify the component doesn't crash when it receives the prop.
60-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
61-
const gridTemplateColumns = '50% 50%' as any;
58+
const gridTemplateColumns = '50% 50%';
6259
const { toJSON } = renderWithTheme(
6360
<InfoGroup gridTemplateColumns={gridTemplateColumns}>
6461
<InfoItem>
@@ -279,9 +276,7 @@ describe('<InfoGroup /> (native)', () => {
279276

280277
it('should render vertical InfoGroup with gridTemplateColumns="1fr" as a single stacked column', () => {
281278
const { toJSON } = renderWithTheme(
282-
// gridTemplateColumns is a web CSS type; cast for the native emulation path.
283-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
284-
<InfoGroup itemOrientation="vertical" isHighlighted gridTemplateColumns={'1fr' as any}>
279+
<InfoGroup itemOrientation="vertical" isHighlighted gridTemplateColumns={'1fr'}>
285280
<InfoItem>
286281
<InfoItemKey>Account Holder</InfoItemKey>
287282
<InfoItemValue>Saurabh Daware</InfoItemValue>
@@ -297,8 +292,7 @@ describe('<InfoGroup /> (native)', () => {
297292

298293
it('should render vertical InfoGroup with gridTemplateColumns="1fr 1fr" as two equal columns', () => {
299294
const { toJSON } = renderWithTheme(
300-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
301-
<InfoGroup itemOrientation="vertical" gridTemplateColumns={'1fr 1fr' as any}>
295+
<InfoGroup itemOrientation="vertical" gridTemplateColumns={'1fr 1fr'}>
302296
<InfoItem>
303297
<InfoItemKey>Account Holder</InfoItemKey>
304298
<InfoItemValue>Saurabh Daware</InfoItemValue>
@@ -318,8 +312,7 @@ describe('<InfoGroup /> (native)', () => {
318312

319313
it('should render vertical InfoGroup with gridTemplateColumns="repeat(2, 1fr)" as two equal columns', () => {
320314
const { toJSON } = renderWithTheme(
321-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
322-
<InfoGroup itemOrientation="vertical" gridTemplateColumns={'repeat(2, 1fr)' as any}>
315+
<InfoGroup itemOrientation="vertical" gridTemplateColumns={'repeat(2, 1fr)'}>
323316
<InfoItem>
324317
<InfoItemKey>Account Holder</InfoItemKey>
325318
<InfoItemValue>Saurabh Daware</InfoItemValue>

packages/blade/src/components/InfoGroup/types.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import type { StringChildrenType, TestID } from '~utils/types';
33
import type { StyledPropsBlade } from '~components/Box/styledProps';
44
import type { BoxProps } from '~components/Box';
55
import type { TextColors } from '~components/Typography/BaseText/types';
6+
import type { Platform } from '~utils';
67

78
export type InfoGroupProps = {
89
/**
@@ -32,10 +33,13 @@ export type InfoGroupProps = {
3233
/**
3334
* Custom grid template columns for the InfoGroup layout
3435
*
36+
* On web this accepts CSS grid template column values (e.g. `'1fr 1fr'`, `'repeat(2, 1fr)'`).
37+
* On native this accepts a string that is parsed to emulate the column count (e.g. `'1fr 1fr'`, `'repeat(2, 1fr)'`).
38+
*
3539
* @default 'max-content 1fr' for horizontal itemOrientation
3640
* @default 'repeat(min(4, ${React.Children.count(children)}), 1fr)' for vertical itemOrientation
3741
*/
38-
gridTemplateColumns?: BoxProps['gridAutoColumns'];
42+
gridTemplateColumns?: Platform.Select<{ web: BoxProps['gridAutoColumns']; native: string }>;
3943

4044
/**
4145
* Children should be InfoItem components

0 commit comments

Comments
 (0)