Input
Form input and textarea primitives with consistent styling.
Dependencies
clsxtailwind-merge
Props
This is a base primitive. It accepts standard HTML attributes plus className for styling via cn().
Source
import * as React from "react";
import { cn } from "@/lib/utils";
export interface InputProps extends React.InputHTMLAttributes<HTMLInputElement> {}
const Input = React.forwardRef<HTMLInputElement, InputProps>(
({ className, type, ...props }, ref) => {
return (
<input
type={type}
className={cn(
"flex h-9 w-full rounded-md border border-gray-200 bg-white px-3 py-2 text-sm",
"ring-offset-white placeholder:text-gray-500",
"focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-gray-900",
"disabled:cursor-not-allowed disabled:opacity-50",
className,
)}
ref={ref}
{...props}
/>
);
},
);
Input.displayName = "Input";
export interface TextareaProps extends React.TextareaHTMLAttributes<HTMLTextAreaElement> {}
const Textarea = React.forwardRef<HTMLTextAreaElement, TextareaProps>(
({ className, ...props }, ref) => {
return (
<textarea
className={cn(
"flex min-h-20 w-full rounded-md border border-gray-200 bg-white px-3 py-2 text-sm",
"ring-offset-white placeholder:text-gray-500",
"focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-gray-900",
"disabled:cursor-not-allowed disabled:opacity-50",
className,
)}
ref={ref}
{...props}
/>
);
},
);
Textarea.displayName = "Textarea";
export { Input, Textarea };
CLI
npx genui add input