11import { useEffect , useState , useRef } from "react" ;
22import CodeMirror from "@uiw/react-codemirror" ;
3- import { javascript } from "@codemirror/lang-javascript " ;
3+ import { json } from "@codemirror/lang-json " ;
44import { createTheme } from "@uiw/codemirror-themes" ;
55import { EditorView } from "@codemirror/view" ;
66import Head from "next/head" ;
@@ -27,7 +27,7 @@ export default function Home() {
2727 const hiddenFileInput = useRef ( null ) ;
2828 const selectRef = useRef ( null ) ;
2929
30- let editorExtensions = [ javascript ( { jsx : true } ) , EditorView . lineWrapping ] ;
30+ let editorExtensions = [ json ( ) , EditorView . lineWrapping ] ;
3131
3232 const handleFormat = ( indentationSpace = 2 ) => {
3333 try {
@@ -58,7 +58,7 @@ export default function Home() {
5858 const handleCopy = ( ) => {
5959 try {
6060 navigator . clipboard . writeText ( outputString ) ;
61- Toastr . success ( "Copied to clipboard" ) ;
61+ Toastr . success ( "🦄 Copied to clipboard! " ) ;
6262 } catch ( error ) {
6363 Toastr . error ( "Could not Copy. Try again" ) ;
6464 }
@@ -88,80 +88,85 @@ export default function Home() {
8888 < link rel = "icon" href = "/favicon.ico" />
8989 </ Head >
9090
91- < main className = "h-screen flex flex-col justify-between bg-zinc-900 p-5 " >
91+ < main className = "h-screen flex flex-col justify-between bg-[#111111] pt-3 pb-4 px-4 " >
9292 < ToastContainer theme = "dark" />
9393 < Header />
9494 < div className = "space-y-3 grow flex flex-col" >
95- < div className = "flex grow space-x-3" >
96- < div className = "w-full bg-[#282c34]" >
97- < Button
98- size = "small"
99- style = "text"
100- label = "Demo JSON"
101- onClick = { handleDemoJson }
102- />
95+ < div className = "flex flex-1 relative grow space-x-3" >
96+ < div className = "w-full" >
10397 < CodeMirror
10498 autoFocus
105- height = "590px "
106- theme = "dark"
99+ height = "660px "
100+ theme = { createTheme ( CODE_EDITOR_THEME ) }
107101 value = { inputString }
108102 extensions = { editorExtensions }
109103 onChange = { ( e ) => setInputString ( e ) }
110104 className = "h-full mt-1"
111105 />
112106 </ div >
113- < div className = "w-full bg-[#282c34] " >
107+ < div className = "w-full relative " >
114108 < Button
115- size = "small "
109+ size = "medium "
116110 style = "text"
117111 onClick = { handleCopy }
118112 icon = { Copy }
119- className = "float-right"
113+ iconSize = "22"
114+ className = "float-right absolute z-10 right-0 top-0"
120115 disabled = { outputString === "" }
121116 />
122117 < CodeMirror
123- height = "590px "
118+ height = "660px "
124119 theme = { createTheme ( CODE_EDITOR_THEME ) }
125120 editable = { false }
126121 value = { outputString }
127122 extensions = { editorExtensions }
128- className = "overflow-auto h-full mt-7 "
123+ className = "overflow-auto absolute h-full mt-1 w-full "
129124 />
130125 </ div >
131- </ div >
132- < div className = "flex justify-end bg-zinc-800 space-x-3 px-3 py-3 rounded" >
133- < Button
134- label = "Format"
135- onClick = { ( ) => handleFormat ( selectRef . current . state . value . value ) }
136- />
137- < Button label = "Clear" onClick = { handleClear } />
138- < Button
139- label = "Download"
140- onClick = { handleDownload }
141- disabled = { outputString === "" }
142- />
143- < Button
144- onClick = { ( ) => hiddenFileInput . current . click ( ) }
145- label = "Upload"
146- />
147- < input
148- type = "file"
149- style = { { display : "none" } }
150- ref = { hiddenFileInput }
151- onChange = { handleUpload }
152- />
153- < Select
154- ref = { selectRef }
155- classNamePrefix = "react-select"
156- onChange = { ( e ) => handleFormat ( e . value ) }
157- className = { "react-select__container" }
158- menuPlacement = "top"
159- options = { INDENTATION_SPACE_OPTIONS }
160- defaultValue = { DEFAULT_INDENTATION_SPACE }
161- />
126+ < div className = "flex flex-col min-w-80 w-80 justify-start space-y-2 px-1 rounded" >
127+ < label className = "text-xs text-[#888888]" > Formatting</ label >
128+ < div className = "flex flex-col space-y-2" >
129+ < Button
130+ label = "Prettify"
131+ onClick = { ( ) => handleFormat ( selectRef . current . state . value . value ) }
132+ />
133+ < Button label = "Clear" onClick = { handleClear } />
134+ < Button
135+ label = "Download ↓"
136+ onClick = { handleDownload }
137+ disabled = { outputString === "" }
138+ />
139+ < Button
140+ onClick = { ( ) => hiddenFileInput . current . click ( ) }
141+ label = "Upload ↑"
142+ />
143+ < Button
144+ onClick = { handleDemoJson }
145+ label = "Demo JSON"
146+ />
147+ </ div >
148+ < label className = "text-xs pt-3 text-[#888888]" > Indentation</ label >
149+ < div className = "flex flex-col" >
150+ < input
151+ type = "file"
152+ style = { { display : "none" } }
153+ ref = { hiddenFileInput }
154+ onChange = { handleUpload }
155+ />
156+ < Select
157+ ref = { selectRef }
158+ classNamePrefix = "react-select"
159+ onChange = { ( e ) => handleFormat ( e . value ) }
160+ className = { "react-select__container" }
161+ menuPlacement = "bottom"
162+ options = { INDENTATION_SPACE_OPTIONS }
163+ defaultValue = { DEFAULT_INDENTATION_SPACE }
164+ />
165+ </ div >
166+
167+ </ div >
162168 </ div >
163169 </ div >
164- { /* <Footer /> */ }
165170 </ main >
166171 < script data-goatcounter = "https://json-style.goatcounter.com/count"
167172 async src = "//gc.zgo.at/count.js" > </ script >
0 commit comments