From 50541c40de5ba77e571a48e4fe785635096d9633 Mon Sep 17 00:00:00 2001 From: PARTHIV PRATIM SAIKIA Date: Mon, 24 Nov 2025 11:57:40 +0530 Subject: [PATCH 1/2] feat: enable ESC and Double Click to close shape Signed-off-by: PARTHIV PRATIM SAIKIA --- site/src/components/ShapeBuilder/index.js | 85 +++++++++++++----- site/src/pages/index.js | 101 +++++++++++++++++----- 2 files changed, 143 insertions(+), 43 deletions(-) diff --git a/site/src/components/ShapeBuilder/index.js b/site/src/components/ShapeBuilder/index.js index 87cd10e..0abb884 100644 --- a/site/src/components/ShapeBuilder/index.js +++ b/site/src/components/ShapeBuilder/index.js @@ -1,6 +1,12 @@ // /* global window */ import React, { useEffect, useRef, useState } from "react"; -import { Wrapper, CanvasContainer, OutputBox, StyledSVG, CopyButton } from "./shapeBuilder.styles"; +import { + Wrapper, + CanvasContainer, + OutputBox, + StyledSVG, + CopyButton, +} from "./shapeBuilder.styles"; import { Button, Typography, Box, CopyIcon } from "@sistent/sistent"; import { SVG, extend as SVGextend } from "@svgdotjs/svg.js"; import draw from "@svgdotjs/svg.draw.js"; @@ -60,13 +66,16 @@ const ShapeBuilder = () => { const points = getPlottedPoints(poly); if (!points) return; - const xs = points.map(p => p[0]); - const ys = points.map(p => p[1]); + const xs = points.map((p) => p[0]); + const ys = points.map((p) => p[1]); const width = Math.abs(Math.max(...xs) - Math.min(...xs)); const height = Math.abs(Math.max(...ys) - Math.min(...ys)); - poly.size(width > height ? 520 : undefined, height >= width ? 520 : undefined); + poly.size( + width > height ? 520 : undefined, + height >= width ? 520 : undefined, + ); poly.move(0, 0); showCytoArray(); }; @@ -79,7 +88,7 @@ const ShapeBuilder = () => { poly.draw("param", "snapToGrid", 0.001); } - if (e.key === "Enter") { + if (e.key === "Enter" || e.key === "Escape") { poly.draw("done"); poly.fill("#00B39F"); showCytoArray(); @@ -172,34 +181,66 @@ const ShapeBuilder = () => { return ( - + - - + + {error && ( -
+
{error}
)} - - - - + + + + diff --git a/site/src/pages/index.js b/site/src/pages/index.js index 157514d..9d417ff 100644 --- a/site/src/pages/index.js +++ b/site/src/pages/index.js @@ -1,41 +1,100 @@ -import React, { useState } from "react"; -import { ThemeProvider } from "styled-components"; +import React from "react"; +import styled, { ThemeProvider } from "styled-components"; import { GlobalStyle, Main, lightTheme, darkTheme } from "../styles/styles"; import { useDarkMode } from "../components/useDarkMode"; import Navigation from "../components/Navigation"; import Footer from "../components/Footer"; import ShapeBuilder from "../components/ShapeBuilder"; -import { Button, SistentThemeProviderWithoutBaseLine, Box } from "@sistent/sistent"; -import InstructionsModal from "../components/utils/instructionsModal"; +import { SistentThemeProviderWithoutBaseLine, Box } from "@sistent/sistent"; + +const Kbd = styled.kbd` + background-color: ${({ theme }) => + theme.mode === "light" ? "#f4f4f4" : "#2b2b2b"}; + border: 1px solid + ${({ theme }) => (theme.mode === "light" ? "#d1d5da" : "#444")}; + border-bottom-color: ${({ theme }) => + theme.mode === "light" ? "#c6cbd1" : "#444"}; + border-radius: 3px; + box-shadow: inset 0 -1px 0 + ${({ theme }) => (theme.mode === "light" ? "#c6cbd1" : "#444")}; + color: ${({ theme }) => (theme.mode === "light" ? "#444" : "#e6e6e6")}; + display: inline-block; + font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace; + font-size: 11px; + font-weight: 600; + line-height: 1; + padding: 3px 6px; + margin-right: 6px; + vertical-align: middle; +`; + +const InstructionsContainer = styled.div` + display: flex; + justify-content: center; + align-items: center; + flex-wrap: wrap; + gap: 24px; + margin-top: 16px; + font-size: 0.9rem; + color: ${({ theme }) => (theme.mode === "light" ? "#666" : "#aaa")}; + + span { + display: flex; + align-items: center; + } +`; const IndexPage = () => { - // const themesistent = useTheme(); const [theme, toggleTheme] = useDarkMode(); const themeMode = theme === "light" ? lightTheme : darkTheme; - const [open, setOpen] = useState(false); + const activeTheme = { ...themeMode, mode: theme }; return ( - +
-

Shape Builder

-

- Click on the grid to start creating a polygon. Each click adds a point. -

-
- - - - setOpen(false)} /> +

Shape Builder

+ +

+ Click on the grid to start creating a polygon. Each click adds a + point. +

+ + + + ENTER /{" "} + ESC Close shape + + + + CTRL Snap to grid + + + + CTRL +{" "} + Z Undo + + + + Maximize Visibility + + + + +