Skip to content

Modern character counter with real-time text analysis, letter density visualization, and dark mode. Built with React 19, TypeScript, and Tailwind CSS V4

License

Notifications You must be signed in to change notification settings

lance0821/character-counter-project

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

3 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

Character Counter

A modern, accessible character counter application built with React, TypeScript, and Tailwind CSS v4. This project demonstrates clean architecture, real-time text analysis, and modern React patterns including the latest React 19 features.

React TypeScript Tailwind CSS Vite

๐Ÿš€ Features

  • Real-time Text Analysis: Character, word, and sentence counting as you type
  • Letter Density Visualization: Interactive bar chart showing letter frequency distribution
  • Character Limit Mode: Set and track character limits with visual feedback
  • Exclude Spaces Option: Toggle to count characters with or without spaces
  • Reading Time Estimation: Automatic calculation based on average reading speed
  • Dark Mode Support: Full dark/light theme with system preference detection
  • Fully Responsive Design: Optimized for mobile (375px+), tablet (768px+), and desktop (1024px+)
  • Persistent Theme: Theme preference saved to localStorage
  • Accessible: WCAG compliant with proper ARIA labels and keyboard navigation

๐Ÿ›  Tech Stack

  • React 19 - Latest React features without forwardRef
  • TypeScript - Type-safe code with type definitions (not interfaces)
  • Tailwind CSS v4 - CSS-based configuration with custom design tokens
  • Vite - Lightning-fast build tool and dev server
  • Bun - Fast JavaScript runtime and package manager
  • ESLint - Code quality and consistency
  • Prettier - Automatic code formatting
  • clsx - Utility for constructing className strings conditionally

๐Ÿ“ Project Structure

src/
โ”œโ”€โ”€ components/           # React components
โ”‚   โ”œโ”€โ”€ CharacterLimitInput.tsx
โ”‚   โ”œโ”€โ”€ Checkbox.tsx
โ”‚   โ”œโ”€โ”€ Controls.tsx
โ”‚   โ”œโ”€โ”€ Header.tsx
โ”‚   โ”œโ”€โ”€ Icons.tsx
โ”‚   โ”œโ”€โ”€ LetterDensity.tsx
โ”‚   โ”œโ”€โ”€ ReadingTime.tsx
โ”‚   โ”œโ”€โ”€ StatCard.tsx
โ”‚   โ””โ”€โ”€ TextInput.tsx
โ”œโ”€โ”€ context/             # React Context providers
โ”‚   โ”œโ”€โ”€ ThemeContext.ts
โ”‚   โ””โ”€โ”€ ThemeProvider.tsx
โ”œโ”€โ”€ hooks/               # Custom React hooks
โ”‚   โ”œโ”€โ”€ useTextAnalysis.ts
โ”‚   โ””โ”€โ”€ useTheme.ts
โ”œโ”€โ”€ assets/              # Images and fonts
โ”‚   โ”œโ”€โ”€ fonts/          # DM Sans font files
โ”‚   โ””โ”€โ”€ images/         # Icons and backgrounds
โ”œโ”€โ”€ index.css           # Global styles and Tailwind v4 config
โ”œโ”€โ”€ App.tsx             # Main app component
โ””โ”€โ”€ main.tsx            # App entry point

๐ŸŽจ Design Highlights

Component Architecture

  • Type-First Development: All components use type (not interface) for props
  • Co-located Types: TypeScript types defined in the same file as components
  • Named Exports: All components use named function declarations
  • Composition Pattern: Small, focused components composed together

Tailwind CSS v4 Features

  • CSS-Based Configuration: Design tokens defined in @theme
  • Custom Utilities: Using @utility directive for component classes
  • Design System: Consistent spacing, typography, and color scales
  • Dark Mode: Class-based dark mode with custom color schemes

React 19 Features

  • No forwardRef: Refs passed as regular props
  • Improved Performance: Leveraging React 19's optimizations
  • Modern Patterns: Function declarations over arrow functions

