Coder Social home page Coder Social logo

carbon-design-system / carbon-web-components Goto Github PK

View Code? Open in Web Editor NEW
466.0 27.0 81.0 695.33 MB

Carbon Design System variant on top of Web Components

Home Page: https://web-components.carbondesignsystem.com/

License: Apache License 2.0

JavaScript 8.43% HTML 0.37% TypeScript 85.76% SCSS 5.41% Shell 0.03%
ibm web-components design-system component-library carbon-design-system community hacktoberfest

carbon-web-components's Introduction

โ— 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

carbon-web-components's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

carbon-web-components's Issues

Bug: Datepicker, Single with Calendar on Mobile

URL:
https://custom-elements.carbondesignsystem.com/?path=/story/date-picker--single-with-calendar

Steps to Reproduce:
Load the above URL in Chrome using any mobile device emulation

Error:

flatpickr.js:2524 TypeError: Cannot read property 'addEventListener' of undefined
    at on (on.js:14)
    at Object.init (shadow-dom-events-plugin.js:142)
    at triggerEvent (flatpickr.js:2365)
    at init (flatpickr.js:615)
    at FlatpickrInstance (flatpickr.js:2501)
    at _flatpickr (flatpickr.js:2520)
    at flatpickr (flatpickr.js:2547)
    at HTMLElement._instantiateDatePicker (date-picker.js:323)
    at HTMLElement._handleSlotChange (date-picker.js:282)
    at EventPart.handleEvent (parts.js:450)

Component: Data table

Basic feature have been implemented in #37. The remainders may go to one of following milestones.

Vue stories

#60 added Angular/React stories. Great to have Vue stories, too.

Progress line width

I was trying to fill all the width of the screen with the progress-line component but it seems that it has a fixed width in different points of the styles.

We can modify the bx-progress-step component but no the internal width of the line that it comes from the .bx--progress-line:
Screen Shot 2020-02-26 at 5 18 28 PM

Should this width of the span instead to be fixed to be 100%? Just to grow with the width of the element accordingly. How this variable is not being exposed through a var I suppose that we don't have a workaround for this case.

Build: Consider shipping .d.ts files

For TypeScript users. Given our source code is written in TypeScript, likely that we can just use the appropriate toolchain for that purpose.

Overflow menu and interactive tooltip: Problems with closing

From @cal-smith at #215:

