vue3-uikit
198 строк · 4.1 Кб
1<template>
2<h3>Accordion to Tabs</h3>
3<section class="accordion">
4<!-- Tab заголовки -->
5<section class="accordion-tabs">
6<button
7v-for="(tab, index) in tabs"
8:key="index"
9:class="['accordion-tab', { 'accordion-active': isActiveTab(index) }]"
10@click="setActiveTab(index)"
11>
12{{ tab.label }}
13</button>
14</section>
15
16<!-- Tab контент -->
17<section class="accordion-content">
18<article
19v-for="(tab, index) in tabs"
20:key="index"
21:class="['accordion-item', { 'accordion-active': isActiveTab(index) }]"
22>
23<h4 class="accordion-item__label" @click="setActiveTab(index)">
24{{ tab.label }}
25</h4>
26<div class="accordion-item__container">
27<p>{{ tab.content }}</p>
28</div>
29</article>
30</section>
31</section>
32</template>
33
34<script>
35import { ref } from "vue";
36
37export default {
38name: "AccordionToTabs",
39setup() {
40const tabs = ref([
41{
42label: "Tab 1",
43content:
44"Lorem ipsum dolor sit amet, consectetur adipisicing elit. Voluptates, deserunt minima?",
45},
46{
47label: "Tab 2",
48content:
49"Reprehenderit temporibus, assumenda cupiditate consequatur soluta odit ex repudiandae delectus cumque.",
50},
51{
52label: "Tab 3",
53content:
54"Bored ipsum dolor sit amet, consectetur adipisicing elit. Voluptates, deserunt minima?",
55},
56{
57label: "Tab 4",
58content:
59"Deus reprehenderit temporibus, assumenda cupiditate consequatur soluta odit ex repudiandae delectus cumque.",
60},
61{
62label: "Tab 5",
63content:
64"Voluptates deserunt minima, reprehenderit temporibus, assumenda cupiditate consequatur soluta.",
65},
66]);
67
68const activeTab = ref(0);
69
70const setActiveTab = (index) => {
71activeTab.value = index;
72};
73
74const isActiveTab = (index) => {
75return activeTab.value === index;
76};
77
78return {
79tabs,
80activeTab,
81setActiveTab,
82isActiveTab,
83};
84},
85};
86</script>
87
88<style scoped>
89.accordion {
90background: #f9f9f9;
91box-shadow: 0 1em 2em -0.9em rgba(0, 0, 0, 0.7);
92border-radius: 10px;
93overflow: hidden;
94width: 100%;
95max-width: 400px;
96margin: 0 auto;
97}
98
99@media (min-width: 600px) {
100.accordion {
101max-width: 600px;
102}
103}
104
105.accordion-tabs {
106display: none;
107}
108
109@media (min-width: 600px) {
110.accordion-tabs {
111display: flex;
112background: rgba(68, 127, 255, 0.1);
113}
114
115.accordion-tab {
116background: rgba(68, 127, 255, 0.1);
117padding: 1rem 2rem;
118font: inherit;
119flex: 1;
120border: none;
121cursor: pointer;
122transition: background-color 0.1s ease;
123}
124
125.accordion-tab:hover {
126background: rgba(249, 249, 249, 0.1);
127}
128
129.accordion-tab.accordion-active {
130background: #f9f9f9;
131}
132}
133
134.accordion-content .accordion-item {
135border-bottom: 1px solid #eaeaea;
136padding: 1.25rem;
137background: #f9f9f9;
138transition: height 0.5s ease;
139cursor: pointer;
140}
141
142.accordion-content .accordion-item:last-child {
143border-bottom: none;
144}
145
146.accordion-content .accordion-item__label {
147margin: 0;
148cursor: pointer;
149transition: padding 0.2s ease;
150}
151
152/* Article не видны по умолчанию */
153.accordion-item {
154display: block;
155}
156
157.accordion-content .accordion-item__container {
158padding: 0;
159height: 0;
160overflow: hidden;
161opacity: 0;
162transition: padding 0.2s ease, opacity 0.5s 0.15s ease;
163}
164
165.accordion-content .accordion-active {
166background: rgba(68, 127, 255, 0.1);
167padding: 1rem;
168display: block;
169border: none;
170min-height: 100px;
171}
172
173.accordion-content .accordion-active .accordion-item__label {
174padding-bottom: 1.5rem;
175cursor: inherit;
176}
177
178.accordion-content .accordion-active .accordion-item__container {
179padding: 0;
180height: auto;
181opacity: 1;
182}
183
184@media (min-width: 600px) {
185.accordion-item {
186display: none;
187}
188
189.accordion-content .accordion-active {
190padding: 2.4rem;
191min-height: 260px;
192}
193
194.accordion-content .accordion-active .accordion-item__container {
195padding: 1.25em;
196}
197}
198</style>
199