best-react-datepicker 0.2.1 → 0.2.3
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 +143 -47
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +143 -47
- package/dist/index.js.map +1 -1
- package/dist/styles.css +194 -23
- package/package.json +1 -1
package/dist/index.cjs
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__ */ jsxRuntime.jsx("svg", { width: "12", height: "12", viewBox: "0 0 12 12", fill: "none", "aria-hidden": "true", style: { marginLeft: 2, opacity: 0.5 }, children: /* @__PURE__ */ jsxRuntime.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 = react.useRef(null);
|
|
48
|
+
react.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__ */ jsxRuntime.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] = react.useState(null);
|
|
88
|
+
const yearGridRef = react.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
|
+
react.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__ */ jsxRuntime.jsxs("div", { className: `brdp-header ${className ?? ""}`, children: [
|
|
66
107
|
showPrev ? /* @__PURE__ */ jsxRuntime.jsx(
|
|
67
108
|
"button",
|
|
@@ -74,31 +115,64 @@ function CalendarHeader({
|
|
|
74
115
|
}
|
|
75
116
|
) : /* @__PURE__ */ jsxRuntime.jsx("span", { className: "brdp-header__nav-btn", style: { visibility: "hidden" } }),
|
|
76
117
|
hasDropdowns ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "brdp-header__selects", children: [
|
|
77
|
-
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "brdp-
|
|
78
|
-
/* @__PURE__ */ jsxRuntime.
|
|
79
|
-
"
|
|
118
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "brdp-header__dropdown-anchor", children: [
|
|
119
|
+
/* @__PURE__ */ jsxRuntime.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__ */ jsxRuntime.jsx(ChevronDown, {})
|
|
130
|
+
]
|
|
86
131
|
}
|
|
87
132
|
),
|
|
88
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
133
|
+
/* @__PURE__ */ jsxRuntime.jsx(Dropdown, { isOpen: openDropdown === "month", onClose: () => setOpenDropdown(null), children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "brdp-dropdown__grid brdp-dropdown__grid--months", children: SHORT_MONTH_NAMES.map((short, m) => /* @__PURE__ */ jsxRuntime.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__ */ jsxRuntime.jsxs("div", { className: "brdp-
|
|
91
|
-
/* @__PURE__ */ jsxRuntime.
|
|
92
|
-
"
|
|
148
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "brdp-header__dropdown-anchor", children: [
|
|
149
|
+
/* @__PURE__ */ jsxRuntime.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__ */ jsxRuntime.jsx(ChevronDown, {})
|
|
160
|
+
]
|
|
99
161
|
}
|
|
100
162
|
),
|
|
101
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
163
|
+
/* @__PURE__ */ jsxRuntime.jsx(Dropdown, { isOpen: openDropdown === "year", onClose: () => setOpenDropdown(null), children: /* @__PURE__ */ jsxRuntime.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__ */ jsxRuntime.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__ */ jsxRuntime.jsx(
|
|
104
178
|
"button",
|
|
@@ -589,12 +663,16 @@ var DatePicker = react.forwardRef(
|
|
|
589
663
|
);
|
|
590
664
|
}
|
|
591
665
|
);
|
|
666
|
+
function SwapArrow() {
|
|
667
|
+
return /* @__PURE__ */ jsxRuntime.jsx("svg", { width: "16", height: "16", viewBox: "0 0 16 16", fill: "none", "aria-hidden": "true", className: "brdp-unified__arrow-icon", children: /* @__PURE__ */ jsxRuntime.jsx("path", { d: "M4 8H12M12 8L9.5 5.5M12 8L9.5 10.5", stroke: "currentColor", strokeWidth: "1.5", strokeLinecap: "round", strokeLinejoin: "round" }) });
|
|
668
|
+
}
|
|
592
669
|
function RangePicker(props) {
|
|
593
670
|
const {
|
|
594
671
|
className,
|
|
595
672
|
style,
|
|
596
673
|
size,
|
|
597
674
|
compact = false,
|
|
675
|
+
variant = "default",
|
|
598
676
|
showPresets = false,
|
|
599
677
|
presetsPosition = "left",
|
|
600
678
|
renderDay,
|
|
@@ -641,6 +719,40 @@ function RangePicker(props) {
|
|
|
641
719
|
},
|
|
642
720
|
i
|
|
643
721
|
)) });
|
|
722
|
+
const isUnified = variant === "unified";
|
|
723
|
+
const inputSection = isUnified ? /* @__PURE__ */ jsxRuntime.jsxs("div", { className: `brdp-unified ${picker.isOpen ? "brdp-unified--focused" : ""}`, children: [
|
|
724
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
725
|
+
"input",
|
|
726
|
+
{
|
|
727
|
+
...startInputProps,
|
|
728
|
+
className: "brdp-unified__input"
|
|
729
|
+
}
|
|
730
|
+
),
|
|
731
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "brdp-unified__separator", children: /* @__PURE__ */ jsxRuntime.jsx(SwapArrow, {}) }),
|
|
732
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
733
|
+
"input",
|
|
734
|
+
{
|
|
735
|
+
...endInputProps,
|
|
736
|
+
className: "brdp-unified__input"
|
|
737
|
+
}
|
|
738
|
+
)
|
|
739
|
+
] }) : /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "brdp-range-input", children: [
|
|
740
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
741
|
+
"input",
|
|
742
|
+
{
|
|
743
|
+
...startInputProps,
|
|
744
|
+
className: "brdp-input brdp-range-input__start"
|
|
745
|
+
}
|
|
746
|
+
),
|
|
747
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "brdp-range-input__separator", children: picker.separator }),
|
|
748
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
749
|
+
"input",
|
|
750
|
+
{
|
|
751
|
+
...endInputProps,
|
|
752
|
+
className: "brdp-input brdp-range-input__end"
|
|
753
|
+
}
|
|
754
|
+
)
|
|
755
|
+
] });
|
|
644
756
|
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
645
757
|
"div",
|
|
646
758
|
{
|
|
@@ -649,23 +761,7 @@ function RangePicker(props) {
|
|
|
649
761
|
style: { ...sizeStyles, ...style },
|
|
650
762
|
dir: dir ?? picker.locale.dir,
|
|
651
763
|
children: [
|
|
652
|
-
|
|
653
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
654
|
-
"input",
|
|
655
|
-
{
|
|
656
|
-
...startInputProps,
|
|
657
|
-
className: "brdp-input brdp-range-input__start"
|
|
658
|
-
}
|
|
659
|
-
),
|
|
660
|
-
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "brdp-range-input__separator", children: picker.separator }),
|
|
661
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
662
|
-
"input",
|
|
663
|
-
{
|
|
664
|
-
...endInputProps,
|
|
665
|
-
className: "brdp-input brdp-range-input__end"
|
|
666
|
-
}
|
|
667
|
-
)
|
|
668
|
-
] }),
|
|
764
|
+
inputSection,
|
|
669
765
|
/* @__PURE__ */ jsxRuntime.jsx(
|
|
670
766
|
Popover,
|
|
671
767
|
{
|