Skip to content

Commit

Permalink
Add checkbox logic
Browse files Browse the repository at this point in the history
  • Loading branch information
X-SLAYER committed Jan 24, 2024
1 parent 90823b8 commit 4601506
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 117 deletions.
69 changes: 62 additions & 7 deletions src/app/components/Controls.jsx
Original file line number Diff line number Diff line change
@@ -1,38 +1,89 @@
import React from "react";
import React, { useEffect, useState } from "react";

export default function Controls({ onControlChange }) {
const [controls, setControls] = useState({
genJson: false,
genCopyWith: false,
genToString: false,
genJsonKeys: false,
useNumForNumber: false,
useSerializable: false,
useEquatable: false,
useDefaultValue: false,
useRequiredFields: false,
});

const handleCheckboxChange = (event) => {
const { id, checked } = event.target;
console.log(id, checked);
setControls((prevControls) => {
const newControls = { ...prevControls, [id]: checked };
onControlChange(newControls);
return newControls;
});
};

useEffect(() => {
onControlChange(controls);
}, []);

export default function Controls({}) {
return (
<div className="mb-4">
<div id="check-group" className="flex flex-wrap -mx-2">
<div className="flex flex-col w-full px-2 sm:w-1/2">
<label className="flex items-center space-x-2">
<input type="checkbox" className="settings-checkbox" id="gen-json" />
<input
type="checkbox"
className="settings-checkbox"
id="gen-json"
onClick={handleCheckboxChange}
/>
<span>
Generate <span className="font-mono">toJson</span> method
</span>
</label>

<label className="flex items-center space-x-2">
<input type="checkbox" className="settings-checkbox " id="gen-cpy" />
<input
type="checkbox"
className="settings-checkbox "
id="gen-cpy"
onClick={handleCheckboxChange}
/>
<span>
Generate <span className="font-mono">copyWith</span> method
</span>
</label>

<label className="flex items-center space-x-2">
<input type="checkbox" className="settings-checkbox" id="gen-ts" />
<input
type="checkbox"
className="settings-checkbox"
id="gen-ts"
onClick={handleCheckboxChange}
/>
<span>
Generate <span className="font-mono">toString</span> method
</span>
</label>

<label className="flex items-center space-x-2">
<input type="checkbox" className="settings-checkbox" id="gen-key" />
<input
type="checkbox"
className="settings-checkbox"
id="gen-key"
onClick={handleCheckboxChange}
/>
<span>Generate JSON keys</span>
</label>

<label className="flex items-center space-x-2">
<input type="checkbox" className="settings-checkbox" id="use-num" />
<input
type="checkbox"
className="settings-checkbox"
id="use-num"
onClick={handleCheckboxChange}
/>
<span>
Always use <span className="font-mono">num</span> type for number
</span>
Expand All @@ -45,6 +96,7 @@ export default function Controls({}) {
type="checkbox"
className="settings-checkbox"
id="use-serializable"
onClick={handleCheckboxChange}
/>
<span>
Use <span className="font-mono">JSONSerializable</span>
Expand All @@ -56,6 +108,7 @@ export default function Controls({}) {
type="checkbox"
className="settings-checkbox"
id="use-equatable"
onClick={handleCheckboxChange}
/>
<span>
Use <span className="font-mono">Equatable</span>
Expand All @@ -67,6 +120,7 @@ export default function Controls({}) {
type="checkbox"
className="settings-checkbox"
id="use-default-value"
onClick={handleCheckboxChange}
/>
<span>Use default value </span>
</label>
Expand All @@ -76,6 +130,7 @@ export default function Controls({}) {
type="checkbox"
className="settings-checkbox"
id="use-required-fields"
onClick={handleCheckboxChange}
/>
<span>Use required fields</span>
</label>
Expand Down
16 changes: 13 additions & 3 deletions src/app/editor/page.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,24 @@
import dynamic from "next/dynamic";
import AppBar from "../components/AppBar";
import Controls from "../components/Controls";
import { useState } from "react";

const Editor = dynamic(() => import("../components/Editor"), { ssr: false });

const ProgrammingEditor = () => {
const [controlsData, setControlsData] = useState({});

const handleControlChange = (newControls) => {
setControlsData(newControls);
};

return (
<div>
<AppBar />
<div className="flex flex-row mx-4">
<div className="flex flex-col flex-grow w-3/6 p-4 mx-auto mt-3">
<Controls />
<div className="flex-grow" style={{ height: "70vh" }}>
<Controls onControlChange={handleControlChange} />
<div className="flex-grow" style={{ height: "60vh" }}>
<Editor readOnly={false} language="json5" />
</div>
<button
Expand All @@ -25,10 +32,13 @@ const ProgrammingEditor = () => {
</div>

<div className="flex flex-col flex-grow w-4/5 p-4 mx-auto mt-3">
<div className="flex-grow" style={{ height: "70vh" }}>
<div className="flex-grow">
<Editor language="dart" readOnly={false} />
</div>
<button
onClick={() => {
navigator.clipboard.writeText(JSON.stringify(controlsData));
}}
type="button"
className="mt-3 w-full text-white bg-blue-700 hover:bg-blue-800 focus:ring-4 focus:ring-blue-300 font-medium rounded-lg text-sm px-5 py-2.5 me-2 mb-2 dark:bg-blue-600 dark:hover:bg-blue-700 focus:outline-none dark:focus:ring-blue-800"
>
Expand Down
110 changes: 3 additions & 107 deletions src/app/page.js
Original file line number Diff line number Diff line change
@@ -1,113 +1,9 @@
import Image from "next/image";
import ProgrammingEditor from "./editor/page";

export default function Home() {
return (
<main className="flex min-h-screen flex-col items-center justify-between p-24">
<div className="z-10 max-w-5xl w-full items-center justify-between font-mono text-sm lg:flex">
<p className="fixed left-0 top-0 flex w-full justify-center border-b border-gray-300 bg-gradient-to-b from-zinc-200 pb-6 pt-8 backdrop-blur-2xl dark:border-neutral-800 dark:bg-zinc-800/30 dark:from-inherit lg:static lg:w-auto lg:rounded-xl lg:border lg:bg-gray-200 lg:p-4 lg:dark:bg-zinc-800/30">
Get started by editing&nbsp;
<code className="font-mono font-bold">src/app/page.js</code>
</p>
<div className="fixed bottom-0 left-0 flex h-48 w-full items-end justify-center bg-gradient-to-t from-white via-white dark:from-black dark:via-black lg:static lg:h-auto lg:w-auto lg:bg-none">
<a
className="pointer-events-none flex place-items-center gap-2 p-8 lg:pointer-events-auto lg:p-0"
href="https://vercel.com?utm_source=create-next-app&utm_medium=appdir-template&utm_campaign=create-next-app"
target="_blank"
rel="noopener noreferrer"
>
By{" "}
<Image
src="/vercel.svg"
alt="Vercel Logo"
className="dark:invert"
width={100}
height={24}
priority
/>
</a>
</div>
</div>

<div className="relative flex place-items-center before:absolute before:h-[300px] before:w-full sm:before:w-[480px] before:-translate-x-1/2 before:rounded-full before:bg-gradient-radial before:from-white before:to-transparent before:blur-2xl before:content-[''] after:absolute after:-z-20 after:h-[180px] after:w-full sm:after:w-[240px] after:translate-x-1/3 after:bg-gradient-conic after:from-sky-200 after:via-blue-200 after:blur-2xl after:content-[''] before:dark:bg-gradient-to-br before:dark:from-transparent before:dark:to-blue-700 before:dark:opacity-10 after:dark:from-sky-900 after:dark:via-[#0141ff] after:dark:opacity-40 before:lg:h-[360px] z-[-1]">
<Image
className="relative dark:drop-shadow-[0_0_0.3rem_#ffffff70] dark:invert"
src="/next.svg"
alt="Next.js Logo"
width={180}
height={37}
priority
/>
</div>

<div className="mb-32 grid text-center lg:max-w-5xl lg:w-full lg:mb-0 lg:grid-cols-4 lg:text-left">
<a
href="https://nextjs.org/docs?utm_source=create-next-app&utm_medium=appdir-template&utm_campaign=create-next-app"
className="group rounded-lg border border-transparent px-5 py-4 transition-colors hover:border-gray-300 hover:bg-gray-100 hover:dark:border-neutral-700 hover:dark:bg-neutral-800/30"
target="_blank"
rel="noopener noreferrer"
>
<h2 className={`mb-3 text-2xl font-semibold`}>
Docs{" "}
<span className="inline-block transition-transform group-hover:translate-x-1 motion-reduce:transform-none">
-&gt;
</span>
</h2>
<p className={`m-0 max-w-[30ch] text-sm opacity-50`}>
Find in-depth information about Next.js features and API.
</p>
</a>

<a
href="https://nextjs.org/learn?utm_source=create-next-app&utm_medium=appdir-template-tw&utm_campaign=create-next-app"
className="group rounded-lg border border-transparent px-5 py-4 transition-colors hover:border-gray-300 hover:bg-gray-100 hover:dark:border-neutral-700 hover:dark:bg-neutral-800 hover:dark:bg-opacity-30"
target="_blank"
rel="noopener noreferrer"
>
<h2 className={`mb-3 text-2xl font-semibold`}>
Learn{" "}
<span className="inline-block transition-transform group-hover:translate-x-1 motion-reduce:transform-none">
-&gt;
</span>
</h2>
<p className={`m-0 max-w-[30ch] text-sm opacity-50`}>
Learn about Next.js in an interactive course with&nbsp;quizzes!
</p>
</a>

<a
href="https://vercel.com/templates?framework=next.js&utm_source=create-next-app&utm_medium=appdir-template&utm_campaign=create-next-app"
className="group rounded-lg border border-transparent px-5 py-4 transition-colors hover:border-gray-300 hover:bg-gray-100 hover:dark:border-neutral-700 hover:dark:bg-neutral-800/30"
target="_blank"
rel="noopener noreferrer"
>
<h2 className={`mb-3 text-2xl font-semibold`}>
Templates{" "}
<span className="inline-block transition-transform group-hover:translate-x-1 motion-reduce:transform-none">
-&gt;
</span>
</h2>
<p className={`m-0 max-w-[30ch] text-sm opacity-50`}>
Explore starter templates for Next.js.
</p>
</a>

<a
href="https://vercel.com/new?utm_source=create-next-app&utm_medium=appdir-template&utm_campaign=create-next-app"
className="group rounded-lg border border-transparent px-5 py-4 transition-colors hover:border-gray-300 hover:bg-gray-100 hover:dark:border-neutral-700 hover:dark:bg-neutral-800/30"
target="_blank"
rel="noopener noreferrer"
>
<h2 className={`mb-3 text-2xl font-semibold`}>
Deploy{" "}
<span className="inline-block transition-transform group-hover:translate-x-1 motion-reduce:transform-none">
-&gt;
</span>
</h2>
<p className={`m-0 max-w-[30ch] text-sm opacity-50 text-balance`}>
Instantly deploy your Next.js site to a shareable URL with Vercel.
</p>
</a>
</div>
<main className="min-h-screen">
<ProgrammingEditor />
</main>
);
}

0 comments on commit 4601506

Please sign in to comment.