siakad-itm/resources/js/components/date-picker.tsx
Yoga Pangestu 1b5510b4e5
Some checks failed
tests / ci (pull_request) Has been cancelled
feat: add reusable components for dialogs and headers
- Implemented DeleteConfirmDialog for confirming deletions.
- Created FormDialog for handling forms within dialogs.
- Added PageHeader component for consistent page headers.
- Introduced RowActions component for action buttons with tooltips.
- Added useServerTable hook for managing server-side table interactions.
- Updated DatePicker component with default month and dropdown caption layout.
- Removed outdated data.json file.
2026-08-05 13:46:38 +07:00

57 lines
1.6 KiB
TypeScript

import { format } from 'date-fns';
import { CalendarIcon } from 'lucide-react';
import { Button } from '@/components/ui/button';
import { Calendar } from '@/components/ui/calendar';
import {
Popover,
PopoverContent,
PopoverTrigger,
} from '@/components/ui/popover';
import { cn } from '@/lib/utils';
type DatePickerProps = {
value?: Date | null;
onChange?: (date: Date | undefined) => void;
placeholder?: string;
className?: string;
disabled?: boolean;
};
export function DatePicker({
value,
onChange,
placeholder = 'Pilih tanggal',
className,
disabled,
}: DatePickerProps) {
return (
<Popover>
<PopoverTrigger asChild>
<Button
variant="outline"
className={cn(
'w-full justify-start text-left font-normal',
!value && 'text-muted-foreground',
className,
)}
disabled={disabled}
>
<CalendarIcon className="mr-2 h-4 w-4" />
{value ? format(value, 'dd MMM yyyy') : placeholder}
</Button>
</PopoverTrigger>
<PopoverContent className="w-auto p-0" align="start">
<Calendar
mode="single"
selected={value ?? undefined}
defaultMonth={value ?? undefined}
captionLayout="dropdown"
onSelect={onChange}
initialFocus
/>
</PopoverContent>
</Popover>
);
}