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
Patterns
Time Picker
A time control in 12 or 24 hour format.
import { useState } from "react"
import { TimePicker } from "@/registry/vcare/ui/time-picker"
export default function TimePickerDemo() {
const [t, setT] = useState("09:30")
return <TimePicker className="w-48" value={t} onChange={setT} clearable />
}Installation
npx shadcn@latest add @vcare/time-pickerOr install directly from the URL: https://ui.vcarehms.com/r/time-picker.json
- Install the dependencies:
npm i lucide-react - Add the registry items it uses: button, i18n, popover, select, system, utils.
- Copy this file into your project and change the
@/registry/vcare/…imports to your own paths.
components/ui/time-picker.tsx
import { useState } from 'react';
import { useTranslation } from '@/registry/vcare/lib/i18n';
import { Clock } from 'lucide-react';
import { Button } from '@/registry/vcare/ui/button';
import { Popover, PopoverContent, PopoverTrigger } from '@/registry/vcare/ui/popover';
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '@/registry/vcare/ui/select';
import { useSettings } from '@/registry/vcare/lib/system';
import { cn } from '@/registry/vcare/lib/utils';
const pad = (n: number) => String(n).padStart(2, '0');
/** A themed time control; values remain HH:mm, including arbitrary minute precision. */
export function TimePicker({
value,
onChange,
disabled,
clearable,
className,
id,
...aria
}: {
value: string;
onChange: (v: string) => void;
disabled?: boolean;
clearable?: boolean;
className?: string;
id?: string;
'aria-describedby'?: string;
'aria-invalid'?: boolean;
'aria-required'?: boolean;
'aria-label'?: string;
}) {
const { t, i18n } = useTranslation();
const hour12 = useSettings().localization.timeFormat === '12h';
const [open, setOpen] = useState(false);
const valid = /^([01]\d|2[0-3]):[0-5]\d$/.test(value);
const [hour, minute] = valid ? value.split(':') : ['', ''];
const hourCycle = hour12 ? 'h12' : 'h23';
const hourLabel = (h: number) =>
new Intl.DateTimeFormat(i18n.language, {
hour: 'numeric',
hourCycle,
}).format(new Date(2024, 0, 1, h));
const label = valid
? new Intl.DateTimeFormat(i18n.language, {
hour: 'numeric',
minute: '2-digit',
hourCycle,
}).format(new Date(2024, 0, 1, Number(hour), Number(minute)))
: t('datePicker.selectTime');
return (
<Popover open={open} onOpenChange={setOpen}>
<PopoverTrigger asChild>
<button
type="button"
id={id}
disabled={disabled}
{...aria}
className={cn(
'flex h-control w-full min-w-0 items-center justify-between gap-2 rounded-lg border border-input bg-transparent px-2.5 text-start text-sm transition-[color,box-shadow,border-color] duration-150 hover:border-ring/60 focus-visible:border-ring focus-visible:outline-none focus-visible:ring-[3px] focus-visible:ring-ring/30 disabled:cursor-not-allowed disabled:opacity-50',
className,
)}
>
<span className={cn('truncate tabular-nums', !valid && 'text-muted-foreground')}>{label}</span>
<Clock className="size-4 shrink-0 text-subtle" />
</button>
</PopoverTrigger>
<PopoverContent align="start" className="w-64 space-y-3 p-3">
<div className="grid grid-cols-2 gap-3">
<div className="space-y-1.5">
<span className="text-xs text-muted-foreground">{t('datePicker.hour')}</span>
<Select value={hour} onValueChange={(h) => onChange(`${h}:${minute || '00'}`)}>
<SelectTrigger className="w-full" aria-label={t('datePicker.hour')}>
<SelectValue placeholder="—" />
</SelectTrigger>
<SelectContent>
{Array.from({ length: 24 }, (_, h) => (
<SelectItem key={h} value={pad(h)}>
{hourLabel(h)}
</SelectItem>
))}
</SelectContent>
</Select>
</div>
<div className="space-y-1.5">
<span className="text-xs text-muted-foreground">{t('datePicker.minute')}</span>
<Select value={minute} onValueChange={(m) => onChange(`${hour || '00'}:${m}`)}>
<SelectTrigger className="w-full" aria-label={t('datePicker.minute')}>
<SelectValue placeholder="—" />
</SelectTrigger>
<SelectContent>
{Array.from({ length: 60 }, (_, m) => (
<SelectItem key={m} value={pad(m)}>
{pad(m)}
</SelectItem>
))}
</SelectContent>
</Select>
</div>
</div>
<div className="flex justify-end gap-2">
{clearable && valid && (
<Button
variant="ghost"
size="sm"
onClick={() => {
onChange('');
setOpen(false);
}}
>
{t('datePicker.clear')}
</Button>
)}
<Button variant="secondary" size="sm" onClick={() => setOpen(false)}>
{t('datePicker.done')}
</Button>
</div>
</PopoverContent>
</Popover>
);
}Usage
import { TimePicker } from "@/components/ui/time-picker"Exports
TimePicker
Dependencies
lucide-react@^1.80.0(npm)@vcare/button(registry)@vcare/i18n(registry)@vcare/popover(registry)@vcare/select(registry)@vcare/system(registry)@vcare/utils(registry)
Raw item: /r/time-picker.json