Skip to content

Commit

Permalink
feat: Setup colours via theme
Browse files Browse the repository at this point in the history
  • Loading branch information
DafyddLlyr committed Oct 8, 2024
1 parent 70e2770 commit aad2b5b
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 20 deletions.
2 changes: 1 addition & 1 deletion editor.planx.uk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"@mui/material": "^5.15.10",
"@mui/utils": "^5.15.11",
"@opensystemslab/map": "1.0.0-alpha.3",
"@opensystemslab/planx-core": "git+https://github.com/theopensystemslab/planx-core#c19c3be",
"@opensystemslab/planx-core": "git+https://github.com/theopensystemslab/planx-core#0ade7fa",
"@tiptap/core": "^2.4.0",
"@tiptap/extension-bold": "^2.0.3",
"@tiptap/extension-bubble-menu": "^2.1.13",
Expand Down
10 changes: 5 additions & 5 deletions editor.planx.uk/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import Box from "@mui/material/Box";
import { PaletteOptions, useTheme } from "@mui/material/styles";
import { NodeTag } from "@opensystemslab/planx-core/types";
import { useStore } from "pages/FlowEditor/lib/store";
import React from "react";
Expand All @@ -7,46 +8,50 @@ import { FONT_WEIGHT_SEMI_BOLD } from "theme";

export const TAG_DISPLAY_VALUES: Record<
NodeTag,
{ color: string; displayName: string }
{ color: keyof PaletteOptions["nodeTag"]; displayName: string }
> = {
placeholder: {
color: "#FAE1B7",
color: "blocking",
displayName: "Placeholder",
},
"to review": {
color: "#E9EDC9",
toReview: {
color: "nonBlocking",
displayName: "To review",
},
"sensitive data": {
color: "#F4978E",
sensitiveData: {
color: "information",
displayName: "Sensitive data",
},
analytics: {
color: "#E9EDC9",
color: "information",
displayName: "Analytics",
},
automation: {
color: "#E9EDC9",
color: "information",
displayName: "Automation",
},
} as const;

export const Tag: React.FC<{ tag: NodeTag }> = ({ tag }) => {
const theme = useTheme();

const showTags = useStore((state) => state.showTags);
if (!showTags) return null;

const tagBgColor = theme.palette.nodeTag[TAG_DISPLAY_VALUES[tag].color];

return (
<Box
sx={(theme) => ({
bgcolor: TAG_DISPLAY_VALUES[tag].color,
bgcolor: tagBgColor,
borderColor: theme.palette.common.black,
borderWidth: "0 1px 1px 1px",
borderStyle: "solid",
width: "100%",
p: 0.5,
textAlign: "center",
fontWeight: FONT_WEIGHT_SEMI_BOLD,
color: getContrastTextColor(TAG_DISPLAY_VALUES[tag].color, "#FFF"),
color: getContrastTextColor(tagBgColor, "#FFF"),
})}
>
{TAG_DISPLAY_VALUES[tag].displayName}
Expand Down
5 changes: 5 additions & 0 deletions editor.planx.uk/src/theme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,11 @@ const DEFAULT_PALETTE: Partial<PaletteOptions> = {
input: "#0B0C0C",
light: "#E0E0E0",
},
nodeTag: {
blocking: "#F4978E",
nonBlocking: "#B7FAD7",
information: "#FAE1B7",
},
tonalOffset: DEFAULT_TONAL_OFFSET,
};

Expand Down
2 changes: 2 additions & 0 deletions editor.planx.uk/src/themeOverrides.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ declare module "@mui/material/styles/createPalette" {
border: { main: string; input: string; light: string };
link: { main: string };
prompt: { main: string; contrastText: string; light: string; dark: string };
nodeTag: { nonBlocking: string; blocking: string; information: string };
}

interface PaletteOptions {
Expand All @@ -43,6 +44,7 @@ declare module "@mui/material/styles/createPalette" {
light: string;
dark: string;
};
nodeTag?: { nonBlocking: string; blocking: string; information: string };
}

interface TypeText {
Expand Down
11 changes: 7 additions & 4 deletions editor.planx.uk/src/ui/editor/ComponentTagSelect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,13 @@ const renderTags: AutocompleteProps<
{...getTagProps({ index })}
key={tag}
label={TAG_DISPLAY_VALUES[tag].displayName}
sx={{
backgroundColor: TAG_DISPLAY_VALUES[tag].color,
color: getContrastTextColor(TAG_DISPLAY_VALUES[tag].color, "#FFF"),
}}
sx={(theme) => ({
backgroundColor: theme.palette.nodeTag[TAG_DISPLAY_VALUES[tag].color],
color: getContrastTextColor(
theme.palette.nodeTag[TAG_DISPLAY_VALUES[tag].color],
"#FFF",
),
})}
/>
));

Expand Down

0 comments on commit aad2b5b

Please sign in to comment.