← full-stack-fastapi-template / frontend/src/components/Common/Logo.tsx
| 1 | import { Link } from "@tanstack/react-router" |
| 2 | |
| 3 | import { useTheme } from "@/components/theme-provider" |
| 4 | import { cn } from "@/lib/utils" |
| 5 | import icon from "/assets/images/fastapi-icon.svg" |
| 6 | import iconLight from "/assets/images/fastapi-icon-light.svg" |
| 7 | import logo from "/assets/images/fastapi-logo.svg" |
| 8 | import logoLight from "/assets/images/fastapi-logo-light.svg" |
| 9 | |
| 10 | interface LogoProps { |
| 11 | variant?: "full" | "icon" | "responsive" |
| 12 | className?: string |
| 13 | asLink?: boolean |
| 14 | } |
| 15 | |
| 16 | export function Logo({ |
| 17 | variant = "full", |
| 18 | className, |
| 19 | asLink = true, |
| 20 | }: LogoProps) { |
| 21 | const { resolvedTheme } = useTheme() |
| 22 | const isDark = resolvedTheme === "dark" |
| 23 | |
| 24 | const fullLogo = isDark ? logoLight : logo |
| 25 | const iconLogo = isDark ? iconLight : icon |
| 26 | |
| 27 | const content = |
| 28 | variant === "responsive" ? ( |
| 29 | <> |
| 30 | <img |
| 31 | src={fullLogo} |
| 32 | alt="FastAPI" |
| 33 | className={cn( |
| 34 | "h-6 w-auto group-data-[collapsible=icon]:hidden", |
| 35 | className, |
| 36 | )} |
| 37 | /> |
| 38 | <img |
| 39 | src={iconLogo} |
| 40 | alt="FastAPI" |
| 41 | className={cn( |
| 42 | "size-5 hidden group-data-[collapsible=icon]:block", |
| 43 | className, |
| 44 | )} |
| 45 | /> |
| 46 | </> |
| 47 | ) : ( |
| 48 | <img |
| 49 | src={variant === "full" ? fullLogo : iconLogo} |
| 50 | alt="FastAPI" |
| 51 | className={cn(variant === "full" ? "h-6 w-auto" : "size-5", className)} |
| 52 | /> |
| 53 | ) |
| 54 | |
| 55 | if (!asLink) { |
| 56 | return content |
| 57 | } |
| 58 | |
| 59 | return <Link to="/">{content}</Link> |
| 60 | } |
| 61 |