Reorganize repo structure and standards references
This commit is contained in:
1 parent
3cb93a81be
commit
be2054274d
5885 files changed
+2588
-195
No files matched your search
+136
@@ -0,0 +1,136 @@
|
||||
import { Fragment, useEffect, useState } from "react";
|
||||
import { Dialog, DialogBackdrop, DialogPanel, DialogTitle, Transition, TransitionChild } from "@headlessui/react";
|
||||
import clsx from "clsx";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { CheckCircleIcon } from "~/components/ui/icons/vendor";
|
||||
|
||||
export type ActionResultDto = { success?: ResultMessageDto; error?: ResultMessageDto };
|
||||
type ResultMessageDto = { title?: string; description: string; closeText?: string };
|
||||
interface Props {
|
||||
actionResult?: ActionResultDto;
|
||||
className?: string;
|
||||
actionData?: { error?: string; success?: string } | null;
|
||||
showSuccess?: boolean;
|
||||
showError?: boolean;
|
||||
onClosed?: () => void;
|
||||
}
|
||||
|
||||
export default function ActionResultModal({ actionResult, className, actionData, showSuccess = true, showError = true, onClosed }: Props) {
|
||||
const { t } = useTranslation();
|
||||
const [data, setData] = useState<ResultMessageDto>();
|
||||
const [open, setOpen] = useState(false);
|
||||
|
||||
const [status, setStatus] = useState(actionResult);
|
||||
|
||||
useEffect(() => {
|
||||
setStatus(actionResult);
|
||||
}, [actionResult]);
|
||||
|
||||
useEffect(() => {
|
||||
if (actionData?.error && showError) {
|
||||
setStatus({ error: { description: actionData.error } });
|
||||
} else if (actionData?.success && showSuccess) {
|
||||
setStatus({ success: { description: actionData.success } });
|
||||
}
|
||||
}, [actionData, showError, showSuccess]);
|
||||
|
||||
useEffect(() => {
|
||||
if (status?.success) {
|
||||
setData({
|
||||
title: status.success.title ?? t("shared.success"),
|
||||
description: status.success.description,
|
||||
closeText: status.success.closeText ?? t("shared.close"),
|
||||
});
|
||||
setOpen(true);
|
||||
} else if (status?.error) {
|
||||
setData({
|
||||
title: status.error.title ?? t("shared.error"),
|
||||
description: status.error.description,
|
||||
closeText: status.error.closeText ?? t("shared.close"),
|
||||
});
|
||||
setOpen(true);
|
||||
}
|
||||
}, [status, t]);
|
||||
|
||||
return (
|
||||
<Transition show={open} as={Fragment}>
|
||||
<Dialog
|
||||
as="div"
|
||||
className={clsx(className, "fixed inset-0 z-50 overflow-y-auto transition duration-300 ease-out data-[closed]:opacity-0")}
|
||||
transition
|
||||
onClose={() => setOpen(false)}
|
||||
>
|
||||
<div className="flex min-h-screen items-end justify-center px-4 pt-4 pb-20 text-center sm:block sm:p-0">
|
||||
<TransitionChild
|
||||
as={Fragment}
|
||||
enter="ease-out duration-300"
|
||||
enterFrom="opacity-0"
|
||||
enterTo="opacity-100"
|
||||
leave="ease-in duration-200"
|
||||
leaveFrom="opacity-100"
|
||||
leaveTo="opacity-0"
|
||||
>
|
||||
<DialogBackdrop className="fixed inset-0 bg-gray-500/75 transition-opacity" />
|
||||
</TransitionChild>
|
||||
|
||||
{/* This element is to trick the browser into centering the modal contents. */}
|
||||
<span className="hidden sm:inline-block sm:h-screen sm:align-middle" aria-hidden="true">
|
||||
​
|
||||
</span>
|
||||
<div className="fixed inset-0 flex w-screen items-center justify-center p-4">
|
||||
{/* Subframe ResultDialog layout: flex-col items-center gap-6, rounded-lg, px-6 py-8, icon badge h-14 w-14 rounded-round, content gap-2, full-width button. */}
|
||||
<DialogPanel className="bg-surface-neutral-modal flex w-full max-w-full transform flex-col items-center gap-6 overflow-hidden rounded-lg px-6 py-8 text-left align-bottom shadow-xl transition-all sm:my-8 sm:w-96 sm:align-middle">
|
||||
{status?.success && (
|
||||
<div className="flex h-14 w-14 flex-none items-center justify-center rounded-round bg-green-100">
|
||||
<CheckCircleIcon className="h-6 w-6 text-green-600" />
|
||||
</div>
|
||||
)}
|
||||
{status?.error && (
|
||||
<div className="flex h-14 w-14 flex-none items-center justify-center rounded-round bg-red-100">
|
||||
<svg
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
className="h-6 w-6 text-red-600"
|
||||
fill="none"
|
||||
viewBox="0 0 24 24"
|
||||
stroke="currentColor"
|
||||
strokeWidth="2"
|
||||
>
|
||||
<path
|
||||
strokeLinecap="round"
|
||||
strokeLinejoin="round"
|
||||
d="M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-3L13.732 4c-.77-1.333-2.694-1.333-3.464 0L3.34 16c-.77 1.333.192 3 1.732 3z"
|
||||
/>
|
||||
</svg>
|
||||
</div>
|
||||
)}
|
||||
<div className="flex w-full flex-col items-center gap-2 text-center">
|
||||
<DialogTitle as="h3" className="text-text-neutral-primary text-lg leading-6 font-medium">
|
||||
{t(data?.title ?? "")}
|
||||
</DialogTitle>
|
||||
<p className="text-text-neutral-tertiary text-sm">{t(data?.description ?? "")}</p>
|
||||
</div>
|
||||
<div className="w-full">
|
||||
<button
|
||||
type="button"
|
||||
className={clsx(
|
||||
"inline-flex w-full justify-center rounded-md border border-transparent px-4 py-2 text-base font-medium text-white shadow-2xs focus:ring-2 focus:ring-offset-2 focus:outline-hidden sm:text-sm",
|
||||
status?.success && "bg-teal-600 hover:bg-teal-700 focus:ring-teal-500",
|
||||
status?.error && "bg-gray-600 hover:bg-gray-700 focus:ring-gray-500"
|
||||
)}
|
||||
onClick={() => {
|
||||
setOpen(false);
|
||||
if (onClosed) {
|
||||
onClosed();
|
||||
}
|
||||
}}
|
||||
>
|
||||
{data?.closeText ?? t("shared.close")}
|
||||
</button>
|
||||
</div>
|
||||
</DialogPanel>
|
||||
</div>
|
||||
</div>
|
||||
</Dialog>
|
||||
</Transition>
|
||||
);
|
||||
}
|
||||
+116
@@ -0,0 +1,116 @@
|
||||
import { Fragment, forwardRef, useEffect, useImperativeHandle, useState, Ref } from "react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import {
|
||||
AlertDialog,
|
||||
AlertDialogAction,
|
||||
AlertDialogCancel,
|
||||
AlertDialogContent,
|
||||
AlertDialogDescription,
|
||||
AlertDialogFooter,
|
||||
AlertDialogHeader,
|
||||
AlertDialogTitle,
|
||||
} from "~/components/ui/alert-dialog";
|
||||
import { Input } from "~/components/ui/input";
|
||||
import { Label } from "~/components/ui/label";
|
||||
|
||||
export interface RefConfirmDialog {
|
||||
show: (options: {
|
||||
title?: string;
|
||||
description?: string;
|
||||
confirmText?: string;
|
||||
cancelText?: string;
|
||||
destructive?: boolean;
|
||||
typeToConfirm?: string;
|
||||
onConfirm?: () => void;
|
||||
}) => void;
|
||||
}
|
||||
|
||||
interface Props {
|
||||
destructive?: boolean;
|
||||
}
|
||||
|
||||
const ConfirmDialog = (props: Props, ref: Ref<RefConfirmDialog>) => {
|
||||
const { t } = useTranslation();
|
||||
const [open, setOpen] = useState(false);
|
||||
const [title, setTitle] = useState("");
|
||||
const [description, setDescription] = useState<string | undefined>();
|
||||
const [confirmText, setConfirmText] = useState(t("shared.confirm"));
|
||||
const [cancelText, setCancelText] = useState(t("shared.cancel"));
|
||||
const [destructive, setDestructive] = useState(props.destructive || false);
|
||||
const [typeToConfirm, setTypeToConfirm] = useState<string | undefined>();
|
||||
const [typedConfirmation, setTypedConfirmation] = useState("");
|
||||
const [onConfirmCallback, setOnConfirmCallback] = useState<(() => void) | undefined>();
|
||||
|
||||
const isConfirmEnabled = !typeToConfirm || typedConfirmation.trim().toLowerCase() === typeToConfirm.toLowerCase();
|
||||
|
||||
const handleCancel = () => {
|
||||
setOpen(false);
|
||||
setTypedConfirmation("");
|
||||
};
|
||||
|
||||
const handleConfirm = () => {
|
||||
if (isConfirmEnabled) {
|
||||
setOpen(false);
|
||||
setTypedConfirmation("");
|
||||
if (onConfirmCallback) {
|
||||
onConfirmCallback();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
useImperativeHandle(ref, () => ({
|
||||
show: ({ title, description, confirmText, cancelText, destructive, typeToConfirm, onConfirm }) => {
|
||||
setTitle(title || t("shared.confirm"));
|
||||
setDescription(description || t("shared.warningCannotUndo"));
|
||||
setConfirmText(confirmText || t("shared.confirm"));
|
||||
setCancelText(cancelText || t("shared.cancel"));
|
||||
setDestructive(destructive ?? props.destructive ?? false);
|
||||
setTypeToConfirm(typeToConfirm);
|
||||
setTypedConfirmation("");
|
||||
setOnConfirmCallback(() => onConfirm);
|
||||
setOpen(true);
|
||||
},
|
||||
}));
|
||||
|
||||
return (
|
||||
<AlertDialog open={open} onOpenChange={setOpen}>
|
||||
<AlertDialogContent>
|
||||
<AlertDialogHeader>
|
||||
<AlertDialogTitle>{title}</AlertDialogTitle>
|
||||
{description && <AlertDialogDescription>{description}</AlertDialogDescription>}
|
||||
</AlertDialogHeader>
|
||||
|
||||
{typeToConfirm && (
|
||||
// Subframe ConfirmDialog spacing handled by AlertDialogContent gap-6 grid; input block uses its own gap-2.
|
||||
<div className="flex flex-col gap-2">
|
||||
<Label htmlFor="confirm-text" className="block">
|
||||
{t("components.confirmDialog.typePrefix")} <span className="font-bold">{typeToConfirm}</span> {t("components.confirmDialog.typeSuffix")}
|
||||
</Label>
|
||||
<Input
|
||||
id="confirm-text"
|
||||
autoComplete="off"
|
||||
value={typedConfirmation}
|
||||
onChange={(e) => setTypedConfirmation(e.target.value)}
|
||||
placeholder={typeToConfirm}
|
||||
className={destructive ? "border-border-negative-solid focus-visible:shadow-focus" : ""}
|
||||
autoFocus
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
|
||||
<AlertDialogFooter>
|
||||
<AlertDialogCancel onClick={handleCancel}>{cancelText}</AlertDialogCancel>
|
||||
<AlertDialogAction
|
||||
onClick={handleConfirm}
|
||||
disabled={!isConfirmEnabled}
|
||||
className={destructive ? "bg-surface-feedback-solid-negative-default hover:bg-surface-feedback-solid-negative-hover text-text-neutral-on-solid disabled:bg-surface-neutral-disabled disabled:text-text-neutral-disabled" : undefined}
|
||||
>
|
||||
{confirmText}
|
||||
</AlertDialogAction>
|
||||
</AlertDialogFooter>
|
||||
</AlertDialogContent>
|
||||
</AlertDialog>
|
||||
);
|
||||
};
|
||||
|
||||
export default forwardRef(ConfirmDialog);
|
||||
+189
@@ -0,0 +1,189 @@
|
||||
import { forwardRef, Ref, useEffect, useImperativeHandle, useRef, useState } from "react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import {
|
||||
AlertDialog,
|
||||
AlertDialogAction,
|
||||
AlertDialogCancel,
|
||||
AlertDialogContent,
|
||||
AlertDialogDescription,
|
||||
AlertDialogFooter,
|
||||
AlertDialogHeader,
|
||||
AlertDialogTitle,
|
||||
} from "~/components/ui/alert-dialog";
|
||||
import { cn } from "~/lib/utils";
|
||||
import { MailIcon } from "~/components/ui/icons/vendor";
|
||||
|
||||
export interface RefConfirmModal {
|
||||
setDestructive: (destructive: boolean) => void;
|
||||
setValue: (value: any) => void;
|
||||
show: (_question: string, _yesTitle?: string, _noTitle?: string, _description?: string, _inputString?: string) => void;
|
||||
}
|
||||
|
||||
interface Props {
|
||||
destructive?: boolean;
|
||||
inputType?: string;
|
||||
onYes?: (value: any) => void;
|
||||
onNo?: () => void;
|
||||
placeholder?: string;
|
||||
contentUiId?: string;
|
||||
}
|
||||
|
||||
const ConfirmModal = (props: Props, ref: Ref<RefConfirmModal>) => {
|
||||
const { t } = useTranslation();
|
||||
|
||||
const [open, setOpen] = useState(false);
|
||||
const [title, setTitle] = useState<string>();
|
||||
const [value, setValue] = useState<string>();
|
||||
const [description, setDescription] = useState<string>();
|
||||
const [inputString, setInputString] = useState<string | undefined>("");
|
||||
const [yesTitle, setYesTitle] = useState<string>("");
|
||||
const [noTitle, setNoTitle] = useState<string>("");
|
||||
const [isDestructive, setDestructive] = useState<boolean>(props.destructive || false);
|
||||
|
||||
const inputValue = useRef<HTMLInputElement>(null);
|
||||
|
||||
useEffect(() => {
|
||||
setTitle(t("shared.confirm").toString());
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, []);
|
||||
|
||||
function no() {
|
||||
setOpen(false);
|
||||
if (props.onNo) {
|
||||
props.onNo();
|
||||
}
|
||||
}
|
||||
|
||||
function yes() {
|
||||
setOpen(false);
|
||||
if (props.onYes) {
|
||||
props.onYes(value ?? inputString);
|
||||
}
|
||||
}
|
||||
|
||||
useImperativeHandle(ref, () => ({ show, setValue, setDestructive }));
|
||||
|
||||
function show(
|
||||
_question: string,
|
||||
_yesTitle: string = t("shared.confirm").toString(),
|
||||
_noTitle: string = t("shared.back").toString(),
|
||||
_description?: string,
|
||||
_inputString?: string
|
||||
) {
|
||||
setTitle(_question.toString());
|
||||
if (_yesTitle) {
|
||||
setYesTitle(_yesTitle);
|
||||
}
|
||||
if (_noTitle) {
|
||||
setNoTitle(_noTitle);
|
||||
}
|
||||
if (_description) {
|
||||
setDescription(_description);
|
||||
}
|
||||
setTimeout(() => {
|
||||
if ((props.inputType === "email" || props.inputType === "string" || props.inputType === "slug" || props.inputType === "password") && inputValue.current) {
|
||||
inputValue.current.focus();
|
||||
inputValue.current.select();
|
||||
}
|
||||
}, 0);
|
||||
setOpen(true);
|
||||
setInputString(_inputString);
|
||||
}
|
||||
|
||||
return (
|
||||
<AlertDialog open={open} onOpenChange={setOpen}>
|
||||
<AlertDialogContent data-ui-id={props.contentUiId}>
|
||||
<AlertDialogHeader>
|
||||
<AlertDialogTitle>{title}</AlertDialogTitle>
|
||||
{description && <AlertDialogDescription>{description}</AlertDialogDescription>}
|
||||
</AlertDialogHeader>
|
||||
|
||||
<div>
|
||||
{/* Subframe ConfirmDialog spacing handled by AlertDialogContent gap-6 grid; per-input top margins removed. */}
|
||||
{props.inputType === "email" && (
|
||||
<div>
|
||||
<div className="relative rounded-md shadow-2xs">
|
||||
<div className="pointer-events-none absolute inset-y-0 left-0 flex items-center pl-3">
|
||||
<MailIcon className="text-text-neutral-tertiary h-5 w-5" aria-hidden="true" />
|
||||
</div>
|
||||
<input
|
||||
value={inputString}
|
||||
onChange={(e) => setInputString(e.target.value)}
|
||||
ref={inputValue}
|
||||
type="email"
|
||||
name="email"
|
||||
id="email"
|
||||
aria-label={title}
|
||||
className="border-border-default focus:border-brand-brand-border-solid-default block w-full rounded-md pl-10 focus:shadow-focus sm:text-sm"
|
||||
placeholder={props.placeholder ?? t("account.shared.emailPlaceholder")}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
{props.inputType === "string" && (
|
||||
<div>
|
||||
<div className="relative rounded-md shadow-2xs">
|
||||
<input
|
||||
value={inputString}
|
||||
onChange={(e) => setInputString(e.target.value)}
|
||||
ref={inputValue}
|
||||
type="text"
|
||||
name="value"
|
||||
id="value"
|
||||
aria-label={title}
|
||||
className="border-border-default focus:border-brand-brand-border-solid-default block w-full rounded-md focus:shadow-focus sm:text-sm"
|
||||
placeholder={props.placeholder}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
{props.inputType === "slug" && (
|
||||
<div>
|
||||
<div className="relative rounded-md shadow-2xs">
|
||||
<input
|
||||
value={inputString}
|
||||
onChange={(e) => setInputString(e.target.value.toLowerCase())}
|
||||
ref={inputValue}
|
||||
type="text"
|
||||
name="value"
|
||||
id="value"
|
||||
aria-label={title}
|
||||
className="border-border-default focus:border-brand-brand-border-solid-default block w-full rounded-md focus:shadow-focus sm:text-sm"
|
||||
placeholder={props.placeholder}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
{props.inputType === "password" && (
|
||||
<div>
|
||||
<div className="relative rounded-md shadow-2xs">
|
||||
<input
|
||||
value={inputString}
|
||||
onChange={(e) => setInputString(e.target.value)}
|
||||
ref={inputValue}
|
||||
type="password"
|
||||
name="passwordCurrent"
|
||||
id="passwordCurrent"
|
||||
aria-label={title}
|
||||
className="border-border-default focus:border-brand-brand-border-solid-default block w-full rounded-md focus:shadow-focus sm:text-sm"
|
||||
placeholder={props.placeholder}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<AlertDialogFooter>
|
||||
<AlertDialogCancel onClick={no} className={cn("sm:col-start-1")} data-ui-id="ui.confirm.cancel">
|
||||
{noTitle}
|
||||
</AlertDialogCancel>
|
||||
<AlertDialogAction onClick={yes} className={cn(isDestructive ? "bg-surface-feedback-solid-negative-default hover:bg-surface-feedback-solid-negative-hover" : undefined)} data-ui-id="ui.confirm.action">
|
||||
{yesTitle}
|
||||
</AlertDialogAction>
|
||||
</AlertDialogFooter>
|
||||
</AlertDialogContent>
|
||||
</AlertDialog>
|
||||
);
|
||||
};
|
||||
|
||||
export default forwardRef(ConfirmModal);
|
||||
+78
@@ -0,0 +1,78 @@
|
||||
import { cn } from "~/lib/utils";
|
||||
import { Dialog, DialogContent, DialogFooter, DialogHeader, DialogTitle } from "../dialog";
|
||||
import { ReactNode } from "react";
|
||||
|
||||
interface Props {
|
||||
open: boolean;
|
||||
onClose: () => void;
|
||||
title?: ReactNode;
|
||||
description?: string;
|
||||
children?: React.ReactNode;
|
||||
footer?: React.ReactNode;
|
||||
buttons?: React.ReactNode;
|
||||
size?: "xs" | "sm" | "md" | "lg" | "xl" | "2xl" | "3xl" | "4xl" | "5xl" | "6xl" | "7xl" | "full";
|
||||
className?: string;
|
||||
overflowHidden?: boolean;
|
||||
closesOnOutsideClick?: boolean;
|
||||
}
|
||||
export default function DialogSticky({
|
||||
open,
|
||||
onClose,
|
||||
title,
|
||||
description,
|
||||
children,
|
||||
footer,
|
||||
size = "sm",
|
||||
buttons,
|
||||
className,
|
||||
overflowHidden = false,
|
||||
closesOnOutsideClick = true,
|
||||
}: Props) {
|
||||
const avoidDefaultDomBehavior = (e: Event) => {
|
||||
if (closesOnOutsideClick) {
|
||||
return;
|
||||
}
|
||||
e.preventDefault();
|
||||
};
|
||||
return (
|
||||
<Dialog open={open} onOpenChange={onClose}>
|
||||
<DialogContent
|
||||
withCloseButton={buttons ? false : true}
|
||||
onPointerDownOutside={avoidDefaultDomBehavior}
|
||||
onInteractOutside={avoidDefaultDomBehavior}
|
||||
onEscapeKeyDown={avoidDefaultDomBehavior}
|
||||
className={cn(
|
||||
"[ &>button:last-child]:top-3.5 flex flex-col gap-0 p-0 sm:max-h-[min(640px,80vh)] sm:max-w-lg",
|
||||
size === "xs" && "sm:max-w-xs",
|
||||
size === "sm" && "sm:max-w-sm",
|
||||
size === "md" && "sm:max-w-md",
|
||||
size === "lg" && "sm:max-w-lg",
|
||||
size === "xl" && "sm:max-w-xl",
|
||||
size === "2xl" && "sm:max-w-2xl",
|
||||
size === "3xl" && "sm:max-w-3xl",
|
||||
size === "4xl" && "sm:max-w-4xl",
|
||||
size === "5xl" && "sm:max-w-5xl",
|
||||
size === "6xl" && "sm:max-w-6xl",
|
||||
size === "7xl" && "sm:max-w-7xl",
|
||||
size === "full" && "sm:max-w-full",
|
||||
className
|
||||
)}
|
||||
>
|
||||
<DialogHeader className="bg-surface-neutral-modal space-y-0 rounded-t-md text-left">
|
||||
<DialogTitle className="border-b border-border-default px-6 py-4 text-base">
|
||||
<div className="flex items-center justify-between gap-2">
|
||||
<div className="truncate">{title}</div>
|
||||
{buttons && buttons}
|
||||
</div>
|
||||
</DialogTitle>
|
||||
</DialogHeader>
|
||||
<div className={overflowHidden ? "overflow-hidden" : "overflow-y-auto"}>{children}</div>
|
||||
{footer && (
|
||||
<DialogFooter className="border-border-default bg-surface-neutral-modal justify-end rounded-b-md border-t p-6">
|
||||
{footer}
|
||||
</DialogFooter>
|
||||
)}
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
);
|
||||
}
|
||||
+84
@@ -0,0 +1,84 @@
|
||||
import { forwardRef, Fragment, Ref, useEffect, useImperativeHandle, useState } from "react";
|
||||
import { Dialog, DialogBackdrop, DialogPanel, Transition, TransitionChild } from "@headlessui/react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import clsx from "~/utils/shared/ClassesUtils";
|
||||
import { AlertTriangleIcon } from "~/components/ui/icons/vendor";
|
||||
|
||||
export interface RefErrorModal {
|
||||
show: (title?: string, description?: string) => void;
|
||||
}
|
||||
|
||||
interface Props {
|
||||
className?: string;
|
||||
onClosed?: () => void;
|
||||
}
|
||||
|
||||
const ErrorModal = ({ className, onClosed }: Props, ref: Ref<RefErrorModal>) => {
|
||||
const { t } = useTranslation();
|
||||
|
||||
const [open, setOpen] = useState(false);
|
||||
|
||||
const [title, setTitle] = useState<string>();
|
||||
const [description, setDescription] = useState<string>();
|
||||
const [closeText, setCloseText] = useState<string>();
|
||||
|
||||
useEffect(() => {
|
||||
setTitle(t("shared.error").toString());
|
||||
setCloseText(t("shared.close"));
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, []);
|
||||
|
||||
function show(_title?: string, _description?: string) {
|
||||
if (_title) {
|
||||
setTitle(_title);
|
||||
}
|
||||
if (_description) {
|
||||
setDescription(_description);
|
||||
} else if (_title) {
|
||||
setTitle(t("shared.error").toString());
|
||||
setDescription(_title);
|
||||
}
|
||||
setOpen(true);
|
||||
}
|
||||
|
||||
useImperativeHandle(ref, () => ({ show }));
|
||||
|
||||
function close() {
|
||||
setOpen(false);
|
||||
if (onClosed) {
|
||||
onClosed();
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<Dialog open={open} onClose={setOpen} className="fixed inset-0 z-50 overflow-y-auto transition duration-300 ease-out data-[closed]:opacity-0" transition>
|
||||
<div className="flex min-h-screen items-end justify-center px-4 pt-4 pb-20 text-center sm:block sm:p-0">
|
||||
<DialogBackdrop className="fixed inset-0 bg-gray-500/75 transition-opacity" />
|
||||
|
||||
<div className="fixed inset-0 flex w-screen items-center justify-center p-4">
|
||||
{/* Subframe ResultDialog layout: flex-col items-center gap-6, rounded-lg, px-6 py-8, icon badge h-14 w-14 rounded-round, content gap-2, full-width button. */}
|
||||
<DialogPanel className="bg-surface-neutral-modal flex w-full max-w-full transform flex-col items-center gap-6 overflow-hidden rounded-lg px-6 py-8 text-left align-bottom shadow-xl transition-all sm:my-8 sm:w-96 sm:align-middle">
|
||||
<div className="flex h-14 w-14 flex-none items-center justify-center rounded-round bg-red-100">
|
||||
<AlertTriangleIcon className="h-6 w-6 text-red-600" />
|
||||
</div>
|
||||
<div className="flex w-full flex-col items-center gap-2 text-center">
|
||||
<h3 className="text-text-neutral-primary text-lg leading-6 font-medium">{title}</h3>
|
||||
<p className="text-text-neutral-tertiary text-sm">{description}</p>
|
||||
</div>
|
||||
<div className="w-full">
|
||||
<button
|
||||
type="button"
|
||||
className="bg-brand-brand-surface-solid-default text-text-neutral-on-solid hover:bg-brand-brand-surface-solid-hover mt-0 inline-flex w-full justify-center rounded-md border border-transparent px-4 py-2 text-sm font-medium shadow-2xs focus:shadow-focus focus:outline-hidden"
|
||||
onClick={close}
|
||||
>
|
||||
{closeText}
|
||||
</button>
|
||||
</div>
|
||||
</DialogPanel>
|
||||
</div>
|
||||
</div>
|
||||
</Dialog>
|
||||
);
|
||||
};
|
||||
|
||||
export default forwardRef(ErrorModal);
|
||||
@@ -0,0 +1,94 @@
|
||||
import { ReactNode, Fragment } from "react";
|
||||
import { Dialog, DialogBackdrop, DialogPanel, Transition, TransitionChild } from "@headlessui/react";
|
||||
import clsx from "clsx";
|
||||
|
||||
interface Props {
|
||||
className?: string;
|
||||
children: ReactNode;
|
||||
open: boolean;
|
||||
setOpen: React.Dispatch<React.SetStateAction<boolean>>;
|
||||
size?: "xs" | "sm" | "md" | "lg" | "xl" | "2xl" | "3xl" | "4xl" | "5xl" | "6xl" | "7xl" | "full";
|
||||
padding?: "none" | "sm";
|
||||
position?: 0 | 1 | 2 | 3 | 4 | 5;
|
||||
title?: ReactNode;
|
||||
"data-ui-id"?: string;
|
||||
}
|
||||
export default function Modal({ className, children, open, setOpen, size = "3xl", padding = "sm", position = 5, title, "data-ui-id": dataUiId }: Props) {
|
||||
function onClose() {
|
||||
setOpen(false);
|
||||
}
|
||||
return (
|
||||
<Dialog
|
||||
open={open}
|
||||
onClose={onClose}
|
||||
as="div"
|
||||
className={clsx(
|
||||
"text-text-neutral-primary fixed inset-0 overflow-y-auto",
|
||||
position === 0 && "z-0",
|
||||
position === 1 && "z-10",
|
||||
position === 2 && "z-20",
|
||||
position === 3 && "z-30",
|
||||
position === 4 && "z-40",
|
||||
position === 5 && "z-50"
|
||||
)}
|
||||
>
|
||||
<div className="flex min-h-screen items-end justify-center px-4 pt-4 pb-20 text-center sm:block sm:p-0">
|
||||
<TransitionChild
|
||||
as={Fragment}
|
||||
enter="ease-out duration-300"
|
||||
enterFrom="opacity-0"
|
||||
enterTo="opacity-100"
|
||||
leave="ease-in duration-200"
|
||||
leaveFrom="opacity-100"
|
||||
leaveTo="opacity-0"
|
||||
>
|
||||
<DialogBackdrop className="fixed inset-0 bg-gray-500/75 transition-opacity" />
|
||||
</TransitionChild>
|
||||
|
||||
{/* This element is to trick the browser into centering the modal contents. */}
|
||||
<span className="hidden sm:inline-block sm:h-screen sm:align-middle" aria-hidden="true">
|
||||
​
|
||||
</span>
|
||||
<TransitionChild
|
||||
as={Fragment}
|
||||
enter="ease-out duration-300"
|
||||
enterFrom="opacity-0 translate-y-4 sm:translate-y-0 sm:scale-95"
|
||||
enterTo="opacity-100 translate-y-0 sm:scale-100"
|
||||
leave="ease-in duration-200"
|
||||
leaveFrom="opacity-100 translate-y-0 sm:scale-100"
|
||||
leaveTo="opacity-0 translate-y-4 sm:translate-y-0 sm:scale-95"
|
||||
>
|
||||
<DialogPanel
|
||||
data-ui-id={dataUiId}
|
||||
className={clsx(
|
||||
className,
|
||||
// Subframe ModalBlank panel radius: rounded-md. Kept: overflow-visible (poppers escape panel), configurable padding/size system, headlessui transitions.
|
||||
"bg-surface-neutral-modal relative inline-block w-full transform overflow-visible rounded-md text-left align-bottom shadow-xl transition-all sm:align-middle",
|
||||
padding === "none" && "px-0 pt-0 pb-0 sm:my-0 sm:p-0",
|
||||
padding === "sm" && "px-4 pt-5 pb-4 sm:my-8 sm:p-6",
|
||||
size === "xs" && "sm:max-w-xs",
|
||||
size === "sm" && "sm:max-w-sm",
|
||||
size === "md" && "sm:max-w-md",
|
||||
size === "lg" && "sm:max-w-lg",
|
||||
size === "xl" && "sm:max-w-xl",
|
||||
size === "2xl" && "sm:max-w-2xl",
|
||||
size === "3xl" && "sm:max-w-3xl",
|
||||
size === "4xl" && "sm:max-w-4xl",
|
||||
size === "5xl" && "sm:max-w-5xl",
|
||||
size === "6xl" && "sm:max-w-6xl",
|
||||
size === "7xl" && "sm:max-w-7xl",
|
||||
size === "full" && "sm:max-w-full"
|
||||
)}
|
||||
>
|
||||
{title && (
|
||||
<div className="mb-4 border-b border-border-default pb-4">
|
||||
<h3 className="text-lg font-medium">{title}</h3>
|
||||
</div>
|
||||
)}
|
||||
{children}
|
||||
</DialogPanel>
|
||||
</TransitionChild>
|
||||
</div>
|
||||
</Dialog>
|
||||
);
|
||||
}
|
||||
+78
@@ -0,0 +1,78 @@
|
||||
import { ReactNode } from "react";
|
||||
import Modal from "./Modal";
|
||||
import SlideOverWideEmpty from "../slideOvers/SlideOverWideEmpty";
|
||||
import DialogSticky from "./DialogSticky";
|
||||
|
||||
interface Props {
|
||||
type: "modal" | "slide" | "dialog";
|
||||
className?: string;
|
||||
children: ReactNode;
|
||||
open: boolean;
|
||||
setOpen: React.Dispatch<React.SetStateAction<boolean>>;
|
||||
title?: ReactNode;
|
||||
description?: string;
|
||||
size?: "xs" | "sm" | "md" | "lg" | "xl" | "2xl" | "3xl" | "4xl" | "5xl" | "6xl" | "7xl" | "full";
|
||||
padding?: "none" | "sm";
|
||||
position?: 0 | 1 | 2 | 3 | 4 | 5;
|
||||
buttons?: ReactNode;
|
||||
footer?: ReactNode;
|
||||
overflowHidden?: boolean;
|
||||
closesOnOutsideClick?: boolean;
|
||||
}
|
||||
export default function ModalOrSlide({
|
||||
type,
|
||||
className,
|
||||
children,
|
||||
open,
|
||||
setOpen,
|
||||
title,
|
||||
description,
|
||||
size = "3xl",
|
||||
padding = "sm",
|
||||
position = 5,
|
||||
buttons,
|
||||
footer,
|
||||
overflowHidden = false,
|
||||
closesOnOutsideClick = true,
|
||||
}: Props) {
|
||||
if (type === "modal") {
|
||||
return (
|
||||
<Modal title={title} className={className} open={open} setOpen={setOpen} size={size} padding={padding} position={position}>
|
||||
{children}
|
||||
</Modal>
|
||||
);
|
||||
} else if (type === "slide") {
|
||||
return (
|
||||
<SlideOverWideEmpty
|
||||
title={title}
|
||||
description={description}
|
||||
className={className}
|
||||
open={open}
|
||||
onClose={() => setOpen(false)}
|
||||
size={size}
|
||||
position={position}
|
||||
buttons={buttons}
|
||||
>
|
||||
{children}
|
||||
</SlideOverWideEmpty>
|
||||
);
|
||||
} else if (type === "dialog") {
|
||||
return (
|
||||
<DialogSticky
|
||||
title={title}
|
||||
description={description}
|
||||
open={open}
|
||||
onClose={() => setOpen(false)}
|
||||
footer={footer}
|
||||
size={size}
|
||||
buttons={buttons}
|
||||
className={className}
|
||||
overflowHidden={overflowHidden}
|
||||
closesOnOutsideClick={closesOnOutsideClick}
|
||||
>
|
||||
{children}
|
||||
</DialogSticky>
|
||||
);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
+80
@@ -0,0 +1,80 @@
|
||||
import { Fragment, useEffect, useState } from "react";
|
||||
import { Dialog, DialogBackdrop, DialogPanel, DialogTitle, Transition, TransitionChild } from "@headlessui/react";
|
||||
import clsx from "clsx";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { AlertTriangleIcon } from "~/components/ui/icons/vendor";
|
||||
|
||||
interface Props {
|
||||
title: string;
|
||||
description: string;
|
||||
closeText?: string;
|
||||
open: boolean;
|
||||
onClose: () => void;
|
||||
className?: string;
|
||||
}
|
||||
|
||||
export default function OpenErrorModal({ title, description, closeText, open, onClose, className }: Props) {
|
||||
const { t } = useTranslation();
|
||||
const [data, setData] = useState<{ title: string; description: string; closeText?: string }>();
|
||||
|
||||
useEffect(() => {
|
||||
if (title && description) {
|
||||
setData({ title, description, closeText });
|
||||
}
|
||||
}, [title, description, closeText]);
|
||||
return (
|
||||
<Transition show={open} as={Fragment}>
|
||||
<Dialog as="div" className={clsx(className, "fixed inset-0 z-50 overflow-y-auto")} onClose={onClose}>
|
||||
<div className="flex min-h-screen items-end justify-center px-4 pb-20 pt-4 text-center sm:block sm:p-0">
|
||||
<TransitionChild
|
||||
as={Fragment}
|
||||
enter="ease-out duration-300"
|
||||
enterFrom="opacity-0"
|
||||
enterTo="opacity-100"
|
||||
leave="ease-in duration-200"
|
||||
leaveFrom="opacity-100"
|
||||
leaveTo="opacity-0"
|
||||
>
|
||||
<DialogBackdrop className="fixed inset-0 bg-gray-500/75 transition-opacity" />
|
||||
</TransitionChild>
|
||||
|
||||
{/* This element is to trick the browser into centering the modal contents. */}
|
||||
<span className="hidden sm:inline-block sm:h-screen sm:align-middle" aria-hidden="true">
|
||||
​
|
||||
</span>
|
||||
<TransitionChild
|
||||
as={Fragment}
|
||||
enter="ease-out duration-300"
|
||||
enterFrom="opacity-0 translate-y-4 sm:translate-y-0 sm:scale-95"
|
||||
enterTo="opacity-100 translate-y-0 sm:scale-100"
|
||||
leave="ease-in duration-200"
|
||||
leaveFrom="opacity-100 translate-y-0 sm:scale-100"
|
||||
leaveTo="opacity-0 translate-y-4 sm:translate-y-0 sm:scale-95"
|
||||
>
|
||||
{/* Subframe ResultDialog layout: flex-col items-center gap-6, rounded-lg, px-6 py-8, icon badge h-14 w-14 rounded-round, content gap-2, full-width button. */}
|
||||
<DialogPanel className="bg-surface-neutral-modal flex w-full max-w-full transform flex-col items-center gap-6 overflow-hidden rounded-lg px-6 py-8 text-left align-bottom shadow-xl transition-all sm:my-8 sm:w-96 sm:align-middle">
|
||||
<div className="flex h-14 w-14 flex-none items-center justify-center rounded-round bg-red-100">
|
||||
<AlertTriangleIcon className="h-6 w-6 text-red-600" />
|
||||
</div>
|
||||
<div className="flex w-full flex-col items-center gap-2 text-center">
|
||||
<DialogTitle as="h3" className="text-text-neutral-primary text-lg font-medium leading-6">
|
||||
{data?.title}
|
||||
</DialogTitle>
|
||||
<p className="text-text-neutral-tertiary text-sm">{data?.description}</p>
|
||||
</div>
|
||||
<div className="w-full">
|
||||
<button
|
||||
type="button"
|
||||
className="bg-brand-brand-surface-solid-default text-text-neutral-on-solid hover:bg-brand-brand-surface-solid-hover mt-0 inline-flex w-full justify-center rounded-md border border-transparent px-4 py-2 text-sm font-medium shadow-2xs focus:outline-hidden focus:shadow-focus"
|
||||
onClick={onClose}
|
||||
>
|
||||
{data?.closeText ?? t("shared.close")}
|
||||
</button>
|
||||
</div>
|
||||
</DialogPanel>
|
||||
</TransitionChild>
|
||||
</div>
|
||||
</Dialog>
|
||||
</Transition>
|
||||
);
|
||||
}
|
||||
+54
@@ -0,0 +1,54 @@
|
||||
import { ReactNode, Fragment } from "react";
|
||||
import { Dialog, DialogBackdrop, DialogPanel, Transition, TransitionChild } from "@headlessui/react";
|
||||
import clsx from "clsx";
|
||||
|
||||
interface Props {
|
||||
children: ReactNode;
|
||||
onClose: () => void;
|
||||
className?: string;
|
||||
}
|
||||
export default function OpenModal({ children, onClose, className = "sm:max-w-3xl" }: Props) {
|
||||
return (
|
||||
<Transition show={true} as={Fragment}>
|
||||
<Dialog as="div" className="fixed inset-0 z-50 overflow-y-auto" onClose={onClose}>
|
||||
<div className="flex min-h-screen items-end justify-center px-4 pb-20 pt-4 text-center sm:block sm:p-0">
|
||||
<TransitionChild
|
||||
as={Fragment}
|
||||
enter="ease-out duration-300"
|
||||
enterFrom="opacity-0"
|
||||
enterTo="opacity-100"
|
||||
leave="ease-in duration-200"
|
||||
leaveFrom="opacity-100"
|
||||
leaveTo="opacity-0"
|
||||
>
|
||||
<DialogBackdrop className={clsx("fixed inset-0 bg-gray-500/75 transition-opacity")} />
|
||||
</TransitionChild>
|
||||
|
||||
{/* This element is to trick the browser into centering the modal contents. */}
|
||||
<span className="hidden sm:inline-block sm:h-screen sm:align-middle" aria-hidden="true">
|
||||
​
|
||||
</span>
|
||||
<TransitionChild
|
||||
as={Fragment}
|
||||
enter="ease-out duration-300"
|
||||
enterFrom="opacity-0 translate-y-4 sm:translate-y-0 sm:scale-95"
|
||||
enterTo="opacity-100 translate-y-0 sm:scale-100"
|
||||
leave="ease-in duration-200"
|
||||
leaveFrom="opacity-100 translate-y-0 sm:scale-100"
|
||||
leaveTo="opacity-0 translate-y-4 sm:translate-y-0 sm:scale-95"
|
||||
>
|
||||
<DialogPanel
|
||||
className={clsx(
|
||||
className,
|
||||
// Subframe ModalBlank panel radius: rounded-md. Kept: overflow-visible (poppers escape panel), padding + sm:p-6, headlessui transitions.
|
||||
"bg-surface-neutral-modal relative inline-block w-full transform overflow-visible rounded-md px-4 pb-4 pt-5 text-left align-bottom shadow-xl transition-all sm:my-8 sm:w-full sm:p-6 sm:align-middle"
|
||||
)}
|
||||
>
|
||||
{children}
|
||||
</DialogPanel>
|
||||
</TransitionChild>
|
||||
</div>
|
||||
</Dialog>
|
||||
</Transition>
|
||||
);
|
||||
}
|
||||
+80
@@ -0,0 +1,80 @@
|
||||
import { Fragment, useEffect, useState } from "react";
|
||||
import { Dialog, DialogBackdrop, DialogPanel, DialogTitle, Transition, TransitionChild } from "@headlessui/react";
|
||||
import clsx from "clsx";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { CheckCircleIcon } from "~/components/ui/icons/vendor";
|
||||
|
||||
interface Props {
|
||||
title: string;
|
||||
description: string;
|
||||
closeText?: string;
|
||||
open: boolean;
|
||||
onClose: () => void;
|
||||
className?: string;
|
||||
}
|
||||
|
||||
export default function OpenSuccessModal({ title, description, closeText, open, onClose, className }: Props) {
|
||||
const { t } = useTranslation();
|
||||
const [data, setData] = useState<{ title: string; description: string; closeText?: string }>();
|
||||
|
||||
useEffect(() => {
|
||||
if (title && description) {
|
||||
setData({ title, description, closeText });
|
||||
}
|
||||
}, [title, description, closeText]);
|
||||
return (
|
||||
<Transition show={open} as={Fragment}>
|
||||
<Dialog as="div" className={clsx(className, "fixed inset-0 z-50 overflow-y-auto")} onClose={onClose}>
|
||||
<div className="flex min-h-screen items-end justify-center px-4 pb-20 pt-4 text-center sm:block sm:p-0">
|
||||
<TransitionChild
|
||||
as={Fragment}
|
||||
enter="ease-out duration-300"
|
||||
enterFrom="opacity-0"
|
||||
enterTo="opacity-100"
|
||||
leave="ease-in duration-200"
|
||||
leaveFrom="opacity-100"
|
||||
leaveTo="opacity-0"
|
||||
>
|
||||
<DialogBackdrop className="fixed inset-0 bg-gray-500/75 transition-opacity" />
|
||||
</TransitionChild>
|
||||
|
||||
{/* This element is to trick the browser into centering the modal contents. */}
|
||||
<span className="hidden sm:inline-block sm:h-screen sm:align-middle" aria-hidden="true">
|
||||
​
|
||||
</span>
|
||||
<TransitionChild
|
||||
as={Fragment}
|
||||
enter="ease-out duration-300"
|
||||
enterFrom="opacity-0 translate-y-4 sm:translate-y-0 sm:scale-95"
|
||||
enterTo="opacity-100 translate-y-0 sm:scale-100"
|
||||
leave="ease-in duration-200"
|
||||
leaveFrom="opacity-100 translate-y-0 sm:scale-100"
|
||||
leaveTo="opacity-0 translate-y-4 sm:translate-y-0 sm:scale-95"
|
||||
>
|
||||
{/* Subframe ResultDialog layout: flex-col items-center gap-6, rounded-lg, px-6 py-8, icon badge h-14 w-14 rounded-round, content gap-2, full-width button. */}
|
||||
<DialogPanel className="bg-surface-neutral-modal flex w-full max-w-full transform flex-col items-center gap-6 overflow-hidden rounded-lg px-6 py-8 text-left align-bottom shadow-xl transition-all sm:my-8 sm:w-96 sm:align-middle">
|
||||
<div className="flex h-14 w-14 flex-none items-center justify-center rounded-round bg-green-100">
|
||||
<CheckCircleIcon className="h-6 w-6 text-green-600" />
|
||||
</div>
|
||||
<div className="flex w-full flex-col items-center gap-2 text-center">
|
||||
<DialogTitle as="h3" className="text-text-neutral-primary text-lg font-medium leading-6">
|
||||
{data?.title}
|
||||
</DialogTitle>
|
||||
<p className="text-text-neutral-tertiary text-sm">{data?.description}</p>
|
||||
</div>
|
||||
<div className="w-full">
|
||||
<button
|
||||
type="button"
|
||||
className="bg-brand-brand-surface-solid-default text-text-neutral-on-solid hover:bg-brand-brand-surface-solid-hover mt-0 inline-flex w-full justify-center rounded-md border border-transparent px-4 py-2 text-sm font-medium shadow-2xs focus:outline-hidden focus:shadow-focus"
|
||||
onClick={onClose}
|
||||
>
|
||||
{data?.closeText ?? t("shared.close")}
|
||||
</button>
|
||||
</div>
|
||||
</DialogPanel>
|
||||
</TransitionChild>
|
||||
</div>
|
||||
</Dialog>
|
||||
</Transition>
|
||||
);
|
||||
}
|
||||
+60
@@ -0,0 +1,60 @@
|
||||
import { useRef, useState } from "react";
|
||||
import { t as i18nT } from "i18next";
|
||||
import ButtonSecondary from "../buttons/ButtonSecondary";
|
||||
import SuccessModal, { RefSuccessModal } from "./SuccessModal";
|
||||
import ErrorModal, { RefErrorModal } from "./ErrorModal";
|
||||
import ConfirmModal, { RefConfirmModal } from "./ConfirmModal";
|
||||
import Modal from "./Modal";
|
||||
|
||||
export default function PreviewModals() {
|
||||
const successModal = useRef<RefSuccessModal>(null);
|
||||
const errorModal = useRef<RefErrorModal>(null);
|
||||
const confirmModal = useRef<RefConfirmModal>(null);
|
||||
|
||||
const [open, setOpen] = useState(false);
|
||||
|
||||
function showSuccessModal() {
|
||||
successModal.current?.show(i18nT("components.modals.preview.title"), i18nT("components.modals.preview.description"));
|
||||
}
|
||||
function showErrorModal() {
|
||||
errorModal.current?.show(i18nT("components.modals.preview.title"), i18nT("components.modals.preview.description"));
|
||||
}
|
||||
function showConfirmModal() {
|
||||
confirmModal.current?.setValue({ name: i18nT("components.modals.preview.sample") });
|
||||
confirmModal.current?.show(
|
||||
i18nT("components.modals.preview.title"),
|
||||
i18nT("shared.confirm"),
|
||||
i18nT("shared.cancel"),
|
||||
i18nT("components.modals.preview.description")
|
||||
);
|
||||
}
|
||||
function onYes(value?: any) {
|
||||
if (value) {
|
||||
alert(i18nT("components.modals.preview.confirmedWithValue", { value: JSON.stringify(value) }));
|
||||
} else {
|
||||
alert(i18nT("components.modals.preview.yes"));
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="border-border bg-background border border-dashed p-6">
|
||||
<div id="modals" className="w-full space-y-2">
|
||||
<div className="mx-auto flex max-w-3xl flex-col items-center justify-center space-y-4 sm:flex-row sm:items-end sm:justify-center sm:space-y-0 sm:space-x-4">
|
||||
<ButtonSecondary onClick={() => showSuccessModal()}>{i18nT("components.modals.preview.success")}</ButtonSecondary>
|
||||
<ButtonSecondary onClick={() => showErrorModal()}>{i18nT("components.modals.preview.error")}</ButtonSecondary>
|
||||
<ButtonSecondary onClick={() => showConfirmModal()}>{i18nT("components.modals.preview.confirm")}</ButtonSecondary>
|
||||
<ButtonSecondary onClick={() => setOpen(!open)}>{i18nT("components.modals.preview.empty")}</ButtonSecondary>
|
||||
</div>
|
||||
<SuccessModal ref={successModal} onClosed={() => alert(i18nT("components.modals.preview.closedSuccess"))} />
|
||||
<ErrorModal ref={errorModal} onClosed={() => alert(i18nT("components.modals.preview.closedError"))} />
|
||||
<ConfirmModal ref={confirmModal} onNo={() => alert(i18nT("components.modals.preview.no"))} onYes={onYes} />
|
||||
<Modal open={open} setOpen={setOpen}>
|
||||
{i18nT("components.modals.preview.contentHere")}
|
||||
</Modal>
|
||||
{/* <Modal ref={emptyModal}>
|
||||
<div>{i18nT("components.catalog.yourContentHere")}</div>
|
||||
</Modal> */}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
+92
@@ -0,0 +1,92 @@
|
||||
import { forwardRef, Fragment, Ref, useEffect, useImperativeHandle, useState } from "react";
|
||||
import { Dialog, DialogBackdrop, DialogPanel, DialogTitle, Transition, TransitionChild } from "@headlessui/react";
|
||||
import clsx from "clsx";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { CheckCircleIcon } from "~/components/ui/icons/vendor";
|
||||
|
||||
export interface RefSuccessModal {
|
||||
show: (title?: string, description?: string) => void;
|
||||
}
|
||||
|
||||
interface Props {
|
||||
className?: string;
|
||||
onClosed?: () => void;
|
||||
}
|
||||
|
||||
const SuccessModal = ({ className, onClosed }: Props, ref: Ref<RefSuccessModal>) => {
|
||||
const { t } = useTranslation();
|
||||
|
||||
const [open, setOpen] = useState(false);
|
||||
const [title, setTitle] = useState<string>();
|
||||
const [description, setDescription] = useState<string>();
|
||||
|
||||
const [closeText, setCloseText] = useState<string>();
|
||||
|
||||
useEffect(() => {
|
||||
setTitle(t("shared.success").toString());
|
||||
setCloseText(t("shared.close"));
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, []);
|
||||
|
||||
function close() {
|
||||
setOpen(false);
|
||||
if (onClosed) {
|
||||
onClosed();
|
||||
}
|
||||
}
|
||||
|
||||
useImperativeHandle(ref, () => ({ show }));
|
||||
|
||||
function show(_title?: string, _description?: string) {
|
||||
if (_title) {
|
||||
setTitle(_title);
|
||||
}
|
||||
if (_description) {
|
||||
setDescription(_description);
|
||||
}
|
||||
setOpen(true);
|
||||
}
|
||||
return (
|
||||
<Dialog open={open} onClose={setOpen} className="fixed inset-0 z-50 overflow-y-auto transition duration-300 ease-out data-[closed]:opacity-0" transition>
|
||||
<div className="flex min-h-screen items-end justify-center px-4 pt-4 pb-20 text-center sm:block sm:p-0">
|
||||
{/* <TransitionChild
|
||||
as={Fragment}
|
||||
enter="ease-out duration-300"
|
||||
enterFrom="opacity-0"
|
||||
enterTo="opacity-100"
|
||||
leave="ease-in duration-200"
|
||||
leaveFrom="opacity-100"
|
||||
leaveTo="opacity-0"
|
||||
>
|
||||
</TransitionChild> */}
|
||||
<DialogBackdrop className="fixed inset-0 bg-gray-500/75 transition-opacity" />
|
||||
|
||||
<div className="fixed inset-0 flex w-screen items-center justify-center p-4">
|
||||
{/* Subframe ResultDialog layout: flex-col items-center gap-6, rounded-lg, px-6 py-8, icon badge h-14 w-14 rounded-round, content gap-2, full-width button. */}
|
||||
<DialogPanel className="bg-surface-neutral-modal flex w-full max-w-full transform flex-col items-center gap-6 overflow-hidden rounded-lg px-6 py-8 text-left align-bottom shadow-xl transition-all sm:my-8 sm:w-96 sm:align-middle">
|
||||
<div className="flex h-14 w-14 flex-none items-center justify-center rounded-round bg-green-100">
|
||||
<CheckCircleIcon className="h-6 w-6 text-green-600" />
|
||||
</div>
|
||||
<div className="flex w-full flex-col items-center gap-2 text-center">
|
||||
<DialogTitle as="h3" className="text-text-neutral-primary text-lg leading-6 font-medium">
|
||||
{title}
|
||||
</DialogTitle>
|
||||
<p className="text-text-neutral-tertiary text-sm">{description}</p>
|
||||
</div>
|
||||
<div className="w-full">
|
||||
<button
|
||||
type="button"
|
||||
className="inline-flex w-full justify-center rounded-md border border-transparent bg-teal-600 px-4 py-2 text-base font-medium text-white shadow-2xs hover:bg-teal-700 focus:ring-2 focus:ring-teal-500 focus:ring-offset-2 focus:outline-hidden sm:text-sm"
|
||||
onClick={close}
|
||||
>
|
||||
{closeText}
|
||||
</button>
|
||||
</div>
|
||||
</DialogPanel>
|
||||
</div>
|
||||
</div>
|
||||
</Dialog>
|
||||
);
|
||||
};
|
||||
|
||||
export default forwardRef(SuccessModal);
|
||||
Reference in new issue
Block a user