• This repository has been archived on 08/Mar/2023
  • Stars
    star
    477
  • Rank 92,112 (Top 2 %)
  • Language
    TypeScript
  • License
    Apache License 2.0
  • Created over 5 years ago
  • Updated almost 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Carbon Design System variant on top of Web Components

❗ This repository has moved!

Carbon Web Components is now part of the Carbon for IBM.com monorepo and will continue to have full official support by that team. In addition, plans for January 2023 (first release candidate) will include :

  • Upgrade to Carbon v11
  • Upgrade to Lit v2
  • Upgrade to Typescript v4

With these upgrades, this will be a major version release to Carbon Web Components v2. Plans to bring Carbon Web Components v2 to feature parity with Carbon React will occur throughout 2023.

If there are any questions, you can open an issue, reach out to us on Discord, or for IBMers can reach us at #carbon-for-ibm-dotcom on Slack!

A Carbon Design System variant that's as easy to use as native HTML elements, with no framework tax, no framework silo.

Carbon Design System

Carbon is an open-source design system built by IBM. With the IBM Design Language as its foundation, the system consists of working code, design tools and resources, human interface guidelines, and a vibrant community of contributors.

Carbon is released under the Apache-2.0 license

This project is using Percy.io for visual regression testing

carbon-web-components

carbon-web-components is a variant of Carbon Design System with Custom Elements v1 and Shadow DOM v1 specs.

The effort stems from carbon-design-system/issue-tracking#121. If you are interested in this project, adding πŸ‘ to the description of that GH issue, or even contributing, will be greatly appreciated!

Getting started

Using CDN

How to install

All components are available via CDN. This means that they can be added to your application without the need of any bundler configuration. Each component is available by the latest tag, or referencing a specific version (starting at version v1.16.0):

<!-- By `latest` tag -->
<script type="module" src="https://1.www.s81c.com/common/carbon/web-components/tag/latest/accordion.min.js"></script>

<!-- By specific version -->
<script type="module" src="https://1.www.s81c.com/common/carbon/web-components/version/v1.16.0/accordion.min.js"></script>

These are the list of available components via CDN:

  • accordion.min.js
  • breadcrumb.min.js
  • button.min.js
  • checkbox.min.js
  • code-snippet.min.js
  • combo-box.min.js
  • content-switcher.min.js
  • copy-button.min.js
  • data-table.min.js
  • date-picker.min.js
  • dropdown.min.js
  • file-uploader.min.js
  • floating-menu.min.js
  • form.min.js
  • inline-loading.min.js
  • input.min.js
  • link.min.js
  • list.min.js
  • loading.min.js
  • modal.min.js
  • multi-select.min.js
  • notification.min.js
  • number-input.min.js
  • overflow-menu.min.js
  • pagination.min.js
  • progress-indicator.min.js
  • radio-button.min.js
  • search.min.js
  • select.min.js
  • skeleton-placeholder.min.js
  • skeleton-text.min.js
  • skip-to-content.min.js
  • slider.min.js
  • structured-list.min.js
  • tabs.min.js
  • tag.min.js
  • textarea.min.js
  • tile.min.js
  • toggle.min.js
  • tooltip.min.js
  • ui-shell.min.js

To use the right-to-left (RTL) version of the artifacts, change the file extention from .min.js to .rtl.min.js. For example:

<!-- By `latest` tag (RTL) -->
<script type="module" src="https://1.www.s81c.com/common/carbon/web-components/tag/latest/accordion.rtl.min.js"></script>

<!-- By specific version (RTL) -->
<script type="module" src="https://1.www.s81c.com/common/carbon/web-components/version/v1.16.0/accordion.rtl.min.js"></script>

Basic usage

The CDN artifacts define the custom elements for the browser, so they can be directly used once the script tag has been added to the page. For example:

