shadcn-templ 2.0 beta. Switch to templUI v1
1.7k

Date Picker

A date picker component with range and presets.

package examples import (

Installation

The Date Picker is built using a composition of the Popover and the Calendar components.

See installation instructions for the Popover and the Calendar components.

Usage

components/example_date_picker.templ
@popover.Popover(popover.Props{ID: "date-picker"}) {	{{		triggerAttrs := popover.Trigger(ctx)		triggerAttrs["data-empty"] = "true"		triggerAttrs["data-tui-datepicker-display"] = ""	}}	@button.Button(button.Props{		Variant:    button.VariantOutline,		Class:      "w-[212px] justify-between text-left font-normal data-[empty=true]:text-muted-foreground",		Attributes: triggerAttrs,	}) {		<span>Pick a date</span>		<span data-icon="inline-end" class="contents">			@icon.ChevronDown()		</span>	}	@popover.Content(popover.ContentProps{		Class: "w-auto p-0",		Side:  popover.SideBottom,		Align: popover.AlignStart,	}) {		@calendar.Calendar()	}}

Listen for the calendar’s calendar-change event to show the selected date in the trigger, see the demo above for the full wiring.

Composition

A date picker is built from Popover and Calendar (there is no DatePicker root component):

popover.Popover├── popover.Trigger└── popover.Content    └── calendar.Calendar

Basic

A basic date picker component.

package examples import (

Range Picker

A date picker component for selecting a range of dates.

package examples import (

Date of Birth

A date picker component for selecting a date of birth. This component includes a dropdown caption layout for date and month selection.

package examples import (

Input

A date picker component with an input field for selecting a date.

package examples import (

Time Picker

A date picker component with a time input field for selecting a time.

package examples import (