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 2] Move panel toggles to control headers #1708

Closed
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
46 changes: 32 additions & 14 deletions src/components/controls/panel-toggle.tsx
Original file line number Diff line number Diff line change
@@ -1,31 +1,49 @@
// A slider toggle to adjust the state of a panel via dispatch.
// A textual toggle to adjust the state of a panel via dispatch.

import React from "react";
import { useDispatch } from "react-redux";
import styled from 'styled-components';

import Toggle from "./toggle";
import { togglePanelDisplay } from "../../actions/panelDisplay";

type Props = {
panel: string
on: boolean
}

const Text = styled.span`
font-size: 14px;
cursor: pointer;
padding: 0 3px;
`;

const TextSelected = styled(Text)`
color: ${(props) => props.theme.selectedColor};
`;

const TextUnselected = styled(Text)`
color: ${(props) => props.theme.unselectedColor};
`;

const PanelToggle = ({ panel, on }: Props) => {
const dispatch = useDispatch();

// There is no slider label since the title in the annotated header acts as a
// visual label.
// FIXME: Add a hidden label?

return (
<Toggle
display={true}
on={on}
callback={() => dispatch(togglePanelDisplay(panel))}
label=""
/>
);
if (on) {
return (
<div>
<TextSelected>ON</TextSelected>
<TextUnselected onClick={() => dispatch(togglePanelDisplay(panel))}>OFF</TextUnselected>
</div>
)
}
else {
return (
<div>
<TextUnselected onClick={() => dispatch(togglePanelDisplay(panel))}>ON</TextUnselected>
<TextSelected>OFF</TextSelected>
</div>
)
}
};

export default PanelToggle;
Loading