Spaces:
Sleeping
Sleeping
Download packages/ui/src/components/Header.tsx from Benaah/MicProtocol: direct link, hf CLI and curl.
- Browser
- Download file 8.34 kB
-
https://huggingface.co/spaces/Benaah/MicProtocol/resolve/main/packages/ui/src/components/Header.tsx
- Command line
-
hf download hf://spaces/Benaah/MicProtocol/packages/ui/src/components/Header.tsx
-
curl -L -o Header.tsx https://huggingface.co/spaces/Benaah/MicProtocol/resolve/main/packages/ui/src/components/Header.tsx
8.34 kB
| import React, { useState } from "react"; | |
| import { cn } from "../lib/cn"; | |
| export interface HeaderProps { | |
| className?: string; | |
| style?: React.CSSProperties; | |
| navLinks?: Array<{ href: string; label: string }>; | |
| ctaLabel?: string; | |
| ctaHref?: string; | |
| actions?: React.ReactNode; | |
| logo?: React.ReactNode; | |
| mobileMenuContent?: React.ReactNode; | |
| } | |
| const mobileMenuStyle: React.CSSProperties = { | |
| position: "fixed", | |
| top: 72, | |
| left: 0, | |
| right: 0, | |
| bottom: 0, | |
| background: "rgba(10, 9, 13, 0.96)", | |
| backdropFilter: "blur(24px)", | |
| WebkitBackdropFilter: "blur(24px)", | |
| padding: "var(--space-8)", | |
| display: "flex", | |
| flexDirection: "column", | |
| gap: "var(--space-6)", | |
| zIndex: 200, | |
| }; | |
| const defaultLinks = [ | |
| { href: "/about", label: "About" }, | |
| { href: "/pricing", label: "Pricing" }, | |
| { href: "/network", label: "Network" }, | |
| ]; | |
| /** Responsive public navigation with desktop links, mobile drawer, and optional actions. */ | |
| export const Header = React.forwardRef<HTMLElement, HeaderProps>( | |
| ( | |
| { | |
| className, | |
| style, | |
| navLinks, | |
| ctaLabel = "Get Started", | |
| ctaHref = "/sign-up", | |
| actions, | |
| logo, | |
| mobileMenuContent, | |
| ...props | |
| }, | |
| ref, | |
| ) => { | |
| const [mobileOpen, setMobileOpen] = useState(false); | |
| const links = navLinks || defaultLinks; | |
| const activePath = | |
| typeof window !== "undefined" ? window.location.pathname : "/"; | |
| const baseLinkStyle: React.CSSProperties = { | |
| fontSize: "var(--text-sm)", | |
| fontWeight: 500, | |
| color: "var(--text-secondary)", | |
| padding: "var(--space-2) var(--space-3)", | |
| textDecoration: "none", | |
| position: "relative", | |
| transition: "color 0.2s var(--transition-fast)", | |
| }; | |
| return ( | |
| <header | |
| ref={ref} | |
| className={cn("mic-header", className)} | |
| role="banner" | |
| style={{ | |
| height: 64, | |
| display: "flex", | |
| alignItems: "center", | |
| justifyContent: "space-between", | |
| padding: "0 var(--space-8)", | |
| position: "sticky", | |
| top: 0, | |
| zIndex: 100, | |
| background: "var(--bg-primary)", | |
| borderBottom: "1px solid var(--border-color-subtle)", | |
| ...style, | |
| }} | |
| {...props} | |
| > | |
| {/* Logo */} | |
| <a | |
| href="/" | |
| aria-label="MicProtocol home" | |
| style={{ | |
| display: "flex", | |
| alignItems: "center", | |
| gap: "var(--space-2)", | |
| textDecoration: "none", | |
| }} | |
| > | |
| <div | |
| style={{ | |
| width: 36, | |
| height: 36, | |
| borderRadius: "var(--radius-md)", | |
| background: "var(--bg-secondary)", | |
| display: "flex", | |
| alignItems: "center", | |
| justifyContent: "center", | |
| }} | |
| > | |
| {logo ?? ( | |
| <img | |
| src="/icon.png" | |
| alt="" | |
| style={{ | |
| width: 28, | |
| height: 28, | |
| borderRadius: "var(--radius-sm)", | |
| objectFit: "contain", | |
| }} | |
| /> | |
| )} | |
| </div> | |
| <span | |
| style={{ | |
| fontSize: "var(--text-xl)", | |
| fontWeight: 700, | |
| fontFamily: "var(--font-display)", | |
| color: "var(--text-primary)", | |
| letterSpacing: "-0.02em", | |
| }} | |
| > | |
| MicProtocol | |
| </span> | |
| </a> | |
| {/* Desktop Nav */} | |
| <nav | |
| className="mic-header__nav" | |
| style={{ | |
| display: "flex", | |
| gap: "var(--space-1)", | |
| alignItems: "center", | |
| }} | |
| aria-label="Main navigation" | |
| > | |
| {links.map((link) => { | |
| const isActive = activePath === link.href; | |
| return ( | |
| <a | |
| key={link.href} | |
| href={link.href} | |
| aria-current={isActive ? "page" : undefined} | |
| style={{ | |
| ...baseLinkStyle, | |
| color: isActive | |
| ? "var(--color-primary)" | |
| : "var(--text-secondary)", | |
| borderBottom: isActive | |
| ? "2px solid var(--color-primary)" | |
| : "2px solid transparent", | |
| }} | |
| onMouseEnter={(e) => { | |
| if (!isActive) { | |
| e.currentTarget.style.color = "var(--color-primary)"; | |
| e.currentTarget.style.borderBottomColor = | |
| "var(--color-primary)"; | |
| } | |
| }} | |
| onMouseLeave={(e) => { | |
| if (!isActive) { | |
| e.currentTarget.style.color = "var(--text-secondary)"; | |
| e.currentTarget.style.borderBottomColor = "transparent"; | |
| } | |
| }} | |
| > | |
| {link.label} | |
| </a> | |
| ); | |
| })} | |
| <a | |
| href="/login" | |
| style={{ | |
| ...baseLinkStyle, | |
| }} | |
| onMouseEnter={(e) => { | |
| e.currentTarget.style.color = "var(--color-primary)"; | |
| }} | |
| onMouseLeave={(e) => { | |
| e.currentTarget.style.color = "var(--text-secondary)"; | |
| }} | |
| > | |
| Log in | |
| </a> | |
| <a | |
| href={ctaHref} | |
| className="mic-header__cta" | |
| style={{ | |
| fontSize: "var(--text-sm)", | |
| fontWeight: 600, | |
| color: "var(--text-inverse)", | |
| background: "var(--color-primary)", | |
| padding: "var(--space-2) var(--space-5)", | |
| borderRadius: "var(--radius-md)", | |
| textDecoration: "none", | |
| display: "inline-flex", | |
| alignItems: "center", | |
| gap: "var(--space-2)", | |
| transition: "background var(--transition-fast)", | |
| }} | |
| > | |
| {ctaLabel} | |
| </a> | |
| {actions && <div className="mic-header__actions">{actions}</div>} | |
| </nav> | |
| {/* Mobile Hamburger */} | |
| <button | |
| className="mic-header__menu-button" | |
| onClick={() => setMobileOpen((prev) => !prev)} | |
| aria-label={mobileOpen ? "Close menu" : "Open menu"} | |
| aria-expanded={mobileOpen} | |
| style={{ | |
| padding: "var(--space-2)", | |
| position: "relative", | |
| width: 36, | |
| height: 36, | |
| background: "none", | |
| border: "none", | |
| cursor: "pointer", | |
| zIndex: 110, | |
| }} | |
| > | |
| <svg | |
| width="20" | |
| height="20" | |
| viewBox="0 0 20 20" | |
| fill="none" | |
| style={{ position: "absolute", inset: 0, margin: "auto" }} | |
| > | |
| <path | |
| d="M3 6h14" | |
| stroke="currentColor" | |
| strokeWidth="1.5" | |
| strokeLinecap="round" | |
| style={{ | |
| transition: "all 0.3s var(--spring)", | |
| transform: mobileOpen | |
| ? "rotate(45deg) translate(5px, 5px)" | |
| : "none", | |
| transformOrigin: "center", | |
| }} | |
| /> | |
| <path | |
| d="M3 10h14" | |
| stroke="currentColor" | |
| strokeWidth="1.5" | |
| strokeLinecap="round" | |
| style={{ | |
| opacity: mobileOpen ? 0 : 1, | |
| transition: "all 0.3s var(--spring)", | |
| }} | |
| /> | |
| <path | |
| d="M3 14h14" | |
| stroke="currentColor" | |
| strokeWidth="1.5" | |
| strokeLinecap="round" | |
| style={{ | |
| transition: "all 0.3s var(--spring)", | |
| transform: mobileOpen | |
| ? "rotate(-45deg) translate(5px, -5px)" | |
| : "none", | |
| transformOrigin: "center", | |
| }} | |
| /> | |
| </svg> | |
| </button> | |
| {/* Mobile Menu Panel */} | |
| {mobileOpen && mobileMenuContent && ( | |
| <div className="mic-header__mobile-menu" style={mobileMenuStyle}> | |
| {mobileMenuContent} | |
| </div> | |
| )} | |
| </header> | |
| ); | |
| }, | |
| ); | |
| Header.displayName = "Header"; | |