npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@contentful/forma-36-react-components

v3.100.7

Published

Contentful UI Component Library

Downloads

72,783

Readme

Forma 36 React Components

This is a version 3 of Forma 36, which is not the current version of the package. From 12th July 2022 it will not be supported anymore. Please install current, supported version 4 of the library

A React component library for Forma 36 design system created by Contentful and powered by Storybook. You can access a Storybook website with the latest changes of the library here

Table of contents

Installing package

yarn add @contentful/forma-36-react-components

Or

npm install @contentful/forma-36-react-components

Usage

Import desired component into your project

import { Input } from '@contentful/forma-36-react-components';

For components in alpha stage, check the instructions in Alpha components

Import styles

import '@contentful/forma-36-react-components/dist/styles.css';

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

To start working on your components in Storybook, you will need to create stories for them. Look in the src/components directory for any .stories.js file. Storybook will automatically include any files with the .stories.js file extension.

Storybook is configured at scripts/.storybook/main.js.

Example component directory structure

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

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

Styling

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.

Component principles

We follow a number of principles when creating our components:

  1. A component is responsible for only its internal spacing

We follow the principle that a 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.

  1. Use descriptive PropTypes

We recommend the following naming convention for PropTypes to make them as clear as possible:

  • 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
  • Array - use a plural noun. E.g. items
  • Object - use a noun. E.g. item
  • Node - use the suffix 'Node'. E.g. containerNode
  • Element - use the suffix 'Element'. E.g. triggerElement
  • Event handler functions - use the prefix 'on'. E.g. onOpen, onClick

Adding documentation for component

We would like to make sure that every component contains a README file with recommendations and guidelines. Using yarn add-readme it will generate a template README file for you for the component that you specify. Follow steps in the CLI to create new README. Make sure that your documentation for the component contains following parts:

  1. A short summary of the component.
  2. Variations/types - try to provide the overview of the components variants.
  3. Example of usage - try to add couple of examples, that includes import
  4. Content recommendations - notes about best practices when it comes to the content used in the component, like message or title
  5. Best practices - try to describe in couple of points when to use the 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

Alpha components

We provide a number of alpha components which are unsupported and subject to breaking changes without warning. In short - use alpha components at your own risk.

Alpha components are provided outside of the main component library bundle and can be used as follows:

import { MyAlphaComponent } from '@contentful/forma-36-react-components/dist/alpha';