|
1 |
| -# react-lib-template |
2 |
| -A template that aims to make the implementation of `React` component packages easier and more methodic. |
| 1 | +# react-icon |
| 2 | + |
| 3 | +[![NPM version][npm-image]][npm-url] [![Downloads][downloads-image]][npm-url] [![Build Status][build-status-image]][build-status-url] [![Coverage Status][codecov-image]][codecov-url] [![Dependency status][david-dm-image]][david-dm-url] [![Dev Dependency status][david-dm-dev-image]][david-dm-dev-url] |
| 4 | + |
| 5 | +[npm-url]:https://npmjs.org/package/@moxy/react-icon |
| 6 | +[downloads-image]:https://img.shields.io/npm/dm/@moxy/react-icon.svg |
| 7 | +[npm-image]:https://img.shields.io/npm/v/@moxy/react-icon.svg |
| 8 | +[build-status-url]:https://github.com/moxystudio/react-icon/actions |
| 9 | +[build-status-image]:https://img.shields.io/github/workflow/status/moxystudio/react-icon/Node%20CI/master |
| 10 | +[codecov-url]:https://codecov.io/gh/moxystudio/react-icon |
| 11 | +[codecov-image]:https://img.shields.io/codecov/c/github/moxystudio/react-icon/master.svg |
| 12 | +[david-dm-url]:https://david-dm.org/moxystudio/react-icon |
| 13 | +[david-dm-image]:https://img.shields.io/david/moxystudio/react-icon.svg |
| 14 | +[david-dm-dev-url]:https://david-dm.org/moxystudio/react-icon?type=dev |
| 15 | +[david-dm-dev-image]:https://img.shields.io/david/dev/moxystudio/react-icon.svg |
| 16 | + |
| 17 | +A component to render `SVG` icons. |
| 18 | + |
| 19 | +## Installation |
| 20 | + |
| 21 | +```sh |
| 22 | +$ npm install @moxy/react-icon |
| 23 | +``` |
| 24 | + |
| 25 | +This library is written in modern JavaScript and is published in both CommonJS and ES module transpiled variants. If you target older browsers please make sure to transpile accordingly. |
| 26 | + |
| 27 | +## Motivation |
| 28 | + |
| 29 | +This package was implemented to help import `SVG` icons in `react` projects. |
3 | 30 |
|
4 | 31 | ## Usage
|
5 | 32 |
|
6 |
| -This repo serves as the template for the creation of MOXY's base `React` components. To use this, just select `@moxystudio/react-lib-template` as the template when creating a new repo for your new package, and you're all set to start working. |
| 33 | +```js |
| 34 | +import React, { forwardRef } from 'react'; |
| 35 | +import Icon from '@moxy/react-icon'; |
| 36 | + |
| 37 | +const arrowLeftSvg = import(/* webpackChunkName: "svg-sprite" */ '../media/arrow-left.inline.svg'); |
| 38 | +const ArrowLeftIcon = forwardRef((props, ref) => <Icon ref={ ref } { ...props } svg={ arrowLeftSvg } />); |
| 39 | + |
| 40 | +const MyComponent = ({ children }) => ( |
| 41 | + <div> |
| 42 | + { children } |
| 43 | + <ArrowLeftIcon /> |
| 44 | + </div> |
| 45 | +); |
| 46 | +``` |
| 47 | + |
| 48 | +## API |
| 49 | + |
| 50 | +These are the props available in `@moxy/react-icon`. |
| 51 | + |
| 52 | +#### svg |
| 53 | + |
| 54 | +Type: `string` or `object` | Required: `true` |
| 55 | + |
| 56 | +The contents of the `SVG` that should be rendered. |
| 57 | +In the case of the prop being an object, it must be the `Promise` that gets the contents of the `SVG`. |
| 58 | + |
| 59 | +#### className |
| 60 | + |
| 61 | +Type: `string` | Required: `false` |
| 62 | + |
| 63 | +A className to apply to the component. |
| 64 | + |
| 65 | +## Tests |
| 66 | + |
| 67 | +```sh |
| 68 | +$ npm test |
| 69 | +$ npm test -- --watch # during development |
| 70 | +``` |
| 71 | + |
| 72 | +## Demo |
| 73 | + |
| 74 | +A demo [Next.js](https://nextjs.org/) project is available in the [`/demo`](./demo) folder so you can try out this component. |
| 75 | + |
| 76 | +First, build the `react-icon` project with: |
| 77 | + |
| 78 | +```sh |
| 79 | +$ npm run build |
| 80 | +``` |
| 81 | + |
| 82 | +To run the demo, do the following inside the demo's folder: |
7 | 83 |
|
8 |
| -This template already includes a `src` folder, with 2 dummy files ready for you to start your work. `NewComponent` is a dummy component, available for demonstration purposes. Just rename `NewComponent.js` and change it according to your needs. An `index.js` for exporting is available as well. Do not forget to update the unit tests and try to reach as much coverage as possible. |
| 84 | +```sh |
| 85 | +$ npm i |
| 86 | +$ npm run dev |
| 87 | +``` |
9 | 88 |
|
10 |
| -In order to help make proper use of this template, here's a quick checklist with some crucial stuff to have in mind: |
| 89 | +## License |
11 | 90 |
|
12 |
| -- Remember to change `package.json` name, description, keywords, etc. |
13 |
| -- Review the dependencies, removing the unnecessary ones. |
14 |
| -- Just to stress this out again: add unit tests and check for a good coverage. The closest to 100%, the better. |
15 |
| -- Make sure to update the `README`, documenting the features of your component as best as possible. |
| 91 | +Released under the [MIT License](./LICENSE). |
0 commit comments