Field
boldkit/fieldFreeComponent
Form field composition: label, control, description and error
Live preview
live · rendered by the registry
Rendered by boldkit on their own page — this is the component running, not a screenshot of it.Install it
npx shadcn@latest add https://boldkit.dev/r/field.jsonSource
1import * as React from 'react'2import { cn } from '@/lib/utils'3import { Label } from '@/components/ui/label'45/** A vertical stack of related fields. */6const FieldGroup = React.forwardRef<7 HTMLDivElement,8 React.HTMLAttributes<HTMLDivElement>9>(({ className, ...props }, ref) => (10 <div ref={ref} className={cn('flex flex-col gap-5', className)} {...props} />11))12FieldGroup.displayName = 'FieldGroup'1314/** A single form field: groups a label, control, description and error. */15const Field = React.forwardRef<16 HTMLDivElement,17 React.HTMLAttributes<HTMLDivElement>18>(({ className, ...props }, ref) => (19 <div ref={ref} className={cn('flex flex-col gap-1.5', className)} {...props} />20))21Field.displayName = 'Field'2223const FieldLabel = React.forwardRef<24 React.ElementRef<typeof Label>,25 React.ComponentPropsWithoutRef<typeof Label>26>(({ className, ...props }, ref) => (27 <Label ref={ref} className={cn('text-xs', className)} {...props} />28))29FieldLabel.displayName = 'FieldLabel'3031const FieldDescription = React.forwardRef<32 HTMLParagraphElement,33 React.HTMLAttributes<HTMLParagraphElement>34>(({ className, ...props }, ref) => (35 <p36 ref={ref}37 className={cn('text-xs font-medium text-muted-foreground', className)}38 {...props}39 />40))41FieldDescription.displayName = 'FieldDescription'4243const FieldError = React.forwardRef<44 HTMLParagraphElement,45 React.HTMLAttributes<HTMLParagraphElement>46>(({ className, children, ...props }, ref) => {47 if (!children) return null48 return (49 <p50 ref={ref}51 role="alert"52 className={cn(53 'text-xs font-bold uppercase tracking-wide text-destructive',54 className55 )}56 {...props}57 >58 {children}59 </p>60 )61})62FieldError.displayName = 'FieldError'6364export { Field, FieldGroup, FieldLabel, FieldDescription, FieldError }
What it pulls in
Other registry items
Files it writes
More from boldkit
All 94 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| Accordionaccordion | boldkit | Components | Free | 2 deps | |
| Alertalert | boldkit | Components | Free | 2 deps | |
| Alert Dialogalert-dialog | boldkit | Components | Free | 1 dep | |
| ASCII Shapesascii-shapes | boldkit | Components | Free | no deps | |
| Aspect Ratioaspect-ratio | boldkit | Components | Free | 1 dep | |
| Avataravatar | boldkit | Components | Free | 1 dep | |
| Badgebadge | boldkit | Components | Free | 1 dep | |
| Breadcrumbbreadcrumb | boldkit | Components | Free | 2 deps |
