UNPKG

@carbon/ibm-products

Version:

Carbon for IBM Products

46 lines (40 loc) 1.07 kB
/** * Copyright IBM Corp. 2020, 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. */ 'use strict'; Object.defineProperty(exports, '__esModule', { value: true }); var React = require('react'); var checkForOverflow = require('../../global/js/utils/checkForOverflow.js'); function useTruncatedText(_ref) { let { lines, value, expanded } = _ref; const [truncated, setTruncated] = React.useState(false); const ref = React.useRef(null); React.useEffect(() => { const resizeObserver = new ResizeObserver(() => { if (!expanded) { const result = 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 }; } exports.default = useTruncatedText;