Skip to content

Commit dcb61b7

Browse files
Composable Coin Sheet component
1 parent 89c4f87 commit dcb61b7

File tree

1 file changed

+82
-0
lines changed

1 file changed

+82
-0
lines changed

packages/app/components/CoinSheet.tsx

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

0 commit comments

Comments
 (0)