@carbon/ibm-products
Version:
Carbon for IBM Products
63 lines (61 loc) • 2.33 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 { __toESM } from "../../../_virtual/_rolldown/runtime.js";
import { require_classnames } from "../../../node_modules/classnames/index.js";
import { pkg } from "../../../settings.js";
import { useCardContext } from "./CardContext.js";
import React, { forwardRef, useCallback } from "react";
import PropTypes from "prop-types";
//#region src/components/Card/next/CardHeader.tsx
/**
* 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.
*/
var import_classnames = /* @__PURE__ */ __toESM(require_classnames());
const componentName = "CardHeader";
const blockClass = `${pkg.prefix}--card-next__header`;
/**
* CardHeader component - Header section of the card.
* Layout is handled entirely by CSS Grid on __header:
* - CardHeaderMedia spans both columns (full-width row above the title area)
* - CardTitleMedia occupies column 1 (left icon slot)
* - CardTitle occupies column 2 (right text slot), or spans full width when
* CardTitleMedia is absent — detected by the :has selector in SCSS.
* No child-scanning or wrapper injection is needed.
*/
let CardHeader = forwardRef(({ className, children, ...rest }, ref) => {
const context = useCardContext();
const cardBlockClass = `${pkg.prefix}--card-next`;
const handleDecoratorClick = useCallback((e) => e.stopPropagation(), []);
const handleDecoratorKeyDown = useCallback((e) => e.stopPropagation(), []);
return /* @__PURE__ */ React.createElement("div", {
...rest,
ref,
className: (0, import_classnames.default)(blockClass, className)
}, children, context.decorator && /* @__PURE__ */ React.createElement("div", {
className: `${cardBlockClass}__decorator`,
role: "presentation",
onClick: handleDecoratorClick,
onKeyDown: handleDecoratorKeyDown
}, context.decorator));
});
CardHeader.propTypes = {
/**
* Header content
*/
children: PropTypes.node,
/**
* Additional CSS class names
*/
className: PropTypes.string
};
CardHeader = pkg.checkComponentEnabled(CardHeader, componentName);
CardHeader.displayName = componentName;
//#endregion
export { CardHeader };