best-react-datepicker 0.2.1 → 0.2.2
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/dist/index.cjs +104 -30
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +104 -30
- package/dist/index.js.map +1 -1
- package/dist/styles.css +101 -23
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -22,8 +22,48 @@ var DEFAULT_MONTH_NAMES = [
|
|
|
22
22
|
"November",
|
|
23
23
|
"December"
|
|
24
24
|
];
|
|
25
|
-
|
|
26
|
-
|
|
25
|
+
var SHORT_MONTH_NAMES = [
|
|
26
|
+
"Jan",
|
|
27
|
+
"Feb",
|
|
28
|
+
"Mar",
|
|
29
|
+
"Apr",
|
|
30
|
+
"May",
|
|
31
|
+
"Jun",
|
|
32
|
+
"Jul",
|
|
33
|
+
"Aug",
|
|
34
|
+
"Sep",
|
|
35
|
+
"Oct",
|
|
36
|
+
"Nov",
|
|
37
|
+
"Dec"
|
|
38
|
+
];
|
|
39
|
+
function ChevronDown() {
|
|
40
|
+
return /* @__PURE__ */ jsx("svg", { width: "12", height: "12", viewBox: "0 0 12 12", fill: "none", "aria-hidden": "true", style: { marginLeft: 2, opacity: 0.5 }, children: /* @__PURE__ */ jsx("path", { d: "M3 4.5L6 7.5L9 4.5", stroke: "currentColor", strokeWidth: "1.5", strokeLinecap: "round", strokeLinejoin: "round" }) });
|
|
41
|
+
}
|
|
42
|
+
function Dropdown({
|
|
43
|
+
isOpen,
|
|
44
|
+
onClose,
|
|
45
|
+
children
|
|
46
|
+
}) {
|
|
47
|
+
const ref = useRef(null);
|
|
48
|
+
useEffect(() => {
|
|
49
|
+
if (!isOpen) return;
|
|
50
|
+
const handleClick = (e) => {
|
|
51
|
+
if (ref.current && !ref.current.contains(e.target)) {
|
|
52
|
+
onClose();
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
const handleKey = (e) => {
|
|
56
|
+
if (e.key === "Escape") onClose();
|
|
57
|
+
};
|
|
58
|
+
document.addEventListener("mousedown", handleClick);
|
|
59
|
+
document.addEventListener("keydown", handleKey);
|
|
60
|
+
return () => {
|
|
61
|
+
document.removeEventListener("mousedown", handleClick);
|
|
62
|
+
document.removeEventListener("keydown", handleKey);
|
|
63
|
+
};
|
|
64
|
+
}, [isOpen, onClose]);
|
|
65
|
+
if (!isOpen) return null;
|
|
66
|
+
return /* @__PURE__ */ jsx("div", { ref, className: "brdp-dropdown", children });
|
|
27
67
|
}
|
|
28
68
|
function CalendarHeader({
|
|
29
69
|
label,
|
|
@@ -44,24 +84,25 @@ function CalendarHeader({
|
|
|
44
84
|
monthNames
|
|
45
85
|
}) {
|
|
46
86
|
const hasDropdowns = viewingMonth != null && viewingYear != null && onMonthChange && onYearChange;
|
|
87
|
+
const [openDropdown, setOpenDropdown] = useState(null);
|
|
88
|
+
const yearGridRef = useRef(null);
|
|
47
89
|
const currentYear = (/* @__PURE__ */ new Date()).getFullYear();
|
|
48
90
|
const minYear = minDate ? minDate.getFullYear() : currentYear - 100;
|
|
49
91
|
const maxYear = maxDate ? maxDate.getFullYear() : currentYear + 20;
|
|
50
92
|
const names = monthNames ?? DEFAULT_MONTH_NAMES;
|
|
51
|
-
const
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
93
|
+
const isMonthDisabled = (m) => {
|
|
94
|
+
if (minDate && viewingYear != null && viewingYear === minDate.getFullYear() && m < minDate.getMonth()) return true;
|
|
95
|
+
if (maxDate && viewingYear != null && viewingYear === maxDate.getFullYear() && m > maxDate.getMonth()) return true;
|
|
96
|
+
return false;
|
|
97
|
+
};
|
|
98
|
+
useEffect(() => {
|
|
99
|
+
if (openDropdown === "year" && yearGridRef.current) {
|
|
100
|
+
const active = yearGridRef.current.querySelector(".brdp-dropdown__item--active");
|
|
101
|
+
if (active) {
|
|
102
|
+
active.scrollIntoView({ block: "center", behavior: "instant" });
|
|
60
103
|
}
|
|
61
|
-
options.push({ value: m, label: names[m], disabled });
|
|
62
104
|
}
|
|
63
|
-
|
|
64
|
-
};
|
|
105
|
+
}, [openDropdown]);
|
|
65
106
|
return /* @__PURE__ */ jsxs("div", { className: `brdp-header ${className ?? ""}`, children: [
|
|
66
107
|
showPrev ? /* @__PURE__ */ jsx(
|
|
67
108
|
"button",
|
|
@@ -74,31 +115,64 @@ function CalendarHeader({
|
|
|
74
115
|
}
|
|
75
116
|
) : /* @__PURE__ */ jsx("span", { className: "brdp-header__nav-btn", style: { visibility: "hidden" } }),
|
|
76
117
|
hasDropdowns ? /* @__PURE__ */ jsxs("div", { className: "brdp-header__selects", children: [
|
|
77
|
-
/* @__PURE__ */ jsxs("div", { className: "brdp-
|
|
78
|
-
/* @__PURE__ */
|
|
79
|
-
"
|
|
118
|
+
/* @__PURE__ */ jsxs("div", { className: "brdp-header__dropdown-anchor", children: [
|
|
119
|
+
/* @__PURE__ */ jsxs(
|
|
120
|
+
"button",
|
|
80
121
|
{
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
122
|
+
type: "button",
|
|
123
|
+
className: `brdp-header__trigger ${openDropdown === "month" ? "brdp-header__trigger--open" : ""}`,
|
|
124
|
+
onClick: () => setOpenDropdown(openDropdown === "month" ? null : "month"),
|
|
84
125
|
"aria-label": "Select month",
|
|
85
|
-
|
|
126
|
+
"aria-expanded": openDropdown === "month",
|
|
127
|
+
children: [
|
|
128
|
+
names[viewingMonth],
|
|
129
|
+
/* @__PURE__ */ jsx(ChevronDown, {})
|
|
130
|
+
]
|
|
86
131
|
}
|
|
87
132
|
),
|
|
88
|
-
/* @__PURE__ */ jsx(
|
|
133
|
+
/* @__PURE__ */ jsx(Dropdown, { isOpen: openDropdown === "month", onClose: () => setOpenDropdown(null), children: /* @__PURE__ */ jsx("div", { className: "brdp-dropdown__grid brdp-dropdown__grid--months", children: SHORT_MONTH_NAMES.map((short, m) => /* @__PURE__ */ jsx(
|
|
134
|
+
"button",
|
|
135
|
+
{
|
|
136
|
+
type: "button",
|
|
137
|
+
className: `brdp-dropdown__item ${viewingMonth === m ? "brdp-dropdown__item--active" : ""} ${isMonthDisabled(m) ? "brdp-dropdown__item--disabled" : ""}`,
|
|
138
|
+
disabled: isMonthDisabled(m),
|
|
139
|
+
onClick: () => {
|
|
140
|
+
onMonthChange(m);
|
|
141
|
+
setOpenDropdown(null);
|
|
142
|
+
},
|
|
143
|
+
children: short
|
|
144
|
+
},
|
|
145
|
+
m
|
|
146
|
+
)) }) })
|
|
89
147
|
] }),
|
|
90
|
-
/* @__PURE__ */ jsxs("div", { className: "brdp-
|
|
91
|
-
/* @__PURE__ */
|
|
92
|
-
"
|
|
148
|
+
/* @__PURE__ */ jsxs("div", { className: "brdp-header__dropdown-anchor", children: [
|
|
149
|
+
/* @__PURE__ */ jsxs(
|
|
150
|
+
"button",
|
|
93
151
|
{
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
152
|
+
type: "button",
|
|
153
|
+
className: `brdp-header__trigger ${openDropdown === "year" ? "brdp-header__trigger--open" : ""}`,
|
|
154
|
+
onClick: () => setOpenDropdown(openDropdown === "year" ? null : "year"),
|
|
97
155
|
"aria-label": "Select year",
|
|
98
|
-
|
|
156
|
+
"aria-expanded": openDropdown === "year",
|
|
157
|
+
children: [
|
|
158
|
+
viewingYear,
|
|
159
|
+
/* @__PURE__ */ jsx(ChevronDown, {})
|
|
160
|
+
]
|
|
99
161
|
}
|
|
100
162
|
),
|
|
101
|
-
/* @__PURE__ */ jsx(
|
|
163
|
+
/* @__PURE__ */ jsx(Dropdown, { isOpen: openDropdown === "year", onClose: () => setOpenDropdown(null), children: /* @__PURE__ */ jsx("div", { ref: yearGridRef, className: "brdp-dropdown__grid brdp-dropdown__grid--years", children: Array.from({ length: maxYear - minYear + 1 }, (_, i) => minYear + i).map((y) => /* @__PURE__ */ jsx(
|
|
164
|
+
"button",
|
|
165
|
+
{
|
|
166
|
+
type: "button",
|
|
167
|
+
className: `brdp-dropdown__item ${viewingYear === y ? "brdp-dropdown__item--active" : ""}`,
|
|
168
|
+
onClick: () => {
|
|
169
|
+
onYearChange(y);
|
|
170
|
+
setOpenDropdown(null);
|
|
171
|
+
},
|
|
172
|
+
children: y
|
|
173
|
+
},
|
|
174
|
+
y
|
|
175
|
+
)) }) })
|
|
102
176
|
] })
|
|
103
177
|
] }) : /* @__PURE__ */ jsx(
|
|
104
178
|
"button",
|