react-native-ll-calendar 0.3.0 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +43 -32
- package/lib/module/calendar/month-calendar/MonthCalendar.js +20 -38
- package/lib/module/calendar/month-calendar/MonthCalendar.js.map +1 -1
- package/lib/module/calendar/month-calendar/logic/useEvents.js +3 -7
- package/lib/module/calendar/month-calendar/logic/useEvents.js.map +1 -1
- package/lib/module/calendar/month-calendar/view/MonthCalendarViewItem.js +24 -42
- package/lib/module/calendar/month-calendar/view/MonthCalendarViewItem.js.map +1 -1
- package/lib/module/calendar/month-calendar/view/MonthCalendarWeekDayRow.js +62 -0
- package/lib/module/calendar/month-calendar/view/MonthCalendarWeekDayRow.js.map +1 -0
- package/lib/module/calendar/month-calendar/view/MonthCalendarWeekRow.js +47 -52
- package/lib/module/calendar/month-calendar/view/MonthCalendarWeekRow.js.map +1 -1
- package/lib/typescript/src/calendar/month-calendar/MonthCalendar.d.ts +3 -1
- package/lib/typescript/src/calendar/month-calendar/MonthCalendar.d.ts.map +1 -1
- package/lib/typescript/src/calendar/month-calendar/logic/useEvents.d.ts.map +1 -1
- package/lib/typescript/src/calendar/month-calendar/view/MonthCalendarViewItem.d.ts +3 -1
- package/lib/typescript/src/calendar/month-calendar/view/MonthCalendarViewItem.d.ts.map +1 -1
- package/lib/typescript/src/calendar/month-calendar/view/MonthCalendarWeekDayRow.d.ts +11 -0
- package/lib/typescript/src/calendar/month-calendar/view/MonthCalendarWeekDayRow.d.ts.map +1 -0
- package/lib/typescript/src/calendar/month-calendar/view/MonthCalendarWeekRow.d.ts +4 -4
- package/lib/typescript/src/calendar/month-calendar/view/MonthCalendarWeekRow.d.ts.map +1 -1
- package/lib/typescript/src/types/month-calendar.d.ts +3 -0
- package/lib/typescript/src/types/month-calendar.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/calendar/month-calendar/MonthCalendar.tsx +23 -39
- package/src/calendar/month-calendar/logic/useEvents.tsx +3 -5
- package/src/calendar/month-calendar/view/MonthCalendarViewItem.tsx +36 -41
- package/src/calendar/month-calendar/view/MonthCalendarWeekDayRow.tsx +79 -0
- package/src/calendar/month-calendar/view/MonthCalendarWeekRow.tsx +68 -81
- package/src/types/month-calendar.ts +3 -0
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import dayjs from 'dayjs';
|
|
2
|
+
import en from 'dayjs/locale/en';
|
|
3
|
+
import { StyleSheet } from 'react-native';
|
|
4
|
+
import { Text, View, type ViewStyle } from 'react-native';
|
|
5
|
+
import type { WeekdayNum } from '../../../types/month-calendar';
|
|
6
|
+
import { CELL_BORDER_WIDTH } from '../../../constants/size';
|
|
7
|
+
import type { TextStyle } from 'react-native';
|
|
8
|
+
|
|
9
|
+
export const MonthCalendarWeekDayRow = (props: {
|
|
10
|
+
locale?: ILocale;
|
|
11
|
+
dates: dayjs.Dayjs[];
|
|
12
|
+
weekdayCellContainerStyle?: (weekDayNum: WeekdayNum) => ViewStyle;
|
|
13
|
+
weekdayCellTextStyle?: (weekDayNum: WeekdayNum) => TextStyle;
|
|
14
|
+
}) => {
|
|
15
|
+
return (
|
|
16
|
+
<View style={styles.container}>
|
|
17
|
+
{props.dates.map((djs, dateIndex) => {
|
|
18
|
+
const text = djs.locale(props.locale ?? en).format('ddd');
|
|
19
|
+
|
|
20
|
+
return (
|
|
21
|
+
<View
|
|
22
|
+
key={djs.get('d')}
|
|
23
|
+
style={[styles.dayCellCountainer, { zIndex: 7 - dateIndex }]}
|
|
24
|
+
>
|
|
25
|
+
<View
|
|
26
|
+
style={[
|
|
27
|
+
styles.dayCellInner,
|
|
28
|
+
props.weekdayCellContainerStyle?.(djs.day()),
|
|
29
|
+
]}
|
|
30
|
+
/>
|
|
31
|
+
<View style={styles.dayCellLabel}>
|
|
32
|
+
<Text
|
|
33
|
+
style={[
|
|
34
|
+
styles.dayCellText,
|
|
35
|
+
props.weekdayCellTextStyle?.(djs.day()),
|
|
36
|
+
]}
|
|
37
|
+
>
|
|
38
|
+
{text}
|
|
39
|
+
</Text>
|
|
40
|
+
</View>
|
|
41
|
+
</View>
|
|
42
|
+
);
|
|
43
|
+
})}
|
|
44
|
+
</View>
|
|
45
|
+
);
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
const styles = StyleSheet.create({
|
|
49
|
+
container: {
|
|
50
|
+
width: '100%',
|
|
51
|
+
display: 'flex',
|
|
52
|
+
flexDirection: 'row',
|
|
53
|
+
flex: 1,
|
|
54
|
+
backgroundColor: 'white',
|
|
55
|
+
},
|
|
56
|
+
dayCellCountainer: {
|
|
57
|
+
flex: 1,
|
|
58
|
+
borderRightWidth: CELL_BORDER_WIDTH,
|
|
59
|
+
borderBottomWidth: CELL_BORDER_WIDTH,
|
|
60
|
+
borderColor: 'lightslategrey',
|
|
61
|
+
backgroundColor: 'white',
|
|
62
|
+
position: 'relative',
|
|
63
|
+
},
|
|
64
|
+
dayCellInner: {
|
|
65
|
+
position: 'absolute',
|
|
66
|
+
top: 0,
|
|
67
|
+
left: 0,
|
|
68
|
+
right: 0,
|
|
69
|
+
bottom: 0,
|
|
70
|
+
},
|
|
71
|
+
dayCellLabel: {
|
|
72
|
+
paddingVertical: 1,
|
|
73
|
+
paddingHorizontal: 2,
|
|
74
|
+
},
|
|
75
|
+
dayCellText: {
|
|
76
|
+
textAlign: 'center',
|
|
77
|
+
fontSize: 12,
|
|
78
|
+
},
|
|
79
|
+
});
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import dayjs from 'dayjs';
|
|
2
|
-
import en from 'dayjs/locale/en';
|
|
3
2
|
import { StyleSheet, useWindowDimensions } from 'react-native';
|
|
4
3
|
import { Text, TouchableOpacity, View, type ViewStyle } from 'react-native';
|
|
5
4
|
import type { CalendarEvent, WeekdayNum } from '../../../types/month-calendar';
|
|
@@ -9,76 +8,55 @@ import type { TextStyle } from 'react-native';
|
|
|
9
8
|
|
|
10
9
|
export const MonthCalendarWeekRow = (props: {
|
|
11
10
|
dates: dayjs.Dayjs[];
|
|
12
|
-
|
|
13
|
-
events?: CalendarEvent[];
|
|
11
|
+
events: CalendarEvent[];
|
|
14
12
|
eventPosition?: MonthCalendarEventPosition;
|
|
15
13
|
onPressEvent?: (event: CalendarEvent) => void;
|
|
14
|
+
onLongPressEvent?: (event: CalendarEvent) => void;
|
|
15
|
+
delayLongPressEvent?: number;
|
|
16
16
|
onPressCell?: (date: Date) => void;
|
|
17
17
|
onLongPressCell?: (date: Date) => void;
|
|
18
|
-
|
|
18
|
+
delayLongPressCell?: number;
|
|
19
19
|
dayCellContainerStyle?: (date: Date) => ViewStyle;
|
|
20
20
|
dayCellTextStyle?: (date: Date) => TextStyle;
|
|
21
|
-
locale?: ILocale;
|
|
22
21
|
weekdayCellContainerStyle?: (weekDayNum: WeekdayNum) => ViewStyle;
|
|
23
22
|
weekdayCellTextStyle?: (weekDayNum: WeekdayNum) => TextStyle;
|
|
24
23
|
weekRowMinHeight?: number;
|
|
25
24
|
todayCellTextStyle?: TextStyle;
|
|
26
25
|
}) => {
|
|
27
|
-
const {
|
|
28
|
-
dates,
|
|
29
|
-
isWeekdayHeader,
|
|
30
|
-
events = [],
|
|
31
|
-
eventPosition,
|
|
32
|
-
onPressEvent,
|
|
33
|
-
onPressCell,
|
|
34
|
-
onLongPressCell,
|
|
35
|
-
delayLongPress = 500,
|
|
36
|
-
dayCellContainerStyle,
|
|
37
|
-
dayCellTextStyle,
|
|
38
|
-
locale = en,
|
|
39
|
-
weekdayCellContainerStyle,
|
|
40
|
-
weekdayCellTextStyle,
|
|
41
|
-
weekRowMinHeight,
|
|
42
|
-
todayCellTextStyle,
|
|
43
|
-
} = props;
|
|
44
26
|
const eventHeight = 26;
|
|
45
27
|
const { width: screenWidth } = useWindowDimensions();
|
|
46
28
|
const dateColumnWidth = screenWidth / 7;
|
|
47
|
-
const weekId = dates[0]?.format('YYYY-MM-DD');
|
|
48
|
-
if (weekId && eventPosition) {
|
|
49
|
-
eventPosition.resetResource(weekId);
|
|
29
|
+
const weekId = props.dates[0]?.format('YYYY-MM-DD');
|
|
30
|
+
if (weekId && props.eventPosition) {
|
|
31
|
+
props.eventPosition.resetResource(weekId);
|
|
50
32
|
}
|
|
51
33
|
|
|
52
34
|
return (
|
|
53
35
|
<View style={styles.container}>
|
|
54
|
-
{dates.map((djs, dateIndex) => {
|
|
55
|
-
const text =
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
.
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
const aEndDjs = dayjs(a.end);
|
|
72
|
-
const bEndDjs = dayjs(b.end);
|
|
73
|
-
const aDiffDays = aEndDjs.diff(aStartDjs, 'day');
|
|
74
|
-
const bDiffDays = bEndDjs.diff(bStartDjs, 'day');
|
|
36
|
+
{props.dates.map((djs, dateIndex) => {
|
|
37
|
+
const text = djs.format('D');
|
|
38
|
+
const filteredEvents = props.events
|
|
39
|
+
?.filter((event) => {
|
|
40
|
+
const startDjs = dayjs(event.start);
|
|
41
|
+
return (
|
|
42
|
+
startDjs.format('YYYY-MM-DD') === djs.format('YYYY-MM-DD') ||
|
|
43
|
+
(dateIndex === 0 && startDjs.isBefore(djs))
|
|
44
|
+
);
|
|
45
|
+
})
|
|
46
|
+
.sort((a, b) => {
|
|
47
|
+
const aStartDjs = dateIndex === 0 ? djs : dayjs(a.start);
|
|
48
|
+
const bStartDjs = dateIndex === 0 ? djs : dayjs(b.start);
|
|
49
|
+
const aEndDjs = dayjs(a.end);
|
|
50
|
+
const bEndDjs = dayjs(b.end);
|
|
51
|
+
const aDiffDays = aEndDjs.diff(aStartDjs, 'day');
|
|
52
|
+
const bDiffDays = bEndDjs.diff(bStartDjs, 'day');
|
|
75
53
|
|
|
76
|
-
|
|
77
|
-
|
|
54
|
+
return bDiffDays - aDiffDays;
|
|
55
|
+
});
|
|
78
56
|
|
|
79
|
-
const
|
|
80
|
-
if (weekId && eventPosition) {
|
|
81
|
-
const rowNums = eventPosition.getRowNums({
|
|
57
|
+
const events: (CalendarEvent | number)[] = [];
|
|
58
|
+
if (weekId && props.eventPosition) {
|
|
59
|
+
const rowNums = props.eventPosition.getRowNums({
|
|
82
60
|
weekId,
|
|
83
61
|
date: djs.toDate(),
|
|
84
62
|
});
|
|
@@ -86,11 +64,11 @@ export const MonthCalendarWeekRow = (props: {
|
|
|
86
64
|
let eventIndex = 0;
|
|
87
65
|
for (let ii = 1; ii <= rowsLength; ii++) {
|
|
88
66
|
if (rowNums.includes(ii)) {
|
|
89
|
-
|
|
67
|
+
events.push(ii);
|
|
90
68
|
} else {
|
|
91
69
|
const event = filteredEvents[eventIndex];
|
|
92
70
|
if (event) {
|
|
93
|
-
|
|
71
|
+
events.push(event);
|
|
94
72
|
}
|
|
95
73
|
eventIndex++;
|
|
96
74
|
}
|
|
@@ -98,56 +76,52 @@ export const MonthCalendarWeekRow = (props: {
|
|
|
98
76
|
}
|
|
99
77
|
return (
|
|
100
78
|
<TouchableOpacity
|
|
101
|
-
key={
|
|
79
|
+
key={djs.get('date')}
|
|
102
80
|
style={[
|
|
103
81
|
styles.dayCellCountainer,
|
|
104
|
-
{ minHeight:
|
|
82
|
+
{ minHeight: props.weekRowMinHeight },
|
|
105
83
|
{ zIndex: 7 - dateIndex },
|
|
106
84
|
]}
|
|
107
85
|
onPress={() => {
|
|
108
|
-
onPressCell?.(djs.toDate());
|
|
86
|
+
props.onPressCell?.(djs.toDate());
|
|
109
87
|
}}
|
|
110
88
|
onLongPress={() => {
|
|
111
|
-
onLongPressCell?.(djs.toDate());
|
|
89
|
+
props.onLongPressCell?.(djs.toDate());
|
|
112
90
|
}}
|
|
113
|
-
delayLongPress={
|
|
91
|
+
delayLongPress={props.delayLongPressCell}
|
|
114
92
|
>
|
|
115
93
|
<View
|
|
116
94
|
style={[
|
|
117
95
|
styles.dayCellInner,
|
|
118
|
-
|
|
119
|
-
? weekdayCellContainerStyle?.(djs.day())
|
|
120
|
-
: dayCellContainerStyle?.(djs.toDate()),
|
|
96
|
+
props.dayCellContainerStyle?.(djs.toDate()),
|
|
121
97
|
]}
|
|
122
98
|
/>
|
|
123
99
|
<View style={styles.dayCellLabel}>
|
|
124
100
|
<Text
|
|
125
101
|
style={[
|
|
126
102
|
styles.dayCellText,
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
!isWeekdayHeader && dayjs(djs).isSame(dayjs(), 'day')
|
|
131
|
-
? todayCellTextStyle
|
|
103
|
+
props.dayCellTextStyle?.(djs.toDate()),
|
|
104
|
+
dayjs(djs).isSame(dayjs(), 'day')
|
|
105
|
+
? props.todayCellTextStyle
|
|
132
106
|
: {},
|
|
133
107
|
]}
|
|
134
108
|
>
|
|
135
109
|
{text}
|
|
136
110
|
</Text>
|
|
137
111
|
</View>
|
|
138
|
-
{
|
|
139
|
-
if (typeof
|
|
112
|
+
{events.map((event, rowIndex) => {
|
|
113
|
+
if (typeof event === 'number') {
|
|
140
114
|
return (
|
|
141
115
|
<View
|
|
142
|
-
key={
|
|
116
|
+
key={event}
|
|
143
117
|
style={{ height: eventHeight, marginBottom: EVENT_GAP }}
|
|
144
118
|
/>
|
|
145
119
|
);
|
|
146
120
|
}
|
|
147
121
|
|
|
148
|
-
const rawStartDjs = dayjs(
|
|
149
|
-
const startDjs = dateIndex === 0 ? djs : dayjs(
|
|
150
|
-
const endDjs = dayjs(
|
|
122
|
+
const rawStartDjs = dayjs(event.start);
|
|
123
|
+
const startDjs = dateIndex === 0 ? djs : dayjs(event.start);
|
|
124
|
+
const endDjs = dayjs(event.end);
|
|
151
125
|
const diffDays = endDjs
|
|
152
126
|
.startOf('day')
|
|
153
127
|
.diff(startDjs.startOf('day'), 'day');
|
|
@@ -162,10 +136,10 @@ export const MonthCalendarWeekRow = (props: {
|
|
|
162
136
|
width += EVENT_GAP + 1;
|
|
163
137
|
}
|
|
164
138
|
|
|
165
|
-
const isLastRow = rowIndex ===
|
|
139
|
+
const isLastRow = rowIndex === events.length - 1;
|
|
166
140
|
|
|
167
|
-
if (eventPosition && weekId) {
|
|
168
|
-
eventPosition.push({
|
|
141
|
+
if (props.eventPosition && weekId) {
|
|
142
|
+
props.eventPosition.push({
|
|
169
143
|
weekId,
|
|
170
144
|
startDate: startDjs.toDate(),
|
|
171
145
|
days: diffDays + 1,
|
|
@@ -175,28 +149,41 @@ export const MonthCalendarWeekRow = (props: {
|
|
|
175
149
|
|
|
176
150
|
return (
|
|
177
151
|
<TouchableOpacity
|
|
178
|
-
key={
|
|
152
|
+
key={event.id}
|
|
179
153
|
style={[
|
|
180
154
|
styles.event,
|
|
181
155
|
{
|
|
182
|
-
backgroundColor:
|
|
183
|
-
borderColor:
|
|
156
|
+
backgroundColor: event.backgroundColor,
|
|
157
|
+
borderColor: event.borderColor,
|
|
184
158
|
width: width,
|
|
185
159
|
height: eventHeight,
|
|
160
|
+
...(event.borderStyle !== undefined && {
|
|
161
|
+
borderStyle: event.borderStyle,
|
|
162
|
+
}),
|
|
163
|
+
...(event.borderWidth !== undefined && {
|
|
164
|
+
borderWidth: event.borderWidth,
|
|
165
|
+
}),
|
|
166
|
+
...(event.borderRadius !== undefined && {
|
|
167
|
+
borderRadius: event.borderRadius,
|
|
168
|
+
}),
|
|
186
169
|
},
|
|
187
170
|
isPrevDateEvent ? styles.prevDateEvent : {},
|
|
188
171
|
isLastRow ? styles.lastRowEvent : {},
|
|
189
172
|
]}
|
|
190
173
|
onPress={() => {
|
|
191
|
-
onPressEvent?.(
|
|
174
|
+
props.onPressEvent?.(event);
|
|
175
|
+
}}
|
|
176
|
+
onLongPress={() => {
|
|
177
|
+
props.onLongPressEvent?.(event);
|
|
192
178
|
}}
|
|
179
|
+
delayLongPress={props.delayLongPressEvent}
|
|
193
180
|
>
|
|
194
181
|
<Text
|
|
195
182
|
numberOfLines={1}
|
|
196
183
|
ellipsizeMode="tail"
|
|
197
|
-
style={[styles.eventTitle, { color:
|
|
184
|
+
style={[styles.eventTitle, { color: event.color }]}
|
|
198
185
|
>
|
|
199
|
-
{
|
|
186
|
+
{event.title}
|
|
200
187
|
</Text>
|
|
201
188
|
</TouchableOpacity>
|
|
202
189
|
);
|