Skip to content

add date picker #49

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
add date picker
  • Loading branch information
prichodko authored May 28, 2025
commit 1825eac663e6e46cb7d5126a35a830c39e34437b
58 changes: 58 additions & 0 deletions src/components/ui/date-picker.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
'use client'

import * as React from 'react'
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we update this per #65?

import { Calendar as CalendarIcon } from 'lucide-react'

import { cn } from '@/lib/utils'
import { Button } from '@/components/ui/button'
import { Calendar } from '@/components/ui/calendar'
import {
Popover,
PopoverContent,
PopoverTrigger,
} from '@/components/ui/popover'

const formatter = new Intl.DateTimeFormat('en-US', {
year: 'numeric',
month: 'long',
day: 'numeric',
})

export function DatePicker({
trigger,
date,
onChange,
...props
}: {
trigger?: React.ReactElement
date: Date
onChange: (date: Date) => void
} & React.ComponentType<typeof Calendar>) {
return (
<Popover>
<PopoverTrigger asChild>
{trigger ?? (
<Button
variant={'outline'}
className={cn(
'w-[280px] justify-start text-left font-normal',
!date && 'text-muted-foreground'
)}
>
<CalendarIcon className="mr-2 h-4 w-4" />
{date ? formatter.format(date) : <span>Pick a date</span>}
</Button>
)}
</PopoverTrigger>
<PopoverContent className="w-auto p-0">
<Calendar
mode="single"
selected={date}
onSelect={onChange}
initialFocus
{...props}
/>
</PopoverContent>
</Popover>
)
}