Skip to content

Conversation

@kurdev2020
Copy link

  • Add React Native framework entry to support table
  • Include React Native usage examples
  • Document react-native-svg prerequisites
  • Add ComponentRef and StyleProp best practices

amanj-kurdev and others added 14 commits November 11, 2025 12:59
This commit refactors the CLI command definitions in `cli.js` to use a more concise syntax. Additionally, it updates the framework options to include 'react-native' across various commands, improving the overall usability of the CLI tool.
This commit refactors the CLI command definitions in `cli.ts` for improved readability and consistency. It also enhances error handling across various commands and ensures the inclusion of 'react-native' in framework options, further improving the CLI's functionality.
… SVG component generation

This commit adds functionality to the FrameworkTemplateEngine to support the 'react-native' framework. It includes methods for generating React Native components from SVG content, enhancing the overall capability of the framework to handle various front-end technologies.
This commit updates the framework templates to improve TypeScript support for SVG components in React Native. It includes the addition of type imports and extends the component props interface to include `SvgProps`, ensuring better type safety and integration with React Native's styling system.
- Validate ComponentRef usage (not ElementRef)
- Enforce StyleProp<ViewStyle> for style prop
- Add react-native-svg import checks
- Ensure forwardRef wrapper presence
- Generate Arrowbenddownleft and Vite components
- Include TypeScript props and forwardRef support
- Add index.ts for component exports
- Add React Native usage examples
- Include code samples and installation notes
- Update framework count to 9+
- Add React Native usage section
- Include code examples and prerequisites
- Update CLI framework options list
- Add React Native framework entry to support table
- Include React Native usage examples
- Document react-native-svg prerequisites
- Add ComponentRef and StyleProp best practices
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds React Native framework support to svger-cli, expanding it from 8 to 9 supported frameworks. The implementation generates React Native components using react-native-svg with proper TypeScript types and modern React best practices.

Key Changes

  • Added react-native as a supported framework type
  • Implemented React Native component generation with react-native-svg integration
  • Added proper TypeScript typing using React.ComponentRef<typeof Svg> and StyleProp<ViewStyle>
  • Documented React Native usage with examples and prerequisites

Reviewed Changes

