import React from 'react'; import { Box, Text, useInput } from 'ink'; import { colors, borders } from '../theme/index.js'; export interface ModalProps { visible: boolean; title: string; children: React.ReactNode; onClose: () => void; width?: number; minHeight?: number; } export const Modal: React.FC = ({ visible, title, children, onClose, width = 60, minHeight, }) => { useInput( (input, key) => { if (key.escape) { onClose(); } }, { isActive: visible } ); if (!visible) { return null; } const innerWidth = width - 2; // width minus left/right borders // Build top border with embedded title: ╭── Title ─────────╮ const titleText = ` ${title} `; const leftDash = borders.horizontal.repeat(2); const rightDashLen = Math.max(0, innerWidth - 2 - titleText.length); const rightDash = borders.horizontal.repeat(rightDashLen); // Bottom border const bottomLine = borders.horizontal.repeat(innerWidth); return ( {/* Top border with title */} {borders.rounded.topLeft} {leftDash} {titleText} {rightDash} {borders.rounded.topRight} {/* Content area with side borders using Ink's borderStyle */} {children} {/* Bottom border */} {borders.rounded.bottomLeft} {bottomLine} {borders.rounded.bottomRight} ); }; export default Modal;