Field
tdds/fieldFreeComponent
Composed form field system with label, description, and error support
Install it
npx shadcn@latest add https://raw.githubusercontent.com/gjohnsx/ttb-label-verification/main/tdds-registry/public/r/field.jsonSource
1"use client"23import { useMemo } from "react"4import { cva, type VariantProps } from "class-variance-authority"56import { cn } from "@/lib/utils"7import { Label } from "@/components/ui/label"8import { Separator } from "@/components/ui/separator"910function FieldSet({ className, ...props }: React.ComponentProps<"fieldset">) {11 return (12 <fieldset13 data-slot="field-set"14 className={cn("gap-6 has-[>[data-slot=checkbox-group]]:gap-3 has-[>[data-slot=radio-group]]:gap-3 flex flex-col", className)}15 {...props}16 />17 )18}1920function FieldLegend({21 className,22 variant = "legend",23 ...props24}: React.ComponentProps<"legend"> & { variant?: "legend" | "label" }) {25 return (26 <legend27 data-slot="field-legend"28 data-variant={variant}29 className={cn("mb-3 font-medium data-[variant=label]:text-sm data-[variant=legend]:text-base", className)}30 {...props}31 />32 )33}3435function FieldGroup({ className, ...props }: React.ComponentProps<"div">) {36 return (37 <div38 data-slot="field-group"39 className={cn(40 "gap-7 data-[slot=checkbox-group]:gap-3 [&>[data-slot=field-group]]:gap-4 group/field-group @container/field-group flex w-full flex-col",41 className42 )}43 {...props}44 />45 )46}4748const fieldVariants = cva("data-[invalid=true]:text-destructive gap-3 group/field flex w-full", {49 variants: {50 orientation: {51 vertical:52 "flex-col [&>*]:w-full [&>.sr-only]:w-auto",53 horizontal:54 "flex-row items-center [&>[data-slot=field-label]]:flex-auto has-[>[data-slot=field-content]]:items-start has-[>[data-slot=field-content]]:[&>[role=checkbox],[role=radio]]:mt-px",55 responsive:56 "flex-col [&>*]:w-full [&>.sr-only]:w-auto @md/field-group:flex-row @md/field-group:items-center @md/field-group:[&>*]:w-auto @md/field-group:[&>[data-slot=field-label]]:flex-auto @md/field-group:has-[>[data-slot=field-content]]:items-start @md/field-group:has-[>[data-slot=field-content]]:[&>[role=checkbox],[role=radio]]:mt-px",57 },58 },59 defaultVariants: {60 orientation: "vertical",61 },62})6364function Field({65 className,66 orientation = "vertical",67 ...props68}: React.ComponentProps<"div"> & VariantProps<typeof fieldVariants>) {69 return (70 <div71 role="group"72 data-slot="field"73 data-orientation={orientation}74 className={cn(fieldVariants({ orientation }), className)}75 {...props}76 />77 )78}7980// … truncated
What it pulls in
npm packages
Other registry items
Files it writes
More from tdds
All 43 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| Accordionaccordion | tdds | Components | Free | 2 deps | |
| Alertalert | tdds | Components | Free | 1 dep | |
| Alert Dialogalert-dialog | tdds | Components | Free | 1 dep | |
| Avataravatar | tdds | Components | Free | 1 dep | |
| Badgebadge | tdds | Components | Free | 1 dep | |
| Breadcrumbbreadcrumb | tdds | Components | Free | 2 deps | |
| Buttonbutton | tdds | Components | Free | 2 deps | |
| Button Groupbutton-group | tdds | Components | Free | 1 dep |
