Docs
Date Picker
Date Picker
A component that allows users to select a date from a calendar.
Installation
npx shadcn-solid@latest add date-picker
Usage
import {
DatePicker,
DatePickerContent,
DatePickerInput,
DatePickerRangeText,
DatePickerTable,
DatePickerTableBody,
DatePickerTableCell,
DatePickerTableCellTrigger,
DatePickerTableHead,
DatePickerTableHeader,
DatePickerTableRow,
DatePickerView,
DatePickerViewControl,
DatePickerViewTrigger
} from "@/components/ui/date-picker";
<DatePicker>
<DatePickerInput />
<DatePickerContent>
<DatePickerView view="day">
{api => (
<>
<DatePickerViewControl>
<DatePickerViewTrigger>
<DatePickerRangeText />
</DatePickerViewTrigger>
</DatePickerViewControl>
<DatePickerTable>
<DatePickerTableHead>
<DatePickerTableRow>
<For each={api().weekDays}>
{weekDay => <DatePickerTableHeader>{weekDay.short}</DatePickerTableHeader>}
</For>
</DatePickerTableRow>
</DatePickerTableHead>
<DatePickerTableBody>
<For each={api().weeks}>
{week => (
<DatePickerTableRow>
<For each={week}>
{day => (
<DatePickerTableCell value={day}>
<DatePickerTableCellTrigger>{day.day}</DatePickerTableCellTrigger>
</DatePickerTableCell>
)}
</For>
</DatePickerTableRow>
)}
</For>
</DatePickerTableBody>
</DatePickerTable>
</>
)}
</DatePickerView>
<DatePickerView view="month">
{api => (
<>
<DatePickerViewControl>
<DatePickerViewTrigger>
<DatePickerRangeText />
</DatePickerViewTrigger>
</DatePickerViewControl>
<DatePickerTable>
<DatePickerTableBody>
<For
each={api().getMonthsGrid({
columns: 4,
format: "short"
})}
>
{months => (
<DatePickerTableRow>
<For each={months}>
{month => (
<DatePickerTableCell value={month.value}>
<DatePickerTableCellTrigger>{month.label}</DatePickerTableCellTrigger>
</DatePickerTableCell>
)}
</For>
</DatePickerTableRow>
)}
</For>
</DatePickerTableBody>
</DatePickerTable>
</>
)}
</DatePickerView>
<DatePickerView view="year">
{api => (
<>
<DatePickerViewControl>
<DatePickerViewTrigger>
<DatePickerRangeText />
</DatePickerViewTrigger>
</DatePickerViewControl>
<DatePickerTable>
<DatePickerTableBody>
<For
each={api().getYearsGrid({
columns: 4
})}
>
{years => (
<DatePickerTableRow>
<For each={years}>
{year => (
<DatePickerTableCell value={year.value}>
<DatePickerTableCellTrigger>{year.label}</DatePickerTableCellTrigger>
</DatePickerTableCell>
)}
</For>
</DatePickerTableRow>
)}
</For>
</DatePickerTableBody>
</DatePickerTable>
</>
)}
</DatePickerView>
</DatePickerContent>
</DatePicker>
Examples
Date Range Picker
Calendar
Sun | Mon | Tue | Wed | Thu | Fri | Sat |
---|---|---|---|---|---|---|
26 | 27 | 28 | 29 | 30 | 31 | 1 |
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 | 29 |
30 | 1 | 2 | 3 | 4 | 5 | 6 |
Jan | Feb | Mar | Apr |
May | Jun | Jul | Aug |
Sep | Oct | Nov | Dec |
2019 | 2020 | 2021 | 2022 |
2023 | 2024 | 2025 | 2026 |
2027 | 2028 | 2029 | 2030 |