-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* fix(ui): #1744: add `size` prop to `AssetIcon` * fix(ui): #1743: update padding in the `Popover` component * fix(ui): #1744: simplify the `size` of `AssetIcon` * fix(ui): #1744: align the `ValueViewComponent` with the latest designs * chore: changeset
- Loading branch information
Showing
9 changed files
with
106 additions
and
44 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,5 @@ | ||
--- | ||
'@penumbra-zone/ui': patch | ||
--- | ||
|
||
Update UI components: `ValueViewComponent`, `AssetIcon`, and `Popover` |
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
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,37 @@ | ||
import type { Meta, StoryObj } from '@storybook/react'; | ||
|
||
import { AssetIcon } from '.'; | ||
import { | ||
PENUMBRA_METADATA, | ||
DELEGATION_TOKEN_METADATA, | ||
UNBONDING_TOKEN_METADATA, | ||
UNKNOWN_TOKEN_METADATA, | ||
PIZZA_METADATA, | ||
} from '../utils/bufs'; | ||
|
||
const meta: Meta<typeof AssetIcon> = { | ||
component: AssetIcon, | ||
tags: ['autodocs', '!dev'], | ||
argTypes: { | ||
metadata: { | ||
options: ['Penumbra', 'Pizza', 'Delegation token', 'Unbonding token', 'Unknown asset'], | ||
mapping: { | ||
Penumbra: PENUMBRA_METADATA, | ||
Pizza: PIZZA_METADATA, | ||
'Delegation token': DELEGATION_TOKEN_METADATA, | ||
'Unbonding token': UNBONDING_TOKEN_METADATA, | ||
'Unknown asset': UNKNOWN_TOKEN_METADATA, | ||
}, | ||
}, | ||
}, | ||
}; | ||
export default meta; | ||
|
||
type Story = StoryObj<typeof AssetIcon>; | ||
|
||
export const Basic: Story = { | ||
args: { | ||
size: 'md', | ||
metadata: PENUMBRA_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 |
---|---|---|
@@ -1,52 +1,62 @@ | ||
import { ReactNode } from 'react'; | ||
import styled from 'styled-components'; | ||
import { Metadata } from '@penumbra-zone/protobuf/penumbra/core/asset/v1/asset_pb'; | ||
import { Identicon } from '../Identicon'; | ||
import { DelegationTokenIcon } from './DelegationTokenIcon'; | ||
import { getDisplay } from '@penumbra-zone/getters/metadata'; | ||
import { assetPatterns } from '@penumbra-zone/types/assets'; | ||
import { Identicon } from '../Identicon'; | ||
import { DelegationTokenIcon } from './DelegationTokenIcon'; | ||
import { UnbondingTokenIcon } from './UnbondingTokenIcon'; | ||
import styled from 'styled-components'; | ||
|
||
const BorderWrapper = styled.div` | ||
type Size = 'lg' | 'md' | 'sm'; | ||
|
||
const sizeMap: Record<Size, number> = { | ||
lg: 32, | ||
md: 24, | ||
sm: 16, | ||
}; | ||
|
||
const BorderWrapper = styled.div<{ $size: Size }>` | ||
width: ${props => sizeMap[props.$size]}px; | ||
height: ${props => sizeMap[props.$size]}px; | ||
border-radius: ${props => props.theme.borderRadius.full}; | ||
border: 1px solid ${props => props.theme.color.other.tonalStroke}; | ||
overflow: hidden; | ||
& > * { | ||
width: 100%; | ||
height: 100%; | ||
} | ||
`; | ||
|
||
const IconImg = styled.img` | ||
display: block; | ||
width: 24px; | ||
height: 24px; | ||
`; | ||
|
||
export interface AssetIcon { | ||
export interface AssetIconProps { | ||
size?: Size; | ||
metadata?: Metadata; | ||
} | ||
|
||
export const AssetIcon = ({ metadata }: AssetIcon) => { | ||
export const AssetIcon = ({ metadata, size = 'md' }: AssetIconProps) => { | ||
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing -- possibly empty string | ||
const icon = metadata?.images[0]?.png || metadata?.images[0]?.svg; | ||
const display = getDisplay.optional()(metadata); | ||
const isDelegationToken = display ? assetPatterns.delegationToken.matches(display) : false; | ||
const isUnbondingToken = display ? assetPatterns.unbondingToken.matches(display) : false; | ||
|
||
return ( | ||
<BorderWrapper> | ||
{/* eslint-disable-next-line no-nested-ternary -- readable ternary */} | ||
{icon ? ( | ||
<IconImg src={icon} alt='Asset icon' /> | ||
) : // eslint-disable-next-line no-nested-ternary -- readable ternary | ||
isDelegationToken ? ( | ||
<DelegationTokenIcon displayDenom={display} /> | ||
) : isUnbondingToken ? ( | ||
/** | ||
* @todo: Render a custom unbonding token for validators that have a | ||
* logo -- e.g., with the validator ID superimposed over the validator | ||
* logo. | ||
*/ | ||
<UnbondingTokenIcon displayDenom={display} /> | ||
) : ( | ||
<Identicon uniqueIdentifier={metadata?.symbol ?? '?'} size={24} type='solid' /> | ||
)} | ||
</BorderWrapper> | ||
); | ||
let assetIcon: ReactNode; | ||
if (icon) { | ||
assetIcon = <IconImg src={icon} alt='Asset icon' />; | ||
} else if (isDelegationToken) { | ||
assetIcon = <DelegationTokenIcon displayDenom={display} />; | ||
} else if (isUnbondingToken) { | ||
/** | ||
* @todo: Render a custom unbonding token for validators that have a | ||
* logo -- e.g., with the validator ID superimposed over the validator logo. | ||
*/ | ||
assetIcon = <UnbondingTokenIcon displayDenom={display} />; | ||
} else { | ||
assetIcon = <Identicon uniqueIdentifier={metadata?.symbol ?? '?'} type='solid' />; | ||
} | ||
|
||
return <BorderWrapper $size={size}>{assetIcon}</BorderWrapper>; | ||
}; |
Empty file.
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
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