mirror of
https://github.com/supabase/supabase.git
synced 2026-10-13 05:09:12 +03:00
* chore: update react-day-picker * fix(design system): date picker demos * refactor(date picker): change logs date picker to use react-day-picker * refactor(date pickers): change remaining date pickers to use react-day-picker * cleanup(date pickers): minor code cleanup * fix(date picker): fix behavior for single day selection
63 lines
1.7 KiB
TypeScript
63 lines
1.7 KiB
TypeScript
'use client'
|
|
|
|
import { addDays, format } from 'date-fns'
|
|
import { Calendar as CalendarIcon } from 'lucide-react'
|
|
import * as React from 'react'
|
|
import { DateRange } from 'react-day-picker'
|
|
|
|
import { cn } from '@/lib/utils'
|
|
import {
|
|
Button,
|
|
Calendar,
|
|
Popover_Shadcn_,
|
|
PopoverContent_Shadcn_,
|
|
PopoverTrigger_Shadcn_,
|
|
} from 'ui'
|
|
|
|
export default function DatePickerWithRange({ className }: React.HTMLAttributes<HTMLDivElement>) {
|
|
const [date, setDate] = React.useState<DateRange | undefined>({
|
|
from: new Date(2022, 0, 20),
|
|
to: addDays(new Date(2022, 0, 20), 20),
|
|
})
|
|
|
|
return (
|
|
<div className={cn('grid gap-2', className)}>
|
|
<Popover_Shadcn_>
|
|
<PopoverTrigger_Shadcn_ asChild>
|
|
<Button
|
|
id="date"
|
|
type={'outline'}
|
|
className={cn(
|
|
'w-[300px] justify-start text-left font-normal',
|
|
!date && 'text-muted-foreground'
|
|
)}
|
|
icon={<CalendarIcon className="h-4 w-4" />}
|
|
>
|
|
{date?.from ? (
|
|
date.to ? (
|
|
<>
|
|
{format(date.from, 'LLL dd, y')} - {format(date.to, 'LLL dd, y')}
|
|
</>
|
|
) : (
|
|
format(date.from, 'LLL dd, y')
|
|
)
|
|
) : (
|
|
<span>Pick a date</span>
|
|
)}
|
|
</Button>
|
|
</PopoverTrigger_Shadcn_>
|
|
<PopoverContent_Shadcn_ className="w-auto p-0" align="start">
|
|
<Calendar
|
|
initialFocus
|
|
mode="range"
|
|
defaultMonth={date?.from}
|
|
selected={date}
|
|
onSelect={setDate}
|
|
numberOfMonths={2}
|
|
/>
|
|
</PopoverContent_Shadcn_>
|
|
</Popover_Shadcn_>
|
|
</div>
|
|
)
|
|
}
|