Unkey
ComponentsDialogs

DateTime

A comprehensive date and time picker component that supports both single date and date range selection with time input capabilities.

Overview

The DateTime component provides a flexible and accessible date and time selection interface. It's designed to handle both single date selection and date range picking with optional time input, making it perfect for filtering, scheduling, and data analysis use cases.

Usage

import { Button, DateTime, Range, TimeUnit } from "@unkey/ui";
 
export default function MyComponent() {
  const handleDateTimeChange = (date?: Range, startTime?: TimeUnit, endTime?: TimeUnit) => {
    // Handle date and time changes
  };
 
  return (
    <DateTime onChange={handleDateTimeChange}>
      <DateTime.Calendar mode="range" />
      <DateTime.TimeInput type="range" />
      <DateTime.Actions>
        <Button variant="primary">Apply</Button>
      </DateTime.Actions>
    </DateTime>
  );
}

Examples

Basic Usage

A comprehensive example showing date range selection with time input and apply functionality.

Date Range: no date - no date

Time Span: undefined:undefined:undefined - undefined:undefined:undefined

July 2025
SuMoTuWeThFrSa
::
::

Features

  • Date Range Selection: Support for both single date and date range picking
  • Time Input: Precise time selection with hours, minutes, and seconds
  • Accessibility: Built-in keyboard navigation and screen reader support
  • Responsive: Adapts to different screen sizes and orientations
  • Customizable: Extensive styling and configuration options
  • Date Constraints: Min/max date validation and disabled date ranges
  • Context Management: Internal state management with external change callbacks

Props

PropTypeDefaultDescription
childrenReact.ReactNodeundefinedChild components (Calendar, TimeInput, Actions)
classNamestringundefinedAdditional CSS classes for the container
minDateDateundefinedMinimum selectable date
maxDateDateundefinedMaximum selectable date
initialRangeDateRangeundefinedInitial date range selection
onChange(date?: DateRange, start?: TimeUnit, end?: TimeUnit) => voidundefinedCallback when date or time changes

Calendar Props

PropTypeDefaultDescription
mode"single" | "range""single"Calendar selection mode
classNamestringundefinedAdditional CSS classes
classNamesRecord<string, string>undefinedCustom class names for calendar elements
showOutsideDaysbooleantrueShow days from adjacent months
disabledDatesArray<{from?: Date, to?: Date, before?: Date, after?: Date}>undefinedDates to disable

TimeInput Props

PropTypeDefaultDescription
type"single" | "range""single"Time input type (single time or time range)
classNamestringundefinedAdditional CSS classes
inputClassNamesstringundefinedCustom classes for input fields

Actions Props

PropTypeDefaultDescription
classNamestringundefinedAdditional CSS classes
childrenReact.ReactNodeundefinedAction buttons or content

Structure

The DateTime component is composed of several sub-components that work together:

  1. DateTime - The main container component that provides context
  2. DateTime.Calendar - Calendar component for date selection
  3. DateTime.TimeInput - Time input component for precise time selection
  4. DateTime.Actions - Container for action buttons

Styling

The component includes default styling with:

  • Consistent spacing and typography
  • Dark mode support
  • Responsive design
  • Customizable through className props
  • Focus states for accessibility

Custom Styling

You can customize the appearance using className props:

<DateTime className="custom-container">
  <DateTime.Calendar 
    className="custom-calendar"
    classNames={{
      day_selected: "bg-blue-500 text-white",
      day_today: "bg-gray-100"
    }}
  />
  <DateTime.TimeInput className="custom-time-input" />
  <DateTime.Actions className="custom-actions">
    <Button>Custom Button</Button>
  </DateTime.Actions>
</DateTime>

Accessibility

The DateTime component is built with accessibility in mind:

  • Keyboard Navigation: Full keyboard support for all interactions
  • Screen Reader Support: Proper ARIA labels and announcements
  • Focus Management: Clear focus indicators and logical tab order
  • High Contrast: Maintains proper contrast ratios
  • Semantic HTML: Uses appropriate HTML elements and roles
  • Date Format: Supports various date formats and localization

On this page