import React from 'react' ; export interface SvgTextProps extends React . SVGProps < SVGTextElement > { text : string ; targetWidth : number ; } param props export const SvgText = ( props ) : JSX . Element => { const { text , targetWidth , ... otherProps } = props ; const callbackRef = ( textElem ) => { if ( ! textElem ) { return ; } for ( textElem . textContent = text ; textElem . getComputedTextLength ( ) > targetWidth ; ) { textElem . textContent = textElem . textContent . slice ( 0 , textElem . textContent . length - 6 ) + '…' ; } } ; return < text ref = { callbackRef } { ... otherProps } />; } ; export default SvgText ;