I will note that the overflow menu and tooltip don't seem to close properly - the tooltip sometimes closes when I click on it, but doesn't seem to close when I click outside it, while the overflow menu never seems to close (clicking the trigger, or outside don't have any affect) ... I don't see any errors in the console unfortunately, so I'm not sure where the cause is

Replace classnames by lit-html/classMap

We tested that the last PR that @asudoh did about the babel dependencies and ESM modules it worked (really thanks!) but we found that we continue having problems with the classnames library now. This library use CJS modules so our proposal is to change this library by the classMap imported by the library lit-html that you have now as dependency in the project. With this change and taking the button component as an example the next code:

const classes = classnames(`${prefix}--btn`, {
      [`${prefix}--btn--${kind}`]: kind,
      [`${prefix}--btn--disabled`]: disabled,
      [`${prefix}--btn--icon-only`]: hasIcon && !hasMainContent,
      [`${prefix}--btn--sm`]: small,
      [`${prefix}-ce--btn--has-icon`]: hasIcon,
    });

would change to this:

const classes = classMap({
          [`${prefix}--btn`]: true,
          [`${prefix}--btn--${kind}`]: kind,
          [`${prefix}--btn--disabled`]: disabled,
          [`${prefix}--btn--icon-only`]: hasIcon && !hasMainContent,
          [`${prefix}--btn--sm`]: small,
          [`${prefix}-ce--btn--has-icon`]: hasIcon
        });

For the button component at least this worked locally in the fork that I did so if you are agree I can try to make a PR with this change in the different components.

Support for ESM modules

I was trying to add the carbon components in a project but I found some problems to add the library.

Initially this piece of code: https://jsbin.com/texojikiri/edit?html,output doesn't work properly until you delete the line import 'https://unpkg.com/[email protected]/es/components/button/button.js?module'; and after that everything goes well.

This can be because during the build process it seems that the library exports some things from babel as CJS instead of ESM so we can't use by default the different components.

Notification proposal

Something that we are trying to achieve with the notification component is to close the notification after X ms but by now and from what I could investigate through the code and storybook the library doesn't have yet a open and a close event to modify the notification behaviour.

Looking into the spec for this component it seems that it has a remove event to handle this kind of things. I don't know if it can be possible to implement it.

Build: Optimize for post-IE

Given this repository itself it optimize for post-IE era, make our (module) builds do that, too. Applications that need IE support can re-transpile.

Build: Consider auto-generating React wrapper

Currently (most of) the React stories (introduced in #60) have wrapper React components to correctly map React props to attributes/events. This issue is for tracking an effort to potentially auto-generate the wrapper using the content of @property() decorator as well as one of eventSomething static properties.

Event handlers don't need to be instance properties

I noticed that here: https://github.com/carbon-design-system/carbon-custom-elements/blob/master/src/components/button/button.ts#L47 there's an event handler property, presumably to capture the this reference.

This isn't necessary with the @ event syntax in lit-html when used from within LitElement. LitElement passes itself as the "event context" to lit-html during render, and event handlers are called with the element as the this reference. So handler can be normal class methods, which saves on memory by not creating multiple handler instances.

TypeScript 3.8 breaking change

With the launch of the TypeScript 3.8 version Microsoft introduced a breaking that affects to the carbon-custom-elements. As we can see in the next image:

Screen Shot 2020-02-27 at 10 20 50 AM

It seems that after 3.8 version the index must contain a strict type and we are using in the addEventListeners and removeEventListeners (from what I could investigate) a K or K_1 type to index.

Tag: Unused selectors

Found selectors like :host(#{$prefix}--tag--red), :host(#{$prefix}--tag--filter), etc. which corresponds to <bx--tag--red>/<bx--tag--filter> that don't seem to exist.

Current tag code seems to style thing in an element in shadow DOM. If we continue this way (similar to <bx-btn>), above selectors will no longer be needed. If we directly style the host element (<bx-tag>/<bx-filter-tag>) and remove the "styling-purpose" shadow element (in a similar manner to what we do with <bx-accordion-item>), we need to change above selectors so they match the right host elements.

Review dependencies

In the Readme there is:

npm install -S carbon-custom-elements carbon-components lit-html lit-element lodash-es @babel/runtime

Why the dependencies are not included? To have an easy install like:

npm install carbon-custom-elements

Theme configuration doubt

With the carbon-custom-elements how can I give a theme to a component? For example, how can I setup the g100 theme to a modal? Thanks in advance.

Firefox compatibility

Working with the different components we found that the checkbox doesn't work in Firefox 71.0. As a test if you run the storybook in Chrome you can see the actions fired:
Screen Shot 2020-01-03 at 4 26 12 PM
Not the same in Firefox where we see the actions empty:
Screen Shot 2020-01-03 at 4 26 49 PM

Storybook: Migrate DocsPage to MDX docs

MDX docs provides more flexible way to write documentation, and paves the cowpath toward web-component-analyzer integration. This issue is tracking the effort of such move.

A prototype based on this recipe can be found at here. Tasks identified during the prototype are:

  • Some setups, e.g. WebPack config
  • Rename src/components/some-component/README.md to src/components/some-component/some-component-story.mdx and:
    • Add story preview
    • Move storyDescription (e.g. one for tile) to the MDX
  • Set parameters.docs of MDX story exports (e.g. one for button) to CSF story exports

Build: Create bundled build

Currently creation of bundled build is missing in our build chain. This issue is for keeping track of the effort to create one.

Progress indicator color question

Using the progress-indicator component we checked that some colors are different from the original design:

From the original carbon design:
Screen Shot 2020-01-27 at 12 50 18 PM

From the current carbon-custom-library:
Screen Shot 2020-01-27 at 12 50 30 PM

To be more precise the color of the circle (the fill property) is blue and in carbon is black. I suppose that this is because for the fill property you are using --cds-interactive-01. I don't know if this difference is intentional, just to know. Thanks in advance!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.