42 lines
1.7 KiB
TypeScript
42 lines
1.7 KiB
TypeScript
import type { ReactNode } from "react";
|
|
import { initials } from "../../lib/format";
|
|
import { Icon } from "./Icon";
|
|
|
|
export function Avatar({ name, size = 30 }: { name: string; size?: number }) {
|
|
return <span className="avatar" style={{ width: size, height: size, fontSize: size * 0.38 }}>{initials(name)}</span>;
|
|
}
|
|
|
|
export function SearchInput({ value, onChange, placeholder = "Search" }: { value: string; onChange: (v: string) => void; placeholder?: string }) {
|
|
return (
|
|
<label className="search">
|
|
<Icon name="search" size={16} />
|
|
<input type="search" value={value} placeholder={placeholder} aria-label={placeholder} onChange={(e) => onChange(e.target.value)} />
|
|
</label>
|
|
);
|
|
}
|
|
|
|
export function Stat({ label, value, tone = "neutral", hint, onClick, selected = false }: { label: string; value: ReactNode; tone?: "neutral" | "warning" | "danger" | "success"; hint?: string; onClick?: () => void; selected?: boolean }) {
|
|
const body = (
|
|
<>
|
|
<span className="stat-label"><i className={`stat-dot stat-${tone}`} />{label}</span>
|
|
<strong className="stat-value">{value}</strong>
|
|
{hint && <span className="stat-hint">{hint}</span>}
|
|
</>
|
|
);
|
|
if (!onClick) return <div className="stat">{body}</div>;
|
|
return <button type="button" className={`stat stat-button${selected ? " selected" : ""}`} aria-pressed={selected} onClick={onClick}>{body}</button>;
|
|
}
|
|
|
|
export function KeyValue({ items }: { items: { label: string; value: ReactNode }[] }) {
|
|
return (
|
|
<dl className="kv">
|
|
{items.map((item) => (
|
|
<div key={item.label}>
|
|
<dt>{item.label}</dt>
|
|
<dd>{item.value || "—"}</dd>
|
|
</div>
|
|
))}
|
|
</dl>
|
|
);
|
|
}
|