date-picker
neobrutalui/date-pickerFreeComponent
Select a date from a calendar popover.
Live preview
live · rendered by the registry
Rendered by neobrutalui on their own page — this is the component running, not a screenshot of it.Install it
npx shadcn@latest add https://www.neobrutalui.live/r/date-picker.jsonSource
1"use client"23import * as React from "react"4import { Popover as BasePopover } from "@base-ui/react/popover"5import { ChevronLeft, ChevronRight, Calendar } from "lucide-react"6import { cn } from "@/lib/utils"78const DAYS = ["Su", "Mo", "Tu", "We", "Th", "Fr", "Sa"] as const910function getDaysInMonth(year: number, month: number) {11 return new Date(year, month + 1, 0).getDate()12}1314function getFirstDayOfMonth(year: number, month: number) {15 return new Date(year, month, 1).getDay()16}1718function formatDate(date: Date) {19 return date.toLocaleDateString("en-US", {20 month: "short",21 day: "numeric",22 year: "numeric",23 })24}2526function getMonthName(month: number) {27 return new Date(2000, month).toLocaleDateString("en-US", { month: "long" })28}2930function isSameDay(a: Date | null, b: Date | null) {31 if (!a || !b) return false32 return (33 a.getFullYear() === b.getFullYear() &&34 a.getMonth() === b.getMonth() &&35 a.getDate() === b.getDate()36 )37}3839function isToday(date: Date) {40 return isSameDay(date, new Date())41}4243interface DatePickerProps {44 value?: Date | null45 onChange?: (date: Date | null) => void46 placeholder?: string47 disabled?: boolean48 className?: string49}5051function DatePicker({52 value = null,53 onChange,54 placeholder = "Select date",55 disabled = false,56 className,57}: DatePickerProps) {58 const [open, setOpen] = React.useState(false)59 const [selectedDate, setSelectedDate] = React.useState<Date | null>(value)60 const [pendingDate, setPendingDate] = React.useState<Date | null>(value)61 const [displayMonth, setDisplayMonth] = React.useState(62 value ? value.getMonth() : new Date().getMonth()63 )64 const [displayYear, setDisplayYear] = React.useState(65 value ? value.getFullYear() : new Date().getFullYear()66 )6768 React.useEffect(() => {69 setSelectedDate(value)70 setPendingDate(value)71 }, [value])7273 const daysInMonth = getDaysInMonth(displayYear, displayMonth)74 const firstDay = getFirstDayOfMonth(displayYear, displayMonth)7576 const prevMonthDays = getDaysInMonth(77 displayMonth === 0 ? displayYear - 1 : displayYear,78 displayMonth === 0 ? 11 : displayMonth - 179 )8081 const calendarDays: { day: number; month: number; year: number; isCurrentMonth: boolean }[] = []8283 // Previous month trailing days84 for (let i = firstDay - 1; i >= 0; i--) {85// … truncated
What it pulls in
npm packages
Other registry items
More from neobrutalui
All 24 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| accordionaccordion | neobrutalui | Components | Free | 2 deps | |
| alertalert | neobrutalui | Components | Free | 1 dep | |
| avataravatar | neobrutalui | Components | Free | no deps | |
| badgebadge | neobrutalui | Components | Free | 1 dep | |
| buttonbutton | neobrutalui | Components | Free | 1 dep | |
| cardcard | neobrutalui | Components | Free | no deps | |
| checkboxcheckbox | neobrutalui | Components | Free | 2 deps | |
| dialogdialog | neobrutalui | Components | Free | 2 deps |
