{"name":"field","dependencies":["class-variance-authority"],"registryDependencies":["@herocn/label","@herocn/separator"],"files":[{"path":"field.tsx","content":"\"use client\";\n\nimport { cva, type VariantProps } from \"class-variance-authority\";\nimport { cn } from \"cn\";\nimport { useMemo } from \"react\";\nimport { Label } from \"@/components/ui/label\";\nimport { Separator } from \"@/components/ui/separator\";\n\nfunction FieldSet({ className, ...props }: React.ComponentProps<\"fieldset\">) {\n\treturn (\n\t\t<fieldset\n\t\t\tdata-slot=\"field-set\"\n\t\t\tclassName={cn(\n\t\t\t\t\"flex flex-col gap-4 has-[>[data-slot=checkbox-group]]:gap-3 has-[>[data-slot=radio-group]]:gap-3\",\n\t\t\t\tclassName,\n\t\t\t)}\n\t\t\t{...props}\n\t\t/>\n\t);\n}\n\nfunction FieldLegend({\n\tclassName,\n\tvariant = \"legend\",\n\t...props\n}: React.ComponentProps<\"legend\"> & { variant?: \"legend\" | \"label\" }) {\n\treturn (\n\t\t<legend\n\t\t\tdata-slot=\"field-legend\"\n\t\t\tdata-variant={variant}\n\t\t\tclassName={cn(\n\t\t\t\t\"mb-1.5 font-medium data-[variant=label]:text-sm data-[variant=legend]:text-base\",\n\t\t\t\tclassName,\n\t\t\t)}\n\t\t\t{...props}\n\t\t/>\n\t);\n}\n\nfunction FieldGroup({ className, ...props }: React.ComponentProps<\"div\">) {\n\treturn (\n\t\t<div\n\t\t\tdata-slot=\"field-group\"\n\t\t\tclassName={cn(\n\t\t\t\t\"group/field-group @container/field-group flex w-full flex-col gap-5 data-[slot=checkbox-group]:gap-3 *:data-[slot=field-group]:gap-4\",\n\t\t\t\tclassName,\n\t\t\t)}\n\t\t\t{...props}\n\t\t/>\n\t);\n}\n\nconst fieldVariants = cva(\n\t\"group/field flex w-full gap-1 data-[invalid=true]:text-destructive\",\n\t{\n\t\tvariants: {\n\t\t\torientation: {\n\t\t\t\tvertical: \"flex-col *:w-full [&>.sr-only]:w-auto\",\n\t\t\t\thorizontal:\n\t\t\t\t\t\"flex-row items-center has-[>[data-slot=field-content]]:items-start *:data-[slot=field-label]:flex-auto has-[>[data-slot=field-content]]:[&>[role=checkbox],[role=radio]]:mt-px\",\n\t\t\t\tresponsive:\n\t\t\t\t\t\"@md/field-group:flex-row flex-col @md/field-group:items-center *:w-full @md/field-group:*:w-auto @md/field-group:has-[>[data-slot=field-content]]:items-start @md/field-group:*:data-[slot=field-label]:flex-auto [&>.sr-only]:w-auto @md/field-group:has-[>[data-slot=field-content]]:[&>[role=checkbox],[role=radio]]:mt-px\",\n\t\t\t},\n\t\t},\n\t\tdefaultVariants: {\n\t\t\torientation: \"vertical\",\n\t\t},\n\t},\n);\n\nfunction Field({\n\tclassName,\n\torientation = \"vertical\",\n\t...props\n}: React.ComponentProps<\"div\"> & VariantProps<typeof fieldVariants>) {\n\treturn (\n\t\t<div\n\t\t\trole=\"group\"\n\t\t\tdata-slot=\"field\"\n\t\t\tdata-orientation={orientation}\n\t\t\tclassName={cn(fieldVariants({ orientation }), className)}\n\t\t\t{...props}\n\t\t/>\n\t);\n}\n\nfunction FieldContent({ className, ...props }: React.ComponentProps<\"div\">) {\n\treturn (\n\t\t<div\n\t\t\tdata-slot=\"field-content\"\n\t\t\tclassName={cn(\n\t\t\t\t\"group/field-content flex flex-1 flex-col gap-0.5 leading-snug\",\n\t\t\t\tclassName,\n\t\t\t)}\n\t\t\t{...props}\n\t\t/>\n\t);\n}\n\nfunction FieldLabel({\n\tclassName,\n\t...props\n}: React.ComponentProps<typeof Label>) {\n\treturn (\n\t\t<Label\n\t\t\tdata-slot=\"field-label\"\n\t\t\tclassName={cn(\n\t\t\t\t\"group/field-label peer/field-label flex w-fit gap-2 leading-snug has-[>[data-slot=field]]:has-data-checked:border-primary has-[>[data-slot=field]]:has-data-checked:bg-primary/15 has-[>[data-slot=field]]:has-data-checked:shadow-none has-[>[data-slot=field]]:rounded-2xl has-[>[data-slot=field]]:border has-[>[data-slot=field]]:border-surface has-[>[data-slot=field]]:bg-surface has-[>[data-slot=field]]:shadow-xs has-[>[data-slot=field]]:transition-[background-color,border-color,opacity,transform] has-[>[data-slot=field]]:duration-200 *:data-[slot=field]:px-5 *:data-[slot=field]:py-4 group-data-[disabled=true]/field:opacity-50 motion-reduce:has-[>[data-slot=field]]:transition-none dark:has-[>[data-slot=field]]:has-data-checked:bg-primary/10\",\n\t\t\t\t\"has-[>[data-slot=field]]:w-full has-[>[data-slot=field]]:flex-col\",\n\t\t\t\tclassName,\n\t\t\t)}\n\t\t\t{...props}\n\t\t/>\n\t);\n}\n\nfunction FieldTitle({ className, ...props }: React.ComponentProps<\"div\">) {\n\treturn (\n\t\t<div\n\t\t\tdata-slot=\"field-label\"\n\t\t\tclassName={cn(\n\t\t\t\t\"flex w-fit items-center gap-2 font-medium text-sm leading-snug group-data-[disabled=true]/field:opacity-50\",\n\t\t\t\tclassName,\n\t\t\t)}\n\t\t\t{...props}\n\t\t/>\n\t);\n}\n\nfunction FieldDescription({ className, ...props }: React.ComponentProps<\"p\">) {\n\treturn (\n\t\t<p\n\t\t\tdata-slot=\"field-description\"\n\t\t\tclassName={cn(\n\t\t\t\t\"text-start font-normal text-muted-foreground text-xs leading-normal group-has-data-horizontal/field:text-balance [[data-variant=legend]+&]:-mt-1.5\",\n\t\t\t\t\"nth-last-2:-mt-1 last:mt-0\",\n\t\t\t\t\"[&>a:hover]:text-primary [&>a]:underline [&>a]:underline-offset-4\",\n\t\t\t\tclassName,\n\t\t\t)}\n\t\t\t{...props}\n\t\t/>\n\t);\n}\n\nfunction FieldSeparator({\n\tchildren,\n\tclassName,\n\t...props\n}: React.ComponentProps<\"div\"> & {\n\tchildren?: React.ReactNode;\n}) {\n\treturn (\n\t\t<div\n\t\t\tdata-slot=\"field-separator\"\n\t\t\tdata-content={!!children}\n\t\t\tclassName={cn(\n\t\t\t\t\"relative -my-2 h-5 text-sm group-data-[variant=outline]/field-group:-mb-2\",\n\t\t\t\tclassName,\n\t\t\t)}\n\t\t\t{...props}\n\t\t>\n\t\t\t<Separator className=\"absolute inset-0 top-1/2\" />\n\t\t\t{children && (\n\t\t\t\t<span\n\t\t\t\t\tclassName=\"relative mx-auto block w-fit bg-background px-2 text-muted-foreground\"\n\t\t\t\t\tdata-slot=\"field-separator-content\"\n\t\t\t\t>\n\t\t\t\t\t{children}\n\t\t\t\t</span>\n\t\t\t)}\n\t\t</div>\n\t);\n}\n\nfunction FieldError({\n\tclassName,\n\tchildren,\n\terrors,\n\t...props\n}: React.ComponentProps<\"div\"> & {\n\terrors?: Array<{ message?: string } | undefined>;\n}) {\n\tconst content = useMemo(() => {\n\t\tif (children) {\n\t\t\treturn children;\n\t\t}\n\n\t\tif (!errors?.length) {\n\t\t\treturn null;\n\t\t}\n\n\t\tconst uniqueErrors = [\n\t\t\t...new Map(errors.map((error) => [error?.message, error])).values(),\n\t\t];\n\n\t\tif (uniqueErrors?.length === 1) {\n\t\t\treturn uniqueErrors[0]?.message;\n\t\t}\n\n\t\treturn (\n\t\t\t<ul className=\"ms-4 flex list-disc flex-col gap-1\">\n\t\t\t\t{uniqueErrors.map(\n\t\t\t\t\t(error, index) =>\n\t\t\t\t\t\terror?.message && (\n\t\t\t\t\t\t\t<li key={`error-message-${index}`}>{error.message}</li>\n\t\t\t\t\t\t),\n\t\t\t\t)}\n\t\t\t</ul>\n\t\t);\n\t}, [children, errors]);\n\n\tif (!content) {\n\t\treturn null;\n\t}\n\n\treturn (\n\t\t<div\n\t\t\trole=\"alert\"\n\t\t\tdata-slot=\"field-error\"\n\t\t\tclassName={cn(\"font-normal text-destructive text-sm\", className)}\n\t\t\t{...props}\n\t\t>\n\t\t\t{content}\n\t\t</div>\n\t);\n}\n\nexport {\n\tField,\n\tFieldContent,\n\tFieldDescription,\n\tFieldError,\n\tFieldGroup,\n\tFieldLabel,\n\tFieldLegend,\n\tFieldSeparator,\n\tFieldSet,\n\tFieldTitle,\n};\n","type":"registry:ui"}],"type":"registry:ui"}