Skip to content

Commit 0644340

Browse files
Composable Coin Sheet component
1 parent fefd560 commit 0644340

File tree

1 file changed

+74
-0
lines changed

1 file changed

+74
-0
lines changed

packages/app/components/CoinSheet.tsx

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
import { Button, Paragraph, Sheet, type SheetProps, useMedia, XStack, YStack } from '@my/ui'
2+
import { IconCoin } from 'app/components/icons/IconCoin'
3+
import type { coin } from 'app/data/coins'
4+
import type { PropsWithChildren } from 'react'
5+
import { IconX } from './icons'
6+
7+
export const CoinSheet = ({ children, ...props }: PropsWithChildren<SheetProps>) => {
8+
const media = useMedia()
9+
return (
10+
<Sheet
11+
modal={media.lg}
12+
dismissOnSnapToBottom
13+
snapPoints={['fit']}
14+
snapPointsMode="fit"
15+
animation={'quick'}
16+
zIndex={100_000}
17+
{...props}
18+
>
19+
<Sheet.Frame elevation={'$5'} w={'100%'} bc={'$color1'}>
20+
{children}
21+
</Sheet.Frame>
22+
{media.lg ? (
23+
<Sheet.Overlay animation="quick" enterStyle={{ opacity: 0 }} exitStyle={{ opacity: 0 }} />
24+
) : (
25+
<Sheet.Overlay opacity={0} />
26+
)}
27+
</Sheet>
28+
)
29+
}
30+
31+
const Handle = ({ children, onPress }: PropsWithChildren & { onPress: () => void }) => (
32+
<Sheet.Handle py="$6" f={1} bc="transparent" jc={'space-between'} opacity={1} m={0}>
33+
<XStack ai="center" jc="space-between" w="100%" px="$4">
34+
<Paragraph fontSize={'$5'} fontWeight={'700'} color={'$color12'}>
35+
{children}
36+
</Paragraph>
37+
<Button chromeless icon={<IconX color={'$color12'} size={'$2'} />} onPress={onPress} />
38+
</XStack>
39+
</Sheet.Handle>
40+
)
41+
42+
const Item = ({ coin }: { coin: coin }) => {
43+
return (
44+
<XStack gap={'$2'} jc={'space-between'} py="$2" px="$3">
45+
<XStack gap={'$2'} ai={'center'}>
46+
<IconCoin symbol={coin.symbol} />
47+
<Paragraph
48+
fontSize={'$5'}
49+
fontWeight={'500'}
50+
textTransform={'uppercase'}
51+
color={'$color12'}
52+
>
53+
{coin.label}
54+
</Paragraph>
55+
</XStack>
56+
</XStack>
57+
)
58+
}
59+
60+
const Items = ({ children }: PropsWithChildren) => {
61+
return (
62+
<Sheet.ScrollView>
63+
<XStack als="flex-start" w="100%" boc={'transparent'} f={1} jc={'flex-start'}>
64+
<YStack gap="$1" p={'$2'} w="100%">
65+
{children}
66+
</YStack>
67+
</XStack>
68+
</Sheet.ScrollView>
69+
)
70+
}
71+
72+
CoinSheet.Item = Item
73+
CoinSheet.Handle = Handle
74+
CoinSheet.Items = Items

0 commit comments

Comments
 (0)