Frameworks
The Carbon React library provides front-end developers and engineers a collection of reusable React components to build websites and user interfaces. Adopting the library enables developers to use consistent markup, styles, and behavior in prototype and production work.
Resources
Install
Using npm:npm install --save @carbon/react
If you prefer Yarn:
yarn add @carbon/react
Getting started
The
@carbon/react
Components require the use of a build pipeline in your project. This could be in the form of a bundler, framework, or other build tool. Some examples include Next.js, Vite, Parcel, and Webpack. A comprehensive list is available in the react documentation.
To use a component, you can import it directly from the package:
import { Button } from '@carbon/react';function MyComponent() {return <Button>Example usage</Button>;}
To include the styles for a specific component, you can either import all the styles from the project or include the styles for a specific component:
// Bring in all the styles for Carbon in your root/global stylesheet@use '@carbon/react';// Or bring in the styles for one component@use '@carbon/react/scss/components/button';
Icons
The @carbon/react package also provides icon components that you can include in your project. You can import these icon components from the
@carbon/react/icons
import { Add } from '@carbon/react/icons';function MyComponent() {return <Add />;}
A full list of available icons is provided in the icon library.
For a more in depth introduction to using
@carbon/react
Development
Please refer to the Contribution Guidelines before starting any work.
Using the server
We use Storybook for developing components.
yarn storybook
-
Open browser to
.http://localhost:9000/ -
Develop components in their respective folders (
or/components)./internal -
Author stories within the
files.*.stories.js*
List of available components
View available React Components in
the
Troubleshooting
If you experience any issues while getting set up with Carbon Components React, please head over to the GitHub repo for more guidelines and support. Please create an issue if your issue does not already exist.