Convert Figma logo to code with AI

carbon-design-system logocarbon-components-react

React components for the Carbon Design System

1,080
399
1,080
0

Top Related Projects

Material UI: Comprehensive React component library that implements Google's Material Design. Free forever.

An enterprise-class UI design language and React UI library

Bootstrap components built with React

A utility-first CSS framework for rapid UI development.

37,442

⚡️ Simple, Modular & Accessible UI Components for your React Applications

84,226

Storybook is the industry standard workshop for building, documenting, and testing UI components in isolation

Quick Overview

Carbon Components React is a comprehensive React component library that implements IBM's Carbon Design System. It provides a set of reusable, accessible, and customizable UI components for building modern web applications with a consistent look and feel aligned with IBM's design principles.

Pros

  • Extensive collection of pre-built, accessible React components
  • Consistent design language following IBM's Carbon Design System
  • Regular updates and active maintenance by IBM and the community
  • Comprehensive documentation and design guidelines

Cons

  • Learning curve for developers unfamiliar with IBM's design system
  • Large bundle size if importing the entire library
  • Some components may be overly opinionated for certain projects
  • Styling customization can be challenging due to the strict design system

Code Examples

  1. Using a Button component:
import { Button } from '@carbon/react';

function MyComponent() {
  return <Button>Click me</Button>;
}
  1. Creating a modal dialog:
import { Modal } from '@carbon/react';

function MyModal({ open, onClose }) {
  return (
    <Modal open={open} onRequestClose={onClose} modalHeading="Example Modal">
      <p>This is the modal content.</p>
    </Modal>
  );
}
  1. Implementing a data table:
import { DataTable, Table, TableHead, TableRow, TableHeader, TableBody, TableCell } from '@carbon/react';

const headers = [
  { key: 'name', header: 'Name' },
  { key: 'age', header: 'Age' },
];

const rows = [
  { id: '1', name: 'John Doe', age: 30 },
  { id: '2', name: 'Jane Smith', age: 25 },
];

function MyDataTable() {
  return (
    <DataTable rows={rows} headers={headers}>
      {({ rows, headers, getHeaderProps, getTableProps }) => (
        <Table {...getTableProps()}>
          <TableHead>
            <TableRow>
              {headers.map((header) => (
                <TableHeader {...getHeaderProps({ header })}>
                  {header.header}
                </TableHeader>
              ))}
            </TableRow>
          </TableHead>
          <TableBody>
            {rows.map((row) => (
              <TableRow key={row.id}>
                {row.cells.map((cell) => (
                  <TableCell key={cell.id}>{cell.value}</TableCell>
                ))}
              </TableRow>
            ))}
          </TableBody>
        </Table>
      )}
    </DataTable>
  );
}

Getting Started

  1. Install the package:
npm install @carbon/react
  1. Import and use components in your React application:
import React from 'react';
import { Button } from '@carbon/react';

function App() {
  return (
    <div>
      <h1>My Carbon App</h1>
      <Button>Click me</Button>
    </div>
  );
}

export default App;
  1. (Optional) Import the Carbon styles in your main CSS file:
@import '@carbon/react/scss/styles.scss';

Competitor Comparisons

Material UI: Comprehensive React component library that implements Google's Material Design. Free forever.

Pros of Material-UI

  • Larger community and ecosystem, with more third-party components and resources
  • More comprehensive documentation and examples
  • Highly customizable theming system with built-in support for CSS-in-JS

Cons of Material-UI

  • Steeper learning curve due to more complex API and extensive features
  • Larger bundle size, which may impact initial load times
  • Less opinionated design, requiring more effort to achieve a consistent look

Code Comparison

Material-UI:

import { Button, TextField } from '@material-ui/core';

<Button variant="contained" color="primary">
  Submit
</Button>
<TextField label="Name" variant="outlined" />

Carbon Components React:

import { Button, TextInput } from 'carbon-components-react';

<Button kind="primary">Submit</Button>
<TextInput labelText="Name" />

Both libraries offer similar components, but Material-UI provides more variants and customization options out of the box. Carbon Components React follows a more streamlined approach, adhering closely to the Carbon Design System guidelines.

An enterprise-class UI design language and React UI library

Pros of Ant Design

  • Larger component library with more pre-built components
  • Extensive documentation and examples
  • Strong community support and frequent updates

Cons of Ant Design

  • Heavier bundle size due to more components
  • Less customizable design system compared to Carbon
  • Steeper learning curve for beginners

Code Comparison

Ant Design button example:

import { Button } from 'antd';

const MyComponent = () => (
  <Button type="primary">Click me</Button>
);

Carbon Components React button example:

import { Button } from 'carbon-components-react';

const MyComponent = () => (
  <Button kind="primary">Click me</Button>
);

