@@ -2,11 +2,17 @@ import classNames from "classnames";
22import "./ConsoleMirror.css" ;
33import { useLayoutEffect , useRef } from "react" ;
44import useStayScrolled from "react-stay-scrolled" ;
5- import { Badge } from "@stratakit/bricks" ;
6- import { caretDown , caretUp , statusError , statusWarning } from "./icons" ;
5+ import { Badge , Button } from "@stratakit/bricks" ;
6+ import {
7+ caretDown ,
8+ caretUp ,
9+ deleteIcon ,
10+ statusError ,
11+ statusWarning ,
12+ } from "./icons" ;
713import { Icon } from "@stratakit/foundations" ;
814
9- export type ConsoleMessageType = "log" | "warn" | "error" ;
15+ export type ConsoleMessageType = "log" | "warn" | "error" | "special" ;
1016export type ConsoleMessage = {
1117 type : ConsoleMessageType ;
1218 message : string ;
@@ -27,10 +33,12 @@ export function ConsoleMirror({
2733 logs,
2834 expanded : consoleExpanded ,
2935 toggleExpanded,
36+ resetConsole,
3037} : {
3138 logs : ConsoleMessage [ ] ;
3239 expanded : boolean ;
3340 toggleExpanded : ( ) => void ;
41+ resetConsole : ( options ?: { showMessage ?: boolean } ) => void ;
3442} ) {
3543 const logsRef = useRef < HTMLDivElement > ( document . createElement ( "div" ) ) ;
3644 // TODO: determine if we need this lib or can implement ourselves. It's a little outdated
@@ -64,6 +72,19 @@ export function ConsoleMirror({
6472 { errors . length > 0 && (
6573 < Badge label = { errors . length } tone = "critical" variant = "muted" />
6674 ) }
75+ < div className = "spacer" > </ div >
76+ < Button
77+ className = "clear-button"
78+ variant = "ghost"
79+ onClick = { ( e ) => {
80+ e . preventDefault ( ) ;
81+ e . stopPropagation ( ) ;
82+ resetConsole ( { showMessage : true } ) ;
83+ } }
84+ >
85+ < Icon href = { deleteIcon } />
86+ Clear console
87+ </ Button >
6788 </ div >
6889 < div className = "logs" ref = { logsRef } >
6990 { logs . length === 0 && (
@@ -79,6 +100,7 @@ export function ConsoleMirror({
79100 className = { classNames ( "message" , {
80101 warning : log . type === "warn" ,
81102 error : log . type === "error" ,
103+ special : log . type === "special" ,
82104 } ) }
83105 >
84106 < ConsoleIcon type = { log . type } />
0 commit comments