Skip to content

TachUI Forms Plugin Structure โ€‹

Comprehensive file-level documentation of packages/forms/

This document provides a complete overview of TachUI's Forms plugin structure, explaining the purpose and functionality of every file and directory in the packages/forms/ codebase.

๐Ÿ“‹ Overview โ€‹

Current Status: Production Ready - 13 TypeScript files, 7 test files, 176KB source

The @tachui/forms plugin extends TachUI's core functionality with advanced form handling, specialized input components, and comprehensive validation. It demonstrates TachUI's plugin architecture by providing enhanced form capabilities without bloating the core framework.

Key Features:

  1. Enhanced Input Components - 15+ specialized TextField variants with built-in validation
  2. Advanced Validation System - 18 built-in validation rules plus custom validator support
  3. Form State Management - Reactive form state with automatic validation and error handling
  4. Formatters & Parsers - Input formatters for phone numbers, credit cards, SSN, currency, etc.
  5. Accessibility Compliance - WCAG 2.1 AA compliant form components with screen reader support
  6. Performance Optimization - Tree-shakeable architecture with ~35KB bundle impact

The Forms plugin is organized into 4 main modules:

  1. Enhanced Components (components/) - Specialized form input components
  2. State Management (state/) - Form state and reactive data management
  3. Validation System (validation/) - Comprehensive validation framework
  4. Utility Functions (utils/) - Formatters, parsers, and helper functions

๐ŸŽฏ Root Level โ€‹

packages/forms/
โ”œโ”€โ”€ package.json               # Forms plugin package configuration
โ”œโ”€โ”€ tsconfig.json             # TypeScript configuration for development
โ”œโ”€โ”€ vite.config.ts            # Vite build configuration for plugin bundling
โ”œโ”€โ”€ vitest.config.ts          # Test configuration for Forms plugin
โ”œโ”€โ”€ dist/                     # Compiled plugin output (build artifacts)
โ”œโ”€โ”€ src/                      # Source code for all Forms functionality
โ””โ”€โ”€ __tests__/               # Comprehensive test suite

๐Ÿ“ Root File Details โ€‹

package.json โ€‹

Purpose: Forms plugin package configuration and dependencies
Functionality:

  • Package name: @tachui/forms as TachUI plugin
  • Peer dependency on @tachui/core for framework integration
  • ESM/CJS dual output for maximum compatibility
  • Tree-shakeable exports with granular component imports

vite.config.ts โ€‹

Purpose: Plugin-optimized build configuration
Functionality:

  • Library mode build for plugin distribution
  • Tree-shaking optimization for minimal bundle impact
  • TypeScript declaration generation
  • External dependency handling for peer dependencies

๐Ÿงฉ Enhanced Components (components/) โ€‹

Specialized form input components with built-in validation and formatting

components/
โ”œโ”€โ”€ index.ts                   # Component library exports and public API
โ”œโ”€โ”€ Form.ts                    # Enhanced form container with state management
โ””โ”€โ”€ input/                    # Specialized input component collection
    โ”œโ”€โ”€ index.ts              # Input component exports
    โ”œโ”€โ”€ TextField.ts          # Enhanced TextField with validation and formatting
    โ”œโ”€โ”€ Checkbox.ts           # Accessible checkbox with indeterminate state
    โ”œโ”€โ”€ Radio.ts              # Radio button with group management
    โ””โ”€โ”€ Select.ts             # Enhanced select with search and keyboard navigation

๐Ÿ“ Component Details โ€‹

Form.ts โ€‹

Purpose: Enhanced form container with advanced state management and validation
Functionality:

  • Form State Management: Centralized form state with reactive updates
  • Automatic Validation: Real-time validation with customizable triggers
  • Submission Handling: Form submission with loading states and error handling
  • Field Registration: Automatic field discovery and management
  • Reset Functionality: Form reset with validation state cleanup
  • Accessibility: ARIA live regions for validation feedback

input/TextField.ts โ€‹

