-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: convert widget into compound components
- Loading branch information
1 parent
088249e
commit 4d77d8c
Showing
5 changed files
with
100 additions
and
97 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
35 changes: 24 additions & 11 deletions
35
apps/mobile/src/components/widgets/collectibles/collectibles-widget.tsx
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,34 +1,47 @@ | ||
import React from 'react'; | ||
import { ScrollView } from 'react-native-gesture-handler'; | ||
|
||
import { t } from '@lingui/macro'; | ||
import { useTheme } from '@shopify/restyle'; | ||
|
||
import { Money } from '@leather.io/models'; | ||
import { CollectibleCard, CollectibleCardProps } from '@leather.io/ui/native'; | ||
import { CollectibleCard, CollectibleCardProps, Theme } from '@leather.io/ui/native'; | ||
|
||
import { Widget, WidgetHeader } from '../components/widget'; | ||
import { Widget } from '../components/widget'; | ||
|
||
interface CollectiblesWidgetProps { | ||
collectibles: CollectibleCardProps[]; | ||
totalBalance: Money; | ||
} | ||
|
||
export function CollectiblesWidget({ collectibles, totalBalance }: CollectiblesWidgetProps) { | ||
const theme = useTheme<Theme>(); | ||
|
||
return ( | ||
<Widget | ||
header={ | ||
<WidgetHeader | ||
<Widget> | ||
<Widget.Header> | ||
<Widget.Title | ||
title={t({ | ||
id: 'collectibles.header_title', | ||
message: 'My collectibles', | ||
})} | ||
totalBalance={totalBalance} | ||
/> | ||
} | ||
scrollDirection="horizontal" | ||
> | ||
{collectibles.map((collectible: CollectibleCardProps, index) => ( | ||
<CollectibleCard key={index} {...collectible} /> | ||
))} | ||
</Widget.Header> | ||
<Widget.Body> | ||
<ScrollView | ||
horizontal | ||
showsHorizontalScrollIndicator | ||
contentContainerStyle={{ | ||
gap: theme.spacing['3'], | ||
paddingHorizontal: theme.spacing['5'], | ||
}} | ||
> | ||
{collectibles.map((collectible: CollectibleCardProps, index) => ( | ||
<CollectibleCard key={index} {...collectible} /> | ||
))} | ||
</ScrollView> | ||
</Widget.Body> | ||
</Widget> | ||
); | ||
} |
37 changes: 14 additions & 23 deletions
37
apps/mobile/src/components/widgets/components/widget/widget-header.tsx
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,35 +1,26 @@ | ||
import { Money } from '@leather.io/models'; | ||
import { Box, SheetRef, TouchableOpacity } from '@leather.io/ui/native'; | ||
import { ReactNode } from 'react'; | ||
|
||
import { WidgetTitle } from './widget-title'; | ||
import { Box, TouchableOpacity } from '@leather.io/ui/native'; | ||
|
||
interface WidgetHeaderProps { | ||
title: string; | ||
sheetRef?: React.RefObject<SheetRef>; | ||
sheet?: React.ReactNode; | ||
totalBalance?: Money; | ||
children: ReactNode; | ||
onPress?(): void; | ||
} | ||
|
||
export function WidgetHeader({ title, totalBalance, sheetRef, sheet }: WidgetHeaderProps) { | ||
if (sheet && sheetRef) { | ||
export function WidgetHeader({ children, onPress }: WidgetHeaderProps) { | ||
if (onPress) { | ||
return ( | ||
<> | ||
<TouchableOpacity | ||
onPress={() => sheetRef.current?.present()} | ||
flexDirection="row" | ||
gap="1" | ||
alignItems="center" | ||
> | ||
<WidgetTitle title={title} totalBalance={totalBalance} /> | ||
</TouchableOpacity> | ||
|
||
{sheet} | ||
</> | ||
<TouchableOpacity onPress={onPress}> | ||
<Box flexDirection="row" gap="1" alignItems="center" px="5"> | ||
{children} | ||
</Box> | ||
</TouchableOpacity> | ||
); | ||
} | ||
|
||
return ( | ||
<Box flexDirection="row" gap="1" alignItems="center" marginHorizontal="5"> | ||
<WidgetTitle title={title} totalBalance={totalBalance} /> | ||
<Box flexDirection="row" gap="1" alignItems="center" px="5"> | ||
{children} | ||
</Box> | ||
); | ||
} |
30 changes: 9 additions & 21 deletions
30
apps/mobile/src/components/widgets/components/widget/widget.tsx
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,30 +1,18 @@ | ||
import { ScrollView } from 'react-native-gesture-handler'; | ||
import { HasChildren } from '@/utils/types'; | ||
|
||
import { useTheme } from '@shopify/restyle'; | ||
import { Box } from '@leather.io/ui/native'; | ||
|
||
import { Box, Theme } from '@leather.io/ui/native'; | ||
import { WidgetHeader } from './widget-header'; | ||
import { WidgetTitle } from './widget-title'; | ||
|
||
interface WidgetProps { | ||
children: React.ReactNode; | ||
header?: React.ReactNode; | ||
scrollDirection?: 'vertical' | 'horizontal'; | ||
} | ||
|
||
export function Widget({ children, header, scrollDirection = 'vertical' }: WidgetProps) { | ||
const theme = useTheme<Theme>(); | ||
export function Widget({ children }: HasChildren) { | ||
return ( | ||
<Box paddingVertical="5" flexDirection="column" gap="3"> | ||
<Box>{header}</Box> | ||
<ScrollView | ||
horizontal={scrollDirection === 'horizontal'} | ||
showsHorizontalScrollIndicator={scrollDirection === 'horizontal' ? false : undefined} | ||
contentContainerStyle={{ gap: theme.spacing['3'], paddingHorizontal: theme.spacing['5'] }} | ||
> | ||
{children} | ||
</ScrollView> | ||
{children} | ||
</Box> | ||
); | ||
} | ||
|
||
// refactor to remove Pressable , fix balance display(reverse for Fiat) + line break | ||
// check if I broke add account | ||
Widget.Header = WidgetHeader; | ||
Widget.Title = WidgetTitle; | ||
Widget.Body = Box; |
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