ink-text-input
Advanced tools
Comparing version 3.1.1 to 3.2.0
@@ -6,3 +6,3 @@ "use strict"; | ||
}); | ||
exports.default = void 0; | ||
exports.UncontrolledTextInput = exports.default = void 0; | ||
@@ -221,2 +221,30 @@ var _react = _interopRequireWildcard(require("react")); | ||
exports.default = TextInputWithStdin; | ||
exports.default = TextInputWithStdin; | ||
class UncontrolledTextInput extends _react.PureComponent { | ||
constructor(...args) { | ||
super(...args); | ||
_defineProperty(this, "state", { | ||
value: '' | ||
}); | ||
_defineProperty(this, "setValue", this.setValue.bind(this)); | ||
} | ||
setValue(value) { | ||
this.setState({ | ||
value | ||
}); | ||
} | ||
render() { | ||
return _react.default.createElement(TextInputWithStdin, _extends({}, this.props, { | ||
value: this.state.value, | ||
onChange: this.setValue | ||
})); | ||
} | ||
} | ||
exports.UncontrolledTextInput = UncontrolledTextInput; |
{ | ||
"name": "ink-text-input", | ||
"version": "3.1.1", | ||
"version": "3.2.0", | ||
"description": "Text input component for Ink", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
@@ -111,5 +111,32 @@ # ink-text-input [![Build Status](https://travis-ci.org/vadimdemedes/ink-text-input.svg?branch=master)](https://travis-ci.org/vadimdemedes/ink-text-input) | ||
## Uncontrolled usage | ||
This component also exposes an [uncontrolled](https://reactjs.org/docs/uncontrolled-components.html) version, which handles `value` changes for you. To receive the final input value, use `onSubmit` prop. | ||
```jsx | ||
import React from 'react'; | ||
import {render, Box} from 'ink'; | ||
import {UncontrolledTextInput} from 'ink-text-input'; | ||
const SearchQuery = () => { | ||
const handleSubmit = query => { | ||
// Do something with query | ||
}; | ||
return ( | ||
<Box> | ||
<Box marginRight={1}> | ||
Enter your query: | ||
</Box> | ||
<UncontrolledTextInput onSubmit={handleSubmit}/> | ||
</Box> | ||
); | ||
}; | ||
render(<SearchQuery/>); | ||
``` | ||
## License | ||
MIT © [Vadim Demedes](https://github.com/vadimdemedes) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
12635
238
142