Field
blok/fieldFreeComponent
Combine labels, controls, and help text to compose accessible form fields and grouped inputs.
Install it
npx shadcn@latest add https://blok.sitecore.com/r/field.jsonSource
1import { cn } from "@/lib/utils";2import { type VariantProps, cva } from "class-variance-authority";3import type * as React from "react";45// FieldSet - Container that renders a semantic fieldset6function FieldSet({ className, ...props }: React.ComponentProps<"fieldset">) {7 return (8 <fieldset9 data-slot="fieldset"10 className={cn("flex flex-col gap-2", className)}11 {...props}12 />13 );14}1516// FieldLegend - Legend element for a FieldSet17const fieldLegendVariants = cva("", {18 variants: {19 variant: {20 legend: "text-lg font-semibold",21 label: "text-md font-medium",22 },23 },24 defaultVariants: {25 variant: "legend",26 },27});2829function FieldLegend({30 className,31 variant = "legend",32 ...props33}: React.ComponentProps<"legend"> & VariantProps<typeof fieldLegendVariants>) {34 return (35 <legend36 data-slot="field-legend"37 className={cn(fieldLegendVariants({ variant }), className)}38 {...props}39 />40 );41}4243// FieldGroup - Layout wrapper that stacks Field components44function FieldGroup({ className, ...props }: React.ComponentProps<"div">) {45 return (46 <div47 data-slot="field-group"48 className={cn("flex flex-col gap-3 mt-5", className)}49 {...props}50 />51 );52}5354// Field - Core wrapper for a single field55const fieldVariants = cva("flex gap-2", {56 variants: {57 orientation: {58 vertical: "flex-col gap-2.5",59 horizontal: "flex-row items-center gap-4",60 responsive:61 "flex-col gap-2.5 @container/field-group:flex-row @container/field-group:items-center @container/field-group:gap-4",62 },63 },64 defaultVariants: {65 orientation: "vertical",66 },67});6869function Field({70 className,71 orientation = "vertical",72 "data-invalid": dataInvalid,73 ...props74}: React.ComponentProps<"div"> &75 VariantProps<typeof fieldVariants> & {76 "data-invalid"?: boolean;77 }) {78 return (79 <div80 data-slot="field"81 role="group"82 data-invalid={dataInvalid}83 className={cn(84 fieldVariants({ orientation }),85 dataInvalid &&86 "data-[invalid=true]:[&_input]:border-destructive data-[invalid=true]:[&_select]:border-destructive data-[invalid=true]:[&_textarea]:border-destructive",87 className,88 )}89 {...props}90 />91 );92}9394// FieldContent - Flex column that groups label and description95function FieldContent({ className, ...props }: React.ComponentProps<"div">) {96 return (97 <div98 data-slot="field-content"99// … truncated
What it pulls in
npm packages
Other registry items
Files it writes
More from blok
All 72 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| Accordionaccordion | blok | Components | Free | 2 deps · 2 files | |
| Action baraction-bar | blok | Components | Free | 1 dep · 2 files | |
| Alertalert | blok | Components | Free | 2 deps · 2 files | |
| Alert dialogalert-dialog | blok | Components | Free | 2 deps | |
| Aspect ratioaspect-ratio | blok | Components | Free | 1 dep | |
| Avataravatar | blok | Components | Free | 1 dep | |
| Badgebadge | blok | Components | Free | 2 deps | |
| All componentsblok-components | blok | Components | Free | no deps |