<!DOCTYPE html>
<html>
  <head>
    <script type="module" src="https://1.www.s81c.com/common/carbon/web-components/tag/latest/dropdown.min.js"></script>
    <style type="text/css">
      // Suppresses the custom element until it has been defined
      bx-dropdown:not(:defined),
      bx-dropdown-item:not(:defined) {
        visibility: hidden;
      }
    </style>
  </head>
  <body>
    <div id="app">
      <bx-dropdown trigger-content="Select an item">
        <bx-dropdown-item value="all">Option 1</bx-dropdown-item>
        <bx-dropdown-item value="cloudFoundry">Option 2</bx-dropdown-item>
        <bx-dropdown-item value="staging">Option 3</bx-dropdown-item>
        <bx-dropdown-item value="dea">Option 4</bx-dropdown-item>
        <bx-dropdown-item value="router">Option 5</bx-dropdown-item>
      </bx-dropdown>
    </div>
  </body>
</html>

Our example at CodeSandbox shows usage with only CDN artifacts:

Edit carbon-web-components

Using ES imports

How to install

To install carbon-web-components in your project, you will need to run the following command using npm:

npm install --save carbon-web-components

If you prefer Yarn, use the following command instead:

yarn add carbon-web-components

NOTE: Carbon and Lit dependencies will be managed by Carbon Web Components starting in v1.19.0. For earlier versions, these dependencies will have to be installed separately:

npm:

npm install --save carbon-components lit-html lit-element

Yarn:

yarn add carbon-components lit-html lit-element

Basic usage

Our example at CodeSandbox shows the most basic usage:

Edit carbon-web-components

The first thing you need is setting up a module bundler to resolve ECMAScript imports. The above example uses Webpack, but you can use other bundlers like Rollup too.

Once you set up a module bundler, you can start importing our component modules, for example:

import 'carbon-web-components/es/components/dropdown/dropdown.js';
import 'carbon-web-components/es/components/dropdown/dropdown-item.js';

Once you've imported the component modules, you can use our components in the same manner as native HTML tags, for example:

<bx-dropdown trigger-content="Select an item">
  <bx-dropdown-item value="all">Option 1</bx-dropdown-item>
  <bx-dropdown-item value="cloudFoundry">Option 2</bx-dropdown-item>
  <bx-dropdown-item value="staging">Option 3</bx-dropdown-item>
  <bx-dropdown-item value="dea">Option 4</bx-dropdown-item>
  <bx-dropdown-item value="router">Option 5</bx-dropdown-item>
</bx-dropdown>

Other usage guides

JavaScript framework support

In addition to the available Web Component versions of Carbon components, this library also supports usage with JavaScript frameworks like Angular, React, and Vue if the desire is to use instead of the pure framework versions of Carbon components. Specifically for React, this library comes with a wrapper implementation around the Carbon Web Components for more seamless integration with your React application.

This is achievable since Web Components is the modern browser standard, and works well with other front-end frameworks that exist in the application. In turn, this also comes with the benefits of encapsulation within the Shadow DOM:

Angular

Edit carbon-web-components with Angular

Angular users can use our components in the same manner as native HTML tags, too, once you add CUSTOM_ELEMENTS_SCHEMA schema to your Angular module, for example:

