File size: 4,870 Bytes
65d68f5 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 | "use client";
import { HTMLAttributes } from "react";
import { clsx } from "clsx";
// =============================================================================
// SectionHeader Types
// =============================================================================
export interface SectionHeaderProps extends HTMLAttributes<HTMLDivElement> {
title: string;
subtitle?: string;
actionText?: string;
actionHref?: string;
actionOnClick?: () => void;
icon?: React.ReactNode;
titleSize?: "page" | "section" | "card" | "small";
showDivider?: boolean;
}
export interface PageHeaderProps extends SectionHeaderProps {
backHref?: string;
backText?: string;
actionSlot?: React.ReactNode;
}
// =============================================================================
// SharedSectionHeader Component
// =============================================================================
export function SharedSectionHeader({
title,
subtitle,
actionText,
actionHref,
actionOnClick,
icon,
titleSize = "section",
showDivider = false,
className,
...props
}: SectionHeaderProps) {
// Map title size to styles
const titleStyles = {
page: {
className: "text-[26px] font-bold tracking-[-0.02em] text-[var(--text-primary)]",
},
section: {
className: "text-[24px] font-bold tracking-[-0.02em] text-[var(--text-primary)]",
},
card: {
className: "text-[18px] font-bold text-[var(--text-primary)]",
},
small: {
className: "text-[15px] font-semibold text-[var(--text-primary)]",
},
};
const style = titleStyles[titleSize];
return (
<div className={clsx("space-y-4", className)} {...props}>
<div className="flex items-start justify-between gap-4">
<div className="flex items-center gap-3">
{icon && (
<div className="grid size-8 shrink-0 place-items-center rounded-md bg-[var(--accent-primary)]/10">
{icon}
</div>
)}
<div>
<h2 className={style.className}>{title}</h2>
{subtitle && (
<p className="mt-1 text-[14px] leading-relaxed text-[var(--text-secondary)]">
{subtitle}
</p>
)}
</div>
</div>
{(actionText || actionHref || actionOnClick) && (
<div className="flex items-center">
{actionHref ? (
<a
href={actionHref}
className="text-[13px] font-semibold text-[var(--accent-primary)] hover:underline"
>
{actionText}
</a>
) : actionOnClick ? (
<button
type="button"
onClick={actionOnClick}
className="text-[13px] font-semibold text-[var(--accent-primary)] hover:underline"
>
{actionText}
</button>
) : null}
</div>
)}
</div>
{showDivider ? <div className="h-px w-full bg-[var(--border-subtle)]" aria-hidden="true" /> : null}
</div>
);
}
// =============================================================================
// Section Label (uppercase small label)
// =============================================================================
export function SectionLabel({
children,
className,
accent = false,
...props
}: HTMLAttributes<HTMLParagraphElement> & { accent?: boolean }) {
return (
<p
className={clsx(
"text-[11px] font-bold uppercase tracking-wider",
accent ? "text-[var(--accent-primary)]" : "text-[var(--text-muted)]",
className,
)}
{...props}
>
{children}
</p>
);
}
// =============================================================================
// Page Header (with back link option)
// =============================================================================
export function PageHeader({
title,
subtitle,
backHref,
backText = "Back",
actionSlot,
className,
...props
}: PageHeaderProps) {
return (
<div className={clsx("space-y-2", className)} {...props}>
{backHref && (
<a
href={backHref}
className="inline-flex items-center gap-1.5 text-[12px] text-[var(--text-muted)] hover:text-[var(--text-secondary)] transition"
>
← {backText}
</a>
)}
<div className="flex items-center justify-between gap-4">
<div className="flex items-center gap-3">
<div>
<h2 className="text-[26px] font-bold tracking-[-0.02em] text-[var(--text-primary)]">{title}</h2>
{subtitle && (
<p className="mt-1 text-[14px] leading-relaxed text-[var(--text-secondary)]">
{subtitle}
</p>
)}
</div>
</div>
{actionSlot && <div className="flex gap-2">{actionSlot}</div>}
</div>
</div>
);
}
|