Skip to content

Commit

Permalink
#139 update project dropdown accessable from keyboard
Browse files Browse the repository at this point in the history
  • Loading branch information
Kreezag committed Jul 28, 2024
1 parent 03736b2 commit 673d317
Showing 1 changed file with 59 additions and 46 deletions.
105 changes: 59 additions & 46 deletions src/widgets/ui/layout-sidebar/layout-sidebar.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<script lang="ts" setup>
import { useFloating } from "@floating-ui/vue";
import { onClickOutside } from "@vueuse/core";
import { storeToRefs } from "pinia";
import { computed, ref } from "vue";
import { useRoute, useRouter } from "#app"; // eslint-disable-line @conarti/feature-sliced/layers-slices
Expand All @@ -26,10 +27,21 @@ const { profile } = storeToRefs(profileStore);
const { getItemsCount } = useEvents();
const projectDd = ref(null);
const projectMenu = ref(null);
const userDd = ref(null);
const userMenu = ref(null);
const projectDd = ref<HTMLElement | null>(null);
const projectMenu = ref<HTMLElement | null>(null);
const userDd = ref<HTMLElement | null>(null);
const userMenu = ref<HTMLElement | null>(null);
const isVisibleProfile = ref(false);
const isVisibleProjects = ref(false);
onClickOutside(projectMenu, () => {
isVisibleProjects.value = false;
});
onClickOutside(userMenu, () => {
isVisibleProfile.value = false;
});
const { floatingStyles: projectDdStyles } = useFloating(
projectDd,
Expand Down Expand Up @@ -73,9 +85,6 @@ const connectionText = computed(
() => `WS connection is ${connectionStatus.value}`,
);
const isVisibleProfile = ref(false);
const isVisibleProjects = ref(false);
const toggleProfileDropdown = () => {
isVisibleProfile.value = !isVisibleProfile.value;
};
Expand Down Expand Up @@ -127,39 +136,12 @@ const generateRadialGradient = (input: string) =>

<template>
<aside class="layout-sidebar">
<div
v-if="isVisibleProjects"
ref="projectMenu"
class="layout-sidebar__dropdown-items"
:style="projectDdStyles"
>
<div
v-for="project in availableProjects"
:key="project.key"
class="layout-sidebar__dropdown-item"
:title="project.name"
:class="{
'layout-sidebar__dropdown-item--active':
activeProject.key === project.key,
}"
@click="setProject(project.key)"
>
<h1
class="layout-sidebar__project"
:style="{ background: generateRadialGradient(project.name) }"
>
{{ makeShortTitle(project.name) }}
</h1>

{{ project.name }}
</div>
</div>

<nav class="layout-sidebar__nav">
<NuxtLink
to="/"
title="Dashboard"
class="layout-sidebar__link layout-sidebar__link--logo"
tabindex="1"
>
<IconSvg class="layout-sidebar__link-icon" name="logo-short" />
</NuxtLink>
Expand All @@ -168,27 +150,28 @@ const generateRadialGradient = (input: string) =>
<hr class="layout-sidebar__sep" />

<div class="layout-sidebar__projects">
<div
<button
ref="projectDd"
class="layout-sidebar__dropdown"
tabindex="1"
@click="toggleProjects"
>
<div
<span
:title="activeProject.name"
class="layout-sidebar__project"
:style="{
background: generateRadialGradient(activeProject.name),
}"
>
<h1>{{ makeShortTitle(activeProject.name) }}</h1>
</div>
</div>
{{ makeShortTitle(activeProject.name) }}
</span>
</button>
</div>

<hr class="layout-sidebar__sep" />
</template>

<template v-else>
<template v-if="!availableProjects.length">
<NuxtLink to="/" title="Events" class="layout-sidebar__link">
<IconSvg class="layout-sidebar__link-icon" name="events" />
</NuxtLink>
Expand Down Expand Up @@ -221,6 +204,36 @@ const generateRadialGradient = (input: string) =>
</NuxtLink>
</nav>

<!-- Need to place projectMenu out of nav because of overflow -->
<div
v-if="isVisibleProjects"
ref="projectMenu"
class="layout-sidebar__dropdown-items"
:style="projectDdStyles"
>
<button
v-for="project in availableProjects"
:key="project.key"
class="layout-sidebar__dropdown-item"
:title="project.name"
:class="{
'layout-sidebar__dropdown-item--active':
activeProject.key === project.key,
}"
tabindex="1"
@click="setProject(project.key)"
>
<span
class="layout-sidebar__project"
:style="{ background: generateRadialGradient(project.name) }"
>
{{ makeShortTitle(project.name) }}
</span>

{{ project.name }}
</button>
</div>

<div>
<div v-if="isAuthEnabled" ref="userDd" class="layout-sidebar__dropdown">
<div
Expand All @@ -229,19 +242,19 @@ const generateRadialGradient = (input: string) =>
class="layout-sidebar__dropdown-items"
:style="userDdStyles"
>
<div
<button
v-if="profileEmail"
class="layout-sidebar__dropdown-item layout-sidebar__dropdown-item--active"
>
{{ profileEmail }}
</div>
<div
</button>
<button
class="layout-sidebar__dropdown-item layout-sidebar__dropdown-item--active"
@click="logout"
>
<IconSvg class="layout-sidebar__dropdown-item-icon" name="logout" />
Logout
</div>
</button>
</div>

<div
Expand Down Expand Up @@ -364,7 +377,7 @@ const generateRadialGradient = (input: string) =>
@apply cursor-pointer;
@apply bg-white dark:bg-gray-800;
@apply hover:bg-gray-200 dark:hover:bg-gray-600;
@apply flex gap-4 items-center;
@apply flex gap-4 items-center text-left w-full;
&:first-child {
@apply rounded-t-lg;
Expand Down

0 comments on commit 673d317

Please sign in to comment.