import React, { PropTypes } from 'react' import ReactDOM from 'react-dom' import _ from 'lodash' import {Key} from '../utils.js' Prompt.contextTypes = { returnFocus: PropTypes.func } Prompt.propTypes = { options: PropTypes.array.isRequired, done: PropTypes.func.isRequired, prompt: PropTypes.string, } export default function Prompt({ prompt, done, options }, context) { const opts = [] function keyTaken(k) { return _.map(opts, 'key').includes(k) } for (let i = 0; i < options.length; i++) { let opt = options[i] if (_.isString(opt)) { let str = opt while (str.length > 0 && keyTaken(str[0])) { str = str.substr(1) } opt = { text: opt, key: str[0] } } if (!opt.text || !opt.key || keyTaken(opt.key)) { throw 'invalid options' } opts.push(opt) } return (