| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192 |
- import type { ReactNode } from 'react';
- import { cn } from '@/lib/utils';
- import { useHref } from './context';
-
- /** Page-width wrapper used by every section. */
- export function Container({
- className,
- children,
- }: {
- className?: string;
- children: ReactNode;
- }) {
- return (
- <div className={cn('mx-auto w-full max-w-6xl px-5 sm:px-8', className)}>
- {children}
- </div>
- );
- }
-
- export function SfButton({
- href,
- variant = 'primary',
- className,
- children,
- }: {
- href: string;
- variant?: 'primary' | 'outline';
- className?: string;
- children: ReactNode;
- }) {
- const resolved = useHref(href);
-
- return (
- <a
- href={resolved}
- className={cn(
- 'inline-flex items-center justify-center rounded-(--sf-radius) px-5 py-2.5 text-sm font-semibold transition-opacity hover:opacity-85 focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-(--sf-primary)',
- variant === 'primary'
- ? 'bg-(--sf-primary) text-(--sf-primary-fg)'
- : 'border border-(--sf-border) text-(--sf-fg)',
- className,
- )}
- >
- {children}
- </a>
- );
- }
-
- /** A plain link whose address is worked out the same way as buttons. */
- export function SfLink({
- href,
- className,
- children,
- }: {
- href: string;
- className?: string;
- children: ReactNode;
- }) {
- return (
- <a href={useHref(href)} className={className}>
- {children}
- </a>
- );
- }
-
- /** A minus button, the number, and a plus button. */
- export function QuantityStepper({
- value,
- max,
- min = 1,
- disabled = false,
- onChange,
- decreaseLabel,
- increaseLabel,
- }: {
- value: number;
- max: number;
- min?: number;
- disabled?: boolean;
- onChange: (value: number) => void;
- decreaseLabel: string;
- increaseLabel: string;
- }) {
- const button =
- 'flex size-9 items-center justify-center text-lg leading-none transition-colors hover:bg-(--sf-surface) disabled:cursor-not-allowed disabled:opacity-40';
-
- return (
- <div className="inline-flex items-center overflow-hidden rounded-(--sf-radius) border border-(--sf-border)">
- <button
- type="button"
- className={button}
- aria-label={decreaseLabel}
- disabled={disabled || value <= min}
- onClick={() => onChange(value - 1)}
- >
- −
- </button>
- <span
- className="min-w-9 px-1 text-center text-sm tabular-nums"
- aria-live="polite"
- >
- {value}
- </span>
- <button
- type="button"
- className={button}
- aria-label={increaseLabel}
- disabled={disabled || value >= max}
- onClick={() => onChange(value + 1)}
- >
- +
- </button>
- </div>
- );
- }
-
- export function Eyebrow({ children }: { children: ReactNode }) {
- return (
- <p className="text-xs font-semibold tracking-[0.18em] text-(--sf-primary) uppercase">
- {children}
- </p>
- );
- }
-
- export function SectionHeading({
- heading,
- subheading,
- align = 'left',
- }: {
- heading: string;
- subheading?: string | null;
- align?: 'left' | 'center';
- }) {
- return (
- <div
- className={cn(
- 'max-w-2xl',
- align === 'center' && 'mx-auto text-center',
- )}
- >
- <h2 className="sf-heading text-3xl leading-tight font-semibold sm:text-4xl">
- {heading}
- </h2>
- {subheading && (
- <p className="mt-3 text-base text-(--sf-muted)">{subheading}</p>
- )}
- </div>
- );
- }
-
- const tilts = ['135deg', '200deg', '45deg', '310deg'];
-
- /**
- * Stands in for a photo when there is no real one.
- * It is drawn from the theme colours so it always matches the store.
- */
- export function ImagePlaceholder({
- seed = 0,
- label,
- className,
- }: {
- seed?: number;
- label?: string;
- className?: string;
- }) {
- const tilt = tilts[seed % tilts.length];
-
- return (
- <div
- role="img"
- aria-label={
- label ? `Placeholder image: ${label}` : 'Placeholder image'
- }
- className={cn(
- 'relative overflow-hidden rounded-(--sf-radius-card) border border-(--sf-border)',
- className,
- )}
- style={{
- background: `linear-gradient(${tilt}, color-mix(in srgb, var(--sf-primary) 28%, var(--sf-surface)), color-mix(in srgb, var(--sf-accent) 38%, var(--sf-surface)))`,
- }}
- >
- <div
- className="absolute -right-[15%] -bottom-[25%] aspect-square w-[70%] rounded-full opacity-40"
- style={{ background: 'var(--sf-accent)' }}
- />
- <div
- className="absolute -top-[20%] -left-[10%] aspect-square w-[45%] rounded-full opacity-25"
- style={{ background: 'var(--sf-primary)' }}
- />
- </div>
- );
- }
|