@letanure/resend-cli
Version:
A command-line interface for Resend email API
26 lines • 1.91 kB
JavaScript
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import { Alert } from '@inkjs/ui';
import { Box, Text, useInput } from 'ink';
import { formatDataWithFields } from '../../utils/display-formatter.js';
import { Layout } from './layout.js';
/**
* Reusable component for displaying success data in a consistent format across all modules.
* Handles both regular success displays and dry run displays with appropriate warnings.
* Replaces the need for individual success/dry run display components in each module.
*/
export const SuccessScreen = ({ data, successMessage, headerText, fields = [], fieldsToShow, isDryRun = false, onExit, }) => {
useInput((input, key) => {
if (input === 'q' || key.escape) {
onExit();
}
});
const formattedFields = formatDataWithFields(data, fields, fieldsToShow);
// Calculate the maximum label width for dynamic spacing
const maxLabelWidth = formattedFields.length > 0
? Math.max(...formattedFields.map((field) => field.label.length)) + 1 // +1 for the colon
: 20; // fallback to original width
const alertVariant = isDryRun ? 'warning' : 'success';
const displayMessage = isDryRun ? `DRY RUN - ${successMessage} (validation only)` : successMessage;
return (_jsx(Layout, { headerText: headerText, showNavigationInstructions: true, navigationContext: "result", children: _jsxs(Box, { flexDirection: "column", gap: 1, children: [_jsx(Box, { children: _jsx(Alert, { variant: alertVariant, children: displayMessage }) }), formattedFields.length > 0 && (_jsx(Box, { flexDirection: "column", children: formattedFields.map((field) => (_jsxs(Box, { children: [_jsx(Box, { width: maxLabelWidth + 2, children: _jsxs(Text, { bold: true, color: "cyan", children: [field.label, ":"] }) }), _jsx(Text, { children: field.value })] }, field.label))) }))] }) }));
};
//# sourceMappingURL=SuccessScreen.js.map