@lazerlen/legend-calendar 1.3.0 → 1.4.1
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/.turbo/turbo-build.log +9 -9
- package/.turbo/turbo-test.log +98 -98
- package/dist/index.d.mts +13 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.js +170 -124
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +170 -124
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/components/CalendarList.stories.tsx +51 -0
- package/src/components/CalendarList.tsx +41 -2
- package/src/hooks/useCalendarList.tsx +6 -0
- package/CHANGELOG.md +0 -127
package/package.json
CHANGED
|
@@ -249,6 +249,57 @@ export const DatePicker = () => {
|
|
|
249
249
|
);
|
|
250
250
|
};
|
|
251
251
|
|
|
252
|
+
export function AutoScrollToActiveRange() {
|
|
253
|
+
const futureDate = addMonths(today, 6);
|
|
254
|
+
const futureDateEnd = addMonths(futureDate, 1);
|
|
255
|
+
|
|
256
|
+
return (
|
|
257
|
+
<VStack grow spacing={20}>
|
|
258
|
+
<Text>
|
|
259
|
+
This calendar has a date range 6 months in the future. It automatically
|
|
260
|
+
scrolls to show the active range on mount.
|
|
261
|
+
</Text>
|
|
262
|
+
<View style={{ flex: 1, width: "100%" }}>
|
|
263
|
+
<Calendar.List
|
|
264
|
+
calendarActiveDateRanges={[
|
|
265
|
+
{
|
|
266
|
+
startId: toDateId(futureDate),
|
|
267
|
+
endId: toDateId(futureDateEnd),
|
|
268
|
+
},
|
|
269
|
+
]}
|
|
270
|
+
onCalendarDayPress={loggingHandler("onCalendarDayPress")}
|
|
271
|
+
/>
|
|
272
|
+
</View>
|
|
273
|
+
</VStack>
|
|
274
|
+
);
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
export function AutoScrollDisabled() {
|
|
278
|
+
const futureDate = addMonths(today, 6);
|
|
279
|
+
const futureDateEnd = addMonths(futureDate, 1);
|
|
280
|
+
|
|
281
|
+
return (
|
|
282
|
+
<VStack grow spacing={20}>
|
|
283
|
+
<Text>
|
|
284
|
+
This calendar has auto-scroll disabled. It opens at the current month
|
|
285
|
+
even though the active range is 6 months in the future.
|
|
286
|
+
</Text>
|
|
287
|
+
<View style={{ flex: 1, width: "100%" }}>
|
|
288
|
+
<Calendar.List
|
|
289
|
+
calendarActiveDateRanges={[
|
|
290
|
+
{
|
|
291
|
+
startId: toDateId(futureDate),
|
|
292
|
+
endId: toDateId(futureDateEnd),
|
|
293
|
+
},
|
|
294
|
+
]}
|
|
295
|
+
calendarInitialScrollToActiveRange={false}
|
|
296
|
+
onCalendarDayPress={loggingHandler("onCalendarDayPress")}
|
|
297
|
+
/>
|
|
298
|
+
</View>
|
|
299
|
+
</VStack>
|
|
300
|
+
);
|
|
301
|
+
}
|
|
302
|
+
|
|
252
303
|
export const TwoCalendarListsMounted = () => {
|
|
253
304
|
return (
|
|
254
305
|
<VStack grow spacing={48}>
|
|
@@ -8,7 +8,12 @@ import { StyleSheet, View } from "react-native";
|
|
|
8
8
|
|
|
9
9
|
import type { CalendarProps } from "@/components/Calendar";
|
|
10
10
|
import { Calendar } from "@/components/Calendar";
|
|
11
|
-
import {
|
|
11
|
+
import {
|
|
12
|
+
fromDateId,
|
|
13
|
+
getWeekOfMonth,
|
|
14
|
+
startOfMonth,
|
|
15
|
+
toDateId,
|
|
16
|
+
} from "@/helpers/dates";
|
|
12
17
|
import type { CalendarMonth } from "@/hooks/useCalendarList";
|
|
13
18
|
import { getHeightForMonth, useCalendarList } from "@/hooks/useCalendarList";
|
|
14
19
|
import { activeDateRangesStore } from "@/hooks/useOptimizedDayMetadata";
|
|
@@ -69,6 +74,20 @@ export interface CalendarListProps
|
|
|
69
74
|
*/
|
|
70
75
|
calendarInitialMonthId?: string;
|
|
71
76
|
|
|
77
|
+
/**
|
|
78
|
+
* When enabled, automatically scrolls to the month containing the start date
|
|
79
|
+
* of the first active range on mount. Only applies when
|
|
80
|
+
* `calendarActiveDateRanges` has at least one range with a `startId`.
|
|
81
|
+
*
|
|
82
|
+
* Takes precedence over `calendarInitialMonthId` when enabled and a valid
|
|
83
|
+
* range exists.
|
|
84
|
+
*
|
|
85
|
+
* Uses `initialScrollIndex` internally, so scrolling only happens on mount.
|
|
86
|
+
*
|
|
87
|
+
* @defaultValue true
|
|
88
|
+
*/
|
|
89
|
+
calendarInitialScrollToActiveRange?: boolean;
|
|
90
|
+
|
|
72
91
|
/**
|
|
73
92
|
* Overwrites the default `Calendar` component.
|
|
74
93
|
*
|
|
@@ -113,6 +132,7 @@ export function CalendarList({
|
|
|
113
132
|
const {
|
|
114
133
|
// List-related props
|
|
115
134
|
calendarInitialMonthId,
|
|
135
|
+
calendarInitialScrollToActiveRange = true,
|
|
116
136
|
calendarPastScrollRangeInMonths = 12,
|
|
117
137
|
calendarFutureScrollRangeInMonths = 12,
|
|
118
138
|
calendarFirstDayOfWeek = "sunday",
|
|
@@ -198,6 +218,25 @@ export function CalendarList({
|
|
|
198
218
|
calendarMinDateId,
|
|
199
219
|
});
|
|
200
220
|
|
|
221
|
+
// Compute the scroll index based on active date range if enabled
|
|
222
|
+
let computedInitialScrollIndex = initialMonthIndex;
|
|
223
|
+
if (calendarInitialScrollToActiveRange && calendarActiveDateRanges) {
|
|
224
|
+
const firstRange = calendarActiveDateRanges[0];
|
|
225
|
+
if (firstRange?.startId) {
|
|
226
|
+
// Convert the startId to the first day of that month
|
|
227
|
+
const startDate = fromDateId(firstRange.startId);
|
|
228
|
+
const monthId = toDateId(startOfMonth(startDate));
|
|
229
|
+
|
|
230
|
+
// Find the index of this month in the monthList
|
|
231
|
+
const monthIndex = monthList.findIndex((month) => month.id === monthId);
|
|
232
|
+
|
|
233
|
+
// Use this index if found, otherwise fall back to initialMonthIndex
|
|
234
|
+
if (monthIndex !== -1) {
|
|
235
|
+
computedInitialScrollIndex = monthIndex;
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
|
|
201
240
|
const monthListWithCalendarProps = monthList.map((month) => ({
|
|
202
241
|
...month,
|
|
203
242
|
calendarProps,
|
|
@@ -320,7 +359,7 @@ export function CalendarList({
|
|
|
320
359
|
drawDistance={560}
|
|
321
360
|
estimatedItemSize={273}
|
|
322
361
|
getFixedItemSize={getFixedItemSize}
|
|
323
|
-
initialScrollIndex={
|
|
362
|
+
initialScrollIndex={computedInitialScrollIndex}
|
|
324
363
|
keyExtractor={keyExtractor}
|
|
325
364
|
maintainVisibleContentPosition
|
|
326
365
|
onEndReached={handleOnEndReached}
|
|
@@ -156,6 +156,9 @@ export const useCalendarList = ({
|
|
|
156
156
|
* Append new months to the list.
|
|
157
157
|
*/
|
|
158
158
|
const appendMonths = (numberOfMonths: number) => {
|
|
159
|
+
if (numberOfMonths <= 0) {
|
|
160
|
+
return monthList;
|
|
161
|
+
}
|
|
159
162
|
// Last month + 1
|
|
160
163
|
const startingMonth = addMonths(monthList[monthList.length - 1].date, 1);
|
|
161
164
|
|
|
@@ -188,6 +191,9 @@ export const useCalendarList = ({
|
|
|
188
191
|
};
|
|
189
192
|
|
|
190
193
|
const prependMonths = (numberOfMonths: number) => {
|
|
194
|
+
if (numberOfMonths <= 0) {
|
|
195
|
+
return monthList;
|
|
196
|
+
}
|
|
191
197
|
const endingMonth = subMonths(monthList[0].date, 1);
|
|
192
198
|
|
|
193
199
|
const startingMonth = getStartingMonth(
|
package/CHANGELOG.md
DELETED
|
@@ -1,127 +0,0 @@
|
|
|
1
|
-
# @marceloterreiro/flash-calendar
|
|
2
|
-
|
|
3
|
-
## 1.0.0
|
|
4
|
-
|
|
5
|
-
### Major Changes
|
|
6
|
-
|
|
7
|
-
- 7eb13ae: Remove CalendarScrollComponent prop from Calendar.List
|
|
8
|
-
|
|
9
|
-
The `CalendarScrollComponent` prop has been removed from `Calendar.List`. LegendList is now the only supported list implementation and cannot be replaced.
|
|
10
|
-
|
|
11
|
-
**Migration:**
|
|
12
|
-
|
|
13
|
-
If you were using `CalendarScrollComponent` to integrate with bottom sheets or other custom scroll containers:
|
|
14
|
-
|
|
15
|
-
1. Wrap `Calendar.List` in your custom scroll container, or
|
|
16
|
-
2. Use the standalone `Calendar` component with your own list implementation
|
|
17
|
-
|
|
18
|
-
This change simplifies the API and reduces maintenance burden by focusing on a single, well-supported list implementation.
|
|
19
|
-
|
|
20
|
-
## 1.6.0
|
|
21
|
-
|
|
22
|
-
### Minor Changes
|
|
23
|
-
|
|
24
|
-
- 256b67d: Add callback support to `activeDayFiller` for dynamic styling based on day metadata
|
|
25
|
-
|
|
26
|
-
## 1.5.0
|
|
27
|
-
|
|
28
|
-
### Minor Changes
|
|
29
|
-
|
|
30
|
-
- 3b65183: Fixes an infinite loop triggered when calendarMaxDateId is today and calendarFutureScrollRangeInMonths is one.
|
|
31
|
-
|
|
32
|
-
## 1.4.0
|
|
33
|
-
|
|
34
|
-
### Minor Changes
|
|
35
|
-
|
|
36
|
-
- f291f09: Add support for passing custom pressable components
|
|
37
|
-
|
|
38
|
-
## 1.3.0
|
|
39
|
-
|
|
40
|
-
### Minor Changes
|
|
41
|
-
|
|
42
|
-
- b66668c: Added support for react-native-web Pressable InteractionState to support hovered and focused alongside pressed
|
|
43
|
-
|
|
44
|
-
## 1.2.0
|
|
45
|
-
|
|
46
|
-
### Minor Changes
|
|
47
|
-
|
|
48
|
-
- f3b9ec8: Add the ability to pass TextProps to the <Text> fields especially when supporting accessibility
|
|
49
|
-
|
|
50
|
-
## 1.1.0
|
|
51
|
-
|
|
52
|
-
### Minor Changes
|
|
53
|
-
|
|
54
|
-
- 863edce: Add the ability to mount more than one calendar at once
|
|
55
|
-
|
|
56
|
-
## 1.0.0
|
|
57
|
-
|
|
58
|
-
### Major Changes
|
|
59
|
-
|
|
60
|
-
- 9bf22ed: Flash Calendar 1.0.0 🚢 🎉
|
|
61
|
-
|
|
62
|
-
This release officially marks the package as production-ready (`1.0.0`).
|
|
63
|
-
While it's been stable since the first release, bumping to `1.0.0` was something
|
|
64
|
-
I had in mind for a while.
|
|
65
|
-
|
|
66
|
-
- New: Add `.scrollToMonth` and `.scrollToDate`, increasing the options available for imperative scrolling.
|
|
67
|
-
|
|
68
|
-
## Breaking changes
|
|
69
|
-
|
|
70
|
-
This release introduces one small change in behavior if your app uses
|
|
71
|
-
imperative scrolling. Previously, `.scrollToDate` would scroll to the month
|
|
72
|
-
containing the date instead of the exact date. Now, `.scrollToDate` scrolls
|
|
73
|
-
to the exact date as implied by the name.
|
|
74
|
-
|
|
75
|
-
If you intentionally want to scroll to the month instead, a new `.scrollToMonth`
|
|
76
|
-
method is available (same signature).
|
|
77
|
-
|
|
78
|
-
I don't expect this to cause any issues, but worth mentioned
|
|
79
|
-
nonetheless.
|
|
80
|
-
|
|
81
|
-
## 0.0.9
|
|
82
|
-
|
|
83
|
-
### Patch Changes
|
|
84
|
-
|
|
85
|
-
- 6d00992: - Add an optional `calendarColorScheme` prop that enables overriding the color scheme used by Flash Calendar.
|
|
86
|
-
|
|
87
|
-
## 0.0.8
|
|
88
|
-
|
|
89
|
-
### Patch Changes
|
|
90
|
-
|
|
91
|
-
- 4fe1276: Remove `borderRadius` type from `itemDay.container`, given it gets overwritten by the base component.
|
|
92
|
-
|
|
93
|
-
## 0.0.7
|
|
94
|
-
|
|
95
|
-
### Patch Changes
|
|
96
|
-
|
|
97
|
-
- ee6b4e5: Fix incorrect scroll position when using the `calendarMinDateId` prop
|
|
98
|
-
|
|
99
|
-
## 0.0.6
|
|
100
|
-
|
|
101
|
-
### Patch Changes
|
|
102
|
-
|
|
103
|
-
- 5363835: Fix `<Calendar.List />` losing track of the active date ranges when the list is scrolled past certain amount
|
|
104
|
-
|
|
105
|
-
## 0.0.5
|
|
106
|
-
|
|
107
|
-
### Patch Changes
|
|
108
|
-
|
|
109
|
-
- cbc7728: Update the registry to Github Packages
|
|
110
|
-
|
|
111
|
-
## 0.0.4
|
|
112
|
-
|
|
113
|
-
### Patch Changes
|
|
114
|
-
|
|
115
|
-
- 801bc18: Fix locale not being forwarded to `Calendar` component
|
|
116
|
-
|
|
117
|
-
## 0.0.3
|
|
118
|
-
|
|
119
|
-
### Patch Changes
|
|
120
|
-
|
|
121
|
-
- e680a96: Add the `calendarFormatLocale` prop
|
|
122
|
-
|
|
123
|
-
## 0.0.2
|
|
124
|
-
|
|
125
|
-
### Patch Changes
|
|
126
|
-
|
|
127
|
-
- First release to test the publish scripts
|