UNPKG

@carbon/ibm-products-web-components

Version:
188 lines (185 loc) 6.66 kB
/** * 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$1 from "./checklist.scss.js"; import "./checklist-chart.js"; import "./checklist-icon.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"; import { iconLoader } from "@carbon/web-components/es/globals/internal/icon-loader.js"; import '@carbon/web-components/es-custom/components/icon-button/index.js'; import '@carbon/web-components/es-custom/components/link/index.js'; import ChevronIcon16 from "@carbon/icons/es/chevron--up/16"; //#region src/components/checklist/checklist.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. */ const blockClass = `c4p--checklist`; /** * @element c4p-checklist * @slot checklist-header - Header area which includes the title and the progress indicator. * @slot default - Contains one or more `c4p-checklist-group` components to organize tasks into logical groups. * @slot checklist-footer - Optional footer area for actions like buttons, links, or additional notes. * @fires c4p-checklist-view-all - The custom event which is fired when a user clicks on View All button in checklist footer. * @fires c4p-checklist-toggle - The custom event which is fired when user clicks on toggle button in checklist header. */ let CDSChecklist = class CDSChecklist extends LitElement { constructor(..._args) { super(..._args); this.open = false; this.disableToggle = false; } _viewAll(event) { const triggeredBy = event.target; event.stopPropagation(); const init = { bubbles: true, cancelable: true, composed: true, detail: { triggeredBy } }; this.dispatchEvent(new CustomEvent(this.constructor.checklistViewAll, init)); } _handleKeyDown(event) { if (event.key === "Enter" || event.key === " ") this._viewAll(event); } _onToggle(event) { this.open = !this.open; const triggeredBy = event.target; event.stopPropagation(); const init = { bubbles: true, cancelable: true, composed: true, detail: { triggeredBy } }; this.dispatchEvent(new CustomEvent(this.constructor.checklistToggle, init)); } render() { const { open, chartLabel, chartValue, title, disableToggle, toggleLabel, toggleLabelAlign, toggleAriaLabel, viewAllLabel, _viewAll: viewAll, _onToggle: onToggle, _handleKeyDown: handleKeyDown } = this; return html` <aside class=${classMap({ [`${blockClass}`]: true, [`${blockClass}__closed`]: !open })} aria-label="Checklist"> <!-- Header --> <header class="${blockClass}__header"> <slot name="checklist-header"> <slot name="header-chart"> <c4p-checklist-chart value=${chartValue}></c4p-checklist-chart> </slot> <div class="${blockClass}__titles"> <!-- checklist title --> <slot name="header-title"> ${title && html`<h2 class="${blockClass}__title">${title}</h2>`} </slot> <!-- chart label --> <slot name="header-chartLabel"> ${chartLabel && html`<p class="${blockClass}__chart-label">${chartLabel}</p>`} </slot> </div> </slot> <!-- Checklist toggle button --> ${!disableToggle && html`<cds-custom-icon-button kind="ghost" size="sm" align=${toggleLabelAlign} aria-label=${toggleAriaLabel} class="${blockClass}__toggle" @click=${onToggle} > ${iconLoader(ChevronIcon16, { slot: "icon", class: `${blockClass}__chevron` })} <span slot="tooltip-content">${toggleLabel}</span> </cds-custom-icon-button>`} </header> <div class="${blockClass}__content-outer"> <div class="${blockClass}__content-inner"> <!-- Checklist body --> <!-- This is where you add c4p-checklist-group elements--> <slot></slot> <!-- Checklist footer --> <div class="${blockClass}__footer"> <slot name="checklist-footer"> ${viewAllLabel && html`<cds-custom-link role="link" @click=${viewAll} @keydown=${handleKeyDown} > ${viewAllLabel} </cds-custom-link>`} </slot> </div> </div> </div> </aside> `; } /** * The custom event which is fired when the view all button in checklist footer is clicked or when the Enter key is pressed on it. */ static get checklistViewAll() { return `c4p-checklist-view-all`; } /** * The custom event which is fired when the checklist toggle button is clicked or when the Enter key is pressed on it. */ static get checklistToggle() { return `c4p-checklist-toggle`; } static { this.styles = checklist_default$1; } }; __decorate([property({ type: Boolean, reflect: true })], CDSChecklist.prototype, "open", void 0); __decorate([property({ type: String })], CDSChecklist.prototype, "title", void 0); __decorate([property({ type: String, attribute: "chart-label" })], CDSChecklist.prototype, "chartLabel", void 0); __decorate([property({ type: Number, attribute: "chart-value" })], CDSChecklist.prototype, "chartValue", void 0); __decorate([property({ type: Boolean, attribute: "disable-toggle" })], CDSChecklist.prototype, "disableToggle", void 0); __decorate([property({ type: String, attribute: "toggle-label" })], CDSChecklist.prototype, "toggleLabel", void 0); __decorate([property({ type: String, attribute: "toggle-label-align" })], CDSChecklist.prototype, "toggleLabelAlign", void 0); __decorate([property({ type: String, attribute: "toggle-aria-label" })], CDSChecklist.prototype, "toggleAriaLabel", void 0); __decorate([property({ type: String, attribute: "view-all-label" })], CDSChecklist.prototype, "viewAllLabel", void 0); CDSChecklist = __decorate([carbonElement(`c4p-checklist`)], CDSChecklist); var checklist_default = CDSChecklist; //#endregion export { checklist_default as default }; //# sourceMappingURL=checklist.js.map