|
@@ -14,14 +14,14 @@
|
|
import React, { useState, useEffect, useCallback } from "react";
|
|
import React, { useState, useEffect, useCallback } from "react";
|
|
import Box from "@mui/material/Box";
|
|
import Box from "@mui/material/Box";
|
|
import Tooltip from "@mui/material/Tooltip";
|
|
import Tooltip from "@mui/material/Tooltip";
|
|
-import { DatePicker } from "@mui/x-date-pickers/DatePicker";
|
|
|
|
|
|
+import { DatePicker, DatePickerProps } from "@mui/x-date-pickers/DatePicker";
|
|
import { BaseDateTimePickerSlotProps } from "@mui/x-date-pickers/DateTimePicker/shared";
|
|
import { BaseDateTimePickerSlotProps } from "@mui/x-date-pickers/DateTimePicker/shared";
|
|
-import { DateTimePicker } from "@mui/x-date-pickers/DateTimePicker";
|
|
|
|
|
|
+import { DateTimePicker, DateTimePickerProps } from "@mui/x-date-pickers/DateTimePicker";
|
|
import { isValid } from "date-fns";
|
|
import { isValid } from "date-fns";
|
|
import { ErrorBoundary } from "react-error-boundary";
|
|
import { ErrorBoundary } from "react-error-boundary";
|
|
|
|
|
|
import { createSendUpdateAction } from "../../context/taipyReducers";
|
|
import { createSendUpdateAction } from "../../context/taipyReducers";
|
|
-import { getSuffixedClassNames, TaipyActiveProps, TaipyChangeProps } from "./utils";
|
|
|
|
|
|
+import { getSuffixedClassNames, TaipyActiveProps, TaipyChangeProps, DateProps, getProps } from "./utils";
|
|
import { dateToString, getDateTime, getTimeZonedDate } from "../../utils";
|
|
import { dateToString, getDateTime, getTimeZonedDate } from "../../utils";
|
|
import { useClassNames, useDispatch, useDynamicProperty, useFormatConfig, useModule } from "../../utils/hooks";
|
|
import { useClassNames, useDispatch, useDynamicProperty, useFormatConfig, useModule } from "../../utils/hooks";
|
|
import Field from "./Field";
|
|
import Field from "./Field";
|
|
@@ -31,6 +31,8 @@ interface DateSelectorProps extends TaipyActiveProps, TaipyChangeProps {
|
|
withTime?: boolean;
|
|
withTime?: boolean;
|
|
format?: string;
|
|
format?: string;
|
|
date: string;
|
|
date: string;
|
|
|
|
+ minDate?: string;
|
|
|
|
+ maxDate?: string;
|
|
defaultDate?: string;
|
|
defaultDate?: string;
|
|
defaultEditable?: boolean;
|
|
defaultEditable?: boolean;
|
|
editable?: boolean;
|
|
editable?: boolean;
|
|
@@ -46,6 +48,8 @@ const DateSelector = (props: DateSelectorProps) => {
|
|
const formatConfig = useFormatConfig();
|
|
const formatConfig = useFormatConfig();
|
|
const tz = formatConfig.timeZone;
|
|
const tz = formatConfig.timeZone;
|
|
const [value, setValue] = useState(() => getDateTime(props.defaultDate, tz, withTime));
|
|
const [value, setValue] = useState(() => getDateTime(props.defaultDate, tz, withTime));
|
|
|
|
+ const [startProps, setStartProps] = useState<DateProps>({});
|
|
|
|
+ const [endProps, setEndProps] = useState<DateProps>({});
|
|
const module = useModule();
|
|
const module = useModule();
|
|
|
|
|
|
const className = useClassNames(props.libClassName, props.dynamicClassName, props.className);
|
|
const className = useClassNames(props.libClassName, props.dynamicClassName, props.className);
|
|
@@ -64,12 +68,12 @@ const DateSelector = (props: DateSelectorProps) => {
|
|
dateToString(newDate, withTime),
|
|
dateToString(newDate, withTime),
|
|
module,
|
|
module,
|
|
props.onChange,
|
|
props.onChange,
|
|
- propagate
|
|
|
|
- )
|
|
|
|
|
|
+ propagate,
|
|
|
|
+ ),
|
|
);
|
|
);
|
|
}
|
|
}
|
|
},
|
|
},
|
|
- [updateVarName, dispatch, withTime, propagate, tz, props.onChange, module]
|
|
|
|
|
|
+ [updateVarName, dispatch, withTime, propagate, tz, props.onChange, module],
|
|
);
|
|
);
|
|
|
|
|
|
// Run every time props.value get updated
|
|
// Run every time props.value get updated
|
|
@@ -77,7 +81,13 @@ const DateSelector = (props: DateSelectorProps) => {
|
|
if (props.date !== undefined) {
|
|
if (props.date !== undefined) {
|
|
setValue(getDateTime(props.date, tz, withTime));
|
|
setValue(getDateTime(props.date, tz, withTime));
|
|
}
|
|
}
|
|
- }, [props.date, tz, withTime]);
|
|
|
|
|
|
+ if (props.minDate !== null) {
|
|
|
|
+ setStartProps((p) => getProps(p, true, getDateTime(props.minDate, tz, withTime), withTime));
|
|
|
|
+ }
|
|
|
|
+ if (props.maxDate !== null) {
|
|
|
|
+ setEndProps((p) => getProps(p, false, getDateTime(props.maxDate, tz, withTime), withTime));
|
|
|
|
+ }
|
|
|
|
+ }, [props.date, props.minDate, props.maxDate, tz, withTime]);
|
|
|
|
|
|
return (
|
|
return (
|
|
<ErrorBoundary FallbackComponent={ErrorFallback}>
|
|
<ErrorBoundary FallbackComponent={ErrorFallback}>
|
|
@@ -86,6 +96,8 @@ const DateSelector = (props: DateSelectorProps) => {
|
|
{editable ? (
|
|
{editable ? (
|
|
withTime ? (
|
|
withTime ? (
|
|
<DateTimePicker
|
|
<DateTimePicker
|
|
|
|
+ {...(startProps as DateTimePickerProps<Date>)}
|
|
|
|
+ {...(endProps as DateTimePickerProps<Date>)}
|
|
value={value}
|
|
value={value}
|
|
onChange={handleChange}
|
|
onChange={handleChange}
|
|
className={getSuffixedClassNames(className, "-picker")}
|
|
className={getSuffixedClassNames(className, "-picker")}
|
|
@@ -96,6 +108,8 @@ const DateSelector = (props: DateSelectorProps) => {
|
|
/>
|
|
/>
|
|
) : (
|
|
) : (
|
|
<DatePicker
|
|
<DatePicker
|
|
|
|
+ {...(startProps as DatePickerProps<Date>)}
|
|
|
|
+ {...(endProps as DatePickerProps<Date>)}
|
|
value={value}
|
|
value={value}
|
|
onChange={handleChange}
|
|
onChange={handleChange}
|
|
className={getSuffixedClassNames(className, "-picker")}
|
|
className={getSuffixedClassNames(className, "-picker")}
|