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
Segmented Meter
A meter split into zones (low, normal, high) with a marker.
import { SegmentedMeter } from "@/registry/vcare/ui/segmented-meter"
export default function SegmentedMeterDemo() {
return (
<SegmentedMeter
className="mx-auto max-w-md"
value={132}
showLabels
showTicks
zones={[
{ label: "Low", from: 60, to: 90, color: "var(--chart-3)" },
{ label: "Normal", from: 90, to: 120, color: "var(--success)" },
{ label: "High", from: 120, to: 160, color: "var(--warning)" },
{ label: "Very high", from: 160, to: 200, color: "var(--destructive)" },
]}
/>
)
}Installation
npx shadcn@latest add @vcare/segmented-meterOr install directly from the URL: https://ui.vcarehms.com/r/segmented-meter.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/segmented-meter.tsx
import * as React from 'react';
import { cn } from '@/registry/vcare/lib/utils';
import { formatNumber } from '@/registry/vcare/lib/format';
export interface MeterZone {
label?: string;
from: number;
to: number;
/** Any CSS color. Defaults to chart-1. */
color?: string;
}
export interface SegmentedMeterProps extends React.ComponentProps<'div'> {
value: number;
zones: MeterZone[];
/** Only color the zone that contains the value; others stay muted. */
highlightActive?: boolean;
/** Show zone boundary values under the bar. */
showTicks?: boolean;
/** Show zone labels under the bar. */
showLabels?: boolean;
/** Show a marker at the current value. */
showMarker?: boolean;
tickFormatter?: (value: number) => string;
}
function SegmentedMeter({
value,
zones,
highlightActive = true,
showTicks = true,
showLabels = false,
showMarker = true,
tickFormatter = (v) => formatNumber(v),
className,
...props
}: SegmentedMeterProps) {
const min = Math.min(...zones.map((z) => z.from));
const max = Math.max(...zones.map((z) => z.to));
const span = max - min || 1;
const position = Math.min(1, Math.max(0, (value - min) / span));
const activeIndex = zones.findIndex((z, i) => value >= z.from && (value < z.to || (i === zones.length - 1 && value <= z.to)));
return (
<div
data-slot="segmented-meter"
role="meter"
aria-valuemin={min}
aria-valuemax={max}
aria-valuenow={value}
className={cn('flex flex-col gap-1.5', className)}
{...props}
>
<div className="relative">
<div className="flex h-2 w-full gap-0.5">
{zones.map((zone, index) => {
const active = index === activeIndex;
const color = zone.color ?? 'var(--chart-1)';
return (
<div
key={index}
data-active={active}
className="bg-muted h-full rounded-sm transition-colors first:rounded-l-full last:rounded-r-full"
style={{
width: `${((zone.to - zone.from) / span) * 100}%`,
backgroundColor: !highlightActive || active ? color : undefined,
}}
/>
);
})}
</div>
{showMarker ? (
<div
aria-hidden="true"
className="bg-foreground ring-background absolute top-1/2 size-3 -translate-x-1/2 -translate-y-1/2 rounded-full ring-2"
style={{ left: `${position * 100}%` }}
/>
) : null}
</div>
{showTicks || showLabels ? (
<div className="text-muted-foreground relative h-4 text-[10px] tabular-nums">
{showTicks
? [min, ...zones.map((z) => z.to)].map((tick, index, all) => (
<span
key={index}
className={cn(
'absolute top-0',
index === 0 && 'left-0',
index === all.length - 1 && 'right-0',
index > 0 && index < all.length - 1 && '-translate-x-1/2',
)}
style={index > 0 && index < all.length - 1 ? { left: `${((tick - min) / span) * 100}%` } : undefined}
>
{tickFormatter(tick)}
</span>
))
: zones.map((zone, index) => (
<span
key={index}
className="absolute top-0 -translate-x-1/2 truncate"
style={{
left: `${(((zone.from + zone.to) / 2 - min) / span) * 100}%`,
}}
>
{zone.label}
</span>
))}
</div>
) : null}
</div>
);
}
export { SegmentedMeter };Usage
import { SegmentedMeter } from "@/components/ui/segmented-meter"Exports
SegmentedMeter
Dependencies
@vcare/format(registry)@vcare/utils(registry)
Raw item: /r/segmented-meter.json