-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Sofia Cantero
committed
Oct 31, 2024
1 parent
a3223b6
commit b37e76a
Showing
4 changed files
with
124 additions
and
113 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
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,67 @@ | ||
import { useState } from 'react'; | ||
import { Dropdown } from 'react-native-element-dropdown'; | ||
|
||
import { Button, Text, View } from '@/ui'; | ||
|
||
type DropdownItem = { | ||
label: string; | ||
value: number; | ||
}; | ||
|
||
type AddToCartSectionProps = { | ||
setQuantity: React.Dispatch<React.SetStateAction<number>>; | ||
quantity: number; | ||
buy: () => void; | ||
}; | ||
|
||
export const AddToCartSection = ({ | ||
quantity, | ||
setQuantity, | ||
buy, | ||
}: AddToCartSectionProps) => { | ||
const numberItems: DropdownItem[] = Array.from( | ||
{ length: quantity }, | ||
(_, index) => ({ | ||
label: (index + 1).toString(), | ||
value: index + 1, | ||
}) | ||
); | ||
const [selectedValue, setSelectedValue] = useState<string>('1'); | ||
|
||
return ( | ||
<View className="mb-4 flex-row items-center justify-between"> | ||
<View className="items-center"> | ||
<Text className="mb-3 mr-2 font-bold">Quantity</Text> | ||
<Dropdown | ||
style={{ | ||
width: 90, | ||
borderColor: 'black', | ||
borderWidth: 2, | ||
padding: 8, | ||
borderRadius: 8, | ||
height: 43, | ||
marginBottom: 8, | ||
}} | ||
data={numberItems} | ||
labelField="label" | ||
valueField="value" | ||
placeholder="1" | ||
value={selectedValue} | ||
onChange={(item: DropdownItem) => { | ||
setSelectedValue(item.value.toString()); | ||
setQuantity(item.value); | ||
}} | ||
/> | ||
</View> | ||
<View className="w-4/5 items-center"> | ||
<Text className=" mr-2 font-bold">Avalability: {quantity} items</Text> | ||
<Button | ||
className="mt-3 h-12 w-72" | ||
label="Add to cart" | ||
textClassName="font-bold text-base" | ||
onPress={buy} | ||
/> | ||
</View> | ||
</View> | ||
); | ||
}; |
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,47 @@ | ||
import { useState } from 'react'; | ||
import { FlatList } from 'react-native'; | ||
|
||
import { Image, TouchableOpacity, View } from '@/ui'; | ||
|
||
export const ImageDisplayer = ({ | ||
images, | ||
}: { | ||
images: string[] | undefined; | ||
}) => { | ||
const [selectedImage, setSelectedImage] = useState(0); | ||
|
||
if (images === undefined) { | ||
return; | ||
} | ||
|
||
return ( | ||
<> | ||
<View className="h-68 w-68 my-3 w-full rounded-lg"> | ||
<Image | ||
source={{ uri: images[selectedImage] }} | ||
className="h-72 w-full" | ||
contentFit="contain" | ||
/> | ||
</View> | ||
<FlatList | ||
horizontal | ||
showsHorizontalScrollIndicator={false} | ||
data={images} | ||
keyExtractor={(index) => index.toString()} | ||
renderItem={({ item, index }) => ( | ||
<TouchableOpacity | ||
className="mr-4 h-28 w-28 rounded-md" | ||
onPress={() => setSelectedImage(index)} | ||
> | ||
<Image | ||
source={{ uri: item }} | ||
contentFit="contain" | ||
className="h-28 w-28 rounded-md" | ||
/> | ||
</TouchableOpacity> | ||
)} | ||
contentContainerStyle={{ paddingBottom: 16 }} | ||
/> | ||
</> | ||
); | ||
}; |