@carbon/ibm-products
Version:
Carbon for IBM Products
122 lines (120 loc) • 4.93 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 { getDevtoolsProps } from "../../../global/js/utils/devtools.js";
import React, { forwardRef } from "react";
import PropTypes from "prop-types";
//#region src/components/Card/next/CardTitle.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 blockClass = `${pkg.prefix}--card-next`;
const componentName = "CardTitle";
/**
* CardTitle displays the main title text in the card header.
* Typography is controlled via className:
* - Productive: Use $heading-compact-02 (16px/22px)
* - Expressive: Use $heading-03 (20px/28px)
* Color uses $text-primary token.
*/
let CardTitle = forwardRef(({ children, className, titleTruncate = false, maxWidth = "100%", titleStart, titleEnd, label, labelTruncate = false, description, descriptionTruncate = false, ...rest }, ref) => {
const isTitleMulti = typeof titleTruncate === "number";
const isLabelMulti = typeof labelTruncate === "number";
const isDescMulti = typeof descriptionTruncate === "number";
const containerClasses = (0, import_classnames.default)(`${blockClass}__title`, className);
const textRowClasses = (0, import_classnames.default)(`${blockClass}__title-text-row`, {
[`${blockClass}__title-text-row--truncate`]: titleTruncate === true,
[`${blockClass}__title-text-row--truncate-multi`]: isTitleMulti,
[`${blockClass}__title-text-row--with-start-icon`]: titleStart,
[`${blockClass}__title-text-row--with-end-icon`]: titleEnd
});
const titleVars = titleTruncate !== false ? {
[`--${blockClass}--title-max-width`]: maxWidth,
...isTitleMulti && { [`--${blockClass}--title-line-clamp`]: titleTruncate }
} : void 0;
const labelVars = isLabelMulti ? { [`--${blockClass}--label-line-clamp`]: labelTruncate } : void 0;
const descVars = isDescMulti ? { [`--${blockClass}--description-line-clamp`]: descriptionTruncate } : void 0;
return /* @__PURE__ */ React.createElement("div", {
...rest,
ref,
className: containerClasses,
...getDevtoolsProps(componentName)
}, label && /* @__PURE__ */ React.createElement("div", {
className: (0, import_classnames.default)(`${blockClass}__label`, {
[`${blockClass}__label--truncate`]: labelTruncate === true,
[`${blockClass}__label--truncate-multi`]: isLabelMulti
}),
style: labelVars
}, label), /* @__PURE__ */ React.createElement("span", {
className: textRowClasses,
style: titleVars
}, titleStart && /* @__PURE__ */ React.createElement("span", { className: `${blockClass}__title-start-icon` }, titleStart), children, titleEnd && /* @__PURE__ */ React.createElement("span", { className: `${blockClass}__title-end-icon` }, titleEnd)), description && /* @__PURE__ */ React.createElement("div", {
className: (0, import_classnames.default)(`${blockClass}__description`, {
[`${blockClass}__description--truncate`]: descriptionTruncate === true,
[`${blockClass}__description--truncate-multi`]: isDescMulti
}),
style: descVars
}, description));
});
CardTitle.propTypes = {
/**
* Provide the contents of the CardTitle.
*/
children: PropTypes.node,
/**
* Provide an optional class to be applied to the containing node.
*/
className: PropTypes.string,
/**
* Optional description rendered below the title text.
*/
description: PropTypes.node,
/**
* Enable truncation on the description text.
* - `true`: Single line truncation
* - `number`: Multi-line truncation (line clamp)
*/
descriptionTruncate: PropTypes.oneOfType([PropTypes.bool, PropTypes.number]),
/**
* Optional label rendered above the title text.
*/
label: PropTypes.node,
/**
* Enable truncation on the label text.
* - `true`: Single line truncation
* - `number`: Multi-line truncation (line clamp)
*/
labelTruncate: PropTypes.oneOfType([PropTypes.bool, PropTypes.number]),
/**
* Maximum width for the title when truncation is active.
*/
maxWidth: PropTypes.string,
/**
* Optional trailing icon or content to display after the title text.
*/
titleEnd: PropTypes.node,
/**
* Optional leading icon or content to display before the title text.
*/
titleStart: PropTypes.node,
/**
* Enable text truncation with ellipsis.
* - `true`: Single line truncation
* - `number`: Multi-line truncation (line clamp)
*/
titleTruncate: PropTypes.oneOfType([PropTypes.bool, PropTypes.number])
};
CardTitle = pkg.checkComponentEnabled(CardTitle, componentName);
CardTitle.displayName = componentName;
//#endregion
export { CardTitle };