add a CodePreview element
This commit is contained in:
parent
2bf4b62082
commit
5a8d7d9071
@ -1,12 +1,13 @@
|
|||||||
import { useState } from "react";
|
import { useState } from "react";
|
||||||
import ImageUpload from "./components/ImageUpload";
|
import ImageUpload from "./components/ImageUpload";
|
||||||
|
import CodePreview from "./components/CodePreview";
|
||||||
|
|
||||||
function App() {
|
function App() {
|
||||||
const [referenceImages, setReferenceImages] = useState<string[]>([]);
|
const [referenceImages, setReferenceImages] = useState<string[]>([]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<div className="mx-auto mt-10 max-w-2xl">
|
||||||
<h1 className="text-2xl">Drag & Drop a Screenshot</h1>
|
<h1 className="text-2xl mb-4">Drag & Drop a Screenshot</h1>
|
||||||
{referenceImages.length > 0 && (
|
{referenceImages.length > 0 && (
|
||||||
<img
|
<img
|
||||||
className="w-[300px]"
|
className="w-[300px]"
|
||||||
@ -15,12 +16,14 @@ function App() {
|
|||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
|
<CodePreview content="Hello World" />
|
||||||
|
|
||||||
{referenceImages.length === 0 && (
|
{referenceImages.length === 0 && (
|
||||||
<>
|
<>
|
||||||
<ImageUpload setReferenceImages={setReferenceImages} />
|
<ImageUpload setReferenceImages={setReferenceImages} />
|
||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
</>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
27
frontend/src/components/CodePreview.tsx
Normal file
27
frontend/src/components/CodePreview.tsx
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
import { useRef, useEffect } from "react";
|
||||||
|
|
||||||
|
interface Props {
|
||||||
|
content: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
function CodePreview({ content }: Props) {
|
||||||
|
const scrollRef = useRef<HTMLDivElement>(null);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (scrollRef.current) {
|
||||||
|
scrollRef.current.scrollLeft = scrollRef.current.scrollWidth;
|
||||||
|
}
|
||||||
|
}, [content]);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
ref={scrollRef}
|
||||||
|
className="w-full px-2 bg-black text-green-400 whitespace-nowrap flex
|
||||||
|
overflow-x-auto font-mono text-[10px]"
|
||||||
|
>
|
||||||
|
{content}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export default CodePreview;
|
||||||
Loading…
Reference in New Issue
Block a user