Form Field Wrapper
shadcn-glass-ui/form-field-wrapperFreeUtility
Unified wrapper for form controls with label, validation states, and messages. * Eliminates code duplication across InputGlass, SliderGlass, ComboBoxGlass, etc. * * Handles:
Install it
npx shadcn@latest add https://raw.githubusercontent.com/artyhoo/shadcn-glass-ui-library/main/public/r/form-field-wrapper.jsonSource
1/**2 * FormFieldWrapper Component3 *4 * Unified wrapper for form controls with label, validation states, and messages.5 * Eliminates code duplication across InputGlass, SliderGlass, ComboBoxGlass, etc.6 *7 * Handles:8 * - Label with optional required indicator9 * - Error messages (highest priority, red)10 * - Success messages (green, shown if no error)11 * - Consistent spacing and typography12 */1314import { forwardRef, type ReactNode, type HTMLAttributes } from 'react';15import { cn } from '@/lib/utils';1617/**18 * Props for the FormFieldWrapper component19 */20export interface FormFieldWrapperProps extends HTMLAttributes<HTMLDivElement> {21 /**22 * Label text displayed above the field23 */24 label?: string;2526 /**27 * Error message - takes priority over success28 * Displays in red below the field29 */30 error?: string;3132 /**33 * Success message - displays in green if no error34 * Displays below the field35 */36 success?: string;3738 /**39 * ID to link label with input via htmlFor40 * Should match the input's id attribute41 */42 htmlFor?: string;4344 /**45 * Shows red asterisk (*) next to label46 * @default false47 */48 required?: boolean;4950 /**51 * The form control element(s) to wrap52 */53 children: ReactNode;54}5556/**57 * FormFieldWrapper component58 *59 * Provides consistent structure for form fields with labels and validation messages.60 * Used by InputGlass, SliderGlass, and other form components.61 *62 * @example63 * ```tsx64 * // Basic usage65 * <FormFieldWrapper label="Email" htmlFor="email-input">66 * <input id="email-input" type="email" />67 * </FormFieldWrapper>68 *69 * // With validation70 * <FormFieldWrapper71 * label="Username"72 * error="Username is required"73 * required74 * htmlFor="username"75 * >76 * <input id="username" />77 * </FormFieldWrapper>78 *79 * // Success state80 * <FormFieldWrapper81 * label="Password"82 * success="Strong password"83 * htmlFor="password"84 * >85 * <input id="password" type="password" />86 * </FormFieldWrapper>87 * ```88 */89export const FormFieldWrapper = forwardRef<HTMLDivElement, FormFieldWrapperProps>(90 (91 {92 label,93 error,94 success,95 htmlFor,96 required,97 className,98 children,99 ...props100 },101 ref102 ) => {103 return (104 <div105 ref={ref}106 className={cn('flex flex-col gap-1 md:gap-1.5', className)}107 {...props}108 >109 {label && (110 <label111 htmlFor={htmlFor}112 className="text-xs md:text-sm font-medium"113// … truncated
More from shadcn-glass-ui
All 76 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| Interactive Cardinteractive-card | shadcn-glass-ui | Utilities | Free | no deps | |
| Touch Targettouch-target | shadcn-glass-ui | Utilities | Free | no deps |
