diff --git a/src/components/Panel.tsx b/src/components/Panel.tsx new file mode 100644 index 00000000..9435e59e --- /dev/null +++ b/src/components/Panel.tsx @@ -0,0 +1,43 @@ +import React, { useState } from "react"; + +interface PanelProps { + title: string; + defaultCollapsed?: boolean; + hide?: boolean; +} + +export const Panel: React.FC = ({ + title, + children, + defaultCollapsed = false, + hide = false +}) => { + const [collapsed, setCollapsed] = useState(defaultCollapsed); + + if (hide) return null; + + return ( +
+

{title}

+ + {!collapsed &&
{children}
} +
+ ); +}; diff --git a/src/components/panels/PanelCanvas.tsx b/src/components/panels/PanelCanvas.tsx index f647e63c..9208b0d9 100644 --- a/src/components/panels/PanelCanvas.tsx +++ b/src/components/panels/PanelCanvas.tsx @@ -1,6 +1,7 @@ import React from "react"; import { ColorPicker } from "../ColorPicker"; +import { Panel } from "../Panel"; interface PanelCanvasProps { viewBackgroundColor: string; @@ -14,22 +15,19 @@ export const PanelCanvas: React.FC = ({ onClearCanvas }) => { return ( - <> -

Canvas

-
-
Canvas Background Color
- onViewBackgroundColorChange(color)} - /> - -
- + +
Canvas Background Color
+ onViewBackgroundColorChange(color)} + /> + +
); }; diff --git a/src/components/panels/PanelExport.tsx b/src/components/panels/PanelExport.tsx index 9c36aba2..81bee94c 100644 --- a/src/components/panels/PanelExport.tsx +++ b/src/components/panels/PanelExport.tsx @@ -1,5 +1,6 @@ import React from "react"; import { EditableText } from "../EditableText"; +import { Panel } from "../Panel"; interface PanelExportProps { projectName: string; @@ -21,8 +22,7 @@ export const PanelExport: React.FC = ({ onExportAsPNG }) => { return ( - <> -

Export

+
Name
{projectName && ( @@ -47,6 +47,6 @@ export const PanelExport: React.FC = ({
- +
); }; diff --git a/src/components/panels/PanelSelection.tsx b/src/components/panels/PanelSelection.tsx index 57eb3e56..6e366c69 100644 --- a/src/components/panels/PanelSelection.tsx +++ b/src/components/panels/PanelSelection.tsx @@ -14,8 +14,7 @@ export const PanelSelection: React.FC = ({ onSendToBack }) => { return ( - <> -

Selection

+
- +
); }; diff --git a/src/components/panels/PanelTools.tsx b/src/components/panels/PanelTools.tsx index b6345a08..4ab9db1a 100644 --- a/src/components/panels/PanelTools.tsx +++ b/src/components/panels/PanelTools.tsx @@ -2,6 +2,7 @@ import React from "react"; import { SHAPES } from "../../shapes"; import { capitalizeString } from "../../utils"; +import { Panel } from "../Panel"; interface PanelToolsProps { activeTool: string; @@ -13,8 +14,7 @@ export const PanelTools: React.FC = ({ onToolChange }) => { return ( - <> -

Shapes

+
{SHAPES.map(({ value, icon }) => ( ))}
- +
); }; diff --git a/src/index.tsx b/src/index.tsx index 2648d721..6ff867af 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -46,6 +46,7 @@ import { PanelSelection } from "./components/panels/PanelSelection"; import { PanelColor } from "./components/panels/PanelColor"; import { PanelExport } from "./components/panels/PanelExport"; import { PanelCanvas } from "./components/panels/PanelCanvas"; +import { Panel } from "./components/Panel"; import "./styles.scss"; @@ -381,112 +382,110 @@ class App extends React.Component<{}, AppState> { this.forceUpdate(); }} /> - {someElementIsSelected(elements) && ( -
- + + - element.strokeColor - )} - /> - - {hasBackground(elements) && ( - <> - element.backgroundColor - )} - /> - -
Fill
- element.fillStyle - )} - onChange={value => { - this.changeProperty(element => { - element.fillStyle = value; - }); - }} - /> - + element.strokeColor )} + /> - {hasStroke(elements) && ( - <> -
Stroke Width
- element.strokeWidth - )} - onChange={value => { - this.changeProperty(element => { - element.strokeWidth = value; - }); - }} - /> + {hasBackground(elements) && ( + <> + element.backgroundColor + )} + /> -
Sloppiness
- element.roughness - )} - onChange={value => - this.changeProperty(element => { - element.roughness = value; - }) - } - /> - - )} +
Fill
+ element.fillStyle + )} + onChange={value => { + this.changeProperty(element => { + element.fillStyle = value; + }); + }} + /> + + )} -
Opacity
- element.opacity) || - 0 /* Put the opacity at 0 if there are two conflicting ones */ - } - /> + {hasStroke(elements) && ( + <> +
Stroke Width
+ element.strokeWidth + )} + onChange={value => { + this.changeProperty(element => { + element.strokeWidth = value; + }); + }} + /> - -
- )} +
Sloppiness
+ element.roughness + )} + onChange={value => + this.changeProperty(element => { + element.roughness = value; + }) + } + /> + + )} + +
Opacity
+ element.opacity) || + 0 /* Put the opacity at 0 if there are two conflicting ones */ + } + /> + + + diff --git a/src/styles.scss b/src/styles.scss index 969174ea..9652ebac 100644 --- a/src/styles.scss +++ b/src/styles.scss @@ -30,6 +30,27 @@ body { margin: 10px 0 10px 0; } + .panel { + position: relative; + .btn-panel-collapse { + position: absolute; + top: -2px; + right: 5px; + background: none; + margin: 0px; + color: black; + } + + .btn-panel-collapse-icon { + transform: none; + display: inline-block; + } + + .btn-panel-collapse-icon-closed { + transform: rotateZ(90deg); + } + } + .panelTools { display: flex; flex-wrap: wrap;