Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enhancement(Utils) implemented confirmation container util methods #574

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@
const now = new Date().getTime();
if (!previous && options.leading === false) previous = now;
const remaining = wait - (now - previous);
context = this;

Check warning on line 273 in src/utils.ts

View workflow job for this annotation

GitHub Actions / build

Unexpected aliasing of 'this' to local variable
if (remaining <= 0) {
clearTimeout(timeout);
timeout = null;
Expand All @@ -283,4 +283,46 @@
return result;
};
}

/**
* Renders confirm/close buttons with callback function
*/
static createConfirmationContainer(
container: HTMLElement,
confirmText: string,
cancelText: string,
onConfirm: (Function: object) => void,
onCancel: (Function: object) => void
): void {
const confirmationButtonsContainer = document.createElement('div');
confirmationButtonsContainer.classList.add('confirmation-btns');
container.append(confirmationButtonsContainer);

this.createButton(confirmationButtonsContainer, cancelText, ['btn-cancel'], true, onCancel);
this.createButton(confirmationButtonsContainer, confirmText, ['btn-confirm'], true, onConfirm);
}

/**
* Renders a button with optional callback function
*/
static createButton(
container: HTMLElement,
text: string,
className: string[] = [],
visibility: boolean = true,
callback: (Function: object) => void = null
): void {
className = className.concat(['btn', 'waves-effect', 'text']);
const button = document.createElement('button');
button.className = className.join(' ');
button.style.visibility = visibility ? 'visible' : 'hidden';
button.type = 'button';
button.tabIndex = !!visibility ? 0 : -1;
button.innerText = text;
button.addEventListener('click', callback);
button.addEventListener('keypress', (e) => {
if (Utils.keys.ENTER.includes(e.key)) callback(e);
});
container.append(button);
}
}
Loading