Purpose: Enhanced TextField with 15+ specialized variants and validation
Functionality:

  • Input Variants: EmailField, PasswordField, PhoneField, NumberField, CreditCardField
  • Advanced Variants: SearchField, URLField, SSNField, PostalCodeField, DateField, TimeField
  • Text Variants: TextArea, ColorField with specialized validation and formatting
  • Selection Variants: Select and MultiSelect with search and keyboard navigation
  • Built-in Formatters: Automatic formatting for phone numbers, credit cards, SSN, currency
  • Real-time Validation: 18 built-in validation rules with custom validator support
  • Accessibility: Screen reader support, error announcements, focus management

input/Select.ts โ€‹

Purpose: Enhanced select component with search and advanced interaction
Functionality:

  • Search Integration: Built-in search with fuzzy matching
  • Keyboard Navigation: Full keyboard accessibility with arrow key navigation
  • Multi-select Support: Multiple selection with tag-based display
  • Option Grouping: Hierarchical option organization
  • Custom Rendering: Customizable option and selection rendering
  • Performance: Virtual scrolling for large option lists

๐Ÿ”„ State Management (state/) โ€‹

Reactive form state with validation and data binding

state/
โ””โ”€โ”€ index.ts                  # Form state management exports and utilities

๐Ÿ“ State Management Details โ€‹

index.ts โ€‹

Purpose: Comprehensive form state management with reactive validation
Functionality:

  • FormState Class: Centralized form state with field registration
  • Field State Management: Individual field state tracking with validation status
  • Validation Orchestration: Coordinates validation across form fields
  • Submission State: Loading states, success/error handling, and retry logic
  • Data Binding: Two-way data binding with TachUI's reactive system
  • Performance Optimization: Efficient field updates with minimal re-rendering

โœ… Validation System (validation/) โ€‹

Comprehensive validation framework with 18+ built-in rules

validation/
โ””โ”€โ”€ index.ts                  # Validation system exports and rule definitions

๐Ÿ“ Validation Details โ€‹

index.ts โ€‹

Purpose: Advanced validation system with extensible rule framework
Functionality:

  • 18+ Built-in Rules: Required, email, phone, URL, credit card, SSN, postal codes
  • Advanced Rules: Password strength, date ranges, numeric constraints, file validation
  • Custom Validators: Framework for creating application-specific validation rules
  • Async Validation: Support for server-side validation with debouncing
  • Conditional Validation: Rules that depend on other field values
  • Internationalization: Localized validation messages with pluralization support
  • Performance: Optimized validation execution with caching and debouncing

Available Validation Rules:

  • Basic: required, minLength, maxLength, pattern
  • Data Types: email, url, number, integer, decimal
  • Specialized: phone, creditCard, ssn, postalCode, dateRange
  • Security: passwordStrength, noXSS, sanitized
  • Files: fileSize, fileType, imageValidation
  • Custom: Framework for domain-specific validation rules

๐Ÿ› ๏ธ Utility Functions (utils/) โ€‹

Formatters, parsers, and helper functions for form processing

utils/
โ”œโ”€โ”€ formatters.ts             # Input formatters for specialized data types
โ””โ”€โ”€ validators.ts            # Validation utilities and helper functions

๐Ÿ“ Utility Details โ€‹

formatters.ts โ€‹

Purpose: Input formatters for automatic data formatting during entry
Functionality:

  • Phone Number Formatting: International and domestic phone number formats
  • Credit Card Formatting: Automatic spacing and validation for all major card types
  • Currency Formatting: Locale-aware currency formatting with decimal handling
  • Date/Time Formatting: Flexible date and time input formatting
  • SSN Formatting: Social Security Number formatting with privacy considerations
  • Custom Formatters: Framework for creating application-specific formatters