๐Ÿšฆ Getting Started

Prerequisites

  • Node.js 18+
  • Bun (recommended) or npm

Installation

  1. Clone the repository:
git clone https://github.com/lance0821/character-counter-project.git
cd character-counter-react
  1. Install dependencies:
bun install
  1. Start the development server:
bun run dev
  1. Open your browser and navigate to http://localhost:5173

Available Scripts

bun run dev          # Start development server
bun run build        # Build for production
bun run lint         # Run ESLint
bun run preview      # Preview production build
bun run format       # Format code with Prettier
bun run format:check # Check if code is formatted
bun run type-check   # TypeScript type checking

๐Ÿ— Architecture Decisions

State Management

  • Context API for global theme state
  • Custom hooks for text analysis logic with memoization
  • Local component state for UI controls
  • localStorage for theme persistence

Styling Approach

  • Tailwind CSS v4 with CSS-based configuration
  • Custom utility classes using @utility directive
  • Design tokens in @theme for consistency
  • Mobile-first responsive design

Code Organization

  • Feature-based structure with clear separation
  • TypeScript types co-located with components
  • Custom hooks for business logic
  • Figma-aligned design system

๐Ÿ”ง Key Components

TextInput

Main textarea component with error state handling and character limit feedback. Adapts to theme and provides visual feedback for limit exceeded state.

LetterDensity

Interactive visualization component showing letter frequency distribution with expandable view and percentage calculations.

StatCard

Reusable card component for displaying statistics with dynamic formatting and decorative patterns.

Controls

Composite component managing user preferences including space exclusion, character limits, and reading time display.

Custom Hooks

  • useTextAnalysis - Memoized text analysis calculations
  • useTheme - Theme context access with error boundaries

๐Ÿ“ฑ Responsive Design

  • Mobile (<768px):
    • Single column layout with 130px stat cards
    • 40px font size for statistics
    • 12px padding on text input
    • Compact header with 18px logo text
  • Tablet (768px-1024px):
    • Three column grid for stat cards
    • Hero text constrained to 510px width
    • 64px font size for headings
    • 32px padding for optimal reading
  • Desktop (>1024px):
    • Full-width three column grid
    • Maximum content width of 7xl (80rem)
    • Enhanced spacing and larger touch targets
  • Adaptive typography using Tailwind v4 responsive utilities

๐ŸŽฏ Performance Optimizations

  • Memoized calculations in useTextAnalysis hook
  • Efficient re-renders with proper component composition
  • Optimized bundle with Vite's tree-shaking
  • Fast Refresh for instant development feedback

โœจ Key Features Explained

Text Analysis Engine

The useTextAnalysis hook provides real-time analysis including:

  • Character counting (with/without spaces)
  • Word boundary detection
  • Sentence parsing with punctuation handling
  • Letter frequency analysis for density visualization

Theme System

  • System preference detection
  • Manual toggle override
  • Persistent storage
  • Smooth transitions

Character Limit

  • Visual feedback when approaching limit
  • Error state when exceeded
  • Real-time remaining character count
  • Customizable limit value

๐Ÿ”ฎ Future Enhancements

  • Add copy to clipboard functionality
  • Export analysis as PDF/CSV
  • Multiple text comparison
  • Language-specific analysis
  • Keyboard shortcuts
  • Text statistics history
  • Custom reading speed settings

๐Ÿ“„ License

This project is open source and available under the MIT License.

๐Ÿค Contributing

Contributions, issues, and feature requests are welcome! Feel free to check the issues page.

๐Ÿ‘ค Author

Lance Lewandowski

๐Ÿ™ Acknowledgments

  • Design inspired by Frontend Mentor challenges
  • Built following modern React best practices
  • Tailwind CSS v4 for next-generation styling
  • DM Sans font for beautiful typography

About

Modern character counter with real-time text analysis, letter density visualization, and dark mode. Built with React 19, TypeScript, and Tailwind CSS V4

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published