Skip to content

Commit c20263f

Browse files
committed
banner slot
1 parent af208d9 commit c20263f

File tree

5 files changed

+68
-10
lines changed

5 files changed

+68
-10
lines changed

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66
},
77
"dependencies": {
88
"@vue/repl": "^0.4.8",
9-
"@vue/theme": "^0.1.25",
9+
"@vue/theme": "^0.1.26",
1010
"dynamics.js": "^1.1.5",
1111
"gsap": "^3.9.0",
12-
"vitepress": "^0.20.9",
12+
"vitepress": "^0.20.10",
1313
"vue": "^3.2.25"
1414
},
1515
"devDependencies": {

pnpm-lock.yaml

Lines changed: 8 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/.vitepress/inlined-scripts/restorePreference.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,7 @@
77
}
88
restore('vue-docs-prefer-composition', 'prefer-composition')
99
restore('vue-docs-prefer-sfc', 'prefer-sfc', true)
10+
11+
window.__VUE_BANNER_ID__ = 'wip'
12+
restore(`vue-docs-banner-${__VUE_BANNER_ID__}`, 'banner-dismissed')
1013
})()
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<script setup>
2+
/**
3+
* Adding a new banner:
4+
* 1. uncomment the banner slot in ../index.ts
5+
* 2. uncomment and update BANNER_ID in ../../inlined-scripts/restorePreferences.ts
6+
* 3. update --vt-banner-height if necessary
7+
*/
8+
9+
let open = $ref(true)
10+
11+
/**
12+
* Call this if the banner is dismissible
13+
*/
14+
function dismiss() {
15+
open = false
16+
document.documentElement.classList.add('banner-dismissed')
17+
localStorage.setItem(`vue-docs-banner-${__VUE_BANNER_ID__}`, 'true')
18+
}
19+
</script>
20+
21+
<template>
22+
<div class="banner" v-if="open">
23+
Work in Progress - for Preview Only
24+
</div>
25+
</template>
26+
27+
<style>
28+
html:not(.banner-dismissed) {
29+
--vt-banner-height: 24px;
30+
}
31+
</style>
32+
33+
<style scoped>
34+
.banner {
35+
position: fixed;
36+
z-index: var(--vp-z-index-banner);
37+
box-sizing: border-box;
38+
top: 0;
39+
left: 0;
40+
right: 0;
41+
height: var(--vt-banner-height);
42+
line-height: var(--vt-banner-height);
43+
text-align: center;
44+
font-size: 12px;
45+
font-weight: 600;
46+
color: #fff;
47+
background-color: var(--vt-c-green);
48+
}
49+
50+
.banner-dismissed .banner {
51+
display: none;
52+
}
53+
</style>

src/.vitepress/theme/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { h } from 'vue'
22
import { VPTheme, VTBadge } from '@vue/theme'
3+
import Banner from './components/Banner.vue'
34
import PreferenceSwitch from './components/PreferenceSwitch.vue'
45
import {
56
preferComposition,
@@ -14,6 +15,7 @@ import './styles/options-boxes.css'
1415
export default Object.assign({}, VPTheme, {
1516
Layout: () => {
1617
return h(VPTheme.Layout, null, {
18+
banner: () => h(Banner),
1719
'sidebar-top': () => h(PreferenceSwitch)
1820
})
1921
},

0 commit comments

Comments
 (0)