Grupo-AFAL/frontend-helpers

View on GitHub
javascript/src/controllers/side-menu-controller.js

Summary

Maintainability
A
3 hrs
Test Coverage
import { Controller } from '@hotwired/stimulus'
 
export class SideMenuController extends Controller {
static targets = ['container', 'overlay']
 
Similar blocks of code found in 2 locations. Consider refactoring.
connect () {
if (this.hasOverlayTarget && this.hasContainerTarget) {
this.overlayTarget.addEventListener('click', this.closeMenu)
this.containerTarget.addEventListener('click', this.closeMenu)
}
}
 
Similar blocks of code found in 2 locations. Consider refactoring.
disconnect () {
if (this.hasOverlayTarget && this.hasContainerTarget) {
this.overlayTarget.removeEventListener('click', this.closeMenu)
this.containerTarget.removeEventListener('click', this.closeMenu)
}
}
 
toggleMenu (e) {
e.stopPropagation()
this.containerTarget.classList.toggle('is-active')
}
 
closeMenu = e => {
this.containerTarget.classList.remove('is-active')
}
}