Skip to content

Commit acece7f

Browse files
feat: allow passing elements to asset table props
1 parent d6bff02 commit acece7f

File tree

2 files changed

+35
-13
lines changed

2 files changed

+35
-13
lines changed

src/design-system/assets-table/assets-table-token-amount.component.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React from 'react';
1+
import React, { ReactElement } from 'react';
22

33
import { Flex } from '../flex';
44
import { Text } from '../text';
@@ -11,7 +11,7 @@ import type { TypographyVariants } from '../text/text.css';
1111

1212
interface Props {
1313
amount: string;
14-
details: string;
14+
details: string | ReactElement;
1515
detailsColor?: TypographyVariants['color'];
1616
detailsWeight?: FontWeights;
1717
detailsTooltip?: string;

src/design-system/assets-table/assets-table-token-profile.component.tsx

Lines changed: 33 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React from 'react';
1+
import React, { ReactElement } from 'react';
22

33
import { Box } from '../box';
44
import { Grid, Cell } from '../grid';
@@ -7,26 +7,48 @@ import { Text } from '../text';
77

88
import * as cx from './assets-table-token-profile.css';
99

10-
interface Props {
11-
imageSrc: string;
12-
name: string;
13-
description: string;
10+
const getImageAlt = ({
11+
alt,
12+
name,
13+
}: {
14+
alt?: string;
15+
name: string | ReactElement;
16+
}) => {
17+
if (alt) return alt;
18+
return typeof name === 'string' ? name : undefined;
19+
};
20+
21+
type TokenProfileProps = {
22+
alt?: string;
23+
image: string | ReactElement;
24+
name: string | ReactElement;
25+
description: string | ReactElement;
1426
testId?: string;
15-
}
27+
};
1628

1729
export const TokenProfile = ({
18-
imageSrc,
30+
alt,
31+
image,
1932
name,
2033
description,
2134
testId = 'token-profile',
22-
}: Readonly<Props>): JSX.Element => {
35+
}: Readonly<TokenProfileProps>): ReactElement => {
36+
const imageNode =
37+
typeof image === 'string' ? (
38+
<Image
39+
imageSrc={image}
40+
alt={getImageAlt({ alt, name })}
41+
testId={`${testId}-icon`}
42+
/>
43+
) : (
44+
image
45+
);
46+
2347
return (
2448
<div className={cx.container} data-testid={testId}>
2549
<Grid columns="$fitContent" gutters="$0">
2650
<Cell>
27-
<Box mr="$24">
28-
<Image imageSrc={imageSrc} alt={name} testId={`${testId}-icon`} />
29-
</Box>
51+
<Box mr="$24">{imageNode}</Box>
3052
</Cell>
3153
<Cell>
3254
<Text.Body.Large weight="$semibold" data-testid={`${testId}-name`}>

0 commit comments

Comments
 (0)