Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
client/dialogs: add support for custom title bar buttons
Adorian Doran07fb5ab01780
diff --git a/apps/client/src/stylesheets/theme-next/dialogs.css b/apps/client/src/stylesheets/theme-next/dialogs.cssindex ed617991c3..768dc55303 100644--- a/apps/client/src/stylesheets/theme-next/dialogs.css+++ b/apps/client/src/stylesheets/theme-next/dialogs.css@@ -25,6 +25,7 @@.modal .modal-header .btn-close,.modal .modal-header .help-button,+.modal .modal-header .custom-title-bar-button,#toast-container .toast .toast-header .btn-close {display: flex;justify-content: center;@@ -55,15 +56,17 @@font-family: boxicons;}-.modal .modal-header .help-button {+.modal .modal-header .help-button,+.modal .modal-header .custom-title-bar-button {margin-inline-end: 0;- font-size: calc(var(--modal-control-button-size) * .75);+ font-size: calc(var(--modal-control-button-size) * .65);font-family: unset;font-weight: bold;}.modal .modal-header .btn-close:hover,.modal .modal-header .help-button:hover,+.modal .modal-header .custom-title-bar-button:hover,#toast-container .toast .toast-header .btn-close:hover {background: var(--modal-control-button-hover-background);color: var(--modal-control-button-hover-color);@@ -71,6 +74,7 @@.modal .modal-header .btn-close:active,.modal .modal-header .help-button:active,+.modal .modal-header .custom-title-bar-button:active,#toast-container .toast .toast-header .btn-close:active {transform: scale(.85);}diff --git a/apps/client/src/widgets/react/Modal.tsx b/apps/client/src/widgets/react/Modal.tsxindex 9c1e4a230f..d28244ac01 100644--- a/apps/client/src/widgets/react/Modal.tsx+++ b/apps/client/src/widgets/react/Modal.tsx@@ -1,3 +1,4 @@+import clsx from "clsx";import { useEffect, useRef, useMemo } from "preact/hooks";import { t } from "../../services/i18n";import { ComponentChildren } from "preact";@@ -7,9 +8,16 @@ import { Modal as BootstrapModal } from "bootstrap";import { memo } from "preact/compat";import { useSyncedRef } from "./hooks";+interface CustomTitleBarButton {+ title: string;+ iconClassName: string;+ onClick: () => void;+}+interface ModalProps {className: string;title: string | ComponentChildren;+ customTitleBarButtons?: (CustomTitleBarButton | null)[];size: "xl" | "lg" | "md" | "sm";children: ComponentChildren;/**@@ -72,7 +80,7 @@ interface ModalProps {noFocus?: boolean;}-export default function Modal({ children, className, size, title, header, footer, footerStyle, footerAlignment, onShown, onSubmit, helpPageId, minWidth, maxWidth, zIndex, scrollable, onHidden: onHidden, modalRef: externalModalRef, formRef, bodyStyle, show, stackable, keepInDom, noFocus }: ModalProps) {+export default function Modal({ children, className, size, title, customTitleBarButtons: titleBarButtons, header, footer, footerStyle, footerAlignment, onShown, onSubmit, helpPageId, minWidth, maxWidth, zIndex, scrollable, onHidden: onHidden, modalRef: externalModalRef, formRef, bodyStyle, show, stackable, keepInDom, noFocus }: ModalProps) {const modalRef = useSyncedRef<HTMLDivElement>(externalModalRef);const modalInstanceRef = useRef<BootstrapModal>();const elementToFocus = useRef<Element | null>();@@ -148,7 +156,17 @@ export default function Modal({ children, className, size, title, header, footer{helpPageId && (<button className="help-button" type="button" data-in-app-help={helpPageId} title={t("modal.help_title")}>?</button>)}++ {titleBarButtons?.filter((b) => b !== null).map((titleBarButton) => (+ <button type="button"+ className={clsx("custom-title-bar-button bx", titleBarButton.iconClassName)}+ title={titleBarButton.title}+ onClick={titleBarButton.onClick}>+ </button>+ ))}+<button type="button" className="btn-close" data-bs-dismiss="modal" aria-label={t("modal.close")}></button>+</div>{onSubmit ? (