Basic code editor

This commit is contained in:
2024-06-19 23:36:48 +02:00
parent 21c4a4c582
commit 055176d83b
6 changed files with 99 additions and 97 deletions
+16
View File
@@ -0,0 +1,16 @@
import { AppProps } from 'next/app'
import Head from 'next/head'
import '../globals.css'
function MyApp({ Component, pageProps }: AppProps) {
return (
<>
<Head>
<meta name="viewport" content="width=device-width, initial-scale=1" />
</Head>
<Component {...pageProps} />
</>
)
}
export default MyApp
-10
View File
@@ -1,10 +0,0 @@
import Layout from "./layout"
import CodeEditor from "../components/codeeditor"
export default function JavaCodeEditor() {
return (
<Layout>
<CodeEditor />
</Layout>
)
}
+7
View File
@@ -0,0 +1,7 @@
import CodeEditor from "../../components/codeeditor"
export default function JavaCodeEditor() {
return (
<CodeEditor />
)
}
+2
View File
@@ -72,5 +72,7 @@
} }
body { body {
@apply bg-background text-foreground; @apply bg-background text-foreground;
margin: 0;
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, 'Noto Sans', sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol', 'Noto Color Emoji';
} }
} }
+50 -16
View File
@@ -1,25 +1,59 @@
import { Work_Sans } from 'next/font/google' "use client";
import './globals.css' import { useState, useEffect } from "react"
import Navigation from '@/components/navigation'; import Navigation from "../components/navigation"
import Footer from '@/components/footer'; import Footer from "../components/footer"
import "./globals.css"
const work_sans = Work_Sans({ export default function RootLayout({ children }: { children: React.ReactNode }) {
subsets: ['latin'], const [showButton, setShowButton] = useState(false)
display: 'swap',
variable: '--font-work_sans', useEffect(() => {
}) const handleScroll = () => {
if (window.scrollY > 300) {
setShowButton(true)
} else {
setShowButton(false)
}
}
window.addEventListener("scroll", handleScroll)
return () => {
window.removeEventListener("scroll", handleScroll)
}
}, [])
const scrollToTop = () => {
window.scrollTo({
top: 0,
behavior: "smooth"
})
}
// @ts-ignore
export default function Layout({ children }) {
return ( return (
<html lang="en"> <html lang="en">
<head>
<body className={work_sans.variable}> <style jsx global>{`
<Navigation/> html {
scroll-behavior: smooth;
}
`}</style>
</head>
<body className="flex flex-col min-h-[100dvh] scroll-smooth">
<Navigation />
<main className="flex-1">
{children} {children}
<Footer/> </main>
{showButton && (
<button
onClick={scrollToTop}
className="fixed bottom-10 right-10 bg-primary text-primary-foreground p-3 rounded-full shadow-lg hover:bg-primary-dark transition"
>
↑ Top
</button>
)}
<Footer />
</body> </body>
</html> </html>
) )
} }
+5 -52
View File
@@ -1,47 +1,11 @@
"use client"
import { useState, useEffect } from "react"
import Link from "next/link"
import JavaText from "./java_tutorial.json" import JavaText from "./java_tutorial.json"
export default function Component() { export default function MainPage() {
const JavaContent = JavaText const JavaContent = JavaText
const [showButton, setShowButton] = useState(false)
useEffect(() => {
const handleScroll = () => {
if (window.scrollY > 300) {
setShowButton(true)
} else {
setShowButton(false)
}
}
window.addEventListener("scroll", handleScroll)
return () => {
window.removeEventListener("scroll", handleScroll)
}
}, [])
const scrollToTop = () => {
window.scrollTo({
top: 0,
behavior: "smooth"
})
}
return ( return (
<div className="flex flex-col min-h-[100dvh] scroll-smooth"> <>
<style jsx global>{`
html {
scroll-behavior: smooth;
}
`}</style>
<main className="flex-1">
{JavaContent.sections.map((section, index) => ( {JavaContent.sections.map((section, index) => (
<section key={index} id={section.id} <section key={index} id={section.id} className={`py-12 md:py-24 ${index % 2 === 0 ? 'bg-muted' : ''}`}>
className={`py-12 md:py-24 ${index % 2 === 0 ? 'bg-muted' : ''}`}>
<div className="container mx-auto px-4 md:px-6"> <div className="container mx-auto px-4 md:px-6">
<h2 className="text-3xl font-bold mb-8">{section.title}</h2> <h2 className="text-3xl font-bold mb-8">{section.title}</h2>
<p className="text-lg mb-8">{section.description}</p> <p className="text-lg mb-8">{section.description}</p>
@@ -50,7 +14,7 @@ export default function Component() {
<div key={itemIndex}> <div key={itemIndex}>
<h3 className="text-2xl font-bold mb-4">{item.title}</h3> <h3 className="text-2xl font-bold mb-4">{item.title}</h3>
<p className="text-muted-foreground mb-6">{item.description}</p> <p className="text-muted-foreground mb-6">{item.description}</p>
<div className="bg-background rounded-lg p-6 shadow-2xl my-4"> <div className="bg-background rounded-lg p-6 shadow my-4">
<pre className="text-sm font-mono"> <pre className="text-sm font-mono">
<code className="text-pretty">{item.code}</code> <code className="text-pretty">{item.code}</code>
</pre> </pre>
@@ -62,17 +26,6 @@ export default function Component() {
</div> </div>
</section> </section>
))} ))}
</main> </>
{showButton && (
<button
onClick={scrollToTop}
className="fixed bottom-10 right-10 bg-primary text-primary-foreground p-3 rounded-full shadow-md hover:bg-primary-dark transition"
>
↑ Top
</button>
)}
</div>
) )
} }