-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathindex.html
272 lines (239 loc) · 12.2 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
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
<!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">
<!-- START: Bootstrap-Vue related stuff -->
<link type="text/css" rel="stylesheet" href="//unpkg.com/bootstrap/dist/css/bootstrap.min.css" />
<link
type="text/css"
rel="stylesheet"
href="//unpkg.com/bootstrap-vue@latest/dist/bootstrap-vue.min.css"
/>
<script src="//unpkg.com/bootstrap-vue@latest/dist/bootstrap-vue.min.js"></script>
<!-- END: Bootstrap-Vue related stuff -->
<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="cayman-btn">View on GitHub</a>
<a href="https://github.com/STUkh/vue-promise-btn/zipball/master" class="cayman-btn">Download .zip</a>
<a href="https://github.com/STUkh/vue-promise-btn/tarball/master" class="cayman-btn">Download .tar.gz</a>
</section>
<section class="main-content">
<h2>Features</h2>
<ul>
<li>Easy-to-use API</li>
<li>Flexible Usage</li>
<li>Works with any tag and even forms</li>
<li>In Extended Mode - compatible with 3rd party components</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>There are 2 modes for this plugin: <b>SIMPLIFIED</b> and <b>EXTENDED</b></p>
<h3>Simplified syntax:</h3>
<p>EXTREMELY easy. 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>Or with single instance options:</p>
<pre class="highlight"><code><button <span class="s1">v-promise-btn="options"</span> @click="getData">Get Data</button></code></pre>
<blockquote>
<b>!!! Event handler should <span class="highlight"><span class="s1">always return Promise</span></span> for SIMPLIFIED mode</b>
</blockquote>
<h3>Extended syntax:</h3>
<p>Simply add option parameter <span class="s1">promise</span> and assing to it promise from data you want to handle.</p>
<pre class="highlight"><code><button <span class="s1">v-promise-btn="{ promise: isLoading }"</span> @click="getData">Get Data</button></code></pre>
<blockquote>
<b>!!! If you face any issue - better to use <span class="highlight"><span class="s1">EXTENDED</span></span> syntax</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>
<hr>
<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>
<hr>
<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>
<hr>
<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>
<hr>
<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>
<hr>
<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>
<p><button class="hide-loader" v-promise-btn v-on="{ click: asyncActionWithArgs($event, 'abc') }">Btn with expression on click handler</button></p>
<div class="highlight">
<pre class="highlight"><code><button <span class="s1">v-promise-btn</span> v-on="{ click: asyncActionWithArgs($event, 'abc') }">Btn with expression on click handle</button></code></pre>
</div>
<hr>
<blockquote>
<b><span class="highlight"><span class="s1">!!! Important:</span></span> if you want to use closure - you have to define <span class="highlight">v-on="{ click: test('abc') }"</span> instead of <span class="highlight">@click="test('abc')"</span></b>
</blockquote>
<p><button class="hide-loader" v-promise-btn="{ promise: dataPromise }" @click="asyncWithPromiseInData('Hello from async action!')">Extended syntax with external promise</button></p>
<div class="highlight">
<pre class="highlight"><code><button <span class="s1">v-promise-btn="{ promise: dataPromise }"</span> @click="asyncWithPromiseInData('Hello from async action!')">Extended syntax with external promise</button></code></pre>
</div>
<hr>
<blockquote>This param allow to use directive with external components. Use this option if you faced issued with simplified syntax</blockquote>
<p><b-btn v-promise-btn="{ promise: bootstrapBtnPromise }" @click="vueBootstrap('Hello from vue bootstrap button!')">Extended with Vue Bootstrap</b-btn></p>
<div class="highlight">
<pre class="highlight"><code><span class="no"><b-btn</span> <span class="s1">v-promise-btn="{ promise: bootstrapBtnPromise }"</span> @click="vueBootstrap('Hello from vue bootstrap button!')"<span class="no">></span>Extended with Vue Bootstrap<span class="no"></b-btn></span></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>
<hr>
<custom-form @submit="dummyAsyncAction" v-promise-btn="{action: 'submit'}"></custom-form>
<div class="highlight">
<pre class="highlight"><code>Vue.component('custom-form', {
template: `<form @submit.prevent="$emit('submit', 'data')">
<p>
<button type="submit">Button Form Submit - Handle Component Event</button>
</p>
</form>`
})
<custom-form @submit="dummyAsyncAction" v-promise-btn="{action: 'submit'}"></custom-form></code></pre>
</div>
<hr>
<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 higher <a href="https://github.com/vuejs/vue/releases/tag/v2.6.0">v2.6.0</a> does not support promise-btn v1.1.0.
<br>
For Vue v2.6 or higher use promise-btn v1.2.0 or higher.
</li>
<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>