@contentful/f36-components

Contentful UI Component Library

Usage no npm install needed!

<script type="module">
  import contentfulF36Components from 'https://cdn.skypack.dev/@contentful/f36-components';
</script>

README

Forma 36 React Components

A React component library for Forma 36 design system created by Contentful and powered by Storybook and (Next.js)[https://nextjs.org/].

Table of contents

Installing package

yarn add @contentful/f36-components

Or

npm install @contentful/f36-components

Usage

Import desired component into your project

import { Button } from '@contentful/f36-components';

Development

For local development, in the root of the repo run yarn to install all dependencies and then yarn build to build all packages. This package depends on several other Forma 36 packages so you will need to build all of them.

Storybook

We use Storybook to create a development environment for our component library. To start it locally run:

yarn storybook

When creating new component, before you start, please have a look at our contribution model for Forma 36.

Example component directory structure

A component's directory should resemble the following:

/my-component
  /examples
  /src
    index.ts // A file for exporting your component
    MyComponent.tsx  // Your React component
    MyComponent.test.tsx // Component tests
    MyComponent.styles.ts // Component styles
  /stories
    # stories for storybook of each component inside the package
  README.mdx
  package.json

For more detailes you can have a look in document that describes folder structure in details.

If you use yarn generate in the root of the repo, this structure will be created automatically for you

Code Style Guide

Our code style guide

Component principles

We follow a number of principles when creating our components:

  1. A component is responsible for only its internal spacing

Component should only be responsible for its own internal spacing - never external spacing. This means that we're flexible in where our components can be used without having to override margins. The only outlier from this rule are typography components - they can manage their own margins. To handle margins and layout you can use our core components, like:

Adding documentation for component

We would like to make sure that every component contains a README file with recommendations and guidelines. Make sure that your documentation for the component contains following parts:

  1. A short summary of the component.
  2. Import - provide example how to import component.
  3. Examples - try to add couple of examples, both basic and more advanced, where component is used in the context with other components.
  4. Props (API reference) - Overview of properties
  5. Content guideliness - try to describe in best practices around content for your component
  6. Accessibility - If possible, we strongly recommend providing accessibility guidelines.

Testing

We are using Jest and Testing Library to test our components.

Tests are kept next to their components and use the .test.js file extension.

Run tests

yarn test

It is recommended to run tests in development with the optional --watch flag.

yarn test --watch

Building

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.

Create a build of the library

yarn build

Commits

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