tsf-time-field
shuip/tsf-time-fieldFreeComponent
shuip publishes no description for this item.
Install it
npx shadcn@latest add https://shuip.plvo.dev/r/tsf-time-field.jsonSource
1'use client';23import { Field, FieldDescription, FieldError, FieldLabel } from '@/components/ui/field';4import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '@/components/ui/select';5import { useFieldContext } from '@/components/ui/shuip/tanstack-form/form-context';6import { HOUR_OPTIONS, isHourDisabled, isMinuteDisabled, joinTime, MINUTE_OPTIONS, splitTime } from '@/lib/time';78export interface TimeFieldProps {9 label?: string;10 description?: string;11 min?: string;12 max?: string;13 disabled?: boolean;14 fieldProps?: React.ComponentProps<typeof Field>;15}1617export function TimeField({ label, description, min, max, disabled, fieldProps }: TimeFieldProps) {18 const field = useFieldContext<string>();19 const { isValid, errors } = field.state.meta;20 const { hour, minute } = splitTime(field.state.value ?? '');21 const bounds = { min, max };2223 return (24 <Field className='gap-2' data-invalid={!isValid} {...fieldProps}>25 {label && <FieldLabel htmlFor={field.name}>{label}</FieldLabel>}26 <div className='flex items-center gap-2'>27 <Select value={hour} onValueChange={(h) => field.handleChange(joinTime(h, minute))} disabled={disabled}>28 <SelectTrigger id={field.name} aria-invalid={!isValid} 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.handleChange(joinTime(hour, m))} disabled={disabled}>41 <SelectTrigger aria-invalid={!isValid} 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 {!isValid && (54 <FieldError55 className='text-xs text-left'56 errors={errors.map((error) => ({ message: typeof error === 'string' ? error : error?.message }))}57 />58 )}59 {description && <FieldDescription className='text-xs'>{description}</FieldDescription>}60// … truncated
What it pulls in
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 |
