@carbon/ibm-products-web-components
Version:
Carbon for IBM Products Web Components
133 lines (131 loc) • 4.64 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 page_header_default$1 from "./page-header.scss.js";
import { pageHeaderContext } from "./context.js";
import { getHeaderOffset } from "./utils.js";
import page_header_content_default from "./page-header-content.js";
import { LitElement, html } from "lit";
import { state } from "lit/decorators.js";
import { carbonElement } from "@carbon/web-components/es/globals/decorators/carbon-element.js";
import { provide } from "@lit/context";
//#region src/components/page-header/page-header.ts
/**
* @license
*
* Copyright IBM Corp. 2025, 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.
*/
/**
* Page header.
* @element c4p-page-header
*/
let CDSPageHeader = class CDSPageHeader extends LitElement {
constructor(..._args) {
super(..._args);
this.context = {};
}
updated(changedProperties) {
super.updated(changedProperties);
if (changedProperties.has("context")) if (this.context.disableStickyTabBar) this.classList.add(`c4p--page-header--disable-sticky-tab-bar`);
else this.classList.remove(`c4p--page-header--disable-sticky-tab-bar`);
}
connectedCallback() {
super.connectedCallback();
const contentElement = this.querySelector(`c4p-page-header-content`);
this.resizeObserver = new ResizeObserver((entries) => {
const contentEl = entries[0].target.querySelector(`c4p-page-header-content`);
const totalContentHeight = (contentEl instanceof page_header_content_default ? contentEl.scrollHeight : 0) + (contentEl instanceof page_header_content_default ? parseFloat(getComputedStyle(contentEl)?.paddingBlockStart) + parseFloat(getComputedStyle(contentEl)?.paddingBlockEnd) : 0);
const headerOffset = getHeaderOffset(this);
const contentPadding = contentEl instanceof page_header_content_default ? 48 : 0;
this.style.setProperty(`--c4p-page-header-header-top`, `${(Math.round(totalContentHeight - contentPadding) - headerOffset) * -1}px`);
this.style.setProperty(`--c4p-page-header-breadcrumb-top`, `${headerOffset}px`);
this.context = {
...this.context,
breadcrumbOffset: headerOffset,
headerOffset: (Math.round(totalContentHeight) - headerOffset) * -1,
root: this,
withContent: !!contentEl
};
});
this.resizeObserver.observe(this);
const predefinedContentPadding = 24;
const totalHeaderOffset = getHeaderOffset(this);
const contentObserver = new IntersectionObserver((entries) => {
entries.forEach((entry) => {
if (!entry.isIntersecting) this.context = {
...this.context,
fullyCollapsed: true
};
else this.context = {
...this.context,
fullyCollapsed: false
};
});
}, {
root: null,
rootMargin: `${(predefinedContentPadding + totalHeaderOffset + 40) * -1}px 0px 0px 0px`,
threshold: .1
});
const titleObserver = new IntersectionObserver((entries) => {
entries.forEach((entry) => {
if (!entry.isIntersecting) this.context = {
...this.context,
titleClipped: true
};
else this.context = {
...this.context,
titleClipped: false
};
});
}, {
root: null,
rootMargin: `${(predefinedContentPadding + totalHeaderOffset + 40) * -1}px 0px 0px 0px`,
threshold: .95
});
const actionsObserver = new IntersectionObserver((entries) => {
entries.forEach((entry) => {
if (!entry.isIntersecting) this.context = {
...this.context,
contentActionsClipped: true
};
else this.context = {
...this.context,
contentActionsClipped: false
};
});
}, {
root: null,
rootMargin: `${(totalHeaderOffset + 48 + 18) * -1}px 0px 0px 0px`,
threshold: .95
});
if (contentElement) {
contentObserver.observe(contentElement);
titleObserver.observe(contentElement);
actionsObserver.observe(contentElement);
}
}
disconnectedCallback() {
this.resizeObserver?.disconnect();
super.disconnectedCallback();
}
render() {
return html`<slot></slot>`;
}
static {
this.styles = page_header_default$1;
}
};
__decorate([state(), provide({ context: pageHeaderContext })], CDSPageHeader.prototype, "context", void 0);
CDSPageHeader = __decorate([carbonElement(`c4p-page-header`)], CDSPageHeader);
var page_header_default = CDSPageHeader;
//#endregion
export { page_header_default as default };
//# sourceMappingURL=page-header.js.map