File size: 5,516 Bytes
0c52aa7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
172
import { ChevronRight } from "lucide-react";
import Link from "next/link";

export function Card({

  title,

  icon,

  action,

  children,

  className = "",

  bodyClassName = "",

}: {

  title?: React.ReactNode;

  icon?: React.ReactNode;

  action?: React.ReactNode;

  children: React.ReactNode;

  className?: string;

  bodyClassName?: string;

}) {
  return (
    <section className={`min-w-0 rounded-xl border border-line bg-surface-solid p-4 shadow-card sm:p-5 ${className}`}>

      {(title || action) && (

        <div className="mb-3.5 flex items-center gap-2.5">

          {icon && <span className="text-accent">{icon}</span>}

          {title && <h2 className="text-[16px] font-semibold text-ink">{title}</h2>}

          {action && <div className="ml-auto flex items-center gap-2">{action}</div>}

        </div>

      )}

      <div className={bodyClassName}>{children}</div>

    </section>
  );
}

/** Plain page header: breadcrumb, title with status pills, one-line description. */
export function Banner({

  crumbs,

  title,

  pills,

  meta,

  right,

  children,

}: {

  crumbs: { label: string; href?: string }[];

  title: React.ReactNode;

  pills?: React.ReactNode;

  meta?: React.ReactNode;

  right?: React.ReactNode;

  children?: React.ReactNode;

}) {
  return (
    <div className="mb-6">

      <nav aria-label="Breadcrumb" className="mb-1.5 flex flex-wrap items-center gap-1.5 text-[13px] text-muted">

        {crumbs.map((c, i) => (

          <span key={i} className="flex items-center gap-1.5">

            {i > 0 && <ChevronRight size={14} className="text-muted/60" />}

            {c.href ? (

              <Link href={c.href} className="hover:text-accent">

                {c.label}

              </Link>

            ) : (

              <span>{c.label}</span>

            )}

          </span>

        ))}

      </nav>

      <div className="flex flex-wrap items-center gap-x-4 gap-y-3">

        <h1 className="text-[24px] font-semibold tracking-tight text-ink [text-wrap:balance] sm:text-[28px]">{title}</h1>

        {pills && <div className="flex flex-wrap items-center gap-2">{pills}</div>}

        {right && <div className="ml-auto flex flex-wrap items-center gap-2">{right}</div>}

      </div>

      {meta && <div className="mt-1 text-[14px] text-muted">{meta}</div>}

      {children}

    </div>
  );
}

const PILL_TONES = {
  dark: "bg-accent-soft text-accent-deep",
  light: "bg-surface-solid text-ink border border-line",
  good: "bg-good-soft text-good",
  warn: "bg-warn-soft text-warn",
  info: "bg-info-soft text-info",
  accent: "accent-fill text-white",
} as const;

export function Pill({ tone = "light", children, className = "" }: { tone?: keyof typeof PILL_TONES; children: React.ReactNode; className?: string }) {
  return (
    <span className={`inline-flex items-center gap-1.5 rounded-full px-3 py-1 text-[12.5px] font-medium whitespace-nowrap ${PILL_TONES[tone]} ${className}`}>

      {children}

    </span>
  );
}

export function Stat({ label, before, after, note }: { label: string; before: string; after: string; note?: string }) {
  return (
    <div className="rounded-xl border border-line bg-surface-solid p-4 shadow-card">

      <p className="text-[13px] font-medium text-muted">{label}</p>

      <p className="tabular mt-2 flex items-baseline gap-2 text-ink">

        <span className="text-[17px] text-muted line-through decoration-1">{before}</span>

        <span className="text-[13px] text-muted">→</span>

        <span className="text-[30px] leading-none font-semibold text-accent">{after}</span>

      </p>

      {note && <p className="mt-2 text-[12.5px] text-muted">{note}</p>}

    </div>
  );
}

export function Segmented<T extends string>({
  options,
  value,
  onChange,
  label,
}: {
  options: { value: T; label: string }[];
  value: T;
  onChange: (v: T) => void;
  label: string;
}) {
  return (
    <div role="radiogroup" aria-label={label} className="inline-flex flex-wrap rounded-lg border border-line bg-sunken p-1">

      {options.map((o) => (

        <button

          key={o.value}

          type="button"

          role="radio"

          aria-checked={value === o.value}

          onClick={() => onChange(o.value)}

          className={`rounded-md px-3 py-1.5 text-[13px] font-medium transition-colors ${

            value === o.value ? "bg-accent text-white" : "text-muted hover:text-ink"

          }`}

        >

          {o.label}

        </button>

      ))}

    </div>
  );
}

export function Button({

  children,

  onClick,

  tone = "light",

  href,

  disabled,

  className = "",

}: {

  children: React.ReactNode;

  onClick?: () => void;

  tone?: "dark" | "light" | "accent";

  href?: string;

  disabled?: boolean;

  className?: string;

}) {
  const styles = {
    dark: "bg-nav text-white hover:bg-ink",
    light: "bg-surface-solid text-ink border border-line hover:border-accent",
    accent: "bg-accent text-white hover:bg-accent-deep",
  }[tone];
  const cls = `inline-flex items-center justify-center gap-2 rounded-lg px-4 py-2.5 text-[14px] font-medium shadow-card transition disabled:opacity-50 ${styles} ${className}`;
  if (href) {
    return (
      <Link href={href} className={cls}>

        {children}

      </Link>
    );
  }
  return (
    <button type="button" onClick={onClick} disabled={disabled} className={cls}>

      {children}

    </button>
  );
}