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
feat(toast): add a wide variant for content-rich toasts
Elian Doran3c6b7e66da36
diff --git a/apps/client/src/services/frontend_script_api.spec.ts b/apps/client/src/services/frontend_script_api.spec.tsindex 11f5de5566..8824b2423a 100644--- a/apps/client/src/services/frontend_script_api.spec.ts+++ b/apps/client/src/services/frontend_script_api.spec.ts@@ -191,7 +191,7 @@ describe("runOnBackend / __runOnBackendInner", () => {// No server round-trip, and a single deduplicated toast (fixed id) is shown instead of a 500.expect(post).not.toHaveBeenCalled();- expect(showPersistent).toHaveBeenCalledWith(expect.objectContaining({ id: "backend-scripting-disabled" }));+ expect(showPersistent).toHaveBeenCalledWith(expect.objectContaining({ id: "backend-scripting-disabled", wide: true }));// The toast's action opens Security settings in the options modal, not a hoisted tab.const triggerCommand = vi.spyOn(appContext, "triggerCommand").mockReturnValue(undefined as never);@@ -320,7 +320,7 @@ describe("runAsyncOnBackendWithManualTransactionHandling", () => {await expect(makeApi().runAsyncOnBackendWithManualTransactionHandling(async () => {}, [])).rejects.toBeInstanceOf(BackendScriptingDisabledError);expect(post).not.toHaveBeenCalled();- expect(showPersistent).toHaveBeenCalledWith(expect.objectContaining({ id: "backend-scripting-disabled" }));+ expect(showPersistent).toHaveBeenCalledWith(expect.objectContaining({ id: "backend-scripting-disabled", wide: true }));});it("warns when passed a sync function reference, then runs non-transactionally", async () => {diff --git a/apps/client/src/services/frontend_script_api.ts b/apps/client/src/services/frontend_script_api.tsindex 5683684197..6dd9a25c81 100644--- a/apps/client/src/services/frontend_script_api.ts+++ b/apps/client/src/services/frontend_script_api.ts@@ -832,6 +832,7 @@ function showBackendScriptingDisabledToast(noteId: string) {message: t("frontend_script_api.backend_scripting_disabled_message"),notesHeading: t("frontend_script_api.backend_scripting_disabled_notes_heading"),noteIds: [ ...backendScriptingAttempts ],+ wide: true,timeout: 60_000,onRemove: () => backendScriptingAttempts.clear(),buttons: [diff --git a/apps/client/src/services/toast.ts b/apps/client/src/services/toast.tsindex d404495fd9..55587e514a 100644--- a/apps/client/src/services/toast.ts+++ b/apps/client/src/services/toast.ts@@ -18,6 +18,11 @@ export interface ToastOptions {* dismissable × there reads as "cancel", which it isn't. Defaults to dismissable.*/dismissible?: boolean;+ /**+ * When `true`, the toast renders with a wider maximum width than the default. Use for toasts with+ * richer content — e.g. a {@link noteIds} reference-link list — that reads poorly cramped.+ */+ wide?: boolean;/*** Notes to render as reference links in the toast body — e.g. the notes an action affected or that* triggered the message. Each is shown with its icon and title and navigates to the note on click.diff --git a/apps/client/src/widgets/Toast.css b/apps/client/src/widgets/Toast.cssindex 26d5ef5287..c89b136cef 100644--- a/apps/client/src/widgets/Toast.css+++ b/apps/client/src/widgets/Toast.css@@ -18,6 +18,12 @@overflow: hidden;}+/* Wider variant for toasts with richer content (e.g. a reference-note list); capped to the+ viewport so it stays within bounds on narrow screens. */+.toast.wide {+ --bs-toast-max-width: min(500px, 90vw);+}+.toast-header {background-color: var(--more-accented-background-color) !important;color: var(--main-text-color) !important;diff --git a/apps/client/src/widgets/Toast.tsx b/apps/client/src/widgets/Toast.tsxindex 58de016084..4fd61bf1b1 100644--- a/apps/client/src/widgets/Toast.tsx+++ b/apps/client/src/widgets/Toast.tsx@@ -16,7 +16,7 @@ export default function ToastContainer() {);}-function Toast({ id, title, timeout, progress, message, icon, buttons, dismissible, noteIds, notesHeading }: ToastOptionsWithRequiredId) {+function Toast({ id, title, timeout, progress, message, icon, buttons, dismissible, wide, noteIds, notesHeading }: ToastOptionsWithRequiredId) {// Autohide.useEffect(() => {if (!timeout || timeout <= 0) return;@@ -40,7 +40,7 @@ function Toast({ id, title, timeout, progress, message, icon, buttons, dismissibreturn (<div- class={clsx("toast", !title && "no-title", dismissible === false && "not-dismissible")}+ class={clsx("toast", !title && "no-title", dismissible === false && "not-dismissible", wide && "wide")}role="alert" aria-live="assertive" aria-atomic="true"id={`toast-${id}`}>