UNPKG

@primer/react

Version:

An implementation of GitHub's Primer Design System using React

55 lines (51 loc) 1.65 kB
import React from 'react'; import { ItemContext } from './shared.js'; import classes from './ActionList.module.css.js'; import { clsx } from 'clsx'; import { jsx } from 'react/jsx-runtime'; import Truncate from '../Truncate/Truncate.js'; const Description = ({ variant = 'inline', className, truncate, style, ...props }) => { const { blockDescriptionId, inlineDescriptionId } = React.useContext(ItemContext); const containerRef = React.useRef(null); const [computedTitle, setComputedTitle] = React.useState(''); // Extract text content from rendered DOM for tooltip React.useEffect(() => { if (truncate && containerRef.current) { const textContent = containerRef.current.textContent || ''; setComputedTitle(textContent); } }, [truncate, props.children]); const effectiveTitle = typeof props.children === 'string' ? props.children : computedTitle; if (variant === 'block' || !truncate) { return /*#__PURE__*/jsx("span", { id: variant === 'block' ? blockDescriptionId : inlineDescriptionId, className: clsx(className, classes.Description), style: style, "data-component": "ActionList.Description", children: props.children }); } else { return /*#__PURE__*/jsx(Truncate, { ref: containerRef, id: inlineDescriptionId, className: clsx(className, classes.Description), style: style, title: effectiveTitle, inline: true, maxWidth: "100%", "data-component": "ActionList.Description", children: props.children }); } }; Description.__SLOT__ = Symbol('ActionList.Description'); export { Description };