Skip to content

Commit

Permalink
Add ability to show/hide options when panel is on
Browse files Browse the repository at this point in the history
  • Loading branch information
victorlin committed Oct 19, 2023
1 parent fe65a35 commit 705b64c
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 6 deletions.
22 changes: 22 additions & 0 deletions src/components/controls/panelChevron.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import React from "react";
import styled from 'styled-components';
import { FaChevronRight, FaChevronDown } from "react-icons/fa";

const Container = styled.span`
padding-right: 6px;
color: white;
`

type Props = {
show: boolean
}

export const PanelChevron = ({ show }: Props) => {
const icon = show ? <FaChevronDown /> : <FaChevronRight />

return (
<Container>
{icon}
</Container>
)
}
16 changes: 11 additions & 5 deletions src/components/controls/panelHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,28 @@ import React from "react";
import { HeaderContainer } from "./styles";
import PanelToggle from "./panel-toggle";
import { AnnotatedTitle } from "./annotatedTitle";
import { PanelChevron } from "./panelChevron";

type Props = {
panel: string
title: string
panelIsVisible: boolean
tooltip: JSX.Element
optionsAreVisible: boolean
setOptionsAreVisible: React.Dispatch<React.SetStateAction<boolean>>
mobile: boolean
}

export const PanelHeader = ({ panel, title, panelIsVisible, tooltip, mobile }: Props) => {
export const PanelHeader = ({ panel, title, panelIsVisible, tooltip, optionsAreVisible, setOptionsAreVisible, mobile }: Props) => {
return (
<HeaderContainer>
<AnnotatedTitle
title={title}
tooltip={tooltip}
mobile={mobile} />
<span onClick={() => setOptionsAreVisible(!optionsAreVisible)}>
<PanelChevron show={optionsAreVisible} />
<AnnotatedTitle
title={title}
tooltip={tooltip}
mobile={mobile} />
</span>
<PanelToggle
panel={panel}
on={panelIsVisible} />
Expand Down
13 changes: 12 additions & 1 deletion src/components/controls/panelSection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { PanelSectionContainer } from "./styles";
import { PanelHeader } from "./panelHeader";
import { RootState } from "../../store";


type Props = {
panel: string
title: string
Expand All @@ -18,6 +19,14 @@ export const PanelSection = ({ panel, title, tooltip, options, mobile }: Props)

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 (
<PanelSectionContainer>
<PanelHeader
Expand All @@ -26,8 +35,10 @@ export const PanelSection = ({ panel, title, tooltip, options, mobile }: Props)
title={title}
tooltip={tooltip}
mobile={mobile}
optionsAreVisible={optionsAreVisible}
setOptionsAreVisible={setOptionsAreVisible}
/>
{panelIsVisible && options}
{optionsAreVisible && options}
</PanelSectionContainer>
);
};

0 comments on commit 705b64c

Please sign in to comment.