0.0.1 • Published 4 years ago

agr-click-outside v0.0.1

Weekly downloads
4
License
-
Repository
-
Last release
4 years ago

AgrClickOutside

Directive to indicate if you click outside of element.

Installation

Using npm:

npm install agr-click-outside

Usage

In app.module:

// Angular
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';

// Modulos
import { AppRoutingModule } from './app-routing.module';
import { AgrClickOutsideModule } from 'agr-click-outside';

// Componentes
import { AppComponent } from './app.component';
import { ExampleAgrClickOutsideComponent } from './examples/example-agr-click-outside/example-agr-click-outside.component';

@NgModule({
  declarations: [
    AppComponent,
    ShowcaseAgrClickOutsideComponent
  ],
  imports: [
    BrowserModule,
    AppRoutingModule,
    AgrClickOutsideModule
  ],
  bootstrap: [AppComponent]
})
export class AppModule { }

In your ts:

import { Component, OnInit } from '@angular/core';

@Component({
  selector: 'app-example-agr-click-outside',
  templateUrl: './example-agr-click-outside.component.html',
  styleUrls: ['./example-agr-click-outside.component.css']
})
export class ExampleAgrClickOutsideComponent implements OnInit {

  showEstandar: boolean;
  showDelay: boolean;
  showDesactivated: boolean;
  actualMode: string;


  constructor() { 
    this.showEstandar = true;
    this.actualMode = 'estandar';
  }

  ngOnInit() {
  }

  clickOutside($event) {
    console.log($event);

  }

  openEstandar() {
    this.showEstandar = true;
    this.showDelay = false;
    this.showDesactivated = false;
    this.actualMode = 'estandar';
  }

  openDelay() {
    this.showEstandar = false;
    this.showDelay = true;
    this.showDesactivated = false;
    this.actualMode = 'delay';
  }

  openDesactivated() {
    this.showEstandar = false;
    this.showDelay = false;
    this.showDesactivated = true;
    this.actualMode = 'desactivated';
  }

}

In your html:

<p>{{'Modo actual: ' +actualMode}}</p>

<button (click)="openEstandar()">Estandar</button>
<button (click)="openDelay()">Delay</button>
<button (click)="openDesactivated()">Desactivated</button>

<div *ngIf="showEstandar" agrClickOutside (clickOutside)="clickOutside($event)" class="block">
  <p>Click outside this div</p>
</div>

<div *ngIf="showDelay" agrClickOutside [clickOutsideDelay]="5000" (clickOutside)="clickOutside($event)" class="block">
  <p>Click outside this div</p>
</div>

<div *ngIf="showDesactivated" agrClickOutside [clickOutsideEnabled]="false" (clickOutside)="clickOutside($event)" class="block">
  <p>Click outside this div</p>
</div>

Inputs

InputDescription
clickOutsideEnabledActive or desativate event
clickOutsideDelayIn x miliseconds, send event.

Outputs

OutputDescription
clickOutsideEvent when click outside, you receive a mouse event