rhf-radio-field
shuip/rhf-radio-fieldFreeComponent
shuip publishes no description for this item.
Live preview
live · rendered by the registry
Rendered by shuip on their own page — this is the component running, not a screenshot of it.Install it
npx shadcn@latest add https://shuip.plvo.dev/r/rhf-radio-field.jsonSource
1'use client';23import type { Lens } from '@hookform/lenses';4import type * as React from 'react';5import { useController } from 'react-hook-form';6import { Field, FieldDescription, FieldError, FieldLabel } from '@/components/ui/field';7import { Label } from '@/components/ui/label';8import { RadioGroup, RadioGroupItem } from '@/components/ui/radio-group';910export interface RadioFieldProps11 extends Omit<React.ComponentProps<typeof RadioGroup>, 'value' | 'defaultValue' | 'onValueChange'> {12 lens: Lens<string>;13 options: string[];14 label?: string;15 description?: string;16}1718export function RadioField({ lens, options, label, description, ...props }: RadioFieldProps) {19 const { field, fieldState } = useController(lens.interop());2021 return (22 <Field className='gap-2' data-invalid={fieldState.invalid}>23 {label && <FieldLabel>{label}</FieldLabel>}24 <RadioGroup25 name={field.name}26 value={field.value ?? ''}27 onValueChange={field.onChange}28 onBlur={field.onBlur}29 className='flex flex-col space-y-1'30 aria-invalid={fieldState.invalid}31 {...props}32 >33 {options.map((value) => (34 <div key={value} className='flex items-center space-x-3 space-y-0'>35 <RadioGroupItem id={`${field.name}-${value}`} value={value} aria-invalid={fieldState.invalid} />36 <Label htmlFor={`${field.name}-${value}`} className='font-normal'>37 {value}38 </Label>39 </div>40 ))}41 </RadioGroup>42 {fieldState.invalid && <FieldError className='text-xs text-left' errors={[fieldState.error]} />}43 {description && <FieldDescription className='text-xs'>{description}</FieldDescription>}44 </Field>45 );46}
What it pulls in
npm packages
Other registry items
Files it writes
More from shuip
All 52 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| confirmation-dialogconfirmation-dialog | shuip | Components | Free | 1 dep | |
| copy-buttoncopy-button | shuip | Components | Free | 3 deps | |
| hover-revealhover-reveal | shuip | Components | Free | 1 dep | |
| rhf-address-fieldrhf-address-field | shuip | Components | Free | 5 deps · 2 files | |
| rhf-autocomplete-fieldrhf-autocomplete-field | shuip | Components | Free | 4 deps | |
| rhf-checkbox-fieldrhf-checkbox-field | shuip | Components | Free | 3 deps | |
| rhf-combobox-fieldrhf-combobox-field | shuip | Components | Free | 5 deps | |
| rhf-date-fieldrhf-date-field | shuip | Components | Free | 6 deps |
