tsf-time-range
shuip/tsf-time-rangeFreeComponent
shuip publishes no description for this item.
Install it
npx shadcn@latest add https://shuip.plvo.dev/r/tsf-time-range.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 {7 addOneHour,8 HOUR_OPTIONS,9 isHourDisabled,10 isMinuteDisabled,11 joinTime,12 MINUTE_OPTIONS,13 nextSlot,14 splitTime,15 type TimeRangeValue,16} from '@/lib/time';1718interface TimePickerProps {19 id?: string;20 value: string;21 onChange: (value: string) => void;22 min?: string;23 disabled?: boolean;24 invalid?: boolean;25}2627function TimePicker({ id, value, onChange, min, disabled, invalid }: TimePickerProps) {28 const { hour, minute } = splitTime(value);29 const bounds = { min };3031 return (32 <div className='flex items-center gap-2'>33 <Select value={hour} onValueChange={(h) => onChange(joinTime(h, minute))} disabled={disabled}>34 <SelectTrigger id={id} aria-invalid={invalid} className='w-full'>35 <SelectValue placeholder='HH' />36 </SelectTrigger>37 <SelectContent>38 {HOUR_OPTIONS.map((h) => (39 <SelectItem key={h} value={h} disabled={isHourDisabled(h, bounds)}>40 {h}41 </SelectItem>42 ))}43 </SelectContent>44 </Select>45 <span className='text-muted-foreground'>:</span>46 <Select value={minute} onValueChange={(m) => onChange(joinTime(hour, m))} disabled={disabled}>47 <SelectTrigger aria-invalid={invalid} className='w-full'>48 <SelectValue placeholder='mm' />49 </SelectTrigger>50 <SelectContent>51 {MINUTE_OPTIONS.map((m) => (52 <SelectItem key={m} value={m} disabled={isMinuteDisabled(m, hour, bounds)}>53 {m}54 </SelectItem>55 ))}56 </SelectContent>57 </Select>58 </div>59 );60}6162export interface TimeRangeFieldProps {63 label?: string;64 description?: string;65 startLabel?: string;66 endLabel?: string;67 disabled?: boolean;68 fieldProps?: React.ComponentProps<typeof Field>;69}7071export function TimeRangeField({72 label,73 description,74 startLabel = 'Start',75 endLabel = 'End',76 disabled,77 fieldProps,78}: TimeRangeFieldProps) {79 const field = useFieldContext<TimeRangeValue>();80 const { isValid, errors } = field.state.meta;81 const value: TimeRangeValue = field.state.value ?? { start: '', end: '' };8283 return (84 <Field className='gap-2' data-invalid={!isValid} {...fieldProps}>85// … 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 |
