Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[preview 3] Redesign panel sections in sidebar #1719

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 0 additions & 33 deletions src/components/controls/panelChevron.tsx

This file was deleted.

32 changes: 4 additions & 28 deletions src/components/controls/panelHeader.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
import React from "react";
import { useSelector } from "react-redux";
import { RootState } from "../../store";
import { useAppDispatch } from "../../hooks";
import { togglePanelDisplay } from "../../actions/panelDisplay";
import { HeaderContainer } from "./styles";
import { PanelToggle, On } from "./panelToggle";
import { AnnotatedTitle, Title, Tooltip } from "./annotatedTitle";
import { PanelChevron } from "./panelChevron";

/** Panel identifier used internally. */
export type PanelId = string;
Expand All @@ -16,45 +13,24 @@ type Props = {
title: Title
tooltip?: Tooltip
panelIsVisible: On

/** Indicates whether there are options for the panel. */
hasOptions: boolean

/** Indicates options visibility. */
optionsAreVisible: boolean

/** Update options visibility. */
setOptionsAreVisible: React.Dispatch<React.SetStateAction<boolean>>
}

/**
* A header used by all panel controls, containing an interactive title.
*/
export const PanelHeader = ({ panel, title, tooltip, panelIsVisible, hasOptions, optionsAreVisible, setOptionsAreVisible }: Props) => {
export const PanelHeader = ({ panel, title, tooltip, panelIsVisible }: Props) => {
const dispatch = useAppDispatch();

const mobile = useSelector((state: RootState) => state.general.mobileDisplay);

function togglePanelVisibility() {
dispatch(togglePanelDisplay(panel))
}

function toggleOptionsVisibility() {
setOptionsAreVisible(!optionsAreVisible);
}

return (
// Clicking anywhere in the element, even whitespace, will toggle panel visibility.
<HeaderContainer onClick={togglePanelVisibility}>
<span>
{hasOptions && !mobile &&
<PanelChevron
show={optionsAreVisible}
onClick={toggleOptionsVisibility} />}
<AnnotatedTitle
title={title}
tooltip={tooltip} />
</span>
<AnnotatedTitle
title={title}
tooltip={tooltip} />
<PanelToggle
on={panelIsVisible}
callback={(togglePanelVisibility)} />
Expand Down
13 changes: 1 addition & 12 deletions src/components/controls/panelSection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,26 +23,15 @@ export const PanelSection = ({ panel, title, tooltip, options=undefined }: 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
panel={panel}
title={title}
tooltip={tooltip}
panelIsVisible={panelIsVisible}
hasOptions={options!==undefined}
optionsAreVisible={optionsAreVisible}
setOptionsAreVisible={setOptionsAreVisible}
/>
{optionsAreVisible && options}
{panelIsVisible && options}
</PanelSectionContainer>
);
};
2 changes: 1 addition & 1 deletion src/components/controls/styles.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export const PanelSectionContainer = styled.div`
`;

export const TitleAndIconContainer = styled.span`
display: inline-flex;
display: flex;
align-items: center;
`;

Expand Down