-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathViewSwitch.tsx
More file actions
74 lines (66 loc) · 2.66 KB
/
ViewSwitch.tsx
File metadata and controls
74 lines (66 loc) · 2.66 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
import React, { useContext } from "react";
import Viewer from "./Viewer";
import { SimulariumContext } from "../simulation/context";
import ProgressionControl from "./shared/ProgressionControl";
import PlayButton from "./PlayButton";
import { OverlayButton } from "./shared/ButtonLibrary";
import LabIcon from "./icons/Lab";
import Molecules from "./icons/Molecules";
import LabView from "./LabView";
import VisibilityControl from "./shared/VisibilityControl";
import { Module, ViewType } from "../types";
import { FIRST_PAGE } from "../content";
import { VIEW_SWITCH_ID } from "../constants";
const ViewSwitch: React.FC = () => {
const { viewportType, setViewportType } = useContext(SimulariumContext);
const { page, isPlaying, setIsPlaying, handleTimeChange, module } =
useContext(SimulariumContext);
const isFirstPageOfFirstModule =
page === FIRST_PAGE[module] + 1 && module === Module.A_B_AB;
let buttonStyle: React.CSSProperties = {
top: 16,
right: 16,
// by default, antd animates everything, and this button moves, so we're only animating
// the hover color change and not the position change
transition:
"background 0.2s, color 0.2s, border-color 0.2s cubic-bezier(0.645, 0.045, 0.355, 1)",
};
// on the first page of the first module, the button is centered, but otherwise it's on the right
if (isFirstPageOfFirstModule) {
buttonStyle = {
...buttonStyle,
right: "50%",
transform: "translateX(50%)",
};
}
return (
<div style={{ position: "relative", height: "100%" }}>
<VisibilityControl notInBonusMaterial>
<ProgressionControl elementId={VIEW_SWITCH_ID}>
<OverlayButton
onClick={setViewportType}
style={buttonStyle}
icon={
viewportType === ViewType.Lab ? (
<Molecules />
) : (
<LabIcon />
)
}
>
{viewportType === ViewType.Lab ? "Molecular" : "Lab"}{" "}
view
</OverlayButton>
</ProgressionControl>
</VisibilityControl>
<PlayButton />
{viewportType === ViewType.Lab ? <LabView /> : null}
<Viewer
isPlaying={isPlaying}
setIsPlaying={setIsPlaying}
handleTimeChange={handleTimeChange}
/>
</div>
);
};
export default ViewSwitch;