UNPKG

@letanure/resend-cli

Version:

A command-line interface for Resend email API

37 lines 2.64 kB
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime"; import { Box, Text } from 'ink'; import { clipContent } from '../../utils/clipContent.js'; export const Table = ({ data, fields, title }) => { if (data.length === 0) { return (_jsxs(Box, { flexDirection: "column", children: [title && (_jsx(Box, { marginBottom: 1, children: _jsx(Text, { bold: true, children: title }) })), _jsx(Text, { dimColor: true, children: "No data found" })] })); } // Calculate column widths based on content const columnWidths = {}; for (const field of fields) { // Start with header width columnWidths[field.name] = field.label.length; // Check data widths (using clipped content for width calculation) for (const row of data) { const rawValue = String(row[field.name] || ''); const clippedValue = clipContent(rawValue, field.name); const currentWidth = columnWidths[field.name] || 0; columnWidths[field.name] = Math.max(currentWidth, clippedValue.length); } // Add some padding and set minimum width const finalWidth = columnWidths[field.name] || 0; columnWidths[field.name] = Math.max(finalWidth + 2, 8); } return (_jsxs(Box, { flexDirection: "column", children: [title && (_jsx(Box, { marginBottom: 1, children: _jsx(Text, { bold: true, children: title }) })), _jsx(Box, { children: fields.map((field) => { const width = columnWidths[field.name] || 8; return (_jsx(Box, { width: width, children: _jsx(Text, { bold: true, color: "blue", children: field.label.padEnd(width - 1) }) }, field.name)); }) }), _jsx(Box, { children: fields.map((field) => { const width = columnWidths[field.name] || 8; return (_jsx(Box, { width: width, children: _jsx(Text, { dimColor: true, children: '-'.repeat(width - 1) }) }, field.name)); }) }), data.map((row, index) => (_jsx(Box, { children: fields.map((field) => { const width = columnWidths[field.name] || 8; const rawValue = String(row[field.name] || ''); const displayValue = clipContent(rawValue, field.name); return (_jsx(Box, { width: width, children: _jsx(Text, { children: displayValue.padEnd(width - 1) }) }, field.name)); }) }, String(row.id || index)))), _jsx(Box, { marginTop: 1, children: _jsxs(Text, { dimColor: true, children: [data.length, " ", data.length === 1 ? 'item' : 'items', " total"] }) })] })); }; //# sourceMappingURL=Table.js.map