feat(mui): kit — DateField over MUI X (date-fns v4, cs locale) + LocalizationProvider

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
BOHA
2026-06-06 21:23:55 +02:00
parent ca55529ff6
commit 58a3bcad70
2 changed files with 38 additions and 0 deletions

View File

@@ -0,0 +1,37 @@
import { DatePicker } from "@mui/x-date-pickers/DatePicker";
import { parseISO, format, isValid } from "date-fns";
/**
* Date input over MUI X DatePicker. String in / string out ("yyyy-MM-dd", or ""),
* so it drops into existing form state. cs locale + dd.MM.yyyy display are provided
* by the LocalizationProvider in MuiProvider.
*/
export default function DateField({
value,
onChange,
label,
disabled,
minDate,
maxDate,
}: {
value: string;
onChange: (value: string) => void;
label?: string;
disabled?: boolean;
minDate?: Date;
maxDate?: Date;
}) {
const parsed = value ? parseISO(value) : null;
return (
<DatePicker
label={label}
disabled={disabled}
minDate={minDate}
maxDate={maxDate}
value={parsed && isValid(parsed) ? parsed : null}
onChange={(d) => onChange(d && isValid(d) ? format(d, "yyyy-MM-dd") : "")}
format="dd.MM.yyyy"
slotProps={{ textField: { size: "small", fullWidth: true } }}
/>
);
}

View File

@@ -15,3 +15,4 @@ export { default as Alert } from "./Alert";
export { Tabs, TabPanel } from "./Tabs"; export { Tabs, TabPanel } from "./Tabs";
export type { TabDef } from "./Tabs"; export type { TabDef } from "./Tabs";
export { default as Pagination } from "./Pagination"; export { default as Pagination } from "./Pagination";
export { default as DateField } from "./DateField";