From 8f4130aafd4ae65cc643119f0d6cbed17ef2fc13 Mon Sep 17 00:00:00 2001 From: Sendou <38327916+Sendouc@users.noreply.github.com> Date: Sat, 20 Jun 2020 14:36:31 +0300 Subject: [PATCH] new color picker --- .../plans/DraggableToolsSelector.tsx | 65 ++++++++++++++++++- .../src/components/plans/MapPlannerPage.tsx | 61 +++-------------- 2 files changed, 72 insertions(+), 54 deletions(-) diff --git a/frontend-react/src/components/plans/DraggableToolsSelector.tsx b/frontend-react/src/components/plans/DraggableToolsSelector.tsx index ca4232495..9cce67d18 100644 --- a/frontend-react/src/components/plans/DraggableToolsSelector.tsx +++ b/frontend-react/src/components/plans/DraggableToolsSelector.tsx @@ -2,7 +2,15 @@ import React, { useState, useContext } from "react" import Draggable from "react-draggable" import { Tools } from "@sendou/react-sketch" import { useHotkeys } from "react-hotkeys-hook" -import { Box, Flex, IconButton } from "@chakra-ui/core" +import { + Box, + Flex, + IconButton, + Popover, + PopoverTrigger, + PopoverContent, + PopoverBody, +} from "@chakra-ui/core" import { FaPencilAlt, FaRegSquare, @@ -11,9 +19,47 @@ import { FaTrashAlt, FaRedo, FaUndo, + FaFont, } from "react-icons/fa" import { AiOutlineLine } from "react-icons/ai" import MyThemeContext from "../../themeContext" +import { CirclePicker, ColorResult } from "react-color" + +interface PlannerColorPickerProps { + color: string + setColor: (newColor: string) => void +} + +const PlannerColorPicker: React.FC = ({ + color, + setColor, +}) => { + const { darkerBgColor } = useContext(MyThemeContext) + return ( + + + + + + + setColor(color.hex)} + /> + + + + ) +} interface DraggableToolsSelectorProps { tool: any @@ -24,6 +70,9 @@ interface DraggableToolsSelectorProps { undoIsDisabled: boolean removeSelected: () => void removeIsDisabled: boolean + addText: () => void + color: string + setColor: (newColor: string) => void } const DraggableToolsSelector: React.FC = ({ @@ -35,6 +84,9 @@ const DraggableToolsSelector: React.FC = ({ undoIsDisabled, removeSelected, removeIsDisabled, + addText, + color, + setColor, }) => { const { darkerBgColor, themeColorHex } = useContext(MyThemeContext) const [activeDrags, setActiveDrags] = useState(0) @@ -150,6 +202,17 @@ const DraggableToolsSelector: React.FC = ({ icon={FaRedo} title="Redo" /> + addText()} + variant="ghost" + size="lg" + aria-label="Add text" + icon={FaFont} + title="Add text" + /> + + + diff --git a/frontend-react/src/components/plans/MapPlannerPage.tsx b/frontend-react/src/components/plans/MapPlannerPage.tsx index 9061c55e8..cb93cf6f4 100644 --- a/frontend-react/src/components/plans/MapPlannerPage.tsx +++ b/frontend-react/src/components/plans/MapPlannerPage.tsx @@ -100,7 +100,6 @@ const MapPlannerPage: React.FC = () => { const [color, setColor] = useState("#f44336") const [canUndo, setCanUndo] = useState(false) const [canRedo, setCanRedo] = useState(false) - const [text, setText] = useState("") const [bg, setBg] = useState(REEFTW) const [uploadError, setUploadError] = useState(null) const [controlledValue, setControlledValue] = useState(defaultValue) @@ -121,7 +120,7 @@ const MapPlannerPage: React.FC = () => { } const addTextToSketch = () => { - sketch.addText(text, { + sketch.addText("Double-click to edit", { fill: color, fontFamily: "lato", stroke: "#000000", @@ -170,10 +169,9 @@ const MapPlannerPage: React.FC = () => { document.body.appendChild(a) a.style.display = "none" a.href = dataUrl - /*a.download = `${ - bg.replace("/static/media/", "").split("-")[0] - } plans ${getDateFormatted()}.${extension}`*/ - a.download = "asd" + a.download = `${bg.view}-${stageToCode.get(bg.stage)}-${ + bg.mode + } plans ${getDateFormatted()}.${extension}` a.click() window.URL.revokeObjectURL(dataUrl) } @@ -217,6 +215,9 @@ const MapPlannerPage: React.FC = () => { undoIsDisabled={!canUndo} removeSelected={removeSelected} removeIsDisabled={tool !== Tools.Select} + addText={addTextToSketch} + color={color} + setColor={(newColor) => setColor(newColor)} /> = () => { {uploadError && {uploadError}} - - ) => - setText(e.currentTarget.value) - } - /> - - - - - - - - {/**/} - setColor(newColor.hex)} - colors={[ - "#f44336", - "#e91e63", - "#9c27b0", - "#673ab7", - "#3f51b5", - "#2196f3", - "#03a9f4", - "#00bcd4", - "#009688", - "#4caf50", - "#8bc34a", - "#cddc39", - "#ffeb3b", - "#ffc107", - "#ff9800", - ]} - /> - + ) }