({
data,
columns = 1,
className,
rowClassName,
keyClassName,
valueClassName,
renderKey,
renderValue,
onItemClick,
copyable = false,
}: KeyValueGridProps)
| 29 | } |
| 30 | |
| 31 | export function KeyValueGrid({ |
| 32 | data, |
| 33 | columns = 1, |
| 34 | className, |
| 35 | rowClassName, |
| 36 | keyClassName, |
| 37 | valueClassName, |
| 38 | renderKey, |
| 39 | renderValue, |
| 40 | onItemClick, |
| 41 | copyable = false, |
| 42 | }: KeyValueGridProps) { |
| 43 | const defaultRenderKey = (item: KeyValueItem) => { |
| 44 | const splitKey = item.name.split('.'); |
| 45 | return ( |
| 46 | <div className="flex items-center gap-1"> |
| 47 | {splitKey.map((name, index) => ( |
| 48 | <span |
| 49 | key={name} |
| 50 | className={ |
| 51 | index === splitKey.length - 1 |
| 52 | ? 'text-foreground' |
| 53 | : 'text-muted-foreground' |
| 54 | } |
| 55 | > |
| 56 | {camelCaseToWords(name)} |
| 57 | {index < splitKey.length - 1 && ( |
| 58 | <span className="text-muted-foreground">.</span> |
| 59 | )} |
| 60 | </span> |
| 61 | ))} |
| 62 | </div> |
| 63 | ); |
| 64 | }; |
| 65 | |
| 66 | const defaultRenderValue = (item: KeyValueItem) => { |
| 67 | return ( |
| 68 | <FieldValue name={item.name} value={item.value} event={item.event} /> |
| 69 | ); |
| 70 | }; |
| 71 | |
| 72 | const gridCols = { |
| 73 | 1: 'grid-cols-1', |
| 74 | 2: 'grid-cols-1 md:grid-cols-2', |
| 75 | 3: 'grid-cols-1 md:grid-cols-2 lg:grid-cols-3', |
| 76 | 4: 'grid-cols-1 md:grid-cols-2 lg:grid-cols-4', |
| 77 | }; |
| 78 | |
| 79 | return ( |
| 80 | <div |
| 81 | className={cn('grid card overflow-hidden', gridCols[columns], className)} |
| 82 | > |
| 83 | {data.map((item, index) => ( |
| 84 | <div |
| 85 | key={`${item.name}-${index}`} |
| 86 | className={cn( |
| 87 | 'relative flex items-center justify-between gap-4 p-4 py-3 shadow-[0_0_0_0.5px] shadow-border group', |
| 88 | onItemClick && 'cursor-pointer hover:bg-muted/50', |
nothing calls this directly
no test coverage detected