forked from vuejs/docs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTestingApiSwitcher.vue
125 lines (108 loc) · 2.47 KB
/
TestingApiSwitcher.vue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
<script setup lang="ts">
import { ref } from 'vue';
const activeId = ref('vtu-api')
const testingLangs = [
{
label: 'Vue Test Utils',
className: 'vtu-api'
},
{
label: 'Cypress',
className: 'cypress-api'
},
{
label: 'Testing Library',
className: 'testing-library-api'
},
]
</script>
<template>
<div class="testing-code-examples" :class="`prefers-${activeId}`">
<div class="tabs">
<div
v-for="lang in testingLangs"
:key="lang.className"
class="tab"
:class="{ active: lang.className === activeId }"
@click="activeId = lang.className"
>{{ lang.label }}</div>
</div>
<div class="code-example">
<slot/>
</div>
</div>
</template>
<style scoped>
/* TODO: Replace with a VTCodeGroup when available */
/* Layout */
.code-examples {
display: flex;
flex-direction: column;
}
.code-example :slotted([class*=language]) {
margin-top: 0;
border-top-left-radius: 0;
}
/* Tab Styles */
.tabs {
display: flex;
}
.tab {
color: white;
background: #292d3ef0;
border-bottom-color: rgba(255,255,255,0.3);
padding: 6px 24px;
border-width: 2px;
border-style: solid;
border-top: transparent;
border-right: transparent;
border-left: transparent;
cursor: pointer;
transition: border, background-color .2s;
transition-property: border, background-color;
transition-duration: 0.2s, 0.2s;
transition-timing-function: ease, ease;
transition-delay: 0s, 0s;
}
.tab.active {
background: #292d3e;
border-bottom: 2px solid var(--vt-c-brand);
}
.tab:first-child {
border-top-left-radius: 8px;
}
.tab:last-child {
border-top-right-radius: 8px;
}
/* When the sm media query hits, make sure the
tabs line up with the negative margins of the
code blocks. Should also remove the border radius.
*/
@media screen and (max-width: 639px) {
.tabs {
margin: 0 -24px;
}
.tab, .tab:first-child, .tab:last-child {
flex-grow: 1;
text-align: center;
border-radius: 0;
}
}
:global(.dark .testing-code-examples .tab:not(.active)) {
border-bottom: 2px solid rgba(255,255,255,.2);
background: #2f2f2f;
color: inherit;
}
:global(.dark .testing-code-examples .tab.active) {
background: var(--vt-c-black-soft);
}
/* Show/Hide logic for codeblocks */
:slotted([class$="api"]) {
display: none;
}
.prefers-cypress-api :slotted(.cypress-api),
.prefers-testing-library-api :slotted(.testing-library-api),
.prefers-vtu-api :slotted(.vtu-api) {
display: block;
}
</style>