24 | react-console
25 | 26 |Simple React.js console emulator.
27 | 28 | 29 | 30 | 33 | 34 | 35 | 36 |37 | Example
38 | 39 |Simple prompt that echoes back input:
40 | 41 |let EchoConsole = React.createClass({
42 | echo: function(text) {
43 | this.refs.console.log(text);
44 | this.refs.console.return();
45 | },
46 | render: function() {
47 | return <Console ref="console"
48 | handler={this.echo}
49 | autofocus={true}
50 | />;
51 | }
52 | });See the example project used in the live demo.
55 | 56 |57 | Installation
58 | 59 |npm install --save-dev react-console-component
60 |
61 |
62 | 63 | Features
64 | 65 |-
66 |
- Readline emulation 67 |
- Mobile friendly 68 |
- Input Method Editor (IME) support 69 |
72 | Props
73 | 74 |Properties you can pass to the console element
75 | 76 || Prop | 80 |Type | 81 |Description | 82 |
|---|---|---|
| autofocus? | 87 |bool | 88 |Autofocus the console on component mount. | 89 |
| cancel? | 92 |()=>any | 93 |Function that should stop execution of the current command and call this.return(). |
94 |
| complete? | 97 |(words: string[], cursor: number, prompt: string)=>string[] | 98 |Return a list of possible completions given a list of (words), index of the word containing the cursor (cursor) , and the full prompt text (prompt). |
99 |
| continue? | 102 |(prompt: string)=>bool | 103 |Return a boolean indicating whether to continue asking for user input on a newline given the current prompt text (prompt). |
104 |
| handler | 107 |(command: string)=>any | 108 |Handle a command (command), logging data with this.log() or this.logX(), and calling this.return() when finished. |
109 |
| promptLabel? | 112 |string | ()=>string | 113 |String or function that generates a string displayed to prompt user for input. | 114 |
| welcomeMessage? | 117 |string | 118 |Initial message displayed after mount. | 119 |
124 | Public members
125 | 126 || Member | 130 |Type | 131 |Description | 132 |
|---|---|---|
| log | 137 |(...messages: any)=>void | 138 |Log messages to the console. If string, print the value, otherwise, print the JSON value of the message. | 139 |
| logX | 142 |(type: string, ...messages: any)=>void | 143 |Log messages of a particular type to the console. The messages will be given the class react-console-message-{type}. |
144 |
| return | 147 |()=>void | 148 |Signal the current command has finished and a new prompt should be displayed. | 149 |
154 | Awknoledgements
155 | 156 |React-console is inspired by chrisdone/jquery-console.
157 | 158 | 163 | 164 |