forked from STUkh/vue-promise-btn
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
190 lines (180 loc) · 8.4 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Vue Promise Btn</title>
<script src="https://cdn.jsdelivr.net/npm/vue@latest/dist/vue.js"></script>
<script src="./dist/vue-promise-btn.umd.js"></script>
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Open+Sans:400,700">
<link rel="stylesheet" href="./example/cayman-theme.min.css?v=61aea895ce389a448a1ddb8f5be47f68a02053c5">
<link rel="stylesheet" href="./dist/vue-promise-btn.css">
<link rel="stylesheet" href="./example/example.css">
</head>
<body>
<div id="app">
<section class="page-header">
<h1 class="project-name">vue-promise-btn</h1>
<h2 class="project-tagline">Vue.js plugin that handles buttons asynchronous lock and show loading state indicator</h2>
<a href="https://github.com/STUkh/vue-promise-btn" class="btn">View on GitHub</a>
<a href="https://github.com/STUkh/vue-promise-btn/zipball/master" class="btn">Download .zip</a>
<a href="https://github.com/STUkh/vue-promise-btn/tarball/master" class="btn">Download .tar.gz</a>
</section>
<section class="main-content">
<h2>Features</h2>
<ul>
<li>Easy-to-use API</li>
<li>Works with any tag and even forms</li>
<li>Packaged with optional built-in spinner</li>
<li>Only 1.5KB minified and gzipped</li>
<li>ESM, CommonJS, UMD versions</li>
</ul>
<h2>Installation</h2>
<div class="highlight">
<pre class="highlight"><span class="no">import</span> Vue <span class="no">from</span> 'vue'
<span class="no">import</span> VuePromiseBtn <span class="no">from</span> 'vue-promise-btn'
// not required. Styles for built-in spinner
<span class="no">import</span> 'vue-promise-btn/dist/vue-promise-btn.css'
Vue.use(VuePromiseBtn) // or with global options: Vue.use(VuePromiseBtn, {loader: '...'})</pre>
</div>
<h2>Quick Start</h2>
<p>Plugin syntax is extremely simple. Just add directive v-promise-btn to your button:</p>
<div class="highlight">
<pre class="highlight"><code><button <span class="s1">v-promise-btn</span> @click="getData">Get Data</button></code></pre>
</div>
<p>Easily change single instance options:</p>
<div class="highlight">
<pre class="highlight"><code><button <span class="s1">v-promise-btn="options"</span> @click="getData">Get Data</button></code></pre>
</div>
<blockquote>
<b>!!! Event handler should always return Promise</b>
</blockquote>
<h3>Examples</h3>
<p><button v-promise-btn @click="dummyAsyncAction">Click handler</button> <button v-promise-btn @click="chain">Promise chain example <span v-show="currentChain">{{currentChain}}</span></button></p>
<div class="highlight">
<pre class="highlight"><code><button <span class="s1">v-promise-btn</span> @click="asyncAction">Click handler</button></code></pre>
</div>
<p><button v-promise-btn @click.prevent="dummyAsyncAction">With Prevent modifier</button></p>
<div class="highlight">
<pre class="highlight"><code><button <span class="s1">v-promise-btn</span> @click.prevent="asyncAction">With Prevent modifier</button></code></pre>
</div>
<p><button v-promise-btn="{action: 'contextmenu'}" @click.right.prevent="dummyAsyncAction">Right mouse</button></p>
<div class="highlight">
<pre class="highlight"><code><button <span class="s1">v-promise-btn="{action: 'contextmenu'}"</span> @click.right="asyncAction">Right mouse</button></code></pre>
</div>
<p><button v-promise-btn="{action: 'mouseup'}" @click.middle="dummyAsyncAction">Middle mouse </button></p>
<div class="highlight">
<pre class="highlight"><code><button <span class="s1">v-promise-btn="{action: 'mouseup'}"</span> @click.middle="asyncAction">Middle mouse</button></code></pre>
</div>
<p><button class="hide-loader" v-promise-btn="promiseBtnOptions.customComponentLoader" @click="dummyAsyncAction">Loader as custom component</button></p>
<div class="highlight">
<pre class="highlight"><code><button <span class="s1">v-promise-btn="{loader: CustomSpinnerComponent}"</span> @click="asyncAction">Loader as custom component</button></code></pre>
</div>
<p><button class="hide-loader" v-promise-btn="promiseBtnOptions.customHTMLLoader" @click="dummyAsyncAction">Loader as simple HTML</button></p>
<div class="highlight">
<pre class="highlight"><code><button <span class="s1">v-promise-btn="{loader: '<b>(HTML loader...)</b>' }"</span> @click="asyncAction">Loader as custom component</button></code></pre>
</div>
<hr>
<form action="" @submit.prevent="dummyAsyncAction" v-promise-btn="{action: 'submit'}">
<p><button type="submit">Button Form Submit</button></p>
</form>
<div class="highlight">
<pre class="highlight"><code><form <span class="s1">v-promise-btn="{action: 'submit'}"</span> @submit.prevent="asyncAction">
<button type="submit">Button Form Submit</button>
</form></code></pre>
</div>
<form action="" @submit.prevent="dummyAsyncAction" v-promise-btn="{action: 'submit'}">
<p><input type="submit" value="Input Form Submit"></p>
<blockquote>Spinner is hidden because it can't be appended into <input type="submit"> element</blockquote>
</form>
<h2>Options</h2>
<table>
<tr>
<th>Option</th>
<th>Type</th>
<th>Default value</th>
</tr>
<tr>
<td>btnLoadingClass</td>
<td>String</td>
<td>loading</td>
</tr>
<tr>
<td>spinnerHiddenClass</td>
<td>String</td>
<td>hidden</td>
</tr>
<tr>
<td>action</td>
<td>String</td>
<td>click</td>
</tr>
<tr>
<td>disableBtn</td>
<td>Boolean</td>
<td>true</td>
</tr>
<tr>
<td>minTimeout</td>
<td>Number</td>
<td>400</td>
</tr>
<tr>
<td>autoHideSpinnerWrapper</td>
<td>Boolean</td>
<td>false (if true - add display property that depends on spinner state)</td>
</tr>
<tr>
<td>loader</td>
<td>Component or HTML String</td>
<td>Built-in Spinner component</td>
</tr>
<tr>
<td>stringHTMLRenderer</td>
<td>Function</td>
<td>Returns HTML string template</td>
</tr>
<tr>
<td>componentRenderer</td>
<td>Function</td>
<td>Returns component render-function</td>
</tr>
</table>
<h2>Action types</h2>
<p>Vue internal action names for mouse modifiers</p>
<table>
<tr>
<th>Mouse Modifier</th>
<th>Action Name</th>
</tr>
<tr>
<td>Left</td>
<td>click</td>
</tr>
<tr>
<td>Right</td>
<td>contextmenu</td>
</tr>
<tr>
<td>Middle</td>
<td>mouseup</td>
</tr>
</table>
<h2>Limitations</h2>
<ul>
<li>
Vue versions below <a href="https://github.com/vuejs/vue/releases/tag/v2.5.14">v2.5.14</a> does not support promise-btn with event modifiers. <br>
This code will not work, because events with modifiers will always return "undefined"
<div class="highlight"><code><button <span class="s1">v-promise-btn</span> @click.prevent="asyncAction">With Prevent modifier</button></code></div>
<p><b>Solution:</b> Update Vue to <a href="https://github.com/vuejs/vue/releases/tag/v2.5.14">v2.5.14</a> or higher. <a href="https://github.com/vuejs/vue/issues/7705">Issue</a> Fixed by <a href="https://github.com/vuejs/vue/pull/7704">this PR</a></p>
</li>
</ul>
<footer class="site-footer">
<span class="site-footer-owner">MIT © {{currentYear}} <a href="https://github.com/STUkh">STUkh</a></span>
<span class="site-footer-credits"><a href="https://github.com/STUkh/vue-promise-btn">GitHub</a> ◉ <a href="https://npmjs.org/package/vue-promise-btn">NPM</a></span>
</footer>
</section>
</div>
<script src="./example/example.js"></script>
</body>
</html>