-
Notifications
You must be signed in to change notification settings - Fork 10
/
index.js
40 lines (34 loc) · 840 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import React, {useCallback} from 'react';
import PropTypes from 'prop-types';
import TextInput from 'ink-text-input';
import yn from 'yn';
const noop = () => {};
const ConfirmInput = ({isChecked, onChange, onSubmit, placeholder, value, ...props}) => {
const handleSubmit = useCallback(newValue => {
onSubmit(yn(newValue, {default: isChecked}));
}, [isChecked, onSubmit]);
return (
<TextInput
{...props}
placeholder={placeholder}
value={value}
onChange={onChange}
onSubmit={handleSubmit}
/>
);
};
ConfirmInput.propTypes = {
isChecked: PropTypes.bool,
placeholder: PropTypes.string,
onChange: PropTypes.func,
onSubmit: PropTypes.func,
value: PropTypes.string
};
ConfirmInput.defaultProps = {
isChecked: false,
placeholder: '',
onChange: noop,
onSubmit: noop,
value: ''
};
export default ConfirmInput;