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
Primitives
Input
A text field, with number handling built in.
import { Input } from "@/registry/vcare/ui/input"
import { Label } from "@/registry/vcare/ui/label"
export default function InputDemo() {
return (
<div className="mx-auto grid w-full max-w-sm gap-4">
<div className="grid gap-1.5">
<Label htmlFor="mobile">Mobile number</Label>
<Input id="mobile" inputMode="tel" placeholder="90000 00000" />
</div>
<div className="grid gap-1.5">
<Label htmlFor="fee">Consultation fee</Label>
<Input id="fee" type="number" defaultValue={500} />
</div>
<Input disabled placeholder="Disabled" />
</div>
)
}Installation
npx shadcn@latest add @vcare/inputOr install directly from the URL: https://ui.vcarehms.com/r/input.json
- Add the registry items it uses: utils.
- Copy this file into your project and change the
@/registry/vcare/…imports to your own paths.
components/ui/input.tsx
import * as React from 'react';
import { cn } from '@/registry/vcare/lib/utils';
/** True when the text in a number box already means the value the form holds ('' counts as 0 or empty). */
function sameNumber(text: string, value: unknown) {
const t = text.trim();
if (t === '') return value === '' || value == null || Number(value) === 0;
const n = Number(t);
return !Number.isNaN(n) && n === Number(value);
}
/**
* Number boxes are often bound as `Number(e.target.value)`, which turns an emptied box back into 0 and lets typing
* build "020". The box remembers what the person typed and keeps showing it while it means the same number, and it
* drops leading zeros, so the box can be cleared and retyped normally.
*/
function Input({ className, type, value, onChange, ...props }: React.ComponentProps<'input'>) {
const [draft, setDraft] = React.useState<string | null>(null);
let shown = value;
if (type === 'number' && value !== undefined) {
if (draft !== null && sameNumber(draft, value)) shown = draft;
else if (value === null) shown = '';
if (typeof shown === 'string') shown = shown.replace(/^(-?)0+(?=\d)/, '$1');
}
return (
<input
type={type}
data-slot="input"
className={cn(
'h-control w-full min-w-0 rounded-2xl border border-input bg-muted/50 px-3.5 py-0 text-sm focus-visible:bg-card transition-[color,box-shadow,border-color] duration-150 ease-power3-out outline-none selection:bg-primary selection:text-primary-foreground file:inline-flex file:h-7 file:border-0 file:bg-transparent file:text-sm file:font-medium file:text-foreground placeholder:text-muted-foreground disabled:pointer-events-none disabled:cursor-not-allowed disabled:opacity-50',
'focus-visible:border-ring focus-visible:ring-2 focus-visible:ring-ring/40',
'aria-invalid:border-destructive aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40',
className,
)}
value={shown}
onChange={
type === 'number' && onChange
? (e) => {
setDraft(e.target.value);
onChange(e);
}
: onChange
}
{...props}
/>
);
}
export { Input };Usage
import { Input } from "@/components/ui/input"Exports
Input
Dependencies
@vcare/utils(registry)
Raw item: /r/input.json