From e0a0c868461467afcaf7a0ab158a4ce07e057bc6 Mon Sep 17 00:00:00 2001 From: Tilman Vatteroth Date: Fri, 26 Nov 2021 21:51:12 +0100 Subject: [PATCH] Deduplicate CommonModal Props (#1649) Signed-off-by: Tilman Vatteroth --- src/components/common/modals/common-modal.tsx | 39 ++++++++++++------- .../common/modals/deletion-modal.tsx | 6 +-- .../common/motd-modal/motd-modal.tsx | 2 +- ...atsheet.tsx => cheatsheet-tab-content.tsx} | 4 +- .../app-bar/help-button/help-modal.tsx | 30 +++++++------- .../{links.tsx => links-tab-content.tsx} | 2 +- ...hortcuts.tsx => shortcuts-tab-content.tsx} | 2 +- .../document-info/document-info-modal.tsx | 12 ++---- .../permissions/permission-modal.tsx | 10 ++--- .../document-bar/revisions/revision-modal.tsx | 16 +++----- .../document-bar/share/share-modal.tsx | 10 ++--- .../max-length-warning-modal.tsx | 9 ++--- .../editor-preferences/editor-preferences.tsx | 6 +-- .../table-picker/custom-table-size-modal.tsx | 6 +-- .../sidebar/delete-note-sidebar-entry.tsx | 2 +- .../dropdown-item-with-deletion-modal.tsx | 2 +- .../history-toolbar/clear-history-button.tsx | 2 +- .../version-info/version-info-modal.tsx | 4 +- .../image/image-lightbox-modal.tsx | 28 +++++-------- .../access-tokens/profile-access-tokens.tsx | 4 +- 20 files changed, 91 insertions(+), 105 deletions(-) rename src/components/editor-page/app-bar/help-button/{cheatsheet.tsx => cheatsheet-tab-content.tsx} (95%) rename src/components/editor-page/app-bar/help-button/{links.tsx => links-tab-content.tsx} (98%) rename src/components/editor-page/app-bar/help-button/{shortcuts.tsx => shortcuts-tab-content.tsx} (97%) diff --git a/src/components/common/modals/common-modal.tsx b/src/components/common/modals/common-modal.tsx index 842dd3e2c..1db3067eb 100644 --- a/src/components/common/modals/common-modal.tsx +++ b/src/components/common/modals/common-modal.tsx @@ -4,7 +4,7 @@ * SPDX-License-Identifier: AGPL-3.0-only */ -import React from 'react' +import React, { useMemo } from 'react' import { Modal } from 'react-bootstrap' import { Trans, useTranslation } from 'react-i18next' import { ForkAwesomeIcon } from '../fork-awesome/fork-awesome-icon' @@ -13,31 +13,40 @@ import { ShowIf } from '../show-if/show-if' import type { PropsWithDataCypressId } from '../../../utils/cypress-attribute' import { cypressId } from '../../../utils/cypress-attribute' -export interface CommonModalProps extends PropsWithDataCypressId { +export interface ModalVisibilityProps { show: boolean onHide?: () => void - titleI18nKey?: string +} + +export interface ModalContentProps { title?: string - closeButton?: boolean - icon?: IconName - size?: 'lg' | 'sm' | 'xl' + titleIsI18nKey?: boolean + showCloseButton?: boolean + titleIcon?: IconName + modalSize?: 'lg' | 'sm' | 'xl' additionalClasses?: string } +export type CommonModalProps = PropsWithDataCypressId & ModalVisibilityProps & ModalContentProps + export const CommonModal: React.FC = ({ show, onHide, - titleI18nKey, title, - closeButton, - icon, + showCloseButton, + titleIcon, additionalClasses, - size, + modalSize, children, + titleIsI18nKey = true, ...props }) => { useTranslation() + const titleElement = useMemo(() => { + return titleIsI18nKey ? : {title} + }, [title, titleIsI18nKey]) + return ( = ({ onHide={onHide} animation={true} dialogClassName={`text-dark ${additionalClasses ?? ''}`} - size={size}> - + size={modalSize}> + - - + +   - {titleI18nKey ? : {title}} + {titleElement} {children} diff --git a/src/components/common/modals/deletion-modal.tsx b/src/components/common/modals/deletion-modal.tsx index e1b14059b..93ba72b64 100644 --- a/src/components/common/modals/deletion-modal.tsx +++ b/src/components/common/modals/deletion-modal.tsx @@ -18,17 +18,17 @@ export interface DeletionModalProps extends CommonModalProps { export const DeletionModal: React.FC = ({ show, onHide, - titleI18nKey, + title, onConfirm, deletionButtonI18nKey, - icon, + titleIcon, children, ...props }) => { useTranslation() return ( - + {children}