@carbon/ibm-products-web-components
Version:
Carbon for IBM Products Web Components
110 lines (108 loc) • 3.62 kB
JavaScript
/**
* Copyright IBM Corp. 2020, 2026
*
* This source code is licensed under the Apache-2.0 license found in the
* LICENSE file in the root directory of this source tree.
*/
import "../../globals/settings.js";
import { __decorate } from "../../_virtual/_@oxc-project_runtime@0.127.0/helpers/decorate.js";
import checklist_default from "./checklist.scss.js";
import "./checklist.types.js";
import { classMap } from "lit/directives/class-map.js";
import { LitElement, html } from "lit";
import { property } from "lit/decorators.js";
import { carbonElement } from "@carbon/web-components/es/globals/decorators/carbon-element.js";
//#region src/components/checklist/checklist-item.ts
/**
* @license
*
* Copyright IBM Corp. 2025
*
* This source code is licensed under the Apache-2.0 license found in the
* LICENSE file in the root directory of this source tree.
*/
/**
* item in c4p-checklist-group
* @element c4p-checklist-item
* @slot icon - checklist item icon, usually a status indicator icon
* @slot content - checklist item title/description
* @fires c4p-checklist-item-clicked - The custom event which is fired when a user clicks on checklist item with clickable attribute.
*/
let CDSChecklistItem = class CDSChecklistItem extends LitElement {
constructor(..._args) {
super(..._args);
this.clickable = false;
}
_handleClick(event) {
const triggeredBy = event.target;
event.stopPropagation();
const init = {
bubbles: true,
cancelable: true,
composed: true,
detail: { triggeredBy }
};
this.dispatchEvent(new CustomEvent(this.constructor.checklistItemClicked, init));
}
_handleKeyDown(event) {
if (event.key === "Enter" || event.key === " ") this._handleClick(event);
}
_mapStatusToKind(status) {
switch (status) {
case "not started": return "unchecked";
case "in progress": return "indeterminate";
case "completed": return "checked";
case "error": return "error";
case "disabled": return "disabled";
default: return "error";
}
}
_updateAttributes() {
this.setAttribute("role", "listitem");
this.classList.add(`c4p--checklist__list-item`);
}
firstUpdated() {
this._updateAttributes();
}
render() {
const { clickable, label, status, _handleClick: handleClick, _handleKeyDown: handleKeyDown } = this;
return html`
<slot name="icon">
<c4p-checklist-icon kind="${this._mapStatusToKind(status)}"></c4p-checklist-icon>
</slot>
<slot name="content">
<div
class="${classMap({
[`c4p--checklist__label`]: true,
[`c4p--checklist__label--clickable`]: clickable,
[`c4p--checklist__label--disabled`]: status === "disabled"
})}"
title=${label}
role=${clickable ? "link" : void 0}
@click=${clickable ? handleClick : void 0}
@keydown=${clickable ? handleKeyDown : void 0}
tabindex=${clickable ? 0 : -1}
>
${label}
</div>
</slot>
`;
}
/**
* The custom event which is fired when the checklist item is clicked.
*/
static get checklistItemClicked() {
return `c4p-checklist-item-clicked`;
}
static {
this.styles = checklist_default;
}
};
__decorate([property()], CDSChecklistItem.prototype, "label", void 0);
__decorate([property()], CDSChecklistItem.prototype, "status", void 0);
__decorate([property({ type: Boolean })], CDSChecklistItem.prototype, "clickable", void 0);
CDSChecklistItem = __decorate([carbonElement(`c4p-checklist-item`)], CDSChecklistItem);
var checklist_item_default = CDSChecklistItem;
//#endregion
export { checklist_item_default as default };
//# sourceMappingURL=checklist-item.js.map