Skip to content

Commit

Permalink
feat: add token avatar skeletons
Browse files Browse the repository at this point in the history
  • Loading branch information
chybisov committed Nov 8, 2022
1 parent 891c325 commit c118e8e
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ export const SelectTokenCardHeader = styled(CardHeader, {
textOverflow: 'ellipsis',
whiteSpace: 'nowrap',
overflow: 'hidden',
width: compact ? (selected ? 92 : 142) : 224,
width: compact ? (selected ? 92 : 142) : 256,
fontWeight: selected ? 500 : 400,
fontSize: compact && !selected ? '1rem' : '1.125rem',
},
[`.${cardHeaderClasses.subheader}`]: {
textOverflow: 'ellipsis',
whiteSpace: 'nowrap',
overflow: 'hidden',
width: compact ? 92 : 224,
width: compact ? 92 : 256,
},
}),
);
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { KeyboardArrowRight as KeyboardArrowRightIcon } from '@mui/icons-material';
import { Skeleton } from '@mui/material';
import { useWatch } from 'react-hook-form';
import { useTranslation } from 'react-i18next';
Expand All @@ -8,7 +7,7 @@ import type { SwapFormTypeProps } from '../../providers';
import { SwapFormKeyHelper, useWidgetConfig } from '../../providers';
import { navigationRoutes } from '../../utils';
import { Card, CardTitle } from '../Card';
import { TokenAvatar } from '../TokenAvatar';
import { TokenAvatar, TokenAvatarSkeleton } from '../TokenAvatar';
import { SelectTokenCardHeader } from './SelectTokenButton.style';

export const SelectTokenButton: React.FC<
Expand Down Expand Up @@ -55,9 +54,12 @@ export const SelectTokenButton: React.FC<
) : (
<SelectTokenCardHeader
avatar={
isSelected ? <TokenAvatar token={token} chain={chain} /> : null
isSelected ? (
<TokenAvatar token={token} chain={chain} />
) : (
<TokenAvatarSkeleton />
)
}
action={!compact ? <KeyboardArrowRightIcon /> : null}
title={isSelected ? token.symbol : defaultTitle}
subheader={
isSelected ? t(`swap.onChain`, { chainName: chain.name }) : null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export const FormPriceHelperText: React.FC<
color={fromAmountTokenPrice ? 'text.secondary' : 'grey.600'}
fontWeight={400}
fontSize={12}
marginLeft={selected ? 8 : 2}
marginLeft={8}
lineHeight={1.3334}
flex={1}
sx={{
Expand Down
6 changes: 4 additions & 2 deletions packages/widget/src/components/SwapInput/SwapInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { SwapFormKeyHelper, useWidgetConfig } from '../../providers';
import { DisabledUI } from '../../types';
import { fitInputText, formatAmount } from '../../utils';
import { Card, CardTitle } from '../Card';
import { TokenAvatar } from '../TokenAvatar';
import { TokenAvatar, TokenAvatarSkeleton } from '../TokenAvatar';
import { FormPriceHelperText } from './FormPriceHelperText';
import {
FormControl,
Expand Down Expand Up @@ -77,7 +77,9 @@ export const SwapInput: React.FC<SwapFormTypeProps> = ({ formType }) => {
startAdornment={
isSelected ? (
<TokenAvatar token={token} chain={chain} sx={{ marginLeft: 2 }} />
) : null
) : (
<TokenAvatarSkeleton sx={{ marginLeft: 2 }} />
)
}
endAdornment={
!disabled ? <SwapInputAdornment formType={formType} /> : undefined
Expand Down
20 changes: 19 additions & 1 deletion packages/widget/src/components/TokenAvatar/TokenAvatar.style.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { AvatarGroup } from '@mui/material';
import { AvatarGroup, Box } from '@mui/material';
import { avatarClasses } from '@mui/material/Avatar';
import { badgeClasses } from '@mui/material/Badge';
import { styled } from '@mui/material/styles';
Expand All @@ -12,3 +12,21 @@ export const TokenAvatarGroup = styled(AvatarGroup)(({ theme }) => ({
marginLeft: theme.spacing(1),
},
}));

export const AvatarSkeleton = styled(Box)(({ theme }) => ({
background:
theme.palette.mode === 'light'
? theme.palette.grey[300]
: theme.palette.grey[800],
border: `2px solid ${theme.palette.background.paper}`,
borderRadius: '50%',
}));

export const AvatarSkeletonContainer = styled(Box)(({ theme }) => ({
border: `2px solid ${
theme.palette.mode === 'light'
? theme.palette.grey[300]
: theme.palette.grey[800]
}`,
borderRadius: '50%',
}));
18 changes: 18 additions & 0 deletions packages/widget/src/components/TokenAvatar/TokenAvatar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import type { SxProps, Theme } from '@mui/material';
import { Avatar, Badge } from '@mui/material';
import { useChain, useToken } from '../../hooks';
import { SmallAvatar } from '../SmallAvatar';
import { AvatarSkeleton, AvatarSkeletonContainer } from './TokenAvatar.style';

export const TokenAvatarFallback: React.FC<{
token: Token;
Expand Down Expand Up @@ -48,3 +49,20 @@ export const TokenAvatar: React.FC<{
}
return <TokenAvatarBase token={token} chain={chain} sx={sx} />;
};

export const TokenAvatarSkeleton: React.FC<{
sx?: SxProps<Theme>;
}> = ({ sx }) => {
return (
<Badge
overlap="circular"
anchorOrigin={{ vertical: 'bottom', horizontal: 'right' }}
badgeContent={<AvatarSkeleton width={16} height={16} />}
sx={sx}
>
<AvatarSkeletonContainer>
<AvatarSkeleton width={28} height={28} />
</AvatarSkeletonContainer>
</Badge>
);
};

0 comments on commit c118e8e

Please sign in to comment.