vue3-uikit
195 строк · 3.9 Кб
1<template>
2<div>
3<div class="demo">
4<Button @click="showModal = true" class="btn btn-primary"
5>Открыть окно</Button
6>
7</div>
8
9<!-- Модальное окно -->
10<transition name="modal">
11<div v-if="showModal" class="modal-overlay" @click="closeModal">
12<div class="modal-content" @click.stop>
13<button class="btn modal-close-btn" @click="closeModal">×</button>
14<div class="modal-body">
15<h3>Modal Title</h3>
16<p>
17Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Donec
18odio. Quisque volutpat mattis eros. Nullam malesuada erat ut
19turpis. Suspendisse urna nibh viverra non semper suscipit posuere
20a pede. Donec nec justo eget felis facilisis fermentum. Aliquam
21porttitor mauris sit amet orci. Aenean dignissim pellentesque
22felis. Morbi in sem quis dui placerat ornare. Pellentesque odio
23nisi euismod in pharetra a ultricies in diam. Sed arcu. Cras
24consequat.
25</p>
26</div>
27<div class="modal-footer">
28<Button @click="closeModal" class="btn btn-primary">Close</Button>
29<Button @click="confirmAction" class="btn btn-confirm"
30>Confirm</Button
31>
32</div>
33</div>
34</div>
35</transition>
36</div>
37</template>
38
39<script>
40import { ref } from "vue";
41
42export default {
43name: "Modal",
44
45setup() {
46const showModal = ref(false);
47
48const closeModal = () => {
49showModal.value = false;
50};
51
52const confirmAction = () => {
53console.log("Confirmed");
54closeModal();
55};
56
57return {
58showModal,
59closeModal,
60confirmAction,
61};
62},
63};
64
65// Компонент кнопки
66export const Button = {
67template: `
68<button class="btn" @click="$emit('click')">
69<slot></slot>
70</button>
71`,
72};
73</script>
74
75<style scoped>
76
77.demo {
78padding: 20px;
79text-align: center;
80}
81
82/* Анимация открытия и закрытия модального окна */
83.modal-enter-active,
84.modal-leave-active {
85transition: opacity 0.5s, transform 0.5s;
86}
87
88.modal-enter, .modal-leave-to {
89opacity: 0;
90transform: translateY(-10px);
91}
92
93/* Стили модального окна */
94.modal-overlay {
95position: fixed;
96top: 0;
97left: 0;
98width: 100%;
99height: 100%;
100background: rgba(0, 0, 0, 0.7);
101display: flex;
102align-items: center;
103justify-content: center;
104z-index: 1000;
105opacity: 0;
106animation: fadeIn 0.3s forwards;
107}
108
109@keyframes fadeIn {
110to {
111opacity: 1;
112}
113}
114
115.modal-content {
116background: white;
117padding: 30px;
118border-radius: 10px;
119box-shadow: 0 10px 25px rgba(0, 0, 0, 0.2);
120max-width: 600px;
121width: 100%;
122position: relative;
123animation: slideUp 0.5s forwards;
124}
125
126@keyframes slideUp {
127from {
128transform: translateY(20px);
129}
130to {
131transform: translateY(0);
132}
133}
134
135.modal-close-btn {
136position: absolute;
137top: 15px;
138right: 15px;
139background: red;
140border: none;
141cursor: pointer;
142color: white;
143}
144
145.modal-body {
146margin-bottom: 20px;
147color: #555;
148line-height: 1.6;
149}
150
151.modal-footer {
152text-align: right;
153}
154
155/* Стили для кнопок */
156.btn {
157padding: 10px 20px;
158border: none;
159cursor: pointer;
160font-size: 14px;
161margin: 5px;
162transition: background-color 0.3s, color 0.3s, box-shadow 0.3s;
163border-radius: 5px;
164box-shadow: 0 3px 6px rgba(0, 0, 0, 0.16);
165}
166
167.btn-primary {
168background-color: #6200ea;
169color: white;
170}
171
172.btn-primary:hover {
173background-color: #531cc0;
174box-shadow: 0 4px 8px rgba(0, 0, 0, 0.24);
175}
176
177.btn-secondary {
178background-color: #03dac6;
179color: white;
180}
181
182.btn-secondary:hover {
183background-color: #02c3b0;
184box-shadow: 0 4px 8px rgba(0, 0, 0, 0.24);
185}
186
187.btn:hover {
188transform: translateY(-2px);
189}
190
191.btn-confirm {
192background-color: orange;
193color: white;
194}
195</style>
196