Available Formatters:

  • formatPhoneNumber(value, country) - International phone formatting
  • formatCreditCard(value, type) - Credit card formatting with type detection
  • formatCurrency(value, locale, currency) - Locale-aware currency formatting
  • formatSSN(value, masked) - SSN formatting with optional masking
  • formatPostalCode(value, country) - Postal code formatting by country
  • formatDate(value, format) - Flexible date formatting
  • formatTime(value, format, meridiem) - Time formatting with AM/PM support

validators.ts โ€‹

Purpose: Validation utilities and reusable validation logic
Functionality:

  • Validation Rule Engine: Core validation rule processing and execution
  • Error Message Generation: Internationalized error messages with context
  • Async Validation Support: Debounced server-side validation utilities
  • Composite Validation: Combining multiple validation rules with logical operators
  • Performance Optimization: Validation result caching and memoization
  • Testing Utilities: Helpers for testing custom validation rules

๐Ÿงช Comprehensive Testing (__tests__/) โ€‹

Extensive test suite with component, state, and integration testing

__tests__/
โ”œโ”€โ”€ components.test.ts        # Component functionality and interaction testing
โ”œโ”€โ”€ state.test.ts            # Form state management testing
โ”œโ”€โ”€ validation.test.ts       # Validation system testing
โ”œโ”€โ”€ textfield-enhanced.test.ts # Enhanced TextField variant testing
โ”œโ”€โ”€ textfield-reactive.test.ts # Reactive TextField behavior testing
โ”œโ”€โ”€ textfield-variants.test.ts # Specialized TextField variant testing
โ””โ”€โ”€ plugin.test.ts           # Plugin integration and architecture testing

๐Ÿ“ Test Coverage Details โ€‹

components.test.ts โ€‹

Purpose: Comprehensive component functionality testing
Test Coverage:

  • Form container behavior and state management
  • Input component variants and specialized behavior
  • Accessibility compliance (ARIA attributes, keyboard navigation)
  • Error handling and validation feedback
  • Component integration with TachUI core system

validation.test.ts โ€‹

Purpose: Validation system comprehensive testing
Test Coverage:

  • All 18+ built-in validation rules with edge cases
  • Custom validation rule creation and integration
  • Async validation behavior and error handling
  • Performance testing for validation optimization
  • Internationalization and error message localization

plugin.test.ts โ€‹

Purpose: Plugin architecture and integration testing
Test Coverage:

  • Plugin loading and initialization
  • Integration with TachUI core framework
  • Tree-shaking and bundle size validation
  • Performance impact assessment
  • Compatibility testing across TachUI versions

๐Ÿ“ฆ Distribution (dist/) โ€‹

Optimized plugin distribution with tree-shaking support

dist/
โ”œโ”€โ”€ index.js                  # Main plugin entry point (ESM)
โ”œโ”€โ”€ index.cjs                 # CommonJS compatibility entry point
โ”œโ”€โ”€ index.d.ts               # TypeScript declarations for plugin API
โ”œโ”€โ”€ components/              # Component-level exports for tree-shaking
โ”‚   โ”œโ”€โ”€ Form.js              # Enhanced Form component
โ”‚   โ”œโ”€โ”€ Form.d.ts           # Form TypeScript declarations
โ”‚   โ””โ”€โ”€ input/              # Specialized input components
โ”‚       โ”œโ”€โ”€ TextField.js     # Enhanced TextField variants
โ”‚       โ”œโ”€โ”€ TextField.d.ts  # TextField TypeScript declarations
โ”‚       โ”œโ”€โ”€ Checkbox.js     # Checkbox component
โ”‚       โ”œโ”€โ”€ Checkbox.d.ts   # Checkbox TypeScript declarations
โ”‚       โ”œโ”€โ”€ Radio.js        # Radio component
โ”‚       โ”œโ”€โ”€ Radio.d.ts      # Radio TypeScript declarations
โ”‚       โ”œโ”€โ”€ Select.js       # Enhanced Select component
โ”‚       โ””โ”€โ”€ Select.d.ts     # Select TypeScript declarations
โ””โ”€โ”€ *.map files            # Source maps for debugging

๐ŸŽฏ Forms Plugin API Reference โ€‹

