@@ -7,60 +7,56 @@ import reactElementToJSXString from 'react-element-to-jsx-string';
77import { LiveEditor , LivePreview , LiveProvider } from 'react-live' ;
88
99type ComponentPreviewProps = {
10- title : string ;
10+ caption : string ;
1111 /** @alpha - Passing a React.ReactNode is currently not compatible with React 19, pass a string to make it work with React 19 until react-element-to-jsx-string supports React 19 */
1212 code : React . ReactNode | string ;
13- /** All custom components that are rendered must be present in the scope */
14- scope : Partial < typeof GrunnmurenIconsScope & typeof GrunnmurenScope > ;
1513} ;
1614
17- export const ComponentPreview = ( {
18- title,
19- code,
20- scope,
21- } : ComponentPreviewProps ) => {
15+ export const ComponentPreview = ( { caption, code } : ComponentPreviewProps ) => {
2216 // Keep of the code string in state to be able to copy it
2317 const [ codeString , setCodeString ] = useState (
2418 typeof code === 'string' ? code : reactElementToJSXString ( code ) ,
2519 ) ;
2620
2721 const [ hasCopied , setHasCopied ] = useState ( false ) ;
22+
2823 return (
29- < LiveProvider code = { codeString } scope = { scope } theme = { themes . vsDark } >
30- < div className = "my-8 grid gap-y-4" >
31- < h2 className = "heading-m" > { title } </ h2 >
32- < hr />
33- < LivePreview className = "flex gap-x-4" />
34- < div className = "grid grid-cols-[1fr,auto] grid-rows-[auto,1fr] overflow-hidden rounded-lg bg-[#1e1e1e]" >
35- < LiveEditor
36- tabMode = "focus"
37- // Use the same black color as the background on the editor
38- className = "row-span-2 font-mono"
39- onChange = { ( newCode ) => setCodeString ( newCode ) }
40- />
41- < div className = "relative text-mint" >
42- < GrunnmurenScope . Button
43- onPress = { ( ) =>
44- navigator . clipboard . writeText ( codeString ) . then ( ( ) => {
45- setHasCopied ( true ) ;
46- setTimeout ( ( ) => setHasCopied ( false ) , 2000 ) ; // Reset after 2 seconds
47- } )
48- }
49- variant = "tertiary"
50- >
51- < GrunnmurenIconsScope . Documents />
52- </ GrunnmurenScope . Button >
53- < span
54- className = { cx (
55- 'absolute right-2 top-full transition-opacity duration-100' ,
56- hasCopied ? 'opacity-100' : 'opacity-0' ,
57- ) }
58- aria-hidden = { ! hasCopied }
59- role = "alert"
60- >
61- Kopiert!
62- </ span >
63- </ div >
24+ < LiveProvider
25+ code = { codeString }
26+ scope = { { ...GrunnmurenIconsScope , ...GrunnmurenScope } }
27+ theme = { themes . vsDark }
28+ >
29+ < p > { caption } </ p >
30+ < LivePreview className = "my-4 flex gap-x-4" />
31+ < div className = "grid grid-cols-[1fr,auto] grid-rows-[auto,1fr] overflow-hidden rounded-lg bg-[#1e1e1e]" >
32+ < LiveEditor
33+ tabMode = "focus"
34+ // Use the same black color as the background on the editor
35+ className = "row-span-2 font-mono"
36+ onChange = { ( newCode ) => setCodeString ( newCode ) }
37+ />
38+ < div className = "relative text-mint" >
39+ < GrunnmurenScope . Button
40+ onPress = { ( ) =>
41+ navigator . clipboard . writeText ( codeString ) . then ( ( ) => {
42+ setHasCopied ( true ) ;
43+ setTimeout ( ( ) => setHasCopied ( false ) , 2000 ) ; // Reset after 2 seconds
44+ } )
45+ }
46+ variant = "tertiary"
47+ >
48+ < GrunnmurenIconsScope . Documents />
49+ </ GrunnmurenScope . Button >
50+ < span
51+ className = { cx (
52+ 'absolute right-2 top-full transition-opacity duration-100' ,
53+ hasCopied ? 'opacity-100' : 'opacity-0' ,
54+ ) }
55+ aria-hidden = { ! hasCopied }
56+ role = "alert"
57+ >
58+ Kopiert!
59+ </ span >
6460 </ div >
6561 </ div >
6662 </ LiveProvider >
0 commit comments