rhf-time-field
shuip/rhf-time-fieldFreeComponent
shuip publishes no description for this item.
Install it
npx shadcn@latest add https://shuip.plvo.dev/r/rhf-time-field.jsonSource
1'use client';23import type { Lens } from '@hookform/lenses';4import { useController } from 'react-hook-form';5import { Field, FieldDescription, FieldError, FieldLabel } from '@/components/ui/field';6import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '@/components/ui/select';7import { HOUR_OPTIONS, isHourDisabled, isMinuteDisabled, joinTime, MINUTE_OPTIONS, splitTime } from '@/lib/time';89export interface TimeFieldProps {10 lens: Lens<string>;11 label?: string;12 description?: string;13 min?: string;14 max?: string;15 disabled?: boolean;16}1718export function TimeField({ lens, label, description, min, max, disabled }: TimeFieldProps) {19 const { field, fieldState } = useController(lens.interop());20 const { hour, minute } = splitTime(field.value ?? '');21 const bounds = { min, max };2223 return (24 <Field className='gap-2' data-invalid={fieldState.invalid}>25 {label && <FieldLabel htmlFor={field.name}>{label}</FieldLabel>}26 <div className='flex items-center gap-2'>27 <Select value={hour} onValueChange={(h) => field.onChange(joinTime(h, minute))} disabled={disabled}>28 <SelectTrigger id={field.name} aria-invalid={fieldState.invalid} className='w-full'>29 <SelectValue placeholder='HH' />30 </SelectTrigger>31 <SelectContent>32 {HOUR_OPTIONS.map((h) => (33 <SelectItem key={h} value={h} disabled={isHourDisabled(h, bounds)}>34 {h}35 </SelectItem>36 ))}37 </SelectContent>38 </Select>39 <span className='text-muted-foreground'>:</span>40 <Select value={minute} onValueChange={(m) => field.onChange(joinTime(hour, m))} disabled={disabled}>41 <SelectTrigger aria-invalid={fieldState.invalid} className='w-full'>42 <SelectValue placeholder='mm' />43 </SelectTrigger>44 <SelectContent>45 {MINUTE_OPTIONS.map((m) => (46 <SelectItem key={m} value={m} disabled={isMinuteDisabled(m, hour, bounds)}>47 {m}48 </SelectItem>49 ))}50 </SelectContent>51 </Select>52 </div>53 {fieldState.invalid && <FieldError className='text-xs text-left' errors={[fieldState.error]} />}54 {description && <FieldDescription className='text-xs'>{description}</FieldDescription>}55 </Field>56 );57}
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 |
