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

Example header #78

Merged
merged 2 commits into from
May 30, 2024
Merged
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
108 changes: 77 additions & 31 deletions examples/components/src/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,8 @@ import {
Image,
Text,
GradientAvatar,
Select,
truncateAddress,
NetworkImage,
IconButton,
CloseIcon,
Card,
Button,
ChevronDownIcon,
Expand Down Expand Up @@ -72,21 +69,23 @@ const AccountMenu = () => {
paddingX="4"
paddingY="3"
cursor="pointer"
gap="2"
alignItems="center"
userSelect="none"
opacity={{ hover: '80' }}
style={{ height: 52 }}
>
<Box gap="2" alignItems="center">
<Box flexDirection="column">
<Box flexDirection="row" gap="2" justifyContent="flex-end" alignItems="center">
<GradientAvatar address={String(address)} size="sm" />
<Text variant="normal" fontWeight="bold" color="text100">
{truncateAddress(String(address), 4)}
</Text>
</Box>
<Box flexDirection="column">
<Box flexDirection="row" gap="2" justifyContent="flex-end" alignItems="center">
<GradientAvatar address={String(address)} size="sm" />
<Text variant="normal" fontWeight="bold" color="text100">
{truncateAddress(String(address), 4)}
</Text>
</Box>
</Box>

<Box color="text50">
<ChevronDownIcon />
</Box>
<Box color="text50">
<ChevronDownIcon />
</Box>
</Box>
</PopoverPrimitive.Trigger>
Expand All @@ -102,10 +101,6 @@ const AccountMenu = () => {
padding="2"
style={{ minWidth: 360 }}
>
{/* <PopoverPrimitive.Close asChild>
<IconButton icon={CloseIcon} size="xs" position="absolute" top="4" right="4" />
</PopoverPrimitive.Close> */}

<Card>
<Box alignItems="center" justifyContent="space-between">
<Text variant="normal" fontWeight="bold" color="text100">
Expand Down Expand Up @@ -142,22 +137,73 @@ const AccountMenu = () => {
const NetworkSelect = () => {
const chainId = useChainId()
const { switchChain } = useSwitchChain()
const [isOpen, toggleOpen] = useState(false)

return (
<Select
name="chainId"
labelLocation="top"
onValueChange={value => switchChain({ chainId: Number(value) })}
value={String(chainId)}
options={Object.values(networks).map(network => ({
label: (
<PopoverPrimitive.Root open={isOpen} onOpenChange={toggleOpen}>
<PopoverPrimitive.Trigger asChild>
<Box
borderColor={isOpen ? 'borderFocus' : 'borderNormal'}
borderWidth="thin"
borderStyle="solid"
borderRadius="md"
paddingX="4"
paddingY="3"
cursor="pointer"
gap="2"
alignItems="center"
userSelect="none"
opacity={{ hover: '80' }}
style={{ height: 52 }}
>
<Box alignItems="center" gap="2">
<NetworkImage chainId={network.chainId} size="sm" />
<Text display={{ sm: 'none', lg: 'block' }}>{network.title!}</Text>
<NetworkImage chainId={chainId} size="sm" />
<Text display={{ sm: 'none', lg: 'block' }} variant="normal" fontWeight="bold" color="text100">
{networks.find(x => x.chainId === chainId)!.title}
</Text>
</Box>
),
value: String(network.chainId)
}))}
/>

<Box color="text50">
<ChevronDownIcon />
</Box>
</Box>
</PopoverPrimitive.Trigger>

{isOpen && (
<PopoverPrimitive.Portal>
<PopoverPrimitive.Content side="bottom" sideOffset={8} align="end" asChild>
<Card
zIndex="20"
background="backgroundRaised"
backdropFilter="blur"
position="relative"
padding="2"
flexDirection="column"
gap="2"
>
{networks.map(({ chainId, title }) => (
<Button
key={chainId}
width="full"
shape="square"
onClick={() => {
switchChain({ chainId })
toggleOpen(false)
}}
leftIcon={() => <NetworkImage chainId={chainId} size="sm" />}
label={
<Box alignItems="center" gap="2">
<Text variant="normal" fontWeight="bold" color="text100">
{title}
</Text>
</Box>
}
/>
))}
</Card>
</PopoverPrimitive.Content>
</PopoverPrimitive.Portal>
)}
</PopoverPrimitive.Root>
)
}