@mhome/ui 0.1.7 → 0.1.8

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mhome/ui",
3
- "version": "0.1.7",
3
+ "version": "0.1.8",
4
4
  "type": "module",
5
5
  "description": "mHome UI Component Library",
6
6
  "main": "dist/index.cjs.js",
@@ -2,24 +2,7 @@ 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
- // Handle dayjs import - it may be a function or an object with default
6
- // Ensure dayjs is a function at runtime
7
- const getDayjs = () => {
8
- if (typeof dayjsModule === "function") {
9
- return dayjsModule;
10
- }
11
- if (dayjsModule.default && typeof dayjsModule.default === "function") {
12
- return dayjsModule.default;
13
- }
14
- // Fallback: try to get the function from the module
15
- const dayjsFn = dayjsModule.default || dayjsModule;
16
- if (typeof dayjsFn === "function") {
17
- return dayjsFn;
18
- }
19
- // Last resort: if it's an object, try to access the function
20
- return dayjsFn;
21
- };
22
- const dayjs = getDayjs();
5
+ const dayjs = dayjsModule.default || dayjsModule;
23
6
 
24
7
  const DatePicker = React.forwardRef(
25
8
  (
@@ -122,20 +105,17 @@ const DatePicker = React.forwardRef(
122
105
 
123
106
  // Generate calendar days
124
107
  const getCalendarDays = () => {
125
- const startOfMonth = selectedDate
126
- ? selectedDate.startOf("month")
127
- : dayjs().startOf("month");
128
- const endOfMonth = selectedDate
129
- ? selectedDate.endOf("month")
130
- : dayjs().endOf("month");
131
- const startDate = startOfMonth.startOf("week");
132
- const endDate = endOfMonth.endOf("week");
108
+ const baseDate = selectedDate || dayjs();
109
+ const startOfMonth = dayjs(baseDate).startOf("month");
110
+ const endOfMonth = dayjs(baseDate).endOf("month");
111
+ const startDate = dayjs(startOfMonth).startOf("week");
112
+ const endDate = dayjs(endOfMonth).endOf("week");
133
113
  const days = [];
134
114
  let currentDate = startDate;
135
115
 
136
116
  while (currentDate.isBefore(endDate) || currentDate.isSame(endDate)) {
137
- days.push(currentDate);
138
- currentDate = currentDate.add(1, "day");
117
+ days.push(dayjs(currentDate));
118
+ currentDate = dayjs(currentDate).add(1, "day");
139
119
  }
140
120
 
141
121
  return days;
@@ -147,14 +127,14 @@ const DatePicker = React.forwardRef(
147
127
 
148
128
  const handlePrevMonth = () => {
149
129
  const newDate = selectedDate
150
- ? selectedDate.subtract(1, "month")
130
+ ? dayjs(selectedDate).subtract(1, "month")
151
131
  : dayjs().subtract(1, "month");
152
132
  setSelectedDate(newDate);
153
133
  };
154
134
 
155
135
  const handleNextMonth = () => {
156
136
  const newDate = selectedDate
157
- ? selectedDate.add(1, "month")
137
+ ? dayjs(selectedDate).add(1, "month")
158
138
  : dayjs().add(1, "month");
159
139
  setSelectedDate(newDate);
160
140
  };
@@ -265,7 +245,7 @@ const DatePicker = React.forwardRef(
265
245
  if (viewMode === "year") {
266
246
  setSelectedDate(
267
247
  selectedDate
268
- ? selectedDate.subtract(10, "year")
248
+ ? dayjs(selectedDate).subtract(10, "year")
269
249
  : dayjs().subtract(10, "year")
270
250
  );
271
251
  } else {
@@ -351,7 +331,7 @@ const DatePicker = React.forwardRef(
351
331
  type="button"
352
332
  onClick={() => {
353
333
  const newDate = selectedDate
354
- ? selectedDate.year(year)
334
+ ? dayjs(selectedDate).year(year)
355
335
  : dayjs().year(year).month(currentMonth);
356
336
  setSelectedDate(newDate);
357
337
  setShowYearPicker(false);
@@ -389,7 +369,7 @@ const DatePicker = React.forwardRef(
389
369
  if (viewMode === "year") {
390
370
  setSelectedDate(
391
371
  selectedDate
392
- ? selectedDate.add(10, "year")
372
+ ? dayjs(selectedDate).add(10, "year")
393
373
  : dayjs().add(10, "year")
394
374
  );
395
375
  } else {
@@ -498,7 +478,7 @@ const DatePicker = React.forwardRef(
498
478
  type="button"
499
479
  onClick={() => {
500
480
  const newDate = selectedDate
501
- ? selectedDate.month(monthIndex)
481
+ ? dayjs(selectedDate).month(monthIndex)
502
482
  : dayjs().month(monthIndex).year(currentYear);
503
483
  setSelectedDate(newDate);
504
484
  setViewMode("month");