Skip to content

Commit 02b1539

Browse files
authored
feat: add demo and styling (#3)
1 parent e87dee6 commit 02b1539

17 files changed

+9399
-520
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ npm-debug.log*
33
coverage
44
lib/
55
es/
6+
dist/

INSTRUCTIONS.md

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
# react-lib-template
2+
3+
A template that aims to make the implementation of `React` component packages easier and more methodic.
4+
5+
## Usage
6+
7+
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.
8+
9+
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.
10+
11+
### Demo
12+
13+
There is a [Next.js](https://nextjs.org/) project available inside the `/demo` folder. This is useful for you to manually test your package before releasing it.
14+
15+
To gain access to your package as if it already was a `node_module`, please update the demo's `package.json` and create a symlink:
16+
```json
17+
"dependencies": {
18+
"{name-of-package}": "file:..",
19+
}
20+
```
21+
To run the demo, just do the following inside the demo's folder:
22+
```cmd
23+
$ npm i
24+
$ npm run dev
25+
```
26+
27+
### With CSS
28+
29+
This package already has css configuration enabled. We are currently using [@moxy/postcss-preset](https://github.com/moxystudio/postcss-preset) without `css-modules`.
30+
31+
Your stylesheets should be placed inside `src/styles` and you must use a good naming convention to avoid collisions with other project's styles. We suggest that you use the package name as a prefix.
32+
Here is an example to a package named `react-foo`:
33+
```css
34+
.react-foo_container {
35+
background-color: black;
36+
}
37+
38+
.react-foo_content {
39+
margin-top: 20px;
40+
color: black;
41+
}
42+
```
43+
44+
Every stylesheet placed inside the `src/styles` folder will be transpiled at build time and the output will be available at `/dist`.
45+
So, whenever you publish a package, please remember to detail in the README file which stylesheets are available and how a developer can import them.
46+
An example with a package named `react-foo`:
47+
48+
> To import a stylesheet, one can import it on the project's entry CSS file:
49+
> ```css
50+
> /* src/index.css */
51+
> @import "@moxy/react-foo/styles";
52+
> ```
53+
> ...or in the project's entry JavaScript file:
54+
> ```js
55+
> /* src/index.js */
56+
> import "@moxy/react-foo/styles/index.css";
57+
> ```
58+
59+
### Without CSS
60+
61+
If your package doesn't need any styling, you can trim it down to disable css support:
62+
1. Delete `postcss.config.js` file.
63+
2. Delete `src/styles` folder.
64+
3. Remove `npm run build:css` from the `"build"` script in `package.json`.
65+
4. Remove `postcss-cli` from the dev dependencies list in `package.json`.
66+
4. Remove all imported css from the demo `/pages/_app.js`.
67+
68+
## DOD Checklist
69+
70+
In order to help make proper use of this template, here's a quick checklist with some crucial stuff to have in mind:
71+
72+
- [ ] Update `package.json` name, description, keywords, etc.
73+
- [ ] Review dependencies, removing unnecessary ones.
74+
- [ ] Add unit tests and reach good coverage. The closest to 100%, the better.
75+
- [ ] Update the `README`, documenting the features of your component as best as possible.

README.md

Lines changed: 60 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,66 @@
1-
# react-lib-template
2-
A template that aims to make the implementation of `React` component packages easier and more methodic.
1+
-------
2+
### ⚠️ PLEASE READ THE [INSTRUCTIONS](/INSTRUCTIONS.md) FOR GUIDELINES ON HOW TO START YOUR PACKAGE.
3+
> Don't forget to remove this warning while updating this README.
4+
-------
5+
6+
# {package-name}
7+
8+
[![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]
9+
10+
[npm-url]:https://npmjs.org/package/@moxy/{package-name}
11+
[downloads-image]:https://img.shields.io/npm/dm/@moxy/{package-name}.svg
12+
[npm-image]:https://img.shields.io/npm/v/@moxy/{package-name}.svg
13+
[build-status-url]:https://github.com/moxystudio/{package-name}/actions
14+
[build-status-image]:https://img.shields.io/github/workflow/status/moxystudio/{package-name}/Node%20CI/master
15+
[codecov-url]:https://codecov.io/gh/moxystudio/{package-name}
16+
[codecov-image]:https://img.shields.io/codecov/c/github/moxystudio/{package-name}/master.svg
17+
[david-dm-url]:https://david-dm.org/moxystudio/{package-name}
18+
[david-dm-image]:https://img.shields.io/david/moxystudio/{package-name}.svg
19+
[david-dm-dev-url]:https://david-dm.org/moxystudio/{package-name}?type=dev
20+
[david-dm-dev-image]:https://img.shields.io/david/dev/moxystudio/{package-name}.svg
21+
22+
{package-drescription}
23+
24+
## Installation
25+
26+
```sh
27+
$ npm install @moxy/{package-name}
28+
```
29+
30+
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.
31+
32+
## Motivation
33+
34+
{package-motivation}
335

436
## Usage
537

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.
38+
{package-usage-example}
39+
40+
## API
41+
42+
{package-api-description}
43+
44+
#### {package-api-prop-example}
45+
46+
Type: `object`
47+
Required: `true`
48+
49+
The `{package-api-prop-example}` has the following shape:
50+
```js
51+
{package-api-prop-example}: PropTypes.shape({
52+
foo: PropTypes.string,
53+
bar: PropTypes.arrayOf(PropTypes.object),
54+
}).isRequired,
55+
```
56+
57+
## Tests
758

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.
59+
```sh
60+
$ npm test
61+
$ npm test -- --watch # during development
62+
```
963

10-
In order to help make proper use of this template, here's a quick checklist with some crucial stuff to have in mind:
64+
## License
1165

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.
66+
Released under the [MIT License](https://www.opensource.org/licenses/mit-license.php).

demo/.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
node_modules
2+
.next/
3+
out/

demo/next.config.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/* eslint-disable import/no-commonjs */
2+
3+
module.exports = {
4+
webpack: (config) => {
5+
config.resolve.symlinks = false;
6+
7+
return config;
8+
},
9+
};

0 commit comments

Comments
 (0)