@carbon/ibm-products-web-components
Version:
Carbon for IBM Products Web Components
190 lines (186 loc) • 6.75 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 add_select_body_default$1 from "./add-select-body.scss.js";
import { classMap } from "lit/directives/class-map.js";
import { LitElement, html } from "lit";
import { property, state } from "lit/decorators.js";
import '@carbon/web-components/es-custom/components/button/index.js';
import { carbonElement } from "@carbon/web-components/es/globals/decorators/carbon-element.js";
import '@carbon/web-components/es-custom/components/link/index.js';
import '@carbon/web-components/es-custom/components/search/index.js';
import '@carbon/web-components/es-custom/components/tag/index.js';
import '@carbon/web-components/es-custom/components/breadcrumb/index.js';
//#region src/components/add-select/add-select-body.ts
/**
* @license
*
* Copyright IBM Corp. 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.
*/
const blockClass = `c4p--add-select__next`;
/**
* Add Select Body component - contains the main content area
* @element c4p-add-select-body
* @slot default - The main content area containing c4p-add-select-content
* @slot header - Custom header content
* @fires c4p-add-select-body-search - Fired when search term changes
*/
let CDSAddSelectBody = class CDSAddSelectBody extends LitElement {
constructor(..._args) {
super(..._args);
this.itemsLabel = "";
this.globalSearchLabel = "";
this.globalSearchPlaceholder = "Search";
this.searchResultsTitle = "Search results";
this._searchTerm = "";
this.itemCount = 0;
this.path = [];
}
/**
* Whether this is a multi-select (inherited from parent c4p-add-select)
* @private
*/
get _multi() {
return this.closest(`c4p-add-select`)?.multi ?? false;
}
/**
* Handle search input
*/
_handleSearch(event) {
this._searchTerm = event.detail.value || "";
const init = {
bubbles: true,
cancelable: true,
composed: true,
detail: { searchTerm: this._searchTerm }
};
this.dispatchEvent(new CustomEvent(this.constructor.eventSearch, init));
}
render() {
const { itemsLabel, globalSearchLabel, globalSearchPlaceholder, searchResultsTitle, itemCount, path, _searchTerm: searchTerm, _handleSearch: handleSearch } = this;
return html`
<div class=${classMap({
[`${blockClass}__body`]: true,
[`${blockClass}__body--single`]: !this._multi,
[`${blockClass}__body--multi`]: this._multi
})}>
<!-- Header Section -->
<div class="${blockClass}__header">
<slot name="header">
<!-- Search -->
<div class="${blockClass}__search">
<cds-custom-search
label-text=${globalSearchLabel}
placeholder=${globalSearchPlaceholder}
size="lg"
@cds-custom-search-input=${handleSearch}
></cds-custom-search>
</div>
<!-- Sub-header with breadcrumbs or item label -->
<div class="${blockClass}__sub-header">
<div class="${blockClass}__tags">
${searchTerm ? html`
<p class="${blockClass}__tags-label">
${searchResultsTitle}
</p>
` : path && path.length > 0 ? html`
<cds-custom-breadcrumb
no-trailing-slash
class="${classMap({
[`c4p--add-select__next__breadcrumbs`]: true,
[`c4p--add-select__next__breadcrumbs--multi`]: this._multi
})}"
>
${path.map((entry, idx) => {
const isCurrentPage = idx === path.length - 1;
return html`
<cds-custom-breadcrumb-item
?is-current-page=${isCurrentPage}
>
${isCurrentPage ? entry.title : html`
<cds-custom-link
href="#"
@click=${(e) => {
e.preventDefault();
const init = {
bubbles: true,
cancelable: true,
composed: true,
detail: { index: idx }
};
this.dispatchEvent(new CustomEvent(this.constructor.eventBreadcrumbClick, init));
}}
>
${entry.title}
</cds-custom-link>
`}
</cds-custom-breadcrumb-item>
`;
})}
</cds-custom-breadcrumb>
` : html`
<p class="${blockClass}__tags-label">${itemsLabel}</p>
`}
<cds-custom-tag type="gray" size="sm">${itemCount}</cds-custom-tag>
</div>
</div>
</slot>
</div>
<!-- Body Content -->
<div class="${blockClass}__content">
<slot></slot>
</div>
</div>
`;
}
/**
* The name of the custom event fired when search term changes
*/
static get eventSearch() {
return `c4p-add-select-body-search`;
}
/**
* The name of the custom event fired when breadcrumb is clicked
*/
static get eventBreadcrumbClick() {
return `c4p-add-select-body-breadcrumb-click`;
}
static {
this.styles = add_select_body_default$1;
}
};
__decorate([property({
type: String,
attribute: "items-label"
})], CDSAddSelectBody.prototype, "itemsLabel", void 0);
__decorate([property({
type: String,
attribute: "global-search-label"
})], CDSAddSelectBody.prototype, "globalSearchLabel", void 0);
__decorate([property({
type: String,
attribute: "global-search-placeholder"
})], CDSAddSelectBody.prototype, "globalSearchPlaceholder", void 0);
__decorate([property({
type: String,
attribute: "search-results-title"
})], CDSAddSelectBody.prototype, "searchResultsTitle", void 0);
__decorate([state()], CDSAddSelectBody.prototype, "_searchTerm", void 0);
__decorate([property({
type: Number,
attribute: "item-count"
})], CDSAddSelectBody.prototype, "itemCount", void 0);
__decorate([property({ type: Array })], CDSAddSelectBody.prototype, "path", void 0);
CDSAddSelectBody = __decorate([carbonElement(`c4p-add-select-body`)], CDSAddSelectBody);
var add_select_body_default = CDSAddSelectBody;
//#endregion
export { add_select_body_default as default };
//# sourceMappingURL=add-select-body.js.map