Added button as footer and a submit form
This commit is contained in:
parent
d5d6f2b4fb
commit
7f371af0e5
2 changed files with 55 additions and 13 deletions
|
|
@ -70,7 +70,12 @@ export default function AddNewVariableButton({ children }): JSX.Element {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
return (
|
return (
|
||||||
<BaseModal open={open} setOpen={setOpen} size="x-small">
|
<BaseModal
|
||||||
|
open={open}
|
||||||
|
setOpen={setOpen}
|
||||||
|
size="x-small"
|
||||||
|
onSubmit={handleSaveVariable}
|
||||||
|
>
|
||||||
<BaseModal.Header
|
<BaseModal.Header
|
||||||
description={
|
description={
|
||||||
"This variable will be encrypted and will be available for you to use in any of your projects."
|
"This variable will be encrypted and will be available for you to use in any of your projects."
|
||||||
|
|
@ -137,9 +142,7 @@ export default function AddNewVariableButton({ children }): JSX.Element {
|
||||||
></InputComponent>
|
></InputComponent>
|
||||||
</div>
|
</div>
|
||||||
</BaseModal.Content>
|
</BaseModal.Content>
|
||||||
<BaseModal.Footer>
|
<BaseModal.Footer submit={{ label: "Save Variable" }} />
|
||||||
<Button onClick={handleSaveVariable}>Save Variable</Button>
|
|
||||||
</BaseModal.Footer>
|
|
||||||
</BaseModal>
|
</BaseModal>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,7 @@ import {
|
||||||
DialogContent as ModalContent,
|
DialogContent as ModalContent,
|
||||||
} from "../../components/ui/dialog-with-no-close";
|
} from "../../components/ui/dialog-with-no-close";
|
||||||
|
|
||||||
|
import { Button } from "../../components/ui/button";
|
||||||
import { modalHeaderType } from "../../types/components";
|
import { modalHeaderType } from "../../types/components";
|
||||||
import { cn } from "../../utils/utils";
|
import { cn } from "../../utils/utils";
|
||||||
|
|
||||||
|
|
@ -61,8 +62,23 @@ const Header: React.FC<{ children: ReactNode; description: string | null }> = ({
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
const Footer: React.FC<{ children: ReactNode }> = ({ children }) => {
|
const Footer: React.FC<{
|
||||||
return <>{children}</>;
|
children?: ReactNode;
|
||||||
|
submit?: { label: string; icon?: ReactNode };
|
||||||
|
}> = ({ children, submit }) => {
|
||||||
|
return submit ? (
|
||||||
|
<div className="flex w-full items-center justify-between">
|
||||||
|
{children ?? <div />}
|
||||||
|
<div className="flex items-center">
|
||||||
|
<Button type="submit">
|
||||||
|
{submit.icon && submit.icon}
|
||||||
|
{submit.label}
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
) : (
|
||||||
|
<>{children && children}</>
|
||||||
|
);
|
||||||
};
|
};
|
||||||
interface BaseModalProps {
|
interface BaseModalProps {
|
||||||
children: [
|
children: [
|
||||||
|
|
@ -91,6 +107,7 @@ interface BaseModalProps {
|
||||||
disable?: boolean;
|
disable?: boolean;
|
||||||
onChangeOpenModal?: (open?: boolean) => void;
|
onChangeOpenModal?: (open?: boolean) => void;
|
||||||
type?: "modal" | "dialog";
|
type?: "modal" | "dialog";
|
||||||
|
onSubmit?: () => void;
|
||||||
}
|
}
|
||||||
function BaseModal({
|
function BaseModal({
|
||||||
open,
|
open,
|
||||||
|
|
@ -99,6 +116,7 @@ function BaseModal({
|
||||||
size = "large",
|
size = "large",
|
||||||
onChangeOpenModal,
|
onChangeOpenModal,
|
||||||
type = "dialog",
|
type = "dialog",
|
||||||
|
onSubmit,
|
||||||
}: BaseModalProps) {
|
}: BaseModalProps) {
|
||||||
const headerChild = React.Children.toArray(children).find(
|
const headerChild = React.Children.toArray(children).find(
|
||||||
(child) => (child as React.ReactElement).type === Header,
|
(child) => (child as React.ReactElement).type === Header,
|
||||||
|
|
@ -212,13 +230,34 @@ function BaseModal({
|
||||||
<div className="truncate-doubleline word-break-break-word">
|
<div className="truncate-doubleline word-break-break-word">
|
||||||
{headerChild}
|
{headerChild}
|
||||||
</div>
|
</div>
|
||||||
<div
|
{onSubmit ? (
|
||||||
className={`flex flex-col ${height} w-full transition-all duration-300`}
|
<form
|
||||||
>
|
onSubmit={(event) => {
|
||||||
{ContentChild}
|
event.preventDefault();
|
||||||
</div>
|
onSubmit();
|
||||||
{ContentFooter && (
|
}}
|
||||||
<div className="flex flex-row-reverse">{ContentFooter}</div>
|
className="flex flex-col gap-4"
|
||||||
|
>
|
||||||
|
<div
|
||||||
|
className={`flex flex-col ${height} w-full transition-all duration-300`}
|
||||||
|
>
|
||||||
|
{ContentChild}
|
||||||
|
</div>
|
||||||
|
{ContentFooter && (
|
||||||
|
<div className="flex flex-row-reverse">{ContentFooter}</div>
|
||||||
|
)}
|
||||||
|
</form>
|
||||||
|
) : (
|
||||||
|
<>
|
||||||
|
<div
|
||||||
|
className={`flex flex-col ${height} w-full transition-all duration-300`}
|
||||||
|
>
|
||||||
|
{ContentChild}
|
||||||
|
</div>
|
||||||
|
{ContentFooter && (
|
||||||
|
<div className="flex flex-row-reverse">{ContentFooter}</div>
|
||||||
|
)}
|
||||||
|
</>
|
||||||
)}
|
)}
|
||||||
</DialogContent>
|
</DialogContent>
|
||||||
</Dialog>
|
</Dialog>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue