-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathTextBox.js
More file actions
108 lines (98 loc) · 3.48 KB
/
Copy pathTextBox.js
File metadata and controls
108 lines (98 loc) · 3.48 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
import { Button, Tabs, Dropdown, Menu, Space } from "antd";
const { TabPane } = Tabs;
import { DownOutlined, PlayCircleOutlined, FullscreenOutlined, FullscreenExitOutlined } from "@ant-design/icons";
import { useIsMobile } from "./useIsMobile";
import React, { useState, useEffect } from 'react';
import preinstalled_programs from "../utils/preinstalled_programs";
import dynamic from 'next/dynamic'
const Editor = dynamic(() => import('./Editor'), {
ssr: false,
});
function TextBox({ disabled, sourceCode, setSourceCode, exampleName, setExampleName, activeTab, handleUserTabChange, myHeight, editorRef }) {
const isMobile = useIsMobile();
const [isFullScreen, setIsFullScreen] = useState(false);
useEffect(() => {
const handler = () => setIsFullScreen(!!document.fullscreenElement);
document.addEventListener("fullscreenchange", handler);
return () => document.removeEventListener("fullscreenchange", handler);
}, []);
const handleFullScreen = () => {
if (!document.fullscreenElement) {
document.documentElement.requestFullscreen();
} else {
document.exitFullscreen();
}
};
var menu_items = [];
for (let category in preinstalled_programs) {
var category_examples = []
for (let example in preinstalled_programs[category]) {
category_examples.push({
key: example,
label: example,
onClick: () => {
setSourceCode(preinstalled_programs[category][example]);
setExampleName(example);
}
});
}
menu_items.push({
key: category,
label: category,
children: category_examples
});
}
const extraOperations = {
right: (
<Space>
<Button
onClick={handleFullScreen}
icon={isFullScreen ? <FullscreenExitOutlined /> : <FullscreenOutlined />}
>
{!isMobile && (isFullScreen ? " Exit Fullscreen" : " Fullscreen")}
</Button>
<Button
disabled={disabled}
onClick={() => handleUserTabChange(activeTab)}
icon={<PlayCircleOutlined />}
>
Run
</Button>
</Space>
),
left: (
<Dropdown menu={{ items: menu_items }} trigger={["hover"]}>
<a onClick={(e) => e.preventDefault()}>
<Space style={{ marginRight: "10px" }}>
{!isMobile && "Examples"} <DownOutlined />
</Space>
</a>
</Dropdown>
)
};
const tabItems = [
{
key: '1',
label: `${exampleName}.f90`,
children: (
<div style={{ height: myHeight }}>
<Editor
sourceCode={sourceCode}
setSourceCode={setSourceCode}
editorRef={editorRef}// Pass the ref to the Editor
/>
</div>
),
},
];
return (
<div className="card-container" style={{height: "100%" }}>
<Tabs
tabBarExtraContent={extraOperations}
style={{ height: "100%" }}
items={tabItems}
/>
</div>
);
}
export default TextBox;