Skip to content

Latest commit

 

History

History
70 lines (52 loc) · 2.25 KB

README.md

File metadata and controls

70 lines (52 loc) · 2.25 KB

SVG to React Component CLI

This command-line interface (CLI) tool converts SVG files into React components from your current folder. It allows developers to easily import SVG icons into their React projects.

Quick start

Go to your folder with your list of svgs and run:

cd paths/to/your/svg/files
npx iconos

Installation (optional) if you want to use the cli without npx.

To use this tool, you must first install it by running the following commands:

npm install -g iconos

Usage

Once the tool is installed, you can run the following command in the folder containing your SVG files:

iconos

This command will convert all SVG files in the current folder into React components and save them in a new folder called Iconos.

ex: your svg in your folder:

  • bell.svg
<svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M13.73 21C13.5542 21.3031 13.3018 21.5547 12.9982 21.7295C12.6946 21.9044 12.3504 21.9965 12 21.9965C11.6496 21.9965 11.3054 21.9044 11.0018 21.7295C10.6982 21.5547 10.4458 21.3031 10.27 21M18 8C18 6.4087 17.3679 4.88258 16.2426 3.75736C15.1174 2.63214 13.5913 2 12 2C10.4087 2 8.88258 2.63214 7.75736 3.75736C6.63214 4.88258 6 6.4087 6 8C6 15 3 17 3 17H21C21 17 18 15 18 8Z" stroke="#101828" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
</svg>

Will create Bell.tsx in a components folder.

import { SVGProps } from 'react';

const Bell = (props: SVGProps<SVGSVGElement> & { size?: number }) => (
  <svg
    width="1em"
    height="1em"
    viewBox="0 0 24 24"
    fill="none"
    xmlns="http://www.w3.org/2000/svg"
    {...props}
    style={{ ...props.style, color: props.color, fontSize: props.size }}
  >
    <path
      d="M13.73 21C13.5542 21.3031 13.3018 21.5547 12.9982 21.7295C12.6946 21.9044 12.3504 21.9965 12 21.9965C11.6496 21.9965 11.3054 21.9044 11.0018 21.7295C10.6982 21.5547 10.4458 21.3031 10.27 21M18 8C18 6.4087 17.3679 4.88258 16.2426 3.75736C15.1174 2.63214 13.5913 2 12 2C10.4087 2 8.88258 2.63214 7.75736 3.75736C6.63214 4.88258 6 6.4087 6 8C6 15 3 17 3 17H21C21 17 18 15 18 8Z"
      stroke="currentColor"
      strokeWidth={2}
      strokeLinecap="round"
      strokeLinejoin="round"
    />
  </svg>
);

export default Bell;