Skip to content

Commit 431c1f7

Browse files
committed
feat: add modal component with slot
1 parent 4d4786a commit 431c1f7

File tree

3 files changed

+121
-2
lines changed

3 files changed

+121
-2
lines changed

doit/todo/src/App.vue

+4-2
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,10 @@ export default {
3030
this.todoItems = [];
3131
},
3232
addTodo(newTodoItem) {
33-
localStorage.setItem(newTodoItem, newTodoItem);
34-
this.todoItems.push(newTodoItem);
33+
if (newTodoItem !== "") {
34+
localStorage.setItem(newTodoItem, newTodoItem);
35+
this.todoItems.push(newTodoItem);
36+
}
3537
},
3638
removeTodo(todoItem, index) {
3739
localStorage.removeItem(todoItem);

doit/todo/src/components/TodoInput.vue

+25
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,35 @@
44
type="text"
55
v-model="newTodoItem"
66
placeholder="Things I have to do..."
7+
ref="inputBox"
78
@keypress.enter="addTodo"
89
/>
910
<span class="addContainer" @click="addTodo">
1011
<i class="addBtn fas fa-plus" aria-hidden="true"></i>
1112
</span>
13+
14+
<Modal v-if="showModal" @close="closeModal">
15+
<template v-slot:header>경고</template>
16+
<template v-slot:footer @click="closeModal"
17+
>할 일을 입력하세요.
18+
<i
19+
class="closeModalBtn fas fa-times"
20+
aria-hidden="true"
21+
@click="closeModal"
22+
></i>
23+
</template>
24+
</Modal>
1225
</div>
1326
</template>
1427

1528
<script>
29+
import Modal from "./common/Modal.vue";
30+
1631
export default {
1732
data() {
1833
return {
1934
newTodoItem: "",
35+
showModal: false,
2036
};
2137
},
2238
methods: {
@@ -25,6 +41,9 @@ export default {
2541
const value = this.newTodoItem && this.newTodoItem.trim();
2642
this.$emit("addTodo", value);
2743
this.clearInput();
44+
} else {
45+
this.showModal = true;
46+
this.$refs.inputBox.blur();
2847
}
2948
},
3049
clearInput() {
@@ -34,6 +53,12 @@ export default {
3453
localStorage.removeItem(todoItem);
3554
this.todoItems.splice(index, 1);
3655
},
56+
closeModal() {
57+
this.showModal = false;
58+
},
59+
},
60+
components: {
61+
Modal,
3762
},
3863
};
3964
</script>
+92
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
<template lang="html">
2+
<transition name="modal">
3+
<div class="modal-mask" @click="closeModal">
4+
<div class="modal-wrapper">
5+
<div class="modal-container">
6+
<div class="modal-header">
7+
<slot name="header">
8+
<!-- -->
9+
</slot>
10+
</div>
11+
12+
<div class="modal-footer">
13+
<slot name="footer">
14+
<!-- -->
15+
</slot>
16+
</div>
17+
</div>
18+
</div>
19+
</div>
20+
</transition>
21+
</template>
22+
23+
<script>
24+
export default {
25+
methods: {
26+
closeModal() {
27+
console.log("safas");
28+
this.$emit("close");
29+
},
30+
},
31+
};
32+
</script>
33+
34+
<style>
35+
.closeModalBtn {
36+
color: #62acde;
37+
}
38+
.modal-mask {
39+
position: fixed;
40+
z-index: 9998;
41+
top: 0;
42+
left: 0;
43+
width: 100%;
44+
height: 100%;
45+
background-color: rgba(0, 0, 0, 0.5);
46+
display: table;
47+
transition: opacity 0.3s ease;
48+
}
49+
.modal-wrapper {
50+
display: table-cell;
51+
vertical-align: middle;
52+
}
53+
.modal-container {
54+
width: 300px;
55+
margin: 0px auto;
56+
padding: 20px 30px;
57+
background-color: #fff;
58+
border-radius: 2px;
59+
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.33);
60+
transition: all 0.3s ease;
61+
font-family: Helvetica, Arial, sans-serif;
62+
}
63+
.modal-header h3 {
64+
margin-top: 0;
65+
color: #62acde;
66+
}
67+
.modal-body {
68+
margin: 20px 0;
69+
}
70+
.modal-default-button {
71+
float: right;
72+
}
73+
/*
74+
* The following styles are auto-applied to elements with
75+
* transition="modal" when their visibility is toggled
76+
* by Vue.js.
77+
*
78+
* You can easily play with the modal transition by editing
79+
* these styles.
80+
*/
81+
.modal-enter {
82+
opacity: 0;
83+
}
84+
.modal-leave-active {
85+
opacity: 0;
86+
}
87+
.modal-enter .modal-container,
88+
.modal-leave-active .modal-container {
89+
-webkit-transform: scale(1.1);
90+
transform: scale(1.1);
91+
}
92+
</style>

0 commit comments

Comments
 (0)