Files
v10/packages/react/react-icons/README.md
T
Christian PillsburyandClaude 6fcb18f1d2 feat(react-icons): implement SVGR-powered auto-generation with full styling support
Replace manually-coded React icon components with SVGR-generated ones from shared SVG assets.
This establishes a maintainable, single-source-of-truth system for icons across the monorepo.

## Key Changes

###  SVGR Integration
- Add @svgr/cli with custom configuration for React component generation
- Generate components from packages/core/icons/assets/ SVG files
- Implement custom templates with generation warnings and JSDoc @generated tags
- Replace manual src/icons/ with auto-generated src/generated-icons/

### 🎨 Complete Styling Support
- Add fill="currentColor" to all SVG source files in core package
- Configure replaceAttrValues to transform currentColor → {color} in React components
- Restore full color prop functionality (fill={color} on path elements)
- Maintain backwards compatibility with existing IconProps interface

### 📚 Developer Experience
- Add comprehensive README.md with usage examples and development workflow
- Include clear "DO NOT EDIT" warnings in all generated files
- Add .gitignore to exclude generated files from version control
- Provide detailed generation instructions and architecture explanation

### 🏗️ Build System Integration
- Update package.json scripts: npm run generate creates React components
- Integrate generation into build pipeline (npm run build runs generate first)
- Add SVGR dependencies: @svgr/cli, plugins, and babel-plugin-add-jsx-attribute
- Maintain existing rollup + TypeScript build chain

## Technical Implementation

- **Source**: SVG files in packages/core/icons/assets/ (single source of truth)
- **Generator**: SVGR v8 with custom TypeScript React templates
- **Output**: Auto-generated components in src/generated-icons/ with full JSDoc
- **Styling**: fill={color} props + currentColor inheritance for dynamic theming
- **Types**: Preserved IconProps interface with SVGAttributes<SVGElement> + color prop

## Verification

 Playwright testing confirms icons render correctly with proper colors
 All 5 icons (Play, Pause, VolumeHigh, VolumeLow, VolumeOff) generate successfully
 Color prop functionality verified (fill attribute updates dynamically)
 Build system integration working across full monorepo
 Backwards compatibility maintained with existing components

This implementation provides automatic React component generation while maintaining
full feature parity with the original manually-coded icons.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-08-13 14:26:00 -07:00

133 lines
3.8 KiB
Markdown

# @vjs-10/react-icons
React-specific icon components derived from `@vjs-10/icons`.
## Overview
This package provides React components for media player icons that are automatically generated from SVG files. All icon components are built using [SVGR](https://react-svgr.com/) to transform SVG assets into optimized React components.
## 🔄 Auto-Generated Components
**Important:** The React components in this package are automatically generated. Do not edit them directly.
### Generated Files Location
```
src/generated-icons/
├── index.ts # Auto-generated exports (DO NOT EDIT)
├── Play.tsx # Auto-generated component (DO NOT EDIT)
├── Pause.tsx # Auto-generated component (DO NOT EDIT)
├── VolumeHigh.tsx # Auto-generated component (DO NOT EDIT)
├── VolumeLow.tsx # Auto-generated component (DO NOT EDIT)
└── VolumeOff.tsx # Auto-generated component (DO NOT EDIT)
```
### Source of Truth
All icons originate from SVG files located in:
```
packages/core/icons/assets/
├── play.svg
├── pause.svg
├── volume-high.svg
├── volume-low.svg
└── volume-off.svg
```
## Usage
```tsx
import { PlayIcon, PauseIcon, VolumeHighIcon } from '@vjs-10/react-icons';
function MediaControls() {
return (
<div>
<PlayIcon color="blue" width={24} height={24} />
<PauseIcon color="red" className="pause-btn" />
<VolumeHighIcon />
</div>
);
}
```
### IconProps Interface
All generated icon components accept the following props:
```tsx
interface IconProps extends SVGAttributes<SVGElement> {
children?: never;
color?: string;
}
```
- **`color`**: Sets the icon color (default: `'currentColor'`)
- **All SVG attributes**: `width`, `height`, `className`, `onClick`, etc.
- **No children**: Icon components don't accept children
## 🔧 Development Workflow
### Adding New Icons
1. **Add SVG file** to `packages/core/icons/assets/filename.svg`
2. **Regenerate components**: Run `npm run generate` in this package
3. **New component** will be available as `FilenameIcon`
### Modifying Existing Icons
1. **Edit SVG file** in `packages/core/icons/assets/`
2. **Regenerate components**: Run `npm run generate` in this package
3. **Component updates automatically**
### Build Process
```bash
# Generate React components from SVG files
npm run generate
# Build the package (includes generation step)
npm run build
# Clean generated files and dist
npm run clean
```
## 📦 Package Scripts
- **`generate`**: Transform SVG files into React components using SVGR
- **`build`**: Generate components + build distribution files
- **`clean`**: Remove generated components and build artifacts
## 🏗️ Architecture
This package follows the monorepo's dependency hierarchy:
- **Depends on**: `@vjs-10/icons` (for shared SVG assets)
- **Peer dependency**: `react` (>=16.8.0)
- **Build tool**: SVGR for SVG-to-React transformation
## 🚫 What NOT to Edit
- `src/generated-icons/` - All files are auto-generated
- Generated components have `@generated` JSDoc tags
- Generated files include clear "DO NOT EDIT" warnings
## ✅ What You CAN Edit
- `src/types.d.ts` - TypeScript interface definitions
- `src/index.ts` - Main export file (if needed)
- `svgr.config.js` - SVGR configuration
- `package.json` - Package configuration
- This `README.md`
## 🎯 Icon Naming Convention
SVG filename → React component name:
- `play.svg``PlayIcon`
- `volume-high.svg``VolumeHighIcon`
- `my-custom-icon.svg``MyCustomIconIcon`
## 🔍 Technical Details
- **Generator**: [SVGR](https://react-svgr.com/) v8
- **Output**: TypeScript React components
- **Optimization**: Automatic SVG optimization via SVGO
- **Styling**: Uses `currentColor` for easy theming
- **Size**: Icons default to `1em` width/height for text alignment