Skip to content

Commit 86e49f1

Browse files
Merge pull request #92 from parthivsaikia/feat/72-exit-shortcuts
[Shape-builder]: enable ESC and Double Click to close shape
2 parents 30e22db + a5318a8 commit 86e49f1

File tree

2 files changed

+87
-23
lines changed

2 files changed

+87
-23
lines changed

site/src/components/ShapeBuilder/index.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ const ShapeBuilder = () => {
7979
poly.draw("param", "snapToGrid", 0.001);
8080
}
8181

82-
if (e.key === "Enter") {
82+
if (e.key === "Enter" || e.key === "Escape") {
8383
poly.draw("done");
8484
poly.fill("#00B39F");
8585
showCytoArray();
@@ -172,7 +172,12 @@ const ShapeBuilder = () => {
172172
return (
173173
<Wrapper>
174174
<CanvasContainer>
175-
<StyledSVG ref={boardRef} width="100%" height="100%">
175+
<StyledSVG
176+
ref={boardRef}
177+
width="100%"
178+
height="100%"
179+
onDoubleClick={closeShape}
180+
>
176181
<defs>
177182
<pattern id="grid" width="16" height="16" patternUnits="userSpaceOnUse">
178183
<path d="M 16 0 L 0 0 0 16" fill="none" stroke="#797d7a" strokeWidth="1" />

site/src/pages/index.js

Lines changed: 80 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,100 @@
1-
import React, { useState } from "react";
2-
import { ThemeProvider } from "styled-components";
1+
import React from "react";
2+
import styled, { ThemeProvider } from "styled-components";
33
import { GlobalStyle, Main, lightTheme, darkTheme } from "../styles/styles";
44
import { useDarkMode } from "../components/useDarkMode";
55
import Navigation from "../components/Navigation";
66
import Footer from "../components/Footer";
77
import ShapeBuilder from "../components/ShapeBuilder";
8-
import { Button, SistentThemeProviderWithoutBaseLine, Box } from "@sistent/sistent";
9-
import InstructionsModal from "../components/utils/instructionsModal";
8+
import { SistentThemeProviderWithoutBaseLine, Box } from "@sistent/sistent";
9+
10+
const Kbd = styled.kbd`
11+
background-color: ${({ theme }) =>
12+
theme.mode === "light" ? "#f4f4f4" : "#2b2b2b"};
13+
border: 1px solid
14+
${({ theme }) => (theme.mode === "light" ? "#d1d5da" : "#444")};
15+
border-bottom-color: ${({ theme }) =>
16+
theme.mode === "light" ? "#c6cbd1" : "#444"};
17+
border-radius: 3px;
18+
box-shadow: inset 0 -1px 0
19+
${({ theme }) => (theme.mode === "light" ? "#c6cbd1" : "#444")};
20+
color: ${({ theme }) => (theme.mode === "light" ? "#444" : "#e6e6e6")};
21+
display: inline-block;
22+
font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
23+
font-size: 11px;
24+
font-weight: 600;
25+
line-height: 1;
26+
padding: 3px 6px;
27+
margin-right: 6px;
28+
vertical-align: middle;
29+
`;
30+
31+
const InstructionsContainer = styled.div`
32+
display: flex;
33+
justify-content: center;
34+
align-items: center;
35+
flex-wrap: wrap;
36+
gap: 24px;
37+
margin-top: 16px;
38+
font-size: 0.9rem;
39+
color: ${({ theme }) => (theme.mode === "light" ? "#666" : "#aaa")};
40+
41+
span {
42+
display: flex;
43+
align-items: center;
44+
}
45+
`;
1046

1147
const IndexPage = () => {
12-
// const themesistent = useTheme();
1348
const [theme, toggleTheme] = useDarkMode();
1449
const themeMode = theme === "light" ? lightTheme : darkTheme;
15-
const [open, setOpen] = useState(false);
50+
const activeTheme = { ...themeMode, mode: theme };
1651

1752
return (
1853
<SistentThemeProviderWithoutBaseLine>
19-
<ThemeProvider theme={themeMode}>
54+
<ThemeProvider theme={activeTheme}>
2055
<GlobalStyle />
2156
<Navigation theme={theme} toggleTheme={toggleTheme} />
2257
<Main>
2358
<section className="hero">
24-
<h1>Shape Builder</h1>
25-
<p className="desc-text">
26-
Click on the grid to start creating a polygon. Each click adds a point.
27-
</p>
28-
</section>
29-
<Box sx={{ display: "flex", justifyContent: "center", mt: 2 }}>
30-
<Button
31-
variant="contained"
32-
sx={{ minWidth: "fit-content" }}
33-
onClick={() => setOpen(true)}
59+
<Box
60+
sx={{
61+
display: "flex",
62+
flexDirection: "column",
63+
alignItems: "center",
64+
justifyContent: "center",
65+
gap: 2,
66+
mb: 4,
67+
}}
3468
>
35-
Show Instructions
36-
</Button>
37-
</Box>
38-
<InstructionsModal open={open} onClose={() => setOpen(false)} />
69+
<h1>Shape Builder</h1>
70+
71+
<p className="desc-text" style={{ margin: 0 }}>
72+
Click on the grid to start creating a polygon. Each click adds a
73+
point.
74+
</p>
75+
76+
<InstructionsContainer theme={activeTheme}>
77+
<span>
78+
<Kbd theme={activeTheme}>ENTER</Kbd> /{" "}
79+
<Kbd theme={activeTheme}>ESC</Kbd> Close shape
80+
</span>
81+
82+
<span>
83+
<Kbd theme={activeTheme}>CTRL</Kbd> Snap to grid
84+
</span>
85+
86+
<span>
87+
<Kbd theme={activeTheme}>CTRL</Kbd> +{" "}
88+
<Kbd theme={activeTheme}>Z</Kbd> Undo
89+
</span>
90+
91+
<span>
92+
<Kbd theme={activeTheme}>Maximize</Kbd> Visibility
93+
</span>
94+
</InstructionsContainer>
95+
</Box>
96+
</section>
97+
3998
<ShapeBuilder />
4099
</Main>
41100
<Footer />

0 commit comments

Comments
 (0)