<!-- PROJECT LOGO -->
<br />
<p align="center">
  <a href="https://github.com/digital-generation">
    <img src="https://genrecruiting-staging.generation.org/static/media/generation-logo.f41870c7.svg" alt="Logo" width="150">
  </a>

  <h3 align="center">Generation Self Service</h3>

  <p align="center">
    Web application to give autonomy for users to create and manage the recruitment processes in their organization
    <br />
    <a href="https://github.com/digital-generation/gen-self-service/tree/develop/docs"><strong>Explore the docs »</strong></a>
    <br />
    <br />
    <a href="#TBD">View Demo</a>
    ·
    <a href="#TBD">Report Bug</a>
    ·
    <a href="#TBD">Request Feature</a>
  </p>
</p>

<!-- TABLE OF CONTENTS -->

# Generation UI Components

This project is the library componets for React. 

## Features
- [x] Core components
- [x] Render testing
- [ ] Warning in PropTypes
- [ ] CD&CI to NPM and Preview
- [ ] Definition for develop, staging and production environments
- [ ] Custom Theme for Styled Componets

## Content
1. [Architecure](#1-architecture)
2. [Install](#2-install)
3. [Configure](#3-configure)
4. [Deploy](#4-deploy)
5. [References](#5-references)

## 1. Architecture

The file structure that we follow is the next:

```
generation-ui-components
│---README.md
│   wepack.config
│
│---assets
│   └---icons
│          icon1.svg
│          icon2.svg
│---components
│   └---ComponentName
│       │ tests
│       │ __snapshots__
│       │ ComponentName.js
│       │ index.js
│       │ README.md
│       │ ...
```

## 2. Install

```shell
$ npm install
```
* Is required [Node 10.16](https://nodejs.org/en/) or higher on your machine
* Is required [React 16](https://reactjs.org/) or higher on your machine

## 3. Run

* To visualize the Style Guide with all the developed components (the command start is not defined):
```shell
$ npm run styleguide
```
The components will be visible in http://localhost:6060/

* To connect this library to another project (say, Self Service)
1. Build the project
```shell
$ npm run build
```

2. Link this project locally to the project you want to use it. First do:
```shell
$ npm link
```
Then, in the project you want to use it:
```shell
$ npm link generation-ui-components
```

3. Whenever a change is made on this library that must be reflected on the linked project, build again.


## 4. Adding external libraries

To mantain the library with a small size, big dependencies should be external
To configure a external dependency go to webpack.config.js and add it.
For example, if you want to have the external library Happy Feet. You would import it as:
```
import HappyFeet from 'happy-feet';
```

So in externals you should add
```
'happy-feet': {
  commonjs: 'happy-feet', 
  commonjs2: 'happy-feet',
  amd: 'HappyFeet',
  root: 'HappyFeet',
},
```

In the same file, resolve > alias add:
```
'happy-feet': path.resolve(__dirname, './node_modules/happy-feet'),
```

## 5. Building
Run 
```shell
npm run build
```

#### Check that external libraries are not packed
Run 
```shell
npm run stats
```

Navigate to http://chrisbateman.github.io/webpack-visualizer/

Find the generated json file, called webpack-stats.js
Verify with the visualizer that your external library wasn't included

## 5. References

- [Styled Compoents](https://styled-components.com/)
- [How to package your React Component](https://itnext.io/how-to-package-your-react-component-for-distribution-via-npm-d32d4bf71b4f)
