deemix-webui/src/components/TheSidebar.vue

150 lines
3.3 KiB
Vue
Raw Normal View History

<template>
<aside
id="sidebar"
2021-01-31 21:35:29 +00:00
:class="{ 'slim-sidebar w-12': isSlim }"
:style="{ minWidth: isSlim ? null : '14rem' }"
aria-label="sidebar"
2021-01-31 19:44:55 +00:00
class="top-0 left-0 flex flex-col h-screen bg-panels-bg text-foreground"
role="navigation"
>
2021-01-31 19:44:55 +00:00
<div class="deemix-icon-container" v-html="deemixIcon" />
<router-link
v-for="link in links"
2020-11-10 23:11:24 +00:00
:key="link.name"
:aria-label="link.ariaLabel"
2021-01-31 19:44:55 +00:00
:class="{ 'bg-background-main': activeTablink === link.name }"
:to="{ name: link.routerName }"
2021-01-31 19:44:55 +00:00
class="relative flex items-center h-16 no-underline group main_tablinks hover:bg-background-main text-foreground"
tag="a"
@click.native="activeTablink = link.name"
>
<i
:class="{ 'text-primary': activeTablink === link.name }"
2021-01-31 19:44:55 +00:00
class="p-2 text-3xl material-icons side_icon group-hover:text-primary"
>
{{ link.icon }}
</i>
2020-11-10 23:11:24 +00:00
<span
:class="{ hidden: isSlim }"
2021-01-31 19:44:55 +00:00
class="ml-5 overflow-hidden capitalize whitespace-no-wrap main-tablinks-text"
2020-11-10 23:11:24 +00:00
style="letter-spacing: 1.3px"
>
{{ $t(link.label) }}
</span>
<span
v-if="link.name === 'about' && updateAvailable"
id="update-notification"
2020-11-10 23:11:24 +00:00
class="absolute w-3 h-3 bg-red-600 rounded-full"
></span>
</router-link>
2020-11-10 23:11:24 +00:00
<span
id="theme_selector"
2021-01-31 19:44:55 +00:00
:class="{ 'inline-grid gap-2': isSlim }"
aria-label="theme selector"
2020-11-10 23:11:24 +00:00
class="flex h-12 mt-5"
role="link"
>
<i class="p-2 text-3xl transition-all duration-500 cursor-default material-icons side_icon side_icon--theme">
brush
</i>
2020-11-10 23:11:24 +00:00
<div
id="theme_togglers"
:class="{ 'inline-grid gap-2': isSlim }"
2021-01-31 19:44:55 +00:00
class="relative flex items-center w-full justify-evenly"
2020-11-10 23:11:24 +00:00
>
<div
2020-11-10 23:11:24 +00:00
v-for="theme of THEMES"
:key="theme"
2020-11-10 23:11:24 +00:00
:class="[{ 'theme_toggler--active': currentTheme === theme }, `theme_toggler--${theme}`]"
2021-01-31 19:44:55 +00:00
class="w-6 h-6 border rounded-full cursor-pointer theme_toggler border-grayscale-500 gap"
2020-11-10 23:11:24 +00:00
@click="currentTheme = theme"
/>
</div>
</span>
</aside>
</template>
<style lang="scss" scoped>
2021-01-31 19:44:55 +00:00
.deemix-icon-container {
display: grid;
place-content: center;
2021-01-31 21:35:29 +00:00
.slim-sidebar & {
margin: 0.5rem 0;
&::v-deep svg {
height: 30px;
}
}
2021-01-31 19:44:55 +00:00
&::v-deep svg {
height: 75px;
}
}
#update-notification {
top: 12px;
2021-01-31 19:44:55 +00:00
left: 30px;
}
.theme_toggler {
transition: border 200ms ease-in-out;
&--active {
border-width: 3px;
}
&--light {
background-color: #fff;
}
&--dark {
background-color: hsl(0, 0%, 8%);
}
&--purple {
background: hsl(261, 85%, 37%);
}
}
</style>
<script>
2020-11-10 23:11:24 +00:00
import { computed, defineComponent, reactive, toRefs } from '@vue/composition-api'
import { links } from '@/data/sidebar'
import { useTheme } from '@/use/theme'
2021-03-12 19:42:32 +00:00
2021-01-31 19:44:55 +00:00
import deemixIcon from '@/assets/deemix-icon.svg'
2020-10-13 17:31:51 +00:00
2020-11-10 23:11:24 +00:00
export default defineComponent({
setup(props, ctx) {
const state = reactive({
activeTablink: 'home',
2020-11-10 23:11:24 +00:00
links
})
2020-11-10 23:11:24 +00:00
const { THEMES, currentTheme } = useTheme()
2020-10-13 17:31:51 +00:00
/* === Add update notification near info === */
2021-03-12 19:42:32 +00:00
const updateAvailable = computed(() => ctx.root.$store.state.appInfo.updateAvailable)
2020-11-10 23:11:24 +00:00
ctx.root.$router.afterEach((to, from) => {
const linkInSidebar = state.links.find(link => link.routerName === to.name)
2020-11-10 23:11:24 +00:00
if (!linkInSidebar) return
2020-11-10 23:11:24 +00:00
state.activeTablink = linkInSidebar.name
})
2020-11-10 23:11:24 +00:00
return {
...toRefs(state),
2021-03-12 19:42:32 +00:00
updateAvailable,
2020-11-10 23:11:24 +00:00
THEMES,
currentTheme,
2021-01-31 19:44:55 +00:00
isSlim: computed(() => ctx.root.$store.getters.getSlimSidebar),
deemixIcon
}
}
2020-11-10 23:11:24 +00:00
})
</script>