Documentation menu
Getting Started
Components
Primitives
- Agent Thinking
- Alert
- Alert Dialog
- Avatar
- Badge
- Breadcrumb
- Button
- Button Group
- Calendar
- Card
- Checkbox
- Command
- Command Palette
- Context Menu
- Data Table
- Dialog
- Dropdown Menu
- Empty
- Field
- Glow Cloud
- Input
- Label
- Medication Schedule
- Period Tabs
- Popover
- Rainbow Button
- Scroll Area
- Select
- Selectable Card
- Separator
- Sheet
- Sidebar
- Skeleton
- Slider
- Sonner
- Spinner
- Switch
- Table
- Tabs
- Tag
- Textarea
- Timeline
- Tooltip
- Use Count Up
Charts and metrics
Patterns
- Confirm Button
- Date Picker
- Embedded
- Empty State
- Entity Drawer
- Error Boundary
- Field Row
- File Dropzone
- Form Dialog
- Kv
- List Editor
- List Page
- Live Time
- Mini Table
- Money
- Note Field
- Note Text
- Page Card
- Page Header
- Page Tabs
- Page Toolbar
- Person Cell
- Picture Field
- Print Card
- Range Switcher
- Row Actions
- Search Input
- Search Select
- Selected Box
- Signature Pad
- Status Badge
- Sub Nav Layout
- Suggest Input
- Tab Icons
- Table Footer
- Theme Accent Picker
- Time Picker
- View All Link
Dashboard cards
Advanced
Device frames
Website widgets
Website screens
Website panels
Charts and metrics
Bar List
A ranked list where each row is a bar sized by its value.
import { BarList } from "@/registry/vcare/ui/bar-list"
const data = [
{ name: "Complete blood count", value: 312 },
{ name: "Lipid profile", value: 204 },
{ name: "HbA1c", value: 188 },
{ name: "Thyroid profile", value: 141 },
{ name: "Liver function", value: 97 },
]
export default function BarListDemo() {
return <BarList className="mx-auto max-w-md" data={data} showPercentage />
}Installation
npx shadcn@latest add @vcare/bar-listOr install directly from the URL: https://ui.vcarehms.com/r/bar-list.json
- Add the registry items it uses: format, utils.
- Copy this file into your project and change the
@/registry/vcare/…imports to your own paths.
components/ui/bar-list.tsx
import * as React from 'react';
import { cn } from '@/registry/vcare/lib/utils';
import { formatNumber } from '@/registry/vcare/lib/format';
export interface BarListItem {
name: string;
value: number;
/** Renders the label as a link. */
href?: string;
icon?: React.ReactNode;
/** Stable key when names can repeat. */
key?: string;
}
export interface BarListProps extends React.ComponentProps<'div'> {
data: BarListItem[];
valueFormatter?: (value: number) => string;
sortOrder?: 'descending' | 'ascending' | 'none';
/** Any CSS color. Defaults to chart-1. */
color?: string;
/** Show each row's share of the total next to its value. */
showPercentage?: boolean;
onItemClick?: (item: BarListItem) => void;
}
function BarList({
data,
valueFormatter = (value) => formatNumber(value, { format: 'compact' }),
sortOrder = 'descending',
color = 'var(--chart-1)',
showPercentage = false,
onItemClick,
className,
...props
}: BarListProps) {
const items = React.useMemo(() => {
if (sortOrder === 'none') return data;
const sorted = [...data].sort((a, b) => a.value - b.value);
return sortOrder === 'descending' ? sorted.reverse() : sorted;
}, [data, sortOrder]);
const max = Math.max(...items.map((item) => item.value), 0);
const total = items.reduce((sum, item) => sum + item.value, 0);
return (
<div data-slot="bar-list" className={cn('flex flex-col gap-1.5', className)} {...props}>
{items.map((item) => {
const width = max > 0 ? (item.value / max) * 100 : 0;
const share = total > 0 ? item.value / total : 0;
const interactive = Boolean(item.href || onItemClick);
const Label = item.href ? 'a' : onItemClick ? 'button' : 'div';
return (
<div key={item.key ?? item.name} data-slot="bar-list-row" className="flex items-center gap-3 text-sm">
<div className="relative flex h-8 min-w-0 flex-1 items-center">
<div
aria-hidden="true"
className="absolute inset-y-0 left-0 rounded-md transition-[width] duration-300"
style={{
width: `${width}%`,
backgroundColor: `color-mix(in oklab, ${color} 20%, transparent)`,
}}
/>
<Label
{...(item.href ? { href: item.href } : {})}
{...(onItemClick && !item.href
? {
type: 'button' as const,
onClick: () => onItemClick(item),
}
: {})}
className={cn('relative flex min-w-0 items-center gap-2 px-2 text-left', interactive && 'hover:underline')}
>
{item.icon ? <span className="text-muted-foreground shrink-0 [&>svg]:size-4">{item.icon}</span> : null}
<span className="truncate">{item.name}</span>
</Label>
</div>
<div className="flex shrink-0 items-center gap-2 tabular-nums">
<span className="font-medium">{valueFormatter(item.value)}</span>
{showPercentage ? (
<span className="text-muted-foreground w-12 text-right text-xs">{formatNumber(share, { format: 'percent' })}</span>
) : null}
</div>
</div>
);
})}
</div>
);
}
export { BarList };Usage
import { BarList } from "@/components/ui/bar-list"Exports
BarList
Dependencies
@vcare/format(registry)@vcare/utils(registry)
Raw item: /r/bar-list.json