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 7138675 commit c9e4480
Show file tree
Hide file tree
Showing 3 changed files with 56 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: ${(props) => props.theme.color};
`

type Props = {
show: boolean
}

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

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

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

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 (
<HeaderContainer>
<AnnotatedTitle
title={title}
tooltip={tooltip}
mobile={mobile} />
<span {...titleContainerProps}>
{hasOptions && <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 @@ -20,6 +20,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 (
<PanelSectionContainer>
<PanelHeader
Expand All @@ -28,8 +36,11 @@ export const PanelSection = ({ panel, title, tooltip, options=undefined, mobile
tooltip={tooltip}
panelIsVisible={panelIsVisible}
mobile={mobile}
hasOptions={options!==undefined}
optionsAreVisible={optionsAreVisible}
setOptionsAreVisible={setOptionsAreVisible}
/>
{panelIsVisible && options}
{optionsAreVisible && options}
</PanelSectionContainer>
);
};

0 comments on commit c9e4480

Please sign in to comment.