Both libraries offer similar component APIs, but Ant Design tends to use type for variant selection, while Carbon uses kind. Ant Design also provides more button types out of the box, whereas Carbon focuses on a smaller set of core variants.

Ant Design is known for its comprehensive set of components and extensive documentation, making it a popular choice for large-scale applications. However, this comes at the cost of a larger bundle size and potentially less flexibility in customization.

Carbon Components React, on the other hand, offers a more streamlined approach with a focus on customization and adherence to IBM's design system. It may have fewer pre-built components but provides more flexibility for creating unique designs.

Bootstrap components built with React

Pros of react-bootstrap

  • Larger community and more widespread adoption, leading to better support and resources
  • Lighter weight and faster to load, with a smaller bundle size
  • More flexible and customizable, allowing for easier integration with existing projects

Cons of react-bootstrap

  • Less comprehensive design system compared to Carbon Components React
  • May require more manual styling and customization to achieve a cohesive look
  • Fewer enterprise-focused components and features

Code Comparison

react-bootstrap:

import { Button } from 'react-bootstrap';

<Button variant="primary">Click me</Button>

carbon-components-react:

import { Button } from 'carbon-components-react';

<Button kind="primary">Click me</Button>

Both libraries offer similar component APIs, but Carbon Components React often provides more specialized props and options for enterprise use cases. react-bootstrap tends to have a simpler API, which can be beneficial for quick prototyping and smaller projects. However, Carbon Components React offers a more comprehensive set of components and design guidelines, making it better suited for large-scale enterprise applications that require a consistent and accessible user interface.

A utility-first CSS framework for rapid UI development.

Pros of Tailwind CSS

  • Highly customizable and flexible, allowing for rapid UI development
  • Utility-first approach enables quick styling without leaving HTML
  • Smaller bundle size due to purging unused styles

Cons of Tailwind CSS

  • Steeper learning curve for developers used to traditional CSS
  • Can lead to cluttered HTML with many utility classes
  • Less opinionated, requiring more design decisions from developers

Code Comparison

Carbon Components React:

<Button kind="primary" size="small">
  Submit
</Button>

Tailwind CSS:

<button class="bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded">
  Submit
</button>

Carbon Components React provides pre-designed, accessible components with built-in functionality, while Tailwind CSS offers a utility-first approach for custom styling. Carbon is more opinionated and consistent, ideal for enterprise applications, whereas Tailwind CSS provides greater flexibility for unique designs but requires more manual implementation of accessibility and functionality.

37,442

⚡️ Simple, Modular & Accessible UI Components for your React Applications

Pros of Chakra UI

  • More customizable and flexible design system
  • Extensive theming capabilities with built-in dark mode support
  • Better accessibility features out of the box

Cons of Chakra UI

  • Less opinionated design, which may require more effort for consistent styling
  • Smaller ecosystem and community compared to Carbon Design System
  • Potentially steeper learning curve for developers new to utility-first CSS

Code Comparison

Chakra UI:

import { Box, Button } from "@chakra-ui/react"

function Example() {
  return (
    <Box bg="gray.100" p={4}>
      <Button colorScheme="blue">Click me</Button>
    </Box>
  )
}

Carbon Components React:

import { Button } from "carbon-components-react"

function Example() {
  return (
    <div className="bx--grid">
      <div className="bx--row">
        <Button kind="primary">Click me</Button>
      </div>
    </div>
  )
}

The code comparison shows that Chakra UI uses a more utility-based approach with props for styling, while Carbon Components React relies on predefined classes and component props for consistent styling across the design system.

84,226

Storybook is the industry standard workshop for building, documenting, and testing UI components in isolation

Pros of Storybook

  • Framework-agnostic: Works with various UI libraries and frameworks
  • Rich ecosystem: Extensive addons and plugins for enhanced functionality
  • Visual testing and documentation: Facilitates UI component testing and documentation

Cons of Storybook

  • Learning curve: Requires additional setup and configuration
  • Performance overhead: Can slow down development process for smaller projects

Code Comparison

Carbon Components React:

import { Button } from 'carbon-components-react';

function MyComponent() {
  return <Button>Click me</Button>;
}

Storybook:

import { Button } from './Button';

export default {
  title: 'Button',
  component: Button,
};

export const Primary = () => <Button primary>Click me</Button>;

Summary

Storybook is a versatile tool for developing and documenting UI components across various frameworks, offering a rich ecosystem of addons. It excels in visual testing and documentation but may introduce a learning curve and performance overhead. Carbon Components React, on the other hand, is specifically designed for React applications using the Carbon Design System, providing a more streamlined experience for projects aligned with IBM's design language.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

Project moved to carbon-design-system/carbon

This project has been moved to the Carbon monorepo. The specific package is available here. For more information about this transition, you can check out this post.

All issues and pull requests for this package should be made on that repo instead.

NPM DownloadsLast 30 Days