• Stars
    star
    356
  • Rank 119,446 (Top 3 %)
  • Language Vue
  • License
    MIT License
  • Created about 7 years ago
  • Updated over 1 year ago

Reviews

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

Repository Details

๐Ÿ”Œ Simple VueJS component to detect offline & online changes.

V-Offline โšก๏ธ

CI CodeQL Ship.js Trigger npm npm npm bundle size (version) npm npm bundle size (version) npm type definitions DeepScan grade Snyk Vulnerabilities for GitHub Repo GitHub contributors FOSSA

eslint prettier vite vue typescript

โš ๏ธ Docs are for Vue 3, for Vue 2 docs, click here

Features

  • Detect offline & online events for your vue app.
  • Built from scratch usign Vue 2 & Composition API with TypeScript
  • For Vue >3.x version โ€“ npm i v-offline@latest
  • For Vue >=2.7 version โ€“ npm i v-offline@legacy
  • For Vue <2.7 version โ€“ npm i [email protected]

Table of Contents

Demo

Edit v-offline demo

Requirements

Installation

npm install --save v-offline ping.js

CDN: UNPKG | jsDelivr (available as window.VOffline)

Build Setup

# install dependencies
$ npm install

# package the library
$ npm run build

Usage

Global component:

// main.ts
import { VOffline } from 'v-offline';
import { createApp } from 'vue';

const app = createApp({});
app.component('VOffline', VOffline);

Or use locally

// component.vue
<script lang="ts">
import { defineComponent } from 'vue';
import { VOffline } from 'v-offline';

export default defineComponent({
  components: {
    VOffline,
  },
});
</script>

For Nuxt 3, create a file in plugins/v-offline.ts

import { VOffline } from 'v-offline';

export default defineNuxtPlugin((nuxtApp) => {
  nuxtApp.vueApp.component('VOffline', VOffline);
});

then import the file in nuxt.config.{j|t}s:

export default {
  // ...
  plugins: [
    // ...
    { src: '~/plugins/v-offline', mode: 'client' },
    // ...
  ],
  // ...
};

Example

<template>
  <v-offline
    online-class="online"
    offline-class="offline"
    @detected-condition="onNetworkChange"
  >
    <template v-if="online">
      <div class="flex w-full h-full justify-center items-center text-6xl">
        โšก๏ธ
      </div>
    </template>
    <template v-if="!online">
      <div class="flex w-full h-full justify-center items-center text-6xl">
        ๐Ÿ’ฉ
      </div>
    </template>
  </v-offline>
  <!-- Netlify Badge -->
  <div class="absolute bottom-4 right-4">
    <a
      href="https://app.netlify.com/sites/v-offline/deploys"
      aria-label="View deploys on Netlify"
      target="_blank"
      rel="noopener noreferrer"
      class="gray-400"
    >
      <img
        src="https://www.netlify.com/img/global/badges/netlify-color-accent.svg"
        alt="Deploys by Netlify"
      />
    </a>
  </div>
</template>

<script lang="ts">
  import { defineComponent, ref } from 'vue';
  import type { Ref } from 'vue';
  import { VOffline } from 'v-offline';

  export default defineComponent({
    components: {
      VOffline,
    },
    setup() {
      const online: Ref<boolean> = ref(false);
      const onNetworkChange = (status: boolean) => {
        online.value = status;
      };
      return { online, onNetworkChange };
    },
  });
</script>
<style>
  @import 'v-github-icon/dist/v-github-icon.css';
</style>

API

Props

Name Type Required? Default Description
online-class String No '' Styling the div which you want to give if you're online.
offline-class String No '' Styling the div which you want to give if you're offline.
ping-url String No https://google.com Pinging any url to double check if you're online or not.

Events

Name Returns Description
@detected-condition String Emits a boolean value

