Skip to content

armgit / jan

Public Imported from GitHub
0

Jan is an open source alternative to ChatGPT that runs 100% offline on your computer.

feat(cowork-ui): animate navigation icons

thinhlpg297e9ba7b27b
diff --git a/web-app/src/components/left-sidebar/NavCowork.tsx b/web-app/src/components/left-sidebar/NavCowork.tsx
index 1ad8d3478..aa4468684 100644
--- a/web-app/src/components/left-sidebar/NavCowork.tsx
+++ b/web-app/src/components/left-sidebar/NavCowork.tsx
@@ -43,6 +43,11 @@ import {
SettingsIcon,
type SettingsIconHandle,
} from '@/components/animated-icon/settings'
+import {
+ AnimatedLucideIcon,
+ type AnimatedLucideIconHandle,
+ type AnimatedLucidePreset,
+} from '@/components/animated-icon/animated-lucide'
import {
startNewSession,
useCoworkSessions,
@@ -55,6 +60,7 @@ import SkillsManagerDialog from '@/containers/dialogs/SkillsManagerDialog'
type CoworkNavItem = {
title: string
icon: LucideIcon
+ preset: AnimatedLucidePreset
onClick: () => void
}
@@ -128,6 +134,31 @@ const SessionItem = memo(function SessionItem({
)
})
+function CoworkNavItemRow({ item }: { item: CoworkNavItem }) {
+ const iconRef = useRef<AnimatedLucideIconHandle>(null)
+
+ return (
+ <SidebarMenuItem>
+ <SidebarMenuButton
+ onBlur={() => iconRef.current?.stopAnimation()}
+ onClick={item.onClick}
+ onFocus={() => iconRef.current?.startAnimation()}
+ onMouseEnter={() => iconRef.current?.startAnimation()}
+ onMouseLeave={() => iconRef.current?.stopAnimation()}
+ >
+ <AnimatedLucideIcon
+ ref={iconRef}
+ icon={item.icon}
+ preset={item.preset}
+ className="text-foreground/70"
+ size={16}
+ />
+ <span>{item.title}</span>
+ </SidebarMenuButton>
+ </SidebarMenuItem>
+ )
+}
+
export function NavCowork() {
const { t } = useTranslation()
const navigate = useNavigate()
@@ -170,11 +201,13 @@ export function NavCowork() {
{
title: t('common:artifacts'),
icon: Box,
+ preset: 'box',
onClick: () => navigate({ to: route.artifacts }),
},
{
title: t('common:customize'),
icon: SlidersHorizontal,
+ preset: 'sliders',
onClick: () => setSkillsOpen(true),
},
]
@@ -209,17 +242,9 @@ export function NavCowork() {
<span>{t('common:newSession')}</span>
</SidebarMenuButton>
</SidebarMenuItem>
- {items.map((item) => {
- const Icon = item.icon
- return (
- <SidebarMenuItem key={item.title}>
- <SidebarMenuButton onClick={item.onClick}>
- <Icon className="text-foreground/70" size={16} />
- <span>{item.title}</span>
- </SidebarMenuButton>
- </SidebarMenuItem>
- )
- })}
+ {items.map((item) => (
+ <CoworkNavItemRow key={item.title} item={item} />
+ ))}
<SidebarMenuItem>
<SidebarMenuButton
onClick={() => navigate({ to: route.settings.general })}
diff --git a/web-app/src/components/left-sidebar/NavTabs.tsx b/web-app/src/components/left-sidebar/NavTabs.tsx
index e586b3eb0..6bdf22977 100644
--- a/web-app/src/components/left-sidebar/NavTabs.tsx
+++ b/web-app/src/components/left-sidebar/NavTabs.tsx
@@ -1,15 +1,22 @@
+import { useRef } from 'react'
import { Link, useLocation } from '@tanstack/react-router'
-import { Handshake, HomeIcon } from 'lucide-react'
+import { Handshake, HomeIcon, type LucideIcon } from 'lucide-react'
import { route, isCoworkRoute } from '@/constants/routes'
import { cn } from '@/lib/utils'
import { useTranslation } from '@/i18n/react-i18next-compat'
import { startNewSession } from '@/hooks/useCoworkSessions'
import { useCoworkRun } from '@/hooks/useCoworkRun'
+import {
+ AnimatedLucideIcon,
+ type AnimatedLucideIconHandle,
+ type AnimatedLucidePreset,
+} from '@/components/animated-icon/animated-lucide'
type TabItem = {
label: string
to: string
- icon: typeof HomeIcon
+ icon: LucideIcon
+ preset: AnimatedLucidePreset
isActive: boolean
onClick?: () => void
}
@@ -19,6 +26,36 @@ type TabItem = {
const openCoworkStart = () =>
startNewSession(Object.keys(useCoworkRun.getState().runId))
+function NavTab({ tab }: { tab: TabItem }) {
+ const iconRef = useRef<AnimatedLucideIconHandle>(null)
+
+ return (
+ <Link
+ to={tab.to}
+ onClick={tab.onClick}
+ aria-current={tab.isActive ? 'page' : undefined}
+ className={cn(
+ 'flex flex-1 items-center justify-center gap-1.5 rounded-md px-2 py-1 text-sm font-medium transition-colors',
+ tab.isActive
+ ? 'bg-sidebar text-foreground shadow-sm'
+ : 'text-muted-foreground hover:text-foreground'
+ )}
+ onBlur={() => iconRef.current?.stopAnimation()}
+ onFocus={() => iconRef.current?.startAnimation()}
+ onMouseEnter={() => iconRef.current?.startAnimation()}
+ onMouseLeave={() => iconRef.current?.stopAnimation()}
+ >
+ <AnimatedLucideIcon
+ ref={iconRef}
+ icon={tab.icon}
+ preset={tab.preset}
+ size={15}
+ />
+ <span>{tab.label}</span>
+ </Link>
+ )
+}
+
export function NavTabs({ surfacePath }: { surfacePath: string }) {
const { t } = useTranslation()
const { pathname } = useLocation()
@@ -31,40 +68,31 @@ export function NavTabs({ surfacePath }: { surfacePath: string }) {
surfacePath.startsWith('/project')
const tabs: TabItem[] = [
- { label: t('common:home'), to: route.home, icon: HomeIcon, isActive: isHome },
+ {
+ label: t('common:home'),
+ to: route.home,
+ icon: HomeIcon,
+ preset: 'home',
+ isActive: isHome,
+ },
{
label: t('common:cowork'),
to: route.cowork,
icon: Handshake,
+ preset: 'handshake',
isActive: isCowork,
- onClick: isCowork && pathname.startsWith('/settings')
- ? undefined
- : openCoworkStart,
+ onClick:
+ isCowork && pathname.startsWith('/settings')
+ ? undefined
+ : openCoworkStart,
},
]
return (
<div className="mt-1 flex items-center gap-0.5 rounded-lg bg-sidebar-foreground/5 p-0.5">
- {tabs.map((tab) => {
- const Icon = tab.icon
- return (
- <Link
- key={tab.to}
- to={tab.to}
- onClick={tab.onClick}
- aria-current={tab.isActive ? 'page' : undefined}
- className={cn(
- 'flex flex-1 items-center justify-center gap-1.5 rounded-md px-2 py-1 text-sm font-medium transition-colors',
- tab.isActive
- ? 'bg-sidebar text-foreground shadow-sm'
- : 'text-muted-foreground hover:text-foreground'
- )}
- >
- <Icon size={15} />
- <span>{tab.label}</span>
- </Link>
- )
- })}
+ {tabs.map((tab) => (
+ <NavTab key={tab.to} tab={tab} />
+ ))}
</div>
)
}