rhf-combobox-field
shuip/rhf-combobox-fieldFreeComponent
shuip publishes no description for this item.
Install it
npx shadcn@latest add https://shuip.plvo.dev/r/rhf-combobox-field.jsonSource
1'use client';23import type { Lens } from '@hookform/lenses';4import { Command as CommandPrimitive } from 'cmdk';5import { Check, Loader2, Search, X } from 'lucide-react';6import * as React from 'react';7import { useController } from 'react-hook-form';8import { Badge } from '@/components/ui/badge';9import { Command, CommandGroup, CommandItem, CommandList } from '@/components/ui/command';10import { Field, FieldDescription, FieldError, FieldLabel } from '@/components/ui/field';11import { cn } from '@/lib/utils';1213const DEBOUNCE_TIME = 300;1415export interface ComboboxOption {16 value: string;17 label: string;18 sublabel?: string;19}2021type ComboboxFieldVariant = 'boxed' | 'ghost';22type ComboboxFieldSize = 'sm' | 'default';2324type ComboboxFieldCommonProps = {25 options?: ComboboxOption[];26 onSearch?: (query: string) => Promise<ComboboxOption[]>;27 maxResults?: number;28 variant?: ComboboxFieldVariant;29 size?: ComboboxFieldSize;30 label?: string;31 description?: string;32 placeholder?: string;33 emptyText?: string;34 debounceMs?: number;35};3637export type ComboboxFieldProps =38 | (ComboboxFieldCommonProps & {39 multiple?: false;40 lens: Lens<string>;41 defaultSelected?: ComboboxOption;42 })43 | (ComboboxFieldCommonProps & {44 multiple: true;45 lens: Lens<string[]>;46 defaultSelected?: ComboboxOption[];47 });4849const shellVariants: Record<ComboboxFieldVariant, string> = {50 boxed:51 'rounded-md border border-input bg-transparent shadow-xs focus-within:border-ring focus-within:ring-ring/50 focus-within:ring-[3px] aria-invalid:border-destructive aria-invalid:ring-destructive/20',52 ghost: 'rounded-md border border-transparent bg-transparent',53};5455const shellSizes: Record<ComboboxFieldSize, string> = {56 default: 'min-h-9 gap-1.5 px-2 py-1 text-sm',57 sm: 'min-h-7 gap-1 px-1.5 py-0.5 text-xs',58};5960function toArray(value: string | string[] | undefined | null): string[] {61 if (Array.isArray(value)) return value;62 if (value) return [value];63 return [];64}6566export function ComboboxField(props: ComboboxFieldProps) {67 const {68 multiple = false,69 options,70 onSearch,71 maxResults,72 variant = 'boxed',73 size = 'default',74 label,75 description,76 placeholder,77 emptyText = 'No results',78 debounceMs = DEBOUNCE_TIME,79 defaultSelected,80 } = props;8182 // The discriminated union ties the lens type to `multiple`; values are normalised through83// … truncated
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-date-fieldrhf-date-field | shuip | Components | Free | 6 deps | |
| rhf-date-range-fieldrhf-date-range-field | shuip | Components | Free | 6 deps |
