-
-
Notifications
You must be signed in to change notification settings - Fork 880
/
Banner.vue
108 lines (90 loc) · 1.91 KB
/
Banner.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
<script setup lang="ts">
import { useElementSize } from '@vueuse/core';
import { ref, watchEffect } from 'vue';
defineProps<{
version: string;
}>();
const el = ref<HTMLElement>();
const { height } = useElementSize(el);
watchEffect(() => {
if (height.value) {
document.documentElement.style.setProperty(
'--vp-layout-top-height',
`${height.value + 16}px`
);
}
});
const dismiss = () => {
localStorage.setItem(
'faker-version-banner',
(Date.now() + 8.64e7 * 1).toString() // current time + 1 day
);
document.documentElement.classList.add('banner-dismissed');
};
</script>
<template>
<div ref="el" class="banner">
<div class="text">
These docs are of {{ version }}. For docs of the current version visit:
<a href="https://fakerjs.dev/">fakerjs.dev</a>
</div>
<button type="button" @click="dismiss">
<svg
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 20 20"
fill="currentColor"
>
<path
d="M6.28 5.22a.75.75 0 00-1.06 1.06L8.94 10l-3.72 3.72a.75.75 0 101.06 1.06L10 11.06l3.72 3.72a.75.75 0 101.06-1.06L11.06 10l3.72-3.72a.75.75 0 00-1.06-1.06L10 8.94 6.28 5.22z"
/>
</svg>
</button>
</div>
</template>
<style>
.banner-dismissed {
--vp-layout-top-height: 0px !important;
}
html {
--vp-layout-top-height: 88px;
}
@media (min-width: 375px) {
html {
--vp-layout-top-height: 64px;
}
}
@media (min-width: 768px) {
html {
--vp-layout-top-height: 40px;
}
}
</style>
<style scoped>
.banner-dismissed .banner {
display: none;
}
.banner {
position: fixed;
top: 0;
right: 0;
left: 0;
z-index: var(--vp-z-index-layout-top);
padding: 8px;
text-align: center;
background: #383636;
color: #fff;
display: flex;
justify-content: space-between;
}
.text {
flex: 1;
}
a {
text-decoration: underline;
}
svg {
width: 20px;
height: 20px;
margin-left: 8px;
}
</style>