import * as React from 'react'; export type PreviewProps = Readonly< React.ComponentPropsWithoutRef<'div'> & { children: string | string[]; } >; const PREVIEW_MAX_LENGTH = 200; export const Preview = React.forwardRef( ({ children = '', ...props }, ref) => { const text = ( Array.isArray(children) ? children.join('') : children ).substring(0, PREVIEW_MAX_LENGTH); return ( <> {text}
{text} {renderWhiteSpace(text)}
); }, ); Preview.displayName = 'Preview'; const whiteSpaceCodes = '\xa0\u200C\u200B\u200D\u200E\u200F\uFEFF'; export const renderWhiteSpace = (text: string) => { if (text.length >= PREVIEW_MAX_LENGTH) { return null; } return
{whiteSpaceCodes.repeat(PREVIEW_MAX_LENGTH - text.length)}
; };