forked from gabrielmouallem/react-native-big-calendar
-
Notifications
You must be signed in to change notification settings - Fork 1
/
events.tsx
130 lines (124 loc) · 4.11 KB
/
events.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
import dayjs from 'dayjs'
import React from 'react'
import { Text, TouchableOpacity, View } from 'react-native'
import { EventRenderer, ICalendarEventBase } from '../src/interfaces'
import { formatStartEnd } from '../src/utils'
const eventNotes = (
<View style={{ marginTop: 3 }}>
<Text style={{ fontSize: 10, color: 'white' }}> Phone number: 555-123-4567 </Text>
<Text style={{ fontSize: 10, color: 'white' }}> Arrive 15 minutes early </Text>
</View>
)
export const events: Array<ICalendarEventBase & { color?: string }> = [
{
title: 'Watch Boxing',
start: dayjs().set('hour', 0).set('minute', 0).set('second', 0).toDate(),
end: dayjs().set('hour', 1).set('minute', 30).toDate(),
},
{
title: 'Meeting',
start: dayjs().set('hour', 10).set('minute', 0).toDate(),
end: dayjs().set('hour', 10).set('minute', 30).toDate(),
},
{
title: 'Coffee break',
start: dayjs().set('hour', 14).set('minute', 30).toDate(),
end: dayjs().set('hour', 15).set('minute', 30).toDate(),
},
{
title: 'with color prop',
start: dayjs().set('hour', 16).set('minute', 0).toDate(),
end: dayjs().set('hour', 18).set('minute', 30).toDate(),
color: 'purple',
},
{
title: 'Repair my car',
start: dayjs().add(1, 'day').set('hour', 7).set('minute', 45).toDate(),
end: dayjs().add(1, 'day').set('hour', 13).set('minute', 30).toDate(),
},
{
title: 'Meet Realtor',
start: dayjs().add(1, 'day').set('hour', 8).set('minute', 25).toDate(),
end: dayjs().add(1, 'day').set('hour', 9).set('minute', 55).toDate(),
},
{
title: 'Laundry',
start: dayjs().add(1, 'day').set('hour', 8).set('minute', 25).toDate(),
end: dayjs().add(1, 'day').set('hour', 11).set('minute', 0).toDate(),
},
{
title: "Doctor's appointment",
start: dayjs().set('hour', 13).set('minute', 0).toDate(),
end: dayjs().set('hour', 14).set('minute', 15).toDate(),
children: eventNotes,
},
]
export const spanningEvents: Array<ICalendarEventBase & { color?: string }> = [
{
title: 'Watch Boxing',
start: dayjs().subtract(1, 'week').set('hour', 14).set('minute', 30).toDate(),
end: dayjs().subtract(1, 'week').set('hour', 15).set('minute', 30).toDate(),
},
{
title: 'Laundry',
start: dayjs().subtract(1, 'week').set('hour', 1).set('minute', 30).toDate(),
end: dayjs().subtract(1, 'week').set('hour', 2).set('minute', 30).toDate(),
},
{
title: 'Meeting',
start: dayjs().subtract(1, 'week').set('hour', 10).set('minute', 0).toDate(),
end: dayjs().add(1, 'week').set('hour', 10).set('minute', 30).toDate(),
},
{
title: 'Coffee break',
start: dayjs().set('hour', 14).set('minute', 30).toDate(),
end: dayjs().add(1, 'week').set('hour', 15).set('minute', 30).toDate(),
},
{
title: 'Repair my car',
start: dayjs().add(1, 'day').set('hour', 7).set('minute', 45).toDate(),
end: dayjs().add(4, 'day').set('hour', 13).set('minute', 30).toDate(),
},
]
export interface MyCustomEventType extends ICalendarEventBase {
color?: string
}
export const customEventRenderer: EventRenderer<MyCustomEventType> = (
event,
touchableOpacityProps,
) => {
return (
<TouchableOpacity
// {...touchableOpacityProps}
style={[
touchableOpacityProps.style,
{
backgroundColor: 'white',
borderWidth: 1,
borderColor: 'lightgrey',
borderLeftColor: event.color ? event.color : 'green',
borderLeftWidth: 10,
borderStyle: 'solid',
borderRadius: 6,
alignItems: 'center',
justifyContent: 'center',
},
]}
>
{dayjs(event.end).diff(event.start, 'minute') < 32 ? (
<Text style={[{ color: 'black' }]}>
{event.title},
<Text style={[{ color: 'black' }]}>{dayjs(event.start).format('HH:mm')}</Text>
</Text>
) : (
<>
<Text style={[{ color: 'black' }]}>{event.title}</Text>
<Text style={[{ color: 'black' }]}>
{formatStartEnd(event.start, event.end, 'HH:mm')}
</Text>
{event.children && event.children}
</>
)}
</TouchableOpacity>
)
}