@@ -2,15 +2,16 @@ import toast, {
22 type Toast ,
33 ToastBar ,
44 Toaster as ReactHotToast ,
5+ resolveValue ,
56 type Renderable ,
67} from 'react-hot-toast' ;
78import { FaCopy , FaTimes } from 'react-icons/fa' ;
8- import { useTheme } from 'styled-components' ;
9+ import styled , { useTheme } from 'styled-components' ;
910import { zIndex } from '../styling' ;
1011import { Row } from './Row' ;
1112import { IconButton } from './IconButton/IconButton' ;
1213
13- import type { JSX } from 'react' ;
14+ import { useRef , type JSX } from 'react' ;
1415
1516/**
1617 * Makes themed toast notifications available in the Context. Render this
@@ -59,31 +60,28 @@ interface ToastMessageProps {
5960}
6061
6162function ToastMessage ( { icon, message, t } : ToastMessageProps ) {
62- let text : string ;
63-
64- if ( typeof message === 'string' ) {
65- text = message ;
66- } else if ( message && 'props' in message ) {
67- // children can technically still be a react node but we never do that in our code so we'll just assume it to be a string.
68- text = message . props . children ;
69- } else {
70- text = '' ;
71- }
63+ const textRef = useRef < HTMLDivElement > ( null ) ;
7264
7365 function handleCopy ( ) {
66+ const text = textRef . current ?. textContent ;
67+
68+ if ( text === undefined ) {
69+ toast . error ( 'Nothing to copy.' ) ;
70+
71+ return ;
72+ }
73+
7474 toast . success ( 'Copied error to clipboard' ) ;
7575 navigator . clipboard . writeText ( text ) ;
7676 toast . dismiss ( t . id ) ;
7777 }
7878
79- if ( text . length > 100 ) {
80- text = text . substring ( 0 , 100 ) + '...' ;
81- }
82-
8379 return (
84- < Row gap = '1ch' center >
80+ < StyledRow gap = '1ch' center >
8581 { icon }
86- { text }
82+ < div ref = { textRef } style = { { display : 'contents' } } >
83+ { resolveValue ( message , t ) }
84+ </ div >
8785 { t . type !== 'loading' && (
8886 < div
8987 style = { {
@@ -101,6 +99,11 @@ function ToastMessage({ icon, message, t }: ToastMessageProps) {
10199 ) }
102100 </ div >
103101 ) }
104- </ Row >
102+ </ StyledRow >
105103 ) ;
106104}
105+
106+ const StyledRow = styled ( Row ) `
107+ max-height: 10rem;
108+ overflow-y: auto;
109+ ` ;
0 commit comments