Glass Date Picker
washiveil/glass-date-pickerFreeComponent
Date picker — glass field trigger, calendar in a strong-glass popover.
Install it
npx shadcn@latest add https://washiveil.alexchih.com/r/glass-date-picker.jsonSource
1'use client'23import * as React from 'react'4import { CalendarIcon } from 'lucide-react'56import { cn } from '@/lib/utils'7import { GlassButton } from './glass-button'8import { GlassPopover, GlassPopoverContent, GlassPopoverTrigger } from './glass-popover'9import { GlassCalendar } from './glass-calendar'1011export interface GlassDatePickerProps {12 value?: Date13 onValueChange?: (date: Date | undefined) => void14 placeholder?: string15 className?: string16 /** Custom date formatter. Defaults to Intl.DateTimeFormat with long month. */17 formatDate?: (date: Date) => string18}1920const defaultFormatDate = (date: Date) =>21 new Intl.DateTimeFormat(undefined, {22 year: 'numeric',23 month: 'long',24 day: 'numeric',25 }).format(date)2627function GlassDatePicker({28 value,29 onValueChange,30 placeholder = 'Pick a date',31 className,32 formatDate = defaultFormatDate,33}: GlassDatePickerProps) {34 const [open, setOpen] = React.useState(false)35 const [mounted, setMounted] = React.useState(false)3637 React.useEffect(() => {38 setMounted(true)39 }, [])4041 let displayText: string | undefined42 if (value) {43 // Before mount, render a deterministic ISO-like fallback so server/client44 // HTML is identical. After mount, swap to the locale-aware formatter.45 displayText = mounted ? formatDate(value) : value.toISOString().slice(0, 10)46 }4748 return (49 <GlassPopover open={open} onOpenChange={setOpen}>50 <GlassPopoverTrigger asChild>51 <GlassButton52 variant="secondary"53 className={cn(54 'w-full justify-start rounded-xl font-normal',55 !value && 'text-muted-foreground',56 className,57 )}58 >59 <CalendarIcon className="mr-2 size-4 text-muted-foreground" />60 {displayText ?? placeholder}61 </GlassButton>62 </GlassPopoverTrigger>63 <GlassPopoverContent className="w-auto p-0">64 <GlassCalendar65 mode="single"66 selected={value}67 onSelect={(date) => {68 onValueChange?.(date)69 setOpen(false)70 }}71 autoFocus72 />73 </GlassPopoverContent>74 </GlassPopover>75 )76}77GlassDatePicker.displayName = 'GlassDatePicker'7879export { GlassDatePicker }
What it pulls in
npm packages
Other registry items
Files it writes
More from washiveil
All 58 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| Ambient Fieldambient-field | washiveil | Components | Free | no deps | |
| Chipchip | washiveil | Components | Free | 1 dep | |
| Code Badgecode-badge | washiveil | Components | Free | no deps | |
| Glass Accordionglass-accordion | washiveil | Components | Free | 2 deps | |
| Glass Alertglass-alert | washiveil | Components | Free | 1 dep | |
| Glass Alert Dialogglass-alert-dialog | washiveil | Components | Free | 1 dep | |
| Glass Aspect Ratioglass-aspect-ratio | washiveil | Components | Free | 1 dep | |
| Glass Avatarglass-avatar | washiveil | Components | Free | 1 dep |
