mirror of
https://github.com/excalidraw/excalidraw.git
synced 2025-05-03 10:00:07 -04:00
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
This commit is contained in:
parent
c46765382b
commit
a120cd4ad2
2 changed files with 104 additions and 101 deletions
|
@ -3,14 +3,19 @@ import React, { useState } from "react";
|
||||||
interface PanelProps {
|
interface PanelProps {
|
||||||
title: string;
|
title: string;
|
||||||
defaultCollapsed?: boolean;
|
defaultCollapsed?: boolean;
|
||||||
|
hide?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const Panel: React.FC<PanelProps> = ({
|
export const Panel: React.FC<PanelProps> = ({
|
||||||
title,
|
title,
|
||||||
children,
|
children,
|
||||||
defaultCollapsed = false
|
defaultCollapsed = false,
|
||||||
|
hide = false
|
||||||
}) => {
|
}) => {
|
||||||
const [collapsed, setCollapsed] = useState(defaultCollapsed);
|
const [collapsed, setCollapsed] = useState(defaultCollapsed);
|
||||||
|
|
||||||
|
if (hide) return null;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="panel">
|
<div className="panel">
|
||||||
<h4>{title}</h4>
|
<h4>{title}</h4>
|
||||||
|
|
|
@ -381,8 +381,7 @@ class App extends React.Component<{}, AppState> {
|
||||||
this.forceUpdate();
|
this.forceUpdate();
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
{someElementIsSelected(elements) && (
|
<Panel title="Selection" hide={!someElementIsSelected(elements)}>
|
||||||
<Panel title="Selection">
|
|
||||||
<PanelSelection
|
<PanelSelection
|
||||||
onBringForward={this.moveOneRight}
|
onBringForward={this.moveOneRight}
|
||||||
onBringToFront={this.moveAllRight}
|
onBringToFront={this.moveAllRight}
|
||||||
|
@ -486,7 +485,6 @@ class App extends React.Component<{}, AppState> {
|
||||||
Delete selected
|
Delete selected
|
||||||
</button>
|
</button>
|
||||||
</Panel>
|
</Panel>
|
||||||
)}
|
|
||||||
<PanelCanvas
|
<PanelCanvas
|
||||||
onClearCanvas={this.clearCanvas}
|
onClearCanvas={this.clearCanvas}
|
||||||
onViewBackgroundColorChange={val =>
|
onViewBackgroundColorChange={val =>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue