• Stars
    star
    108
  • Rank 320,288 (Top 7 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created about 4 years ago
  • Updated over 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Vue 3.0 Compatible Click Away Directive

Vue Click Away

Demo is available using VitePress and is included in this repository. See Demo Section on how to use and the reason why it's not live yet.

Vue 3.0 Compatible Click Away Directive

npm version GitHub issues NPM GitHub contributors GitHub code size in bytes

Example GIF

Overview

Detect if a click event happened outside of an element. Compatible with Vue 3.x.

Requirements

  • Vue 3.x

Installation

npm i -s vue3-click-away

yarn add vue3-click-away

Usage

By default the module exports a plugin, but you can also use this as a mixin which is documented below or as a directive.

import { createApp } from "vue";
import App from "./App.vue";
import VueClickAway from "vue3-click-away";

const app = createApp(App);

app.use(VueClickAway) // Makes 'v-click-away' directive usable in every component
app.mount('#app')

With Options API

<template>
  <div v-click-away="onClickAway">
    ...
  </div>
</template>

<script>
export default {
  methods: {
    onClickAway(event) {
      console.log(event)
    }
  }
}
</script>

or with Vue Composition API & Typescript

<template>
  <div v-click-away="onClickAway">
    ...
  </div>
</template>

<script>
export default {
  setup() {
    const onClickAway = (event) => {
      console.log(event)
    }

    return { onClickAway }
  } 
}
</script>

Directive

<template>
  <div v-click-away="onClickAway">
    ...
  </div>
</template>

import { directive } from "vue3-click-away";
export default {
  directives: {
    ClickAway: directive
  },
  methods: {
    onClickAway(event) {
      console.log(event);
    }
  }
}

Mixin

<template>
  <div v-click-away="onClickAway">
    ...
  </div>
</template>

import { mixin as VueClickAway } from "vue3-click-away";
export default {
  mixins: [VueClickAway],
  methods: {
    onClickAway(event) {
      console.log(event);
    }
  }
}

Demo

Currently VitePress is having an issue building for production since Directives require SSR implementation and there is no way to override this or skip it (VuePress has ClientOnly component, VitePress doesn't, Yet).

I've opened an issue and pending to see if there is a way to go around it, Click Here to view the issue reported.

For the time being, to test this out clone the repository and run the following inside the /docs folder

npx vitepress

VitePress Documentation

More Repositories

1

Bootstrap-Admin-Theme

A generic admin theme built with Bootstrap free for both personal and commercial use.
CSS
1,639
star
2

twitter-bootstrap-wizard

This twitter bootstrap plugin builds a wizard out of a formatter tabbable structure. It allows to build a wizard functionality using buttons to go through the different wizard steps and using events allows to hook into each step individually.
JavaScript
1,389
star
3

Bootstrap-Admin-Theme-3

A generic admin theme built with Bootstrap 3 free for both personal and commercial use.
CSS
574
star
4

vue-web-cam

Webcam component for VueJs.
Vue
257
star
5

USPS-php-api

USPS PHP based API address verify, city lookup, service delivery calculator, track confirm, zip code lookup
PHP
186
star
6

Auto-Cars-Makes-And-Models

JSON string, DB Dump, PHP Array of all cars makes and models
PHP
124
star
7

Bootstrap-ecommerce-theme

Bootstrap 2.x Theme for an e-Commerce Website
HTML
43
star
8

php-first-data-api

PHP First Data Service API
PHP
36
star
9

yii-ecommerce

eCommerce platform built using Yii Framework. WIP.
PHP
31
star
10

world-geo-data

GEO data including Country information, Postal Codes, City Names and information, TimeZones. MySQL tables and MongoDB Collections
27
star
11

xenforo-sdk

XenForo Software Development Kit
PHP
22
star
12

PHP-DB-Migration-Class

PHP DB Migration Class to create and update db using migrations across environments
PHP
16
star
13

Yii-RedactorJS-Widget

Yii Widget for the WYSIWYG RedactorJS editor
JavaScript
14
star
14

US-Zip-Codes

Updated list of US Zip Codes, State, City & County
11
star
15

zillow

This is a simple PHP Wrapper for the Zillow API services.
PHP
10
star
16

laravel-angular

Laravel + Angular application starter
PHP
10
star
17

Yii-Rain-TPL-View-Renderer

Rain TPL Yii View Renderer
PHP
9
star
18

Yii-Aloha-Editor-Widget

Yii Widget for the Aloha Editor
JavaScript
7
star
19

PHP-Console-Progress-Bar

This class creates and maintains progress bars to be printed to the console.
PHP
5
star
20

realtor.com

Search, List and pull property information
PHP
4
star
21

New-Facebook-Graph-API

PHP
3
star
22

html-to-image

This will convert an HTML page to any image format using PhantomJS
HTML
2
star
23

code-challenge

PHP
2
star
24

US-Adjacent-States

PHP
2
star
25

php-database-wrapper

PHP Class to manipulate MySQL databases.
PHP
2
star
26

Israel-Cities-and-Streets

Two database tables with a list of 1,270 cities and over 41,650 street names with relations between the two tables
2
star
27

Yii-Widget-Raptor-Editor

Yii Widget for the Raptor Editor
1
star
28

consumertrackexercise

Exercise written for consumer track
PHP
1
star
29

vincent-blog

Blog created using Hexo
PHP
1
star
30

php-cups-print

PHP Wrapper around Mac CUPS printing system
PHP
1
star