import { Controller } from '@hotwired/stimulus'; export default class extends Controller { static targets = ['container', 'modal']; static classes = ['background']; connect() { this.open(); } open() { this.containerTarget.classList.add(this.hasBackgroundClass ? this.backgroundClass : 'mix-modal-bg'); document.body.classList.add('overflow-hidden'); this.modalTarget.classList.remove('hidden'); } close() { this.containerTarget.classList.remove(this.hasBackgroundClass ? this.backgroundClass : 'mix-modal-bg'); document.body.classList.remove('overflow-hidden'); this.modalTarget.classList.add('hidden'); } disconnect() { this.close(); this._clear_cache_for_history_back(); } _clear_cache_for_history_back() { if (this.element) { this.element.remove(); } } }