@jordif/react-calendar-list 1.0.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 jordif
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,17 @@
1
+ # @jordif/react-calendar-list
2
+
3
+ A lightweight, unstyled React component for rendering schedules or archives as a list of monthly calendars. Perfect for event feeds, blog archives and availability overviews.
4
+
5
+ ---
6
+
7
+ ## 🚀 Features
8
+
9
+ * **🪶 Lightweight:** Zero dependencies (other than React).
10
+ * **🎨 Unstyled:** Provides the logic and structure; you provide the CSS.
11
+ * **📅 Sequential Layout:** Renders months in a list.
12
+ * **🧩 Flexible:** Perfect for event feeds, availability overviews or blog archives.
13
+
14
+ ## 📦 Installation
15
+
16
+ ```bash
17
+ npm install @jordif/react-calendar-list
package/dist/index.cjs ADDED
@@ -0,0 +1,172 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/CalendarList/index.tsx
21
+ var index_exports = {};
22
+ __export(index_exports, {
23
+ CalendarList: () => CalendarList
24
+ });
25
+ module.exports = __toCommonJS(index_exports);
26
+
27
+ // src/CalendarList/helpers.ts
28
+ var sortPosts = (posts) => {
29
+ return [...posts].sort((a, b) => {
30
+ if (a.date < b.date) {
31
+ return -1;
32
+ }
33
+ if (a.date > b.date) {
34
+ return 1;
35
+ }
36
+ return 0;
37
+ });
38
+ };
39
+ var groupPosts = (posts) => {
40
+ const grouped = {};
41
+ posts.forEach((post) => {
42
+ const year = post.date.getFullYear();
43
+ const month = post.date.getMonth();
44
+ const day = post.date.getDate();
45
+ grouped[year] = grouped[year] || {};
46
+ grouped[year][month] = grouped[year][month] || {};
47
+ grouped[year][month][day] = grouped[year][month][day] || [];
48
+ grouped[year][month][day].push(post);
49
+ });
50
+ return grouped;
51
+ };
52
+ var getDaysInMonth = (month) => {
53
+ return new Date(month.year, month.month + 1, 0).getDate();
54
+ };
55
+ function getMonthsBetweenDates(startDate, endDate) {
56
+ const months = [];
57
+ const currentDate = new Date(
58
+ startDate.getFullYear(),
59
+ startDate.getMonth(),
60
+ 1
61
+ );
62
+ while (currentDate <= endDate) {
63
+ months.push({
64
+ month: currentDate.getMonth(),
65
+ year: currentDate.getFullYear()
66
+ });
67
+ currentDate.setMonth(currentDate.getMonth() + 1);
68
+ }
69
+ return months;
70
+ }
71
+ function getDaysOfTheWeek(locale, startOnMonday = false) {
72
+ const days = [];
73
+ const baseDay = startOnMonday ? 6 : 5;
74
+ for (let i = 0; i < 7; i++) {
75
+ const date = new Date(2025, 0, baseDay + i);
76
+ const dayAbbreviation = new Intl.DateTimeFormat(locale, {
77
+ weekday: "short"
78
+ }).format(date);
79
+ days.push(dayAbbreviation);
80
+ }
81
+ return days;
82
+ }
83
+ var getAdjustedDayOfWeek = (date, startOnMonday) => {
84
+ const day = date.getDay();
85
+ if (startOnMonday) {
86
+ return day === 0 ? 6 : day - 1;
87
+ }
88
+ return day;
89
+ };
90
+ var getCalendarGrid = (month, locale, startOnMonday) => {
91
+ const startDate = new Date(month.year, month.month, 1);
92
+ const daysInMonth = getDaysInMonth(month);
93
+ const endDate = new Date(month.year, month.month, daysInMonth);
94
+ const leftPadding = getAdjustedDayOfWeek(startDate, startOnMonday);
95
+ const rightPadding = 6 - getAdjustedDayOfWeek(endDate, startOnMonday);
96
+ const totalCells = leftPadding + daysInMonth + rightPadding;
97
+ const days = [];
98
+ for (let index = 0; index < totalCells; index++) {
99
+ const dayNumber = index - leftPadding + 1;
100
+ const isPadding = dayNumber < 1 || dayNumber > daysInMonth;
101
+ const rowNumber = Math.floor(index / 7);
102
+ const day = {
103
+ index,
104
+ day: isPadding ? 0 : dayNumber
105
+ };
106
+ if (!days[rowNumber]) {
107
+ days[rowNumber] = { index: rowNumber, cells: [] };
108
+ }
109
+ days[rowNumber].cells.push(day);
110
+ }
111
+ const label = new Intl.DateTimeFormat(locale, { month: "long" }).format(startDate) + " " + month.year;
112
+ const daysOfTheWeek = getDaysOfTheWeek(locale, startOnMonday);
113
+ return { days, label, daysOfTheWeek };
114
+ };
115
+
116
+ // src/CalendarList/Month.tsx
117
+ var import_jsx_runtime = require("react/jsx-runtime");
118
+ var Month = ({ month, locale, startOnMonday, events }) => {
119
+ const { days, label, daysOfTheWeek } = getCalendarGrid(
120
+ month,
121
+ locale,
122
+ startOnMonday
123
+ );
124
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("table", { children: [
125
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("thead", { children: [
126
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("tr", { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("th", { colSpan: 7, children: label }) }),
127
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("tr", { children: daysOfTheWeek.map((dayLabel) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)("th", { children: dayLabel }, dayLabel)) })
128
+ ] }),
129
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("tbody", { children: days.map((row) => {
130
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("tr", { children: row.cells.map((cell) => {
131
+ const hasEvents = events?.[cell.day] && events[cell.day]?.length;
132
+ if (!hasEvents) {
133
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("td", { children: cell.day ? cell.day : "" }, cell.index);
134
+ }
135
+ const className = events[cell.day]?.at(0)?.className;
136
+ const url = events[cell.day]?.at(0)?.url;
137
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("td", { className, children: url ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("a", { href: url, children: cell.day }) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)("strong", { children: cell.day }) }, cell.index);
138
+ }) }, row.index);
139
+ }) })
140
+ ] });
141
+ };
142
+ var Month_default = Month;
143
+
144
+ // src/CalendarList/index.tsx
145
+ var import_jsx_runtime2 = require("react/jsx-runtime");
146
+ var CalendarList = ({
147
+ posts,
148
+ locale = "en-US",
149
+ startOnMonday = false
150
+ }) => {
151
+ const sortedPosts = sortPosts(posts);
152
+ const groupedPosts = groupPosts(sortedPosts);
153
+ const startDate = sortedPosts?.at(0)?.date || /* @__PURE__ */ new Date();
154
+ const endDate = sortedPosts?.at(-1)?.date || /* @__PURE__ */ new Date();
155
+ const monthsInRange = getMonthsBetweenDates(startDate, endDate);
156
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_jsx_runtime2.Fragment, { children: monthsInRange.map((month) => {
157
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
158
+ Month_default,
159
+ {
160
+ month,
161
+ locale,
162
+ startOnMonday,
163
+ events: groupedPosts[month.year]?.[month.month]
164
+ },
165
+ `${month.year}-${month.month}`
166
+ );
167
+ }) });
168
+ };
169
+ // Annotate the CommonJS export names for ESM import in node:
170
+ 0 && (module.exports = {
171
+ CalendarList
172
+ });
@@ -0,0 +1,16 @@
1
+ import * as react_jsx_runtime from 'react/jsx-runtime';
2
+
3
+ interface Post {
4
+ date: Date;
5
+ url?: string;
6
+ className?: string;
7
+ }
8
+ interface CalendarListProps {
9
+ posts: Post[];
10
+ locale?: string;
11
+ startOnMonday?: boolean;
12
+ }
13
+
14
+ declare const CalendarList: ({ posts, locale, startOnMonday, }: CalendarListProps) => react_jsx_runtime.JSX.Element;
15
+
16
+ export { CalendarList };
@@ -0,0 +1,16 @@
1
+ import * as react_jsx_runtime from 'react/jsx-runtime';
2
+
3
+ interface Post {
4
+ date: Date;
5
+ url?: string;
6
+ className?: string;
7
+ }
8
+ interface CalendarListProps {
9
+ posts: Post[];
10
+ locale?: string;
11
+ startOnMonday?: boolean;
12
+ }
13
+
14
+ declare const CalendarList: ({ posts, locale, startOnMonday, }: CalendarListProps) => react_jsx_runtime.JSX.Element;
15
+
16
+ export { CalendarList };
package/dist/index.js ADDED
@@ -0,0 +1,145 @@
1
+ // src/CalendarList/helpers.ts
2
+ var sortPosts = (posts) => {
3
+ return [...posts].sort((a, b) => {
4
+ if (a.date < b.date) {
5
+ return -1;
6
+ }
7
+ if (a.date > b.date) {
8
+ return 1;
9
+ }
10
+ return 0;
11
+ });
12
+ };
13
+ var groupPosts = (posts) => {
14
+ const grouped = {};
15
+ posts.forEach((post) => {
16
+ const year = post.date.getFullYear();
17
+ const month = post.date.getMonth();
18
+ const day = post.date.getDate();
19
+ grouped[year] = grouped[year] || {};
20
+ grouped[year][month] = grouped[year][month] || {};
21
+ grouped[year][month][day] = grouped[year][month][day] || [];
22
+ grouped[year][month][day].push(post);
23
+ });
24
+ return grouped;
25
+ };
26
+ var getDaysInMonth = (month) => {
27
+ return new Date(month.year, month.month + 1, 0).getDate();
28
+ };
29
+ function getMonthsBetweenDates(startDate, endDate) {
30
+ const months = [];
31
+ const currentDate = new Date(
32
+ startDate.getFullYear(),
33
+ startDate.getMonth(),
34
+ 1
35
+ );
36
+ while (currentDate <= endDate) {
37
+ months.push({
38
+ month: currentDate.getMonth(),
39
+ year: currentDate.getFullYear()
40
+ });
41
+ currentDate.setMonth(currentDate.getMonth() + 1);
42
+ }
43
+ return months;
44
+ }
45
+ function getDaysOfTheWeek(locale, startOnMonday = false) {
46
+ const days = [];
47
+ const baseDay = startOnMonday ? 6 : 5;
48
+ for (let i = 0; i < 7; i++) {
49
+ const date = new Date(2025, 0, baseDay + i);
50
+ const dayAbbreviation = new Intl.DateTimeFormat(locale, {
51
+ weekday: "short"
52
+ }).format(date);
53
+ days.push(dayAbbreviation);
54
+ }
55
+ return days;
56
+ }
57
+ var getAdjustedDayOfWeek = (date, startOnMonday) => {
58
+ const day = date.getDay();
59
+ if (startOnMonday) {
60
+ return day === 0 ? 6 : day - 1;
61
+ }
62
+ return day;
63
+ };
64
+ var getCalendarGrid = (month, locale, startOnMonday) => {
65
+ const startDate = new Date(month.year, month.month, 1);
66
+ const daysInMonth = getDaysInMonth(month);
67
+ const endDate = new Date(month.year, month.month, daysInMonth);
68
+ const leftPadding = getAdjustedDayOfWeek(startDate, startOnMonday);
69
+ const rightPadding = 6 - getAdjustedDayOfWeek(endDate, startOnMonday);
70
+ const totalCells = leftPadding + daysInMonth + rightPadding;
71
+ const days = [];
72
+ for (let index = 0; index < totalCells; index++) {
73
+ const dayNumber = index - leftPadding + 1;
74
+ const isPadding = dayNumber < 1 || dayNumber > daysInMonth;
75
+ const rowNumber = Math.floor(index / 7);
76
+ const day = {
77
+ index,
78
+ day: isPadding ? 0 : dayNumber
79
+ };
80
+ if (!days[rowNumber]) {
81
+ days[rowNumber] = { index: rowNumber, cells: [] };
82
+ }
83
+ days[rowNumber].cells.push(day);
84
+ }
85
+ const label = new Intl.DateTimeFormat(locale, { month: "long" }).format(startDate) + " " + month.year;
86
+ const daysOfTheWeek = getDaysOfTheWeek(locale, startOnMonday);
87
+ return { days, label, daysOfTheWeek };
88
+ };
89
+
90
+ // src/CalendarList/Month.tsx
91
+ import { jsx, jsxs } from "react/jsx-runtime";
92
+ var Month = ({ month, locale, startOnMonday, events }) => {
93
+ const { days, label, daysOfTheWeek } = getCalendarGrid(
94
+ month,
95
+ locale,
96
+ startOnMonday
97
+ );
98
+ return /* @__PURE__ */ jsxs("table", { children: [
99
+ /* @__PURE__ */ jsxs("thead", { children: [
100
+ /* @__PURE__ */ jsx("tr", { children: /* @__PURE__ */ jsx("th", { colSpan: 7, children: label }) }),
101
+ /* @__PURE__ */ jsx("tr", { children: daysOfTheWeek.map((dayLabel) => /* @__PURE__ */ jsx("th", { children: dayLabel }, dayLabel)) })
102
+ ] }),
103
+ /* @__PURE__ */ jsx("tbody", { children: days.map((row) => {
104
+ return /* @__PURE__ */ jsx("tr", { children: row.cells.map((cell) => {
105
+ const hasEvents = events?.[cell.day] && events[cell.day]?.length;
106
+ if (!hasEvents) {
107
+ return /* @__PURE__ */ jsx("td", { children: cell.day ? cell.day : "" }, cell.index);
108
+ }
109
+ const className = events[cell.day]?.at(0)?.className;
110
+ const url = events[cell.day]?.at(0)?.url;
111
+ return /* @__PURE__ */ jsx("td", { className, children: url ? /* @__PURE__ */ jsx("a", { href: url, children: cell.day }) : /* @__PURE__ */ jsx("strong", { children: cell.day }) }, cell.index);
112
+ }) }, row.index);
113
+ }) })
114
+ ] });
115
+ };
116
+ var Month_default = Month;
117
+
118
+ // src/CalendarList/index.tsx
119
+ import { Fragment, jsx as jsx2 } from "react/jsx-runtime";
120
+ var CalendarList = ({
121
+ posts,
122
+ locale = "en-US",
123
+ startOnMonday = false
124
+ }) => {
125
+ const sortedPosts = sortPosts(posts);
126
+ const groupedPosts = groupPosts(sortedPosts);
127
+ const startDate = sortedPosts?.at(0)?.date || /* @__PURE__ */ new Date();
128
+ const endDate = sortedPosts?.at(-1)?.date || /* @__PURE__ */ new Date();
129
+ const monthsInRange = getMonthsBetweenDates(startDate, endDate);
130
+ return /* @__PURE__ */ jsx2(Fragment, { children: monthsInRange.map((month) => {
131
+ return /* @__PURE__ */ jsx2(
132
+ Month_default,
133
+ {
134
+ month,
135
+ locale,
136
+ startOnMonday,
137
+ events: groupedPosts[month.year]?.[month.month]
138
+ },
139
+ `${month.year}-${month.month}`
140
+ );
141
+ }) });
142
+ };
143
+ export {
144
+ CalendarList
145
+ };
package/package.json ADDED
@@ -0,0 +1,34 @@
1
+ {
2
+ "name": "@jordif/react-calendar-list",
3
+ "description": "A lightweight, unstyled React component for rendering schedules or archives as a list of monthly calendars. Perfect for event feeds, blog archives and availability overviews.",
4
+ "version": "1.0.0",
5
+ "author": "Jordi Fontseca",
6
+ "license": "MIT",
7
+ "type": "module",
8
+ "files": [
9
+ "dist"
10
+ ],
11
+ "exports": {
12
+ "./CalendarList": {
13
+ "import": "./dist/index.js",
14
+ "require": "./dist/index.cjs"
15
+ }
16
+ },
17
+ "devDependencies": {
18
+ "@biomejs/biome": "2.3.10",
19
+ "@types/react": "^19.1.8",
20
+ "@types/react-dom": "^19.1.6",
21
+ "tsup": "^8.5.1",
22
+ "typescript": "latest"
23
+ },
24
+ "dependencies": {
25
+ "react": "^19.1.0"
26
+ },
27
+ "scripts": {
28
+ "dev": "tsup src/CalendarList/index.tsx --format cjs,esm --dts --watch",
29
+ "build": "tsup src/CalendarList/index.tsx --format cjs,esm --dts",
30
+ "lint": "biome lint ./src",
31
+ "format": "biome format ./src --write",
32
+ "check": "biome check ./src"
33
+ }
34
+ }