Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added sidebar stickiness, icon clicking #155

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions src/lib/Icon.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,22 @@
export let icon;
export let info;
export let activity;

import { createEventDispatcher } from 'svelte';
const dispatch = createEventDispatcher();

const dispatch = createEventDispatcher();
function handleMouseover() {
dispatch('mouseover', info);
}
function handleClick() {
dispatch('click', { icon, info });
}
</script>

<div
class="p-3 cursor-pointer text-center hover:bg-neutral-600 {$activity ? "text-amber-500 animate-pulse" : "hover:text-gray-100"}"
style="animation-duration: 0.5s"
on:mouseenter={handleMouseover}
>
<i class='{icon} fa-xl'></i>
on:click={handleClick}
>
<i class='{icon} fa-xl'></i>
</div>
59 changes: 48 additions & 11 deletions src/lib/SideBar.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@
import PostsTab from './PostsTab.svelte';
import DiscordTab from './DiscordTab.svelte';
import GitHubTab from './GitHubTab.svelte';
import { cpuActivity, diskActivity, aiActivity } from './activities.js'

import { cpuActivity, diskActivity, aiActivity } from './activities.js';
const icons = [
{ icon: 'fas fa-info-circle', info: 'Information', activity: null },
{ icon: 'fas fa-wifi', info: 'Networking', activity: null },
Expand All @@ -21,15 +20,46 @@
{ icon: 'fab fa-discord', info: 'Discord', activity: null },
{ icon: 'fab fa-github', info: 'GitHub', activity: null },
];

let activeInfo = null;

let activeInfo = null; // Tracks currently visible info
let lastHoveredInfo = null; // Tracks last hovered info
let isPanelHovered = false; // Tracks if info panel is hovered
let hideTimeout = 0; // Timeout for hiding info panel
function showInfo(info) {
activeInfo = info;
if (hideTimeout) {
hideTimeout = 0;
}
if (info !== lastHoveredInfo) {
activeInfo = info;
lastHoveredInfo = info;
}
}

function hideInfo() {
activeInfo = null;
if (!hideTimeout) {
hideTimeout = setTimeout(() => {
if (!isPanelHovered) {
activeInfo = null;
lastHoveredInfo = null;
}
hideTimeout = 0;
}, 400);
}
}
function handleMouseOverPanel() {
isPanelHovered = true;
if (hideTimeout) {
hideTimeout = 0;
}
}
function handleMouseLeavePanel() {
isPanelHovered = false;
hideInfo();
}
function handleClick(icon) {
if (activeInfo === icon.info) {
activeInfo = null;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you clarify if the indented UX here is to close a panel by clicking on it even if hovering?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The intention with this is that when we hover over the panel/icon and click on a icon, the panel closes. The reason behind this was to be able to immediately go to the command line instead of moving the mouse from the panel and waiting that small moment to wait for timeout to be over before you're able to see/type. It felt move efficient. Please let me know if you want to keep it or be changed

} else {
activeInfo = icon.info;
}
}

export let handleTool;
Expand All @@ -44,13 +74,19 @@
info={i.info}
activity={i.activity}
on:mouseover={(e) => showInfo(e.detail)}
on:click={() => handleClick(i)}
/>
{:else}
<div class="grow" on:mouseover={(e) => showInfo(null)}></div>
<div class="grow pointer-events-none"></div>
{/if}
{/each}
</div>
<div class="flex flex-col gap-5 shrink-0 w-80 h-full z-10 p-2 bg-neutral-600 text-gray-100 opacity-95" class:hidden={!activeInfo}>
<div
class="flex flex-col gap-5 shrink-0 w-80 h-full z-10 p-2 bg-neutral-600 text-gray-100 opacity-95"
class:hidden={!activeInfo}
on:mouseover={handleMouseOverPanel}
on:mouseleave={handleMouseLeavePanel}
>
{#if activeInfo === 'Information'}
<InformationTab>
<slot></slot>
Expand All @@ -72,6 +108,7 @@
{:else}
<p>TODO: {activeInfo}</p>
{/if}

<div class="mt-auto text-sm text-gray-300">
<div class="pt-1 pb-1">
<a href="https://cheerpx.io/" target="_blank">
Expand All @@ -81,7 +118,7 @@
</div>
<hr class="border-t border-solid border-gray-300">
<div class="pt-1 pb-1">
<a href="https://leaningtech.com/" target="”_blank”">© 2022-2024 Leaning Technologies</a>
<a href="https://leaningtech.com/" target="”_blank”">© 2022-2025 Leaning Technologies</a>
</div>
</div>
</div>
Expand Down