|
15 | 15 |
|
16 | 16 | [https://godofbrowser.github.io/vuejs-dialog/](https://godofbrowser.github.io/vuejs-dialog/) |
17 | 17 |
|
| 18 | +## Important updates in version v1.x.x |
| 19 | +1. Dialog will always resolve with an object. (i.e callback for proceed always will receive an object) |
| 20 | +2. For directives usage, the object returned in (1) above will include a node. The node is the element the directive was bound to (see issue #5) |
| 21 | +3. Styles will have to be included explicitly as they have been extracted into a separate file (see issue #28) |
| 22 | +4. If loader is enabled globally, and a dialog is triggered via a directive without a callback, the loader is ignored for clicks on proceed |
| 23 | +5. Custom class injection on parent node (see issue #25) |
| 24 | +6. Ability to register custom views. This allows for custom logic, custom buttons, etc (see issue #13, #14, #33) |
| 25 | + |
18 | 26 | ## Installation |
19 | 27 |
|
20 | 28 | #### HTML |
@@ -126,7 +134,7 @@ methods: { |
126 | 134 | } |
127 | 135 | ``` |
128 | 136 |
|
129 | | -__A more practical use of ths `v-confirm` directive inside a loop__ |
| 137 | +__A more practical use of ths `v-confirm` directive inside a loop - Solution 1__ |
130 | 138 |
|
131 | 139 | ```html |
132 | 140 | // While looping through users |
@@ -156,6 +164,41 @@ methods: { |
156 | 164 | } |
157 | 165 | ``` |
158 | 166 |
|
| 167 | + |
| 168 | +__( new ) A more practical use of ths `v-confirm` directive inside a loop - Solution 2__ |
| 169 | + |
| 170 | +```html |
| 171 | +// While looping through users |
| 172 | +<button v-for="user in users" |
| 173 | + :data-user="user" |
| 174 | + v-confirm="{ |
| 175 | + loader: true, |
| 176 | + ok: makeAdmin, |
| 177 | + cancel: doNothing, |
| 178 | + message: 'User will be given admin privileges. Make user an Admin?'}" |
| 179 | +> |
| 180 | +Make Admin |
| 181 | +</button> |
| 182 | +``` |
| 183 | +```javascript |
| 184 | +methods: { |
| 185 | + makeAdmin: function(dialog) { |
| 186 | + let button = dialog.node // node is only available if triggered via a directive |
| 187 | + let user = button.dataset.user |
| 188 | + |
| 189 | + // Make user admin from the backend |
| 190 | + /* tellServerToMakeAdmin(user) */ |
| 191 | + |
| 192 | + // When completed, close the dialog |
| 193 | + /* dialog.close() */ |
| 194 | + |
| 195 | + }, |
| 196 | + doNothing: function() { |
| 197 | + // Do nothing or some other stuffs |
| 198 | + } |
| 199 | +} |
| 200 | +``` |
| 201 | + |
159 | 202 | __For v-confirm directive, if an "OK" callback is not provided, the default event would be triggered.__ |
160 | 203 |
|
161 | 204 | ```html |
@@ -197,6 +240,7 @@ let options = { |
197 | 240 | verificationHelp: 'Type "[+:verification]" below to confirm', // Verification help text. [+:verification] will be matched with 'options.verification' (i.e 'Type "continue" below to confirm') |
198 | 241 | clicksCount: 3, // for soft confirm, user will be asked to click on "proceed" btn 3 times before actually proceeding |
199 | 242 | backdropClose: false // set to true to close the dialog when clicking outside of the dialog window, i.e. click landing on the mask |
| 243 | + customClass: '' // Custom class to be injected into the parent node for the current dialog instance |
200 | 244 | }; |
201 | 245 |
|
202 | 246 | this.$dialog.confirm(message, options) |
@@ -246,11 +290,95 @@ this.$dialog.confirm($message, { |
246 | 290 | type: 'hard' |
247 | 291 | }) |
248 | 292 | ``` |
| 293 | +## More flexibility with Custom components |
| 294 | + |
| 295 | +```vue |
| 296 | +/* File: custom-component.vue */ |
| 297 | +<template> |
| 298 | + <div class="custom-view-wrapper"> |
| 299 | + <template v-if=messageHasTitle> |
| 300 | + <h2 v-if="options.html" class="dg-title" v-html="messageTitle"></h2> |
| 301 | + <h2 v-else class="dg-title">{{ messageTitle }}</h2> |
| 302 | + </template> |
| 303 | + <template v-else> |
| 304 | + <h2>Share with friends</h2> |
| 305 | + </template> |
| 306 | +
|
| 307 | + <div v-if="options.html" class="dg-content" v-html="messageBody"></div> |
| 308 | + <div v-else class="dg-content">{{ messageBody }}</div> |
| 309 | + <br/> |
| 310 | +
|
| 311 | + <ok-btn @click="handleShare('facebook')" :options="options">Facebook</ok-btn> |
| 312 | + <ok-btn @click="handleShare('twitter')" :options="options">Twitter</ok-btn> |
| 313 | + <ok-btn @click="handleShare('googleplus')" :options="options">Google+</ok-btn> |
| 314 | + <ok-btn @click="handleShare('linkedin')" :options="options">LinkedIn</ok-btn> |
| 315 | + <cancel-btn @click="handleDismiss()" :options="options">Dismiss</cancel-btn> |
| 316 | + </div> |
| 317 | +</template> |
| 318 | +
|
| 319 | +<script> |
| 320 | + import DialogMixin from 'vuejs-dialog/vuejs-dialog-mixin.min.js' // Include mixin |
| 321 | + import OkBtn from 'path/to/components/ok-btn.vue' |
| 322 | + import CancelBtn from 'path/to/components/cancel-btn.vue' |
| 323 | +
|
| 324 | + export default { |
| 325 | + mixins: [ DialogMixin ], |
| 326 | + methods: { |
| 327 | + handleShare(platform) { |
| 328 | + this.proceed(platform) // included in DialogMixin |
| 329 | + }, |
| 330 | + handleDismiss() { |
| 331 | + this.cancel() // included in DialogMixin |
| 332 | + } |
| 333 | + }, |
| 334 | + components: { CancelBtn, OkBtn } |
| 335 | + } |
| 336 | +</script> |
| 337 | +
|
| 338 | +<style scoped=""> |
| 339 | + button { |
| 340 | + width: 100%; |
| 341 | + margin-bottom: 10px; |
| 342 | + float: none; |
| 343 | + } |
| 344 | +</style> |
| 345 | +
|
| 346 | +``` |
| 347 | + |
| 348 | +```javascript |
| 349 | +import CustomView from './path/to/file/custom-component.vue' |
| 350 | +const VIEW_NAME = 'my-unique-view-name' |
| 351 | + |
| 352 | +let vm = new Vue({ |
| 353 | + created() { |
| 354 | + this.$dialog.registerComponent(VIEW_NAME, CustomView) |
| 355 | + }, |
| 356 | + methods: { |
| 357 | + showCustomView(){ |
| 358 | + this.$dialog.alert(trans('messages.html'), { |
| 359 | + view: VIEW_NAME, // can be set globally too |
| 360 | + html: true, |
| 361 | + animation: 'fade', |
| 362 | + backdropClose: true |
| 363 | + }) |
| 364 | + } |
| 365 | + } |
| 366 | +}) |
| 367 | +``` |
| 368 | + |
| 369 | + ... and you get your custom view |
| 370 | + |
| 371 | + |
| 372 | + |
249 | 373 |
|
250 | 374 | # License |
251 | 375 |
|
252 | 376 | [MIT](http://opensource.org/licenses/MIT) |
253 | 377 |
|
254 | 378 | ## Contributing |
255 | 379 |
|
256 | | -Let's make it better :) |
| 380 | +* Fork it! |
| 381 | +* Create your feature branch: git checkout -b my-new-feature |
| 382 | +* Commit your changes: git commit -am 'Add some feature' |
| 383 | +* Push to the branch: git push origin my-new-feature |
| 384 | +* Submit a pull request :) |
0 commit comments