diff --git a/src/docs/demos/alert/alert-demo.md b/src/docs/demos/alert/alert-demo.md index 617d033..db58d63 100644 --- a/src/docs/demos/alert/alert-demo.md +++ b/src/docs/demos/alert/alert-demo.md @@ -1,5 +1,5 @@ ## ngbs-alert -**alert-type** (*string*, optional) - The alert type, as supplied by bottstrap: "success", "info", "warning", "danger". When no value is supplied the type defaults to "info". +**alert-type** (*string*, optional) - The alert type, as supplied by Bootstrap: "success", "info", "warning", or "danger". Defaults to `'info'`. -**alert-dismissible** (*boolean*, optional) - Whether or not to show a close button inside the alert. Defaults to false. \ No newline at end of file +**alert-dismissible** (*boolean*, optional) - Whether or not to show a close button inside the alert. Defaults to `false`. \ No newline at end of file diff --git a/src/library/alert/alert.component.js b/src/library/alert/alert.component.js index a9cc870..4e64f60 100644 --- a/src/library/alert/alert.component.js +++ b/src/library/alert/alert.component.js @@ -2,14 +2,30 @@ import template from './alert.html'; const DEFAULT_ALERT_TYPE = 'info'; +const DEFAULT_ALERT_DISMISSIBLE = false; class controller { + constructor() { + this.dismissed = false; + } $onInit() { - // Set defaults - this.alertType = this.alertType || DEFAULT_ALERT_TYPE; } + $onChanges() { + // set defaults + this.alertType = this.alertType || DEFAULT_ALERT_TYPE; + this.alertDismissible = this.alertDismissible || DEFAULT_ALERT_DISMISSIBLE; + + // (re)validate bindings + if (this.alertType && (typeof this.alertType !== 'string' || ['success', 'info', 'warning', 'danger'].includes(this.alertType) === false)) { + this.$log.error('invalid ngbsAlert::alertType:', JSON.stringify(this.alertType), 'expecting "success", "info", "warning", or "danger"'); + } + + if (this.alertDismissible && typeof this.alertDismissible !== 'boolean') { + this.$log.error('invalid ngbsAlert::alertDismissible:', JSON.stringify(this.alertDismissible), 'expecting a boolean'); + } + } } // Define and export component diff --git a/src/library/alert/alert.html b/src/library/alert/alert.html index c348975..9dd7506 100644 --- a/src/library/alert/alert.html +++ b/src/library/alert/alert.html @@ -1,5 +1,5 @@ -