@@ -6,10 +6,11 @@ import { CH } from "@code-hike/mdx/components";
66import "@code-hike/mdx/styles.css" ;
77import { ErrorBoundary } from "react-error-boundary" ;
88import { getTheme } from "./themes" ;
9+ import { toHash } from "./hash" ;
910
1011export function Preview ( props ) {
1112 return (
12- < div className = " preview" >
13+ < div className = { ` preview ${ props . standalone ? "standalone" : "" } ` } >
1314 < ErrorBoundary
1415 resetKeys = { [ props . input . mdx , props . input . css , props . input . config ] }
1516 FallbackComponent = { ErrorFallback }
@@ -28,7 +29,7 @@ function ErrorFallback({ error }) {
2829 ) ;
2930}
3031
31- function InnerPreview ( { input } ) {
32+ function InnerPreview ( { input, standalone } ) {
3233 const [ Content , setContent ] = useState ( undefined ) ;
3334 const [ error , setError ] = useState ( undefined ) ;
3435 useEffect ( ( ) => {
@@ -67,9 +68,57 @@ function InnerPreview({ input }) {
6768 < pre > { error } </ pre >
6869 </ div >
6970 ) : null }
71+ { standalone ? (
72+ < a href = { `/#${ toHash ( input ) } ` } className = "standalone-link" >
73+ < PlaygroundIcon />
74+ </ a >
75+ ) : (
76+ < a href = { `/?preview=1#${ toHash ( input ) } ` } className = "standalone-link" >
77+ < ExternalIcon />
78+ </ a >
79+ ) }
7080 < div className = { `preview-container ${ error ? "with-error" : "" } ` } >
7181 { Content ? < Content components = { { CH } } /> : null }
7282 </ div >
7383 </ >
7484 ) ;
7585}
86+
87+ function ExternalIcon ( ) {
88+ return (
89+ < svg
90+ className = "icon"
91+ fill = "none"
92+ stroke = "currentColor"
93+ viewBox = "0 0 24 24"
94+ xmlns = "http://www.w3.org/2000/svg"
95+ >
96+ < title > Open in new window</ title >
97+ < path
98+ strokeLinecap = "round"
99+ strokeLinejoin = "round"
100+ strokeWidth = { 2 }
101+ d = "M10 6H6a2 2 0 00-2 2v10a2 2 0 002 2h10a2 2 0 002-2v-4M14 4h6m0 0v6m0-6L10 14"
102+ />
103+ </ svg >
104+ ) ;
105+ }
106+ function PlaygroundIcon ( ) {
107+ return (
108+ < svg
109+ className = "icon"
110+ fill = "none"
111+ stroke = "currentColor"
112+ viewBox = "0 0 24 24"
113+ xmlns = "http://www.w3.org/2000/svg"
114+ >
115+ < title > Open playground</ title >
116+ < path
117+ strokeLinecap = "round"
118+ strokeLinejoin = "round"
119+ strokeWidth = { 2 }
120+ d = "M10 20l4-16m4 4l4 4-4 4M6 16l-4-4 4-4"
121+ />
122+ </ svg >
123+ ) ;
124+ }
0 commit comments