Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
module.exports = createPrompt((config, done) => {
const [status, setStatus] = useState('pending');
const [cursorPosition, setCursorPos] = useState(0);
const { choices, pageSize = 7 } = config;
const paginator = useRef(new Paginator()).current;
const prefix = usePrefix();
useKeypress(key => {
if (isEnterKey(key)) {
setStatus('done');
done(choices[cursorPosition].value);
} else if (isUpKey(key) || isDownKey(key)) {
let newCursorPosition = cursorPosition;
const offset = isUpKey(key) ? -1 : 1;
let selectedOption;
while (!selectedOption || selectedOption.disabled) {
newCursorPosition =
(newCursorPosition + offset + choices.length) % choices.length;
selectedOption = choices[newCursorPosition];
}