diff --git a/src/components/map/controls/DrawingToolSettings.js b/src/components/map/controls/DrawingToolSettings.js
index 676ab98..66b0137 100644
--- a/src/components/map/controls/DrawingToolSettings.js
+++ b/src/components/map/controls/DrawingToolSettings.js
@@ -1,9 +1,11 @@
import React, { useEffect, useContext } from "react";
import { Flex, IconButton } from "theme-ui";
+import { useMedia } from "react-media";
import ColorControl from "./ColorControl";
import AlphaBlendToggle from "./AlphaBlendToggle";
import RadioIconButton from "./RadioIconButton";
+import ToolSection from "./ToolSection";
import BrushIcon from "../../../icons/BrushToolIcon";
import BrushPaintIcon from "../../../icons/BrushPaintIcon";
@@ -78,6 +80,47 @@ function DrawingToolSettings({
}
}, [disabledActions, settings, onSettingChange]);
+ const isSmallScreen = useMedia({ query: "(max-width: 799px)" });
+
+ const tools = [
+ {
+ id: "brush",
+ title: "Brush",
+ isSelected: settings.type === "brush",
+ icon: ,
+ },
+ {
+ id: "paint",
+ title: "Paint",
+ isSelected: settings.type === "paint",
+ icon: ,
+ },
+ {
+ id: "line",
+ title: "Line",
+ isSelected: settings.type === "line",
+ icon: ,
+ },
+ {
+ id: "rectangle",
+ title: "Rectangle",
+ isSelected: settings.type === "rectangle",
+ icon: ,
+ },
+ {
+ id: "circle",
+ title: "Circle",
+ isSelected: settings.type === "circle",
+ icon: ,
+ },
+ {
+ id: "triangle",
+ title: "Triangle",
+ isSelected: settings.type === "triangle",
+ icon: ,
+ },
+ ];
+
return (
onSettingChange({ color })}
/>
- onSettingChange({ type: "brush" })}
- isSelected={settings.type === "brush"}
- >
-
-
- onSettingChange({ type: "paint" })}
- isSelected={settings.type === "paint"}
- >
-
-
- onSettingChange({ type: "line" })}
- isSelected={settings.type === "line"}
- >
-
-
- onSettingChange({ type: "rectangle" })}
- isSelected={settings.type === "rectangle"}
- >
-
-
- onSettingChange({ type: "circle" })}
- isSelected={settings.type === "circle"}
- >
-
-
- onSettingChange({ type: "triangle" })}
- isSelected={settings.type === "triangle"}
- >
-
-
+ onSettingChange({ type: tool.id })}
+ collapse={isSmallScreen}
+ />
,
+ },
+ {
+ id: "brush",
+ title: "Fog Brush",
+ isSelected: settings.type === "brush",
+ icon: ,
+ },
+ ];
+
+ const modeTools = [
+ {
+ id: "add",
+ title: "Add Fog",
+ isSelected: !settings.useFogSubtract,
+ icon: ,
+ },
+ {
+ id: "subtract",
+ title: "Subtracy Fog",
+ isSelected: settings.useFogSubtract,
+ icon: ,
+ },
+ ];
+
return (
- onSettingChange({ type: "polygon" })}
- isSelected={settings.type === "polygon"}
- >
-
-
- onSettingChange({ type: "brush" })}
- isSelected={settings.type === "brush"}
- >
-
-
+ onSettingChange({ type: tool.id })}
+ collapse={isSmallScreen}
+ />
- onSettingChange({ useFogSubtract: false })}
- isSelected={!settings.useFogSubtract}
- >
-
-
- onSettingChange({ useFogSubtract: true })}
- isSelected={settings.useFogSubtract}
- >
-
-
+
+ onSettingChange({ useFogSubtract: tool.id === "subtract" })
+ }
+ collapse={isSmallScreen}
+ />
{
+ const selectedTool = tools.find((tool) => tool.isSelected);
+ if (selectedTool) {
+ setCollapsedTool(selectedTool);
+ } else {
+ setCollapsedTool(
+ (prevTool) => prevTool && { ...prevTool, isSelected: false }
+ );
+ }
+ }, [tools]);
+
+ function handleToolClick(tool) {
+ if (collapse && tool.isSelected) {
+ setShowMore(!showMore);
+ } else if (collapse && !tool.isSelected) {
+ setShowMore(false);
+ }
+ onToolClick(tool);
+ }
+
+ function renderTool(tool) {
+ return (
+ handleToolClick(tool)}
+ key={tool.id}
+ isSelected={tool.isSelected}
+ >
+ {tool.icon}
+
+ );
+ }
+
+ if (collapse) {
+ if (!collapsedTool) {
+ return null;
+ }
+ return (
+
+ {renderTool(collapsedTool)}
+ {/* Render chevron when more tools is available */}
+
+ {showMore && (
+
+ {tools.filter((tool) => !tool.isSelected).map(renderTool)}
+
+ )}
+
+ );
+ } else {
+ return tools.map((tool) => (
+ handleToolClick(tool)}
+ key={tool.id}
+ isSelected={tool.isSelected}
+ >
+ {tool.icon}
+
+ ));
+ }
+}
+
+export default ToolSection;