forked from mrzachnugent/react-native-reusables
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdate-picker.tsx
79 lines (78 loc) · 2.54 KB
/
date-picker.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import { CalendarIcon } from 'lucide-react-native';
import React from 'react';
import { Text, View } from 'react-native';
import {
BottomSheet,
BottomSheetCloseTrigger,
BottomSheetContent,
BottomSheetOpenTrigger,
BottomSheetView,
} from '~/components/ui/bottom-sheet';
import { Button, buttonTextVariants } from '~/components/ui/button';
import { Calendar } from '~/components/ui/calendar';
import { cn } from '~/lib/utils';
export default function DatePickerScreen() {
const [selectedDate, setSelectedDate] = React.useState('');
return (
<View className='flex-1 justify-center items-center'>
<BottomSheet className='px-6'>
<BottomSheetOpenTrigger asChild>
<Button variant='outline' className='gap-3'>
{({ pressed }) => (
<>
<CalendarIcon
className={buttonTextVariants({
variant: 'outline',
className: pressed ? 'opacity-70' : '',
})}
size={21}
/>
<Text
className={buttonTextVariants({
variant: 'outline',
className: pressed ? 'opacity-70' : '',
})}
>
{selectedDate ? selectedDate : 'Pick a date'}
</Text>
</>
)}
</Button>
</BottomSheetOpenTrigger>
<BottomSheetContent>
<BottomSheetView hadHeader={false} className='pt-2'>
<Calendar
style={{ height: 358 }}
onDayPress={(day) => {
setSelectedDate((prev) =>
day.dateString === prev ? '' : day.dateString
);
}}
markedDates={{
[selectedDate]: {
selected: true,
},
}}
current={selectedDate} // opens calendar on selected date
/>
<View className={'pb-2 pt-4'}>
<BottomSheetCloseTrigger asChild>
<Button size='sm'>
{({ pressed }) => (
<Text
className={buttonTextVariants({
className: cn(pressed && 'opacity-70'),
})}
>
Close
</Text>
)}
</Button>
</BottomSheetCloseTrigger>
</View>
</BottomSheetView>
</BottomSheetContent>
</BottomSheet>
</View>
);
}