1- import { createSignal , createMemo } from "solid-js" ;
1+ import { createSignal , createMemo , For , Show } from "solid-js" ;
22import { createStore } from "solid-js/store" ;
3- import { For } from "solid-js" ;
43import type { Component } from "solid-js" ;
54import PlusIcon from "lucide-solid/icons/plus" ;
65import { CopyIcon , TrashIcon } from "lucide-solid" ;
@@ -119,16 +118,16 @@ const App: Component = () => {
119118 </ div >
120119 ) ) }
121120
122- < div >
121+ < div >
123122 < h2 class = "text-lg" > Body</ h2 >
124123 < div class = "space-y-2 divide-y-[1px] dark:divide-white/20" >
125124 < For each = { store . sections } >
126125 { ( section , index ) => (
127- < div class = "space-y-3" >
126+ < div class = "space-y-3 py-2 " >
128127 < Select
129128 class = "block my-4"
130129 value = { section . type }
131- onInput = { ( e ) => handleChange ( index ( ) , " { type" , : e . currentTarget . value as Section [ "type" ] } ) }
130+ onInput = { ( e ) => handleChange ( index ( ) , { type : e . currentTarget . value as Section [ "type" ] } ) }
132131 >
133132 { [ "Markdown" , "Textarea" , "Input" , "Dropdown" , "Checkboxes" ] . map ( ( type ) => (
134133 < option value = { type } > { type } </ option >
@@ -141,28 +140,27 @@ const App: Component = () => {
141140 class = "w-full block"
142141 placeholder = "Enter label"
143142 value = { section . label || "" }
144- onInput = { ( e ) => handleChange ( index ( ) , " label" , e . currentTarget . value ) }
143+ onInput = { ( e ) => handleChange ( index ( ) , { label : e . currentTarget . value } ) }
145144 />
146145 < Input
147146 class = "w-full block"
148147 placeholder = "Enter description"
149148 value = { section . description || "" }
150- onInput = { ( e ) => handleChange ( index ( ) , " description" , e . currentTarget . value ) }
149+ onInput = { ( e ) => handleChange ( index ( ) , { description : e . currentTarget . value } ) }
151150 />
152151 { section . type === "Input" && (
153152 < >
154153 < Input
155154 class = "w-full block"
156155 placeholder = "Enter placeholder"
157156 value = { section . placeholder || "" }
158- onInput = { ( e ) => handleChange ( index ( ) , " placeholder" , e . currentTarget . value ) }
157+ onInput = { ( e ) => handleChange ( index ( ) , { placeholder : e . currentTarget . value } ) }
159158 />
160159 < Input
161160 class = "w-full block"
162161 placeholder = "Enter value"
163162 value = { section . value || "" }
164- onInputflex justify-end ">
165- < Button variety = "primary" class = "flex gap-1" onClick = { ( e ) => handleChange ( index ( ) , "value" , e . currentTarget . value ) }
163+ onInput = { ( e ) => handleChange ( index ( ) , { value : e . currentTarget . value } ) }
166164 />
167165 </ >
168166 ) }
@@ -172,35 +170,34 @@ const App: Component = () => {
172170 class = "w-full block"
173171 placeholder = "Enter text"
174172 value = { section . value || "" }
175- onInput = { ( e ) => handleChange ( index ( ) , " value" , e . currentTarget . value ) }
173+ onInput = { ( e ) => handleChange ( index ( ) , { value : e . currentTarget . value } ) }
176174 />
177175 ) }
178- { section . type === "Dropdown" && (
176+ { ( section . type === "Dropdown" || section . type === "Checkboxes" ) && (
179177 < Input
180178 class = "w-full block"
181179 placeholder = "Enter options"
182180 value = { section . options ?. join ( ", " ) || "" }
183- onInput = { ( e ) => handleChange ( index ( ) , "options" , e . currentTarget . value . split ( ", " ) ) }
184- />
185- ) }
186- { section . type === "Checkboxes" && (
187- < Input
188- class = "w-full block"
189- placeholder = "Enter options"
190- value = { section . options ?. join ( ", " ) || "" }
191- onInput = { ( e ) => handleChange ( index ( ) , "options" , e . currentTarget . value . split ( ", " ) ) }
181+ onInput = { ( e ) => handleChange ( index ( ) , { options : e . currentTarget . value . split ( ", " ) } ) }
192182 />
193183 ) }
194184 </ Show >
195- { section . type === "Markdown" && (
185+
186+ < Show when = { section . type === "Markdown" } >
196187 < Textarea
197188 rows = { 3 }
198189 class = "w-full block"
199190 placeholder = "Enter markdown content"
200191 value = { section . value || "" }
201- onInput = { ( e ) => handleChange ( index ( ) , " value" , e . currentTarget . value ) }
192+ onInput = { ( e ) => handleChange ( index ( ) , { value : e . currentTarget . value } ) }
202193 />
203- ) } removeSection(index())} >
194+ </ Show >
195+
196+ < Button
197+ variety = "ghost"
198+ class = "flex gap-1 text-red-600"
199+ onClick = { ( ) => removeSection ( index ( ) ) }
200+ >
204201 < TrashIcon size = { 14 } /> Remove
205202 </ Button >
206203 </ div >
@@ -212,7 +209,7 @@ const App: Component = () => {
212209 < Button
213210 variety = "primary"
214211 class = "flex gap-1 py-1.5 items-center"
215- variety = "primary" class = "flex gap-1 py-1.5" onClick = { addSection }
212+ onClick = { addSection }
216213 >
217214 < PlusIcon size = { 14 } />
218215 Add Section
@@ -226,15 +223,13 @@ const App: Component = () => {
226223 < div class = "flex justify-end" >
227224 < button
228225 class = "px-4 py-1 flex items-center gap-2 text-sm hover:bg-black/10 dark:hover:bg-white/10 rounded transform duration-200"
229- rounded " onClick = { handleCopy }
226+ onClick = { handleCopy }
230227 >
231228 { copied ( ) ? "Copied" : "Copy" }
232229 < CopyIcon size = { 17 } />
233230 </ button >
234231 </ div >
235- < Highlight language = "yaml" >
236- { store . yamlOutput }
237- { yamlOutput ( ) } </ Highlight >
232+ < Highlight language = "yaml" > { yamlOutput ( ) } </ Highlight >
238233 </ div >
239234 </ div >
240235 </ div >
0 commit comments