You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
65 lines
1.8 KiB
TypeScript
65 lines
1.8 KiB
TypeScript
1 year ago
|
import * as RadixTabs from "@radix-ui/react-tabs";
|
||
1 year ago
|
import { ReactNode, useRef } from "react";
|
||
1 year ago
|
import { useExcalidrawSetAppState } from "../App";
|
||
1 year ago
|
import { isMemberOf } from "../../utils";
|
||
1 year ago
|
|
||
1 year ago
|
const TTDDialogTabs = (
|
||
|
props: {
|
||
|
children: ReactNode;
|
||
|
} & (
|
||
|
| { dialog: "ttd"; tab: "text-to-diagram" | "mermaid" }
|
||
|
| { dialog: "settings"; tab: "text-to-diagram" | "diagram-to-code" }
|
||
|
),
|
||
|
) => {
|
||
1 year ago
|
const setAppState = useExcalidrawSetAppState();
|
||
|
|
||
1 year ago
|
const rootRef = useRef<HTMLDivElement>(null);
|
||
|
const minHeightRef = useRef<number>(0);
|
||
|
|
||
1 year ago
|
return (
|
||
|
<RadixTabs.Root
|
||
1 year ago
|
ref={rootRef}
|
||
1 year ago
|
className="ttd-dialog-tabs-root"
|
||
1 year ago
|
value={props.tab}
|
||
1 year ago
|
onValueChange={(
|
||
|
// at least in test enviros, `tab` can be `undefined`
|
||
|
tab: string | undefined,
|
||
|
) => {
|
||
1 year ago
|
if (!tab) {
|
||
|
return;
|
||
|
}
|
||
|
const modalContentNode =
|
||
|
rootRef.current?.closest<HTMLElement>(".Modal__content");
|
||
|
if (modalContentNode) {
|
||
|
const currHeight = modalContentNode.offsetHeight || 0;
|
||
|
if (currHeight > minHeightRef.current) {
|
||
|
minHeightRef.current = currHeight;
|
||
|
modalContentNode.style.minHeight = `min(${minHeightRef.current}px, 100%)`;
|
||
|
}
|
||
|
}
|
||
|
if (
|
||
|
props.dialog === "settings" &&
|
||
|
isMemberOf(["text-to-diagram", "diagram-to-code"], tab)
|
||
|
) {
|
||
|
setAppState({
|
||
|
openDialog: { name: props.dialog, tab, source: "settings" },
|
||
|
});
|
||
|
} else if (
|
||
|
props.dialog === "ttd" &&
|
||
|
isMemberOf(["text-to-diagram", "mermaid"], tab)
|
||
|
) {
|
||
1 year ago
|
setAppState({
|
||
1 year ago
|
openDialog: { name: props.dialog, tab },
|
||
1 year ago
|
});
|
||
|
}
|
||
|
}}
|
||
|
>
|
||
1 year ago
|
{props.children}
|
||
1 year ago
|
</RadixTabs.Root>
|
||
|
);
|
||
|
};
|
||
|
|
||
|
TTDDialogTabs.displayName = "TTDDialogTabs";
|
||
|
|
||
|
export default TTDDialogTabs;
|