-
-
Notifications
You must be signed in to change notification settings - Fork 181
Expand file tree
/
Copy pathform.jsx
More file actions
61 lines (55 loc) · 1.3 KB
/
form.jsx
File metadata and controls
61 lines (55 loc) · 1.3 KB
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import React, {Component} from 'react';
import blessed from 'blessed';
import {render} from '../src';
import AnimatedBox from './components/AnimatedBox';
class Form extends Component {
constructor(props) {
super(props);
this.state = {
name: ''
};
this.submit = data => this.setState(state => ({name: data}));
this.cancel = _ => console.log('Form canceled');
}
render() {
return (
<form
keys
vi
focused
onSubmit={this.submit}
onReset={this.cancel}
left="5%"
top="5%"
width="90%"
height="90%"
border={{type: 'line'}}
style={{bg: 'cyan', border: {fg: 'blue'}}}>
<box width={6} height={3}>
Name:{' '}
</box>
<textbox
onSubmit={this.submit}
left={6}
height={3}
keys
mouse
inputOnFocus
/>
<box top={3} height={3}>
{`Result: ${this.state.name}`}
</box>
<AnimatedBox />
</form>
);
}
}
const screen = blessed.screen({
autoPadding: true,
// smartCSR: true,
title: 'react-blessed form example'
});
screen.key(['escape', 'q', 'C-c'], function (ch, key) {
return process.exit(0);
});
render(<Form />, screen, inst => console.log('Rendered Form!'));