it-tools/src/layouts/base.layout.vue

150 lines
4 KiB
Vue
Raw Normal View History

2022-04-04 00:24:45 +02:00
<script lang="ts" setup>
import { NIcon } from 'naive-ui';
import { h, ref, type Component } from 'vue';
import { RouterLink, useRoute } from 'vue-router';
2022-04-04 01:52:59 +02:00
import { LightModeFilled, DarkModeFilled } from '@vicons/material'
2022-04-14 22:41:51 +02:00
import { Heart } from '@vicons/tabler'
2022-04-06 00:49:56 +02:00
import { toolsByCategory } from '@/tools';
2022-04-04 01:03:06 +02:00
import SearchBar from '../components/SearchBar.vue';
2022-04-04 01:52:59 +02:00
import { useStyleStore } from '@/stores/style.store';
2022-04-14 22:41:51 +02:00
import HeroGradient from '../assets/hero-gradient.svg?component'
import { useThemeVars } from 'naive-ui'
2022-04-04 00:24:45 +02:00
2022-04-14 22:41:51 +02:00
const themeVars = useThemeVars()
2022-04-04 00:24:45 +02:00
const collapsed = ref(false)
const activeKey = ref(null)
const route = useRoute()
2022-04-04 01:52:59 +02:00
const styleStore = useStyleStore()
2022-04-04 00:24:45 +02:00
const makeLabel = (text: string, to: string) => () => h(RouterLink, { to }, { default: () => text })
const makeIcon = (icon: Component) => () => h(NIcon, null, { default: () => h(icon) })
2022-04-06 00:49:56 +02:00
const m = toolsByCategory.map(category => ({
label: category.name,
key: category.name,
type: 'group',
children: category.components.map(({ name, path, icon }) => ({
label: makeLabel(name, path),
2022-04-07 22:14:18 +02:00
icon: makeIcon(icon),
key: name
2022-04-06 00:49:56 +02:00
}))
2022-04-04 00:24:45 +02:00
}))
2022-04-06 00:49:56 +02:00
2022-03-31 00:33:29 +02:00
</script>
<template>
2022-04-04 00:24:45 +02:00
<n-layout has-sider>
2022-04-14 18:45:47 +02:00
<n-layout-sider bordered collapse-mode="width" :collapsed-width="64" :width="260" :collapsed="collapsed"
@collapse="collapsed = true" @expand="collapsed = false" :show-trigger="false">
<n-scrollbar>
2022-04-14 22:41:51 +02:00
<router-link to="/" class="hero-wrapper">
<hero-gradient class="gradient" />
<div class="text-wrapper">
<div class="title">IT - TOOLS</div>
<div class="divider" />
<div class="subtitle">Handy tools for developers</div>
</div>
2022-04-14 18:45:47 +02:00
</router-link>
2022-04-04 00:24:45 +02:00
2022-04-14 18:45:47 +02:00
<n-menu :value="route.name" class="menu" :collapsed="collapsed" :collapsed-width="64"
:collapsed-icon-size="22" :options="m" v-model:value="activeKey" />
2022-04-14 22:41:51 +02:00
2022-04-14 18:45:47 +02:00
</n-scrollbar>
2022-04-04 00:24:45 +02:00
</n-layout-sider>
<n-layout class="content">
<div class="bar-wrapper">
2022-04-04 01:03:06 +02:00
<search-bar />
2022-04-14 22:41:51 +02:00
<n-button type="primary" tag="a" href="https://github.com/sponsors/CorentinTh" rel="noopener"
target="_blank">
<n-icon :component="Heart" />&nbsp;
Sponsor
</n-button>
2022-04-14 18:45:47 +02:00
<n-button circle quaternary @click="styleStore.isDarkTheme = !styleStore.isDarkTheme">
2022-04-04 01:52:59 +02:00
<n-icon size="large" v-if="styleStore.isDarkTheme">
<LightModeFilled />
</n-icon>
<n-icon size="large" v-else>
<DarkModeFilled />
2022-04-04 00:24:45 +02:00
</n-icon>
</n-button>
</div>
<slot />
</n-layout>
</n-layout>
2022-03-31 00:33:29 +02:00
</template>
<style lang="less" scoped>
2022-04-14 22:41:51 +02:00
.n-menu {
padding-top: 160px;
padding-bottom: 200px;
}
.hero-wrapper {
position: absolute;
display: block;
position: absolute;
left: 0;
width: 100%;
z-index: 10;
.gradient {
margin-top: -80px;
}
.text-wrapper {
position: absolute;
left: 0;
width: 100%;
text-align: center;
top: 16px;
color: #fff;
.title {
font-size: 25px;
font-weight: 600;
}
.divider {
width: 50px;
height: 2px;
border-radius: 4px;
background-color: v-bind('themeVars.primaryColor');
margin: 0 auto 5px;
}
.subtitle {
font-size: 16px;
}
}
}
2022-04-04 00:24:45 +02:00
.bar-wrapper {
display: flex;
2022-04-14 22:41:51 +02:00
align-items: center;
justify-content: center;
2022-04-14 18:45:47 +02:00
&>*:not(:first-child) {
2022-04-04 00:24:45 +02:00
margin-left: 15px;
}
2022-04-14 18:45:47 +02:00
2022-04-14 22:41:51 +02:00
.search-bar {
2022-04-04 00:24:45 +02:00
flex-grow: 1;
}
}
.content {
2022-04-14 18:45:47 +02:00
2022-04-04 01:52:59 +02:00
// background-color: #f1f5f9;
2022-04-04 00:24:45 +02:00
::v-deep(.n-layout-scroll-container) {
padding: 26px;
}
}
2022-04-14 18:45:47 +02:00
2022-04-04 00:24:45 +02:00
.n-layout {
height: 100vh;
2022-03-31 00:33:29 +02:00
}
</style>