Skip to content

Commit b511287

Browse files
committed
Feature: Ability to set dialog title
1 parent 68953c4 commit b511287

File tree

7 files changed

+84
-46
lines changed

7 files changed

+84
-46
lines changed

README.md

Lines changed: 50 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -89,18 +89,17 @@ this.$dialog.confirm("If you delete this record, it'll be gone forever.", {
8989
});
9090
```
9191

92-
## Usage as a directive (new)
92+
## Usage as a directive
9393

94-
If you don't pass a message, the global/default message would be used.
94+
__If you don't pass a message, the global/default message would be used.__
9595
```html
9696
<button type="submit" v-confirm="">submit</button>
9797
```
9898

99-
10099
```html
101100
// Callbacks can be provided
102-
// Note: If "loader" is set to true, the makeAdmin callback will be passed a "dialog" object
103-
// Which is useful for stoping the loader, or closing the dialog.
101+
// Note: If "loader" is set to true, the makeAdmin callback will receive a "dialog" object
102+
// Which is useful for closing the dialog when transaction is complete.
104103
<button v-confirm="{ok: makeAdmin, cancel: doNothing, message: 'User will be given admin privileges. Make user an Admin?'}">Make Admin</button>
105104
```
106105
```javascript
@@ -115,15 +114,59 @@ methods: {
115114
}
116115
```
117116

117+
__A more practical use of ths `v-confirm` directive inside a loop__
118+
119+
```html
120+
// While looping through users
121+
<button v-for="user in users"
122+
v-confirm="{
123+
loader: true,
124+
ok: dialog => makeAdmin(dialog, user),
125+
cancel: doNothing,
126+
message: 'User will be given admin privileges. Make user an Admin?'}"
127+
>
128+
Make Admin
129+
</button>
130+
```
131+
```javascript
132+
methods: {
133+
makeAdmin: function(dialog, user) {
134+
// Make user admin from the backend
135+
/* tellServerToMakeAdmin(user) */
136+
137+
// When completed, close the dialog
138+
/* dialog.close() */
139+
140+
},
141+
doNothing: function() {
142+
// Do nothing or some other stuffs
143+
}
144+
}
145+
```
118146

119-
For v-confirm directive, if an "OK" callback is not provided, the default event would be triggered.
147+
__For v-confirm directive, if an "OK" callback is not provided, the default event would be triggered.__
120148

121149
```html
122-
// You can use it on links too
150+
// Default Behaviour when used on links
123151
<a href="http://example.com" v-confirm="'This will take you to http://example.com. Proceed with caution'">Go to example.com</a>
124152

125153
```
126154

155+
## Setting a dialog title (new)
156+
157+
You can now set a dialog title by passing your message as an object instead of a string.
158+
The message object should contain a `title` and `body`
159+
160+
```javascript
161+
let message = {
162+
title: 'Vuejs Dialog Plugin',
163+
body: 'A lightweight, promise based alert, prompt and confirm dialog'
164+
}
165+
166+
this.$dialog.confirm(message)
167+
```
168+
169+
127170
### Options
128171
```javascript
129172
// Parameters and options

dist/vuejs-dialog.min.js

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

dist/vuejs-dialog.min.js.map

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

docs/js/vuejs-dialog.min.js

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

src/plugin/components/dialog-window.vue

Lines changed: 12 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,14 @@
99
<div class="dg-content-cont dg-content-cont--floating">
1010
<div class="dg-main-content">
1111

12-
<div class="dg-content-body">
13-
<div v-if="options.html" class="dg-content" v-html="options.message"></div>
14-
<div v-else="" class="dg-content">{{ options.message }}</div>
12+
<div :class="['dg-content-body', {'dg-content-body--has-title': messageHasTitle}]">
13+
<template v-if="messageHasTitle">
14+
<h6 v-if="options.html" class="dg-title" v-html="messageTitle"></h6>
15+
<h6 v-else="" class="dg-title">{{ messageTitle }}</h6>
16+
</template>
17+
18+
<div v-if="options.html" class="dg-content" v-html="messageBody"></div>
19+
<div v-else="" class="dg-content">{{ messageBody }}</div>
1520

