Skip to content

Commit

Permalink
Add options.
Browse files Browse the repository at this point in the history
  • Loading branch information
constkhi committed Nov 4, 2019
1 parent 859a175 commit 819f835
Show file tree
Hide file tree
Showing 25 changed files with 1,498 additions and 202 deletions.
13 changes: 10 additions & 3 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,18 @@ root = true

# All files
[*]
charset = utf-8
# Widely Supported by Editors
indent_style = space
indent_size = 2
tab_width = 2
end_of_line = lf
quote_type = double
insert_final_newline = true
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

# Supported By A Limited Number of Editors
max_line_length = 80

# Domain-Specific Properties
quote_type = double
spaces_around_operators = true
18 changes: 18 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
module.exports = {
root: true,
env: {
node: true
},
extends: [
"plugin:@typescript-eslint/recommended",
"prettier/@typescript-eslint",
"plugin:prettier/recommended"
],
rules: {
"no-console": "error",
"no-debugger": process.env.NODE_ENV === "production" ? "error" : "off"
},
parserOptions: {
parser: "@typescript-eslint/parser"
}
};
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"typescript.tsdk": "node_modules/typescript/lib"
}
55 changes: 39 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
# Vue Simple Alert

![downloads](https://img.shields.io/npm/dw/vue-simple-alert)
![version](https://img.shields.io/npm/v/vue-simple-alert)
![license](https://img.shields.io/npm/l/vue-simple-alert)
![screenshot](./example/src/assets/screenshot.gif)

Simple but cool _**alert()**_, _**confirm()**_, _**prompt()**_ for Vue.js.
[![version](https://img.shields.io/npm/v/vue-simple-alert)](https://www.npmjs.com/package/vue-simple-alert)
[![Vue.js version](https://badgen.net/badge/vue.js/2.x/4fc08d)](https://vuejs.org)
[![total downloads](https://img.shields.io/npm/dt/vue-simple-alert)](https://www.npmjs.com/package/vue-simple-alert)
[![downloads](https://img.shields.io/npm/dw/vue-simple-alert)](https://www.npmjs.com/package/vue-simple-alert)
[![Codacy Badge](https://api.codacy.com/project/badge/Grade/97f03b2ea96049fbaff5591a94a7d0aa)](https://www.codacy.com/manual/constkhi/vue-simple-alert?utm_source=github.com&utm_medium=referral&utm_content=constkhi/vue-simple-alert&utm_campaign=Badge_Grade)
[![license](https://img.shields.io/npm/l/vue-simple-alert)](LICENSE)

Simple _**alert()**_, _**confirm()**_, _**prompt()**_ for Vue.js, using sweetalert2.

## Demo

Expand Down Expand Up @@ -33,7 +38,7 @@ npm i vue-simple-alert

```javascript
// main.js
import Vue from "vue"
import Vue from "vue";
import VueSimpleAlert from "vue-simple-alert";

Vue.use(VueSimpleAlert);
Expand Down Expand Up @@ -62,14 +67,28 @@ this.$confirm("Are you sure?").then(() => {
```javascript
// in any component

this.$prompt("Input your name").then((text) => {
this.$prompt("Input your name").then(text => {
// do somthing with text
});
```

## Advanced Usage

You can use sweetalert2's _**fire()**_ method through _**$fire()**_.
### Global options

Global options can be set when initialize plugin. Refer to [sweetalert2 documentation](https://sweetalert2.github.io/#configuration)

```javascript
// main.js
import Vue from "vue";
import VueSimpleAlert from "vue-simple-alert";

Vue.use(VueSimpleAlert, { reverseButtons: true });
```

### More advanced usage

You can use sweetalert2's _**fire()**_ method through _**\$fire()**_.
For detailed usage, refer to [sweetalert2](https://sweetalert2.github.io) documentation.

```javascript
Expand All @@ -81,13 +100,13 @@ this.$fire({
type: "success",
timer: 3000
}).then(r => {
console.log(r.value);
console.log(r.value);
});
```

## API

### alert(message?, title?, type?)
### alert(message?, title?, type?, options?)

The _alert()_ method displays an alert box with a specified message and an OK button.

Expand All @@ -103,11 +122,15 @@ The _alert()_ method displays an alert box with a specified message and an OK bu

> Optional. Specifies icon type.
- options: SweetAlertOptions

> Optional. Advanced options. Refer to [sweetalert2 documentation](https://sweetalert2.github.io/#configuration).
- returns: Promise\<boolean\>

> Will be resolved when OK button clicked. If alert box closed by any other reason, this promise will be rejected.
> Will be resolved with true when alert box closed.
### confirm(message?, title?, type?, reverseButton?)
### confirm(message?, title?, type?, options?)

The confirm() method displays a dialog box with a specified message, along with an OK and a Cancel button.

Expand All @@ -123,15 +146,15 @@ The confirm() method displays a dialog box with a specified message, along with

> Optional. Specifies icon type.
- reverseButton: boolean
- options: SweetAlertOptions

> Optional. Set to true if you want to invert default buttons positions.
> Optional. Advanced options. Refer to [sweetalert2 documentation](https://sweetalert2.github.io/#configuration).
- returns: Promise\<boolean\>

> Will be resolved when OK button clicked. If confirm box closed by any other reason, this promise will be rejected.
### prompt(message, defaultText?, title?, type?, reverseButton?)
### prompt(message, defaultText?, title?, type?, options?)

The prompt() method displays a dialog box that prompts the user for input.

Expand All @@ -151,9 +174,9 @@ The prompt() method displays a dialog box that prompts the user for input.

> Optional. Specifies icon type.
- reverseButton: boolean
- options: SweetAlertOptions

> Optional. Set to true if you want to invert default buttons positions.
> Optional. Advanced options. Refer to [sweetalert2 documentation](https://sweetalert2.github.io/#configuration).
- returns: Promise\<string\>

Expand Down
2 changes: 1 addition & 1 deletion docs/css/app.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion docs/index.html
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<!DOCTYPE html><html lang=en><head><meta charset=utf-8><meta http-equiv=X-UA-Compatible content="IE=edge"><meta name=viewport content="width=device-width,initial-scale=1"><link rel=icon href=/vue-simple-alert/favicon.ico><link rel=stylesheet href=https://cdnjs.cloudflare.com/ajax/libs/animate.css/3.7.2/animate.min.css><title>vue-simple-alert example</title><link href=/vue-simple-alert/css/app.css rel=preload as=style><link href=/vue-simple-alert/js/app.js rel=preload as=script><link href=/vue-simple-alert/js/chunk-vendors.js rel=preload as=script><link href=/vue-simple-alert/css/app.css rel=stylesheet></head><body><noscript><strong>We're sorry but example doesn't work properly without JavaScript enabled. Please enable it to continue.</strong></noscript><div id=app></div><script defer src=https://use.fontawesome.com/releases/v5.8.1/js/all.js integrity=sha384-g5uSoOSBd7KkhAMlnQILrecXvzst9TdC09/VM+pjDTCM+1il8RHz5fKANTFFb+gQ crossorigin=anonymous></script><script src=/vue-simple-alert/js/chunk-vendors.js></script><script src=/vue-simple-alert/js/app.js></script></body></html>
<!DOCTYPE html><html lang=en><head><meta charset=utf-8><meta http-equiv=X-UA-Compatible content="IE=edge"><meta name=viewport content="width=device-width,initial-scale=1"><link rel=icon href=/vue-simple-alert/favicon.ico><link rel=stylesheet href=https://cdnjs.cloudflare.com/ajax/libs/animate.css/3.7.2/animate.min.css><link href="https://fonts.googleapis.com/css?family=Dosis&display=swap" rel=stylesheet><title>vue-simple-alert example</title><link href=/vue-simple-alert/css/app.css rel=preload as=style><link href=/vue-simple-alert/js/app.js rel=preload as=script><link href=/vue-simple-alert/js/chunk-vendors.js rel=preload as=script><link href=/vue-simple-alert/css/app.css rel=stylesheet></head><body><noscript><strong>We're sorry but example doesn't work properly without JavaScript enabled. Please enable it to continue.</strong></noscript><div id=app></div><script defer src=https://use.fontawesome.com/releases/v5.8.1/js/all.js integrity=sha384-g5uSoOSBd7KkhAMlnQILrecXvzst9TdC09/VM+pjDTCM+1il8RHz5fKANTFFb+gQ crossorigin=anonymous></script><script src=/vue-simple-alert/js/chunk-vendors.js></script><script src=/vue-simple-alert/js/app.js></script></body></html>
Loading

0 comments on commit 819f835

Please sign in to comment.