Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: use grid for asset rows to stop overflow while allowing width, c… #4359

Merged
merged 1 commit into from
Oct 16, 2023
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
20 changes: 20 additions & 0 deletions src/app/components/crypto-assets/components/asset-row-grid.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { Grid, GridItem } from 'leather-styles/jsx';

interface AssetRowGridProps {
title: React.ReactNode;
balance: React.ReactNode;
caption: React.ReactNode;
usdBalance?: React.ReactNode;
}
export function AssetRowGrid({ title, balance, caption, usdBalance }: AssetRowGridProps) {
return (
<Grid columns={2} gridTemplateColumns="2fr 1fr" gridTemplateRows={2} gap={0}>
<GridItem whiteSpace="nowrap" overflow="hidden" textOverflow="ellipsis">
{title}
</GridItem>
<GridItem textAlign="right">{balance}</GridItem>
<GridItem>{caption}</GridItem>
{usdBalance && <GridItem>{usdBalance}</GridItem>}
</Grid>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Flex, StackProps } from '@stacks/ui';
import { forwardRefWithAs } from '@stacks/ui-core';
import { truncateMiddle } from '@stacks/ui-utils';
import { CryptoAssetSelectors } from '@tests/selectors/crypto-asset.selectors';
import { HStack, styled } from 'leather-styles/jsx';
import { styled } from 'leather-styles/jsx';

import { CryptoCurrencies } from '@shared/models/currencies.model';
import { Money } from '@shared/models/money.model';
Expand All @@ -13,6 +13,8 @@ import { usePressable } from '@app/components/item-hover';
import { Flag } from '@app/components/layout/flag';
import { Tooltip } from '@app/components/tooltip';

import { AssetRowGrid } from '../components/asset-row-grid';

interface CryptoCurrencyAssetItemLayoutProps extends StackProps {
balance: Money;
caption: string;
Expand Down Expand Up @@ -67,31 +69,35 @@ export const CryptoCurrencyAssetItemLayout = forwardRefWithAs(
<Flag
align="middle"
img={isHovered && copyIcon ? copyIcon : icon}
spacing="base"
spacing="space.04"
width="100%"
>
<HStack alignItems="center" justifyContent="space-between" width="100%">
<styled.span textStyle="label.01">
{isHovered ? truncateMiddle(address, 6) : title}
</styled.span>
<Tooltip
label={formattedBalance.isAbbreviated ? balance.amount.toString() : undefined}
placement="left-start"
>
<styled.span data-testid={title} textStyle="label.01">
{formattedBalance.value} {additionalBalanceInfo}
<AssetRowGrid
title={
<styled.span textStyle="label.01">
{isHovered ? truncateMiddle(address, 6) : title}
</styled.span>
</Tooltip>
</HStack>
<HStack alignItems="center" justifyContent="space-between" height="1.25rem" width="100%">
<styled.span textStyle="caption.02">{caption}</styled.span>
<Flex>
{balance.amount.toNumber() > 0 && address ? (
<styled.span textStyle="caption.02">{usdBalance}</styled.span>
) : null}
{additionalUsdBalanceInfo}
</Flex>
</HStack>
}
balance={
<Tooltip
label={formattedBalance.isAbbreviated ? balance.amount.toString() : undefined}
placement="left-start"
>
<styled.span data-testid={title} textStyle="label.01">
{formattedBalance.value} {additionalBalanceInfo}
</styled.span>
</Tooltip>
}
caption={<styled.span textStyle="caption.02">{caption}</styled.span>}
usdBalance={
<Flex justifyContent="flex-end">
{balance.amount.toNumber() > 0 && address ? (
<styled.span textStyle="caption.02">{usdBalance}</styled.span>
) : null}
{additionalUsdBalanceInfo}
</Flex>
}
/>
</Flag>
{component}
</Flex>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { BoxProps } from '@stacks/ui';
import { forwardRefWithAs } from '@stacks/ui-core';
import { Flex, HStack, styled } from 'leather-styles/jsx';
import { Flex, styled } from 'leather-styles/jsx';

import type { Money } from '@shared/models/money.model';

Expand All @@ -12,6 +12,7 @@ import { Flag } from '@app/components/layout/flag';
import { Tooltip } from '@app/components/tooltip';

import { AssetCaption } from '../../components/asset-caption';
import { AssetRowGrid } from '../../components/asset-row-grid';

interface StacksFungibleTokenAssetItemLayoutProps extends BoxProps {
avatar: string;
Expand Down Expand Up @@ -45,32 +46,23 @@ export const StacksFungibleTokenAssetItemLayout = forwardRefWithAs(
{title[0]}
</StacksAssetAvatar>
}
spacing="base"
spacing="space.04"
width="100%"
>
<HStack alignItems="center" justifyContent="space-between" width="100%">
<styled.span
maxWidth="150px"
overflow="hidden"
textAlign="left"
textOverflow="ellipsis"
textStyle="label.01"
whiteSpace="nowrap"
>
{title}
</styled.span>
<Tooltip
label={formattedBalance.isAbbreviated ? amount : undefined}
placement="left-start"
>
<styled.span data-testid={title} textStyle="label.01">
{formattedBalance.value}
</styled.span>
</Tooltip>
</HStack>
<HStack alignItems="center" justifyContent="space-between" height="1.25rem" width="100%">
<AssetCaption caption={caption} />
</HStack>
<AssetRowGrid
title={<styled.span textStyle="label.01">{title}</styled.span>}
balance={
<Tooltip
label={formattedBalance.isAbbreviated ? amount : undefined}
placement="left-start"
>
<styled.span data-testid={title} textStyle="label.01">
{formattedBalance.value}
</styled.span>
</Tooltip>
}
caption={<AssetCaption caption={caption} />}
/>
{component}
</Flag>
</Flex>
Expand Down
Loading