Skip to content

Commit

Permalink
feat: move sizable hack into a separate wrapper
Browse files Browse the repository at this point in the history
  • Loading branch information
horvathmarton committed Oct 19, 2023
1 parent f116e23 commit 495e952
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 15 deletions.
19 changes: 4 additions & 15 deletions components/mermaid.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"use client";
import React, { useEffect, useState } from "react";
import mermaid from "mermaid";
import { useEffect } from "react";
import Sizable from "./sizable";

export default function Mermaid({
chart,
Expand All @@ -19,20 +20,8 @@ export default function Mermaid({
}, []);

return (
<div
className="mermaid my-8"
style={
width
? {
width: "" + width + "vw",
position: "relative",
left: "50%",
marginLeft: "-" + width / 2 + "vw",
}
: {}
}
>
<Sizable className="mermaid my-8" width={width}>
{chart}
</div>
</Sizable>
);
}
23 changes: 23 additions & 0 deletions components/sizable.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
"use client";

export interface SizableProps {
width: number;
className: string;
children: string | JSX.Element;
}

export default function Sizable({ width, children, className }: SizableProps) {
return (
<div
className={className}
style={{
width: "" + width + "vw",
position: "relative",
left: "50%",
marginLeft: "-" + width / 2 + "vw",
}}
>
{children}
</div>
);
}

0 comments on commit 495e952

Please sign in to comment.