From 32bb052b02fe6262e9261015c9bd8579f9eec048 Mon Sep 17 00:00:00 2001 From: Corban Riley Date: Tue, 7 Jan 2025 15:47:11 -0500 Subject: [PATCH] TokenImage added to tailwind --- .../TokenImage/TokenImage.stories.tsx | 1 - src/components/TokenImage/TokenImage.tsx | 76 ++++++++++++------- 2 files changed, 47 insertions(+), 30 deletions(-) diff --git a/src/components/TokenImage/TokenImage.stories.tsx b/src/components/TokenImage/TokenImage.stories.tsx index 4b49a2754..7e9e427c4 100644 --- a/src/components/TokenImage/TokenImage.stories.tsx +++ b/src/components/TokenImage/TokenImage.stories.tsx @@ -11,7 +11,6 @@ type Story = StoryObj export const WithImage: Story = { args: { - borderRadius: 'circle', size: 'lg', src: 'https://assets.coingecko.com/coins/images/4713/large/matic-token-icon.png?1624446912', }, diff --git a/src/components/TokenImage/TokenImage.tsx b/src/components/TokenImage/TokenImage.tsx index f82d2584b..dccb9a9b8 100644 --- a/src/components/TokenImage/TokenImage.tsx +++ b/src/components/TokenImage/TokenImage.tsx @@ -1,29 +1,47 @@ -import { clsx } from 'clsx' +import { cva, VariantProps } from 'class-variance-authority' import { memo } from 'react' -import { Box, BoxProps } from '../Box' +import { cn } from '~/utils' + import { Image } from '../Image' import { NetworkImage } from '../NetworkImage' import { Text } from '../Text' -import * as styles from './styles.css' +const NETWORK_IMAGE_SIZE = '40%' +const NETWORK_IMAGE_OFFSET = '-2%' -type TokenImageProps = BoxProps & - styles.RootVariants & { - className?: string - disableAnimation?: boolean - style?: any - src?: string - symbol?: string - withNetwork?: number +const tokenImageVariants = cva( + ['relative', 'flex', 'items-center', 'justify-center', 'flex-shrink-0'], + { + variants: { + size: { + xs: 'w-3 h-3 text-[4px]', + sm: 'w-5 h-5 text-[6px]', + md: 'w-8 h-8 text-[9px]', + lg: 'w-10 h-10 text-[11px]', + xl: 'w-16 h-16 text-[16px]', + }, + }, + defaultVariants: { + size: 'md', + }, } +) -const NETWORK_IMAGE_SIZE = '40%' -const NETWORK_IMAGE_OFFSET = '-2%' +const maskClass = + '[mask-image:radial-gradient(circle_at_82%_82%,transparent_22%,black_0)]' + +interface TokenImageProps + extends React.HTMLAttributes, + VariantProps { + disableAnimation?: boolean + src?: string + symbol?: string + withNetwork?: number +} export const TokenImage = memo((props: TokenImageProps) => { const { - borderRadius = 'circle', className, disableAnimation = false, style, @@ -31,32 +49,33 @@ export const TokenImage = memo((props: TokenImageProps) => { symbol, size = 'md', withNetwork, - ...boxProps + ...rest } = props return ( - {src ? ( ) : ( {symbol?.replace(/\s/, '').slice(0, 4)} @@ -65,8 +84,7 @@ export const TokenImage = memo((props: TokenImageProps) => { {withNetwork && ( { }} /> )} - + ) })