timepicker-ui
4.5.0GitHub
timepicker-ui

A time picker you can configure part by part.

Each part of the picker maps to one option or one tp-ui- class. Analog clock, scroll wheel or compact wheel. No dependencies, 12 themes, TypeScript types, safe to render on the server.

Get started
npm install timepicker-ui
Fig. 1Analog mode with the default theme. Drag the hand or type a time.
  1. labels.clockTitleHeader text. Every label is an option.
  2. clock.incrementHoursHour step: 1, 2, 3, 4 or 6.
  3. ui.mode'clock', 'wheel' or 'compact-wheel'.
  4. labels.ok · labels.cancelButton text. Optional in inline mode.
  5. clock.type'12h', '24h' or 'auto' from the locale.
  6. clock.incrementMinutesMinute step, for example 5 or 15.
  7. clock.discreteHourJumpThe hour hand jumps from hour to hour while you drag.
  8. .tp-ui-wrapperRoot class. Every part has a stable tp-ui- class.

Three modes, one option

The analog clock is built in. The scroll wheel and the compact wheel come from the wheel plugin, so they only reach your bundle when you import it.

Fig. 2aClock ui: { mode: 'clock' }
Fig. 2bWheel ui: { mode: 'wheel' }
Fig. 2cCompact wheel ui: { mode: 'compact-wheel' }

Twelve themes

Each theme is a CSS file that sets the picker's custom properties. Pick one here, or write your own on top of main.css.

Fig. 3The same picker in each built-in theme.
ui.theme
import 'timepicker-ui/index.css';
new TimepickerUI(input, { ui: { theme: 'basic' } }).create();

What the picker does

Every feature has an option and a page in the docs. Options are grouped by what they change: clock, ui, labels, behavior, callbacks.

Table 1 Features and the options that control them. All options
No.FeatureOptionDocs
0112-hour, 24-hour, or the browser's choiceclock.type12h/24h Format
02Seconds field, wheel column and clock faceclock.showSecondsSeconds
03Hours, minutes or ranges that can't be pickedclock.disabledTimeDisabled Time
04Render in the page instead of a modalui.inlineInline Mode
05Layout for phonesui.mobileMobile Support
06Button that clears the valueui.clearButtonClear Button
07Every text, in any languagelabels.*Localization
08Keyboard, focus trap and screen-reader labelsbuilt inAccessibility
09Events for every selectioncallbacks.*, picker.on()Events
10Types for every option and eventincludedTypeScript

Plugins you import when you need them

Register a plugin once and its options start working. Sizes are min + gzip from the bundle analysis. The core is 25.66 KB.

Range
Start and end time in one picker, with a minimum and maximum duration.import { RangePlugin } from 'timepicker-ui/plugins/range';
3.68 KB
Timezone
A timezone dropdown next to the time, with keyboard support.import { TimezonePlugin } from 'timepicker-ui/plugins/timezone';
2.57 KB
Wheel
The scroll wheel and compact-wheel modes from Fig. 2.import { WheelPlugin } from 'timepicker-ui/plugins/wheel';
Bundle analysis
Fig. 4Range plugin, at least 30 minutes.

Works where your app runs

The core is plain TypeScript with no DOM access at import time, so it runs under Next.js, Nuxt and other SSR setups. React has its own wrapper.

main.ts
import { TimepickerUI } from 'timepicker-ui';
import 'timepicker-ui/index.css';
const picker = new TimepickerUI('#time', {
clock: { type: '24h' },
callbacks: { onConfirm: (data) => console.log(data.hour, data.minutes) },
});
picker.create();

Open source, MIT

Written and maintained by one developer. No runtime dependencies, no telemetry. Bugs and ideas go to GitHub issues. Every release is listed in the changelog.

Star on GitHub
Esc