import hide from '../_utils/animations/hide';

export default class Alert {
	constructor(element, options) {
		this.element = element;
		this.name = 'alert';

		this._defaults = {
			close: 'close'
		};

		this.options = {
			...options,
			...this._defaults
		};

		this.init();
	}

	init() {
		this.buildCache();
		this.bindEvents();
	}

	buildCache() {
		this.closeSelector = `[data-plugin-${this.name}="${this.options.close}"]`;
		this.$close = this.element.querySelector(this.closeSelector);
	}

	bindEvents() {
		this.$close.addEventListener('click', event => this.onClick.call(this, event));
	}

	onClick(event) {
		event.preventDefault();
		hide(this.element);
	}
}

import hide from '../_utils/animations/hide';

/**
 * Simple alert message with close button
 *
 * @export
 * @class Alert
 */
export default class Alert {

	/**
	 * Creates an instance of Alert.
	 * @param {element} element
	 * @param {object} options
	 * @memberof Alert
	 */
	constructor(element, options) {
		this.element = element;
		this.name = 'alert';

		this._defaults = {
			close: 'close'
		};

		this.options = {
			...options,
			...this._defaults
		};

		this.init();
	}

	init() {
		this.buildCache();
		this.bindEvents();
	}

	buildCache() {
		this.closeSelector = `[data-plugin-${this.name}="${this.options.close}"]`;
		this.$close = this.element.querySelector(this.closeSelector);
	}

	bindEvents() {
		this.$close.addEventListener('click', event => this.onClick.call(this, event));
	}

	/**
	 * Handle click on close button
	 *
	 * @param {event} event
	 * @memberof Alert
	 */
	onClick(event) {
		event.preventDefault();
		hide(this.element);
	}
}

Add alert jsDocs comments