refactor(ui): use shadcn button and tooltip in sidebar

This commit is contained in:
yiling
2026-05-27 09:40:25 +08:00
parent d3b8e602b6
commit 331899f0e4
8 changed files with 180 additions and 108 deletions
+38 -27
View File
@@ -1,5 +1,7 @@
import { Menu } from 'lucide-react'
import React, { useMemo, useState } from 'react'
import { Button } from './ui/button'
import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from './ui/tooltip'
import { UserMenu } from './user-menu'
interface DualSidebarItemProps {
@@ -65,14 +67,16 @@ export const DualSidebar: React.FC<DualSidebarProps> = ({ children }) => {
return (
<>
{/* Mobile Hamburger Button */}
<button
<Button
variant="ghost"
size="icon"
onClick={toggleMobileMenu}
className="md:hidden fixed top-4 left-4 z-50 p-2 rounded-md bg-white/50 dark:bg-slate-800/50 backdrop-blur-sm text-slate-800 dark:text-slate-200 focus:outline-none focus-visible:ring-2 focus-visible:ring-blue-500"
className="md:hidden fixed top-4 left-4 z-50 rounded-md bg-white/50 dark:bg-slate-800/50 backdrop-blur-sm text-slate-800 dark:text-slate-200 focus:outline-none focus-visible:ring-2 focus-visible:ring-blue-500"
aria-label="Open navigation menu"
aria-expanded={isMobileMenuOpen}
>
<Menu />
</button>
</Button>
{/* Mobile Overlay */}
{isMobileMenuOpen && (
@@ -98,31 +102,38 @@ export const DualSidebar: React.FC<DualSidebarProps> = ({ children }) => {
<div className="absolute bottom-0 w-full h-[70dvh] bg-linear-to-t from-orange-400/10 to-transparent"></div>
{/* Level 1: Icon Bar */}
<nav className="w-16 bg-slate-100 dark:bg-slate-900 border-r border-slate-200 dark:border-slate-800 flex flex-col items-center pb-4 pt-0 space-y-2 flex-shrink-0">
<div className="flex-1 w-full flex flex-col items-center space-y-5">
{sidebarItems.map((item, index) => (
<div key={item.props.label} className="relative group">
<button
onClick={() => handleItemClick(index)}
aria-label={item.props.label}
aria-expanded={activeItem === index}
className={`p-3 rounded-lg transition-all duration-200 outline-none focus-visible:ring-2 focus-visible:ring-offset-2 focus-visible:ring-blue-500 dark:focus-visible:ring-offset-slate-900 ${
activeItem === index
? 'bg-blue-600 text-white shadow-lg'
: 'text-slate-400 hover:text-slate-500 dark:hover:text-slate-400 dark:text-slate-500 cursor-pointer'
}`}
>
{item.props.icon}
</button>
<span
className="absolute left-full ml-4 px-2 py-1 text-sm bg-slate-800 text-white rounded-md shadow-lg opacity-0 group-hover:opacity-100 transition-opacity duration-200 pointer-events-none whitespace-nowrap"
role="tooltip"
>
{item.props.label}
</span>
</div>
))}
<div className="flex-1 w-full flex flex-col items-center space-y-5 pt-1">
<TooltipProvider>
{sidebarItems.map((item, index) => (
<Tooltip key={item.props.label}>
<TooltipTrigger asChild>
<Button
variant="ghost"
size="icon-lg"
onClick={() => handleItemClick(index)}
aria-label={item.props.label}
aria-expanded={activeItem === index}
className={`w-12 h-12 [&_svg:not([class*='size-'])]:size-6 transition-all duration-200 ${
activeItem === index
? 'bg-blue-600 text-white shadow-lg hover:bg-blue-600 hover:text-white'
: 'text-slate-400 hover:text-slate-500 dark:hover:text-slate-400 dark:text-slate-500 hover:bg-slate-200 dark:hover:bg-slate-800'
}`}
>
{item.props.icon}
</Button>
</TooltipTrigger>
<TooltipContent
side="right"
sideOffset={16}
className="bg-slate-800 text-white border-slate-700"
>
<p>{item.props.label}</p>
</TooltipContent>
</Tooltip>
))}
</TooltipProvider>
</div>
<div className="mt-auto w-full flex flex-col items-center">
<div className="mt-auto w-full flex flex-col items-center pb-2">
<UserMenu />
</div>
</nav>
+49 -7
View File
@@ -60,7 +60,7 @@ export const NotificationFillIcon: React.FC<React.SVGProps<SVGSVGElement>> = (pr
xmlns="http://www.w3.org/2000/svg"
width={30}
height={30}
viewBox="0 -960 960 960"
viewBox="120 -792 720 720"
fill="none"
aria-hidden="true"
focusable="false"
@@ -69,9 +69,8 @@ export const NotificationFillIcon: React.FC<React.SVGProps<SVGSVGElement>> = (pr
<path
fillRule="evenodd"
clipRule="evenodd"
d="M160-200v-80h80v-280q0-83 50-147.5T420-792v-28q0-25 17.5-42.5T480-880q25 0 42.5 17.5T540-820v28q80 20 130 84.5T720-560v280h80v80H160ZM480-80q-33 0-56.5-23.5T400-160h160q0 33-23.5 56.5T480-80Z"
d="M 160 -180 v -72 h 80 v -252 q 0 -74.7 50 -132.75 T 420 -712.8 v -25.2 q 0 -22.5 17.5 -38.25 T 480 -792 q 25 0 42.5 15.75 T 540 -738 v 25.2 q 80 18 130 76.05 T 720 -504 v 252 h 80 v 72 H 160 Z M 480 -72 q -33 0 -56.5 -21.15 T 400 -144 h 160 q 0 29.7 -23.5 50.85 T 480 -72 Z"
fill="currentColor"
transform="translate(0, -48) scale(1, 0.9)"
/>
</svg>
)
@@ -145,9 +144,7 @@ export const ShumaiLogo: React.FC<React.SVGProps<SVGSVGElement>> = (props) => {
export const HomeIcon: React.FC<React.SVGProps<SVGSVGElement>> = (props) => (
<svg
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 200 200"
width={30}
height={30}
viewBox="24 24 152 152"
fill="none"
aria-hidden="true"
focusable="false"
@@ -156,7 +153,52 @@ export const HomeIcon: React.FC<React.SVGProps<SVGSVGElement>> = (props) => (
<path
d="M 44 170 L 44 100 L 24 100 L 100 30 L 126 54 L 126 36 L 142 36 L 142 69 L 176 100 L 156 100 L 156 170 L 120 170 L 120 136 A 20 20 0 0 0 80 136 L 80 170 Z"
fill="currentColor"
transform="scale(1, 0.95)"
/>
</svg>
)
interface UploadCloudIconProps extends React.SVGProps<SVGSVGElement> {
uploading?: boolean
className?: string
}
/**
* Custom UploadCloudIcon component.
* Replaces the animated version with a custom SVG while maintaining prop compatibility.
*/
export function UploadCloudIcon({
uploading = false,
className = '',
...props
}: UploadCloudIconProps) {
return (
<svg
xmlns="http://www.w3.org/2000/svg"
viewBox="15 15 70 70"
width={30}
height={30}
className={className}
aria-hidden="true"
focusable="false"
{...props}
>
<path
d="M 44.1 75 H 30 A 15 15 0 0 1 30 45 A 20 20 0 0 1 70 45 A 15 15 0 0 1 70 75 H 55.9 V 60.2 H 61.9 L 50 45.3 L 38.1 60.2 H 44.1 Z"
fill="currentColor"
/>
{uploading && (
<circle
cx="50"
cy="50"
r="48"
stroke="currentColor"
strokeWidth="2"
strokeDasharray="10 20"
fill="none"
className="animate-spin"
style={{ transformOrigin: 'center' }}
/>
)}
</svg>
)
}
+30
View File
@@ -0,0 +1,30 @@
import * as React from "react"
import * as TooltipPrimitive from "@radix-ui/react-tooltip"
import { cn } from "@/ui/lib/utils"
const TooltipProvider = TooltipPrimitive.Provider
const Tooltip = TooltipPrimitive.Root
const TooltipTrigger = TooltipPrimitive.Trigger
const TooltipContent = React.forwardRef<
React.ElementRef<typeof TooltipPrimitive.Content>,
React.ComponentPropsWithoutRef<typeof TooltipPrimitive.Content>
>(({ className, sideOffset = 4, ...props }, ref) => (
<TooltipPrimitive.Portal>
<TooltipPrimitive.Content
ref={ref}
sideOffset={sideOffset}
className={cn(
"z-50 overflow-hidden rounded-md bg-primary px-3 py-1.5 text-xs text-primary-foreground animate-in fade-in-0 zoom-in-95 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 origin-[--radix-tooltip-content-transform-origin]",
className
)}
{...props}
/>
</TooltipPrimitive.Portal>
))
TooltipContent.displayName = TooltipPrimitive.Content.displayName
export { Tooltip, TooltipTrigger, TooltipContent, TooltipProvider }
-48
View File
@@ -1,48 +0,0 @@
import React from 'react'
interface UploadCloudIconProps extends React.SVGProps<SVGSVGElement> {
uploading?: boolean
className?: string
}
/**
* Custom UploadCloudIcon component.
* Replaces the animated version with a custom SVG while maintaining prop compatibility.
*/
export function UploadCloudIcon({
uploading = false,
className = '',
...props
}: UploadCloudIconProps) {
return (
<svg
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 100 100"
width={30}
height={30}
className={className}
aria-hidden="true"
focusable="false"
{...props}
>
<path
d="M 44.4 75 H 30 A 15 15 0 0 1 30 45 A 20 20 0 0 1 70 45 A 15 15 0 0 1 70 75 H 55.6 V 61 H 61.2 L 50 47 L 38.8 61 H 44.4 Z"
fill="currentColor"
transform="scale(1.01, 1.05)"
/>
{uploading && (
<circle
cx="50"
cy="50"
r="48"
stroke="currentColor"
strokeWidth="2"
strokeDasharray="10 20"
fill="none"
className="animate-spin"
style={{ transformOrigin: 'center' }}
/>
)}
</svg>
)
}
+11 -11
View File
@@ -1,19 +1,19 @@
import { client } from '@/ui/api/client'
import { Avatar, AvatarFallback } from '@/ui/components/ui/avatar'
import {
DropdownMenu,
DropdownMenuContent,
DropdownMenuItem,
DropdownMenuLabel,
DropdownMenuSeparator,
DropdownMenuTrigger,
DropdownMenu,
DropdownMenuContent,
DropdownMenuItem,
DropdownMenuLabel,
DropdownMenuSeparator,
DropdownMenuTrigger,
} from '@/ui/components/ui/dropdown-menu'
import { useTeamId } from '@/ui/hooks/use-team-id'
import { signOut } from '@/ui/lib/auth-client'
import { useAuthStore } from '@/ui/stores/auth'
import { useQuery } from '@tanstack/react-query'
import { useNavigate } from '@tanstack/react-router'
import { useTheme } from './theme-provider'
import { client } from '@/ui/api/client'
import { useQuery } from '@tanstack/react-query'
import { signOut } from '@/ui/lib/auth-client'
export function UserMenu() {
const { clearAuth } = useAuthStore()
@@ -51,8 +51,8 @@ export function UserMenu() {
return (
<DropdownMenu>
<DropdownMenuTrigger asChild>
<Avatar>
<AvatarFallback className="text-black bg-orange-500/80">
<Avatar className="rounded-lg w-10 h-10">
<AvatarFallback className="rounded-lg bg-primary/40 text-foreground">
{getInitials(me?.name)}
</AvatarFallback>
</Avatar>
+6 -7
View File
@@ -1,20 +1,19 @@
import { DualSidebar, DualSidebarItem } from '@/ui/components/dual-sidebar'
import { NotificationList } from '@/ui/components/notification-list'
import { NotificationFillIcon, HomeIcon } from '@/ui/components/ui/icons'
import { TopNav } from '@/ui/components/top-nav'
import { HomeIcon, NotificationFillIcon, UploadCloudIcon } from '@/ui/components/ui/icons'
import { Toaster } from '@/ui/components/ui/sonner'
import { UploadCloudIcon } from '@/ui/components/ui/upload-cloud'
import { UploadTasks } from '@/ui/components/upload-tasks'
import { useAuthStore } from '@/ui/stores/auth'
import { useTeamContextStore } from '@/ui/stores/team-context'
import { useUploadStore } from '@/ui/stores/upload'
import {
createRootRouteWithContext,
Outlet,
useNavigate,
useRouterState,
createRootRouteWithContext,
Outlet,
useNavigate,
useRouterState,
} from '@tanstack/react-router'
import { useEffect } from 'react'
import { TopNav } from '@/ui/components/top-nav'
function RootComponent() {
const user = useAuthStore((state) => state.user)