To install @carbon/ibmdotcom-web-components in your project, you will need to
run the following command using npm:
npm install -S @carbon/ibmdotcom-web-components
If you prefer Yarn, use the following command
instead:
yarn add @carbon/ibmdotcom-web-components
NOTE: Lit dependencies will be managed by Carbon for IBM.com starting in
v1.13.0. For earlier versions, Lit dependencies will have to be installed
separately:
npm:
npm install -S lit-html lit-element
Yarn:
yarn add lit-html lit-element
@carbon/ibmdotcom-web-components uses
lit for reactive templating on top of
raw Web Components standard and
lit/decorators for reactive
properties/attributes on top of lit.
Above CodeSandbox example uses
html-webpack-plugin
to let WebPack server
serve the .html file, but you can use other means to serve .html files,
for example, using Express server.
To prevent a flash of unstyled content (FOUC) from happening on your page be
sure to to display: none if a component has not been defined yet. For example
There are references to the process.env global variable in the our
web-components package and dependencies. If a build toolchain (e.g. WebPack’s
EnvironmentPlugin) to replace process.env.* is not used in your application,
you can place the following code in the polyfills.ts file of your application.
The CDN packages are available by NPM tags latest (full releases), next
(latest release candidate), and specific versions. The URL pattern for import
would be:
<!-- LATEST --><scripttype="module"src="https://1.www.s81c.com/common/carbon-for-ibm-dotcom/tag/v2/latest/dotcom-shell.min.js"></script><!-- NEXT --><scripttype="module"src="https://1.www.s81c.com/common/carbon-for-ibm-dotcom/tag/v2/next/dotcom-shell.min.js"></script>
A specific release would be called as:
<!-- SPECIFIC VERSION (available starting v1.6.0) --><scripttype="module"src="https://1.www.s81c.com/common/carbon-for-ibm-dotcom/version/v2.x.y/dotcom-shell.min.js"></script>
NOTE: The latest/next tags are moving versions. While beneficial to always
stay on the most recent version, it is recommended to choose a specific
version and properly test your application when upgrading to a newer version.
Shadow DOM, one of the
standards used in Carbon for IBM.com Web Components, isolates the web component
styles from the application styles. This means those two styles won't adversely
affect each other.
For applications that are currently running on other design systems like
legacy Northstar v18, such isolation
will assist with gradual migration from legacy IBM.com Northstar v18 styles to
Carbon for IBM.com styles. Both technologies can co-exist safely in the same
application. Here is an example with the Carbon for IBM.com masthead and legacy
IBM.com Northstar footer:
<!-- Loads legacy IBM.com Design System (Northstar) --><linkrel="stylesheet"href="https://1.www.s81c.com/common/v18/css/www.css" /><scriptsrc="https://1.www.s81c.com/common/v18/js/www.js"></script><!-- Loads Carbon for IBM.com Web Components masthead --><scripttype="module"src="https://1.www.s81c.com/common/carbon-for-ibm-dotcom/tag/v1/latest/masthead.min.js"></script>
...
<bodyid="ibm-com"class="ibm-type"><divid="ibm-top"class="ibm-landing-page"><!-- Uses Carbon for IBM.com Web Components masthead --><c4d-masthead-container></c4d-masthead-container><divid="ibm-content-wrapper">...</div><!-- Uses legacy IBM.com Design System (Northstar) footer --><footerrole="contentinfo"aria-label="IBM"></footer></div></body>
Above example requires setting up a module bundler, as discussed in earlier
section.
Going to Docs tab, where it shows the usage and available attributes,
properties and custom events.
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
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.
As Shadow DOM (one of the Web Components specs that
@carbon/ibmdotcom-web-components uses) promises, styles that
@carbon/ibmdotcom-web-components defines does not affect styles in your
application, or vice versa.
However, in cases where your application or a Carbon-derived style guide wants
to change the styles of our components, there are a few options.
Some components support
CSS Shadow Parts too, so you can
use your application's CSS to affect @carbon/ibmdotcom-web-components styles
in a more flexible manner.
For example, below style changes back button's text color in
<cds-locale-modal> to one of g100 theme:
Warning While shadow parts selectors are available as an option, use them at your own
risk. Changing component styles may cause components to not behave as
expected. You are responsible for ensuring your components remain functional
while using shadow parts selectors. We cannot guarantee updates to our
library's component styles won't conflict with shadow part modifications.
This package uses IBM Telemetry to collect de-identified and anonymized metrics
data. By installing this package as a dependency you are agreeing to telemetry
collection. To opt out, see
Opting out of IBM Telemetry data collection.
For more information on the data being collected, please see the
IBM Telemetry documentation.