A beautifully crafted, accessible input field component built with React, TypeScript, and TailwindCSS. This component library provides a comprehensive set of input field variations with thoughtful design details and smooth interactions.
- Multiple Variants: Filled, outlined, and ghost styles
- Size Options: Small, medium, and large sizes
- State Management: Normal, disabled, loading, and error states
- Password Toggle: Show/hide password functionality
- Clear Button: Optional clear functionality for text inputs
- Form Validation: Built-in error handling and validation states
- Clean, Human Design: Thoughtful design that feels handcrafted, not AI-generated
- Accessibility: Full ARIA support and keyboard navigation
- Dark Mode: Seamless dark/light theme switching
- Responsive: Works perfectly on all screen sizes
- Smooth Animations: Subtle, natural transitions and interactions
- TypeScript: Full type safety and excellent developer experience
- React 18: Built with modern React patterns and hooks
- TailwindCSS: Utility-first styling with custom design system
- Storybook: Comprehensive component documentation and testing
- Vite: Fast development and build tooling
- Node.js 16+
- npm or yarn
-
Clone the repository
git clone <repository-url> cd input-field-component
-
Install dependencies
npm install
-
Start the development server
npm run dev
-
Open your browser Navigate to
http://localhost:5173to see the demo
# Development
npm run dev # Start development server
npm run build # Build for production
npm run preview # Preview production build
# Storybook
npm run storybook # Start Storybook development server
npm run build-storybook # Build Storybook for production
# Type checking
npm run type-check # Run TypeScript type checkingimport { InputField } from './components/InputField';
function MyForm() {
return (
<InputField
label="Email Address"
placeholder="Enter your email"
type="email"
helperText="We'll never share your email"
/>
);
}import { InputField } from './components/InputField';
function AdvancedForm() {
return (
<div className="space-y-6">
{/* Password with toggle */}
<InputField
label="Password"
type="password"
showPasswordToggle
required
helperText="Must be at least 8 characters"
/>
{/* Search with clear button */}
<InputField
label="Search"
placeholder="Search for anything..."
clearable
variant="ghost"
/>
{/* Error state */}
<InputField
label="Email"
type="email"
invalid
errorMessage="Please enter a valid email address"
/>
{/* Loading state */}
<InputField
label="Processing"
loading
defaultValue="Validating..."
/>
</div>
);
}| Prop | Type | Default | Description |
|---|---|---|---|
label |
string |
- | Label text displayed above the input |
helperText |
string |
- | Helper text displayed below the input |
errorMessage |
string |
- | Error message displayed below the input |
invalid |
boolean |
false |
Whether the input is in an invalid state |
loading |
boolean |
false |
Whether the input is in a loading state |
variant |
'filled' | 'outlined' | 'ghost' |
'outlined' |
Visual variant of the input |
size |
'sm' | 'md' | 'lg' |
'md' |
Size of the input |
clearable |
boolean |
false |
Whether to show a clear button |
showPasswordToggle |
boolean |
false |
Whether to show password toggle |
required |
boolean |
false |
Whether the input is required |
onClear |
() => void |
- | Callback when clear button is clicked |
- Outlined (Default): Clean white background with border
- Filled: Subtle gray background for form-heavy interfaces
- Ghost: Transparent background for search interfaces
- Small: Compact size for tight spaces
- Medium: Standard size for most use cases
- Large: Comfortable size for better accessibility
The component was designed with a human-centered approach, focusing on:
- Simplicity Over Complexity: Clean, minimal design that prioritizes usability
- Thoughtful Interactions: Subtle animations that enhance rather than distract
- Accessibility First: Built with ARIA standards and keyboard navigation
- Consistency: Unified design language across all variants and states
InputField/
βββ InputField.tsx # Main component logic
βββ index.ts # Export file
βββ types.ts # TypeScript interfaces
-
State Management
- Uses React hooks for internal state (password visibility, input value)
- Controlled component pattern for external state management
- Callback-based communication with parent components
-
Styling Approach
- TailwindCSS utility classes for consistency
- Custom CSS classes for complex interactions
- CSS custom properties for theme switching
- Responsive design with mobile-first approach
-
Accessibility Implementation
- Proper ARIA attributes (
aria-describedby,aria-invalid,aria-required) - Unique ID generation for form associations
- Keyboard navigation support
- Screen reader friendly labels and descriptions
- Proper ARIA attributes (
-
Performance Considerations
- Memoized callbacks with
useCallback - Efficient re-rendering with proper dependency arrays
- Lazy loading of icons and animations
- Memoized callbacks with
src/
βββ components/
β βββ InputField/
β βββ InputField.tsx
β βββ index.ts
βββ App.tsx
βββ main.tsx
βββ index.css
βββ vite-env.d.ts
stories/
βββ InputField.stories.tsx
.storybook/
βββ main.ts
βββ preview.ts
public/
βββ vite.svg
-
Component Development
- Start with TypeScript interfaces
- Implement core functionality
- Add styling and interactions
- Test accessibility features
-
Storybook Integration
- Create comprehensive stories for all variants
- Document props and usage examples
- Test different states and interactions
-
Testing & Validation
- Manual testing across browsers
- Accessibility testing with screen readers
- Responsive design validation
- Performance optimization
- Primary: Blue (#3b82f6) for focus states and interactions
- Gray Scale: Neutral grays for backgrounds and borders
- Semantic Colors: Red for errors, green for success states
- Font Family: Inter with system font fallbacks
- Font Sizes: Responsive scale (sm, base, lg)
- Line Heights: Optimized for readability
- Consistent Scale: 4px base unit system
- Responsive: Adapts to different screen sizes
- Visual Hierarchy: Clear spacing between elements
- Duration: 200ms for natural feel
- Easing:
ease-outfor smooth interactions - Subtle: Focus on enhancing UX, not distracting
The component uses TailwindCSS custom properties for easy theming:
/* Custom colors */
:root {
--color-primary: #3b82f6;
--color-error: #ef4444;
--color-success: #22c55e;
}
/* Dark mode */
.dark {
--color-primary: #60a5fa;
--color-error: #f87171;
--color-success: #4ade80;
}You can customize the component using TailwindCSS classes:
<InputField
label="Custom Input"
className="border-purple-300 focus:border-purple-500"
helperText="Custom styling applied"
/>The project includes comprehensive Storybook documentation:
npm run storybook- Default: Basic input field usage
- With Error: Error state demonstration
- With Helper Text: Helper text examples
- Password with Toggle: Password field functionality
- Clearable: Clear button functionality
- Size Variations: All size options
- Variant Styles: All visual variants
- States: Loading, disabled, and validation states
- Dark Mode: Dark theme showcase
- Accessibility: ARIA and keyboard navigation
- Responsive Design: Mobile and tablet layouts
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
- Follow TypeScript best practices
- Maintain accessibility standards
- Add comprehensive tests
- Update documentation
- Follow the existing code style
This project is licensed under the MIT License - see the LICENSE file for details.
- React Team: For the amazing framework
- TailwindCSS: For the utility-first CSS framework
- Lucide React: For the beautiful icons
- Storybook: For the component documentation platform
- Vite: For the fast build tooling