Skip to content

Commit 95c588f

Browse files
committed
Merge branch 'feature-custom_component'
# Conflicts: # package-lock.json # package.json
2 parents 3eae6bd + 00a5a48 commit 95c588f

33 files changed

+13628
-5252
lines changed

.babelrc

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
{
2-
"presets": ["env"],
3-
"plugins": [
4-
"transform-object-assign",
5-
["transform-runtime", {
6-
"polyfill": false,
7-
"regenerator": true
8-
}]
2+
"presets": [
3+
"env",
4+
"stage-2"
95
]
106
}

.eslintrc

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"parser": "babel-eslint",
3+
"extends": [
4+
"standard"
5+
],
6+
"plugins": [
7+
"babel"
8+
],
9+
"env": {
10+
"es6": true
11+
},
12+
"rules": {
13+
"semi" : 0,
14+
"indent" : [2, "tab"],
15+
"no-tabs" : 0,
16+
"no-trailing-spaces" : 0,
17+
"key-spacing" : 0,
18+
"jsx-quotes" : [2, "prefer-single"],
19+
"max-len" : [2, 120, 2],
20+
"object-curly-spacing" : [2, "always"]
21+
}
22+
}

README.md

Lines changed: 147 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,32 +15,52 @@
1515

1616
[https://godofbrowser.github.io/vuejs-dialog/](https://godofbrowser.github.io/vuejs-dialog/)
1717

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+
1826
## Installation
1927

2028
#### HTML
21-
Include the script:
2229

2330
```html
2431
// Include vuejs
2532
<script type="text/javascript" src="./path/to/vue.min.js"></script>
2633

27-
// Include the vuejs-dialog plugin
34+
// Include vuejs-dialog plugin
35+
<link href="./path/to/vuejs-dialog.min.css" rel="stylesheet">
2836
<script type="text/javascript" src="./path/to/vuejs-dialog.min.js"></script>
2937

3038
<script>
3139
// Tell Vue to install the plugin.
3240
window.Vue.use(VuejsDialog.default)
3341
</script>
3442
```
35-
#### NPM
43+
#### Package Manager
3644
```javascript
3745
// installation via npm
38-
npm install vuejs-dialog
46+
npm i -S vuejs-dialog
47+
48+
// or
49+
50+
// installation via yarn
51+
yarn add vuejs-dialog
52+
```
53+
54+
```javascript
55+
// then
3956

4057
// import into project
4158
import Vue from "vue"
4259
import VuejsDialog from "vuejs-dialog"
4360

61+
// include the default style
62+
import 'vuejs-dialog/vuejs-dialog.min.css'
63+
4464
// Tell Vue to install the plugin.
4565
Vue.use(VuejsDialog)
4666
```
@@ -114,7 +134,7 @@ methods: {
114134
}
115135
```
116136

117-
__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__
118138

119139
```html
120140
// While looping through users
@@ -144,6 +164,41 @@ methods: {
144164
}
145165
```
146166

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+
147202
__For v-confirm directive, if an "OK" callback is not provided, the default event would be triggered.__
148203

149204
```html
@@ -185,6 +240,7 @@ let options = {
185240
verificationHelp: 'Type "[+:verification]" below to confirm', // Verification help text. [+:verification] will be matched with 'options.verification' (i.e 'Type "continue" below to confirm')
186241
clicksCount: 3, // for soft confirm, user will be asked to click on "proceed" btn 3 times before actually proceeding
187242
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
188244
};
189245

190246
this.$dialog.confirm(message, options)
@@ -214,7 +270,7 @@ Vue.use(VuejsDialog, {
214270

215271
### CSS Override
216272

217-
Please use basic css, ex:
273+
If you have included the plugin's style and wish to make a few overides, you can do so with basic css, ex:
218274
```css
219275
.dg-btn--ok {
220276
border-color: green;
@@ -234,6 +290,86 @@ this.$dialog.confirm($message, {
234290
type: 'hard'
235291
})
236292
```
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+
![Vuejs Dialog Plugin](./src/docs/img/custom-view.png?raw=true "Vuejs Dialog Plugin custom view demo")
237373

238374
## What's next?
239375
### Custom components (coming soon!!!)
@@ -305,4 +441,8 @@ let vm = new Vue({
305441

306442
## Contributing
307443

308-
Let's make it better :)
444+
* Fork it!
445+
* Create your feature branch: git checkout -b my-new-feature
446+
* Commit your changes: git commit -am 'Add some feature'
447+
* Push to the branch: git push origin my-new-feature
448+
* Submit a pull request :)

dist/vuejs-dialog-mixin.min.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)