Contributing

  1. Fork it ( https://github.com/vinayakkulkarni/v-offline/fork )
  2. Create your feature branch (git checkout -b feat/new-feature)
  3. Commit your changes (git commit -Sam 'feat: add feature')
  4. Push to the branch (git push origin feat/new-feature)
  5. Create a new Pull Request

Note:

  1. Please contribute using GitHub Flow
  2. Commits & PRs will be allowed only if the commit messages & PR titles follow the conventional commit standard, read more about it here
  3. PS. Ensure your commits are signed. Read why

Author

v-offline ยฉ Vinayak, Released under the MIT License.
Authored and maintained by Vinayak Kulkarni with help from contributors (list).

vinayakkulkarni.dev ยท GitHub @vinayakkulkarni ยท Twitter @_vinayak_k

License

FOSSA Status

More Repositories

1

v-mapbox

A cloned & maintained version of vue-mapbox
Vue
152
star
2

vue-identify-network

โšก Identify what kinda internet your users are using!
Vue
64
star
3

s-offline

๐Ÿ”Œ Simple Svelte component to detect offline & online changes.
JavaScript
56
star
4

v-rating

โญ Rating component in Semantic-UI made with VueJS (< 1kB, blazing fast)
JavaScript
49
star
5

nuxt-ava-e2e-unit-testing

๐Ÿงช Nuxt + Ava for E2E & Unit Testing
JavaScript
47
star
6

v-image

๐Ÿ“ท Tiny little component for input type=file (css free! style it as you want!)
Vue
38
star
7

v-pip

๐Ÿ–ผ Tiny vue wrapper for supporting native picture-in-picture mode.
Vue
32
star
8

janak

Your next vue.js package!
JavaScript
28
star
9

v-clappr

๐Ÿ‘๐ŸปVue.js wrapper for Clappr media player
Vue
22
star
10

v-tweakpane

Tweakpane ๐Ÿค Vue ๐Ÿ’š
Vue
14
star
11

v-intl

Add i18n to your awesome Vue 3 app ๐Ÿ”‰
Vue
14
star
12

mapbox-gl-interpolate-heatmap

(IDW) Interpolated Heatmap Layer for mapbox-gl
TypeScript
13
star
13

jobify

๐Ÿ“ƒ Job Board Playground with Laravel / VueJS 2.x โšก
PHP
11
star
14

v-spotlight

๐Ÿ”ฆ Tiny reusable spotlight component for your Vue App
JavaScript
9
star
15

laravel-vue-semantic-ui-pagination

A VueJS 2.x pagination used with Laravel & Semantic-UI โ˜€๏ธ
JavaScript
8
star
16

v-tree

[WIP] Bare clone of `vue-treeview` with support for tailwind css
Vue
7
star
17

meme-reviews

๐Ÿ‘[Meme] ReViEwS ๐Ÿ‘
JavaScript
6
star
18

v-kong-dashboard

Kong Dashboard built from scratch with Nuxt 3 ๐ŸŽ‰
Vue
6
star
19

dashboard

๐Ÿ–– Dashboard for GeoSpoc using Leaflet.js, Chart.js & Vue.js
JavaScript
6
star
20

v-github-icon

GitHub corner Icons built using Vue 3 (Vue 2 + Composition API) ๐Ÿฅณ
Vue
5
star
21

vue-intl-numberformat

Tiny reusable Vue wrapper for Intl.Numberformat
JavaScript
5
star
22

v-bpm-calc

๐Ÿค™ Metronome Meter made with VueJS
JavaScript
4
star
23

vuejs-sort

๐Ÿ’ฏ A Simple VueJS sort using vue-router โšก
JavaScript
4
star
24

angular-bootstrap4

AngularJS Examples with Bootstrap 4 alpha2 elements
HTML
4
star
25

vuejs-image

๐ŸŽ‰ Vue Image Component replacing native <input type="file" />
Vue
4
star
26

v-intl-listformat

Tiny vue component for Intl.ListFormat
JavaScript
4
star
27

prettier-config-vue

My Prettier Config for Vue / Nuxt apps
3
star
28

map-my-google-photos

Nuxt app using Firebase + Google Photos APIs rendering the photos on a Mapbox based map interface
Vue
3
star
29

companies

๐Ÿ” Search For Companies based out of ๐Ÿ‡ฎ๐Ÿ‡ณ
JavaScript
3
star
30

vuejs-colorpicker

๐Ÿ”ด Simple VueJS colorpicker using Semantic-UI โšก
JavaScript
2
star
31

offline

โšซ Being Offline โšก
JavaScript
2
star
32

colorelephant

๐Ÿ“ธ ColorElephant Website Playground
JavaScript
2
star
33

colorpay

โšก Laravel 5.x & Vue 2.x with Stripe / PayPal API's playground :)
PHP
2
star
34

newsify

๐Ÿ—ž๏ธ NYTimes Articles playground with Laravel 5.x / Vue 2.x. โšก
PHP
2
star
35

KATA-TDD

Test Driven Development with phpSpec
PHP
2
star
36

v-vectors

Dynamic Component to render SVGs
TypeScript
2
star
37

cluster

V-Mapbox Demo :: Clusters
Vue
2
star
38

worker-module

๐Ÿค– Integrate Web Worker in your Nuxt apps
JavaScript
2
star
39

vinayakkulkarni.dev

My Portfolio Website
Vue
2
star
40

vuejs-datatables-sui

(WIP) Vue.js 2 data tables using Semantic-UI styling instead of Bootstrap themed styling (https://github.com/matfish2/vue-tables-2)
JavaScript
2
star
41

nuxt-mocha-composition-api-unit-tests

Repro repo for Nuxt + Mocha + TypeScript + nuxt/composition-api
TypeScript
1
star
42

vinayakkulkarni.github.io

My Portfolio Website
HTML
1
star
43

v-range-slider

Bare clone of @bumbeishvili's `data-driven-range-slider` with the power of Vue
JavaScript
1
star
44

poll

โšก Gutenberg Poll
JavaScript
1
star
45

vinayakkulkarni

1
star
46

github-gitlab-sync

When code pushed on GitHub, push it to Gitlab repo
1
star