Skip to content

Commit

Permalink
feat(web-components): addition of web components to website (#2215)
Browse files Browse the repository at this point in the history
* feat(web-components): addition of web components to website

This PR introduced documentation around the support of Carbon Web
Components. This is a community contributed library that is based on the
 Web Components custom elements and shadow dom spec, and is the new
 browser standard.

* docs(web-components): adding link to web components on the homepage

* fix(mdxicon): adding webcomponents as an icon

* Update src/pages/developing/frameworks/web-components.mdx

Co-authored-by: Jan Child <[email protected]>

* Update src/pages/developing/frameworks/web-components.mdx

Co-authored-by: Jan Child <[email protected]>

* Update src/pages/developing/frameworks/web-components.mdx

Co-authored-by: Jan Child <[email protected]>

* Update src/pages/developing/frameworks/web-components.mdx

Co-authored-by: Jan Child <[email protected]>

* Update src/pages/developing/frameworks/web-components.mdx

Co-authored-by: Jan Child <[email protected]>

* Update src/pages/developing/frameworks/web-components.mdx

Co-authored-by: Jan Child <[email protected]>

* Update src/pages/developing/frameworks/web-components.mdx

Co-authored-by: Jan Child <[email protected]>

* docs(web-components): added section for framework wrappers

* docs(web-components): fix to run-on sentence

* docs(web-components): another small sentence fix

* docs(web-components): modification to the Javascript framework description

* docs(web-components): change usage of `web components` to lowercase

* fix(config): reverting local config files

* docs(web-components): added note on difference with framework wrappers

* Update src/pages/developing/frameworks/web-components.mdx

Co-authored-by: Jan Child <[email protected]>

* Update src/pages/developing/frameworks/web-components.mdx

Co-authored-by: Jan Child <[email protected]>

* Update src/pages/developing/frameworks/web-components.mdx

Co-authored-by: Jan Child <[email protected]>

* Update src/pages/developing/frameworks/web-components.mdx

Co-authored-by: Jan Child <[email protected]>

Co-authored-by: Jan Child <[email protected]>
  • Loading branch information
jeffchew and janchild authored Apr 9, 2021
1 parent f2ed696 commit a4edea7
Show file tree
Hide file tree
Showing 12 changed files with 288 additions and 16 deletions.
Binary file added src/components/MdxIcon/icons/webcomponents.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions src/components/MdxIcon/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import illustrator from './icons/illustrator.svg';
import react from './icons/react.png';
import vue from './icons/vue.png';
import angular from './icons/angular.png';
import webcomponents from './icons/webcomponents.png';
import npm from './icons/npm.svg';

const localIcons = {
Expand All @@ -22,6 +23,7 @@ const localIcons = {
react,
vue,
angular,
webcomponents,
npm,
};

Expand Down
19 changes: 19 additions & 0 deletions src/pages/developing/dev-resources/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,14 @@ your framework of choice.
<MdxIcon name="github" />
</ResourceCard>
</Column>

<Column colMd={4} colLg={4} noGutterSm>
<ResourceCard
subTitle="Carbon Web Components"
href="https://github.com/carbon-design-system/carbon-web-components">
<MdxIcon name="github" />
</ResourceCard>
</Column>
</Row>

### Storybooks
Expand Down Expand Up @@ -105,6 +113,17 @@ your framework of choice.

</ResourceCard>
</Column>

<Column colLg={4} colMd={4} noGutterSm>
<ResourceCard
subTitle="Carbon Web Components Storybook"
href="http://web-components.carbondesignsystem.com/"
>

<MdxIcon name="webcomponents" />

</ResourceCard>
</Column>
</Row>

### Tools
Expand Down
13 changes: 11 additions & 2 deletions src/pages/developing/frameworks/angular.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,17 @@
title: Frameworks
description:
The Carbon Design System is built React first. We also support core parts of
the system in vanilla JS, Angular, Vue, and Svelte.
tabs: ['React', 'Vanilla', 'Angular', 'Vue', 'Svelte', 'Other frameworks']
the system in vanilla JS, Angular, Vue, Svelte, and web components.
tabs:
[
'React',
'Vanilla',
'Angular',
'Vue',
'Svelte',
'Web Components',
'Other frameworks',
]
---

<PageDescription>
Expand Down
20 changes: 15 additions & 5 deletions src/pages/developing/frameworks/other-frameworks.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,25 @@
title: Frameworks
description:
The Carbon Design System is built React first. We also support core parts of
the system in vanilla JS, Angular, Vue, and Svelte.
tabs: ['React', 'Vanilla', 'Angular', 'Vue', 'Svelte', 'Other frameworks']
the system in vanilla JS, Angular, Vue, Svelte, and web components.
tabs:
[
'React',
'Vanilla',
'Angular',
'Vue',
'Svelte',
'Web Components',
'Other frameworks',
]
---

<PageDescription>

The Carbon Design System is built React first. We also support core parts of the
system in vanilla JS, Angular, Vue, and Svelte. If you’re using a different
framework, you can still build components by following the guidelines below.
system in vanilla JS, Angular, Vue, Svelte, and web components. If you’re using
a different framework, you can still build components by following the
guidelines below.

</PageDescription>

Expand Down Expand Up @@ -41,7 +51,7 @@ there are no zombie event handlers.

The easiest way to hook on the creation/destruction of DOM elements is by
defining a "wrapping component", with the JavaScript framework of your choice.
Here's an example using Web Components'
Here's an example using web components'
[Custom Elements v1 spec](https://developer.mozilla.org/en-US/docs/Web/Web_Components/Custom_Elements),
but the notion of components, along with the lifecycle callbacks, are commonly
found in many other JavaScript frameworks.
Expand Down
13 changes: 11 additions & 2 deletions src/pages/developing/frameworks/react.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,17 @@
title: Frameworks
description:
The Carbon Design System is built React first. We also support core parts of
the system in vanilla JS, Angular, Vue, and Svelte.
tabs: ['React', 'Vanilla', 'Angular', 'Vue', 'Svelte', 'Other frameworks']
the system in vanilla JS, Angular, Vue, Svelte, and web components.
tabs:
[
'React',
'Vanilla',
'Angular',
'Vue',
'Svelte',
'Web Components',
'Other frameworks',
]
---

<PageDescription>
Expand Down
13 changes: 11 additions & 2 deletions src/pages/developing/frameworks/svelte.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,17 @@
title: Frameworks
description:
The Carbon Design System is built React first. We also support core parts of
the system in vanilla JS, Angular, Vue, and Svelte.
tabs: ['React', 'Vanilla', 'Angular', 'Vue', 'Svelte', 'Other frameworks']
the system in vanilla JS, Angular, Vue, Svelte, and web components.
tabs:
[
'React',
'Vanilla',
'Angular',
'Vue',
'Svelte',
'Web Components',
'Other frameworks',
]
---

<PageDescription>
Expand Down
15 changes: 12 additions & 3 deletions src/pages/developing/frameworks/vanilla.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,17 @@
title: Frameworks
description:
The Carbon Design System is built React first. We also support core parts of
the system in vanilla JS, Angular, Vue, and Svelte.
tabs: ['React', 'Vanilla', 'Angular', 'Vue', 'Svelte', 'Other frameworks']
the system in vanilla JS, Angular, Vue, Svelte, and web components.
tabs:
[
'React',
'Vanilla',
'Angular',
'Vue',
'Svelte',
'Web Components',
'Other frameworks',
]
---

<PageDescription>
Expand Down Expand Up @@ -298,7 +307,7 @@ there are no zombie event handlers.

The easiest way to hook on the creation/destroy of DOM elements is defining a
"wrapping component", with the JavaScript framework of your choice. Here's an
example using Web Components'
example using web components'
[Custom Elements v1 spec](https://developer.mozilla.org/en-US/docs/Web/Web_Components/Custom_Elements),
but the notion of components, along with the lifecycle callbacks, are commonly
found in many other JavaScript frameworks.
Expand Down
13 changes: 11 additions & 2 deletions src/pages/developing/frameworks/vue.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,17 @@
title: Frameworks
description:
The Carbon Design System is built React first. We also support core parts of
the system in vanilla JS, Angular, Vue, and Svelte.
tabs: ['React', 'Vanilla', 'Angular', 'Vue', 'Svelte', 'Other frameworks']
the system in vanilla JS, Angular, Vue, Svelte, and web components.
tabs:
[
'React',
'Vanilla',
'Angular',
'Vue',
'Svelte',
'Web Components',
'Other frameworks',
]
---

<PageDescription>
Expand Down
185 changes: 185 additions & 0 deletions src/pages/developing/frameworks/web-components.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,185 @@
---
title: Frameworks
description:
The Carbon Design System is built React first. We also support core parts of
the system in vanilla JS, Angular, Vue, Svelte, and web components.
tabs:
[
'React',
'Vanilla',
'Angular',
'Vue',
'Svelte',
'Web Components',
'Other frameworks',
]
---

<PageDescription>

The library provides front-end developers and engineers a collection of reusable
web components to build websites and user interfaces. Adopting the library
enables developers to use consistent markup, styles, and behavior in prototype
and production work.

This library uses Custom Elements v1 and Shadow DOM v1 specs.

</PageDescription>

<InlineNotification>

The web components library is maintained by members of the Carbon community. For
support, contact the
[Carbon Web Components team](https://github.com/carbon-design-system/carbon-web-components/issues/new/choose).

</InlineNotification>

## Resources

<Row className="resource-card-group">
<Column colLg={4} colMd={4} noGutterSm>
<ResourceCard
subTitle="Carbon Web Components"
href="https://web-components.carbondesignsystem.com"
>

![Storybook icon](images/storybook.svg)

</ResourceCard>
</Column>
<Column colMd={4} colLg={4} noGutterSm>
<ResourceCard
subTitle="Try web components with CodeSandbox"
href="https://codesandbox.io/s/github/carbon-design-system/carbon-web-components/tree/master/examples/codesandbox/basic"
>
<MdxIcon name="codesandbox" />
</ResourceCard>
</Column>
</Row>

## Getting started

To install `carbon-web-components` in your project, you will need to run the
following command using [npm](https://www.npmjs.com/):

```bash
npm install -S carbon-web-components carbon-components lit-html lit-element
```

If you prefer [Yarn](https://yarnpkg.com/en/), use the following command
instead:

```bash
yarn add carbon-web-components carbon-components lit-html lit-element
```

### Basic usage

Our example at [CodeSandbox](https://codesandbox.io) shows the most basic usage:

[![Edit carbon-web-components](https://codesandbox.io/static/img/play-codesandbox.svg)](https://codesandbox.io/s/github/carbon-design-system/carbon-web-components/tree/master/examples/codesandbox/basic)

The first thing you need to do is **set up a module bundler** to resolve
ECMAScript `import`s. The above example uses [Webpack](https://webpack.js.org) but you
can use other bundlers like [Rollup](https://rollupjs.org/) too.

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

```javascript
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:

```html
<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>
```

If you just want to try our components for demonstrations and so on, you can use
CDNs that support module mapping (for example, [JSPM](https://jspm.org)). With
CDNs, you can import just our modules in `<script type="module">`:

```html
<!DOCTYPE html>
<html>
<head>
<script type="module">
import 'https://jspm.dev/carbon-web-components/es/components/dropdown/dropdown.js';
import 'https://jspm.dev/carbon-web-components/es/components/dropdown/dropdown-item.js';
</script>
<style type="text/css">
#app {
font-family: 'IBM Plex Sans', 'Helvetica Neue', Arial, sans-serif;
width: 300px;
margin: 2rem;
}
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>
```

### List of available components

View available web components
[here](https://web-components.carbondesignsystem.com). Usage information is
available in the notes provided with each story.

### JavaScript framework integration

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:

- [Carbon Web Components with Angular](https://web-components.carbondesignsystem.com/angular/index.html)
- [Carbon Web Components with React](https://web-components.carbondesignsystem.com/react/index.html)
- [Carbon Web Components with Vue](https://web-components.carbondesignsystem.com/vue/index.html)

<InlineNotification>

**Note:** The approaches above detail the usage of Carbon Web Components within
popular JavaScript frameworks. The APIs are based on how the web components are
used, and differ from its pure framework counterparts (Carbon React, Carbon
Angular, Carbon Vue).

</InlineNotification>

## Troubleshooting

If you experience any issues while getting set up with Carbon Web Components,
please head over to the
[GitHub repo](https://github.com/carbon-design-system/carbon-web-components) for
more guidelines and support. Please
[create an issue](https://github.com/carbon-design-system/carbon-web-components/issues)
if your issue does not already exist.
1 change: 1 addition & 0 deletions src/pages/developing/get-started.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ question to you and will jump in to help you out.
- [#carbon-react](https://ibm-studios.slack.com/archives/C2K6RFJ1G)
- [#carbon-ng](https://ibm-studios.slack.com/archives/CBZC0LM2N)
- [#carbon-vue](https://ibm-studios.slack.com/archives/CAM5P6NR1)
- [#carbon-web-components](https://ibm-studios.slack.com/archives/CL83LMKSA)
- [#carbon-tutorial](https://ibm-studios.slack.com/archives/CJUGA7P6H)

And be sure to sign up for the latest Carbon news at
Expand Down
Loading

1 comment on commit a4edea7

@vercel
Copy link

@vercel vercel bot commented on a4edea7 Apr 9, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.