1 | # V-Offline ⚡️
|
2 |
|
3 | [![GitHub Workflow Status](https://img.shields.io/github/workflow/status/vinayakkulkarni/v-offline/ci?logo=github-actions)](https://github.com/vinayakkulkarni/v-offline/actions/workflows/ci.yml)
|
4 | [![GitHub Workflow Status](https://img.shields.io/github/workflow/status/vinayakkulkarni/v-offline/Ship%20js%20trigger?label=⛴%20Ship.js%20trigger)](https://github.com/vinayakkulkarni/v-offline/actions/workflows/shipjs-trigger.yml)
|
5 | [![GitHub release (latest SemVer)](https://img.shields.io/github/v/release/vinayakkulkarni/v-offline?sort=semver&logo=github)](https://github.com/vinayakkulkarni/v-offline/releases)
|
6 | [![npm](https://img.shields.io/npm/v/v-offline?logo=npm)](https://www.npmjs.com/package/v-offline)
|
7 | [![npm](https://img.shields.io/npm/dm/v-offline?logo=npm)](http://npm-stat.com/charts.html?package=v-offline)
|
8 | [![npm bundle size (version)](https://img.shields.io/bundlephobia/min/v-offline/latest)](https://bundlephobia.com/package/v-offline@latest)
|
9 | [![npm type definitions](https://img.shields.io/npm/types/v-offline)](https://github.com/vinayakkulkarni/v-offline/blob/master/package.json)
|
10 | [![DeepScan grade](https://deepscan.io/api/teams/9055/projects/16121/branches/339368/badge/grade.svg)](https://deepscan.io/dashboard#view=project&tid=9055&pid=16121&bid=339368)
|
11 | [![Snyk Vulnerabilities for GitHub Repo](https://img.shields.io/snyk/vulnerabilities/github/vinayakkulkarni/v-offline)](https://snyk.io/test/github/vinayakkulkarni/v-offline)
|
12 | [![LGTM Alerts](https://img.shields.io/lgtm/alerts/github/vinayakkulkarni/v-offline?logo=lgtm)](https://lgtm.com/projects/g/vinayakkulkarni/v-offline/alerts/)
|
13 | [![LGTM Grade](https://img.shields.io/lgtm/grade/javascript/github/vinayakkulkarni/v-offline?logo=lgtm)](https://lgtm.com/projects/g/vinayakkulkarni/v-offline/context:javascript)
|
14 | [![GitHub contributors](https://img.shields.io/github/contributors/vinayakkulkarni/v-offline)](https://github.com/vinayakkulkarni/v-offline/graphs/contributors)
|
15 | [![FOSSA](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fvinayakkulkarni%2Fv-offline.svg?type=shield)](https://app.fossa.io/projects/git%2Bgithub.com%2Fvinayakkulkarni%2Fv-offline?ref=badge_shield)
|
16 |
|
17 | [![eslint](https://img.shields.io/npm/dependency-version/v-offline/dev/eslint?logo=eslint)](https://eslint.org/)
|
18 | [![prettier](https://img.shields.io/npm/dependency-version/v-offline/dev/prettier?logo=prettier)](https://prettier.io/)
|
19 | [![rollup](https://img.shields.io/npm/dependency-version/v-offline/dev/rollup?logo=rollup.js)](https://rollupjs.org/guide/en/)
|
20 | [![vue](https://img.shields.io/npm/dependency-version/v-offline/dev/vue?logo=vue.js)](https://vuejs.org/)
|
21 | [![typescript](https://img.shields.io/npm/dependency-version/v-offline/dev/typescript?logo=TypeScript)](https://www.typescriptlang.org/)
|
22 |
|
23 | ## Features
|
24 |
|
25 | * Detect offline & online events for your vue app.
|
26 | * Built from scratch usign Vue 2 & Composition API with TypeScript
|
27 | * For Vue 2.x version – `npm i v-offline@2`
|
28 | * For Vue 3.x version – `npm i v-offline@3`
|
29 |
|
30 |
|
31 | ## Table of Contents
|
32 |
|
33 | - [V-Offline ⚡️](#v-offline-️)
|
34 | - [Features](#features)
|
35 | - [Table of Contents](#table-of-contents)
|
36 | - [Demo](#demo)
|
37 | - [Requirements](#requirements)
|
38 | - [Installation](#installation)
|
39 | - [Build Setup](#build-setup)
|
40 | - [Usage](#usage)
|
41 | - [Globally](#globally)
|
42 | - [As a component](#as-a-component)
|
43 | - [As a plugin](#as-a-plugin)
|
44 | - [Locally](#locally)
|
45 | - [Example](#example)
|
46 | - [API](#api)
|
47 | - [Props](#props)
|
48 | - [Events](#events)
|
49 | - [Built with](#built-with)
|
50 | - [Contributing](#contributing)
|
51 | - [Author](#author)
|
52 | - [License](#license)
|
53 |
|
54 | ## Demo
|
55 |
|
56 | [![Edit v-offline demo](https://codesandbox.io/static/img/play-codesandbox.svg)](https://codesandbox.io/s/v-offline-demo-8itb1?fontsize=14&hidenavigation=1&theme=dark)
|
57 |
|
58 | ## Requirements
|
59 |
|
60 | * [vue](https://vuejs.org/) `^2.x`
|
61 | * [@vue/composition-api](https://v3.vuejs.org/guide/composition-api-introduction.html) `^1.x`
|
62 |
|
63 | ### Installation
|
64 |
|
65 | ```sh
|
66 | npm install --save v-offline
|
67 | npm install --save-dev @vue/composition-api
|
68 | ```
|
69 |
|
70 | CDN: [UNPKG](https://unpkg.com/v-offline/dist/) | [jsDelivr](https://cdn.jsdelivr.net/npm/v-offline/dist/) (available as `window.VOffline`)
|
71 |
|
72 | ### Build Setup
|
73 |
|
74 | ``` bash
|
75 | # install dependencies
|
76 | $ npm ci
|
77 |
|
78 | # package the library
|
79 | $ npm run build
|
80 | ```
|
81 |
|
82 |
|
83 | ## Usage
|
84 |
|
85 | ### Globally
|
86 |
|
87 | #### As a component
|
88 | ```javascript
|
89 | Vue.component('VOffline', require('v-offline'));
|
90 | ```
|
91 |
|
92 | #### As a plugin
|
93 |
|
94 | ```javascript
|
95 | import Vue from 'vue';
|
96 | import VOffline from 'v-offline';
|
97 |
|
98 | Vue.use(VOffline);
|
99 | ```
|
100 |
|
101 | ### Locally
|
102 |
|
103 | ```javascript
|
104 | import { VOffline } from 'v-offline';
|
105 | ```
|
106 |
|
107 | #### Example
|
108 | <details>
|
109 | <summary>Locally imported as a component</summary>
|
110 | <br />
|
111 |
|
112 | ```html
|
113 | <v-offline @detected-condition="amIOnline">
|
114 | <template v-if="online"> ( Online: {{ onLine }} ) </template>
|
115 | <template v-if="offline"> ( Online: {{ onLine }} ) </template>
|
116 | </v-offline>
|
117 | ```
|
118 |
|
119 | ```javascript
|
120 | import { VOffline } from 'v-offline';
|
121 |
|
122 | Vue.component('example-component', {
|
123 | components: {
|
124 | VOffline
|
125 | },
|
126 | data() {
|
127 | return {
|
128 | onLine: true,
|
129 | };
|
130 | },
|
131 | methods: {
|
132 | amIOnline(e) {
|
133 | this.onLine = e;
|
134 | },
|
135 | },
|
136 | });
|
137 | ```
|
138 |
|
139 | ```css
|
140 | .offline {
|
141 | background-color: #fc9842;
|
142 | background-image: linear-gradient(315deg, #fc9842 0%, #fe5f75 74%);
|
143 | }
|
144 | .online {
|
145 | background-color: #00b712;
|
146 | background-image: linear-gradient(315deg, #00b712 0%, #5aff15 74%);
|
147 | }
|
148 | ```
|
149 | </details>
|
150 |
|
151 |
|
152 | ## API
|
153 | ### Props
|
154 |
|
155 | | Name | Type | Required? | Default | Description |
|
156 | | -------------- | ------ | --------- | --------- | ----------------------------------------------------------- |
|
157 | | `online-class` | String | No | '' | Styling the `div` which you want to give if you're online. |
|
158 | | `offline-class` | String | No | '' | Styling the `div` which you want to give if you're offline. |
|
159 | | `ping-url` | String | No | https://google.com | Pinging any url to double check if you're online or not. |
|
160 |
|
161 | ### Events
|
162 |
|
163 | | Name | Returns | Description |
|
164 | | --- | --- | --- |
|
165 | | `@detected-condition` | String | Emits a boolean value |
|
166 |
|
167 | ## Built with
|
168 |
|
169 | - [TypeScript](https://www.typescriptlang.org/).
|
170 | - [Vue 2](https://v3.vuejs.org)
|
171 |
|
172 | ## Contributing
|
173 |
|
174 | 1. Fork it ( [https://github.com/vinayakkulkarni/v-offline/fork](https://github.com/vinayakkulkarni/v-offline/fork) )
|
175 | 2. Create your feature branch (`git checkout -b feat/new-feature`)
|
176 | 3. Commit your changes (`git commit -Sam 'feat: add feature'`)
|
177 | 4. Push to the branch (`git push origin feat/new-feature`)
|
178 | 5. Create a new [Pull Request](https://github.com/vinayakkulkarni/v-offline/compare)
|
179 |
|
180 | _Note_:
|
181 | 1. Please contribute using [Github Flow](https://guides.github.com/introduction/flow/)
|
182 | 2. Commits & PRs will be allowed only if the commit messages & PR titles follow the [conventional commit standard](https://www.conventionalcommits.org/), _read more about it [here](https://github.com/conventional-changelog/commitlint/tree/master/%40commitlint/config-conventional#type-enum)_
|
183 | 3. PS. Ensure your commits are signed. _[Read why](https://withblue.ink/2020/05/17/how-and-why-to-sign-git-commits.html)_
|
184 |
|
185 |
|
186 | ## Author
|
187 |
|
188 | **v-offline** © [Vinayak](https://vinayakkulkarni.dev), Released under the [MIT](./LICENSE) License.<br>
|
189 | Authored and maintained by Vinayak Kulkarni with help from contributors ([list](https://github.com/vinayakkulkarni/v-offline/contributors)).
|
190 |
|
191 | > [vinayakkulkarni.dev](https://vinayakkulkarni.dev) · GitHub [@vinayakkulkarni](https://github.com/vinayakkulkarni) · Twitter [@\_vinayak_k](https://twitter.com/_vinayak_k)
|
192 |
|
193 |
|
194 | ## License
|
195 | [![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fvinayakkulkarni%2Fv-offline.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Fvinayakkulkarni%2Fv-offline?ref=badge_large) |
\ | No newline at end of file |