Skip to main content

TimePicker

The TimePicker component provides time selection with iOS wheel style or Material Design 3 clock face.

Import

import { TimePicker, type TimeValue } from '@dreamstack-us/kaal';

Props

value

Type: TimeValue ({ hours: number; minutes: number }) Required: Yes

The currently selected time.

const [time, setTime] = useState<TimeValue>({ hours: 9, minutes: 30 });
<TimePicker value={time} onChange={setTime} />

onChange

Type: (time: TimeValue) => void Required: Yes

Callback fired when the selected time changes.

theme

Type: 'native' | 'ios' | 'android' Default: 'native'

The visual theme for the picker.

  • native - Uses platform-specific native picker
  • ios - Wheel-based picker (iOS style)
  • android - Clock face picker (Material Design 3)
// iOS wheel style
<TimePicker value={time} onChange={setTime} theme="ios" />

// Material clock face
<TimePicker value={time} onChange={setTime} theme="android" />

is24Hour

Type: boolean Default: false

Whether to use 24-hour format.

<TimePicker
value={time}
onChange={setTime}
is24Hour={true}
/>

minuteInterval

Type: 1 | 5 | 10 | 15 | 30 Default: 1

The interval for minute selection.

<TimePicker
value={time}
onChange={setTime}
minuteInterval={15}
/>

minTime

Type: TimeValue Default: undefined

The minimum selectable time.

<TimePicker
value={time}
onChange={setTime}
minTime={{ hours: 9, minutes: 0 }}
/>

maxTime

Type: TimeValue Default: undefined

The maximum selectable time.

<TimePicker
value={time}
onChange={setTime}
maxTime={{ hours: 17, minutes: 0 }}
/>

themeOverrides

Type: TimePickerThemeOverrides Default: undefined

Custom theme overrides for styling the TimePicker without using a theme provider. This is the recommended approach for web apps and when you want to integrate with your existing design system.

<TimePicker
value={time}
onChange={setTime}
themeOverrides={{
primaryColor: '#22d3ee',
backgroundColor: '#1f2937',

// Wheel picker (iOS style)
wheelContainerBackground: '#1f2937',
wheelTextColor: '#FFFFFF',
wheelSeparatorColor: '#374151',

// Clock face (Material style)
clockBackground: '#374151',
clockHandColor: '#22d3ee',
clockTextColor: '#FFFFFF',
clockTextSelectedColor: '#FFFFFF',
clockCenterColor: '#22d3ee',

// Period toggle (AM/PM)
periodBackground: '#374151',
periodActiveBackground: 'rgba(34, 211, 238, 0.2)',
periodTextColor: '#9ca3af',
periodTextActiveColor: '#22d3ee',

// Time field display
timeFieldBackground: '#374151',
timeFieldActiveBackground: '#22d3ee',
textColor: '#FFFFFF',
textActiveColor: '#FFFFFF',

borderRadius: 16,
}}
/>

TimePickerThemeOverrides Properties

PropertyTypeDescription
primaryColorstringPrimary accent color
backgroundColorstringContainer background color
borderRadiusnumberBorder radius for container
Wheel Picker (iOS style)
wheelContainerBackgroundstringBackground of the wheel picker
wheelTextColorstringText color in wheel
wheelTextSelectedColorstringText color of selected item
wheelSeparatorColorstringColor of the colon separator
wheelSelectionHighlightstringBackground of selection indicator
Clock Face (Material style)
clockBackgroundstringBackground of the clock face
clockHandColorstringColor of the clock hand
clockTextColorstringColor of clock numbers
clockTextSelectedColorstringColor of selected number
clockCenterColorstringColor of the center dot
clockSelectionColorstringColor of selection dot on edge
Period Toggle (AM/PM)
periodBackgroundstringBackground of period buttons
periodActiveBackgroundstringBackground of active period
periodBorderColorstringBorder color of period buttons
periodTextColorstringText color of period buttons
periodTextActiveColorstringText color of active period
Time Field Display
timeFieldBackgroundstringBackground of time fields
timeFieldActiveBackgroundstringBackground of active time field
textColorstringText color of time fields
textActiveColorstringText color of active time field
separatorColorstringColor of the colon separator

Examples

iOS Wheel Picker

import { TimePicker, type TimeValue } from '@dreamstack-us/kaal';
import { useState } from 'react';

function IOSTimePicker() {
const [time, setTime] = useState<TimeValue>({ hours: 9, minutes: 30 });

return (
<TimePicker
value={time}
onChange={setTime}
theme="ios"
is24Hour={false}
/>
);
}

Material Clock Face

import { TimePicker, type TimeValue } from '@dreamstack-us/kaal';
import { useState } from 'react';

function MaterialTimePicker() {
const [time, setTime] = useState<TimeValue>({ hours: 14, minutes: 30 });

return (
<TimePicker
value={time}
onChange={setTime}
theme="android"
is24Hour={true}
/>
);
}

Business Hours Only

import { TimePicker, type TimeValue } from '@dreamstack-us/kaal';
import { useState } from 'react';

function BusinessHoursPicker() {
const [time, setTime] = useState<TimeValue>({ hours: 9, minutes: 0 });

return (
<TimePicker
value={time}
onChange={setTime}
theme="native"
minTime={{ hours: 9, minutes: 0 }}
maxTime={{ hours: 17, minutes: 0 }}
minuteInterval={30}
/>
);
}

TypeScript

import type { TimePickerProps, TimeValue, TimePickerThemeOverrides } from '@dreamstack-us/kaal';

// TimeValue type
type TimeValue = {
hours: number; // 0-23
minutes: number; // 0-59
};

// TimePickerProps interface
interface TimePickerProps {
value: TimeValue;
onChange: (time: TimeValue) => void;
theme?: 'native' | 'ios' | 'android';
is24Hour?: boolean;
minuteInterval?: 1 | 5 | 10 | 15 | 30;
minTime?: TimeValue;
maxTime?: TimeValue;
themeOverrides?: TimePickerThemeOverrides;
}

// TimePickerThemeOverrides interface
interface TimePickerThemeOverrides {
// General
primaryColor?: string;
backgroundColor?: string;
borderRadius?: number;
textColor?: string;

// Wheel picker
wheelContainerBackground?: string;
wheelSelectionHighlight?: string;
wheelSeparatorColor?: string;
wheelTextColor?: string;
wheelTextSelectedColor?: string;

// Clock face
clockBackground?: string;
clockHandColor?: string;
clockTextColor?: string;
clockTextSelectedColor?: string;
clockCenterColor?: string;
clockSelectionColor?: string;

// Period toggle
periodBackground?: string;
periodActiveBackground?: string;
periodBorderColor?: string;
periodTextColor?: string;
periodTextActiveColor?: string;

// Time field
timeFieldBackground?: string;
timeFieldActiveBackground?: string;
textActiveColor?: string;
separatorColor?: string;
}

Utility Functions

Kaal provides utility functions for working with time values:

import { to12Hour, to24Hour, formatTime } from '@dreamstack-us/kaal';

// Convert 24h to 12h format
const { hours12, period } = to12Hour(14); // { hours12: 2, period: 'PM' }

// Convert 12h to 24h format
const hours24 = to24Hour(2, 'PM'); // 14

// Format time for display
const display = formatTime({ hours: 14, minutes: 30 }, false); // "2:30 PM"