Transform SVG icons into production-ready React components instantly
Demo β’ Features β’ Installation β’ Usage β’ API β’ Contributing
SVG to React Transformer is a modern web application designed specifically for developers working with Lucide Icons. It automates the tedious process of converting raw SVG code into properly formatted, reusable React components with full TypeScript support.
Built with Next.js 13 and styled using Tailwind CSS with shadcn/ui components, this tool provides a seamless developer experience with instant transformations and one-click copying.
| Feature | Description |
|---|---|
| π Instant Transformation | Real-time SVG to React component conversion |
| π― Smart Naming | Automatic kebab-case to PascalCase conversion |
| π¨ Dynamic Styling | Injects className prop for flexible styling |
| π§ React Property Fixes | Auto-converts SVG attributes to React-compatible camelCase |
| π One-Click Copy | Copy transformed code instantly to clipboard |
| π Dark Mode Support | Full light/dark theme compatibility |
| π± Responsive Design | Works seamlessly on desktop and mobile |
| ποΈ Static Export | Can be deployed as a static site anywhere |
The transformer applies the following modifications to make SVGs React-ready:
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β INPUT SVG β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β 1. Extract component name from class="lucide lucide-{name}" β
β 2. Remove class attribute entirely β
β 3. Add className={className} prop to <svg> tag β
β 4. Remove stroke="..." attribute β
β 5. Convert kebab-case attributes to camelCase: β
β β’ stroke-width β strokeWidth β
β β’ stroke-linecap β strokeLinecap β
β β’ stroke-linejoin β strokeLinejoin β
β 6. Convert component name: kebab-case β PascalCase β
β 7. Wrap with withClassName HOC for default sizing β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β OUTPUT REACT COMPONENT β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
- Node.js 18.0 or higher
- npm, yarn, or pnpm
# Clone the repository
git clone https://github.com/DinukaSandeepa/SVGReact.git
# Navigate to project directory
cd SVGReact
# Install dependencies
npm install
# Start development server
npm run devThe application will be available at http://localhost:3000
| Command | Description |
|---|---|
npm run dev |
Start development server with hot reload |
npm run build |
Build production-ready static export |
npm run start |
Start production server |
npm run lint |
Run ESLint for code quality checks |
- Copy your Lucide SVG icon code
- Paste it into the input textarea
- Click "Transform SVG" button
- Copy the generated React component and export statement
- Use in your React project!
Input SVG (from Lucide Icons):
<svg class="lucide lucide-arrow-right" xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
<path d="M5 12h14"/>
<path d="m12 5 7 7-7 7"/>
</svg>Output React Component:
const ArrowRightBase = ({ className }) => (
<svg className={className} xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round">
<path d="M5 12h14"/>
<path d="m12 5 7 7-7 7"/>
</svg>
);
export const ArrowRight = withClassName(ArrowRightBase);Usage in Your Project:
import { ArrowRight } from './icons/ArrowRight';
function MyComponent() {
return (
<button>
Next <ArrowRight className="ml-2 text-blue-500" />
</button>
);
}Main transformation function that converts SVG code to React component.
Parameters:
svgCode(string): Raw SVG code with Lucide class naming
Returns:
{
componentName: string; // PascalCase component name with "Base" suffix
componentCode: string; // Full React component code
exportCode: string; // Export statement with withClassName HOC
} | nullReturns null if:
- SVG doesn't contain
class="lucide lucide-{name}"pattern - Invalid SVG format
Higher-Order Component that adds default sizing to icon components.
Behavior:
- Applies default
w-6 h-6(24x24 pixels) sizing - Merges with any additional className passed as prop
- Preserves component displayName for debugging
Example:
const IconBase = ({ className }) => <svg className={className}>...</svg>;
export const Icon = withClassName(IconBase);
// Usage - default 24x24 size
<Icon />
// Usage - custom size
<Icon className="w-8 h-8" />
// Usage - with additional styles
<Icon className="w-4 h-4 text-red-500 hover:text-red-700" />SVGReact/
βββ app/
β βββ globals.css # Global styles & CSS variables
β βββ layout.jsx # Root layout with Inter font
β βββ page.jsx # Main application page
βββ components/
β βββ ui/
β βββ code-block.tsx # Code display with copy functionality
β βββ ... # shadcn/ui components (40+ components)
βββ hooks/
β βββ use-toast.ts # Toast notification hook
βββ lib/
β βββ transformSvg.js # Core SVG transformation logic
β βββ withClassName.js # HOC for className injection
β βββ utils.js # Utility functions (cn helper)
βββ components.json # shadcn/ui configuration
βββ next.config.js # Next.js configuration
βββ tailwind.config.ts # Tailwind CSS configuration
βββ package.json # Dependencies & scripts
- Next.js 13.5 - React framework with App Router
- React 18.2 - UI library
- Tailwind CSS 3.3 - Utility-first CSS framework
- shadcn/ui - Beautifully designed components
- tailwindcss-animate - Animation utilities
- Accordion, Dialog, Dropdown Menu, Popover, Toast, Tooltip, and 30+ more
- clsx - Conditional className utility
- tailwind-merge - Merge Tailwind classes intelligently
- Lucide React - Beautiful & consistent icons
The app is configured for static export, making it deployable to any static hosting:
// next.config.js
const nextConfig = {
output: 'export',
images: { unoptimized: true },
};CSS variables are defined in app/globals.css for easy customization:
:root {
--background: 0 0% 100%;
--foreground: 0 0% 3.9%;
--primary: 0 0% 9%;
--primary-foreground: 0 0% 98%;
}
.dark {
--background: 0 0% 3.9%;
--foreground: 0 0% 98%;
}# Build static files
npm run build
# Output will be in 'out' directory
# Deploy to Vercel, Netlify, GitHub Pages, etc.Contributions are welcome! Here's how you can help:
- Fork the repository
- Create a feature branch:
git checkout -b feature/amazing-feature - Commit your changes:
git commit -m 'Add amazing feature' - Push to the branch:
git push origin feature/amazing-feature - Open a Pull Request
- Follow existing code style and conventions
- Write meaningful commit messages
- Test your changes before submitting PR
- Update documentation as needed
This project is licensed under the MIT License - see the LICENSE file for details.
MIT License
Copyright (c) 2024 Dinuka Sandeepa
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software.
- Lucide Icons - Beautiful open-source icons
- shadcn/ui - Excellent component library
- Vercel - Amazing deployment platform
Made with β€οΈ by Dinuka Sandeepa