From c8f8bce7e4ce802962bfeb5b9b11719c91e25301 Mon Sep 17 00:00:00 2001 From: Ian Jones Date: Tue, 23 Apr 2024 12:40:12 +0100 Subject: [PATCH] feat: React states for sidebar tabs --- .../FlowEditor/components/PreviewBrowser.tsx | 42 ++++++++++++++----- 1 file changed, 31 insertions(+), 11 deletions(-) diff --git a/editor.planx.uk/src/pages/FlowEditor/components/PreviewBrowser.tsx b/editor.planx.uk/src/pages/FlowEditor/components/PreviewBrowser.tsx index dd12b5ba6f..e0b01cfce5 100644 --- a/editor.planx.uk/src/pages/FlowEditor/components/PreviewBrowser.tsx +++ b/editor.planx.uk/src/pages/FlowEditor/components/PreviewBrowser.tsx @@ -8,6 +8,7 @@ import Badge from "@mui/material/Badge"; import Box from "@mui/material/Box"; import Button from "@mui/material/Button"; import Collapse from "@mui/material/Collapse"; +import Container from "@mui/material/Container"; import Dialog from "@mui/material/Dialog"; import DialogActions from "@mui/material/DialogActions"; import DialogContent from "@mui/material/DialogContent"; @@ -18,7 +19,7 @@ import List from "@mui/material/List"; import ListItem from "@mui/material/ListItem"; import ListItemText from "@mui/material/ListItemText"; import { styled } from "@mui/material/styles"; -import Tab from '@mui/material/Tab'; +import Tab, { tabClasses } from '@mui/material/Tab'; import Tabs from '@mui/material/Tabs'; import Tooltip from "@mui/material/Tooltip"; import Typography from "@mui/material/Typography"; @@ -55,7 +56,7 @@ const EmbeddedBrowser = styled(Box)(({ theme }) => ({ }, })); -const PreviewContainer = styled(Box)(() => ({ +const SidebarContainer = styled(Box)(() => ({ overflow: "auto", flex: 1, background: "#fff", @@ -93,6 +94,10 @@ const TabList = styled(Box)(({ theme }) => ({ "& .MuiTabs-root": { minHeight: "0", }, + // Hide default MUI indicator as we're using custom styling + "& .MuiTabs-indicator": { + display: "none", + }, })); @@ -109,13 +114,12 @@ const StyledTab = styled(Tab)(({ theme }) => ({ margin: theme.spacing(0, 0.5), marginBottom: "-1px", padding: "0.5em", - // Using as placeholder stying for active/current tab - "&[data-state='active']": { + [`&.${tabClasses.selected}`]: { background: theme.palette.background.default, borderColor: theme.palette.border.main, borderBottomColor: theme.palette.common.white, color: theme.palette.text.primary, - }, + }, })) as typeof Tab; @@ -156,6 +160,8 @@ interface AlteredNode { data?: any; } +type SideBarTabs = "PreviewBrowser" | "History" + const AlteredNodeListItem = (props: { node: AlteredNode }) => { const { node } = props; let text, data; @@ -388,6 +394,11 @@ const PreviewBrowser: React.FC<{ const [alteredNodes, setAlteredNodes] = useState(); const [dialogOpen, setDialogOpen] = useState(false); const [summary, setSummary] = useState(); + const [activeTab, setActiveTab] = useState("PreviewBrowser"); + + const handleChange = (event: React.SyntheticEvent, newValue: SideBarTabs) => { + setActiveTab(newValue); + }; const _lastPublishedRequest = useAsync(async () => { const date = await lastPublished(flowId); @@ -618,14 +629,23 @@ const PreviewBrowser: React.FC<{ - - - + + + - - - + {activeTab === "PreviewBrowser" && + + + + } + {activeTab === "History" && + + +

History

+
+
+ } {showDebugConsole && } );