pglejzer / timepicker-ui

timepicker-ui is an easy library with timepicker. Fully wrote with TypeScript. This library is based on Material Design from Google.
MIT License
64 stars 19 forks source link

[REQUEST] Destroy the picker or change some options #15

Closed Polm90 closed 2 years ago

Polm90 commented 2 years ago

Hi, I have a request.

I need to dynamically change some timepicker options such as the labels of the picker. If I create twice the picker, 2 instances overlaps so it doesn't work well (for example, changing the minutes, changes also the hour). So it could be nice to have a method to destroy the current instance and to create another one using the same input.

Another way to achieve my goal would be to add the possibility to change some picker options once the picker has been created (but I think it's more complicated).

Thank you

pglejzer commented 2 years ago

Hello, I will try to add in new version destroy and update methods. The destroy will destroy the instance of picker (by cloning). The update method will have 2 arguments, first will be required with options what you want to update and the second argument will be optional boolean which will allow create a new instance of this picker by triggering create method with updated options. Is this what you need?

Something like this:

const basic = document.querySelector('.basic') as HTMLDivElement;

const basicPicker = new TimepickerUI(basic, {
  enableScrollbar: true,
  backdrop: false,
  clockType: '12h',
});

basicPicker.create();

document.querySelector('#test-button')?.addEventListener('click', () => {
  basicPicker.destroy();
  basicPicker.update({ mobile: true, backdrop: true }, true);
});
Polm90 commented 2 years ago

Hello! Thank you.

I think that what you propose is what I need.

pglejzer commented 2 years ago

I added a new release with these methods. You can check it, if you find new bugs let me know.