1621
<form v-if="isHardConfirm || isPrompt"
1722
class="dg-form"
@@ -56,6 +61,9 @@
5661
import CancelBtn from './cancel-btn.vue'
5762
import {DIALOG_TYPES, ANIMATION_TYPES, CONFIRM_TYPES} from '../js/constants'
5863
64+
import MessageMixin from '../js/mixins/message-mixin'
65+
import ButtonMixin from '../js/mixins/btn-mixin'
66+
5967
export default {
6068
data: function () {
6169
return {
@@ -100,38 +108,12 @@
100108
isPrompt(){
101109
return (this.options.window === DIALOG_TYPES.PROMPT)
102110
},
103-
cancelBtnDisabled(){
104-
return (this.options.window === DIALOG_TYPES.ALERT)
105-
},
106-
okBtnDisabled(){
107-
return (this.options.window === DIALOG_TYPES.CONFIRM)
108-
&& (this.options.type === CONFIRM_TYPES.HARD)
109-
&& (this.input !== this.options.verification)
110-
},
111-
leftBtnEnabled(){
112-
return (this.cancelBtnDisabled === false) || (this.options.reverse === true)
113-
},
114-
rightBtnEnabled(){
115-
return (this.cancelBtnDisabled === false) || (this.options.reverse === false)
116-
},
117111
leftBtnComponent(){
118112
return (this.options.reverse === false) ? 'cancel-btn' : 'ok-btn'
119113
},
120114
rightBtnComponent(){
121115
return (this.options.reverse === true) ? 'cancel-btn' : 'ok-btn'
122116
},
123-
leftBtnFocus(){
124-
return !this.isHardConfirm && (this.options.reverse === true)
125-
},
126-
rightBtnFocus(){
127-
return !this.isHardConfirm && (this.options.reverse === false)
128-
},
129-
leftBtnText(){
130-
return this.options.reverse ? this.options.okText : this.options.cancelText
131-
},
132-
rightBtnText(){
133-
return this.options.reverse ? this.options.cancelText : this.options.okText
134-
},
135117
hardConfirmHelpText() {
136118
return this.options.verificationHelp
137119
.replace(/\[\+:(\w+)]/g, (match, $1) => {
@@ -197,6 +179,7 @@
197179
this.cancelBtnDisabled ? this.proceed() : this.cancel()
198180
}
199181
},
182+
mixins: [MessageMixin, ButtonMixin],
200183
components: {CancelBtn, OkBtn}
201184
}
202185
</script>

src/plugin/components/dialog.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
watch: {
2929
'dialogsARR': {
3030
handler (dialogs) {
31-
let clsName = 'dg-no-scroll'
31+
let clsName = 'dg-open'
3232
const body = document.getElementsByTagName('body')[0]
3333
3434
if (!body) {

src/plugin/styles/default/_layout.scss

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
//@import url('https://fonts.googleapis.com/css?family=Noto+Sans:400,700');
22

3+
body.dg-open {
4+
width: 100%;
5+
height: 100%;
6+
overflow: hidden;
7+
}
8+
39
.dg-container * {
410
box-sizing: border-box;
511
}
@@ -49,6 +55,12 @@
4955
line-height: 1.3em;
5056
}
5157

58+
.dg-title {
59+
margin: 0 0 10px 0;
60+
padding: 0;
61+
font-size: 18px;
62+
}
63+
5264
.dg-content-body {
5365
border-bottom: 2px solid #E1E6EA;
5466
padding-bottom: 15px;
@@ -135,6 +147,12 @@
135147
clear: both;
136148
}
137149

150+
.dg-content-body--has-title {
151+
.dg-content {
152+
font-size: 14px;
153+
}
154+
}
155+
138156
.dg-container--has-input {
139157
.dg-main-content {
140158
max-width: 450px;
@@ -164,9 +182,3 @@
164182
padding: 0 10px 10px;
165183
}
166184
}
167-
168-
.dg-no-scroll {
169-
width: 100%;
170-
height: 100%;
171-
overflow: hidden;
172-
}

0 commit comments

Comments
 (0)