A lightweight, customizable, TimePicker.
→ NPM
npm i timepicker.jsInstalling with npm needs Node.js 22, 24 or 26 (the LTS lines) and npm 10 or higher.
→ CDN Hosted - jsDelivr
Load:
<script src="https://cdn.jsdelivr.net/npm/timepicker.js/dist/timepicker.iife.js"></script>const timepicker = new TimePicker('#click-trigger', {
theme: 'dark',
lang: 'pt',
})
timepicker.on('change', (evt) => {
console.log(evt)
// {
// hour: string;
// minute: string;
// element: HTMLElement;
// }
}){String|Element} String or DOM node.
A picker binds to the element that exists when it is created. To use one with an input you add later, create the picker after the input is in the DOM.
Replacing that input binds nothing new. container.innerHTML += '…' does replace it, because it rebuilds every child of container. The picker stays attached to the old, detached element, and the new input won't open it. Add markup with container.insertAdjacentHTML('beforeend', '…') or container.append(…) instead, which keeps the existing inputs. Or create a new picker for the new element, after calling destroy() on the old one.
theme:'dark'; Theme colorlang:'en'; Header language
To be used programatically. Same for hide().
All targets passed to the constructor will be shown.
Removes the picker: its container, its listeners on the target, the document and its own elements, and every on() handler. After destroy(), show(), hide() and on() do nothing, and calling destroy() again is a no-op.
timepicker.on('open', function (evt) {});
timepicker.on('close', function (evt) {});
timepicker.on('change', function (evt) {});change receives { hour, minute, element }. hour and minute are strings such as '9' and '05', and each stays null until it has been picked, so the first change after picking only an hour has minute: null.
- dark
- red
- pink
- purple
- deep-purple
- indigo
- blue
- light-blue
- cyan
- teal
- green
- light-green
- lime
- yellow
- amber
- orange
- deep-orange
- brown
- blue-grey
If timepicker.js is useful to you, you can sponsor its maintenance on GitHub.
