diff --git a/.changeset/gorgeous-emus-shave.md b/.changeset/gorgeous-emus-shave.md new file mode 100644 index 000000000..43ba28812 --- /dev/null +++ b/.changeset/gorgeous-emus-shave.md @@ -0,0 +1,5 @@ +--- +'@penumbra-zone/ui': patch +--- + +Truncate Toast description diff --git a/packages/ui/src/Toast/open.ts b/packages/ui/src/Toast/open.ts index 2de1cd6a2..36c8e1cde 100644 --- a/packages/ui/src/Toast/open.ts +++ b/packages/ui/src/Toast/open.ts @@ -27,6 +27,10 @@ export interface Toast { dismiss: VoidFunction; } +function truncateString(str: string, maxLength: number): string { + return str.length > maxLength ? `${str.slice(0, maxLength)}...` : str; +} + /** * If `` exists in the document, opens a toast with provided type and options. * By default, the toast is dismissible and has a duration of 4000 milliseconds. It can @@ -72,7 +76,10 @@ export const openToast = (props: ToastProps): Toast => { id = fn(options.message, { id, - description: options.description, + description: + typeof options.description === 'string' + ? truncateString(options.description, 200) + : options.description, closeButton: options.dismissible ?? true, dismissible: options.dismissible ?? true, duration: options.persistent ? Infinity : 4000,