File tree Expand file tree Collapse file tree 4 files changed +49
-33
lines changed
docs/pages/docs/components Expand file tree Collapse file tree 4 files changed +49
-33
lines changed Original file line number Diff line number Diff line change 22
22
return {
23
23
component: ' bModal' ,
24
24
jsfiddle: ' bofh9aaa' ,
25
+ events: [
26
+ {
27
+ event : ' shown' ,
28
+ description: ' always emits when modal is shown'
29
+ },
30
+ {
31
+ event : ' hidden' ,
32
+ description: ' always emits when modal is hidden'
33
+ },
34
+ {
35
+ event : ' ok' ,
36
+ description: ' when default ok button pressed'
37
+ },
38
+ {
39
+ event : ' cancel' ,
40
+ description: ' when default cancel button pressed'
41
+ }
42
+ ],
25
43
slots: [
26
44
{
27
45
name: ' modal-header' ,
Original file line number Diff line number Diff line change 1
1
< div id ="app ">
2
2
< b-btn @click ="$root.$emit('show::modal','modal1') "> Launch demo modal</ b-btn >
3
3
4
+ <!-- Main UI -->
4
5
< div class ="mt-3 mb-3 ">
5
6
Submitted Names:
6
7
< ul >
7
8
< li v-for ="n in names "> {{n}}</ li >
8
9
</ ul >
9
10
</ div >
10
11
11
- < b-modal id ="modal1 " title ="Submit your name " :on-save ="onSave " save-title ="Submit ">
12
- < b-form-input type ="text " placeholder ="Enter your name " v-model ="name "> </ b-form-input >
12
+ <!-- Modal Component -->
13
+ < b-modal id ="modal1 "
14
+ title ="Submit your name "
15
+ @ok ="submit "
16
+ @shown ="clearName "
17
+ >
18
+ < b-form-input type ="text "
19
+ placeholder ="Enter your name " v-model ="name "
20
+ > </ b-form-input >
13
21
</ b-modal >
22
+
14
23
</ div >
Original file line number Diff line number Diff line change @@ -5,7 +5,10 @@ window.app = new Vue({
5
5
names : [ ]
6
6
} ,
7
7
methods : {
8
- onSave ( ) {
8
+ clearName ( ) {
9
+ this . name = "" ;
10
+ } ,
11
+ submit ( ) {
9
12
if ( ! this . name ) {
10
13
/* eslint-disable no-alert */
11
14
alert ( 'Please enter your name' ) ;
Original file line number Diff line number Diff line change 11
11
<div key =" modal" :id =" id"
12
12
v-show =" visible"
13
13
:class =" ['modal',{fade :fade}]"
14
- @click =" onClickOut($event)" >
14
+ @click =" onClickOut($event)"
15
+ >
15
16
16
17
<div :class =" ['modal-dialog','modal-'+size]" >
17
18
<div class =" modal-content" >
33
34
34
35
<div class =" modal-footer" v-if =" !hideFooter" >
35
36
<slot name =" modal-footer" >
36
- <b-btn variant =" secondary" @click =" $close " >{{closeTitle}}</b-btn >
37
- <b-btn variant =" primary" @click =" $save " >{{saveTitle }}</b-btn >
37
+ <b-btn variant =" secondary" @click =" hide(false) " >{{closeTitle}}</b-btn >
38
+ <b-btn variant =" primary" @click =" hide(true) " >{{okTitle }}</b-btn >
38
39
</slot >
39
40
</div >
40
41
54
55
55
56
/* Make modal display as block instead of inline style, and because Vue's v-show deletes inline "display" style*/
56
57
.modal {
57
- display :block ;
58
+ display : block ;
58
59
}
59
-
60
60
</style >
61
61
62
62
<script >
80
80
},
81
81
title: {
82
82
type: String ,
83
- default: ' Save '
83
+ default: ' '
84
84
},
85
85
size: {
86
86
type: String ,
94
94
type: String ,
95
95
default: ' Close'
96
96
},
97
- onClose: {
98
- type: Function ,
99
- default: null
100
- },
101
- saveTitle: {
97
+ okTitle: {
102
98
type: String ,
103
99
default: ' OK'
104
100
},
105
- onSave: {
106
- type: Function ,
107
- default: null
108
- },
109
101
closeOnBackdrop: {
110
102
type: Boolean ,
111
103
default: true
127
119
this .visible = true ;
128
120
this .$root .$emit (' shown::modal' , this .id );
129
121
this .body .classList .add (' modal-open' );
122
+ this .$emit (' shown' );
130
123
},
131
- hide () {
124
+ hide (isOK ) {
132
125
if (! this .visible ) {
133
126
return ;
134
127
}
135
128
this .visible = false ;
136
129
this .$root .$emit (' hidden::modal' , this .id );
137
130
this .body .classList .remove (' modal-open' );
138
- },
139
- $save () {
140
- if (this .onSave ) {
141
- if (this .onSave () === false ) {
142
- // Cancel event
143
- return ;
144
- }
145
- }
146
- this .hide ();
147
- },
148
- $close () {
149
- if (this .onClose ) {
150
- this .onClose ();
131
+
132
+ this .$emit (' hidden' , isOK);
133
+
134
+ if (isOK === true ) {
135
+ this .$emit (' ok' );
136
+ } else if (isOK === false ) {
137
+ this .$emit (' cancel' );
151
138
}
152
- this .hide ();
153
139
},
154
140
onClickOut (e ) {
155
141
// If backdrop clicked, hide modal
You can’t perform that action at this time.
0 commit comments