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

@doofiss/web-components-test

v2.3.0

Published

Carbon web components

Downloads

6

Readme

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

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/web-components

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

The original repository, carbon-web-components, has been archived. All future work for the package will take place in this monorepo. Please visit the original repository for full history of the files.

The effort stems from https://github.com/carbon-design-system/issue-tracking/issues/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/v2/latest/accordion.min.js"></script>

<!-- By specific version -->
<script
  type="module"
  src="https://1.www.s81c.com/common/carbon/web-components/version/v2.0.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-icon.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/v2/latest/accordion.rtl.min.js"></script>

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

<cds-dropdown trigger-content="Select an item">
  <cds-dropdown-item value="all">Option 1</cds-dropdown-item>
  <cds-dropdown-item value="cloudFoundry">Option 2</cds-dropdown-item>
  <cds-dropdown-item value="staging">Option 3</cds-dropdown-item>
  <cds-dropdown-item value="dea">Option 4</cds-dropdown-item>
  <cds-dropdown-item value="router">Option 5</cds-dropdown-item>
</cds-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

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 CDSDropdown from '@carbon/web-components/es/components-react/dropdown/dropdown.js';
import CDSDropdownItem from '@carbon/web-components/es/components-react/dropdown/dropdown-item.js';

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

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. cd packages/carbon-web-components
  4. yarn wca && yarn storybook

List of available components

View available web components at: https://www.ibm.com/standards/carbon/carbon-web-components. 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 cds-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.