A powerful online tool that converts SVG files into reusable React components. Supports TypeScript and JavaScript with real-time preview and code generation.
- 🎨 Drag & Drop Upload - Support drag and drop SVG files for conversion
- 🔄 Real-time Preview - Live preview of SVG effects during conversion
- 🎯 Smart Conversion - Automatically converts SVG attributes to React-compatible format
- 🎨 Color Customization - Support custom preview colors and sizes
- 📝 Code Generation - Generate TypeScript or JavaScript React component code
- 📋 One-click Copy - Generated code can be copied to clipboard with one click
- 🎨 Syntax Highlighting - Code display with syntax highlighting
- 📱 Responsive Design - Perfect adaptation for desktop and mobile devices
Visit the live version to start using it directly.
-
Clone the repository
git clone https://github.com/The-End-Hero/svg2react.git cd svg2react -
Install dependencies
pnpm install
-
Start development server
pnpm dev
-
Build for production
pnpm build
- Frontend Framework: React 19 + TypeScript
- Build Tool: Vite
- Styling: Tailwind CSS
- Routing: React Router DOM
- Drag & Drop: React Dropzone
- Code Highlighting: Prism React Renderer
- Animations: Motion
- State Management: Zustand
- Utilities: ahooks, lodash-es, dayjs
- Package Manager: pnpm
-
Upload SVG File
- Drag and drop SVG file to the page area
- Or click anywhere on the page to select a file
-
Preview and Adjust
- View SVG preview effect
- Adjust colors and sizes
- Modify component name
-
Generate Code
- Choose output format (TSX/JSX)
- Copy the generated React component code
- Smart Attribute Conversion: Automatically converts SVG attributes to React-compatible format
- Color Handling: Intelligently handles
fillandstrokeattributes, supportscurrentColor - Type Safety: TypeScript version provides complete type definitions
- Accessibility: Supports
titleattribute for improved accessibility
The generated React components have the following features:
- ✅ Support for all SVG attributes
- ✅ Responsive size control
- ✅ Color theme support
- ✅ TypeScript type safety
- ✅ Accessibility support
- ✅ Performance optimization
svg2react/
├── public/ # Static assets
├── src/
│ ├── pages/ # Page components
│ │ └── svg-converter/ # SVG converter page
│ ├── App.tsx # App entry point
│ └── main.tsx # App startup
├── package.json # Project configuration
└── README.md # Project documentation
Contributions are welcome! Please follow these steps:
- Fork the repository
- Create a feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
Thanks to all the developers who contributed to this project!
⭐ If this project helps you, please give it a star!