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
Distribution Bar
One bar split into colored segments, with a legend.
import { DistributionBar } from "@/registry/vcare/ui/distribution-bar"
export default function DistributionBarDemo() {
return (
<DistributionBar
className="mx-auto max-w-md"
showValues
segments={[
{ name: "Paid", value: 64 },
{ name: "Insurance", value: 22 },
{ name: "Pending", value: 9 },
{ name: "Waived", value: 5 },
]}
/>
)
}Installation
npx shadcn@latest add @vcare/distribution-barOr install directly from the URL: https://ui.vcarehms.com/r/distribution-bar.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/distribution-bar.tsx
import * as React from 'react';
import { cn } from '@/registry/vcare/lib/utils';
import { formatNumber } from '@/registry/vcare/lib/format';
export interface DistributionSegment {
name: string;
value: number;
/** Any CSS color. Defaults to chart-1 through chart-5 in order. */
color?: string;
}
export interface DistributionBarProps extends React.ComponentProps<'div'> {
segments: DistributionSegment[];
valueFormatter?: (value: number) => string;
showLegend?: boolean;
/** Show absolute values in the legend in addition to the share. */
showValues?: boolean;
}
const defaultColors = ['var(--chart-1)', 'var(--chart-2)', 'var(--chart-3)', 'var(--chart-4)', 'var(--chart-5)'];
function DistributionBar({
segments,
valueFormatter = (value) => formatNumber(value, { format: 'compact' }),
showLegend = true,
showValues = false,
className,
...props
}: DistributionBarProps) {
const total = segments.reduce((sum, segment) => sum + segment.value, 0);
const resolved = segments.map((segment, index) => ({
...segment,
color: segment.color ?? defaultColors[index % defaultColors.length],
share: total > 0 ? segment.value / total : 0,
}));
return (
<div data-slot="distribution-bar" className={cn('flex flex-col gap-3', className)} {...props}>
<div
role="img"
aria-label={resolved.map((segment) => `${segment.name} ${formatNumber(segment.share, { format: 'percent' })}`).join(', ')}
className="flex h-2.5 w-full gap-0.5 overflow-hidden rounded-full"
>
{resolved.map((segment) =>
segment.share > 0 ? (
<div
key={segment.name}
className="h-full transition-[width] duration-300 first:rounded-l-full last:rounded-r-full"
style={{
width: `${segment.share * 100}%`,
backgroundColor: segment.color,
}}
/>
) : null,
)}
</div>
{showLegend ? (
<ul className="flex flex-wrap gap-x-4 gap-y-1.5 text-sm">
{resolved.map((segment) => (
<li key={segment.name} className="flex items-center gap-2">
<span aria-hidden="true" className="size-2.5 shrink-0 rounded-[2px]" style={{ backgroundColor: segment.color }} />
<span className="text-muted-foreground">{segment.name}</span>
<span className="font-medium tabular-nums">{formatNumber(segment.share, { format: 'percent' })}</span>
{showValues ? <span className="text-muted-foreground tabular-nums">({valueFormatter(segment.value)})</span> : null}
</li>
))}
</ul>
) : null}
</div>
);
}
export { DistributionBar };Usage
import { DistributionBar } from "@/components/ui/distribution-bar"Exports
DistributionBar
Dependencies
@vcare/format(registry)@vcare/utils(registry)
Raw item: /r/distribution-bar.json