Skip to content

Commit 41a769c

Browse files
committed
replace date-fns with custom implementation
1 parent 4a942a3 commit 41a769c

21 files changed

+1099
-251
lines changed
File renamed without changes.

apps/example/src/components/ThemeableCalendar/Calendar.stories.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type {
22
CalendarActiveDateRange,
3-
CalendaronCalendarDayPress,
3+
CalendarOnDayPress,
44
} from "@marceloterreiro/flash-calendar";
55
import {
66
Calendar,
@@ -49,7 +49,7 @@ export const WindowsXP = () => {
4949
setIsPickerVisible((p) => !p);
5050
}, []);
5151

52-
const handleDayPress = useCallback<CalendaronCalendarDayPress>((dateId) => {
52+
const handleDayPress = useCallback<CalendarOnDayPress>((dateId) => {
5353
setCurrentCalendarMonth(fromDateId(dateId));
5454
setSelectedDate(fromDateId(dateId));
5555
setIsPickerVisible(false);

bun.lockb

72 Bytes
Binary file not shown.

kitchen-sink/expo/package.json

+5-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
"clean": "rm -rf dist && rm -rf node_modules",
1313
"ios": "expo start --ios",
1414
"start": "expo start",
15+
"lint": "eslint .",
1516
"web": "expo start --web"
1617
},
1718
"dependencies": {
@@ -24,7 +25,10 @@
2425
"devDependencies": {
2526
"@babel/core": "^7.20.0",
2627
"@types/react": "~18.2.45",
28+
"eslint": "^8.56.0",
2729
"source-map-explorer": "^2.5.3",
28-
"typescript": "^5.1.3"
30+
"typescript": "^5.3.3",
31+
"@marceloterreiro/tsconfig": "*",
32+
"@marceloterreiro/eslint-config": "*"
2933
}
3034
}

kitchen-sink/expo/src/CalendarList.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1+
import type { CalendarListProps } from "@marceloterreiro/flash-calendar";
12
import {
23
Calendar,
3-
CalendarListProps,
44
toDateId,
55
useDateRange,
66
} from "@marceloterreiro/flash-calendar";
@@ -33,7 +33,7 @@ export function CalendarListDemo() {
3333
<Calendar.HStack
3434
alignItems="center"
3535
justifyContent="space-between"
36-
width={"100%"}
36+
width="100%"
3737
>
3838
<Button title="Clear range" onPress={onClearDateRange} />
3939
<View style={styles.vStack}>

packages/flash-calendar/.eslintrc.js

+11-8
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,23 @@ module.exports = {
77
"error",
88
{
99
patterns: [
10-
// {
11-
// group: ["date-fns"],
12-
// importNames: ["startOfMonth", "startOfWeek"],
13-
// message:
14-
// "Please use the respective function from @/helpers/dates instead.",
15-
// },
1610
{
1711
group: ["date-fns"],
18-
importNames: ["add", "sub"],
1912
message:
20-
"Please use `addDays`, `addWeeks`, `subDays`, `subWeeks` instead for smaller bundles.",
13+
"Please use the custom date functions from @/helpers/dates instead. This decreases the bundle size significantly.",
2114
},
2215
],
2316
},
2417
],
2518
},
19+
20+
// Allow date-fns imports in test files since we use them to test our custom date functions
21+
overrides: [
22+
{
23+
files: ["**/*.test.ts", "**/*.test.tsx", "**/*.stories.tsx"],
24+
rules: {
25+
"no-restricted-imports": ["error", { patterns: [] }],
26+
},
27+
},
28+
],
2629
};

packages/flash-calendar/package.json

+17-18
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,39 @@
11
{
22
"name": "@marceloterreiro/flash-calendar",
33
"version": "0.0.1",
4+
"private": false,
45
"description": "A better calendar for React Native.",
6+
"repository": "github.com/marceloprado/flash-calendar",
7+
"license": "MIT",
8+
"author": "Marcelo Prado",
59
"main": "./dist/index.js",
610
"module": "./dist/index.mjs",
711
"types": "./dist/index.d.ts",
8-
"repository": "github.com/marceloprado/flash-calendar",
9-
"author": "Marcelo Prado",
10-
"license": "MIT",
1112
"scripts": {
12-
"dev": "tsup --watch --silent",
13-
"lint": "eslint src",
1413
"build": "tsup --dts",
15-
"clean": "rm -rf dist && rm -rf node_modules"
16-
},
17-
"dependencies": {
18-
"date-fns": "^3.3.1"
19-
},
20-
"peerDependencies": {
21-
"react": "*",
22-
"react-native": "*",
23-
"@shopify/flash-list": "*"
14+
"clean": "rm -rf dist && rm -rf node_modules",
15+
"dev": "tsup --watch --silent",
16+
"lint": "eslint src"
2417
},
18+
"dependencies": {},
2519
"devDependencies": {
2620
"@marceloterreiro/eslint-config": "*",
2721
"@marceloterreiro/tsconfig": "*",
2822
"@shopify/flash-list": "1.6.3",
29-
"eslint-plugin-react-hooks": "^4.6.0",
3023
"@testing-library/react-hooks": "^8.0.1",
31-
"react-test-renderer": "^18.2.0",
32-
"eslint": "^8.56.0",
3324
"@types/bun": "^1.0.5",
25+
"date-fns": "^3.3.1",
26+
"eslint": "^8.56.0",
27+
"eslint-plugin-react-hooks": "^4.6.0",
3428
"react": "18.2.0",
3529
"react-native": "0.73.4",
30+
"react-test-renderer": "^18.2.0",
3631
"tsup": "^8.0.1",
3732
"typescript": "^5.3.3"
3833
},
39-
"private": false
34+
"peerDependencies": {
35+
"@shopify/flash-list": "*",
36+
"react": "*",
37+
"react-native": "*"
38+
}
4039
}

packages/flash-calendar/src/components/Calendar.stories.tsx

+17-11
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
import type { Meta, StoryObj } from "@storybook/react";
2-
import { addDays, endOfMonth, subDays, startOfMonth } from "date-fns";
2+
import { addDays, subDays } from "date-fns";
3+
import { format } from "date-fns/fp/format";
34

45
import { paddingDecorator } from "@/developer/decorators";
5-
import { toDateId } from "@/helpers/dates";
6+
import { toDateId, endOfMonth, startOfMonth } from "@/helpers/dates";
7+
import { loggingHandler } from "@/developer/loggginHandler";
68

79
import { Calendar } from "./Calendar";
810

@@ -22,17 +24,11 @@ const CalendarMeta: Meta<typeof Calendar> = {
2224
options: ["monday", "sunday"],
2325
},
2426
onCalendarDayPress: { action: "onCalendarDayPress" },
25-
calendarDayFormat: { type: "string" },
26-
calendarMonthFormat: { type: "string" },
27-
calendarWeekDayFormat: { type: "string" },
2827
},
2928

3029
args: {
3130
calendarFirstDayOfWeek: "sunday",
3231
calendarMonthId: toDateId(startOfThisMonth),
33-
calendarDayFormat: "d",
34-
calendarWeekDayFormat: "EEEEE",
35-
calendarMonthFormat: "MMMM yyyy",
3632
},
3733
decorators: [paddingDecorator],
3834
};
@@ -50,9 +46,6 @@ export const KichenSink: StoryObj<typeof Calendar> = {
5046
args: {
5147
calendarFirstDayOfWeek: "sunday",
5248
calendarMonthId: toDateId(startOfThisMonth),
53-
calendarDayFormat: "d",
54-
calendarWeekDayFormat: "EEEEE",
55-
calendarMonthFormat: "MMMM yyyy",
5649
calendarDisabledDateIds: [
5750
toDateId(addDays(today, 1)),
5851
toDateId(subDays(today, 1)),
@@ -105,3 +98,16 @@ export const ActiveDateRanges: StoryObj<typeof Calendar> = {
10598
calendarMonthId: "2024-01-01",
10699
},
107100
};
101+
102+
export const WithCustomFormatting = (args: typeof KichenSink.args) => {
103+
return (
104+
<Calendar
105+
{...args}
106+
calendarMonthId={toDateId(startOfThisMonth)}
107+
getCalendarDayFormat={format("dd")}
108+
getCalendarMonthFormat={format("MMMM yyyy (LL/yyyy)")}
109+
getCalendarWeekDayFormat={format("E")}
110+
onCalendarDayPress={loggingHandler("onCalendarDayPress")}
111+
/>
112+
);
113+
};

packages/flash-calendar/src/components/Calendar.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,10 @@ export interface CalendarTheme {
3535
itemDay?: CalendarItemDayProps["theme"];
3636
}
3737

38-
export type CalendaronCalendarDayPress = (dateId: string) => void;
38+
export type CalendarOnDayPress = (dateId: string) => void;
3939

4040
export interface CalendarProps extends UseCalendarParams {
41-
onCalendarDayPress: CalendaronCalendarDayPress;
41+
onCalendarDayPress: CalendarOnDayPress;
4242
/**
4343
* The spacing between each calendar row (the month header, the week days row,
4444
* and the weeks row)

packages/flash-calendar/src/components/CalendarList.stories.tsx

-3
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,6 @@ const CalendarListMeta: Meta<typeof Calendar.List> = {
3636

3737
calendarFirstDayOfWeek: "sunday",
3838
calendarInitialMonthId: toDateId(startOfThisMonth),
39-
calendarDayFormat: "d",
40-
calendarWeekDayFormat: "EEEEE",
41-
calendarMonthFormat: "MMMM yyyy",
4239
},
4340
decorators: [paddingDecorator],
4441
};

packages/flash-calendar/src/components/CalendarList.tsx

+10-11
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,10 @@ import {
1010
useRef,
1111
} from "react";
1212
import { View } from "react-native";
13-
import { startOfMonth } from "date-fns";
1413

1514
import type { CalendarProps } from "@/components/Calendar";
1615
import { Calendar } from "@/components/Calendar";
17-
import { toDateId } from "@/helpers/dates";
16+
import { toDateId, startOfMonth } from "@/helpers/dates";
1817
import type { CalendarMonth } from "@/hooks/useCalendarList";
1918
import { getHeightForMonth, useCalendarList } from "@/hooks/useCalendarList";
2019

@@ -126,9 +125,9 @@ export const CalendarList = memo(
126125
onCalendarDayPress,
127126
calendarActiveDateRanges: activeDateRanges,
128127
calendarDisabledDateIds,
129-
calendarDayFormat,
130-
calendarWeekDayFormat,
131-
calendarMonthFormat,
128+
getCalendarDayFormat,
129+
getCalendarWeekDayFormat,
130+
getCalendarMonthFormat,
132131
calendarMaxDateId,
133132
calendarMinDateId,
134133
...flatListProps
@@ -139,13 +138,13 @@ export const CalendarList = memo(
139138
calendarActiveDateRanges: activeDateRanges,
140139
calendarDayHeight,
141140
calendarFirstDayOfWeek,
142-
calendarDayFormat,
143-
calendarWeekDayFormat,
141+
getCalendarDayFormat,
142+
getCalendarWeekDayFormat,
144143
calendarMaxDateId,
145144
calendarMinDateId,
146145
calendarMonthHeaderHeight,
147146
calendarRowHorizontalSpacing,
148-
calendarMonthFormat,
147+
getCalendarMonthFormat,
149148
calendarRowVerticalSpacing,
150149
calendarWeekHeaderHeight,
151150
calendarDisabledDateIds,
@@ -156,13 +155,13 @@ export const CalendarList = memo(
156155
activeDateRanges,
157156
calendarDayHeight,
158157
calendarFirstDayOfWeek,
159-
calendarDayFormat,
160-
calendarWeekDayFormat,
158+
getCalendarDayFormat,
159+
getCalendarWeekDayFormat,
161160
calendarMaxDateId,
162161
calendarMinDateId,
163162
calendarMonthHeaderHeight,
164163
calendarRowHorizontalSpacing,
165-
calendarMonthFormat,
164+
getCalendarMonthFormat,
166165
calendarRowVerticalSpacing,
167166
calendarWeekHeaderHeight,
168167
calendarDisabledDateIds,

packages/flash-calendar/src/components/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ type CalendarNamespace = {
6363
VStack: typeof VStack;
6464
} & typeof CalendarDefault;
6565
export type {
66-
CalendaronCalendarDayPress,
66+
CalendarOnDayPress,
6767
CalendarProps,
6868
CalendarTheme,
6969
} from "@/components/Calendar";

0 commit comments

Comments
 (0)