thailife-react 0.0.42 → 0.0.43
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/cjs/index.js
CHANGED
|
@@ -203,12 +203,18 @@ requireEn();
|
|
|
203
203
|
dayjs.extend(localeData);
|
|
204
204
|
dayjs.extend(buddhistEra);
|
|
205
205
|
const DatePicker = React.forwardRef(({ value, defaultValue, onChange, format = 'DD/MM/YYYY', locale = 'th', yearType = 'BE', placeholder, disabled = false, className = '', size = 'md', fullWidth = false, error, helperText, label, required = false, register, disableFuture, disablePast, minDate, maxDate, }, ref) => {
|
|
206
|
-
const
|
|
206
|
+
const safeDate = (d) => {
|
|
207
|
+
if (!d)
|
|
208
|
+
return null;
|
|
209
|
+
const parsed = dayjs(d);
|
|
210
|
+
return parsed.isValid() ? parsed : null;
|
|
211
|
+
};
|
|
212
|
+
const [selectedDate, setSelectedDate] = React.useState(safeDate(value) || safeDate(defaultValue) || null);
|
|
207
213
|
const [isOpen, setIsOpen] = React.useState(false);
|
|
208
214
|
const [currentMonth, setCurrentMonth] = React.useState(dayjs().locale(locale));
|
|
209
215
|
React.useEffect(() => {
|
|
210
216
|
if (value !== undefined) {
|
|
211
|
-
setSelectedDate(value);
|
|
217
|
+
setSelectedDate(safeDate(value));
|
|
212
218
|
}
|
|
213
219
|
}, [value]);
|
|
214
220
|
React.useEffect(() => {
|
|
@@ -238,12 +244,14 @@ const DatePicker = React.forwardRef(({ value, defaultValue, onChange, format = '
|
|
|
238
244
|
return true;
|
|
239
245
|
}
|
|
240
246
|
}
|
|
241
|
-
|
|
242
|
-
|
|
247
|
+
const min = safeDate(minDate);
|
|
248
|
+
if (min) {
|
|
249
|
+
if (targetDate.isBefore(min.startOf('day')))
|
|
243
250
|
return true;
|
|
244
251
|
}
|
|
245
|
-
|
|
246
|
-
|
|
252
|
+
const max = safeDate(maxDate);
|
|
253
|
+
if (max) {
|
|
254
|
+
if (targetDate.isAfter(max.startOf('day')))
|
|
247
255
|
return true;
|
|
248
256
|
}
|
|
249
257
|
return false;
|