@mhome/ui 0.1.7 → 0.1.9
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.js +1 -1
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +2 -2
- package/dist/index.esm.js.map +1 -1
- package/package.json +1 -1
- package/src/components/date-picker.jsx +30 -31
package/package.json
CHANGED
|
@@ -2,24 +2,26 @@ import * as React from "react";
|
|
|
2
2
|
import { cn } from "../lib/utils";
|
|
3
3
|
import { TextField } from "./text-field";
|
|
4
4
|
import * as dayjsModule from "dayjs";
|
|
5
|
-
|
|
5
|
+
|
|
6
6
|
// Ensure dayjs is a function at runtime
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
7
|
+
// Handle both ESM and CJS dayjs exports
|
|
8
|
+
let dayjs;
|
|
9
|
+
if (typeof dayjsModule === "function") {
|
|
10
|
+
dayjs = dayjsModule;
|
|
11
|
+
} else if (dayjsModule.default && typeof dayjsModule.default === "function") {
|
|
12
|
+
dayjs = dayjsModule.default;
|
|
13
|
+
} else {
|
|
14
14
|
// Fallback: try to get the function from the module
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
15
|
+
dayjs = dayjsModule.default || dayjsModule;
|
|
16
|
+
// If still not a function, this is an error
|
|
17
|
+
if (typeof dayjs !== "function") {
|
|
18
|
+
console.error("dayjs is not a function. Module:", dayjsModule);
|
|
19
|
+
// Create a fallback that throws an error
|
|
20
|
+
dayjs = function() {
|
|
21
|
+
throw new Error("dayjs is not properly initialized");
|
|
22
|
+
};
|
|
18
23
|
}
|
|
19
|
-
|
|
20
|
-
return dayjsFn;
|
|
21
|
-
};
|
|
22
|
-
const dayjs = getDayjs();
|
|
24
|
+
}
|
|
23
25
|
|
|
24
26
|
const DatePicker = React.forwardRef(
|
|
25
27
|
(
|
|
@@ -122,20 +124,17 @@ const DatePicker = React.forwardRef(
|
|
|
122
124
|
|
|
123
125
|
// Generate calendar days
|
|
124
126
|
const getCalendarDays = () => {
|
|
125
|
-
const
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
const
|
|
129
|
-
|
|
130
|
-
: dayjs().endOf("month");
|
|
131
|
-
const startDate = startOfMonth.startOf("week");
|
|
132
|
-
const endDate = endOfMonth.endOf("week");
|
|
127
|
+
const baseDate = selectedDate || dayjs();
|
|
128
|
+
const startOfMonth = dayjs(baseDate).startOf("month");
|
|
129
|
+
const endOfMonth = dayjs(baseDate).endOf("month");
|
|
130
|
+
const startDate = dayjs(startOfMonth).startOf("week");
|
|
131
|
+
const endDate = dayjs(endOfMonth).endOf("week");
|
|
133
132
|
const days = [];
|
|
134
133
|
let currentDate = startDate;
|
|
135
134
|
|
|
136
135
|
while (currentDate.isBefore(endDate) || currentDate.isSame(endDate)) {
|
|
137
|
-
days.push(currentDate);
|
|
138
|
-
currentDate = currentDate.add(1, "day");
|
|
136
|
+
days.push(dayjs(currentDate));
|
|
137
|
+
currentDate = dayjs(currentDate).add(1, "day");
|
|
139
138
|
}
|
|
140
139
|
|
|
141
140
|
return days;
|
|
@@ -147,14 +146,14 @@ const DatePicker = React.forwardRef(
|
|
|
147
146
|
|
|
148
147
|
const handlePrevMonth = () => {
|
|
149
148
|
const newDate = selectedDate
|
|
150
|
-
? selectedDate.subtract(1, "month")
|
|
149
|
+
? dayjs(selectedDate).subtract(1, "month")
|
|
151
150
|
: dayjs().subtract(1, "month");
|
|
152
151
|
setSelectedDate(newDate);
|
|
153
152
|
};
|
|
154
153
|
|
|
155
154
|
const handleNextMonth = () => {
|
|
156
155
|
const newDate = selectedDate
|
|
157
|
-
? selectedDate.add(1, "month")
|
|
156
|
+
? dayjs(selectedDate).add(1, "month")
|
|
158
157
|
: dayjs().add(1, "month");
|
|
159
158
|
setSelectedDate(newDate);
|
|
160
159
|
};
|
|
@@ -265,7 +264,7 @@ const DatePicker = React.forwardRef(
|
|
|
265
264
|
if (viewMode === "year") {
|
|
266
265
|
setSelectedDate(
|
|
267
266
|
selectedDate
|
|
268
|
-
? selectedDate.subtract(10, "year")
|
|
267
|
+
? dayjs(selectedDate).subtract(10, "year")
|
|
269
268
|
: dayjs().subtract(10, "year")
|
|
270
269
|
);
|
|
271
270
|
} else {
|
|
@@ -351,7 +350,7 @@ const DatePicker = React.forwardRef(
|
|
|
351
350
|
type="button"
|
|
352
351
|
onClick={() => {
|
|
353
352
|
const newDate = selectedDate
|
|
354
|
-
? selectedDate.year(year)
|
|
353
|
+
? dayjs(selectedDate).year(year)
|
|
355
354
|
: dayjs().year(year).month(currentMonth);
|
|
356
355
|
setSelectedDate(newDate);
|
|
357
356
|
setShowYearPicker(false);
|
|
@@ -389,7 +388,7 @@ const DatePicker = React.forwardRef(
|
|
|
389
388
|
if (viewMode === "year") {
|
|
390
389
|
setSelectedDate(
|
|
391
390
|
selectedDate
|
|
392
|
-
? selectedDate.add(10, "year")
|
|
391
|
+
? dayjs(selectedDate).add(10, "year")
|
|
393
392
|
: dayjs().add(10, "year")
|
|
394
393
|
);
|
|
395
394
|
} else {
|
|
@@ -498,7 +497,7 @@ const DatePicker = React.forwardRef(
|
|
|
498
497
|
type="button"
|
|
499
498
|
onClick={() => {
|
|
500
499
|
const newDate = selectedDate
|
|
501
|
-
? selectedDate.month(monthIndex)
|
|
500
|
+
? dayjs(selectedDate).month(monthIndex)
|
|
502
501
|
: dayjs().month(monthIndex).year(currentYear);
|
|
503
502
|
setSelectedDate(newDate);
|
|
504
503
|
setViewMode("month");
|