Skip to content

Commit 637fc71

Browse files
committed
feat: add CModal component
1 parent c612303 commit 637fc71

File tree

3 files changed

+142
-0
lines changed

3 files changed

+142
-0
lines changed

src/components/Modal/CModal.vue

Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
<template>
2+
<div @click="checkHide($event)">
3+
<div :class="modalClasses" tabindex="-1" role="dialog" style="overflow-y:scroll">
4+
<div :class="dialogClasses" role="document">
5+
<div :class="contentClasses">
6+
<slot name="header">
7+
<div class="modal-header" v-if="!noHeader" style="border-bottom:none !important">
8+
<h5 class="modal-title">{{title}}dasdasdgdasfgdafgfdgdfgdfgsd<br>fgsdfgsdfgsdfgsdfgsdfgsdhbgkash</h5>
9+
<button type="button" class="close" aria-label="Close" @click="hide()">
10+
<span>&times;</span>
11+
</button>
12+
</div>
13+
</slot>
14+
<slot name="body" v-if="!noBody">
15+
<div class="modal-body">
16+
<slot></slot>
17+
</div>
18+
</slot>
19+
<slot name="footer" v-if="!noFooter">
20+
<div class="modal-footer">
21+
<button type="button" class="btn btn-secondary" @click="hide()">Close</button>
22+
<button type="button" :class="btnClasses" @click="hide()">OK</button>
23+
</div>
24+
</slot>
25+
</div>
26+
</div>
27+
</div>
28+
<div :class="backdropClasses" v-if="!noBackdrop && (is_visible || is_transitioning)">
29+
</div>
30+
</div>
31+
</template>
32+
33+
<script>
34+
export default {
35+
name: 'CModal',
36+
// components: { BButton, BButtonClose },
37+
model: {
38+
prop: 'visible',
39+
event: 'change'
40+
},
41+
props: {
42+
visible: Boolean,
43+
centered: Boolean,
44+
noFade: Boolean,
45+
noBackdrop: Boolean,
46+
noCloseOnBackdrop: Boolean,
47+
noHeader: Boolean,
48+
noBody: Boolean,
49+
noFooter: Boolean,
50+
title: String,
51+
size: String,
52+
variant: String,
53+
borderVariant: String,
54+
addModalClasses: String,
55+
addDialogClasses: String,
56+
addContentClasses: String
57+
},
58+
data () {
59+
return {
60+
is_visible: false,
61+
is_transitioning: false,
62+
timeout: null,
63+
}
64+
},
65+
computed: {
66+
backdropClasses () {
67+
return {
68+
'modal-backdrop': true,
69+
fade: !this.noFade,
70+
show: this.is_visible || this.noFade
71+
}
72+
},
73+
modalClasses () {
74+
return [
75+
'modal',
76+
this.addModalClasses,
77+
{
78+
closeModal: !this.noCloseOnBackdrop,
79+
fade: !this.noFade,
80+
show: this.is_visible,
81+
'd-block': this.is_visible || this.is_transitioning,
82+
[`modal-${this.variant}`]: Boolean(this.variant)
83+
}
84+
]
85+
},
86+
dialogClasses () {
87+
return [
88+
this.addDialogClasses,
89+
'modal-dialog',
90+
{
91+
'modal-dialog-centered': this.centered,
92+
[`modal-${this.size}`]: Boolean(this.size),
93+
}
94+
]
95+
},
96+
contentClasses () {
97+
return [
98+
this.addContentClasses,
99+
'modal-content',
100+
{
101+
[`border-${this.borderVariant}`]: Boolean(this.borderVariant),
102+
}
103+
]
104+
},
105+
btnClasses () {
106+
return [`btn btn-${this.variant || 'primary'}`]
107+
}
108+
},
109+
watch: {
110+
visible (newVal, oldVal) {
111+
if (newVal === oldVal)
112+
return
113+
this.toggle(newVal)
114+
}
115+
},
116+
methods: {
117+
checkHide (e) {
118+
if(e.target.classList.contains('closeModal'))
119+
this.hide()
120+
},
121+
hide () {
122+
this.$emit('change', false)
123+
},
124+
toggle (newVal) {
125+
setTimeout(() => { this.is_visible = newVal }, 0)
126+
if (!this.noFade) {
127+
this.is_transitioning = true
128+
clearTimeout(this.timeout)
129+
this.timeout = setTimeout(() => {
130+
this.is_transitioning = false
131+
}, 150)
132+
}
133+
}
134+
}
135+
}
136+
</script>

src/components/Modal/index.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import CModal from './CModal'
2+
3+
export {
4+
CModal
5+
}

src/components/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,4 @@ export * from './Tooltip'
2121
export * from './Table'
2222
export * from './Form'
2323
export * from './Collapse'
24+
export * from './Modal'

0 commit comments

Comments
 (0)