diff --git a/components/DebugStream.tsx b/components/DebugStream.tsx index 0ca72ed..97ea1e3 100644 --- a/components/DebugStream.tsx +++ b/components/DebugStream.tsx @@ -42,6 +42,8 @@ const DebugStream = () => { message, timestamp, jsonData: jsonData?.result, + linkText: 'Expand', + defaultCollapsed: true }; }, []); diff --git a/components/Link.tsx b/components/Link.tsx index 7c688d4..269c892 100644 --- a/components/Link.tsx +++ b/components/Link.tsx @@ -3,6 +3,7 @@ import { styled } from "../stitches.config"; const StyledLink = styled("a", { color: "CurrentColor", textDecoration: "underline", + cursor: 'pointer' }); export default StyledLink; diff --git a/components/LogBox.tsx b/components/LogBox.tsx index 331a8d3..f9d9fab 100644 --- a/components/LogBox.tsx +++ b/components/LogBox.tsx @@ -1,4 +1,4 @@ -import React, { useRef, useLayoutEffect, ReactNode } from "react"; +import { useRef, useLayoutEffect, ReactNode, FC, useState } from "react"; import { Notepad, Prohibit } from "phosphor-react"; import useStayScrolled from "react-stay-scrolled"; import NextLink from "next/link"; @@ -16,7 +16,7 @@ interface ILogBox { enhanced?: boolean; } -const LogBox: React.FC = ({ title, clearLog, logs, children, renderNav, enhanced }) => { +const LogBox: FC = ({ title, clearLog, logs, children, renderNav, enhanced }) => { const logRef = useRef(null); const { stayScrolled /*, scrollBottom*/ } = useStayScrolled(logRef); @@ -117,16 +117,7 @@ const LogBox: React.FC = ({ title, clearLog, logs, children, renderNav, p: enhanced ? "$1" : undefined, }} > - - {log.timestamp && {log.timestamp.toLocaleTimeString()} } - {log.message}{" "} - {log.link && ( - - {log.linkText} - - )} - {log.jsonData && {JSON.stringify(log.jsonData, null, 2)}} - + ))} {children} @@ -136,4 +127,33 @@ const LogBox: React.FC = ({ title, clearLog, logs, children, renderNav, ); }; +export const Log: FC = ({ + type, + timestamp, + message, + link, + linkText, + defaultCollapsed, + jsonData, +}) => { + const [expanded, setExpanded] = useState(!defaultCollapsed); + return ( + + {timestamp && {timestamp.toLocaleTimeString()} } + {message}{" "} + {link && ( + + {linkText} + + )} + {jsonData && ( + setExpanded(!expanded)} as="a"> + {expanded ? "Collapse" : "Expand"} + + )} + {expanded && jsonData && {JSON.stringify(jsonData, null, 2)}} + + ); +}; + export default LogBox; diff --git a/components/LogText.tsx b/components/LogText.tsx index 268ed43..f7408fb 100644 --- a/components/LogText.tsx +++ b/components/LogText.tsx @@ -5,7 +5,6 @@ const Text = styled("span", { lineHeight: "$body", color: "$text", wordWrap: "break-word", - whiteSpace: 'pre-wrap', variants: { variant: { log: { diff --git a/state/index.ts b/state/index.ts index 1ad0034..8d6e18e 100644 --- a/state/index.ts +++ b/state/index.ts @@ -37,6 +37,7 @@ export interface ILog { timestamp?: Date; link?: string; linkText?: string; + defaultCollapsed?: boolean } export interface ISelect {