@@ -6,10 +6,11 @@ import { CH } from "@code-hike/mdx/components";
6
6
import "@code-hike/mdx/styles.css" ;
7
7
import { ErrorBoundary } from "react-error-boundary" ;
8
8
import { getTheme } from "./themes" ;
9
+ import { toHash } from "./hash" ;
9
10
10
11
export function Preview ( props ) {
11
12
return (
12
- < div className = " preview" >
13
+ < div className = { ` preview ${ props . standalone ? "standalone" : "" } ` } >
13
14
< ErrorBoundary
14
15
resetKeys = { [ props . input . mdx , props . input . css , props . input . config ] }
15
16
FallbackComponent = { ErrorFallback }
@@ -28,7 +29,7 @@ function ErrorFallback({ error }) {
28
29
) ;
29
30
}
30
31
31
- function InnerPreview ( { input } ) {
32
+ function InnerPreview ( { input, standalone } ) {
32
33
const [ Content , setContent ] = useState ( undefined ) ;
33
34
const [ error , setError ] = useState ( undefined ) ;
34
35
useEffect ( ( ) => {
@@ -67,9 +68,57 @@ function InnerPreview({ input }) {
67
68
< pre > { error } </ pre >
68
69
</ div >
69
70
) : 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
+ ) }
70
80
< div className = { `preview-container ${ error ? "with-error" : "" } ` } >
71
81
{ Content ? < Content components = { { CH } } /> : null }
72
82
</ div >
73
83
</ >
74
84
) ;
75
85
}
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