|
1 | 1 | # Auth0 React Components |
| 2 | + |
| 3 | +Library of Auth0 React components. This is for internal use by Auth0 only. |
| 4 | + |
| 5 | +## Installation |
| 6 | + |
| 7 | +If you are using npm you can do: |
| 8 | +``` |
| 9 | +npm i --save auth0/styleguide#react-components-1.0.0 |
| 10 | +``` |
| 11 | +This will let you consume the components as a collection of ES modules using a module bundler like Webpack or Browserify. |
| 12 | + |
| 13 | +You can use the components like this: |
| 14 | + |
| 15 | +``` |
| 16 | +import { Select, TryBanner, EmptyState } from 'auth0-styleguide-react-components'; |
| 17 | +``` |
| 18 | + |
| 19 | +Also you can download the files from our CDN: |
| 20 | + |
| 21 | +``` |
| 22 | +<link rel="stylesheet" href="https://cdn.auth0.com/styleguide-react-components/0.0.0/react-components.css" /> |
| 23 | +<script src="https://cdn.auth0.com/styleguide-react-components/0.0.0/react-components.js"></script> |
| 24 | +``` |
| 25 | + |
| 26 | +This will include an UMD version that make the components available as a `window.Auth0ReactComponents` global variable. |
| 27 | + |
| 28 | +## Development |
| 29 | + |
| 30 | +**Node version: 6.9.x NPM version: 3.10.x** |
| 31 | + |
| 32 | +### Add a new component |
| 33 | + |
| 34 | +You can develop new components using [React StoryBook](https://github.com/kadirahq/react-storybook). Just run `npm start` and add your component inside the `/src` folder with the following files: |
| 35 | + |
| 36 | +#### **index.js** |
| 37 | +Main component file, it should export the main component. |
| 38 | + |
| 39 | +We use [react-docgen](https://github.com/reactjs/react-docgen) to document our components using the following structure: |
| 40 | +``` |
| 41 | +import React, { PropTypes } from 'react'; |
| 42 | +
|
| 43 | +/** |
| 44 | + * Example component title: Example component description. |
| 45 | + */ |
| 46 | +const ExampleComponent = ({ prop1, prop2 }) => ( |
| 47 | + <div>Example component</div> |
| 48 | +); |
| 49 | +
|
| 50 | +ExampleComponent.propTypes = { |
| 51 | + /** |
| 52 | + * prop1 description |
| 53 | + */ |
| 54 | + prop1: PropTypes.array.isRequired, |
| 55 | + /** |
| 56 | + * prop2 description |
| 57 | + */ |
| 58 | + prop2: PropTypes.number.isRequired, |
| 59 | +}; |
| 60 | +
|
| 61 | +export default ExampleComponent; |
| 62 | +``` |
| 63 | +#### **examples.js** |
| 64 | + |
| 65 | +Export an array of objects representing the different examples of the component to showcase them in the [Auth0 React Styleguide](https://styleguide.auth0.com/react). |
| 66 | + |
| 67 | +Each object of the array can have the following properties: |
| 68 | + |
| 69 | +| Property | Type | Description | |
| 70 | +|:---|:---|:---| |
| 71 | +|component|React element|React element| |
| 72 | +|code|string|Code of the component (should match the code of the component property) |
| 73 | +|center|boolean|Center the component in the middle of the playground |
| 74 | +|title|string|Example title |
| 75 | +|showTitle|boolean|Show the example title |
| 76 | +|url|string| Url for the component page |
| 77 | + |
| 78 | +#### **index.test.js** |
| 79 | + |
| 80 | +Test your component using [mocha](https://github.com/mochajs/mocha), [chai](https://github.com/chaijs/chai) and [enzyme](https://github.com/airbnb/enzyme). |
| 81 | + |
| 82 | +#### **index.stories.js** |
| 83 | + |
| 84 | +Add stories for your React component. You can check [React StoryBook - Writing Stories](https://getstorybook.io/docs/react-storybook/basics/writing-stories) for more information. |
| 85 | + |
| 86 | +### Components style |
| 87 | + |
| 88 | +Follow this conventions when you are developing components: |
| 89 | + |
| 90 | +- Your components should be [stateless functional components](https://medium.com/@joshblack/stateless-components-in-react-0-14-f9798f8b992d#.3bqak5qjt). |
| 91 | +- Add propTypes for all properties and add the proper comments so that information is shown in the Auth0 React Styleguide. |
| 92 | +- Prefix your component css classes with it's name so it doesn't conflict with others existing classes. |
| 93 | + |
| 94 | + |
| 95 | +### Releasing a new version |
| 96 | + |
| 97 | +Complete |
0 commit comments