Date Time Picker

A versatile date and time picker component that supports both direct input and calendar-based selection with natural language parsing.


Preview

Installation

Run the following command:

pnpm dlx shadcn@latest add 'https://ui.gesturs.com/r/date-time-picker.json'

Usage

import { DateTimePicker } from "@/components/ui/date-time-picker";
import { useState } from "react";
export default function Demo() {
  const [date, setDate] = useState<Date>(new Date());
  return <DateTimePicker date={date} setDate={setDate} />;
}

Features

  • 📅 Calendar-based date selection
  • ⌨️ Direct text input with natural language parsing
  • 🎨 Fully customizable styling
  • ♿ Keyboard navigation and screen reader support
  • 🌍 Internationalization support through date-fns
  • 📝 Natural language date parsing (e.g., "next friday at 3pm")

API Reference

NameTypeDefaultDescription
dateDateRequiredThe currently selected date
setDate(date: Date) => voidRequiredCallback function to update the selected date
formatstring"PPP"The date format string using date-fns format
classNamestringOptional CSS class name for the root element
popoverContentClassNamestringOptional CSS class name for the popover content
disabledbooleanfalseWhether the date picker is disabled
clearablebooleanfalseWhether to show a clear button
onClear() => voidCallback function when the clear button is clicked

Examples

Basic Usage

<DateTimePicker date={date} setDate={setDate} />;

Custom Format

<DateTimePicker date={date} format="PP p" /* Will display date and time*/ setDate={setDate} />;

With Clear Button

<DateTimePicker date={date} setDate={setDate} clearable onClear={() => setDate(new Date())} />;

Disabled State

<DateTimePicker date={date} setDate={setDate} disabled />;

Styling

The component uses Tailwind CSS for styling and can be customized using the className and popoverContentClassName props. The default styling follows your application's theme and can be overridden using Tailwind classes.

Accessibility

The date picker is built with accessibility in mind:

  • Full keyboard navigation support
  • ARIA labels and roles
  • Screen reader announcements for selected dates
  • Focus management