Skip to content

Commit a08cdc4

Browse files
feat: initial implementation (#1)
1 parent b6bcd9a commit a08cdc4

21 files changed

+22711
-87
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,5 @@ npm-debug.log*
33
coverage
44
lib/
55
es/
6+
dist/
7+

README.md

+85-9
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,91 @@
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.
330

431
## Usage
532

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:
783

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+
```
988

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
1190

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).

demo/.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
node_modules
2+
.next/
3+
out/

demo/next.config.js

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/* eslint-disable import/no-commonjs */
2+
3+
const { withSVG } = require('@moxy/next-common-files');
4+
const withOneOf = require('@moxy/next-webpack-oneof');
5+
const withPlugins = require('next-compose-plugins');
6+
7+
const withSymlinks = (nextConfig = {}) => ({
8+
...nextConfig,
9+
webpack(config) {
10+
config.resolve.symlinks = false;
11+
12+
return config;
13+
},
14+
});
15+
16+
module.exports = (phase, nextConfig) =>
17+
withPlugins([
18+
withSymlinks,
19+
withOneOf,
20+
withSVG(),
21+
withSVG({
22+
include: /\.data-url\./,
23+
options: {
24+
limit: Infinity,
25+
},
26+
}),
27+
withSVG({
28+
include: /\.inline\./,
29+
inline: true,
30+
}),
31+
], {})(phase, nextConfig);

0 commit comments

Comments
 (0)