Migration Guide v3 to v4
Breaking ChangesComplete guide for upgrading from v3.x to v4.0.0
Important Notice
Version 4.0.0 introduces breaking changes in the options structure. There is NO backward compatibility - all v3.x code will break and must be updated.
Migration typically takes 15-60 minutes depending on your codebase size.
Migrating from v2.x?
If you're still using version 2.x, please see the Legacy Migration Guide v2 to v3 first, then follow this guide to upgrade to v4.
Option names from 4.5.0
The v4 side of this guide uses the option names from 4.5.0. Some options had other names in 4.0 to 4.4. Those names still work until 5.0 and are listed in Renamed in 4.5.0.
What Changed?
#The previous flat structure with 40+ fields has been reorganized into 5 logical groups to improve code clarity, maintainability, and developer experience:
clock- Clock behavior configuration
ui- UI appearance and behavior
labels- Text labels customization
behavior- General behavior settings
callbacks- Event handler callbacks
Before & After
#Old API (v3.x) - Flat Structure
const timepicker = new TimepickerUI('#input', {clockType: '12h',amLabel: 'AM',pmLabel: 'PM',okLabel: 'OK',cancelLabel: 'Cancel',timeLabel: 'Select time',animation: true,backdrop: true,theme: 'basic',incrementHours: 1,incrementMinutes: 5,focusTrap: true,delayHandler: 300,mobile: false,editable: false,onOpen: (event) => console.log('opened', event),onConfirm: (event) => console.log('confirmed', event),});
New API (v4) - Grouped Structure
const timepicker = new TimepickerUI('#input', {clock: {type: '12h',incrementHours: 1,incrementMinutes: 5,},ui: {animation: true,backdrop: true,theme: 'basic',initialView: 'clock',editable: false,},labels: {am: 'AM',pm: 'PM',ok: 'OK',cancel: 'Cancel',clockTitle: 'Select time',},behavior: {focusTrap: true,delayHandler: 300,},callbacks: {onOpen: (event) => console.log('opened', event),onConfirm: (event) => console.log('confirmed', event),},});
Complete Field Mapping
#Clock Options
| v3.x (Flat) | v4.5 (Grouped) |
|---|---|
clockType | clock.type |
incrementHours | clock.incrementHours |
incrementMinutes | clock.incrementMinutes |
autoSwitchToMinutes | clock.autoSwitchToMinutes |
disabledTime | clock.disabledTime |
currentTime: true | clock.defaultTime: 'now' |
currentTime: { time, updateInput } | clock.defaultTime: { time, updateInput } |
UI Options
| v3.x (Flat) | v4.5 (Grouped) |
|---|---|
theme | ui.theme |
animation | ui.animation |
backdrop | ui.backdrop |
mobile: true | ui.initialView: 'keyboard' |
enableSwitchIcon | ui.viewSwitch |
editable | ui.editable |
enableScrollbar | ui.allowPageScroll |
cssClass | ui.cssClass |
appendModalSelector | ui.appendTo |
iconTemplate | ui.keyboardIcon |
iconTemplateMobile | ui.clockIcon |
inline | ui.inline |
inline: { containerId: 'x' } | ui.inline: { container: '#x' } |
Label Options
| v3.x (Flat) | v4.5 (Grouped) |
|---|---|
amLabel | labels.am |
pmLabel | labels.pm |
okLabel | labels.ok |
cancelLabel | labels.cancel |
timeLabel | labels.clockTitle |
mobileTimeLabel | labels.keyboardTitle |
hourMobileLabel | labels.hour |
minuteMobileLabel | labels.minute |
Behavior Options
| v3.x (Flat) | v4.5 (Grouped) |
|---|---|
focusInputAfterCloseModal | behavior.returnFocus |
focusTrap | behavior.focusTrap |
delayHandler | behavior.delayHandler |
id | behavior.id |
Callback Options
| v3.x (Flat) | v4.5 (Grouped) |
|---|---|
onOpen | callbacks.onOpen |
onCancel | callbacks.onCancel |
onConfirm | callbacks.onConfirm |
onUpdate | callbacks.onUpdate |
onSelectHour | callbacks.onSelectHour |
onSelectMinute | callbacks.onSelectMinute |
onSelectAM, onSelectPM | callbacks.onSelectPeriod (data.type is 'AM' or 'PM') |
onError | callbacks.onError |
Accessing & Updating Options
#Accessing Options in Code
v3.x
const options = timepicker.options;console.log(options.clockType); // '12h'console.log(options.amLabel); // 'AM'
v4.0.0
const options = timepicker.options;console.log(options.clock.type); // '12h'console.log(options.labels.am); // 'AM'
Updating Options
v3.x - NO LONGER WORKS
timepicker.update({options: {clockType: '24h',animation: false,},});
v4.5 - REQUIRED
timepicker.setOptions({clock: { type: '24h' },ui: { animation: false },});
Before 4.5.0, pass the same groups to timepicker.update({ options }). It still works until 5.0.
TypeScript Support
#Version 4.0.0 provides improved TypeScript types for the new grouped structure:
import type {TimepickerOptions, // Main grouped options typeClockOptions, // Clock groupUIOptions, // UI groupLabelsOptions, // Labels groupBehaviorOptions, // Behavior groupCallbacksOptions, // Callbacks group} from 'timepicker-ui';const options: TimepickerOptions = {clock: {type: '12h',incrementMinutes: 5,},ui: {theme: 'basic',animation: true,},labels: {ok: 'Confirm',cancel: 'Close',},};const timepicker = new TimepickerUI('#input', options);
Note: OptionTypes Is Deprecated
OptionTypes is still exported, but it describes the old flat v3 options and is deprecated in favour of TimepickerOptions. It is removed in 5.0.
Benefits of the New Structure
#- Better Organization
- Related options are grouped together logically
- Improved Discoverability
- Easier to find related settings
- Autocomplete by Group
- Suggestions list only the options of the current group
- Reduced Cognitive Load
- Smaller, focused option groups
- Future-Proof
- Easier to add new options without cluttering
- Cleaner API
- No more 40+ flat fields to navigate
Common Migration Examples
#Basic Setup
// v4.0.0const timepicker = new TimepickerUI('#input', {clock: { type: '12h' },});
Advanced Setup
// v4.5const timepicker = new TimepickerUI('#input', {clock: {type: '24h',incrementMinutes: 15,disabledTime: {ranges: ['00:00 - 06:00', '22:00 - 23:59'],},},ui: {theme: 'm3-green',animation: true,backdrop: true,initialView: 'clock',editable: true,},labels: {clockTitle: 'Pick a time',ok: 'Confirm',cancel: 'Dismiss',},behavior: {focusTrap: true,delayHandler: 300,returnFocus: true,},callbacks: {onOpen: () => console.log('Opened'),onConfirm: (data) => console.log('Time selected:', data),onCancel: () => console.log('Cancelled'),},});
Inline Mode
// v4.5const timepicker = new TimepickerUI('#input', {ui: {inline: {enabled: true,container: '#timepicker-container',showButtons: false,autoUpdate: true,},},behavior: {focusTrap: false, // Automatically set if not specified},});
FAQ
#- Will my v3.x code break?
- Yes. v4.0.0 is a major breaking change. You MUST update all code to use grouped options.
- Is there a migration layer?
- No. There is NO backward compatibility. All old flat structure code will break.
- Can I mix flat and grouped structures?
- No. Only grouped structure is supported in v4.0.0.
- How long will migration take?
- Depending on your codebase size, it should take 15-60 minutes using find-and-replace.
Need Help?
#If you encounter issues during migration: