Skip to content

Commit 1d8cb84

Browse files
authored
Merge pull request #575 from gselderslaghs/timepicker-confirmation-buttons-util
enhancement(Timepicker) implementation with confirmation buttons util
2 parents 504b426 + b2866c4 commit 1d8cb84

File tree

1 file changed

+34
-27
lines changed

1 file changed

+34
-27
lines changed

src/timepicker.ts

Lines changed: 34 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -376,40 +376,51 @@ export class Timepicker extends Component<TimepickerOptions> {
376376
this.amOrPm = 'PM';
377377
}
378378

379-
private _createButton(text: string, visibility: string): HTMLButtonElement {
379+
/*private _createButton(text: string, visibility: string): HTMLButtonElement {
380380
const button = document.createElement('button');
381-
button.classList.add('btn', 'btn-flat', 'waves-effect', 'text');
381+
button.classList.add('btn', 'waves-effect', 'text');
382382
button.style.visibility = visibility;
383383
button.type = 'button';
384384
button.tabIndex = -1;
385385
button.innerText = text;
386386
return button;
387-
}
387+
}*/
388388

389389
_pickerSetup() {
390-
const clearButton = this._createButton(
390+
// clearButton.classList.add('timepicker-clear');
391+
// clearButton.addEventListener('click', this.clear);
392+
// this.footer.appendChild(clearButton);
393+
Utils.createButton(
394+
this.footer,
391395
this.options.i18n.clear,
392-
this.options.showClearBtn ? '' : 'hidden'
396+
['timepicker-clear'],
397+
this.options.showClearBtn,
398+
this.clear
393399
);
394-
clearButton.classList.add('timepicker-clear');
395-
clearButton.addEventListener('click', this.clear);
396-
this.footer.appendChild(clearButton);
397400

398401
if (!this.options.autoSubmit) {
399-
const confirmationBtnsContainer = document.createElement('div');
400-
confirmationBtnsContainer.classList.add('confirmation-btns');
401-
this.footer.append(confirmationBtnsContainer);
402-
403-
const cancelButton = this._createButton(this.options.i18n.cancel, '');
404-
cancelButton.classList.add('timepicker-close');
405-
cancelButton.addEventListener('click', this.close);
406-
confirmationBtnsContainer.appendChild(cancelButton);
407-
408-
const doneButton = this._createButton(this.options.i18n.done, '');
409-
doneButton.classList.add('timepicker-close');
410-
doneButton.addEventListener('click', this.done);
411-
confirmationBtnsContainer.appendChild(doneButton);
402+
/*const confirmationBtnsContainer = document.createElement('div');
403+
confirmationBtnsContainer.classList.add('confirmation-btns');
404+
this.footer.append(confirmationBtnsContainer);
405+
406+
const cancelButton = this._createButton(this.options.i18n.cancel, '');
407+
cancelButton.classList.add('timepicker-close');
408+
cancelButton.addEventListener('click', this.close);
409+
confirmationBtnsContainer.appendChild(cancelButton);
410+
411+
const doneButton = this._createButton(this.options.i18n.done, '');
412+
doneButton.classList.add('timepicker-close');
413+
//doneButton.addEventListener('click', this._finishSelection);
414+
confirmationBtnsContainer.appendChild(doneButton);*/
415+
Utils.createConfirmationContainer(
416+
this.footer,
417+
this.options.i18n.done,
418+
this.options.i18n.cancel,
419+
this.confirm,
420+
this.cancel
421+
);
412422
}
423+
413424
this._updateTimeFromInput();
414425
this.showView('hours');
415426
}
@@ -791,16 +802,12 @@ export class Timepicker extends Component<TimepickerOptions> {
791802

792803
confirm = () => {
793804
this.done();
794-
if (typeof this.options.onDone === 'function') {
795-
setTimeout(() => {
796-
this.options.onDone.call(this);
797-
}, this.options.duration / 2);
798-
}
805+
if (typeof this.options.onDone === 'function') this.options.onDone.call(this);
799806
}
800807

801808
cancel = () => {
802809
this.clear();
803-
if (typeof this.options.onDone === 'function') this.options.onCancel.call(this);
810+
if (typeof this.options.onCancel === 'function') this.options.onCancel.call(this);
804811
}
805812

806813
clear = () => {

0 commit comments

Comments
 (0)