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

feat: Environment dependant header chip styling #3717

Merged
merged 3 commits into from
Sep 23, 2024
Merged
Changes from 2 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
21 changes: 21 additions & 0 deletions editor.planx.uk/src/components/Header.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import Edit from "@mui/icons-material/Edit";
import KeyboardArrowDown from "@mui/icons-material/KeyboardArrowDown";
import MenuOpenIcon from "@mui/icons-material/MenuOpen";
import OpenInNewIcon from "@mui/icons-material/OpenInNew";
import OpenInNewOffIcon from "@mui/icons-material/OpenInNewOff";
import Person from "@mui/icons-material/Person";
import Visibility from "@mui/icons-material/Visibility";
import AppBar from "@mui/material/AppBar";
import Avatar from "@mui/material/Avatar";
import Box from "@mui/material/Box";
import Chip from "@mui/material/Chip";
import { grey } from "@mui/material/colors";
import Container from "@mui/material/Container";
import IconButton from "@mui/material/IconButton";
Expand Down Expand Up @@ -172,6 +175,8 @@ const SkipLink = styled("a")(({ theme }) => ({

const ServiceTitleRoot = styled("span")(({ theme }) => ({
display: "flex",
alignItems: "center",
gap: theme.spacing(1),
flexGrow: 1,
flexShrink: 1,
lineHeight: LINE_HEIGHT_BASE,
Expand Down Expand Up @@ -428,9 +433,25 @@ const PublicToolbar: React.FC<{

const ServiceTitle: React.FC = () => {
const flowName = useStore((state) => state.flowName);
const route = useCurrentRoute();
const path = route.url.pathname.split("/").slice(-1)[0];

return (
<ServiceTitleRoot data-testid="service-title">
{(path === "preview" || path === "draft") && (
<Chip
label={capitalize(path)}
variant="notApplicableTag"
size="medium"
icon={
path === "preview" ? (
<OpenInNewIcon fontSize="small" />
) : (
<OpenInNewOffIcon fontSize="small" />
)
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
icon={
path === "preview" ? (
<OpenInNewIcon fontSize="small" />
) : (
<OpenInNewOffIcon fontSize="small" />
)
}
icon={{
preview: <OpenInNewIcon fontSize="small" />
draft: <OpenInNewOffIcon fontSize="small" />
}[path]}
}

Maybe a little clearer and more expandable?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @DafyddLlyr , I see a recurring theme here — my first instinct to use boolean / ternary operators vs expandable list based code.

/>
)}
<Typography component="span" variant="h4">
{flowName}
</Typography>
Expand Down
Loading