| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788 |
- import { ShoppingBag } from 'lucide-react';
- import { cn } from '@/lib/utils';
- import { useStorefront } from '../context';
- import { storefrontText } from '../text';
- import type { HeaderSection } from '../types';
- import { Container, SfButton, SfLink } from '../ui';
-
- export function Header({
- section,
- }: {
- section: Pick<HeaderSection, 'variant' | 'content'>;
- }) {
- const { logoText, links, cta } = section.content;
- const centered = section.variant === 'centered';
- const { cart, language } = useStorefront();
- const t = storefrontText(language);
-
- const cartLink = (
- <SfLink
- href="/cart"
- className="relative inline-flex size-10 items-center justify-center rounded-(--sf-radius) text-(--sf-fg) transition-colors hover:bg-(--sf-surface)"
- >
- <ShoppingBag className="size-5" aria-hidden="true" />
- <span className="sr-only">{t.cartCount(cart.count)}</span>
- {cart.count > 0 && (
- <span
- aria-hidden="true"
- className="absolute -top-0.5 -right-0.5 flex min-w-5 items-center justify-center rounded-full bg-(--sf-primary) px-1 text-[11px] leading-5 font-semibold text-(--sf-primary-fg)"
- >
- {cart.count}
- </span>
- )}
- </SfLink>
- );
-
- return (
- <header className="sticky top-0 z-20 border-b border-(--sf-border) bg-(--sf-bg)/90 backdrop-blur">
- <Container
- className={cn(
- 'relative flex items-center gap-6 py-4',
- centered ? 'flex-col sm:gap-3' : 'justify-between',
- )}
- >
- <SfLink href="#" className="sf-heading text-xl font-semibold">
- {logoText}
- </SfLink>
-
- <nav
- aria-label="Main"
- className={cn(
- 'items-center gap-7 text-sm',
- centered
- ? 'flex flex-wrap justify-center'
- : 'hidden md:flex',
- )}
- >
- {links.map((link) => (
- <SfLink
- key={link.label + link.href}
- href={link.href}
- className="text-(--sf-muted) transition-colors hover:text-(--sf-fg)"
- >
- {link.label}
- </SfLink>
- ))}
- </nav>
-
- {centered ? (
- <div className="absolute top-3 right-5 sm:right-8">
- {cartLink}
- </div>
- ) : (
- <div className="flex items-center gap-2">
- {cartLink}
- {cta && (
- <SfButton
- href={cta.href}
- className="hidden px-4 py-2 sm:inline-flex"
- >
- {cta.label}
- </SfButton>
- )}
- </div>
- )}
- </Container>
- </header>
- );
- }
|