Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 | /** * UI Component Standard Types * * Standard prop interfaces for consistent component APIs across the design system. * These types establish conventions for sizing, state, and common patterns. * * @example * ```tsx * import { StandardComponentProps, FormFieldProps, Size } from '@/components/ui/types'; * * interface MyInputProps extends FormFieldProps, StandardComponentProps { * // Component-specific props * } * ``` */ import * as React from 'react'; // ============================================================================= // SIZE SCALE // ============================================================================= /** * Standard size scale used across all sizable components. * Provides consistent sizing from extra-small to extra-large. */ export type Size = 'xs' | 'sm' | 'md' | 'lg' | 'xl'; /** * Common size scale (subset without xs/xl for simpler components) */ export type CommonSize = 'sm' | 'md' | 'lg'; // ============================================================================= // STATE PROPS // ============================================================================= /** * Standard state props for components with loading, disabled, or validation states. * Uses `is` prefix for boolean states as per naming conventions. */ export interface StateProps { /** Loading state - shows spinner and disables interaction */ isLoading?: boolean; /** Disabled state - prevents interaction */ isDisabled?: boolean; /** Error state - shows error styling */ isError?: boolean; /** Success state - shows success styling */ isSuccess?: boolean; } // ============================================================================= // FORM FIELD PROPS // ============================================================================= /** * Standard props for form field components (inputs, selects, textareas). * Includes label, helper text, error messaging, and accessibility props. */ export interface FormFieldProps extends StateProps { /** Field label displayed above the input */ label?: string; /** Helper text displayed below the input */ helperText?: string; /** Error message displayed when field has errors */ errorMessage?: string; /** Whether the field is required */ required?: boolean; /** Unique identifier for the field */ id?: string; /** Field name for form submission */ name?: string; /** Whether the field has been touched (for validation display) */ touched?: boolean; } // ============================================================================= // EVENT HANDLERS // ============================================================================= /** * Standard event handler naming conventions. * Uses `on` prefix for all event handlers. */ export interface EventHandlers<T = unknown> { /** Called when value changes */ onChange?: (value: T) => void; /** Called when field loses focus */ onBlur?: () => void; /** Called when field gains focus */ onFocus?: () => void; } // ============================================================================= // STYLE PROPS // ============================================================================= /** * Standard style props for custom styling. */ export interface StyleProps { /** Additional CSS classes */ className?: string; } // ============================================================================= // COMBINED STANDARD PROPS // ============================================================================= /** * Combined standard props for most components. * Includes size, state, and style props. */ export interface StandardComponentProps extends StateProps, StyleProps { /** Component size */ size?: CommonSize; /** Child elements */ children?: React.ReactNode; } /** * Extended standard props with full size scale. */ export interface ExtendedComponentProps extends StateProps, StyleProps { /** Component size (full scale) */ size?: Size; /** Child elements */ children?: React.ReactNode; } // ============================================================================= // ICON PROPS // ============================================================================= /** * Props for components that support left/right icons. */ export interface IconSlotProps { /** Icon displayed before content */ leftIcon?: React.ReactNode; /** Icon displayed after content */ rightIcon?: React.ReactNode; } // ============================================================================= // VARIANT PROPS // ============================================================================= /** * Common button/action variants */ export type ActionVariant = 'primary' | 'secondary' | 'outline' | 'ghost' | 'danger'; /** * Common status/state variants for feedback */ export type StatusVariant = 'default' | 'success' | 'warning' | 'error' | 'info'; /** * Common color variants */ export type ColorVariant = 'default' | 'primary' | 'secondary' | 'success' | 'warning' | 'error'; // ============================================================================= // LAYOUT PROPS // ============================================================================= /** * Common orientation options */ export type Orientation = 'horizontal' | 'vertical'; /** * Common alignment options */ export type Alignment = 'start' | 'center' | 'end'; /** * Common spacing scale */ export type Spacing = 'none' | 'xs' | 'sm' | 'md' | 'lg' | 'xl'; // ============================================================================= // SIZE STYLE MAPPINGS // ============================================================================= /** * Standard size class mappings for inputs */ export const inputSizeClasses: Record<CommonSize, string> = { sm: 'h-8 text-sm px-3', md: 'h-10 text-base px-4', lg: 'h-12 text-lg px-4', }; /** * Extended size class mappings for inputs */ export const inputSizeClassesExtended: Record<Size, string> = { xs: 'h-6 text-xs px-2', sm: 'h-8 text-sm px-3', md: 'h-10 text-base px-4', lg: 'h-12 text-lg px-4', xl: 'h-14 text-xl px-5', }; /** * Standard size class mappings for buttons */ export const buttonSizeClasses: Record<CommonSize, string> = { sm: 'px-4 py-2.5 text-sm min-h-[44px]', md: 'px-5 py-3 text-base min-h-[44px]', lg: 'px-6 py-3.5 text-lg min-h-[48px]', }; /** * Standard size class mappings for text */ export const textSizeClasses: Record<Size, string> = { xs: 'text-xs', sm: 'text-sm', md: 'text-base', lg: 'text-lg', xl: 'text-xl', }; // ============================================================================= // UTILITY TYPES // ============================================================================= /** * Make specific props required */ export type WithRequired<T, K extends keyof T> = T & { [P in K]-?: T[P] }; /** * Remove props from a type */ export type Without<T, K extends keyof T> = Pick<T, Exclude<keyof T, K>>; /** * Polymorphic component props helper */ export type PolymorphicRef<C extends React.ElementType> = React.ComponentPropsWithRef<C>['ref']; export type PolymorphicComponentProps< C extends React.ElementType, Props = Record<string, unknown> > = Props & { as?: C; } & Omit<React.ComponentPropsWithoutRef<C>, keyof Props | 'as'>; |