@carbon/ibm-products
Version:
Carbon for IBM Products
45 lines (43 loc) • 1.22 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.
*/
require("../../_virtual/_rolldown/runtime.js");
const require_checkForOverflow = require("../../global/js/utils/checkForOverflow.js");
let react = require("react");
//#region src/components/TruncatedText/useTruncatedText.ts
/**
* 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.
*/
function useTruncatedText({ lines, value, expanded }) {
const [truncated, setTruncated] = (0, react.useState)(false);
const ref = (0, react.useRef)(null);
(0, react.useEffect)(() => {
const resizeObserver = new ResizeObserver(() => {
if (!expanded) {
const result = require_checkForOverflow.checkHeightOverflow(ref.current);
if (result !== truncated) setTruncated(result);
}
});
if (ref.current) resizeObserver.observe(ref.current);
return () => {
resizeObserver.disconnect();
};
}, [
expanded,
lines,
value,
truncated
]);
return {
ref,
truncated
};
}
//#endregion
exports.default = useTruncatedText;