mirror of
https://github.com/sharevb/it-tools.git
synced 2026-11-20 21:23:08 +03:00
Made sidebar responsive (#130)
* - 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
This commit is contained in:
1 parent
7824f48383
commit
e811a5b654
7 files changed
+13356
-10449
No files matched your search
Vendored
+13
-8
@@ -196,17 +196,23 @@ declare module '@vue/runtime-core' {
|
||||
IcoConverter: typeof import('./src/tools/ico-converter/ico-converter.vue')['default']
|
||||
'IconMdi:brushVariant': typeof import('~icons/mdi/brush-variant')['default']
|
||||
'IconMdi:kettleSteamOutline': typeof import('~icons/mdi/kettle-steam-outline')['default']
|
||||
IconMdiArrowRightBottom: typeof import('~icons/mdi/arrow-right-bottom')['default']
|
||||
IconMdiCamera: typeof import('~icons/mdi/camera')['default']
|
||||
IconMdiChevronDown: typeof import('~icons/mdi/chevron-down')['default']
|
||||
IconMdiChevronRight: typeof import('~icons/mdi/chevron-right')['default']
|
||||
IconMdiClose: typeof import('~icons/mdi/close')['default']
|
||||
IconMdiContentCopy: typeof import('~icons/mdi/content-copy')['default']
|
||||
IconMdiDeleteOutline: typeof import('~icons/mdi/delete-outline')['default']
|
||||
IconMdiDownload: typeof import('~icons/mdi/download')['default']
|
||||
IconMdiEye: typeof import('~icons/mdi/eye')['default']
|
||||
IconMdiEyeOff: typeof import('~icons/mdi/eye-off')['default']
|
||||
IconMdiHeart: typeof import('~icons/mdi/heart')['default']
|
||||
IconMdiPause: typeof import('~icons/mdi/pause')['default']
|
||||
IconMdiPlay: typeof import('~icons/mdi/play')['default']
|
||||
IconMdiRecord: typeof import('~icons/mdi/record')['default']
|
||||
IconMdiSearch: typeof import('~icons/mdi/search')['default']
|
||||
IconMdiTranslate: typeof import('~icons/mdi/translate')['default']
|
||||
IconMdiTriangleDown: typeof import('~icons/mdi/triangle-down')['default']
|
||||
IconMdiVideo: typeof import('~icons/mdi/video')['default']
|
||||
IesLightingGuidelines: typeof import('./src/tools/ies-lighting-guidelines/ies-lighting-guidelines.vue')['default']
|
||||
IlluminanceConverter: typeof import('./src/tools/illuminance-converter/illuminance-converter.vue')['default']
|
||||
ImageConverter: typeof import('./src/tools/image-converter/image-converter.vue')['default']
|
||||
@@ -293,6 +299,8 @@ declare module '@vue/runtime-core' {
|
||||
MenuBar: typeof import('./src/tools/html-wysiwyg-editor/editor/menu-bar.vue')['default']
|
||||
MenuBarItem: typeof import('./src/tools/html-wysiwyg-editor/editor/menu-bar-item.vue')['default']
|
||||
MenuIconItem: typeof import('./src/components/MenuIconItem.vue')['default']
|
||||
MenuItemTooltip: typeof import('./src/components/MenuItemTooltip.vue')['default']
|
||||
MenuItemWithTooltip: typeof import('./src/components/MenuItemWithTooltip.vue')['default']
|
||||
MenuLayout: typeof import('./src/components/MenuLayout.vue')['default']
|
||||
MermaidExporter: typeof import('./src/tools/mermaid-exporter/mermaid-exporter.vue')['default']
|
||||
MetaTagGenerator: typeof import('./src/tools/meta-tag-generator/meta-tag-generator.vue')['default']
|
||||
@@ -304,7 +312,6 @@ declare module '@vue/runtime-core' {
|
||||
MorseConverter: typeof import('./src/tools/morse-converter/morse-converter.vue')['default']
|
||||
MultiLinkDownloader: typeof import('./src/tools/multi-link-downloader/multi-link-downloader.vue')['default']
|
||||
MyIp: typeof import('./src/tools/my-ip/my-ip.vue')['default']
|
||||
NA: typeof import('naive-ui')['NA']
|
||||
NanoidGenerator: typeof import('./src/tools/nanoid-generator/nanoid-generator.vue')['default']
|
||||
NanoMemo: typeof import('./src/tools/nano-memo/nano-memo.vue')['default']
|
||||
'NanoMemo.content': typeof import('./src/tools/nano-memo/nano-memo.content.md')['default']
|
||||
@@ -316,7 +323,6 @@ declare module '@vue/runtime-core' {
|
||||
NColorPicker: typeof import('naive-ui')['NColorPicker']
|
||||
NConfigProvider: typeof import('naive-ui')['NConfigProvider']
|
||||
NDivider: typeof import('naive-ui')['NDivider']
|
||||
NDynamicInput: typeof import('naive-ui')['NDynamicInput']
|
||||
NEllipsis: typeof import('naive-ui')['NEllipsis']
|
||||
NForm: typeof import('naive-ui')['NForm']
|
||||
NFormItem: typeof import('naive-ui')['NFormItem']
|
||||
@@ -328,20 +334,19 @@ declare module '@vue/runtime-core' {
|
||||
NH1: typeof import('naive-ui')['NH1']
|
||||
NH3: typeof import('naive-ui')['NH3']
|
||||
NIcon: typeof import('naive-ui')['NIcon']
|
||||
NImage: typeof import('naive-ui')['NImage']
|
||||
NInput: typeof import('naive-ui')['NInput']
|
||||
NInputNumber: typeof import('naive-ui')['NInputNumber']
|
||||
NLayout: typeof import('naive-ui')['NLayout']
|
||||
NLayoutSider: typeof import('naive-ui')['NLayoutSider']
|
||||
NMenu: typeof import('naive-ui')['NMenu']
|
||||
NRadio: typeof import('naive-ui')['NRadio']
|
||||
NRadioGroup: typeof import('naive-ui')['NRadioGroup']
|
||||
NScrollbar: typeof import('naive-ui')['NScrollbar']
|
||||
NSelect: typeof import('naive-ui')['NSelect']
|
||||
NSpace: typeof import('naive-ui')['NSpace']
|
||||
NSpin: typeof import('naive-ui')['NSpin']
|
||||
NStatistic: typeof import('naive-ui')['NStatistic']
|
||||
NSwitch: typeof import('naive-ui')['NSwitch']
|
||||
NTable: typeof import('naive-ui')['NTable']
|
||||
NTabPane: typeof import('naive-ui')['NTabPane']
|
||||
NTabs: typeof import('naive-ui')['NTabs']
|
||||
NTooltip: typeof import('naive-ui')['NTooltip']
|
||||
NumberInput: typeof import('./src/tools/pomodoro-timer/app/components/NumberInput.vue')['default']
|
||||
NumeronymGenerator: typeof import('./src/tools/numeronym-generator/numeronym-generator.vue')['default']
|
||||
OcrImage: typeof import('./src/tools/ocr-image/ocr-image.vue')['default']
|
||||
|
||||
Generated
+13165
-10416
File diff suppressed because it is too large.
Load diff
@@ -1,4 +1,4 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 300 275">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 300 275" preserveAspectRatio="none">
|
||||
<defs>
|
||||
<linearGradient id="small-hero-gradient-1" x1="13.74" y1="183.7" x2="303.96" y2="45.59" gradientUnits="userSpaceOnUse">
|
||||
<stop offset="0" stop-color="#25636c"/>
|
||||
|
||||
|
Before Width: | Height: | Size: 894 B After Width: | Height: | Size: 921 B |
@@ -1,15 +1,16 @@
|
||||
<script setup lang="ts">
|
||||
import { useStorage } from '@vueuse/core';
|
||||
import { useThemeVars } from 'naive-ui';
|
||||
import { RouterLink, useRoute } from 'vue-router';
|
||||
import { useRoute } from 'vue-router';
|
||||
import MenuIconItem from './MenuIconItem.vue';
|
||||
import MenuItemWithTooltip from './MenuItemTooltip.vue';
|
||||
import type { Tool, ToolCategory } from '@/tools/tools.types';
|
||||
|
||||
const props = withDefaults(defineProps<{ toolsByCategory?: ToolCategory[] }>(), { toolsByCategory: () => [] });
|
||||
const { toolsByCategory } = toRefs(props);
|
||||
const route = useRoute();
|
||||
|
||||
const makeLabel = (tool: Tool) => () => h(RouterLink, { to: tool.path }, { default: () => tool.name });
|
||||
const makeLabel = (tool: Tool) => () => h(MenuItemWithTooltip, { tool });
|
||||
const makeIcon = (tool: Tool) => () => h(MenuIconItem, { tool });
|
||||
|
||||
const collapsedCategories = useStorage<Record<string, boolean>>(
|
||||
@@ -25,14 +26,26 @@ const collapsedCategories = useStorage<Record<string, boolean>>(
|
||||
},
|
||||
);
|
||||
|
||||
// Initialize default values for all categories
|
||||
watchEffect(() => {
|
||||
toolsByCategory.value.forEach(({ name }) => {
|
||||
if (!(name in collapsedCategories.value)) {
|
||||
collapsedCategories.value[name] = true;
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
const isToggling = ref(false);
|
||||
|
||||
function toggleCategoryCollapse({ name }: { name: string }) {
|
||||
collapsedCategories.value[name] = !collapsedCategories.value[name];
|
||||
const currentState = collapsedCategories.value[name];
|
||||
collapsedCategories.value[name] = !currentState;
|
||||
}
|
||||
|
||||
const areAllCollapsed = computed(() => {
|
||||
return toolsByCategory.value.every(({ name }) => collapsedCategories.value[name] !== false);
|
||||
return toolsByCategory.value.every(({ name }) =>
|
||||
collapsedCategories.value[name] !== false,
|
||||
);
|
||||
});
|
||||
|
||||
async function toggleAllCategories() {
|
||||
@@ -63,15 +76,13 @@ function getAnimationDuration(itemCount: number): number {
|
||||
|
||||
const additionalDuration = (itemCount - baseItemCount) * durationIncrement;
|
||||
|
||||
// Ensure the duration doesn't go below the base duration
|
||||
// This means that only if the item count is higher than the base item count, each extra element will add `durationIncrement` milliseconds to the animation
|
||||
return Math.max(baseDuration + additionalDuration, baseDuration);
|
||||
}
|
||||
|
||||
const menuOptions = computed(() =>
|
||||
toolsByCategory.value.map(({ name, components }) => ({
|
||||
name,
|
||||
isCollapsed: collapsedCategories.value[name] === undefined ? true : collapsedCategories.value[name],
|
||||
isCollapsed: collapsedCategories.value[name],
|
||||
animationDuration: getAnimationDuration(components.length),
|
||||
tools: components.map(tool => ({
|
||||
label: makeLabel(tool),
|
||||
@@ -85,7 +96,7 @@ const themeVars = useThemeVars();
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="top-controls" ml-6px>
|
||||
<div class="top-controls" mb-12px ml-12px>
|
||||
<c-button :disabled="isToggling" @click="toggleAllCategories">
|
||||
<span v-if="isToggling">
|
||||
{{ areAllCollapsed ? 'Expanding...' : 'Collapsing...' }}
|
||||
@@ -97,7 +108,11 @@ const themeVars = useThemeVars();
|
||||
</div>
|
||||
|
||||
<div v-for="{ name, tools, isCollapsed, animationDuration } of menuOptions" :key="name" class="category-container">
|
||||
<div ml-6px mt-12px flex cursor-pointer items-center op-60 @click="toggleCategoryCollapse({ name })">
|
||||
<button
|
||||
class="category-button"
|
||||
flex cursor-pointer items-center op-60
|
||||
@click="toggleCategoryCollapse({ name })"
|
||||
>
|
||||
<span :class="{ 'rotate-0': isCollapsed, 'rotate-90': !isCollapsed }" text-16px lh-1 op-50 transition-transform>
|
||||
<icon-mdi-chevron-right />
|
||||
</span>
|
||||
@@ -105,7 +120,7 @@ const themeVars = useThemeVars();
|
||||
<span ml-8px text-13px>
|
||||
{{ name }}
|
||||
</span>
|
||||
</div>
|
||||
</button>
|
||||
|
||||
<div
|
||||
class="menu-container"
|
||||
@@ -130,6 +145,20 @@ const themeVars = useThemeVars();
|
||||
</template>
|
||||
|
||||
<style scoped lang="less">
|
||||
.category-button {
|
||||
border: none;
|
||||
background: transparent;
|
||||
padding: 6px;
|
||||
width: 100%;
|
||||
color: v-bind('themeVars.textColor1');
|
||||
text-align: left;
|
||||
user-select: none;
|
||||
|
||||
&:hover {
|
||||
background-color: v-bind('themeVars.buttonColor2Hover');
|
||||
opacity: 0.8;
|
||||
}
|
||||
}
|
||||
.category-container {
|
||||
.menu-container {
|
||||
display: grid;
|
||||
@@ -152,6 +181,7 @@ const themeVars = useThemeVars();
|
||||
::v-deep(.n-menu-item-content::before) {
|
||||
left: 0;
|
||||
right: 13px;
|
||||
transition: none !important; // Disables hover transition effect to instantly show hover state
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,90 @@
|
||||
<script setup lang="ts">
|
||||
import { RouterLink } from 'vue-router';
|
||||
import { nextTick, onMounted, onUnmounted, ref } from 'vue';
|
||||
import type { Tool } from '@/tools/tools.types';
|
||||
|
||||
defineProps<{
|
||||
tool: Tool
|
||||
}>();
|
||||
|
||||
const textRef = ref<HTMLElement>();
|
||||
const showTooltip = ref(false);
|
||||
let resizeTimeout: ReturnType<typeof setTimeout> | null = null;
|
||||
|
||||
async function checkTruncation() {
|
||||
await nextTick();
|
||||
if (textRef.value) {
|
||||
const text = textRef.value.textContent || '';
|
||||
const computedStyle = window.getComputedStyle(textRef.value);
|
||||
|
||||
// Create canvas context for precise text measurement
|
||||
const canvas = document.createElement('canvas');
|
||||
const context = canvas.getContext('2d')!;
|
||||
context.font = `${computedStyle.fontWeight} ${computedStyle.fontSize} ${computedStyle.fontFamily}`;
|
||||
|
||||
const textWidth = context.measureText(text).width;
|
||||
const containerWidth = textRef.value.clientWidth;
|
||||
|
||||
showTooltip.value = textWidth > containerWidth;
|
||||
}
|
||||
}
|
||||
|
||||
function debouncedCheckTruncation() {
|
||||
if (resizeTimeout) {
|
||||
clearTimeout(resizeTimeout);
|
||||
}
|
||||
// Prevent the truncation check from running too frequently when the window is resized
|
||||
resizeTimeout = setTimeout(checkTruncation, 500);
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
checkTruncation();
|
||||
window.addEventListener('resize', debouncedCheckTruncation);
|
||||
});
|
||||
|
||||
onUnmounted(() => {
|
||||
if (resizeTimeout) {
|
||||
clearTimeout(resizeTimeout);
|
||||
}
|
||||
window.removeEventListener('resize', debouncedCheckTruncation);
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<n-tooltip
|
||||
placement="right"
|
||||
:delay="500"
|
||||
:show-arrow="true"
|
||||
:disabled="!showTooltip"
|
||||
>
|
||||
<template #trigger>
|
||||
<RouterLink :to="tool.path" class="menu-link">
|
||||
<span
|
||||
ref="textRef"
|
||||
class="menu-text"
|
||||
@mouseenter="checkTruncation"
|
||||
>
|
||||
{{ tool.name }}
|
||||
</span>
|
||||
</RouterLink>
|
||||
</template>
|
||||
{{ tool.name }}
|
||||
</n-tooltip>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.menu-link {
|
||||
display: block;
|
||||
width: 100%;
|
||||
text-decoration: none;
|
||||
color: inherit;
|
||||
}
|
||||
|
||||
.menu-text {
|
||||
display: block;
|
||||
width: 100%;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
</style>
|
||||
@@ -4,6 +4,35 @@ 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;
|
||||
}
|
||||
|
||||
// Get 10% of window width, but ensure it's at least 240px
|
||||
const tenPercent = windowWidth.value * 0.1;
|
||||
return Math.max(240, tenPercent);
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
@@ -12,7 +41,7 @@ const siderPosition = computed(() => (isSmallScreen.value ? 'absolute' : 'static
|
||||
bordered
|
||||
collapse-mode="width"
|
||||
:collapsed-width="0"
|
||||
:width="240"
|
||||
:width="siderWidth"
|
||||
:collapsed="isMenuCollapsed"
|
||||
:show-trigger="false"
|
||||
:native-scrollbar="false"
|
||||
|
||||
+17
-13
@@ -1,18 +1,16 @@
|
||||
<script lang="ts" setup>
|
||||
import { NIcon, useThemeVars } from 'naive-ui';
|
||||
|
||||
import { RouterLink } from 'vue-router';
|
||||
import { Home2, Menu2 } from '@vicons/tabler';
|
||||
|
||||
import { NIcon, useThemeVars } from 'naive-ui';
|
||||
import { storeToRefs } from 'pinia';
|
||||
import { RouterLink } from 'vue-router';
|
||||
import HeroGradient from '../assets/hero-gradient.svg?component';
|
||||
import MenuLayout from '../components/MenuLayout.vue';
|
||||
import NavbarButtons from '../components/NavbarButtons.vue';
|
||||
import { useStyleStore } from '@/stores/style.store';
|
||||
import { config } from '@/config';
|
||||
import type { ToolCategory } from '@/tools/tools.types';
|
||||
import { useToolStore } from '@/tools/tools.store';
|
||||
import CollapsibleToolMenu from '@/components/CollapsibleToolMenu.vue';
|
||||
import { config } from '@/config';
|
||||
import { useStyleStore } from '@/stores/style.store';
|
||||
import { useToolStore } from '@/tools/tools.store';
|
||||
import type { ToolCategory } from '@/tools/tools.types';
|
||||
|
||||
const themeVars = useThemeVars();
|
||||
const styleStore = useStyleStore();
|
||||
@@ -156,20 +154,26 @@ const tools = computed<ToolCategory[]>(() => [
|
||||
}
|
||||
|
||||
.sider-content {
|
||||
padding-top: 160px;
|
||||
padding-top: 20px;
|
||||
padding-bottom: 200px;
|
||||
}
|
||||
|
||||
.hero-wrapper {
|
||||
position: absolute;
|
||||
display: block;
|
||||
position: sticky;
|
||||
display: flex;
|
||||
left: 0;
|
||||
width: 100%;
|
||||
z-index: 10;
|
||||
height: 150px;
|
||||
overflow: hidden;
|
||||
position: relative;
|
||||
|
||||
.gradient {
|
||||
margin-top: -65px;
|
||||
position: absolute;
|
||||
top: 0;
|
||||
left: 0;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
display: block;
|
||||
}
|
||||
|
||||
.text-wrapper {
|
||||
|
||||
Reference in new issue
Block a user