Files
it-tools/src/components/MenuLayout.vue
T
Dark_Phoenix_andsharevb aabbfca763 Additions for responsive sidebar pull request (#131)
* - Made the sidebar responsive
- Edited the hero-gradient svg to fix an issue where it would never scale to the full width of the sidebar
- Fixed a bug on Chrome where you'd need to click twice on a category element in the sidebar to see its tools

* - Added hover effect for category button
- Disabled transition built into the n-menu element to display the hover effect for tools items directly instead of after a slight delay

* - Added a tooltip which shows when the title of the tool is truncated

* - Increased sidebar width from 10% to 12.5%
- Changed check truncation calculation for container width to a more accurate variant to fix a bug where a tooltip was shown without the text being truncated

* fixed merge conflicts

* Fixed merge conflict in pnpm lock file

* Another fix for merge conflixt pnpm lock file

---------

Co-authored-by: sharevb <sharevb@gmail.com>
2025-07-20 21:01:17 +02:00

81 lines
1.8 KiB
Vue

<script setup lang="ts">
import { useStyleStore } from '@/stores/style.store';
const styleStore = useStyleStore();
const { isMenuCollapsed, isSmallScreen } = toRefs(styleStore);
const siderPosition = computed(() => (isSmallScreen.value ? 'absolute' : 'static'));
// Reactive window width
const windowWidth = ref(window.innerWidth);
// Update window width on resize
function updateWindowWidth() {
windowWidth.value = window.innerWidth;
}
// Add resize listener
onMounted(() => {
window.addEventListener('resize', updateWindowWidth);
});
// Clean up listener
onUnmounted(() => {
window.removeEventListener('resize', updateWindowWidth);
});
// Calculate the actual width to ensure minimum width is respected
const siderWidth = computed(() => {
if (isMenuCollapsed.value) {
return 0;
}
// Use 12.5% of window width, but ensure it's at least 240px
const tenPercent = windowWidth.value * 0.125;
return Math.max(240, tenPercent);
});
</script>
<template>
<n-layout has-sider>
<n-layout-sider
bordered
collapse-mode="width"
:collapsed-width="0"
:width="siderWidth"
:collapsed="isMenuCollapsed"
:show-trigger="false"
:native-scrollbar="false"
:position="siderPosition"
>
<slot name="sider" />
</n-layout-sider>
<n-layout class="content">
<slot name="content" />
<div v-show="isSmallScreen && !isMenuCollapsed" class="overlay" @click="isMenuCollapsed = true" />
</n-layout>
</n-layout>
</template>
<style lang="less" scoped>
.overlay {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-color: #00000080;
cursor: pointer;
}
.content {
// background-color: #f1f5f9;
::v-deep(.n-layout-scroll-container) {
padding: 26px;
}
}
.n-layout {
height: 100vh;
}
</style>