Skip to content

Commit ee6609d

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

File tree

3 files changed

+33
-17
lines changed

3 files changed

+33
-17
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, { ReactNode } 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: ReactNode;
1515
detailsColor?: TypographyVariants['color'];
1616
detailsWeight?: FontWeights;
1717
detailsTooltip?: string;

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

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

33
import { Box } from '../box';
44
import { Grid, Cell } from '../grid';
@@ -7,26 +7,42 @@ 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 = ({ alt, name }: { alt?: string; name: ReactNode }) => {
11+
if (alt) return alt;
12+
return typeof name === 'string' ? name : undefined;
13+
};
14+
15+
type TokenProfileProps = {
16+
alt?: string;
17+
image: ReactNode;
18+
name: ReactNode;
19+
description: ReactNode;
1420
testId?: string;
15-
}
21+
};
1622

1723
export const TokenProfile = ({
18-
imageSrc,
24+
alt,
25+
image,
1926
name,
2027
description,
2128
testId = 'token-profile',
22-
}: Readonly<Props>): JSX.Element => {
29+
}: Readonly<TokenProfileProps>): ReactElement => {
30+
const imageNode =
31+
typeof image === 'string' ? (
32+
<Image
33+
imageSrc={image}
34+
alt={getImageAlt({ alt, name })}
35+
testId={`${testId}-icon`}
36+
/>
37+
) : (
38+
image
39+
);
40+
2341
return (
2442
<div className={cx.container} data-testid={testId}>
2543
<Grid columns="$fitContent" gutters="$0">
2644
<Cell>
27-
<Box mr="$24">
28-
<Image imageSrc={imageSrc} alt={name} testId={`${testId}-icon`} />
29-
</Box>
45+
<Box mr="$24">{imageNode}</Box>
3046
</Cell>
3147
<Cell>
3248
<Text.Body.Large weight="$semibold" data-testid={`${testId}-name`}>

src/design-system/assets-table/assets-table.stories.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ interface AssetInfoProps {
4949
const SimpleAssetInfo = ({ id }: Readonly<AssetInfoProps>): JSX.Element => (
5050
<AssetsTable id={id}>
5151
<TokenProfile
52-
imageSrc={cardanoImage}
52+
image={cardanoImage}
5353
name="Token name"
5454
description="Subtitle"
5555
/>
@@ -60,7 +60,7 @@ const SimpleAssetInfo = ({ id }: Readonly<AssetInfoProps>): JSX.Element => (
6060
const PendingAssetInfo = ({ id }: Readonly<AssetInfoProps>): JSX.Element => (
6161
<AssetsTable id={id}>
6262
<TokenProfile
63-
imageSrc={cardanoImage}
63+
image={cardanoImage}
6464
name="Token with pending amount"
6565
description="description"
6666
/>
@@ -79,7 +79,7 @@ const DetailedAssetInfo = ({
7979
}: Readonly<AssetInfoProps>): JSX.Element => (
8080
<AssetsTable id={id}>
8181
<TokenProfile
82-
imageSrc={cardanoImage}
82+
image={cardanoImage}
8383
name="Token name"
8484
description="Subtitle"
8585
/>
@@ -200,7 +200,7 @@ export const Controls: Controls = ({
200200
<Flex alignItems="center" flexDirection="column">
201201
<AssetsTable>
202202
<TokenProfile
203-
imageSrc={cardanoImage}
203+
image={cardanoImage}
204204
name={tokenName}
205205
description={tokenSubtitle}
206206
/>

0 commit comments

Comments
 (0)