Make panels collapsible (#239)
* Make panels collapsible - Add Panel component with collapse logic - Use the component in all the necessary panel groups * Remove unnecessary container from PanelCanvas * Add "hide property" to Pane component to hide Panel contents using a prop - Instead of doing conditional rendering, pass the condition to Panel as props * Change collapse icon rotation for closed - Use one icon and use CSS transforms to rotate it * Remove unnecessary imports from PanelSelection
This commit is contained in:
parent
e38f65dea7
commit
36ce6a26e6
43
src/components/Panel.tsx
Normal file
43
src/components/Panel.tsx
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
import React, { useState } from "react";
|
||||||
|
|
||||||
|
interface PanelProps {
|
||||||
|
title: string;
|
||||||
|
defaultCollapsed?: boolean;
|
||||||
|
hide?: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
export const Panel: React.FC<PanelProps> = ({
|
||||||
|
title,
|
||||||
|
children,
|
||||||
|
defaultCollapsed = false,
|
||||||
|
hide = false
|
||||||
|
}) => {
|
||||||
|
const [collapsed, setCollapsed] = useState(defaultCollapsed);
|
||||||
|
|
||||||
|
if (hide) return null;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="panel">
|
||||||
|
<h4>{title}</h4>
|
||||||
|
<button
|
||||||
|
className="btn-panel-collapse"
|
||||||
|
type="button"
|
||||||
|
onClick={e => {
|
||||||
|
e.preventDefault();
|
||||||
|
setCollapsed(collapsed => !collapsed);
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{
|
||||||
|
<span
|
||||||
|
className={`btn-panel-collapse-icon ${
|
||||||
|
collapsed ? "btn-panel-collapse-icon-closed" : ""
|
||||||
|
}`}
|
||||||
|
>
|
||||||
|
▼
|
||||||
|
</span>
|
||||||
|
}
|
||||||
|
</button>
|
||||||
|
{!collapsed && <div className="panelColumn">{children}</div>}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
@ -1,6 +1,7 @@
|
|||||||
import React from "react";
|
import React from "react";
|
||||||
|
|
||||||
import { ColorPicker } from "../ColorPicker";
|
import { ColorPicker } from "../ColorPicker";
|
||||||
|
import { Panel } from "../Panel";
|
||||||
|
|
||||||
interface PanelCanvasProps {
|
interface PanelCanvasProps {
|
||||||
viewBackgroundColor: string;
|
viewBackgroundColor: string;
|
||||||
@ -14,9 +15,7 @@ export const PanelCanvas: React.FC<PanelCanvasProps> = ({
|
|||||||
onClearCanvas
|
onClearCanvas
|
||||||
}) => {
|
}) => {
|
||||||
return (
|
return (
|
||||||
<>
|
<Panel title="Canvas">
|
||||||
<h4>Canvas</h4>
|
|
||||||
<div className="panelColumn">
|
|
||||||
<h5>Canvas Background Color</h5>
|
<h5>Canvas Background Color</h5>
|
||||||
<ColorPicker
|
<ColorPicker
|
||||||
color={viewBackgroundColor}
|
color={viewBackgroundColor}
|
||||||
@ -29,7 +28,6 @@ export const PanelCanvas: React.FC<PanelCanvasProps> = ({
|
|||||||
>
|
>
|
||||||
Clear canvas
|
Clear canvas
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</Panel>
|
||||||
</>
|
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
import React from "react";
|
import React from "react";
|
||||||
import { EditableText } from "../EditableText";
|
import { EditableText } from "../EditableText";
|
||||||
|
import { Panel } from "../Panel";
|
||||||
|
|
||||||
interface PanelExportProps {
|
interface PanelExportProps {
|
||||||
projectName: string;
|
projectName: string;
|
||||||
@ -21,8 +22,7 @@ export const PanelExport: React.FC<PanelExportProps> = ({
|
|||||||
onExportAsPNG
|
onExportAsPNG
|
||||||
}) => {
|
}) => {
|
||||||
return (
|
return (
|
||||||
<>
|
<Panel title="Export">
|
||||||
<h4>Export</h4>
|
|
||||||
<div className="panelColumn">
|
<div className="panelColumn">
|
||||||
<h5>Name</h5>
|
<h5>Name</h5>
|
||||||
{projectName && (
|
{projectName && (
|
||||||
@ -47,6 +47,6 @@ export const PanelExport: React.FC<PanelExportProps> = ({
|
|||||||
<button onClick={onSaveScene}>Save as...</button>
|
<button onClick={onSaveScene}>Save as...</button>
|
||||||
<button onClick={onLoadScene}>Load file...</button>
|
<button onClick={onLoadScene}>Load file...</button>
|
||||||
</div>
|
</div>
|
||||||
</>
|
</Panel>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
@ -14,8 +14,7 @@ export const PanelSelection: React.FC<PanelSelectionProps> = ({
|
|||||||
onSendToBack
|
onSendToBack
|
||||||
}) => {
|
}) => {
|
||||||
return (
|
return (
|
||||||
<>
|
<div>
|
||||||
<h4>Selection</h4>
|
|
||||||
<div className="buttonList">
|
<div className="buttonList">
|
||||||
<button type="button" onClick={onBringForward}>
|
<button type="button" onClick={onBringForward}>
|
||||||
Bring forward
|
Bring forward
|
||||||
@ -30,6 +29,6 @@ export const PanelSelection: React.FC<PanelSelectionProps> = ({
|
|||||||
Send to back
|
Send to back
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
</>
|
</div>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
@ -2,6 +2,7 @@ import React from "react";
|
|||||||
|
|
||||||
import { SHAPES } from "../../shapes";
|
import { SHAPES } from "../../shapes";
|
||||||
import { capitalizeString } from "../../utils";
|
import { capitalizeString } from "../../utils";
|
||||||
|
import { Panel } from "../Panel";
|
||||||
|
|
||||||
interface PanelToolsProps {
|
interface PanelToolsProps {
|
||||||
activeTool: string;
|
activeTool: string;
|
||||||
@ -13,8 +14,7 @@ export const PanelTools: React.FC<PanelToolsProps> = ({
|
|||||||
onToolChange
|
onToolChange
|
||||||
}) => {
|
}) => {
|
||||||
return (
|
return (
|
||||||
<>
|
<Panel title="Shapes">
|
||||||
<h4>Shapes</h4>
|
|
||||||
<div className="panelTools">
|
<div className="panelTools">
|
||||||
{SHAPES.map(({ value, icon }) => (
|
{SHAPES.map(({ value, icon }) => (
|
||||||
<label
|
<label
|
||||||
@ -33,6 +33,6 @@ export const PanelTools: React.FC<PanelToolsProps> = ({
|
|||||||
</label>
|
</label>
|
||||||
))}
|
))}
|
||||||
</div>
|
</div>
|
||||||
</>
|
</Panel>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
@ -46,6 +46,7 @@ import { PanelSelection } from "./components/panels/PanelSelection";
|
|||||||
import { PanelColor } from "./components/panels/PanelColor";
|
import { PanelColor } from "./components/panels/PanelColor";
|
||||||
import { PanelExport } from "./components/panels/PanelExport";
|
import { PanelExport } from "./components/panels/PanelExport";
|
||||||
import { PanelCanvas } from "./components/panels/PanelCanvas";
|
import { PanelCanvas } from "./components/panels/PanelCanvas";
|
||||||
|
import { Panel } from "./components/Panel";
|
||||||
|
|
||||||
import "./styles.scss";
|
import "./styles.scss";
|
||||||
|
|
||||||
@ -381,8 +382,7 @@ class App extends React.Component<{}, AppState> {
|
|||||||
this.forceUpdate();
|
this.forceUpdate();
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
{someElementIsSelected(elements) && (
|
<Panel title="Selection" hide={!someElementIsSelected(elements)}>
|
||||||
<div className="panelColumn">
|
|
||||||
<PanelSelection
|
<PanelSelection
|
||||||
onBringForward={this.moveOneRight}
|
onBringForward={this.moveOneRight}
|
||||||
onBringToFront={this.moveAllRight}
|
onBringToFront={this.moveAllRight}
|
||||||
@ -485,8 +485,7 @@ class App extends React.Component<{}, AppState> {
|
|||||||
<button onClick={this.deleteSelectedElements}>
|
<button onClick={this.deleteSelectedElements}>
|
||||||
Delete selected
|
Delete selected
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</Panel>
|
||||||
)}
|
|
||||||
<PanelCanvas
|
<PanelCanvas
|
||||||
onClearCanvas={this.clearCanvas}
|
onClearCanvas={this.clearCanvas}
|
||||||
onViewBackgroundColorChange={val =>
|
onViewBackgroundColorChange={val =>
|
||||||
|
@ -30,6 +30,27 @@ body {
|
|||||||
margin: 10px 0 10px 0;
|
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 {
|
.panelTools {
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-wrap: wrap;
|
flex-wrap: wrap;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user