import { Directive , HostListener , Inject } from '@angular/core' ; import { ObOffCanvasService } from './off-canvas.service' ; import { WINDOW , isNotKeyboardEventOnButton } from '../utilities' ; @ Directive ( { selector : '[obOffCanvasToggle]' , exportAs : 'obOffCanvasToggle' , host : { class : 'ob-off-canvas-toggle' } } ) export class ObOffCanvasToggleDirective { constructor ( private readonly offCanvas , @ Inject ( WINDOW ) private readonly window ) { } @ HostListener ( 'click' , [ '$event' ] ) @ HostListener ( 'keyup.enter' , [ '$event' ] ) toggle ( event ? ) { if ( isNotKeyboardEventOnButton ( event ) ) { this . window . setTimeout ( ( ) => ( this . offCanvas . open = ! this . offCanvas . open ) ) ; } } }