|
| 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. |
0 commit comments