Core Components โ€‹

typescript
// Enhanced Form container
import { Form } from '@tachui/forms'

const contactForm = Form({
  onSubmit: handleSubmit,
  validation: { mode: 'onChange' },
  children: [
    // Form fields
  ]
})

// Enhanced TextField with variants
import { TextField, EmailField, PhoneField } from '@tachui/forms/components/input'

const emailInput = EmailField({
  label: 'Email Address',
  required: true,
  validation: { email: true, required: true }
})

const phoneInput = PhoneField({
  label: 'Phone Number',
  format: 'international',
  validation: { phone: { country: 'US' } }
})

Advanced Usage โ€‹

typescript
// Custom validation rules
import { createValidator } from '@tachui/forms/validation'

const customValidator = createValidator({
  name: 'uniqueUsername',
  async validate(value) {
    const exists = await checkUsernameExists(value)
    return !exists || 'Username already taken'
  }
})

// Multi-step form with state management
import { FormState, ValidationSchema } from '@tachui/forms/state'

const formState = new FormState({
  initialValues: { name: '', email: '', phone: '' },
  validationSchema: ValidationSchema({
    name: { required: true, minLength: 2 },
    email: { required: true, email: true },
    phone: { required: true, phone: { country: 'US' } }
  }),
  onSubmit: async (values) => {
    await submitForm(values)
  }
})

๐Ÿ“Š Forms Plugin Statistics โ€‹

๐Ÿ“ˆ Current Implementation Metrics โ€‹

  • 13 Source Files: Complete forms functionality with specialized components
  • 7 Test Files: Comprehensive test coverage including edge cases and integration
  • 15+ Component Variants: Specialized TextField variants for common use cases
  • 18+ Validation Rules: Built-in validation rules covering most common scenarios
  • Bundle Impact: ~35KB additional bundle size (tree-shakeable)
  • Performance: <5ms validation execution for complex forms

๐ŸŽฏ Plugin Architecture Benefits โ€‹

  • Tree-Shakeable: Import only the components and features you need
  • Core Integration: Seamless integration with TachUI's reactive system
  • Accessibility First: WCAG 2.1 AA compliant by default
  • TypeScript Native: Full type safety with intelligent auto-completion
  • Extensible: Framework for custom components and validation rules

๐Ÿ—๏ธ Framework Integration โ€‹

  • Reactive Updates: Form state automatically updates UI through TachUI's signal system
  • Modifier Compatibility: All form components work with TachUI's modifier system
  • Theme Integration: Automatic theme support through TachUI's asset system
  • Error Handling: Integration with TachUI's error boundary system

๐Ÿ”„ Development Workflow Integration โ€‹

The Forms plugin integrates seamlessly with TachUI development:

  1. Installation: npm install @tachui/forms as peer dependency to @tachui/core
  2. Import: Import specific components for optimal tree-shaking
  3. Integration: Works with all TachUI modifiers and theme systems
  4. Testing: Comprehensive test utilities for form validation and behavior
  5. Production: Optimized bundle with minimal impact on core framework

Usage Examples โ€‹

typescript
// Basic form with validation
import { Form, TextField, EmailField } from '@tachui/forms'

const signupForm = Form([
  TextField({ label: 'Full Name', required: true }),
  EmailField({ label: 'Email', required: true }),
  TextField({ label: 'Password', type: 'password', minLength: 8 })
]).modifier
  .padding(20)
  .cornerRadius(8)
  .backgroundColor(Assets.systemBackground)
  .build()

// Advanced form with custom validation
import { FormState, createValidator } from '@tachui/forms'

const customForm = FormState({
  validation: {
    email: [required(), email(), customValidator()],
    password: [required(), minLength(8), passwordStrength()]
  }
})

This document serves as the definitive guide to TachUI's Forms plugin structure. The Forms plugin demonstrates TachUI's extensible architecture while providing production-ready form components with advanced validation and accessibility features.

Released under the MPL-2.0 License.