|
| 1 | +# CLAUDE.md |
| 2 | + |
| 3 | +This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository. |
| 4 | + |
| 5 | +## Commands |
| 6 | + |
| 7 | +### Development |
| 8 | +- `npm run watch` - Build and watch for changes (uses tsup) |
| 9 | +- `npm run build` - Clean and build the library for production |
| 10 | + |
| 11 | +### Testing |
| 12 | +- `npm test` - Run tests in watch mode (development) |
| 13 | +- `npm run test:coverage` - Run tests with coverage report |
| 14 | +- Run a single test: `vitest run test/index.spec.tsx` |
| 15 | + |
| 16 | +### Quality Checks |
| 17 | +- `npm run lint` - Lint and fix code issues |
| 18 | +- `npm run typecheck` - Run TypeScript type checking |
| 19 | +- `npm run validate` - Run full validation suite (lint, typecheck, test, build, size check) |
| 20 | +- `npm run size` - Check bundle size limits |
| 21 | + |
| 22 | +## Architecture |
| 23 | + |
| 24 | +### Core Component Flow |
| 25 | +The library uses a state machine pattern for managing the floater lifecycle: |
| 26 | + |
| 27 | +1. **Main Entry** (`src/index.tsx`): The `ReactFloater` component manages state using `useReducer` and handles: |
| 28 | + - Popper.js instance creation/management for positioning |
| 29 | + - Event handling (click/hover) with mobile detection |
| 30 | + - Portal rendering for the floating element |
| 31 | + - Status transitions: IDLE → OPENING → OPEN → CLOSING → IDLE |
| 32 | + |
| 33 | +2. **Component Structure**: |
| 34 | + - `Portal` (`src/components/Portal.tsx`): Manages DOM portal rendering |
| 35 | + - `Floater` (`src/components/Floater/index.tsx`): The floating UI container |
| 36 | + - `Container` (`src/components/Floater/Container.tsx`): Content wrapper with title/footer |
| 37 | + - `Arrow` (`src/components/Floater/Arrow.tsx`): Customizable arrow element |
| 38 | + - `Wrapper` (`src/components/Wrapper.tsx`): Target element wrapper for beacon mode |
| 39 | + |
| 40 | +3. **Positioning System**: Uses Popper.js v2 with: |
| 41 | + - Custom modifiers configuration via `getModifiers()` helper |
| 42 | + - Fallback placements for auto-positioning |
| 43 | + - Fixed positioning detection for proper scrolling behavior |
| 44 | + |
| 45 | +### Key Patterns |
| 46 | + |
| 47 | +**State Management**: The component uses `useReducer` with status-based state transitions. Changes are tracked using `tree-changes-hook` for efficient callback triggers. |
| 48 | + |
| 49 | +**Style Merging**: Custom styles are deeply merged with defaults using `deepmerge-ts`. The styles object structure is defined in `src/modules/styles.ts`. |
| 50 | + |
| 51 | +**Event Handling**: Special handling for mobile devices (converts hover to click) and delayed hiding for hover events using timeouts. |
| 52 | + |
| 53 | +**Type Safety**: Uses TypeScript with strict typing. Key type definitions in: |
| 54 | +- `src/types/common.ts`: Component props, states, and common types |
| 55 | +- `src/types/popper.ts`: Popper.js related types |
| 56 | + |
| 57 | +### Testing Approach |
| 58 | +- Uses Vitest with React Testing Library |
| 59 | +- Test files in `test/` directory |
| 60 | +- Coverage requirements: 90% for all metrics |
| 61 | +- Mock components in `test/__fixtures__/` |
0 commit comments