|
1 | | -import React from "react"; |
2 | 1 | import "./index.css"; |
3 | 2 |
|
4 | | -class ControlBox extends React.Component { |
5 | | - handleSupercellChange = (index, value) => { |
6 | | - let newSupercell = this.props.viewerParams.supercell; |
| 3 | +const ControlBox = ({ viewerParams, onViewerParamChange, onViewerEvent }) => { |
| 4 | + const handleSupercellChange = (index, value) => { |
| 5 | + let newSupercell = viewerParams.supercell; |
7 | 6 | newSupercell[index] = parseInt(value); |
8 | | - this.props.onViewerParamChange("supercell", newSupercell); |
| 7 | + onViewerParamChange("supercell", newSupercell); |
9 | 8 | }; |
10 | 9 |
|
11 | | - handleOptionChange = (option) => { |
12 | | - this.props.onViewerParamChange(option, !this.props.viewerParams[option]); |
| 10 | + const handleOptionChange = (option) => { |
| 11 | + onViewerParamChange(option, !viewerParams[option]); |
13 | 12 | }; |
14 | 13 |
|
15 | | - handleCameraEvent = (orientation) => { |
16 | | - this.props.onViewerEvent("camera", orientation); |
| 14 | + const handleCameraEvent = (orientation) => { |
| 15 | + onViewerEvent("camera", orientation); |
17 | 16 | }; |
18 | 17 |
|
19 | | - render() { |
20 | | - return ( |
21 | | - <div className="control-box"> |
22 | | - <div className="control-box-row"> |
23 | | - <div className="supercell-container"> |
24 | | - <label>Supercell: </label> |
25 | | - <div style={{ display: "flex" }}> |
26 | | - {[0, 1, 2].map((index) => ( |
27 | | - <input |
28 | | - key={index} |
29 | | - className="supercell-input" |
30 | | - type="number" |
31 | | - min="1" |
32 | | - max="99" |
33 | | - value={this.props.viewerParams.supercell[index]} |
34 | | - onChange={(e) => |
35 | | - this.handleSupercellChange(index, e.target.value) |
36 | | - } |
37 | | - /> |
38 | | - ))} |
39 | | - </div> |
40 | | - </div> |
41 | | - |
42 | | - <div className="camera-controls"> |
43 | | - <label>Camera: </label> |
44 | | - <button |
45 | | - className="camera-button" |
46 | | - onClick={() => this.handleCameraEvent("x")} |
47 | | - > |
48 | | - x |
49 | | - </button> |
50 | | - <button |
51 | | - className="camera-button" |
52 | | - onClick={() => this.handleCameraEvent("y")} |
53 | | - > |
54 | | - y |
55 | | - </button> |
56 | | - <button |
57 | | - className="camera-button" |
58 | | - onClick={() => this.handleCameraEvent("z")} |
59 | | - > |
60 | | - z |
61 | | - </button> |
| 18 | + return ( |
| 19 | + <div className="control-box"> |
| 20 | + <div className="control-box-row"> |
| 21 | + <div className="supercell-container"> |
| 22 | + <label>Supercell: </label> |
| 23 | + <div style={{ display: "flex" }}> |
| 24 | + {[0, 1, 2].map((index) => ( |
| 25 | + <input |
| 26 | + key={index} |
| 27 | + className="supercell-input" |
| 28 | + type="number" |
| 29 | + min="1" |
| 30 | + max="99" |
| 31 | + value={viewerParams.supercell[index]} |
| 32 | + onChange={(e) => handleSupercellChange(index, e.target.value)} |
| 33 | + /> |
| 34 | + ))} |
62 | 35 | </div> |
63 | 36 | </div> |
64 | | - <div className="control-box-row" style={{ display: "flex" }}> |
65 | | - <label className="option-checkbox"> |
66 | | - <input |
67 | | - type="checkbox" |
68 | | - checked={this.props.viewerParams.bonds} |
69 | | - onChange={() => this.handleOptionChange("bonds")} |
70 | | - /> |
71 | | - <span>Bonds</span> |
72 | | - </label> |
73 | | - <label className="option-checkbox"> |
74 | | - <input |
75 | | - type="checkbox" |
76 | | - checked={this.props.viewerParams.packedCell} |
77 | | - onChange={() => this.handleOptionChange("packedCell")} |
78 | | - /> |
79 | | - <span>Packed cell</span> |
80 | | - </label> |
81 | | - <label className="option-checkbox"> |
82 | | - <input |
83 | | - type="checkbox" |
84 | | - checked={this.props.viewerParams.atomLabels} |
85 | | - onChange={() => this.handleOptionChange("atomLabels")} |
86 | | - /> |
87 | | - <span>Atom labels</span> |
88 | | - </label> |
89 | | - <label className="option-checkbox"> |
90 | | - <input |
91 | | - type="checkbox" |
92 | | - checked={this.props.viewerParams.spaceFilling} |
93 | | - onChange={() => this.handleOptionChange("vdwRadius")} |
94 | | - /> |
95 | | - <span>vdW radius</span> |
96 | | - </label> |
| 37 | + |
| 38 | + <div className="camera-controls"> |
| 39 | + <label>Camera: </label> |
| 40 | + <button |
| 41 | + className="camera-button" |
| 42 | + onClick={() => handleCameraEvent("x")} |
| 43 | + > |
| 44 | + x |
| 45 | + </button> |
| 46 | + <button |
| 47 | + className="camera-button" |
| 48 | + onClick={() => handleCameraEvent("y")} |
| 49 | + > |
| 50 | + y |
| 51 | + </button> |
| 52 | + <button |
| 53 | + className="camera-button" |
| 54 | + onClick={() => handleCameraEvent("z")} |
| 55 | + > |
| 56 | + z |
| 57 | + </button> |
97 | 58 | </div> |
98 | 59 | </div> |
99 | | - ); |
100 | | - } |
101 | | -} |
| 60 | + <div className="control-box-row" style={{ display: "flex" }}> |
| 61 | + <label className="option-checkbox"> |
| 62 | + <input |
| 63 | + type="checkbox" |
| 64 | + checked={viewerParams.bonds} |
| 65 | + onChange={() => handleOptionChange("bonds")} |
| 66 | + /> |
| 67 | + <span>Bonds</span> |
| 68 | + </label> |
| 69 | + <label className="option-checkbox"> |
| 70 | + <input |
| 71 | + type="checkbox" |
| 72 | + checked={viewerParams.packedCell} |
| 73 | + onChange={() => handleOptionChange("packedCell")} |
| 74 | + /> |
| 75 | + <span>Packed cell</span> |
| 76 | + </label> |
| 77 | + <label className="option-checkbox"> |
| 78 | + <input |
| 79 | + type="checkbox" |
| 80 | + checked={viewerParams.atomLabels} |
| 81 | + onChange={() => handleOptionChange("atomLabels")} |
| 82 | + /> |
| 83 | + <span>Atom labels</span> |
| 84 | + </label> |
| 85 | + <label className="option-checkbox"> |
| 86 | + <input |
| 87 | + type="checkbox" |
| 88 | + checked={viewerParams.spaceFilling} |
| 89 | + onChange={() => handleOptionChange("vdwRadius")} |
| 90 | + /> |
| 91 | + <span>vdW radius</span> |
| 92 | + </label> |
| 93 | + </div> |
| 94 | + </div> |
| 95 | + ); |
| 96 | +}; |
102 | 97 |
|
103 | 98 | export default ControlBox; |
0 commit comments