first modal with subcomponents
This commit is contained in:
parent
b7124de011
commit
e832711a1f
1 changed files with 45 additions and 50 deletions
|
|
@ -1,17 +1,7 @@
|
||||||
import { useContext, useEffect, useRef, useState } from "react";
|
import { ReactNode, useEffect, useRef } from "react";
|
||||||
import { FlowType } from "../../types/flow";
|
|
||||||
import { alertContext } from "../../contexts/alertContext";
|
|
||||||
import { classNames, validateNodes } from "../../utils";
|
|
||||||
import { typesContext } from "../../contexts/typesContext";
|
|
||||||
import {
|
import {
|
||||||
TerminalSquare,
|
TerminalSquare,
|
||||||
MessageSquare,
|
|
||||||
Variable,
|
|
||||||
Eraser,
|
|
||||||
MessageSquarePlus,
|
|
||||||
} from "lucide-react";
|
} from "lucide-react";
|
||||||
import { sendAllProps } from "../../types/api";
|
|
||||||
import { ChatMessageType } from "../../types/chat";
|
|
||||||
|
|
||||||
import _ from "lodash";
|
import _ from "lodash";
|
||||||
import {
|
import {
|
||||||
|
|
@ -22,38 +12,45 @@ import {
|
||||||
DialogTitle,
|
DialogTitle,
|
||||||
DialogTrigger,
|
DialogTrigger,
|
||||||
} from "../../components/ui/dialog";
|
} from "../../components/ui/dialog";
|
||||||
import { CHAT_FORM_DIALOG_SUBTITLE } from "../../constants";
|
import React from "react";
|
||||||
import { Label } from "../../components/ui/label";
|
|
||||||
import { TabsContext } from "../../contexts/tabsContext";
|
|
||||||
import {
|
|
||||||
Accordion,
|
|
||||||
AccordionContent,
|
|
||||||
AccordionItem,
|
|
||||||
AccordionTrigger,
|
|
||||||
} from "../../components/ui/accordion";
|
|
||||||
import { Textarea } from "../../components/ui/textarea";
|
|
||||||
import { Badge } from "../../components/ui/badge";
|
|
||||||
import ToggleShadComponent from "../../components/toggleShadComponent";
|
|
||||||
import Dropdown from "../../components/dropdownComponent";
|
|
||||||
import {
|
|
||||||
DropdownMenu,
|
|
||||||
DropdownMenuContent,
|
|
||||||
DropdownMenuItem,
|
|
||||||
DropdownMenuTrigger,
|
|
||||||
} from "../../components/ui/dropdown-menu";
|
|
||||||
import { Button } from "../../components/ui/button";
|
|
||||||
|
|
||||||
export default function TwoColumnsModal({
|
const First: React.FC<{ children: ReactNode }> = ({ children }) => {
|
||||||
|
return (
|
||||||
|
<div className="w-2/5 h-full">
|
||||||
|
{children}
|
||||||
|
</div>)
|
||||||
|
}
|
||||||
|
const Second: React.FC<{ children: ReactNode }> = ({ children }) => {
|
||||||
|
return (
|
||||||
|
<div className="w-full">
|
||||||
|
{children}
|
||||||
|
</div>)
|
||||||
|
}
|
||||||
|
|
||||||
|
const Header: React.FC<{ children: ReactNode, description:string }> = ({ children,description }) => {
|
||||||
|
return (
|
||||||
|
<DialogHeader>
|
||||||
|
<DialogTitle className="flex items-center">
|
||||||
|
{children}
|
||||||
|
</DialogTitle>
|
||||||
|
<DialogDescription>{description}</DialogDescription>
|
||||||
|
</DialogHeader>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
function TwoColumnsModal({
|
||||||
title,
|
title,
|
||||||
description,
|
description,
|
||||||
open,
|
open,
|
||||||
setOpen,
|
setOpen,
|
||||||
|
children,
|
||||||
}: {
|
}: {
|
||||||
|
children: ReactNode;
|
||||||
description: string;
|
description: string;
|
||||||
title: string;
|
title: string;
|
||||||
open: boolean;
|
open: boolean;
|
||||||
setOpen: Function;
|
setOpen: Function;
|
||||||
}) {
|
}, { }) {
|
||||||
const isOpen = useRef(open);
|
const isOpen = useRef(open);
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
isOpen.current = open;
|
isOpen.current = open;
|
||||||
|
|
@ -62,32 +59,30 @@ export default function TwoColumnsModal({
|
||||||
function setModalOpen(x: boolean) {
|
function setModalOpen(x: boolean) {
|
||||||
setOpen(x);
|
setOpen(x);
|
||||||
}
|
}
|
||||||
|
const firstChild = React.Children.toArray(children).find(
|
||||||
|
(child) => (child as React.ReactElement).type === First
|
||||||
|
);
|
||||||
|
|
||||||
|
const secondChild = React.Children.toArray(children).find(
|
||||||
|
(child) => (child as React.ReactElement).type === Second
|
||||||
|
);
|
||||||
|
const headerChild = React.Children.toArray(children).find((child) => (child as React.ReactElement).type === Header);
|
||||||
//UPDATE COLORS AND STYLE CLASSSES
|
//UPDATE COLORS AND STYLE CLASSSES
|
||||||
return (
|
return (
|
||||||
<Dialog open={open} onOpenChange={setModalOpen}>
|
<Dialog open={open} onOpenChange={setModalOpen}>
|
||||||
<DialogTrigger className="hidden"></DialogTrigger>
|
<DialogTrigger className="hidden"></DialogTrigger>
|
||||||
<DialogContent className="min-w-[80vw]">
|
<DialogContent className="min-w-[80vw]">
|
||||||
<DialogHeader>
|
{headerChild}
|
||||||
<DialogTitle className="flex items-center">
|
|
||||||
<span className="pr-2">{title}</span>
|
|
||||||
<TerminalSquare
|
|
||||||
className="h-6 w-6 text-gray-800 pl-1 dark:text-white"
|
|
||||||
aria-hidden="true"
|
|
||||||
/>
|
|
||||||
</DialogTitle>
|
|
||||||
<DialogDescription>{description}</DialogDescription>
|
|
||||||
</DialogHeader>
|
|
||||||
|
|
||||||
<div className="flex h-[80vh] w-full mt-2 ">
|
<div className="flex h-[80vh] w-full mt-2 ">
|
||||||
<div className="w-2/5 h-full">
|
{firstChild}
|
||||||
</div>
|
{secondChild}
|
||||||
<div className="w-full">
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
</DialogContent>
|
</DialogContent>
|
||||||
</Dialog>
|
</Dialog>
|
||||||
);
|
);
|
||||||
|
|
||||||
}
|
}
|
||||||
TwoColumnsModal.first = ({children})=><div>{children}</div>
|
TwoColumnsModal.First = First;
|
||||||
TwoColumnsModal.second = ({children})=><div>{children}</div>
|
TwoColumnsModal.Second = Second;
|
||||||
|
TwoColumnsModal.Header = Header;
|
||||||
|
export default TwoColumnsModal;
|
||||||
Loading…
Add table
Add a link
Reference in a new issue