Copilot reviewed 11 out of 13 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
yarn.lock Added TypeScript 5.9.3 dependency entry (misplaced location)
src/types/index.ts Added react-native to FrameworkType union
src/core/framework-templates.ts Implemented React Native component generator with SVG element conversion
src/cli.ts Updated CLI help text to include react-native option
frameworks.test.js Added React Native test cases and validation logic
docs/IMPLEMENTATION-SUMMARY.md Updated framework count and documentation
docs/FRAMEWORK-GUIDE.md Added comprehensive React Native usage guide
cli-test-react-native/* Added example generated React Native components
dist/cli.js Compiled output of CLI changes
README.md Updated framework count in main documentation
cli-framework.test.js Added react-native to test frameworks array

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

style={style}
{...props}
>
<Defs><LinearGradient id="IconifyId1813088fe1fbc01fb466" x1="-.828%" x2="57.636%" y1="7.652%" y2="78.411%"><Stop offset="0%" stop-color="#41D1FF"></Stop><Stop offset="100%" stop-color="#BD34FE"></Stop></LinearGradient><LinearGradient id="IconifyId1813088fe1fbc01fb467" x1="43.376%" x2="50.316%" y1="2.242%" y2="89.03%"><Stop offset="0%" stop-color="#FFEA83"></Stop><Stop offset="8.333%" stop-color="#FFDD35"></Stop><Stop offset="100%" stop-color="#FFA800"></Stop></LinearGradient></Defs><Path fill="url(#IconifyId1813088fe1fbc01fb466)" d="M255.153 37.938L134.897 252.976c-2.483 4.44-8.862 4.466-11.382.048L.875 37.958c-2.746-4.814 1.371-10.646 6.827-9.67l120.385 21.517a6.537 6.537 0 0 0 2.322-.004l117.867-21.483c5.438-.991 9.574 4.796 6.877 9.62Z"></Path><Path fill="url(#IconifyId1813088fe1fbc01fb467)" d="M185.432.063L96.44 17.501a3.268 3.268 0 0 0-2.634 3.014l-5.474 92.456a3.268 3.268 0 0 0 3.997 3.378l24.777-5.718c2.318-.535 4.413 1.507 3.936 3.838l-7.361 36.047c-.495 2.426 1.782 4.5 4.151 3.78l15.304-4.649c2.372-.72 4.652 1.36 4.15 3.788l-11.698 56.621c-.732 3.542 3.979 5.473 5.943 2.437l1.313-2.028l72.516-144.72c1.215-2.423-.88-5.186-3.54-4.672l-25.505 4.922c-2.396.462-4.435-1.77-3.759-4.114l16.646-57.705c.677-2.35-1.37-4.583-3.769-4.113Z"></Path>
Copy link

Copilot AI Nov 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The SVG attribute conversion is incomplete. The stop-color attribute has not been converted to stopColor in camelCase format. React Native requires all hyphenated SVG attributes to be in camelCase. The convertSVGToReactNative function should include a replacement for stop-color to stopColor.

Suggested change
<Defs><LinearGradient id="IconifyId1813088fe1fbc01fb466" x1="-.828%" x2="57.636%" y1="7.652%" y2="78.411%"><Stop offset="0%" stop-color="#41D1FF"></Stop><Stop offset="100%" stop-color="#BD34FE"></Stop></LinearGradient><LinearGradient id="IconifyId1813088fe1fbc01fb467" x1="43.376%" x2="50.316%" y1="2.242%" y2="89.03%"><Stop offset="0%" stop-color="#FFEA83"></Stop><Stop offset="8.333%" stop-color="#FFDD35"></Stop><Stop offset="100%" stop-color="#FFA800"></Stop></LinearGradient></Defs><Path fill="url(#IconifyId1813088fe1fbc01fb466)" d="M255.153 37.938L134.897 252.976c-2.483 4.44-8.862 4.466-11.382.048L.875 37.958c-2.746-4.814 1.371-10.646 6.827-9.67l120.385 21.517a6.537 6.537 0 0 0 2.322-.004l117.867-21.483c5.438-.991 9.574 4.796 6.877 9.62Z"></Path><Path fill="url(#IconifyId1813088fe1fbc01fb467)" d="M185.432.063L96.44 17.501a3.268 3.268 0 0 0-2.634 3.014l-5.474 92.456a3.268 3.268 0 0 0 3.997 3.378l24.777-5.718c2.318-.535 4.413 1.507 3.936 3.838l-7.361 36.047c-.495 2.426 1.782 4.5 4.151 3.78l15.304-4.649c2.372-.72 4.652 1.36 4.15 3.788l-11.698 56.621c-.732 3.542 3.979 5.473 5.943 2.437l1.313-2.028l72.516-144.72c1.215-2.423-.88-5.186-3.54-4.672l-25.505 4.922c-2.396.462-4.435-1.77-3.759-4.114l16.646-57.705c.677-2.35-1.37-4.583-3.769-4.113Z"></Path>
<Defs><LinearGradient id="IconifyId1813088fe1fbc01fb466" x1="-.828%" x2="57.636%" y1="7.652%" y2="78.411%"><Stop offset="0%" stopColor="#41D1FF"></Stop><Stop offset="100%" stopColor="#BD34FE"></Stop></LinearGradient><LinearGradient id="IconifyId1813088fe1fbc01fb467" x1="43.376%" x2="50.316%" y1="2.242%" y2="89.03%"><Stop offset="0%" stopColor="#FFEA83"></Stop><Stop offset="8.333%" stopColor="#FFDD35"></Stop><Stop offset="100%" stopColor="#FFA800"></Stop></LinearGradient></Defs><Path fill="url(#IconifyId1813088fe1fbc01fb466)" d="M255.153 37.938L134.897 252.976c-2.483 4.44-8.862 4.466-11.382.048L.875 37.958c-2.746-4.814 1.371-10.646 6.827-9.67l120.385 21.517a6.537 6.537 0 0 0 2.322-.004l117.867-21.483c5.438-.991 9.574 4.796 6.877 9.62Z"></Path><Path fill="url(#IconifyId1813088fe1fbc01fb467)" d="M185.432.063L96.44 17.501a3.268 3.268 0 0 0-2.634 3.014l-5.474 92.456a3.268 3.268 0 0 0 3.997 3.378l24.777-5.718c2.318-.535 4.413 1.507 3.936 3.838l-7.361 36.047c-.495 2.426 1.782 4.5 4.151 3.78l15.304-4.649c2.372-.72 4.652 1.36 4.15 3.788l-11.698 56.621c-.732 3.542 3.979 5.473 5.943 2.437l1.313-2.028l72.516-144.72c1.215-2.423-.88-5.186-3.54-4.672l-25.505 4.922c-2.396.462-4.435-1.77-3.759-4.114l16.646-57.705c.677-2.35-1.37-4.583-3.769-4.113Z"></Path>

Copilot uses AI. Check for mistakes.
.replace(/font-size=/g, 'fontSize=')
.replace(/font-weight=/g, 'fontWeight=')
.replace(/text-anchor=/g, 'textAnchor=')
.replace(/xlink:href=/g, 'href=')
Copy link

Copilot AI Nov 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The attribute conversion is missing stop-color to stopColor and stop-opacity to stopOpacity conversions. These are commonly used in SVG gradients (as seen in the generated Vite.tsx file). Add .replace(/stop-color=/g, 'stopColor=') and .replace(/stop-opacity=/g, 'stopOpacity=') to the conversion chain.

Suggested change
.replace(/xlink:href=/g, 'href=')
.replace(/xlink:href=/g, 'href=')
.replace(/stop-color=/g, 'stopColor=')
.replace(/stop-opacity=/g, 'stopOpacity=')

Copilot uses AI. Check for mistakes.
Comment on lines +596 to +597
const regex = new RegExp(svgTag, 'gi')
converted = converted.replace(regex, reactNativeTag)
Copy link

Copilot AI Nov 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Creating a new RegExp object for each element in the loop is inefficient. The 'gi' flag makes this case-insensitive, which could cause unintended replacements (e.g., matching 'PATH' as well as 'path'). Since SVG tags are case-sensitive in the source and the target React Native components use specific casing, use string replacement with a global flag or compile the regex outside the loop. Consider using .replaceAll() or pre-compiled regexes stored in the elementMap.

Suggested change
const regex = new RegExp(svgTag, 'gi')
converted = converted.replace(regex, reactNativeTag)
converted = converted.replaceAll(svgTag, reactNativeTag)

Copilot uses AI. Check for mistakes.
@@ -0,0 +1,36 @@
import React from "react";
import Svg, { Defs, Line, LinearGradient, Path, Stop } from "react-native-svg";
Copy link

Copilot AI Nov 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unused import Line.

Suggested change
import Svg, { Defs, Line, LinearGradient, Path, Stop } from "react-native-svg";
import Svg from "react-native-svg";

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants