diff --git a/packages/shadcn/src/components/ui/autoform/components/DateField.tsx b/packages/shadcn/src/components/ui/autoform/components/DateField.tsx index 9132dfa..efcd1c6 100644 --- a/packages/shadcn/src/components/ui/autoform/components/DateField.tsx +++ b/packages/shadcn/src/components/ui/autoform/components/DateField.tsx @@ -1,16 +1,60 @@ -import React from "react"; -import { Input } from "@/components/ui/input"; +import { Button } from "@/components/ui/button"; +import { Calendar } from "@/components/ui/calendar"; +import { PopoverContent } from "@/components/ui/popover"; +import { cn } from "@/lib/utils"; import { AutoFormFieldProps } from "@autoform/react"; +import { Popover, PopoverTrigger } from "@radix-ui/react-popover"; +import { format } from "date-fns"; +import { CalendarIcon } from "lucide-react"; +import React, { useEffect } from "react"; export const DateField: React.FC = ({ - inputProps, - error, - id, -}) => ( - -); + inputProps, + field, + value, +}) => { + const [date, setDate] = React.useState( + field.default ? new Date(field.default) : undefined, + ); + const [openPopover, setOpenPopover] = React.useState(false); + + useEffect(() => { + if (value) { + setDate(new Date(value)); + } + }, [value]); + return ( + + + + + + { + inputProps.onChange({ + target: { value: value?.toString(), name: inputProps.name }, + }); + setDate(value); + setOpenPopover(false); + }} + initialFocus + /> + + + ); +};