import { Controller } from '@hotwired/stimulus' export default class extends Controller { connect() { this.scrollHandler = this.onScroll.bind(this) window.addEventListener('scroll', this.scrollHandler, { passive: true }) this.onScroll() } disconnect() { window.removeEventListener('scroll', this.scrollHandler) } onScroll() { this.element.classList.toggle('is-visible', window.scrollY > 300) } scrollToTop(e) { e.preventDefault() window.scrollTo({ top: 0, behavior: 'smooth' }) } }