This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
npm run watch- Build and watch for changes (uses tsup)npm run build- Clean and build the library for production
npm test- Run tests in watch mode (development)npm run test:coverage- Run tests with coverage report- Run a single test:
vitest run test/index.spec.tsx
npm run lint- Lint and fix code issuesnpm run typecheck- Run TypeScript type checkingnpm run validate- Run full validation suite (lint, typecheck, test, build, size check)npm run size- Check bundle size limits
The library uses a state machine pattern for managing the floater lifecycle:
-
Main Entry (
src/index.tsx): Thin JSX shell that delegates touseFloaterhookuseFloater(src/modules/useFloater.ts): All state management, Popper.js integration, event handlers- Status transitions: INIT → IDLE → RENDER → OPENING → OPEN → CLOSING → IDLE
-
Component Structure:
Portal(src/components/Portal.tsx): Manages DOM portal renderingFloater(src/components/Floater/index.tsx): The floating UI containerContainer(src/components/Floater/Container.tsx): Content wrapper with title/footerArrow(src/components/Floater/Arrow.tsx): Customizable arrow elementWrapper(src/components/Wrapper.tsx): Target element wrapper for beacon mode
-
Positioning System: Uses Popper.js v2 with:
- Custom modifiers configuration via
getModifiers()helper - Fallback placements for auto-positioning
- Fixed positioning detection for proper scrolling behavior
- Custom modifiers configuration via
State Management: The useFloater hook uses useReducer with status-based state transitions. A previousStatus ref tracks the prior status, and 3 focused useEffect hooks handle controlled mode, wrapper positioning, and status transitions.
Style Merging: Custom styles are deeply merged with defaults using deepmerge-ts. The styles object structure is defined in src/modules/styles.ts.
Event Handling: Special handling for mobile devices (converts hover to click) and delayed hiding for hover events using timeouts.
Type Safety: Uses TypeScript with strict typing. Key type definitions in:
src/types/common.ts: Component props, states, and common typessrc/types/popper.ts: Popper.js related types
- Uses Vitest with React Testing Library
test/index.spec.tsx: Rendering, UI, and integration teststest/modules/useFloater.spec.tsx: State machine, lifecycle, and event handling tests- Coverage requirements: 90% for all metrics
- Mock components in
test/__fixtures__/