mirror of https://github.com/usememos/memos
chore: add `CommonDialog`
parent
5617118fa8
commit
2b8078a19b
@ -0,0 +1,84 @@
|
|||||||
|
import { generateDialog } from "./BaseDialog";
|
||||||
|
import "../../less/common-dialog.less";
|
||||||
|
|
||||||
|
type DialogStyle = "info" | "warning";
|
||||||
|
|
||||||
|
interface Props extends DialogProps {
|
||||||
|
title: string;
|
||||||
|
content: string;
|
||||||
|
style?: DialogStyle;
|
||||||
|
closeBtnText?: string;
|
||||||
|
confirmBtnText?: string;
|
||||||
|
onClose?: () => void;
|
||||||
|
onConfirm?: () => void;
|
||||||
|
}
|
||||||
|
|
||||||
|
const defaultProps = {
|
||||||
|
title: "",
|
||||||
|
content: "",
|
||||||
|
style: "info",
|
||||||
|
closeBtnText: "Close",
|
||||||
|
confirmBtnText: "Confirm",
|
||||||
|
onClose: () => null,
|
||||||
|
onConfirm: () => null,
|
||||||
|
};
|
||||||
|
|
||||||
|
const CommonDialog: React.FC<Props> = (props: Props) => {
|
||||||
|
const { title, content, destroy, closeBtnText, confirmBtnText, onClose, onConfirm, style } = {
|
||||||
|
...defaultProps,
|
||||||
|
...props,
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleCloseBtnClick = () => {
|
||||||
|
onClose();
|
||||||
|
destroy();
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleConfirmBtnClick = async () => {
|
||||||
|
onConfirm();
|
||||||
|
destroy();
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<div className="dialog-header-container">
|
||||||
|
<p className="title-text">{title}</p>
|
||||||
|
<button className="btn close-btn" onClick={handleCloseBtnClick}>
|
||||||
|
<i className="fa-solid fa-xmark fa-lg"></i>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
<div className="dialog-content-container">
|
||||||
|
<p className="content-text">{content}</p>
|
||||||
|
<div className="btns-container">
|
||||||
|
<span className="btn cancel-btn" onClick={handleCloseBtnClick}>
|
||||||
|
{closeBtnText}
|
||||||
|
</span>
|
||||||
|
<span className={`btn confirm-btn ${style}`} onClick={handleConfirmBtnClick}>
|
||||||
|
{confirmBtnText}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
interface CommonDialogProps {
|
||||||
|
title: string;
|
||||||
|
content: string;
|
||||||
|
className?: string;
|
||||||
|
style?: DialogStyle;
|
||||||
|
closeBtnText?: string;
|
||||||
|
confirmBtnText?: string;
|
||||||
|
onClose?: () => void;
|
||||||
|
onConfirm?: () => void;
|
||||||
|
}
|
||||||
|
|
||||||
|
export const showCommonDialog = (props: CommonDialogProps) => {
|
||||||
|
generateDialog(
|
||||||
|
{
|
||||||
|
className: `common-dialog ${props?.className ?? ""}`,
|
||||||
|
},
|
||||||
|
CommonDialog,
|
||||||
|
props
|
||||||
|
);
|
||||||
|
};
|
@ -0,0 +1 @@
|
|||||||
|
export { generateDialog } from "./BaseDialog";
|
@ -0,0 +1,40 @@
|
|||||||
|
@import "./mixin.less";
|
||||||
|
|
||||||
|
.dialog-wrapper {
|
||||||
|
@apply fixed top-0 left-0 flex flex-col justify-start items-center w-full h-full pt-16 z-100 overflow-x-hidden overflow-y-scroll bg-transparent transition-all;
|
||||||
|
.hide-scroll-bar();
|
||||||
|
|
||||||
|
&.showup {
|
||||||
|
background-color: rgba(0, 0, 0, 0.6);
|
||||||
|
}
|
||||||
|
|
||||||
|
&.showoff {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
> .dialog-container {
|
||||||
|
@apply flex flex-col justify-start items-start bg-white p-4 rounded-lg;
|
||||||
|
|
||||||
|
> .dialog-header-container {
|
||||||
|
@apply flex flex-row justify-between items-center w-full mb-4;
|
||||||
|
|
||||||
|
> .title-text {
|
||||||
|
> .icon-text {
|
||||||
|
@apply mr-2 text-base;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.btn {
|
||||||
|
@apply flex flex-col justify-center items-center w-6 h-6 rounded hover:bg-gray-100 hover:shadow;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
> .dialog-content-container {
|
||||||
|
@apply flex flex-col justify-start items-start w-full;
|
||||||
|
}
|
||||||
|
|
||||||
|
> .dialog-footer-container {
|
||||||
|
@apply flex flex-row justify-end items-center w-full mt-4;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,31 @@
|
|||||||
|
@import "./mixin.less";
|
||||||
|
|
||||||
|
.common-dialog {
|
||||||
|
> .dialog-container {
|
||||||
|
@apply w-80;
|
||||||
|
|
||||||
|
> .dialog-content-container {
|
||||||
|
@apply flex flex-col justify-start items-start;
|
||||||
|
|
||||||
|
> .content-text {
|
||||||
|
@apply pt-2;
|
||||||
|
}
|
||||||
|
|
||||||
|
> .btns-container {
|
||||||
|
@apply flex flex-row justify-end items-center w-full mt-3;
|
||||||
|
|
||||||
|
> .btn {
|
||||||
|
@apply text-sm py-1 px-3 mr-2 rounded-md hover:opacity-80;
|
||||||
|
|
||||||
|
&.confirm-btn {
|
||||||
|
@apply bg-red-100 border border-solid border-blue-600 text-blue-600;
|
||||||
|
|
||||||
|
&.warning {
|
||||||
|
@apply border-red-600 text-red-600;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,36 +0,0 @@
|
|||||||
@import "./mixin.less";
|
|
||||||
|
|
||||||
.confirm-reset-openid-dialog {
|
|
||||||
> .dialog-container {
|
|
||||||
@apply w-80;
|
|
||||||
|
|
||||||
> .dialog-content-container {
|
|
||||||
.flex(column, flex-start, flex-start);
|
|
||||||
|
|
||||||
> .warn-text {
|
|
||||||
@apply pt-2;
|
|
||||||
}
|
|
||||||
|
|
||||||
> .btns-container {
|
|
||||||
.flex(row, flex-end, center);
|
|
||||||
@apply w-full mt-3;
|
|
||||||
|
|
||||||
> .btn {
|
|
||||||
@apply text-sm py-1 px-3 mr-2 rounded-md;
|
|
||||||
|
|
||||||
&:hover {
|
|
||||||
@apply opacity-80;
|
|
||||||
}
|
|
||||||
|
|
||||||
&.confirm-btn {
|
|
||||||
@apply bg-red-100 border border-solid border-red-600 text-red-600;
|
|
||||||
|
|
||||||
&.loading {
|
|
||||||
@apply opacity-80 cursor-wait;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,46 +0,0 @@
|
|||||||
@import "./mixin.less";
|
|
||||||
|
|
||||||
.dialog-wrapper {
|
|
||||||
.flex(column, flex-start, center);
|
|
||||||
@apply fixed top-0 left-0 w-full h-full pt-16 z-100 overflow-x-hidden overflow-y-scroll bg-transparent transition-all;
|
|
||||||
.hide-scroll-bar();
|
|
||||||
|
|
||||||
&.showup {
|
|
||||||
background-color: rgba(0, 0, 0, 0.6);
|
|
||||||
}
|
|
||||||
|
|
||||||
&.showoff {
|
|
||||||
display: none;
|
|
||||||
}
|
|
||||||
|
|
||||||
> .dialog-container {
|
|
||||||
.flex(column, flex-start, flex-start);
|
|
||||||
@apply bg-white p-4 rounded-lg;
|
|
||||||
|
|
||||||
> .dialog-header-container {
|
|
||||||
.flex(row, space-between, center);
|
|
||||||
@apply w-full mb-4;
|
|
||||||
|
|
||||||
> .title-text {
|
|
||||||
> .icon-text {
|
|
||||||
@apply mr-2 text-base;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
.btn {
|
|
||||||
.flex(column, center, center);
|
|
||||||
@apply w-6 h-6 rounded hover:bg-gray-100 hover:shadow;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
> .dialog-content-container {
|
|
||||||
.flex(column, flex-start, flex-start);
|
|
||||||
@apply w-full;
|
|
||||||
}
|
|
||||||
|
|
||||||
> .dialog-footer-container {
|
|
||||||
.flex(row, flex-end, center);
|
|
||||||
@apply w-full mt-4;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in New Issue