Skip to content

Commit

Permalink
theme
Browse files Browse the repository at this point in the history
  • Loading branch information
florianbgt committed Oct 26, 2024
1 parent e356332 commit 6a3e5d8
Show file tree
Hide file tree
Showing 10 changed files with 188 additions and 55 deletions.
20 changes: 8 additions & 12 deletions packages/app/src/components/ApiTree/ApiTree.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export default function ApiTree(props: {

const reactFlow = useReactFlow();

const [currentZoom, setCurrentZoom] = useState(1);
const [currentZoom, setCurrentZoom] = useState<number>(reactFlow.getZoom());

const [nodes, setNodes, onNodesChange] = useNodesState<Node>([]);
const [edges, setEdges] = useEdgesState<Edge>([]);
Expand Down Expand Up @@ -177,10 +177,6 @@ export default function ApiTree(props: {
setEdges(layoutedEdges);
}

function getCurrentZoom() {
setCurrentZoom(reactFlow.getZoom());
}

useEffect(() => {
const element = document.querySelector(".react-flow__panel") as HTMLElement;
if (element) {
Expand All @@ -196,11 +192,11 @@ export default function ApiTree(props: {
edges={edges}
onNodesChange={onNodesChange}
fitView
onResize={getCurrentZoom} // TODO fix this, does not work
onViewportChange={() => setCurrentZoom(reactFlow.getZoom())} // TODO fix this, does not work
>
<div className="absolute bottom-4 inset-x-4 z-10 flex justify-around">
<div className="flex gap-5 items-center">
<div className="bg-background-dark flex gap-4 p-2 rounded-xl">
<div className="bg-background-light dark:bg-background-dark flex gap-4 p-2 rounded-xl">
<Button
size="1"
variant="ghost"
Expand Down Expand Up @@ -245,7 +241,7 @@ export default function ApiTree(props: {
viewBox="0 0 20 20"
fill="currentColor"
xmlns="http://www.w3.org/2000/svg"
className="text-text-dark"
className="text-text-light dark:text-text-dark"
>
<path d="M15.8334 19.9999H14.1667C13.9457 19.9999 13.7337 19.9121 13.5775 19.7558C13.4212 19.5996 13.3334 19.3876 13.3334 19.1666C13.3334 18.9456 13.4212 18.7336 13.5775 18.5773C13.7337 18.421 13.9457 18.3333 14.1667 18.3333H15.8334C16.4964 18.3333 17.1323 18.0699 17.6011 17.601C18.07 17.1322 18.3334 16.4963 18.3334 15.8333V14.1666C18.3334 13.9456 18.4212 13.7336 18.5775 13.5773C18.7337 13.421 18.9457 13.3333 19.1667 13.3333C19.3877 13.3333 19.5997 13.421 19.756 13.5773C19.9122 13.7336 20 13.9456 20 14.1666V15.8333C19.9987 16.9379 19.5593 17.997 18.7782 18.7781C17.9971 19.5592 16.938 19.9986 15.8334 19.9999Z" />
<path d="M0.833333 6.66667C0.61232 6.66667 0.400358 6.57887 0.244078 6.42259C0.0877974 6.26631 0 6.05435 0 5.83333V4.16667C0.00132321 3.062 0.440735 2.00296 1.22185 1.22185C2.00296 0.440735 3.062 0.00132321 4.16667 0L5.83333 0C6.05435 0 6.26631 0.0877974 6.42259 0.244078C6.57887 0.400358 6.66667 0.61232 6.66667 0.833333C6.66667 1.05435 6.57887 1.26631 6.42259 1.42259C6.26631 1.57887 6.05435 1.66667 5.83333 1.66667H4.16667C3.50363 1.66667 2.86774 1.93006 2.3989 2.3989C1.93006 2.86774 1.66667 3.50363 1.66667 4.16667V5.83333C1.66667 6.05435 1.57887 6.26631 1.42259 6.42259C1.26631 6.57887 1.05435 6.66667 0.833333 6.66667Z" />
Expand All @@ -266,7 +262,7 @@ export default function ApiTree(props: {
viewBox="0 0 24 24"
xmlns="http://www.w3.org/2000/svg"
fill="currentColor"
className="text-text-dark"
className="text-text-light dark:text-text-dark"
>
<path d="M15 3c.552 0 1 .448 1 1v4c0 .552-.448 1-1 1h-2v2h4c.552 0 1 .448 1 1v3h2c.552 0 1 .448 1 1v4c0 .552-.448 1-1 1h-6c-.552 0-1-.448-1-1v-4c0-.552.448-1 1-1h2v-2H8v2h2c.552 0 1 .448 1 1v4c0 .552-.448 1-1 1H4c-.552 0-1-.448-1-1v-4c0-.552.448-1 1-1h2v-3c0-.552.448-1 1-1h4V9H9c-.552 0-1-.448-1-1V4c0-.552.448-1 1-1h6zM9 17H5v2h4v-2zm10 0h-4v2h4v-2zM14 5h-4v2h4V5z"></path>{" "}
</svg>
Expand All @@ -284,13 +280,13 @@ export default function ApiTree(props: {
viewBox="0 0 20 20"
fill="currentColor"
xmlns="http://www.w3.org/2000/svg"
className="text-text-dark"
className="text-text-light dark:text-text-dark"
>
<path d="M19.7559 18.5774L14.7817 13.6033C16.1373 11.9454 16.8037 9.83002 16.6433 7.69458C16.4828 5.55913 15.5077 3.56705 13.9197 2.13037C12.3317 0.693699 10.2522 -0.0776494 8.11143 -0.0241229C5.97064 0.0294036 3.93232 0.90371 2.41807 2.41795C0.903832 3.93219 0.0295257 5.97052 -0.0240008 8.11131C-0.0775274 10.2521 0.693821 12.3316 2.1305 13.9196C3.56717 15.5076 5.55926 16.4827 7.6947 16.6431C9.83014 16.8036 11.9456 16.1371 13.6034 14.7816L18.5776 19.7558C18.7347 19.9076 18.9452 19.9916 19.1637 19.9897C19.3822 19.9878 19.5912 19.9001 19.7457 19.7456C19.9003 19.5911 19.9879 19.3821 19.9898 19.1636C19.9917 18.9451 19.9077 18.7346 19.7559 18.5774ZM8.3334 14.9999C7.01485 14.9999 5.72592 14.6089 4.62959 13.8764C3.53327 13.1439 2.67878 12.1027 2.1742 10.8845C1.66961 9.66632 1.53759 8.32588 1.79483 7.03267C2.05206 5.73947 2.687 4.55158 3.61935 3.61923C4.5517 2.68688 5.73959 2.05194 7.03279 1.79471C8.326 1.53747 9.66644 1.66949 10.8846 2.17408C12.1028 2.67866 13.144 3.53314 13.8765 4.62947C14.6091 5.7258 15.0001 7.01473 15.0001 8.33327C14.9981 10.1008 14.2951 11.7953 13.0452 13.0451C11.7954 14.2949 10.1009 14.998 8.3334 14.9999Z" />
<path d="M10.8333 7.5H5.83333C5.61232 7.5 5.40036 7.5878 5.24408 7.74408C5.0878 7.90036 5 8.11232 5 8.33333C5 8.55435 5.0878 8.76631 5.24408 8.92259C5.40036 9.07887 5.61232 9.16667 5.83333 9.16667H10.8333C11.0543 9.16667 11.2663 9.07887 11.4226 8.92259C11.5789 8.76631 11.6667 8.55435 11.6667 8.33333C11.6667 8.11232 11.5789 7.90036 11.4226 7.74408C11.2663 7.5878 11.0543 7.5 10.8333 7.5Z" />
</svg>
</Button>
<div>{currentZoom.toFixed(2)}x</div>
<div>{(currentZoom * 100).toFixed(0)}%</div>
<Button
size="1"
variant="ghost"
Expand All @@ -304,7 +300,7 @@ export default function ApiTree(props: {
viewBox="0 0 20 20"
fill="currentColor"
xmlns="http://www.w3.org/2000/svg"
className="text-text-dark"
className="text-text-light dark:text-text-dark"
>
<path d="M19.7559 18.5774L14.7817 13.6033C16.1373 11.9454 16.8037 9.83002 16.6433 7.69458C16.4828 5.55913 15.5077 3.56705 13.9197 2.13037C12.3317 0.693699 10.2522 -0.0776494 8.11143 -0.0241229C5.97064 0.0294036 3.93232 0.90371 2.41807 2.41795C0.903832 3.93219 0.0295257 5.97052 -0.0240008 8.11131C-0.0775274 10.2521 0.693821 12.3316 2.1305 13.9196C3.56717 15.5076 5.55926 16.4827 7.6947 16.6431C9.83014 16.8036 11.9456 16.1371 13.6034 14.7816L18.5776 19.7558C18.7347 19.9076 18.9452 19.9916 19.1637 19.9897C19.3822 19.9878 19.5912 19.9001 19.7457 19.7456C19.9003 19.5911 19.9879 19.3821 19.9898 19.1636C19.9917 18.9451 19.9077 18.7346 19.7559 18.5774ZM8.3334 14.9999C7.01485 14.9999 5.72592 14.6089 4.62959 13.8764C3.53327 13.1439 2.67878 12.1027 2.1742 10.8845C1.66961 9.66632 1.53759 8.32588 1.79483 7.03267C2.05206 5.73947 2.687 4.55158 3.61935 3.61923C4.5517 2.68688 5.73959 2.05194 7.03279 1.79471C8.326 1.53747 9.66644 1.66949 10.8846 2.17408C12.1028 2.67866 13.144 3.53314 13.8765 4.62947C14.6091 5.7258 15.0001 7.01473 15.0001 8.33327C14.9981 10.1008 14.2951 11.7953 13.0452 13.0451C11.7954 14.2949 10.1009 14.998 8.3334 14.9999Z" />
<path d="M10.8333 7.5H9.16667V5.83333C9.16667 5.61232 9.07887 5.40036 8.92259 5.24408C8.76631 5.0878 8.55435 5 8.33333 5C8.11232 5 7.90036 5.0878 7.74408 5.24408C7.5878 5.40036 7.5 5.61232 7.5 5.83333V7.5H5.83333C5.61232 7.5 5.40036 7.5878 5.24408 7.74408C5.0878 7.90036 5 8.11232 5 8.33333C5 8.55435 5.0878 8.76631 5.24408 8.92259C5.40036 9.07887 5.61232 9.16667 5.83333 9.16667H7.5V10.8333C7.5 11.0543 7.5878 11.2663 7.74408 11.4226C7.90036 11.5789 8.11232 11.6667 8.33333 11.6667C8.55435 11.6667 8.76631 11.5789 8.92259 11.4226C9.07887 11.2663 9.16667 11.0543 9.16667 10.8333V9.16667H10.8333C11.0543 9.16667 11.2663 9.07887 11.4226 8.92259C11.5789 8.76631 11.6667 8.55435 11.6667 8.33333C11.6667 8.11232 11.5789 7.90036 11.4226 7.74408C11.2663 7.5878 11.0543 7.5 10.8333 7.5Z" />
Expand Down
20 changes: 14 additions & 6 deletions packages/app/src/components/ApiTree/EndpointNode.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export default function EndpointNode(
) {
return (
<>
<div className="backdrop-blur-sm bg-[#FFFFFF1A] rounded-xl border border-border-dark overflow-hidden">
<div className="backdrop-blur-sm bg-[#FFFFFF1A] rounded-xl border border-border-light dark:border-border-dark overflow-hidden">
<Handle
type="target"
position={Position.Top}
Expand All @@ -27,7 +27,7 @@ export default function EndpointNode(
className="h-[5px]"
style={{ backgroundColor: props.data.groupColor }}
/>
<div className="bg-background-dark px-5 py-1 flex justify-between items-center">
<div className="bg-background-light dark:bg-background-dark px-5 py-1 flex justify-between items-center">
<div>Action</div>
<EndpointNodeContentDialog
busy={props.data.busy}
Expand All @@ -38,20 +38,28 @@ export default function EndpointNode(
<div className="px-5 py-3">
<DataList.Root>
<DataList.Item>
<DataList.Label className="text-white">Method</DataList.Label>
<DataList.Label className="text-text-light dark:text-text-dark">
Method
</DataList.Label>
<DataList.Value>
<MethodBadge method={props.data.endpoint.method} />
</DataList.Value>
</DataList.Item>
<DataList.Item>
<DataList.Label className="text-white">Path</DataList.Label>
<DataList.Label className="text-text-light dark:text-text-dark">
Path
</DataList.Label>
<DataList.Value>
<div className="text-white">{props.data.endpoint.path}</div>
<div className="text-text-light dark:text-text-dark">
{props.data.endpoint.path}
</div>
</DataList.Value>
</DataList.Item>
{props.data.endpoint.group && (
<DataList.Item>
<DataList.Label className="text-white">Group</DataList.Label>
<DataList.Label className="text-text-light dark:text-text-dark">
Group
</DataList.Label>
<DataList.Value>
<GroupBadge name={props.data.endpoint.group} />
</DataList.Value>
Expand Down
35 changes: 20 additions & 15 deletions packages/app/src/components/ApiTree/EndpointNodeContentDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export default function EndpointNodeContentDialog(props: {
viewBox="0 0 15 15"
fill="none"
xmlns="http://www.w3.org/2000/svg"
className="text-text-dark"
className="text-text-light dark:text-text-dark"
>
<path
d="M3.625 7.5C3.625 8.12132 3.12132 8.625 2.5 8.625C1.87868 8.625 1.375 8.12132 1.375 7.5C1.375 6.87868 1.87868 6.375 2.5 6.375C3.12132 6.375 3.625 6.87868 3.625 7.5ZM8.625 7.5C8.625 8.12132 8.12132 8.625 7.5 8.625C6.87868 8.625 6.375 8.12132 6.375 7.5C6.375 6.87868 6.87868 6.375 7.5 6.375C8.12132 6.375 8.625 6.87868 8.625 7.5ZM12.5 8.625C13.1213 8.625 13.625 8.12132 13.625 7.5C13.625 6.87868 13.1213 6.375 12.5 6.375C11.8787 6.375 11.375 6.87868 11.375 7.5C11.375 8.12132 11.8787 8.625 12.5 8.625Z"
Expand All @@ -45,7 +45,7 @@ export default function EndpointNodeContentDialog(props: {
</svg>
</Button>
</Dialog.Trigger>
<Dialog.Content className="bg-secondarySurface-dark text-text-dark border-0">
<Dialog.Content className="bg-secondarySurface-light text-text-light dark:bg-secondarySurface-dark dark:text-text-dark border-0">
<Dialog.Title>
<div className="flex justify-between">
<div>Endpoint details</div>
Expand All @@ -57,7 +57,7 @@ export default function EndpointNodeContentDialog(props: {
viewBox="0 0 20 20"
fill="none"
xmlns="http://www.w3.org/2000/svg"
className="text-gray-dark"
className="text-gray-light dark:text-gray-dark"
>
<g opacity="0.5">
<path
Expand All @@ -78,24 +78,27 @@ export default function EndpointNodeContentDialog(props: {
/>
<DataList.Root className="mt-5">
<DataList.Item align="center">
<DataList.Label className="text-gray-dark">Method</DataList.Label>
<DataList.Label className="text-gray-light dark:text-gray-dark">
Method
</DataList.Label>
<DataList.Value>
<MethodBadge method={props.endpoint.method} />
</DataList.Value>
</DataList.Item>
<DataList.Item>
<DataList.Label className="text-gray-dark">Path</DataList.Label>
<DataList.Label className="text-gray-light dark:text-gray-dark">
Path
</DataList.Label>
<DataList.Value>
<div>{props.endpoint.path}</div>
</DataList.Value>
</DataList.Item>
<DataList.Item align="center">
<DataList.Label className="text-gray-dark">Group</DataList.Label>
<DataList.Label className="text-gray-light dark:text-gray-dark">
Group
</DataList.Label>
<DataList.Value>
<form
className="flex gap-2 items-center gap-2"
onSubmit={handleApply}
>
<form className="flex gap-2 items-center" onSubmit={handleApply}>
<TextField.Root
value={group}
onChange={(e) => setGroup(e.target.value)}
Expand All @@ -109,9 +112,9 @@ export default function EndpointNodeContentDialog(props: {
viewBox="0 0 16 16"
fill="none"
xmlns="http://www.w3.org/2000/svg"
className="text-gray-dark"
className="text-gray-light dark:text-gray-dark"
>
<g clip-path="url(#clip0_22_36940)">
<g clipPath="url(#clip0_22_36940)">
<path
d="M15.2353 0.765303C14.7821 0.312767 14.1678 0.0585938 13.5273 0.0585938C12.8869 0.0585938 12.2726 0.312767 11.8193 0.765303L0.976677 11.608C0.666178 11.9167 0.419985 12.284 0.252342 12.6885C0.0846994 13.093 -0.00106532 13.5268 9.98748e-06 13.9646V15.3333C9.98748e-06 15.5101 0.0702479 15.6797 0.195272 15.8047C0.320296 15.9297 0.489866 16 0.666677 16H2.03534C2.47319 16.0012 2.90692 15.9156 3.31145 15.748C3.71597 15.5805 4.08325 15.3344 4.39201 15.024L15.2353 4.18064C15.6877 3.72743 15.9417 3.11328 15.9417 2.47297C15.9417 1.83266 15.6877 1.21851 15.2353 0.765303ZM3.44934 14.0813C3.07335 14.4548 2.56532 14.6651 2.03534 14.6666H1.33334V13.9646C1.33267 13.7019 1.38411 13.4417 1.4847 13.1989C1.58529 12.9562 1.73302 12.7359 1.91934 12.5506L10.148 4.32197L11.6813 5.8553L3.44934 14.0813ZM14.292 3.23797L12.6213 4.9093L11.088 3.3793L12.7593 1.70797C12.86 1.60751 12.9795 1.52786 13.111 1.47358C13.2424 1.41929 13.3833 1.39143 13.5255 1.39158C13.6678 1.39174 13.8086 1.41991 13.9399 1.47448C14.0712 1.52905 14.1905 1.60896 14.291 1.70964C14.3915 1.81032 14.4711 1.9298 14.5254 2.06126C14.5797 2.19272 14.6076 2.33359 14.6074 2.47581C14.6072 2.61804 14.5791 2.75885 14.5245 2.89019C14.4699 3.02153 14.39 3.14084 14.2893 3.2413L14.292 3.23797Z"
fill="currentColor"
Expand Down Expand Up @@ -147,14 +150,16 @@ export default function EndpointNodeContentDialog(props: {

<DataList.Root className="mt-5">
<DataList.Item>
<DataList.Label className="text-gray-dark">Source:</DataList.Label>
<DataList.Label className="text-gray-light dark:text-gray-dark">
Source:
</DataList.Label>
<DataList.Value>
<div>{props.endpoint.filePath}</div>
</DataList.Value>
</DataList.Item>

<DataList.Item>
<DataList.Label className="text-gray-dark">
<DataList.Label className="text-gray-light dark:text-gray-dark">
Dependants:
</DataList.Label>
<DataList.Value>
Expand All @@ -171,7 +176,7 @@ export default function EndpointNodeContentDialog(props: {
</DataList.Item>

<DataList.Item>
<DataList.Label className="text-gray-dark">
<DataList.Label className="text-gray-light dark:text-gray-dark">
Dependencies:
</DataList.Label>
<DataList.Value>
Expand Down
6 changes: 3 additions & 3 deletions packages/app/src/components/ApiTree/GroupNode.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@ import { Handle, Node, NodeProps, Position } from "@xyflow/react";
export default function GroupNode(props: NodeProps<Node<{ path: string }>>) {
return (
<>
<div className="backdrop-blur-sm bg-[#FFFFFF1A] rounded-xl border border-border-dark">
<div className="backdrop-blur-sm bg-[#FFFFFF1A] rounded-xl border border-border-light dark:border-border-dark">
<Handle
type="target"
position={Position.Top}
className="border border-gray-dark"
className="border border-gray-light dark:border-gray-dark"
/>
<div className="text-center font-bold p-5">/{props.data.path}</div>
<Handle
type="source"
position={Position.Bottom}
className="border border-gray-dark"
className="border border-gray-light dark:border-gray-dark"
/>
</div>
</>
Expand Down
2 changes: 1 addition & 1 deletion packages/app/src/components/GroupBadge.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export default function GroupBadge(props: { name: string }) {
<Badge
radius="full"
size="2"
className="text-text-dark bg-[#FFFFFF1A] border border-primary-dark"
className="text-text-light dark:text-text-dark bg-[#FFFFFF1A] border border-primary-light dark:border-primary-dark"
>
{props.name}
</Badge>
Expand Down
45 changes: 45 additions & 0 deletions packages/app/src/contexts/ThemeContext.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { createContext, useState } from "react";

export const ThemeContext = createContext<{
theme: "light" | "dark";
changeTheme: (newTheme: "light" | "dark") => void;
}>({
theme: "light",
// eslint-disable-next-line @typescript-eslint/no-empty-function
changeTheme: () => {},
});

export function ThemeProvider({ children }: { children: React.ReactNode }) {
function getModeFromLocalStorage() {
if (
localStorage.theme === "dark" ||
(!("theme" in localStorage) &&
window.matchMedia("(prefers-color-scheme: dark)").matches)
) {
localStorage.theme = "dark";
document.documentElement.classList.add("dark");
return "dark";
}
return "light";
}

const [theme, setTheme] = useState<"light" | "dark">(
getModeFromLocalStorage(),
);

function changeTheme(newTheme: "light" | "dark") {
localStorage.theme = newTheme;
setTheme(newTheme);
if (newTheme === "light") {
document.documentElement.classList.remove("dark");
} else {
document.documentElement.classList.add("dark");
}
}

return (
<ThemeContext.Provider value={{ theme, changeTheme }}>
{children}
</ThemeContext.Provider>
);
}
Loading

0 comments on commit 6a3e5d8

Please sign in to comment.