aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/docs/plugins
diff options
context:
space:
mode:
Diffstat (limited to 'docs/plugins')
-rw-r--r--docs/plugins/menu.ts48
-rw-r--r--docs/plugins/scrollbars.client.ts5
2 files changed, 53 insertions, 0 deletions
diff --git a/docs/plugins/menu.ts b/docs/plugins/menu.ts
new file mode 100644
index 0000000..82512c3
--- /dev/null
+++ b/docs/plugins/menu.ts
@@ -0,0 +1,48 @@
+export default defineNuxtPlugin((ctx: any) => {
+ // Menu visible reference
+ const visible = ref(false)
+
+ // Open the menu
+ const open = () => (visible.value = true)
+
+ // Close the menu
+ const close = () => (visible.value = false)
+
+ // Toggle the menu (useful for one-off buttons)
+ const toggle = () => (visible.value = !visible.value)
+
+ // Watch route change, close on change
+ ctx.$router.afterEach(() => setTimeout(close, 50))
+
+ // Watch visible and remove overflow so the scrollbar disappears when menu is opened
+ if (process.client) {
+ watch(
+ visible,
+ (isVisible) => {
+ const html = document.documentElement
+
+ if (isVisible) {
+ html.style.overflow = 'hidden'
+ } else {
+ setTimeout(() => {
+ html.style.overflow = ''
+ }, 100) /* had to put it, because of layout shift on leave transition */
+ }
+ },
+ {
+ immediate: true
+ }
+ )
+ }
+
+ return {
+ provide: {
+ menu: {
+ visible,
+ close,
+ open,
+ toggle
+ }
+ }
+ }
+})
diff --git a/docs/plugins/scrollbars.client.ts b/docs/plugins/scrollbars.client.ts
new file mode 100644
index 0000000..d1078cf
--- /dev/null
+++ b/docs/plugins/scrollbars.client.ts
@@ -0,0 +1,5 @@
+export default defineNuxtPlugin(() => {
+ if (navigator && navigator.userAgent && navigator.userAgent.match(/Win[a-z0-9]*;/)) {
+ document.documentElement.classList.add('docus-scrollbars')
+ }
+})