Skip to content

Commit

Permalink
feat(code glow): code glow screen added
Browse files Browse the repository at this point in the history
  • Loading branch information
yokesh-ks committed Sep 19, 2023
1 parent cd0da2c commit 9b8b476
Show file tree
Hide file tree
Showing 21 changed files with 887 additions and 1 deletion.
9 changes: 8 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,22 +49,29 @@
"cmdk": "^0.2.0",
"commitizen": "^4.2.4",
"cz-conventional-changelog": "^3.3.0",
"flourite": "^1.2.4",
"framer-motion": "^6.3.16",
"highlight.js": "^11.8.0",
"html-to-image": "^1.11.11",
"lucide-react": "^0.274.0",
"next": "^13.4.19",
"next-themes": "^0.2.1",
"pdf-parser": "^1.0.5",
"re-resizable": "^6.9.11",
"react": "^18.2.0",
"react-day-picker": "^8.8.1",
"react-dom": "^18.2.0",
"react-dropzone": "^14.2.3",
"react-hook-form": "^7.46.0",
"react-hot-toast": "^2.4.1",
"react-lottie-player": "^1.5.0",
"react-simple-code-editor": "^0.13.1",
"styled-components": "^5.3.5",
"styled-normalize": "^8.0.7",
"tailwind-merge": "^1.14.0",
"tailwindcss-animate": "^1.0.7",
"webpack": "^5.75.0"
"webpack": "^5.75.0",
"zustand": "^4.4.1"
},
"devDependencies": {
"@svgr/cli": "^6.5.1",
Expand Down
93 changes: 93 additions & 0 deletions pages/code-glow.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
import { useEffect, useRef, useState } from "react";
import CodeEditor from "@/components/code-glow/code-editor";
import { cn } from "@/utils/cn";
import { fonts } from "@/constants/code-fonts";
import { themes } from "@/constants/code-theme";
import useStore from "@/store/store";
import { Resizable } from "re-resizable";
import { Button } from "@/components/ui/button";
// import { ResetIcon } from "@radix-ui/react-icons";
import WidthMeasurement from "@/components/code-glow/width-measurement";
import { Control } from "@/components/code-glow/control";
import Head from "next/head";

export default function CodeGlow() {
const [width, setWidth] = useState("auto");
const [showWidth, setShowWidth] = useState(false);

const theme = useStore((state) => state.theme);
const padding = useStore((state) => state.padding);
const fontStyle = useStore((state) => state.fontStyle);
const showBackground = useStore((state) => state.showBackground);

const editorRef = useRef(null);

useEffect(() => {
const queryParams = new URLSearchParams(location.search);
if (queryParams.size === 0) return;
const state = Object.fromEntries(queryParams);

useStore.setState({
...state,
code: state.code ? atob(state.code) : "",
autoDetectLanguage: state.autoDetectLanguage === "true",
darkMode: state.darkMode === "true",
fontSize: Number(state.fontSize || 18),
padding: Number(state.padding || 64),
});
}, []);

return (
<main className="min-h-screen flex justify-center items-center overflow-scroll">
<Head>
<link
rel="stylesheet"
href={themes[theme].theme}
crossOrigin="anonymous"
/>
<link
rel="stylesheet"
href={fonts[fontStyle].src}
crossOrigin="anonymous"
/>
</Head>

<Resizable
enable={{ left: true, right: true }}
minWidth={padding * 2 + 400}
size={{ width, height: "auto" }}
onResize={(e, dir, ref) => setWidth(ref.offsetWidth.toString())}
onResizeStart={() => setShowWidth(true)}
onResizeStop={() => setShowWidth(false)}
>
<div
className={cn(
"overflow-hidden mb-2 transition-all ease-out",
showBackground
? themes[theme].background
: "ring dark:ring-neutral-900 ring-neutral-100"
)}
style={{ padding }}
ref={editorRef}
>
<CodeEditor />
</div>
<WidthMeasurement showWidth={showWidth} width={width} />
<div
className={cn(
"transition-opacity w-fit mx-auto -mt-4",
showWidth || width === "auto"
? "invisible opacity-0"
: "visible opacity-100"
)}
>
<Button size="sm" onClick={() => setWidth("auto")} variant="ghost">
{/* <ResetIcon className="mr-2" /> */}
Reset width
</Button>
</div>
</Resizable>
<Control editorRef={editorRef} />
</main>
);
}
6 changes: 6 additions & 0 deletions pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ const data = [
iconName: "",
routeName: "font-wise",
},
{
title: "Code Glow",
description: "Illuminate Your Code, Captivate Your Audience",
iconName: "",
routeName: "code-glow",
},
// {
// title: "PDF to WORD",
// description: "Transform Your PDFs into Word Docs in a Snap",
Expand Down
105 changes: 105 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 9b8b476

Please sign in to comment.