UNPKG

@carbon/ibm-products

Version:
61 lines (59 loc) 3.85 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 { __toESM } from "../../../_virtual/_rolldown/runtime.js"; import { require_classnames } from "../../../node_modules/classnames/index.js"; import { TruncatedText } from "../../TruncatedText/TruncatedText.js"; import { TearsheetContext, blockClass } from "./context.js"; import React, { cloneElement, isValidElement, useContext } from "react"; import { AILabel, IconButton, usePrefix } from "@carbon/react"; import { Close } from "@carbon/react/icons"; //#region src/components/Tearsheet/next/TearsheetHeaderContent.tsx /** * 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. */ var import_classnames = /* @__PURE__ */ __toESM(require_classnames()); const TearsheetHeaderContent = React.forwardRef((props, ref) => { const { children, label, title, description, headerActions, titleStart, titleEnd, ...rest } = props; const carbonPrefix = usePrefix(); const { isSm, onClose, decorator, closeIconDescription, hideCloseButton = false, titleId } = useContext(TearsheetContext); const normalizedDecorator = isValidElement(decorator) && decorator.type === AILabel ? cloneElement(decorator, { size: "sm" }) : decorator; const headerContent = /* @__PURE__ */ React.createElement("div", { className: `${blockClass}__header-content` }, label ? /* @__PURE__ */ React.createElement("div", { className: `${blockClass}__header-label` }, label) : null, /* @__PURE__ */ React.createElement("div", { className: `${blockClass}__content__title-wrapper` }, /* @__PURE__ */ React.createElement("h2", { className: (0, import_classnames.default)(`${blockClass}__header-title`), id: titleId }, titleStart ? /* @__PURE__ */ React.createElement("span", { className: `${blockClass}__title-start` }, titleStart) : null, /* @__PURE__ */ React.createElement(TruncatedText, { id: `${blockClass}__header-title__truncatedText`, className: `${blockClass}__content__title`, align: "bottom", autoAlign: true, value: title }), titleEnd ? /* @__PURE__ */ React.createElement("span", { className: `${blockClass}__title-end` }, titleEnd) : null)), /* @__PURE__ */ React.createElement("div", { className: `${blockClass}__header-description` }, description), children && /* @__PURE__ */ React.createElement("div", { className: `${blockClass}__header-content--extra` }, children)); const headerActionsElement = headerActions && /* @__PURE__ */ React.createElement("div", { className: `${blockClass}__header-actions` }, headerActions); const decoratorElement = decorator && /* @__PURE__ */ React.createElement("div", { className: `${blockClass}__decorator`, role: "complementary" }, normalizedDecorator); const closeButtonElement = !hideCloseButton && /* @__PURE__ */ React.createElement("div", { className: `${blockClass}__close-button ${carbonPrefix}--modal-close-button` }, /* @__PURE__ */ React.createElement(IconButton, { className: `${carbonPrefix}--modal-close`, label: closeIconDescription || "Close", onClick: onClose, align: "left" }, /* @__PURE__ */ React.createElement(Close, { size: 20, "aria-hidden": "true", tabIndex: "-1", className: `${carbonPrefix}--modal-close__icon` }))); return /* @__PURE__ */ React.createElement("div", { className: `${blockClass}__header-content-wrapper`, ref }, !isSm ? /* @__PURE__ */ React.createElement(React.Fragment, null, headerActionsElement, decoratorElement, closeButtonElement, headerContent) : /* @__PURE__ */ React.createElement(React.Fragment, null, decoratorElement, closeButtonElement, headerContent, headerActionsElement)); }); //#endregion export { TearsheetHeaderContent as default };