Skip to content

Commit

Permalink
fix(nuxt-admin): hide drawer on mobile only
Browse files Browse the repository at this point in the history
  • Loading branch information
gravitano committed Mar 3, 2023
1 parent f5d696f commit 5696bdf
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 10 deletions.
4 changes: 0 additions & 4 deletions starter/nuxt-admin/components/Admin/Sidebar.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<script setup lang="ts">
import {breakpointsTailwind, useBreakpoints} from '@vueuse/core';
import {Menu} from '../Aside/Menus.vue';
const props =
Expand All @@ -10,9 +9,6 @@ const props =
const appConfig = useAppConfig();
const adminDrawer = useAdminDrawer();
const $breakpoints = useBreakpoints(breakpointsTailwind);
const isMobile = $breakpoints.smaller('sm'); // only smaller than lg
watchEffect(() => {
adminDrawer.value = !isMobile.value;
});
Expand Down
4 changes: 1 addition & 3 deletions starter/nuxt-admin/components/Aside/Account.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ const {signOut, data: session} = useSession();
function logout() {
signOut();
}
const adminDrawer = useAdminDrawer();
</script>

<template>
Expand All @@ -26,7 +24,7 @@ const adminDrawer = useAdminDrawer();
!rounded-md
flex-1
"
@click="adminDrawer = false"
@click="hideDrawerOnMobile"
>
<Avatar :src="session?.user?.image" />
<div class="text-sm text-left w-8/12">
Expand Down
4 changes: 1 addition & 3 deletions starter/nuxt-admin/components/Aside/Menus.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,13 @@ export type Menu = InstanceType<typeof VListItem>['$props'] & {
defineProps<{
menus: Menu[];
}>();
const adminDrawer = useAdminDrawer();
</script>

<template>
<VList hover class="flex-1 px-2 mb-4 overflow-y-auto">
<template v-for="{text, header, ...menu} in menus" :key="text">
<VListItemHeader v-if="header">{{ header }}</VListItemHeader>
<VListItem v-else v-bind="menu" @click="adminDrawer = false">
<VListItem v-else v-bind="menu" @click="hideDrawerOnMobile">
{{ text }}
</VListItem>
</template>
Expand Down
12 changes: 12 additions & 0 deletions starter/nuxt-admin/composables/admin.ts
Original file line number Diff line number Diff line change
@@ -1 +1,13 @@
import {breakpointsTailwind, useBreakpoints} from '@vueuse/core';

export const useAdminDrawer = () => useState('admin-drawer', () => true);

export const $breakpoints = useBreakpoints(breakpointsTailwind);

export const isMobile = $breakpoints.smaller('sm'); // only smaller than lg

export const hideDrawerOnMobile = () => {
if (isMobile.value) {
useAdminDrawer().value = false;
}
};

1 comment on commit 5696bdf

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Deploy preview for gits-nuxt-admin ready!

✅ Preview
https://gits-nuxt-admin-47hzebh19-gravitano.vercel.app

Built with commit 5696bdf.
This pull request is being automatically deployed with vercel-action

Please sign in to comment.