@molecule/app-mini-calendar-react 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 +115 -0
- package/dist/MiniCalendar.d.ts +26 -0
- package/dist/MiniCalendar.d.ts.map +1 -0
- package/dist/MiniCalendar.js +75 -0
- package/dist/index.d.ts +36 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +35 -0
- package/package.json +46 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work.
|
|
38
|
+
|
|
39
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
40
|
+
form, that is based on (or derived from) the Work and for which the
|
|
41
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
42
|
+
represent, as a whole, an original work of authorship.
|
|
43
|
+
|
|
44
|
+
"Contribution" shall mean any work of authorship, including the
|
|
45
|
+
original version of the Work and any modifications or additions
|
|
46
|
+
to that Work, that is intentionally submitted to the Licensor for
|
|
47
|
+
inclusion in the Work by the copyright owner or by an individual or
|
|
48
|
+
Legal Entity authorized to submit on behalf of the copyright owner.
|
|
49
|
+
|
|
50
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
51
|
+
on behalf of whom a Contribution has been received by the Licensor and
|
|
52
|
+
subsequently incorporated within the Work.
|
|
53
|
+
|
|
54
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
55
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
56
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
57
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
58
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
59
|
+
Work and such Derivative Works in Source or Object form.
|
|
60
|
+
|
|
61
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
62
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
63
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
64
|
+
patent license to make, have made, use, offer to sell, sell, import,
|
|
65
|
+
and otherwise transfer the Work.
|
|
66
|
+
|
|
67
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
68
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
69
|
+
modifications, and in Source or Object form, provided that You
|
|
70
|
+
meet the following conditions:
|
|
71
|
+
|
|
72
|
+
(a) You must give any other recipients of the Work or
|
|
73
|
+
Derivative Works a copy of this License; and
|
|
74
|
+
|
|
75
|
+
(b) You must cause any modified files to carry prominent notices
|
|
76
|
+
stating that You changed the files; and
|
|
77
|
+
|
|
78
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
79
|
+
that You distribute, all copyright, patent, trademark, and
|
|
80
|
+
attribution notices from the Source form of the Work,
|
|
81
|
+
excluding those notices that do not pertain to any part of
|
|
82
|
+
the Derivative Works; and
|
|
83
|
+
|
|
84
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
85
|
+
distribution, then any Derivative Works that You distribute must
|
|
86
|
+
include a readable copy of the attribution notices contained
|
|
87
|
+
within such NOTICE file.
|
|
88
|
+
|
|
89
|
+
5. Submission of Contributions.
|
|
90
|
+
|
|
91
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
92
|
+
names, trademarks, service marks, or product names of the Licensor.
|
|
93
|
+
|
|
94
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
95
|
+
agreed to in writing, Licensor provides the Work on an "AS IS" BASIS,
|
|
96
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND.
|
|
97
|
+
|
|
98
|
+
8. Limitation of Liability. In no event and under no legal theory shall
|
|
99
|
+
any Contributor be liable to You for damages.
|
|
100
|
+
|
|
101
|
+
9. Accepting Warranty or Additional Liability.
|
|
102
|
+
|
|
103
|
+
Copyright 2026 Molecule Dev, Inc.
|
|
104
|
+
|
|
105
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
106
|
+
you may not use this file except in compliance with the License.
|
|
107
|
+
You may obtain a copy of the License at
|
|
108
|
+
|
|
109
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
110
|
+
|
|
111
|
+
Unless required by applicable law or agreed to in writing, software
|
|
112
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
113
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
114
|
+
See the License for the specific language governing permissions and
|
|
115
|
+
limitations under the License.
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { type JSX } from 'react';
|
|
2
|
+
/** Props for {@link MiniCalendar}. */
|
|
3
|
+
export interface MiniCalendarProps {
|
|
4
|
+
/** Controlled selected date (ISO yyyy-mm-dd or Date). */
|
|
5
|
+
selected?: Date | string;
|
|
6
|
+
/** Called when the user picks a day. */
|
|
7
|
+
onSelect?: (date: Date) => void;
|
|
8
|
+
/** Controlled visible month. If omitted the component tracks its own. */
|
|
9
|
+
month?: Date;
|
|
10
|
+
/** Called when the user navigates months. */
|
|
11
|
+
onMonthChange?: (date: Date) => void;
|
|
12
|
+
/** Locale for weekday + month name formatting. */
|
|
13
|
+
locale?: string;
|
|
14
|
+
/** Optional day-disabled predicate. */
|
|
15
|
+
isDisabled?: (date: Date) => boolean;
|
|
16
|
+
/** Extra classes. */
|
|
17
|
+
className?: string;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Compact month-view calendar. Supports controlled `selected` + `month`
|
|
21
|
+
* props or runs uncontrolled. Weekday / month names come from
|
|
22
|
+
* `Intl.DateTimeFormat` so locales render correctly without extra data.
|
|
23
|
+
* @param props - Component props (see {@link MiniCalendarProps}).
|
|
24
|
+
*/
|
|
25
|
+
export declare function MiniCalendar({ selected, onSelect, month: monthProp, onMonthChange, locale, isDisabled, className, }: MiniCalendarProps): JSX.Element;
|
|
26
|
+
//# sourceMappingURL=MiniCalendar.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MiniCalendar.d.ts","sourceRoot":"","sources":["../src/MiniCalendar.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,GAAG,EAAY,MAAM,OAAO,CAAA;AAK1C,sCAAsC;AACtC,MAAM,WAAW,iBAAiB;IAChC,yDAAyD;IACzD,QAAQ,CAAC,EAAE,IAAI,GAAG,MAAM,CAAA;IACxB,wCAAwC;IACxC,QAAQ,CAAC,EAAE,CAAC,IAAI,EAAE,IAAI,KAAK,IAAI,CAAA;IAC/B,yEAAyE;IACzE,KAAK,CAAC,EAAE,IAAI,CAAA;IACZ,6CAA6C;IAC7C,aAAa,CAAC,EAAE,CAAC,IAAI,EAAE,IAAI,KAAK,IAAI,CAAA;IACpC,kDAAkD;IAClD,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,uCAAuC;IACvC,UAAU,CAAC,EAAE,CAAC,IAAI,EAAE,IAAI,KAAK,OAAO,CAAA;IACpC,qBAAqB;IACrB,SAAS,CAAC,EAAE,MAAM,CAAA;CACnB;AAkCD;;;;;GAKG;AACH,wBAAgB,YAAY,CAAC,EAC3B,QAAQ,EACR,QAAQ,EACR,KAAK,EAAE,SAAS,EAChB,aAAa,EACb,MAAM,EACN,UAAU,EACV,SAAS,GACV,EAAE,iBAAiB,GAAG,GAAG,CAAC,OAAO,CAmFjC"}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useState } from 'react';
|
|
3
|
+
import { getClassMap } from '@molecule/app-ui';
|
|
4
|
+
import { Button } from '@molecule/app-ui-react';
|
|
5
|
+
/**
|
|
6
|
+
* Coerces a Date or ISO string to a Date, returning undefined for invalid values.
|
|
7
|
+
* @param v
|
|
8
|
+
*/
|
|
9
|
+
function toDate(v) {
|
|
10
|
+
if (!v)
|
|
11
|
+
return undefined;
|
|
12
|
+
if (v instanceof Date)
|
|
13
|
+
return v;
|
|
14
|
+
const d = new Date(v);
|
|
15
|
+
return isNaN(+d) ? undefined : d;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Returns a new Date set to the first day of the given date's month.
|
|
19
|
+
* @param d
|
|
20
|
+
*/
|
|
21
|
+
function startOfMonth(d) {
|
|
22
|
+
return new Date(d.getFullYear(), d.getMonth(), 1);
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Returns true if two Date values represent the same calendar day.
|
|
26
|
+
* @param a
|
|
27
|
+
* @param b
|
|
28
|
+
*/
|
|
29
|
+
function isSameDay(a, b) {
|
|
30
|
+
return (a.getFullYear() === b.getFullYear() &&
|
|
31
|
+
a.getMonth() === b.getMonth() &&
|
|
32
|
+
a.getDate() === b.getDate());
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Compact month-view calendar. Supports controlled `selected` + `month`
|
|
36
|
+
* props or runs uncontrolled. Weekday / month names come from
|
|
37
|
+
* `Intl.DateTimeFormat` so locales render correctly without extra data.
|
|
38
|
+
* @param props - Component props (see {@link MiniCalendarProps}).
|
|
39
|
+
*/
|
|
40
|
+
export function MiniCalendar({ selected, onSelect, month: monthProp, onMonthChange, locale, isDisabled, className, }) {
|
|
41
|
+
const cm = getClassMap();
|
|
42
|
+
const selectedDate = toDate(selected);
|
|
43
|
+
const [internalMonth, setInternalMonth] = useState(startOfMonth(monthProp ?? selectedDate ?? new Date()));
|
|
44
|
+
const visibleMonth = monthProp ? startOfMonth(monthProp) : internalMonth;
|
|
45
|
+
/**
|
|
46
|
+
* Advances the visible month by the given number of months (negative to go back).
|
|
47
|
+
* @param delta
|
|
48
|
+
*/
|
|
49
|
+
function navigate(delta) {
|
|
50
|
+
const next = new Date(visibleMonth.getFullYear(), visibleMonth.getMonth() + delta, 1);
|
|
51
|
+
if (!monthProp)
|
|
52
|
+
setInternalMonth(next);
|
|
53
|
+
onMonthChange?.(next);
|
|
54
|
+
}
|
|
55
|
+
const monthFmt = new Intl.DateTimeFormat(locale, { month: 'long', year: 'numeric' });
|
|
56
|
+
const weekdayFmt = new Intl.DateTimeFormat(locale, { weekday: 'narrow' });
|
|
57
|
+
// Build grid: 6 rows × 7 cols, starting from the Sunday before the 1st.
|
|
58
|
+
const first = startOfMonth(visibleMonth);
|
|
59
|
+
const gridStart = new Date(first);
|
|
60
|
+
gridStart.setDate(1 - first.getDay());
|
|
61
|
+
const days = [];
|
|
62
|
+
for (let i = 0; i < 42; i++) {
|
|
63
|
+
const d = new Date(gridStart);
|
|
64
|
+
d.setDate(gridStart.getDate() + i);
|
|
65
|
+
days.push(d);
|
|
66
|
+
}
|
|
67
|
+
// Weekday header derived from the first week
|
|
68
|
+
const weekdayHeader = days.slice(0, 7);
|
|
69
|
+
return (_jsxs("div", { className: cm.cn(cm.stack(2), className), children: [_jsxs("header", { className: cm.flex({ justify: 'between', align: 'center', gap: 'sm' }), children: [_jsx(Button, { variant: "ghost", size: "sm", onClick: () => navigate(-1), "aria-label": "Previous month", children: "\u2039" }), _jsx("span", { className: cm.cn(cm.textSize('sm'), cm.fontWeight('semibold')), children: monthFmt.format(visibleMonth) }), _jsx(Button, { variant: "ghost", size: "sm", onClick: () => navigate(1), "aria-label": "Next month", children: "\u203A" })] }), _jsxs("div", { className: cm.grid({ cols: 7, gap: 'xs' }), children: [weekdayHeader.map((d, i) => (_jsx("span", { className: cm.cn(cm.textSize('xs'), cm.fontWeight('semibold'), cm.textCenter), children: weekdayFmt.format(d) }, i))), days.map((d, i) => {
|
|
70
|
+
const outOfMonth = d.getMonth() !== visibleMonth.getMonth();
|
|
71
|
+
const isSelected = selectedDate && isSameDay(d, selectedDate);
|
|
72
|
+
const disabled = isDisabled?.(d) ?? false;
|
|
73
|
+
return (_jsx("button", { type: "button", onClick: () => !disabled && onSelect?.(d), disabled: disabled, "aria-current": isSelected ? 'date' : undefined, className: cm.cn(cm.textSize('xs'), cm.sp('py', 1), cm.textCenter, cm.roundedFull, isSelected ? cm.fontWeight('bold') : cm.fontWeight('medium')), style: outOfMonth ? { opacity: 0.3 } : undefined, children: d.getDate() }, i));
|
|
74
|
+
})] })] }));
|
|
75
|
+
}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* React mini month-view calendar.
|
|
3
|
+
*
|
|
4
|
+
* Exports `<MiniCalendar>` — compact day picker with prev/next navigation,
|
|
5
|
+
* Intl-localized weekday + month names, controlled-optional `selected` +
|
|
6
|
+
* `month` props, and an `isDisabled` day predicate.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```tsx
|
|
10
|
+
* import { MiniCalendar } from '@molecule/app-mini-calendar-react'
|
|
11
|
+
*
|
|
12
|
+
* <MiniCalendar
|
|
13
|
+
* selected={new Date('2026-06-15')}
|
|
14
|
+
* onSelect={(date) => console.log(date.toISOString())}
|
|
15
|
+
* locale="en-US"
|
|
16
|
+
* />
|
|
17
|
+
* ```
|
|
18
|
+
*
|
|
19
|
+
* @remarks
|
|
20
|
+
* Requires a wired ClassMap bond (`setClassMap(...)` at startup) —
|
|
21
|
+
* `getClassMap()` throws before wiring, and the prev/next buttons come
|
|
22
|
+
* from `@molecule/app-ui-react`.
|
|
23
|
+
*
|
|
24
|
+
* Weekday and month names localize automatically through
|
|
25
|
+
* `Intl.DateTimeFormat(locale)` — no locale bond involved. The prev/next
|
|
26
|
+
* button aria-labels are currently English-only.
|
|
27
|
+
*
|
|
28
|
+
* When `month` is supplied the visible month is fully controlled —
|
|
29
|
+
* wire `onMonthChange` too or the arrows will appear dead. The grid
|
|
30
|
+
* always renders 6 weeks; days outside the visible month render dimmed
|
|
31
|
+
* and remain clickable unless `isDisabled` filters them.
|
|
32
|
+
*
|
|
33
|
+
* @module
|
|
34
|
+
*/
|
|
35
|
+
export * from './MiniCalendar.js';
|
|
36
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AAEH,cAAc,mBAAmB,CAAA"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* React mini month-view calendar.
|
|
3
|
+
*
|
|
4
|
+
* Exports `<MiniCalendar>` — compact day picker with prev/next navigation,
|
|
5
|
+
* Intl-localized weekday + month names, controlled-optional `selected` +
|
|
6
|
+
* `month` props, and an `isDisabled` day predicate.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```tsx
|
|
10
|
+
* import { MiniCalendar } from '@molecule/app-mini-calendar-react'
|
|
11
|
+
*
|
|
12
|
+
* <MiniCalendar
|
|
13
|
+
* selected={new Date('2026-06-15')}
|
|
14
|
+
* onSelect={(date) => console.log(date.toISOString())}
|
|
15
|
+
* locale="en-US"
|
|
16
|
+
* />
|
|
17
|
+
* ```
|
|
18
|
+
*
|
|
19
|
+
* @remarks
|
|
20
|
+
* Requires a wired ClassMap bond (`setClassMap(...)` at startup) —
|
|
21
|
+
* `getClassMap()` throws before wiring, and the prev/next buttons come
|
|
22
|
+
* from `@molecule/app-ui-react`.
|
|
23
|
+
*
|
|
24
|
+
* Weekday and month names localize automatically through
|
|
25
|
+
* `Intl.DateTimeFormat(locale)` — no locale bond involved. The prev/next
|
|
26
|
+
* button aria-labels are currently English-only.
|
|
27
|
+
*
|
|
28
|
+
* When `month` is supplied the visible month is fully controlled —
|
|
29
|
+
* wire `onMonthChange` too or the arrows will appear dead. The grid
|
|
30
|
+
* always renders 6 weeks; days outside the visible month render dimmed
|
|
31
|
+
* and remain clickable unless `isDisabled` filters them.
|
|
32
|
+
*
|
|
33
|
+
* @module
|
|
34
|
+
*/
|
|
35
|
+
export * from './MiniCalendar.js';
|
package/package.json
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@molecule/app-mini-calendar-react",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Month-view calendar with day selection and prev/next navigation",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "dist/index.js",
|
|
7
|
+
"types": "dist/index.d.ts",
|
|
8
|
+
"scripts": {
|
|
9
|
+
"build": "tsc",
|
|
10
|
+
"test": "vitest run",
|
|
11
|
+
"test:watch": "vitest"
|
|
12
|
+
},
|
|
13
|
+
"exports": {
|
|
14
|
+
".": {
|
|
15
|
+
"types": "./dist/index.d.ts",
|
|
16
|
+
"import": "./dist/index.js"
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
"files": [
|
|
20
|
+
"dist"
|
|
21
|
+
],
|
|
22
|
+
"keywords": [
|
|
23
|
+
"molecule",
|
|
24
|
+
"mini-calendar",
|
|
25
|
+
"react"
|
|
26
|
+
],
|
|
27
|
+
"license": "Apache-2.0",
|
|
28
|
+
"peerDependencies": {
|
|
29
|
+
"@molecule/app-react": "^1.0.0",
|
|
30
|
+
"@molecule/app-ui": "^1.0.0",
|
|
31
|
+
"@molecule/app-ui-react": "^1.0.0",
|
|
32
|
+
"react": "^18.0.0 || ^19.0.0"
|
|
33
|
+
},
|
|
34
|
+
"devDependencies": {
|
|
35
|
+
"@molecule/app-react": "1.0.0",
|
|
36
|
+
"@molecule/app-ui": "1.0.0",
|
|
37
|
+
"@molecule/app-ui-react": "1.0.0",
|
|
38
|
+
"@types/node": "26.1.2",
|
|
39
|
+
"@types/react": "19.2.17",
|
|
40
|
+
"@types/react-dom": "19.2.3",
|
|
41
|
+
"react": "19.2.8",
|
|
42
|
+
"react-dom": "19.2.8",
|
|
43
|
+
"typescript": "6.0.3",
|
|
44
|
+
"vitest": "4.1.10"
|
|
45
|
+
}
|
|
46
|
+
}
|