From 554bf41d507cc40f8dd140e8f408c1680a68b4ec Mon Sep 17 00:00:00 2001
From: Victor Lin <13424970+victorlin@users.noreply.github.com>
Date: Wed, 18 Oct 2023 15:59:30 -0700
Subject: [PATCH] Add ability to show/hide options when panel is on
---
src/components/controls/panelChevron.tsx | 25 ++++++++++++++++++
src/components/controls/panelHeader.tsx | 33 ++++++++++++++++++++----
src/components/controls/panelSection.tsx | 13 +++++++++-
3 files changed, 65 insertions(+), 6 deletions(-)
create mode 100644 src/components/controls/panelChevron.tsx
diff --git a/src/components/controls/panelChevron.tsx b/src/components/controls/panelChevron.tsx
new file mode 100644
index 000000000..520a99fce
--- /dev/null
+++ b/src/components/controls/panelChevron.tsx
@@ -0,0 +1,25 @@
+import React from "react";
+import styled from 'styled-components';
+import { FaChevronRight, FaChevronDown } from "react-icons/fa";
+
+const Container = styled.span`
+ padding-right: 6px;
+ color: ${(props) => props.theme.color};
+`
+
+type Props = {
+ show: boolean
+}
+
+/**
+ * An interactive chevron to show/hide a panel's options.
+ */
+export const PanelChevron = ({ show }: Props) => {
+ const icon = show ? :
+
+ return (
+
+ {icon}
+
+ )
+}
diff --git a/src/components/controls/panelHeader.tsx b/src/components/controls/panelHeader.tsx
index faa1cd100..15ace4626 100644
--- a/src/components/controls/panelHeader.tsx
+++ b/src/components/controls/panelHeader.tsx
@@ -2,6 +2,7 @@ import React from "react";
import { HeaderContainer } from "./styles";
import { PanelToggle, Panel, On } from "./panelToggle";
import { AnnotatedTitle, Mobile, Title, Tooltip } from "./annotatedTitle";
+import { PanelChevron } from "./panelChevron";
type Props = {
panel: Panel
@@ -9,18 +10,40 @@ type Props = {
tooltip?: Tooltip
panelIsVisible: On
mobile: Mobile
+
+ /** Indicates whether there are options for the panel. */
+ hasOptions: boolean
+
+ /** Indicates options visibility. */
+ optionsAreVisible: boolean
+
+ /** Update options visibility. */
+ setOptionsAreVisible: React.Dispatch>
}
/**
* A header used by all panel controls, containing an interactive title.
*/
-export const PanelHeader = ({ panel, title, tooltip, panelIsVisible, mobile }: Props) => {
+export const PanelHeader = ({ panel, title, tooltip, panelIsVisible, hasOptions, optionsAreVisible, setOptionsAreVisible, mobile }: Props) => {
+
+ let titleContainerProps = {}
+
+ if (hasOptions) {
+ titleContainerProps = {
+ role: "button",
+ onClick: () => setOptionsAreVisible(!optionsAreVisible),
+ }
+ }
+
return (
-
+
+ {hasOptions && }
+
+
diff --git a/src/components/controls/panelSection.tsx b/src/components/controls/panelSection.tsx
index 173a67ef1..019e796a3 100644
--- a/src/components/controls/panelSection.tsx
+++ b/src/components/controls/panelSection.tsx
@@ -25,6 +25,14 @@ export const PanelSection = ({ panel, title, tooltip, options=undefined, mobile
const panelIsVisible = panelsToDisplay.includes(panel)
+ // Initially, panel visibility determines options visibility.
+ const [optionsAreVisible, setOptionsAreVisible] = React.useState(panelIsVisible);
+
+ // Subsequent panel visibility updates also determines options visibility.
+ React.useEffect(() => {
+ setOptionsAreVisible(panelIsVisible)
+ }, [panelIsVisible])
+
return (
- {panelIsVisible && options}
+ {optionsAreVisible && options}
);
};