Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 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 | 105x 1036x 105x 105x 184x | import React from "react";
/**
* One labelled field in a resource's metadata strip — an uppercase caption
* over a value, optionally led by an icon.
*
* Twelve pages declared this identically. The `size` prop is the one real
* difference between them: `Activity` packs many fields into a trace header
* and wants them tighter, everything else uses the roomier default.
*/
export interface MetaItemProps {
/** Lucide icon component, rendered before the label. */
icon?: React.ElementType;
label: React.ReactNode;
value: React.ReactNode;
/** Right-aligned control on the label row — a copy button, an edit link. */
action?: React.ReactNode;
/** `sm` for dense headers with many fields. */
size?: "sm" | "md";
className?: string;
}
export const MetaItem: React.FC<MetaItemProps> = ({
icon: Icon,
label,
value,
action,
size = "md",
className = "",
}) => (
<div className={`flex flex-col gap-0.5 ${className}`.trim()}>
<div
className={`flex items-center gap-1 text-gray-400 dark:text-gray-500 uppercase tracking-wide font-medium ${
size === "sm" ? "text-[10px]" : "text-xs"
}`}
>
{Icon && <Icon className="size-3" />}
{label}
{action && <span className="ml-auto">{action}</span>}
</div>
<div
className={`text-gray-800 dark:text-gray-200 font-medium ${
size === "sm" ? "text-xs" : "text-sm"
}`}
>
{value}
</div>
</div>
);
export interface MetaGridProps {
children: React.ReactNode;
/** Columns at the `sm` breakpoint and up. Below it, always two. */
columns?: 2 | 3 | 4;
className?: string;
}
/** Tailwind needs whole class names at build time, so the column variants are
* spelled out rather than interpolated. */
const COLUMNS: Record<NonNullable<MetaGridProps["columns"]>, string> = {
2: "grid-cols-2",
3: "grid-cols-2 sm:grid-cols-3",
4: "grid-cols-2 sm:grid-cols-4",
};
/** The responsive grid a metadata strip's {@link MetaItem}s sit in. */
export const MetaGrid: React.FC<MetaGridProps> = ({
children,
columns = 3,
className = "",
}) => (
<div className={`grid gap-5 ${COLUMNS[columns]} ${className}`.trim()}>
{children}
</div>
);
export default MetaItem;
|