-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.modern.js
59 lines (58 loc) · 1.41 KB
/
index.modern.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import * as readline from 'node:readline';
import React from 'react';
import { render, useFocusManager, useInput, Box, Text, useFocus } from 'ink';
readline.emitKeypressEvents(process.stdin);
process.stdin.on('keypress', function (str, key) {
if (key && key.name === 'q') {
process.stdin.pause();
}
});
process.stdin.setRawMode(true);
function Item(props) {
const {
id,
label
} = props;
const {
isFocused
} = useFocus({
id
});
return /*#__PURE__*/React.createElement(Text, {
inverse: isFocused
}, label);
}
function App() {
const {
focus
} = useFocusManager();
useInput(input => {
switch (input) {
case '1':
focus('item-1');
break;
case '2':
focus('item-2');
break;
case '3':
focus('item-3');
break;
}
});
return /*#__PURE__*/React.createElement(Box, {
width: "100%",
height: "100%",
flexDirection: "column"
}, /*#__PURE__*/React.createElement(Text, null, "Press 1, 2 or 3 to focus an item. Press Tab to focus next item. Press q to exit."), /*#__PURE__*/React.createElement(Item, {
id: "item-1",
label: "Item 1"
}), /*#__PURE__*/React.createElement(Item, {
id: "item-2",
label: "Item 2"
}), /*#__PURE__*/React.createElement(Item, {
id: "item-3",
label: "Item 3"
}));
}
render( /*#__PURE__*/React.createElement(App, null));
//# sourceMappingURL=index.modern.js.map