mirror of
https://github.com/hanzoui/ci-dashboard.git
synced 2026-10-30 19:47:45 +00:00
27 lines
977 B
TypeScript
27 lines
977 B
TypeScript
import React, { useState } from 'react';
|
|
|
|
const LongTextPreview = ({ text, previewLines = 1 }) => {
|
|
const [isExpanded, setIsExpanded] = useState(false);
|
|
const lines = text.split('\n');
|
|
const preview = lines.slice(0, previewLines).join('\n');
|
|
|
|
return (
|
|
<div className="border rounded-md p-2 bg-gray-50 dark:bg-gray-900">
|
|
<pre className="whitespace-pre-wrap break-words">
|
|
{isExpanded ? text : preview}
|
|
{lines.length > previewLines && !isExpanded && '...'}
|
|
</pre>
|
|
{lines.length > previewLines && (
|
|
<button
|
|
onClick={() => setIsExpanded(!isExpanded)}
|
|
className="mt-2 text-blue-600 hover:text-blue-800 dark:text-blue-400 dark:hover:text-blue-600 underline"
|
|
>
|
|
{isExpanded ? 'Show Less' : 'Show More'}
|
|
</button>
|
|
)}
|
|
</div>
|
|
);
|
|
};
|
|
|
|
export default LongTextPreview;
|