Skip to content

Commit

Permalink
refactor(ui): move sidebar to component and set collapsed width to 50px
Browse files Browse the repository at this point in the history
  • Loading branch information
sfxcode committed Aug 4, 2024
1 parent 8a2f333 commit 5b5e03c
Show file tree
Hide file tree
Showing 11 changed files with 964 additions and 1,108 deletions.
9 changes: 9 additions & 0 deletions app/assets/sass/main.scss
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ html {
}

#workspace {
padding-left: 220px;
a {
text-decoration: none;
color: var(--p-primary-color);
Expand All @@ -20,6 +21,14 @@ html {
}
}

#workspace.collapsed {
padding-left: 50px;
}

#workspace.onmobile {
padding-left: 50px;
}

@media (min-width: 1024px) {
.top-navbar {
display: inline-flex !important;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@ const mode = useColorMode({
},
})
const { state, next } = useCycleList(['dark', 'light', 'auto'], { initialValue: mode })
const modes = ['dark', 'light', 'auto']
// const allModes = [...modes, 'cafe', 'contrast']
watchEffect(() => {
mode.value = state.value as any
})
const { state, next } = useCycleList(modes, { initialValue: mode })
watchEffect(() => mode.value = state.value)
</script>

<template>
Expand Down
79 changes: 79 additions & 0 deletions app/components/app/AppSidebar.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
<script setup lang='ts'>
const config = useRuntimeConfig()
const { menu } = useNavigationMenu()
const collapsed = useState<boolean>('collapsed')
const isOnMobile = useState<boolean>('isOnMobile')
function onResize() {
if (window.innerWidth <= 980) {
collapsed.value = true
isOnMobile.value = true
}
else {
collapsed.value = false
isOnMobile.value = false
}
}
function onToggleCollapse() {
}
function onItemClick() {
}
onMounted(() => {
onResize()
window.addEventListener('resize', onResize)
})
</script>

<template>
<div>
<sidebar-menu
v-model:collapsed="collapsed"
link-component-name="nuxt-sidebar-link"
:menu="menu"
:show-one-child="true"
width="220px"
width-collapsed="50px"
@update:collapsed="onToggleCollapse"
@item-click="onItemClick"
>
<template #header>
<div v-if="!collapsed" class="flex">
<img class="m-6 w-8" src="/primevue-logo.webp" alt="PrimeVue">
<img class="m-6 w-8" src="/nuxt-logo.svg" alt="Nuxt">
</div>
<div v-else>
<img class="ml-4 mt-6 w-6" src="/primevue-logo.webp" alt="PrimeVue">
<img class="ml-4 mt-2 w-6" src="/nuxt-logo.svg" alt="Nuxt">
</div>
</template>
<template #footer>
<div class="m-2 text-center text-xs text-color-[var(--primary-color)]">
<span v-if="!collapsed">MongoCamp Admin {{ config.public.APP_VERSION }}</span>
<span v-if="collapsed">{{ config.public.APP_VERSION }}</span>
</div>
</template>
</sidebar-menu>
<div
v-if="isOnMobile && !collapsed"
class="sidebar-overlay"
@click="collapsed = true"
/>
</div>
</template>

<style lang="scss">
.sidebar-overlay {
position: fixed;
width: 100%;
height: 100%;
top: 0;
left: 0;
background-color: #000;
opacity: 0.5;
z-index: 900;
}
</style>
4 changes: 1 addition & 3 deletions app/components/app/AppTopbar.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
<script setup lang="ts">
import ColorMode from '~/components/app/ColorMode.vue'
function redirectToGithub() {
window.open('https://github.com/sfxcode/nuxt3-primevue-starter', '_blank')
}
Expand All @@ -12,7 +10,7 @@ function redirectToGithub() {
<template #start />

<template #end>
<ColorMode class="ml-6 mr-2" />
<AppColorMode class="ml-6 mr-2" />
<Button icon="pi pi-github" class="mr-2" @click="redirectToGithub" />
<Button icon="pi pi-sign-out" severity="danger" />
</template>
Expand Down
60 changes: 0 additions & 60 deletions app/composables/layout.ts

This file was deleted.

1 change: 0 additions & 1 deletion app/composables/navigation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ export function useNavigationMenu() {
title: 'Home',
icon: 'pi pi-fw pi-home',
},

{
component: markRaw(separator),
},
Expand Down
File renamed without changes.
85 changes: 3 additions & 82 deletions app/layouts/default.vue
Original file line number Diff line number Diff line change
@@ -1,99 +1,20 @@
<script setup lang='ts'>
const config = useRuntimeConfig()
const { menu } = useNavigationMenu()
const collapsed = useState<boolean>('collapsed')
const isOnMobile = useState<boolean>('isOnMobile')
function onResize() {
if (window.innerWidth <= 980) {
collapsed.value = true
isOnMobile.value = true
}
else {
collapsed.value = false
isOnMobile.value = false
}
}
function onToggleCollapse() {
}
function onItemClick() {
}
onMounted(() => {
onResize()
window.addEventListener('resize', onResize)
})
</script>

<template>
<div class="">
<sidebar-menu
v-model:collapsed="collapsed"
link-component-name="nuxt-sidebar-link"
:menu="menu"
:show-one-child="true"
width="220px"
@update:collapsed="onToggleCollapse"
@item-click="onItemClick"
>
<template #header>
<div v-if="!collapsed" class="flex">
<img class="m-6 w-8" src="/primevue-logo.webp" alt="PrimeVue">
<img class="m-6 w-8" src="/nuxt-logo.svg" alt="Nuxt">
</div>
<div v-else>
<img class="ml-5 mt-2 w-6" src="/primevue-logo.webp" alt="PrimeVue">
<img class="ml-5 mt-2 w-6" src="/nuxt-logo.svg" alt="Nuxt">
</div>
</template>
<template #footer>
<div class="m-2 ml-5 text-color-[var(--p-primary-color)]">
<span v-if="!collapsed">Version {{ config.public.APP_VERSION }}</span>
<span v-if="collapsed">{{ config.public.APP_VERSION }}</span>
</div>
</template>
</sidebar-menu>
<div
v-if="isOnMobile && !collapsed"
class="sidebar-overlay"
@click="collapsed = true"
/>
<div id="workspace" :class="[{ collapsed }, { onmobile: isOnMobile }]">
<AppSidebar />
<div id="workspace" :class="[{ collapsed }, { mobile: isOnMobile }]">
<AppTopbar />
<div class="mt-4">
<div class="m-4">
<slot />
</div>
</div>
</div>
</template>

<style lang="scss">
#workspace {
padding-left: 220px;
transition: 0.3s ease;
}
#workspace.collapsed {
padding-left: 65px;
}
#workspace.onmobile {
padding-left: 65px;
}
.sidebar-overlay {
position: fixed;
width: 100%;
height: 100%;
top: 0;
left: 0;
background-color: #000;
opacity: 0.5;
z-index: 900;
}
</style>
4 changes: 3 additions & 1 deletion nuxt3-primevue-starter.iml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
<module type="WEB_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$" />
<content url="file://$MODULE_DIR$">
<excludeFolder url="file://$MODULE_DIR$/.output" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
Expand Down
24 changes: 12 additions & 12 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "nuxt3-primevue-starter",
"type": "module",
"version": "2.0.1",
"version": "2.0.2",
"license": "MIT",
"scripts": {
"build": "nuxi build",
Expand All @@ -19,7 +19,7 @@
"postinstall": "nuxt prepare"
},
"devDependencies": {
"@antfu/eslint-config": "2.23.2",
"@antfu/eslint-config": "2.24.1",
"@formkit/nuxt": "1.6.5",
"@iconify-json/carbon": "^1.1.36",
"@iconify-json/mdi": "^1.1.67",
Expand All @@ -30,32 +30,32 @@
"@nuxt/fonts": "^0.7.1",
"@nuxt/image": "^1.7.0",
"@nuxt/test-utils": "^3.14.0",
"@nuxtjs/i18n": "8.3.2",
"@nuxtjs/i18n": "8.3.3",
"@pinia/nuxt": "^0.5.2",
"@primevue/nuxt-module": "4.0.2",
"@primevue/themes": "4.0.2",
"@sfxcode/formkit-primevue": "^2.4.1",
"@primevue/nuxt-module": "4.0.4",
"@primevue/themes": "4.0.4",
"@sfxcode/formkit-primevue": "^2.4.3",
"@tiptap/extension-highlight": "^2.5.8",
"@tiptap/extension-text-align": "^2.5.8",
"@tiptap/extension-text-style": "^2.5.8",
"@tiptap/pm": "^2.5.8",
"@tiptap/starter-kit": "^2.5.8",
"@tiptap/vue-3": "^2.5.8",
"@unocss/nuxt": "^0.61.8",
"@vitest/ui": "^2.0.4",
"@unocss/nuxt": "^0.61.9",
"@vitest/ui": "^2.0.5",
"@vue/test-utils": "^2.4.6",
"@vueuse/nuxt": "^10.11.0",
"c8": "^10.1.2",
"eslint": "^9.8.0",
"happy-dom": "^14.12.3",
"jsdom": "^24.1.1",
"nuxt": "^3.12.4",
"primevue": "^4.0.3",
"sass": "1.76.0",
"primevue": "^4.0.4",
"sass": "1.77.8",
"typescript": "^5.5.4",
"unstorage": "^1.10.2",
"vitest": "^2.0.4",
"vue-sidebar-menu": "^5.4.0"
"vitest": "^2.0.5",
"vue-sidebar-menu": "^5.4.1"
},
"packageManager": "pnpm@9.4.0+sha256.b6fd0bfda555e7e584ad7e56b30c68b01d5a04f9ee93989f4b93ca8473c49c74"
}
Loading

0 comments on commit 5b5e03c

Please sign in to comment.