import { CUSTOM_ELEMENTS_SCHEMA, NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';

import { AppComponent } from './app.component';

@NgModule({
  schemas: [CUSTOM_ELEMENTS_SCHEMA],
  declarations: [AppComponent],
  imports: [BrowserModule],
  bootstrap: [AppComponent],
})
export class AppModule {}

The .d.ts files in carbon-web-components package are compiled with TypeScript 3.7. You can use TypeScript 3.7 in your Angular application with upcoming Angular 9.0 release, or with the following instructions, so your application can use those .d.ts files:

React

Edit carbon-web-components with React

You can use wrapper React components in carbon-web-components/es/components-react generated automatically from the custom elements which allows you to use our components seamlessly in your React code. Here's an example:

import React from 'react';
import { render } from 'react-dom';
import BXDropdown from 'carbon-web-components/es/components-react/dropdown/dropdown.js';
import BXDropdownItem from 'carbon-web-components/es/components-react/dropdown/dropdown-item.js';

const App = () => (
  <BXDropdown triggerContent="Select an item">
    <BXDropdownItem value="all">Option 1</BXDropdownItem>
    <BXDropdownItem value="cloudFoundry">Option 2</BXDropdownItem>
    <BXDropdownItem value="staging">Option 3</BXDropdownItem>
    <BXDropdownItem value="dea">Option 4</BXDropdownItem>
    <BXDropdownItem value="router">Option 5</BXDropdownItem>
  </BXDropdown>
);

render(<App />, document.getElementById('root'));

Note: Using the React wrapper requires an additional dependency, prop-types.

To run the wrapper React components in SSR environment requires Node 12.16.3 or above that supports "conditional mapping" feature:

Edit carbon-web-components with React SSR

Same Node version requirement applies to Next.js:

Edit carbon-web-components with React SSR

Vue

Edit carbon-web-components with Vue

Vue users can use our components in the same manner as native HTML tags, without any additional steps!

Getting started with development

  1. Fork this repository and clone it
  2. yarn install
  3. yarn wca && yarn storybook

Running React/Angular/Vue Storybook demo

List of available components

View available web components at: https://web-components.carbondesignsystem.com/. You can see usage information in several ways:

  1. Going to Docs tab, where it shows the usage and available attributes, properties and custom events.
  2. Clicking the KNOBS tab at the bottom and changing values there. Most knobs are shown as something like Button kind (kind), where kind is the attribute name
  3. Clicking the ACTION LOGGER tab at the bottom and interacting with the selected component. You may see something like bx-modal-closed which typically indicates that an event with such event type is fired. You can also expand the twistie to see the details of the event

Browser support

  • Latest Chrome/Safari/FF ESR
  • IE/Edge support is bast-effort basis
    • Some components may not be supported

To support IE, you need a couple additional setups:

  • Toolstack to re-transpile our code to ES5 (e.g. by specifying IE11 in @babel/preset-env configuration)
  • Polyfills, listed here

Here's an example code that shows such setup:

Edit carbon-web-components with IE

Coding conventions

Can be found at here.

Creating build

> yarn clean
> yarn build

You'll see the build artifacts in /path/to/carbon-web-components/es directory.

Running unit test

You can run unit test by:

> gulp test:unit

You can run specific test spec by:

> gulp test:unit -s tests/spec/dropdown_spec.ts

You can choose a browser (instead of Headless Chrome) by:

> gulp test:unit -b Firefox

You can keep the browser after the test (and re-run the test when files change) by:

> gulp test:unit -b Chrome -k

You can prevent code coverate instrumentation code from being generated by:

> gulp test:unit -d

You can update snapshots by:

> gulp test:unit --update-snapshot

Above options can be used together. This is useful to debug your code as you test:

> gulp test:unit -s tests/spec/dropdown_spec.ts -b Chrome -d -k

Running build integration test

You can run build integration test by:

> yarn test:integration:build

You can run a specific set of UI test steps (e.g. running tests/integration/build/form-angular_steps.js only) by:

> yarn test:integration:build form-angular_steps

By default Chrome runs in headless mode. You can show Chrome UI by:

> CI=false yarn test:integration:build

Running UI integration test

You can run UI integration test by:

> yarn test:integration:ui

You can run a specific set of UI test steps (e.g. running tests/integration/ui/dropdown_steps.js only) by:

> yarn test:integration:ui dropdown_steps

By default Chrome runs in headless mode. You can show Chrome UI by:

> CI=false yarn test:integration:ui

More Repositories

1

carbon

A design system built by IBM
JavaScript
7,718
star
2

carbon-components-svelte

Svelte implementation of the Carbon Design System
Svelte
2,665
star
3

carbon-components-react

React components for the Carbon Design System
JavaScript
1,080
star
4

carbon-design-kit

A versioned, comprehensive kit of the Carbon Design System visual assets (components, icons, pictograms, text styles, color styles, grid templates).
1,072
star
5

carbon-charts

πŸ“Š πŸ“ˆβ €Robust dataviz framework implemented using D3 & typescript
HTML
904
star
6

carbon-components-vue

Vue implementation of the Carbon Design System
JavaScript
607
star
7

carbon-components-angular

An Angular implementation of the Carbon Design System for IBM.
TypeScript
510
star
8

sveld

Generate TypeScript definitions for your Svelte components
Svelte
402
star
9

carbon-icons-svelte

Carbon Design System SVG icons as Svelte components
TypeScript
394
star
10

gatsby-theme-carbon

A Carbon inspired Gatsby theme
MDX
351
star
11

carbon-website

The website for the Carbon Design System.
MDX
261
star
12

carbon-for-ibm-dotcom

Carbon for IBM.com is based on the Carbon Design System for IBM
TypeScript
258
star
13

carbon-website-archive

The old website for the Carbon Design System. This repo is archived.
JavaScript
238
star
14

carbon-tutorial

An app for the Carbon Design System tutorial
JavaScript
157
star
15

carbon-pictograms-svelte

Carbon Design System SVG pictograms as Svelte components
TypeScript
119
star
16

carbon-addons-iot-react

A collection of React components shared between IBM Watson IoT products.
JavaScript
96
star
17

carbon-icons

SVG icon library for the Carbon Design System
HTML
85
star
18

ibm-products

A Carbon-powered React component library for IBM Products
JavaScript
81
star
19

design-language-website

IBM Design Language website
CSS
76
star
20

carbon-angular-starter

A simple starter app for bootstrapping applications with Carbon
TypeScript
76
star
21

ibm-security

A Carbon-powered React component library built by IBM Security
JavaScript
76
star
22

carbon-elements

Project moved to carbon-design-system/carbon
71
star
23

carbon-preprocess-svelte

Svelte preprocessors for the Carbon Design System
TypeScript
68
star
24

design-system-website

This repo has been archived, the new repo can can be found at
JavaScript
46
star
25

devtools

A simple set of tools for teams building live Carbon pages.
JavaScript
43
star
26

carbon-boilerplate

A simple boilerplate for rapid UI prototyping with Carbon components
JavaScript
42
star
27

carbon-for-ibm-dotcom-website

This is the Carbon for IBM.com website, which includes documentation and guidelines around design and development for IBM.com
MDX
39
star
28

carbon-for-ibm-dotcom-nextjs-template

This is a NextJS template utilizing Carbon for IBM.com React
JavaScript
33
star
29

carbon-tutorial-vue

JavaScript
31
star
30

carbon-react-native

The React Native implementation of the Carbon Design System
TypeScript
28
star
31

carbon-themes

A collection of themes for use with Carbon Components
28
star
32

carbon-addons-data-viz-react

DEPRECATED. Please use Carbon Charts instead
JavaScript
26
star
33

carbon-platform

The "next" version of the Carbon Design System website, as a platform.
JavaScript
22
star
34

carbon-tutorial-angular

An Angular app for the Carbon Design System tutorial
20
star
35

carbon-addons-ics

Carbon Add-on for IBM Collaboration Solutions
JavaScript
19
star
36

carbon-icons-angular

Carbon icons, in Angular!
JavaScript
19
star
37

gatsby-starter-carbon-theme

A Gatsby starter demonstrating the Gatsby Carbon theme
JavaScript
18
star
38

carbon-tutorial-svelte

An app for the Carbon Svelte tutorial
Svelte
18
star
39

tailwind-preset-carbon

JavaScript
17
star
40

icons-motion

A library of animated Carbon icons
JavaScript
17
star
41

carbon-addons-cloud

[DEPRECATED] Carbon Design System add-on for IBM Cloud
CSS
15
star
42

carbon-tutorial-nextjs

CSS
14
star
43

carbon-for-ibm-dotcom-nextjs-test

This is a sample NextJS application utilizing Carbon for IBM.com
JavaScript
14
star
44

carbon-sandbox

A theme playground for Carbon Components
CSS
13
star
45

carbon-addons-cloud-react

[DEPRECATED] React components for the Cloud Add-on
JavaScript
13
star
46

issue-tracking

For tracking issues that can't be put in the relevant open source repositories. Using to deprecate issue tracking in GHE.
11
star
47

carbon-design-system.framerfx

CSS
11
star
48

carbon-for-ibm-dotcom-web-components-template

This is an HTML Template utilizing Carbon for IBM.com Web Components. It contains a basic WebPack setup using Handlebars for page management, which includes the dds-dotcom-shell, along with other various patterns and components available in Carbon for IBM.com.
Handlebars
11
star
49

toolkit

[Experimental] A UI Toolkit for the Carbon Design System
JavaScript
10
star
50

stylelint-plugin-carbon-tokens

JavaScript
9
star
51

developer-essentials

For creation of Developer Essentials course for Carbon / Front-end Skills
9
star
52

uptime

Uptime monitoring for Carbon
Markdown
9
star
53

carbon-nextjs-template

Template for Next.js and Carbon
JavaScript
8
star
54

carbon-contribution

Documentation on how to contribute back to Carbon
7
star
55

carbon-spec

[WIP] Specification for the Carbon Design System
7
star
56

carbon-addons-beta-react

Beta React components. May be elevated into the main library.
JavaScript
7
star
57

carbonated

Internal services for building the Carbon Design System
JavaScript
6
star
58

carbon-addons-infrastructure

Carbon Add-on for IBM Cloud Infrastructure
JavaScript
6
star
59

carbon-utils-position

Position elements anywhere
TypeScript
6
star
60

carbon-addons-boilerplate-react

JavaScript
5
star
61

roadmap

Carbon Design System's roadmap.
5
star
62

sync

Internal tool for keeping project repositories in sync
JavaScript
5
star
63

carbon-addons-cloud-vanilla

JavaScript
4
star
64

carbon-addons-website

Carbon Design System add-on for design system website
CSS
4
star
65

carbon-for-ibm-dotcom-tutorial

JavaScript
4
star
66

carbon-badges

A site to apply for Carbon badges.
JavaScript
4
star
67

carbon-upgrade

[Experimental] A tool for upgrading Carbon versions (to v10): `npx carbon-upgrade`
4
star
68

carbon-for-ibm-dotcom-design-kit

A versioned, comprehensive kit of the Carbon for IBM.com visual assets.
4
star
69

carbon-addons-catalog-react

Bluemix Catalog components in React
JavaScript
3
star
70

carbon-labs

A collection of components and patterns implemented using Carbon Web Components for the IBM AI experience.
TypeScript
3
star
71

okrs

Objectives and key results for the Carbon team.
3
star
72

digital-design-ideation

3
star
73

carbon-shared-tests

Carbon Shared Tests are re-usable UI unit tests aligned to the Carbon Design System
TypeScript
3
star
74

carb

[Experimental] Tooling for managing design systems
Rust
2
star
75

ibm-cloud

Carbon for IBM Cloud
JavaScript
2
star
76

sandboxes

JavaScript
2
star
77

action-ibmcloud-cf

Common GitHub actions used in various repositories in carbon-design-system org, for deploying a IBM Cloud CF app.
JavaScript
2
star
78

rfcs

RFCs for changes to the Carbon Design System
2
star
79

carbon-sketch-assistant

Carbon Design System design validation directly in Sketch
TypeScript
2
star
80

incubator

[Experimental] Explore, build, and try-out new work with Carbon
JavaScript
2
star
81

remote-learning-enablement

https://remote-learning-enablement.vercel.app/remotelearning/
JavaScript
2
star
82

platform

[Internal] Tools and services for managing a design system
JavaScript
2
star
83

carbon-dco

Signed Developer Certificate of Origins for the Carbon Design System.
JavaScript
2
star
84

carbon-for-ibm-dotcom-web-components-test

Environment for testing Carbon for IBM.com web components as a mock application
Handlebars
2
star
85

repo-transfer-test

a repo to test the transferring from account to organization
JavaScript
1
star
86

Contentful-for-IBM.com

JavaScript
1
star
87

gatsby-theme-presentation

JavaScript
1
star
88

.github

1
star
89

pattern-contributions

This repository is a single place to triage, manage, and maintain pattern contributions to the Carbon Design System.
1
star
90

archived-v10-release-issues

The default for issues and epics is public. There may be rare occasions when an issue needs to remain confidential. If so, put that issue in this repo.
1
star
91

content-planning

This is a place to plan, organize, and communicate about Carbon content
1
star
92

ibm-cdai

IBM CDAI
1
star
93

carbon-job-stories

1
star
94

carbon-v11

1
star
95

carbon-style-stats

Dashboard for analyzing various Carbon stylesheet statistics
JavaScript
1
star
96

carbon-triage

Tools for helping with issue triage
JavaScript
1
star
97

carbon-tutorial-test1

Build an app with the Carbon Design System and Next.js
1
star
98

carbon-vega-theme

The official 4 Carbon themes offered for Vega users
SCSS
1
star