A collection of helper utilities for KTUI including alerts and form helpers.
npm install @dadofcode/kt-helpersThe Alerts class offers a clean API for showing different types of modal dialogs:
- Simple alerts - Single button notifications
- Confirmation dialogs - Two-button prompts for user decisions
- Error alerts - Styled error notifications
All dialogs are built on top of KTUI's modal component and styled according to KTUI design principles.
import Alerts from '@dadofcode/kt-helpers';
// Simple success alert
Alerts.show('Success', 'Operation completed successfully', 'success');
// Confirmation dialog
Alerts.confirm('Confirm Action', 'Are you sure you want to proceed?', 'warning')
.then(result => {
if (result) {
// User clicked "Okay"
} else {
// User clicked "Cancel" or closed the dialog
}
});
// Error alert
Alerts.error('Error', 'Something went wrong', 'error');
// Delete confirmation
Alerts.delete('Delete Item', 'Are you sure you want to delete this item?')
.then(result => {
if (result) {
// User clicked "Delete"
}
});You can set global configuration options that will apply to all alerts:
Alerts.setConfig({
styles: {
// Override existing styles
success: {
backgroundClass: 'bg-emerald-100',
foregroundClass: 'text-emerald-800',
iconClass: 'ki-filled ki-check-circle text-emerald-600 text-3xl',
borderClass: 'border-emerald-200'
},
// Add custom types
custom: {
backgroundClass: 'bg-purple-100',
foregroundClass: 'text-purple-800',
iconClass: 'ki-filled ki-star text-purple-600 text-3xl',
borderClass: 'border-purple-200'
}
},
// Change the default type
defaultType: 'info'
});For maximum flexibility, use the fire() method with a configuration object:
Alerts.fire({
title: 'Custom Alert',
message: 'This is a fully customized alert',
type: 'custom', // Can be any type defined in your config
buttons: [
{ text: 'Cancel', className: 'kt-btn kt-btn-light', value: false, dismiss: true },
{ text: 'Continue', className: 'kt-btn kt-btn-primary', value: true, dismiss: true },
{ text: 'Help', className: 'kt-btn kt-btn-info', value: 'help', dismiss: false }
],
customStyles: {
// Override just the icon for this specific alert
iconClass: 'ki-filled ki-rocket text-purple-600 text-3xl'
}
}).then(result => {
console.log('User selected:', result);
});The following alert types are supported:
success- Green styling with check iconwarning- Yellow styling with information iconsecondary- Secondary color styling with information iconinfo- Blue styling with information iconerror- Red styling with cross icondestructive- Red styling with trash icon
Shows a simple alert with a single "Okay" button.
Shows a confirmation dialog with "Cancel" and "Okay" buttons. Returns a Promise that resolves to true if "Okay" is clicked, or false if "Cancel" is clicked or the dialog is closed.
Shows an error alert with a single "Close" button.
This module is built on top of KTUI, a modern UI framework by KeenThemes. It leverages KTUI's modal component and styling classes to create consistent, responsive alert dialogs.
The alerts are styled using KTUI's utility classes for colors, spacing, and typography, ensuring they match the overall design system of the application.
Icons are provided by KeenIcons and are used to enhance the visual appeal of the alerts.
The module is peer-dependant on KTUI and intended to be used with Metronic 9 Metronic.