A React component library for Contentful, powered by Storybook.
yarn add @contentful/forma-36-react-components
Or for NPM
npm i @contentful/forma-36-react-components
import { Input } from '@contentful/forma-36-react-components';
import '@contentful/forma-36-react-components/dist/styles.css';
nvm use
yarn
or
npm i
Storybook is a UI development environment we are using to power our component library. Using Storybook allows us to work on components in isolation.
yarn start
Using Storybook requires you to wrap your component in a story. Look in the src/components
directory for an example .stories.js
file. Storybook has been configured to automatically include any files with the .stories.js
file extension.
Storybook is setup using its own Webpack configuration file located at tools/.storybook/webpack.config.js
.
A component's directory should resemble the following:
YourComponent
├── index.js // A file for exporting your component
├── YourComponent.js // Your React component
├── YourComponent.css // Component styles
├── YourComponent.stories.js // Storybook for the component
└── YourComponent.test.js. // Component tests
We are using postcss-preset-env for styling our components. Using postcss-preset-env allows us to use the latest CSS syntax without having to wait for browser support. tools/postcss.config.js
is used for adding plugins and configuration.
You can use Plop to scaffold new components. Run yarn add-component
and follow the steps in the CLI to create a component. Using your input here, Plop will generate the relevant files and add the relevant imports/exports to the main src/index.js
file required to make the component available when publishing the library.
Here is the example output of running the yarn add-component
command:
? What is the name of your component? button
[SUCCESS] add /src/components/Button/Button.js
[SUCCESS] add /src/components/Button/Button.css
[SUCCESS] add /src/components/Button/Button.test.js
[SUCCESS] add /src/components/Button/Button.stories.js
[SUCCESS] modify /src/index.js
[SUCCESS] modify /src/index.js
You can also use Plop to scaffold documentation sections in Storybook. Run yarn add-documentation
and follow the steps in the CLI to create new documentation. Using your input here, Plop will generate the relevant files required to make the documentation show in Storybook.
Here is the example output of running the yarn add-documentation
command:
? What is the title of your documentation? general
[SUCCESS] add /.storybook/docs/General/General.md
[SUCCESS] add /.storybook/docs/General/General.stories.js
We are using Jest and Enzyme to test our components.
Tests are kept next to their components and use the .test.js
file extension.
yarn test
It is recommended to run tests in development with the optional --watch
flag.
yarn test --watch
We are using a combination of Webpack and Babel to create builds of our component library. We use Webpack with the tools/webpack.production.config.js
config to build a stylesheet including all CSS used for our components using the ExtractTextPlugin. Babel is used for transpiling our React components into CommonJS modules. Babel and Webpack both output the build to the dist
directory.
yarn build
This project uses the Angular JS Commit Message Conventions, via semantic-release. See the semantic-release Default Commit Message Format section for more details.
You can commit the changes by running
yarn commit
We recommend the following naming convention for PropTypes:
- Array - use plural nouns. e.g.
items
- Number - use a prefix or suffix to imply that the prop accepts a number. e.g.
numItems
,itemCount
,itemIndex
- Boolean - use the prefix 'is'/'can'/'has'. e.g.
isVisible
,canExpand
,hasImage
- Object - use a noun. e.g.
item
- Node - use the prefix 'node'. e.g.
containerNode
- Element - use the prefix 'element'. e.g.
triggerElement
- Event handler functions - use the prefix 'on'. e.g.
onOpen
,onClick