From 3e1c040ebe68ba429175a3d49a4bbf9db689bea6 Mon Sep 17 00:00:00 2001 From: Xiao Yijun Date: Mon, 20 Jun 2022 20:20:26 +0800 Subject: [PATCH] refactor(console): extract confirm modal component (#1163) --- .../console/src/components/Button/index.tsx | 4 +- .../components/ConfirmModal/index.module.scss | 9 +++ .../src/components/ConfirmModal/index.tsx | 67 ++++++++++--------- .../MultiTextInput/DeleteConfirm.tsx | 44 ------------ .../MultiTextInput/index.module.scss | 12 ---- .../src/components/MultiTextInput/index.tsx | 38 +++++------ .../console/src/pages/GetStarted/index.tsx | 1 + ...=> SignInMethodsChangePreview.module.scss} | 0 ...ert.tsx => SignInMethodsChangePreview.tsx} | 31 ++------- .../components/SignInMethodsPreview.tsx | 2 +- .../src/pages/SignInExperience/index.tsx | 29 ++++---- 11 files changed, 82 insertions(+), 155 deletions(-) create mode 100644 packages/console/src/components/ConfirmModal/index.module.scss delete mode 100644 packages/console/src/components/MultiTextInput/DeleteConfirm.tsx rename packages/console/src/pages/SignInExperience/components/{SaveAlert.module.scss => SignInMethodsChangePreview.module.scss} (100%) rename packages/console/src/pages/SignInExperience/components/{SaveAlert.tsx => SignInMethodsChangePreview.tsx} (55%) diff --git a/packages/console/src/components/Button/index.tsx b/packages/console/src/components/Button/index.tsx index 8c65a18ae..db0765ec7 100644 --- a/packages/console/src/components/Button/index.tsx +++ b/packages/console/src/components/Button/index.tsx @@ -8,9 +8,11 @@ import { Ring as Spinner } from '@/components/Spinner'; import DangerousRaw from '../DangerousRaw'; import * as styles from './index.module.scss'; +export type ButtonType = 'primary' | 'danger' | 'outline' | 'plain' | 'default'; + type BaseProps = Omit, 'type' | 'size' | 'title'> & { htmlType?: 'button' | 'submit' | 'reset'; - type?: 'primary' | 'danger' | 'outline' | 'plain' | 'default'; + type?: ButtonType; size?: 'small' | 'medium' | 'large'; isLoading?: boolean; loadingDelay?: number; diff --git a/packages/console/src/components/ConfirmModal/index.module.scss b/packages/console/src/components/ConfirmModal/index.module.scss new file mode 100644 index 000000000..ede9f85d8 --- /dev/null +++ b/packages/console/src/components/ConfirmModal/index.module.scss @@ -0,0 +1,9 @@ +@use '@/scss/underscore' as _; + +.content { + font: var(--font-body-medium); + + > :not(:first-child) { + margin: _.unit(6) 0; + } +} diff --git a/packages/console/src/components/ConfirmModal/index.tsx b/packages/console/src/components/ConfirmModal/index.tsx index 3bb36a903..122905cb8 100644 --- a/packages/console/src/components/ConfirmModal/index.tsx +++ b/packages/console/src/components/ConfirmModal/index.tsx @@ -1,55 +1,58 @@ import { AdminConsoleKey, I18nKey } from '@logto/phrases'; -import React from 'react'; -import Modal from 'react-modal'; +import classNames from 'classnames'; +import React, { ReactNode } from 'react'; +import ReactModal from 'react-modal'; +import Button, { ButtonType } from '@/components/Button'; import * as modalStyles from '@/scss/modal.module.scss'; -import Button from '../Button'; import ModalLayout from '../ModalLayout'; +import * as styles from './index.module.scss'; -type Props = { - title: AdminConsoleKey; - children: React.ReactNode; +export type ConfirmModalProps = { + children: ReactNode; className?: string; + title?: AdminConsoleKey; + confirmButtonType?: ButtonType; confirmButtonText?: I18nKey; cancelButtonText?: I18nKey; isOpen: boolean; - isPending?: boolean; - onConfirm: () => void; onCancel: () => void; + onConfirm: () => void; }; const ConfirmModal = ({ - title, children, className, + title = 'form.confirm', + confirmButtonType = 'danger', confirmButtonText = 'general.confirm', cancelButtonText = 'general.cancel', isOpen, - isPending, - onConfirm, onCancel, -}: Props) => ( - - -