lorehub
Version:
Capture and surface the collective wisdom of your codebase
38 lines • 1.79 kB
JavaScript
import React, { useState } from 'react';
import { Box, Text, useInput } from 'ink';
export function ConfirmDialog({ message, onConfirm, onCancel, dangerous = false }) {
const [selectedOption, setSelectedOption] = useState('no');
useInput((input, key) => {
if (key.leftArrow || key.rightArrow || key.tab) {
setSelectedOption(prev => prev === 'yes' ? 'no' : 'yes');
}
else if (key.return) {
if (selectedOption === 'yes') {
onConfirm();
}
else {
onCancel();
}
}
else if (key.escape || input === 'n' || input === 'N') {
onCancel();
}
else if (input === 'y' || input === 'Y') {
onConfirm();
}
});
return (React.createElement(Box, { flexDirection: "column", borderStyle: "round", borderColor: dangerous ? 'red' : 'yellow', padding: 1 },
React.createElement(Text, null, message),
React.createElement(Box, { marginTop: 1 },
React.createElement(Box, { marginRight: 2 },
React.createElement(Text, { color: selectedOption === 'yes' ? (dangerous ? 'red' : 'green') : undefined, bold: selectedOption === 'yes' },
selectedOption === 'yes' ? '▶ ' : ' ',
"Yes")),
React.createElement(Box, null,
React.createElement(Text, { color: selectedOption === 'no' ? 'cyan' : undefined, bold: selectedOption === 'no' },
selectedOption === 'no' ? '▶ ' : ' ',
"No"))),
React.createElement(Box, { marginTop: 1 },
React.createElement(Text, { dimColor: true }, "Press Y/N or use \u2190/\u2192 then Enter"))));
}
//# sourceMappingURL=ConfirmDialog.js.map