-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(ui): #2053: implement
AssetGroup
component
- Loading branch information
Showing
4 changed files
with
89 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import type { Meta, StoryObj } from '@storybook/react'; | ||
|
||
import { | ||
PENUMBRA_METADATA, | ||
PIZZA_METADATA, | ||
USDC_METADATA, | ||
} from '../utils/bufs'; | ||
import { AssetGroup } from '.'; | ||
|
||
const meta: Meta<typeof AssetGroup> = { | ||
title: 'AssetIcon/Group', | ||
component: AssetGroup, | ||
tags: ['autodocs', '!dev'], | ||
}; | ||
export default meta; | ||
|
||
type Story = StoryObj<typeof AssetGroup>; | ||
|
||
export const Overlay: Story = { | ||
args: { | ||
size: 'md', | ||
variant: 'overlay', | ||
assets: [PENUMBRA_METADATA, PIZZA_METADATA, USDC_METADATA], | ||
}, | ||
}; | ||
|
||
export const Split: Story = { | ||
args: { | ||
size: 'md', | ||
variant: 'split', | ||
assets: [PENUMBRA_METADATA, USDC_METADATA], | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import { Metadata } from '@penumbra-zone/protobuf/penumbra/core/asset/v1/asset_pb'; | ||
import { ElementType } from 'react'; | ||
import cn from 'clsx'; | ||
import { Size, AssetIcon } from './index'; | ||
|
||
export interface AssetGroupProps { | ||
assets?: Metadata[]; | ||
as?: ElementType; | ||
size?: Size; | ||
variant?: 'overlay' | 'split'; | ||
} | ||
|
||
const OVERLAY_SIZE_MAP: Record<Size, string> = { | ||
lg: '[&>*:not(:first-child)]:-ml-4', | ||
md: '[&>*:not(:first-child)]:-ml-3', | ||
sm: '[&>*:not(:first-child)]:-ml-2', | ||
}; | ||
|
||
const SPLIT_SIZE_MAP: Record<Size, string> = { | ||
lg: 'w-4 max-w-4', | ||
md: 'w-3 max-w-3', | ||
sm: 'w-2 max-w-2', | ||
}; | ||
|
||
export const AssetGroup = ({ assets, as: Container = 'div', size = 'md', variant = 'overlay' }: AssetGroupProps) => { | ||
if (variant === 'split') { | ||
return (<Container className={cn('relative flex items-center gap-[1px]')}> | ||
{assets?.[0] && ( | ||
<div className={cn(SPLIT_SIZE_MAP[size], 'overflow-hidden')}> | ||
<AssetIcon metadata={assets[0]} size={size} /> | ||
</div> | ||
)} | ||
{assets?.[1] && ( | ||
<div className={cn(SPLIT_SIZE_MAP[size], 'overflow-hidden [&>*]:-translate-x-1/2')}> | ||
<AssetIcon metadata={assets[1]} size={size} /> | ||
</div> | ||
)} | ||
</Container>); | ||
} | ||
|
||
return ( | ||
<Container className={cn('relative flex items-center', OVERLAY_SIZE_MAP[size])}> | ||
{assets?.map((asset, index) => ( | ||
<AssetIcon metadata={asset} key={index} size={size} zIndex={assets.length - index} /> | ||
))} | ||
</Container> | ||
) | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters