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.
|
@@ -4,8 +4,8 @@ import 'dayjs/locale/th';
|
|
|
4
4
|
import 'dayjs/locale/en';
|
|
5
5
|
import { UseFormRegisterReturn } from 'react-hook-form';
|
|
6
6
|
export interface DatePickerProps {
|
|
7
|
-
value?:
|
|
8
|
-
defaultValue?:
|
|
7
|
+
value?: any;
|
|
8
|
+
defaultValue?: any;
|
|
9
9
|
onChange?: (date: Dayjs | null) => void;
|
|
10
10
|
format?: string;
|
|
11
11
|
locale?: 'th' | 'en';
|
|
@@ -22,8 +22,8 @@ export interface DatePickerProps {
|
|
|
22
22
|
register?: UseFormRegisterReturn;
|
|
23
23
|
disableFuture?: boolean | number;
|
|
24
24
|
disablePast?: boolean | number;
|
|
25
|
-
minDate?:
|
|
26
|
-
maxDate?:
|
|
25
|
+
minDate?: any;
|
|
26
|
+
maxDate?: any;
|
|
27
27
|
}
|
|
28
28
|
export declare const DatePicker: React.ForwardRefExoticComponent<DatePickerProps & React.RefAttributes<HTMLInputElement>>;
|
|
29
29
|
//# sourceMappingURL=DatePicker.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DatePicker.d.ts","sourceRoot":"","sources":["../../../../src/components/DatePicker/DatePicker.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAuC,MAAM,OAAO,CAAC;AAC5D,OAAc,EAAE,KAAK,EAAE,MAAM,OAAO,CAAC;AAGrC,OAAO,iBAAiB,CAAC;AACzB,OAAO,iBAAiB,CAAC;AACzB,OAAO,EAAE,qBAAqB,EAAE,MAAM,iBAAiB,CAAC;AAKxD,MAAM,WAAW,eAAe;IAC5B,KAAK,CAAC,EAAE,
|
|
1
|
+
{"version":3,"file":"DatePicker.d.ts","sourceRoot":"","sources":["../../../../src/components/DatePicker/DatePicker.tsx"],"names":[],"mappings":"AAAA,OAAO,KAA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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) => {
|
|
204
|
-
const
|
|
204
|
+
const safeDate = (d) => {
|
|
205
|
+
if (!d)
|
|
206
|
+
return null;
|
|
207
|
+
const parsed = dayjs(d);
|
|
208
|
+
return parsed.isValid() ? parsed : null;
|
|
209
|
+
};
|
|
210
|
+
const [selectedDate, setSelectedDate] = useState(safeDate(value) || safeDate(defaultValue) || null);
|
|
205
211
|
const [isOpen, setIsOpen] = useState(false);
|
|
206
212
|
const [currentMonth, setCurrentMonth] = useState(dayjs().locale(locale));
|
|
207
213
|
useEffect(() => {
|
|
208
214
|
if (value !== undefined) {
|
|
209
|
-
setSelectedDate(value);
|
|
215
|
+
setSelectedDate(safeDate(value));
|
|
210
216
|
}
|
|
211
217
|
}, [value]);
|
|
212
218
|
useEffect(() => {
|
|
@@ -236,12 +242,14 @@ const DatePicker = React.forwardRef(({ value, defaultValue, onChange, format = '
|
|
|
236
242
|
return true;
|
|
237
243
|
}
|
|
238
244
|
}
|
|
239
|
-
|
|
240
|
-
|
|
245
|
+
const min = safeDate(minDate);
|
|
246
|
+
if (min) {
|
|
247
|
+
if (targetDate.isBefore(min.startOf('day')))
|
|
241
248
|
return true;
|
|
242
249
|
}
|
|
243
|
-
|
|
244
|
-
|
|
250
|
+
const max = safeDate(maxDate);
|
|
251
|
+
if (max) {
|
|
252
|
+
if (targetDate.isAfter(max.startOf('day')))
|
|
245
253
|
return true;
|
|
246
254
|
}
|
|
247
255
|
return false;
|