Skip to content

Commit

Permalink
First commit
Browse files Browse the repository at this point in the history
  • Loading branch information
marverix committed Dec 24, 2018
0 parents commit 28b9548
Show file tree
Hide file tree
Showing 20 changed files with 2,566 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
_static/
coverage/
docs/
dist/
38 changes: 38 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
"env": {
"browser": true,
"commonjs": true,
"node": true,
"shared-node-browser": true,
"amd": true,
"mocha": true
},
"extends": "eslint:recommended",
"parserOptions": {
"ecmaVersion": 6,
"sourceType": "module"
},
"globals": {
"Promise": true,
"FileSize": true
},
"rules": {
"indent": [
"error",
2
],
"linebreak-style": [
"error",
"unix"
],
"quotes": [
"error",
"single",
{ "avoidEscape": true }
],
"semi": [
"error",
"always"
]
}
}
10 changes: 10 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# npm
node_modules/
*.tgz

# tests
coverage/

# IDE
.vscode/
.idea/
5 changes: 5 additions & 0 deletions .huskyrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"hooks": {
"pre-commit": "npm run lint"
}
}
35 changes: 35 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Static files for README
_static/

# Documentation
docs/
jsdoc.json

# Tests related
test/
coverage/

# Source files
src/

# Rollup config
rollup.config.js

# Bower config
bower.json

# Lint config
.eslint*

# Husky config
.huskyrc.json

# npm files
*.tgz

# Travis files
.travis*

# IDE files
.vscode/
.idea/
7 changes: 7 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
language: node_js
node_js:
- "8"
install:
- npm install
script:
- npm run lint
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#### 1.0.0 (2018-12-23)

* Initialization of this repository
3 changes: 3 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Contributing

TODO
15 changes: 15 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
ISC License

Copyright (c) 2018, Marek Sierociński

Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.

THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
140 changes: 140 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
# v-Tostini

[![Build Status](https://img.shields.io/travis/com/marverix/v-tostini/master.svg)](https://travis-ci.com/marverix/v-tostini)
[![Language grade: JavaScript](https://img.shields.io/lgtm/grade/javascript/g/marverix/v-tostini.svg)](https://lgtm.com/projects/g/marverix/v-tostini/context:javascript)
[![Current Release](https://img.shields.io/github/release/marverix/v-tostini.svg)](releases)
[![License: MIT](https://img.shields.io/badge/License-ISC-blue.svg)](LICENSE.md)

_v-Tostini_ is really plain toast notifications mechanism for Vue.js 2.x.
There is no CSS included, which means that you need to add your own flavor for it.
Just like with tostini - no one will tell you how it should look like ;)


## Getting Started

### Prerequisites

This package is using [UMD](https://github.com/umdjs/umd/blob/master/templates/returnExportsGlobal.js) pattern.


### Usage

1. Install it (or download):

```sh
npm i v-tostini
```

2. Require in your project:

```js
const vTostini = require('v-tostini');
```

3. Tell Vue to use it:

```js
Vue.use(vTostini);
```

4. Now simply place `tostini-plate` in your HTML:

```html
<tostini-plate />
```

5. Call from any Vue instance:
```js
this.$tostini({
message: 'Delicious!',
type: 'success'
});
```


### Features

#### Use String as an argument

You can also use as argument a string:

```js
this.$tostini('Yupi!');
```

Above will be the same as:

```js
this.$tostini({
message: 'Yupi!'
});
```


#### Notification Duration

By default duration is calculated by the length of given message.
The formula I have created is based on an experiment carried out on colleagues from work. I checked what is the average time that an adult needs to notice and read the technical text that one saw for the first time. Since I have implemented it, complaining that someone did not manage to read the text - ended :)

Of course you can set your own duration:

```js
this.$tostini({
message: 'This message will be visible for 2s.',
duration: 2000
});
```


#### Types

`type` field in toastini config is set as `data-type` in added tostini to tostini-plate. So basicly it's up to you how you will use it.


### Exmaple CSS

So this is CSS that I'm using. As you can see I'm using types:

* default
* success
* error
* warning
* info


```css
.tostini-plate {
position: fixed;
bottom: 0;
left: 0;
width: 100%;
height: auto !important;
}
.tostini-plate .tostini {
padding: 0.75rem;
width: calc(100vw - 3.5rem);
margin: 0.5rem auto;
max-width: 40rem;
color: white;
}
.tostini-plate .tostini[data-type="default"] {
background: rgba(0, 0, 0, 0.5);
}
.tostini-plate .tostini[data-type="success"] {
background: rgba(45, 148, 27, 0.95);
}
.tostini-plate .tostini[data-type="error"] {
background: rgba(148, 27, 27, 0.95);
}
.tostini-plate .tostini[data-type="warning"] {
background: rgba(216, 143, 9, 0.95);
}
.tostini-plate .tostini[data-type="info"] {
background: rgba(0, 147, 204, 0.95);
}
```


## License

This project is licensed under the ISC License - see the [LICENSE](LICENSE) file for details
127 changes: 127 additions & 0 deletions dist/v-tostini.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
/* v-tostini v1.0.0 | (c) Marek Sierociński | https://github.com/marverix/v-tostini/blob/master/LICENSE.md */
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('vue')) :
typeof define === 'function' && define.amd ? define(['vue'], factory) :
(global['v-tostini'] = factory(global.vue));
}(this, (function (Vue) { 'use strict';

Vue = Vue && Vue.hasOwnProperty('default') ? Vue['default'] : Vue;

/**
* Bus
*
* Use it to communicate between some Vue instances/components and Tostini Component
*/
var bus = new Vue();

/**
* Component
*
* Here will appear all delicious tostinis (or something else :) )
*/
const component = {
name: 'tostini-plate',

template: '\
<div class="tostini-plate">\
<div v-for="tostini in tostinis"\
class="tostini"\
:data-type="tostini.type">{{ tostini.message }}</div>\
</div>\
',

data: function() {
return {
tostinis: []
};
},

methods: {
/**
* Add
* @private
*/
_add: function(config) {
this.tostinis.push(config);
this._setTimer(config);
},

/**
* Remove
* @private
*/
_remove: function(id) {
var idx = this.tostinis.findIndex((tostini) => tostini.id === id);
this.tostinis.splice(idx, 1);
},

/**
* Set timer
* @private
*/
_setTimer: function(config) {
var that = this;
setTimeout(function(id) {
that._remove(id);
}, config.duration, config.id);
},

/**
* Bake
*/
bake: function(config) {
var _config = Object.assign({
id: Date.now()
}, config);
this._add(_config);
}
},

mounted: function() {
bus.$on('tostini-bake', this.bake);
}
};

/**
* Bake
*/
function bake(config) {
// Handling config as string
if(typeof config === 'string') {
config = {
message: config
};
}

// Calculate duration
if(config.duration == null) {
config.duration = Math.max(2000, 1000 * config.message.length / 12.84 + 400);
}

// Type
if(config.type == null) {
config.type = 'default';
}

// Emit
bus.$emit('tostini-bake', config);
}

/**
* Plugin
*
* Definition of plugin itself
*/
const plugin = {
install: function(Vue$$1) {
// Define component
Vue$$1.component(component.name, component);

// Extend Vue prototype
Vue$$1.prototype.$tostini = bake;
}
};

return plugin;

})));
Loading

0 comments on commit 28b9548

Please sign in to comment.