zasuiv0.1
GitHub
Menú

Dashboard

Top List

Lista numerada de tipo «top N» del dashboard.

Uso

Instalación

Con la CLI de zasui (ver Introducción): instala el componente con sus dependencias y queda listo para usar.

pnpm dlx @medialityc/zasui add top-list
Ver el código
import { cn } from '@/lib/utils';
import React from 'react';

export interface TopListItem {
	id: string | number;
	/** Línea principal, normalmente el nombre. */
	primary: React.ReactNode;
	/** Línea secundaria bajo la principal. */
	secondary?: React.ReactNode;
	/** Contenido alineado a la derecha, normalmente un importe. */
	trailing?: React.ReactNode;
}

export interface TopListProps {
	items: TopListItem[];
	emptyLabel?: string;
	className?: string;
}

/** Lista numerada de tipo "top N" del dashboard. */
export const TopList = ({
	items,
	emptyLabel = 'Sin datos disponibles',
	className,
}: TopListProps) => {
	return (
		<div className={cn('max-h-72 space-y-2 overflow-y-auto', className)}>
			{items.length === 0 && (
				<p className='text-muted-foreground py-4 text-center text-sm'>
					{emptyLabel}
				</p>
			)}
			{items.map((item, index) => (
				<div
					key={item.id}
					data-slot='top-list-item'
					className='border-border bg-card flex items-center justify-between rounded-lg border p-3'
				>
					<div className='flex items-center gap-3'>
						<div className='flex h-8 w-8 items-center justify-center rounded-full bg-blue-50 text-sm font-semibold text-blue-600 dark:bg-blue-900/30 dark:text-blue-300'>
							{index + 1}
						</div>
						<div>
							<div className='text-sm font-medium'>{item.primary}</div>
							{item.secondary ? (
								<div className='text-muted-foreground text-xs'>
									{item.secondary}
								</div>
							) : null}
						</div>
					</div>
					{item.trailing ? (
						<div className='text-right'>{item.trailing}</div>
					) : null}
				</div>
			))}
		</div>
	);
};