From a120cd4ad289119cd66a88cd4a2e4f8a68c61839 Mon Sep 17 00:00:00 2001 From: Gasim Gasimzada Date: Wed, 8 Jan 2020 11:39:09 +0400 Subject: [PATCH] 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 --- src/components/Panel.tsx | 7 +- src/index.tsx | 198 +++++++++++++++++++-------------------- 2 files changed, 104 insertions(+), 101 deletions(-) diff --git a/src/components/Panel.tsx b/src/components/Panel.tsx index 4ecbe3fbb..ecb3638c0 100644 --- a/src/components/Panel.tsx +++ b/src/components/Panel.tsx @@ -3,14 +3,19 @@ import React, { useState } from "react"; interface PanelProps { title: string; defaultCollapsed?: boolean; + hide?: boolean; } export const Panel: React.FC = ({ title, children, - defaultCollapsed = false + defaultCollapsed = false, + hide = false }) => { const [collapsed, setCollapsed] = useState(defaultCollapsed); + + if (hide) return null; + return (

{title}

diff --git a/src/index.tsx b/src/index.tsx index 691ac16f0..d4ad3d5ef 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -381,112 +381,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 */ + } + /> + + +