0.1.4 • Published 2 years ago

@salesforce-ux/wes-badge v0.1.4

Weekly downloads
-
License
SEE LICENSE IN RE...
Repository
-
Last release
2 years ago

@salesforce-ux/wes-badge

npm (custom registry)

About

A badge is a read-only element used to label content. Use badges to help tag data or copy to show it belongs in a certain category or has a certain status.

Getting Started

Let's start by installing wes-badge as a dependency of your project with npm.

npm i @salesforce-ux/wes-badge

Distributable

After installation, all the distributables for the wes-badge are found under /node_modules/@salesforce-ux/wes-badge/dist/ folder.

File NameDescription
badge.cssThe CSS file specific to wes-badge only. It doesnot include the styles for it's parent sds-badge. wes-badge extends from sds-badge
badge.compiled.cssThe Compiled CSS file for wes-badge.This file includes styles for both wes-badge and its parent sds-badge. This file is useful for LWC applications.(see below )
badge.jsThe bundled JS file for wes-badge component. This file is useful for Non LWC applications.(see below )

wes-badge Integration

For the sake of understanding, we have categorized the development environment into LWC and Non LWC application. If you are using the Salesforce Experience Cloud platform, WES is supported through an Unlocked Package, see the Confluence page for the WES Unlocked Package.

This Guide covers the integration approach for these two types of application.

For Lightning Web Component(LWC) Application

Dependency Inclusion

wes-styling-hooks is a styling dependency for wes-badge. Hence, this needs to be embedded into the root of the web app in order to make the wes-badge render properly.

<html>
  <head>
    <link rel="stylesheet" href="/node_modules/@salesforce-ux/wes-styling-hooks/dist/hooks.custom-props.css">
    <!-- Your application's other stylesheets go below -->
    <link rel="stylesheet" href="...">
  </head>
  <body>
    <!-- Your application -->
  </body>
</html>

There are also other ways wes-styling-hooks can be embedded. Please checkout the wes-styling-hooks Integration Guide to learn more.

Component CSS Import

/* myComponent.css */
@import "@salesforce-ux/wes-badge/dist/badge.compiled.css";

HTML Decoration

After that,the HTML of your LWC component template needs to be decorated to have all the named part attributes as per the component's specification. Below is a reference to the component's structure.

<wes-badge>
  <span part="badge">
    <slot name="start"></slot>
    Label
    <slot name="end"></slot>
  </span>
</wes-badge>

For Non LWC Application

Dependency Inclusion Read the section above

Component Import

/* myComponent.js */
import WESBadge from "@salesforce-ux/wes-badge/dist/badge";

Component Registration

/* myComponent.js */
customElements.define('wes-badge', WESBadge);

Example

Below is one approach to integrate your wes-badge component.

Script
/* myComponent.js */
import "@salesforce-ux/wes-styling-hooks/dist/hooks.custom-props.css";
import WESBadge from "@salesforce-ux/wes-badge/dist/badge";
window.customElements.define('wes-badge', WESBadge);
HTML
<wes-badge> Badge </wes-badge>

Interactive Demo

To see more examples with interactive demo, please visit WES Subsytem's Storybook Environment