Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from 'react';
import React, { ReactNode } from 'react';

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

interface Props {
amount: string;
details: string;
details: ReactNode;
detailsColor?: TypographyVariants['color'];
detailsWeight?: FontWeights;
detailsTooltip?: string;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from 'react';
import React, { ReactElement, ReactNode } from 'react';

import { Box } from '../box';
import { Grid, Cell } from '../grid';
Expand All @@ -7,26 +7,42 @@ import { Text } from '../text';

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

interface Props {
imageSrc: string;
name: string;
description: string;
const getImageAlt = ({ alt, name }: { alt?: string; name: ReactNode }) => {
if (alt) return alt;
return typeof name === 'string' ? name : undefined;
};

type TokenProfileProps = {
alt?: string;
image: ReactNode;
name: ReactNode;
description: ReactNode;
testId?: string;
}
};

export const TokenProfile = ({
imageSrc,
alt,
image,
name,
description,
testId = 'token-profile',
}: Readonly<Props>): JSX.Element => {
}: Readonly<TokenProfileProps>): ReactElement => {
const imageNode =
typeof image === 'string' ? (
<Image
imageSrc={image}
alt={getImageAlt({ alt, name })}
testId={`${testId}-icon`}
/>
) : (
image
);

return (
<div className={cx.container} data-testid={testId}>
<Grid columns="$fitContent" gutters="$0">
<Cell>
<Box mr="$24">
<Image imageSrc={imageSrc} alt={name} testId={`${testId}-icon`} />
</Box>
<Box mr="$24">{imageNode}</Box>
</Cell>
<Cell>
<Text.Body.Large weight="$semibold" data-testid={`${testId}-name`}>
Expand Down
8 changes: 4 additions & 4 deletions src/design-system/assets-table/assets-table.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ interface AssetInfoProps {
const SimpleAssetInfo = ({ id }: Readonly<AssetInfoProps>): JSX.Element => (
<AssetsTable id={id}>
<TokenProfile
imageSrc={cardanoImage}
image={cardanoImage}
name="Token name"
description="Subtitle"
/>
Expand All @@ -60,7 +60,7 @@ const SimpleAssetInfo = ({ id }: Readonly<AssetInfoProps>): JSX.Element => (
const PendingAssetInfo = ({ id }: Readonly<AssetInfoProps>): JSX.Element => (
<AssetsTable id={id}>
<TokenProfile
imageSrc={cardanoImage}
image={cardanoImage}
name="Token with pending amount"
description="description"
/>
Expand All @@ -79,7 +79,7 @@ const DetailedAssetInfo = ({
}: Readonly<AssetInfoProps>): JSX.Element => (
<AssetsTable id={id}>
<TokenProfile
imageSrc={cardanoImage}
image={cardanoImage}
name="Token name"
description="Subtitle"
/>
Expand Down Expand Up @@ -200,7 +200,7 @@ export const Controls: Controls = ({
<Flex alignItems="center" flexDirection="column">
<AssetsTable>
<TokenProfile
imageSrc={cardanoImage}
image={cardanoImage}
name={tokenName}
description={tokenSubtitle}
/>
Expand Down