0.1.4-b3 • Published 2 years ago

react-scripts-svg v0.1.4-b3

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

react-scripts-svg :rocket:

Transform a directory of SVG files into an easily usable React component.

Installation

npm install react-scripts-svg --save-dev
yarn add -D react-scripts-svg

Usage

react-scripts-svg -p src/assets/svg -o src/components -t -d vector

This will take SVG files from directory src/assets/svg and generate files containing the component and SVG data. From the working directory where the command is executed; the generated files will be:

  • src/components/vector/index.tsx - component
  • src/components/vector/types.ts - data, TypeScript types (if -t flag is provided)

Parameters

ParameterDescriptionTypeDefaultRequired
--path, -pPath to directory containing SVG filesstring
--out, -oOutput path (directory will be created)string
--typescript, -tOutput TypeScript filesbooleanfalse
--component, cGenerated React component namestringsvg
--directory, -dGenerated directory namestringSVG
--jsx, -jUse JSX file extensions (.jsx, .tsx)booleantrue
--propTypes, --ptGenerate PropTypes definition for componentbooleanfalse

Usage in package.json

The script below can be run using npm run svg

package.json
{
    "scripts": {
        "svg": "react-scripts-svg -p src/assets/svg -o src/components"
    }
}

Component Usage

This example assumes all default values are used.

src/components/settings-icon/index.ts
import React from "react"
import Icon from "../icon"

export const SettingsIcon = () => (
    <Icon name="settings" className="settings-icon" style={{fill: "red"}}/>
);

Component Props

PropTypeRequired
name*string
classNamestring
styleCSSProperties

* name prop must be one of the strings exported in types.js or types.ts - if using TypeScript this will be enforced.

Assumptions

  • SVG file names must contain only letters or hyphens, such as:
    • settings.svg -> settings
    • alarm-clock.svg -> alarmClock
0.1.4-b3

2 years ago

0.0.40

2 years ago

0.0.41

2 years ago

0.0.42

2 years ago

0.0.43

2 years ago

0.0.37

2 years ago

0.0.38

2 years ago

0.0.39

2 years ago

0.0.36

2 years ago

0.1.0

2 years ago

0.1.2

2 years ago

0.1.1

2 years ago

0.1.4

2 years ago

0.1.3

2 years ago

0.1.4-b1

2 years ago

0.1.4-b2

2 years ago

0.0.30

2 years ago

0.0.31

2 years ago

0.0.32

2 years ago

0.0.34

2 years ago

0.0.35

2 years ago

0.0.29

2 years ago

0.0.28

2 years ago

0.0.27

2 years ago

0.0.26

2 years ago

0.0.25

2 years ago

0.0.24

2 years ago

0.0.23

2 years ago

0.0.22

2 years ago

0.0.21

2 years ago

0.0.20

2 years ago

0.0.19

2 years ago

0.0.18

2 years ago

0.0.17

2 years ago

0.0.16

2 years ago

0.0.15

2 years ago

0.0.14

2 years ago

0.0.13

2 years ago

0.0.12

2 years ago

0.0.11

2 years ago

0.0.10

2 years ago

0.0.9

2 years ago

0.0.8

2 years ago

0.0.7

2 years ago

0.0.6

2 years ago

0.0.5

2 years ago

0.0.4

2 years ago

0.0.3

2 years ago

0.0.2

2 years ago

0.0.1

2 years ago