forge
Explore
Log in

Don't you dare go Hollow

🎯 compact question form with better visual hierarchy

Browse files at this commit

cda1ab74bd6af6924d62b5907eaffa7fe090cba8Burak BoduroğluParent: af7500b
  • refactor
    • 🎯 compact question form with better visual hierarchy
Show full message
refactor: 🎯 compact question form with better visual hierarchy

- textarea + image upload combined into one card
- subject/kind/points as compact inline bar (h-9)
- choices single-column with emerald correct-answer highlight
- choice images as minimal text-[10px] buttons
src/components/exams/question-form.tsxmodified+140 -138
@@ -126,180 +126,182 @@ export function QuestionForm(props: {
126 };126 };
127 127
128 return (128 return (
129- <form class="space-y-4" onSubmit={(e) => void submit(e)}>129+ <form class="space-y-3" onSubmit={(e) => void submit(e)}>
130- <div class="grid gap-4 sm:grid-cols-[minmax(0,1fr)_15rem] sm:items-start">130+ <div class="rounded-lg border bg-card p-3.5 shadow-sm">
131- <div class="space-y-3">131+ <div class="space-y-2">
132- <div class="space-y-1.5">132+ <Label for="question-text" class="text-sm font-semibold">{t("questions.text")}</Label>
133- <Label for="question-text" class="text-sm font-semibold">{t("questions.text")}</Label>133+ <Textarea
134- <Textarea134+ id="question-text"
135- id="question-text"135+ ref={textAreaRef}
136- ref={textAreaRef}136+ class="min-h-[7rem] resize-none overflow-hidden bg-background text-base"
137- class="min-h-[9rem] resize-none overflow-hidden bg-background text-base"137+ value={text()}
138- value={text()}138+ maxlength={2000}
139- maxlength={2000}139+ rows={3}
140- rows={4}140+ required
141- required141+ placeholder={t("questions.text")}
142- placeholder={t("questions.text")}142+ onInput={(e) => {
143- onInput={(e) => {143+ setText(e.currentTarget.value);
144- setText(e.currentTarget.value);144+ resizeTextArea();
145- resizeTextArea();145+ }}
146- }}146+ />
147- />147+ <div class="flex items-center gap-3">
148- </div>
149-
150- <div class="rounded-lg border bg-card p-3 shadow-sm">
151- <Label for="question-image" class="text-xs font-semibold text-muted-foreground">{t("questions.image")}</Label>
152 <Show when={props.initial?.image}>148 <Show when={props.initial?.image}>
153- <img149+ <div class="relative shrink-0">
154- src={`/api/exams/${props.initial!.exam}/questions/${props.initial!.id}/image`}150+ <img
155- alt={t("questions.image")}151+ src={`/api/exams/${props.initial!.exam}/questions/${props.initial!.id}/image`}
156- class="mt-2 h-36 w-full max-w-md rounded-md border bg-muted/20 object-contain"152+ alt={t("questions.image")}
157- />153+ class="h-14 w-24 rounded border bg-muted/20 object-contain"
154+ />
155+ </div>
158 </Show>156 </Show>
159- <input157+ <div class="flex items-center gap-2">
160- id="question-image"158+ <input
161- type="file"159+ id="question-image"
162- accept="image/png,image/jpeg,image/webp,image/gif"160+ type="file"
163- class="sr-only"161+ accept="image/png,image/jpeg,image/webp,image/gif"
164- onChange={(event) => setImage(event.currentTarget.files?.[0] ?? null)}162+ class="sr-only"
165- />163+ onChange={(event) => setImage(event.currentTarget.files?.[0] ?? null)}
166- <label for="question-image" class="mt-2 flex cursor-pointer items-center gap-2 rounded-md border border-dashed bg-muted/30 px-3 py-2 text-xs font-medium text-muted-foreground transition-colors hover:bg-muted/60 hover:text-foreground">164+ />
167- <IconFileImage class="h-4 w-4" />165+ <label for="question-image" class="flex cursor-pointer items-center gap-1.5 rounded-md border border-dashed bg-muted/30 px-2.5 py-1.5 text-xs font-medium text-muted-foreground transition-colors hover:bg-muted/60 hover:text-foreground">
168- <span class="truncate">{image()?.name ?? t("common.createItem", { item: t("questions.image") })}</span>166+ <IconFileImage class="h-3.5 w-3.5" />
169- </label>167+ <span class="truncate">{image()?.name ?? t("questions.image")}</span>
170- </div>168+ </label>
171- </div>
172-
173- <div class="space-y-3 rounded-lg border bg-card p-3.5 shadow-sm">
174- <div class="space-y-1.5">
175- <Label for="question-subject">{t("subjects.subject")}</Label>
176- <Select id="question-subject" class="h-10 py-2" value={subjectId()} required onChange={(e) => setSubjectId(e.currentTarget.value)}>
177- <option value="">{t("subjects.select")}</option>
178- <For each={props.subjects}>{(subject) => <option value={subject.id}>{subject.name}</option>}</For>
179- </Select>
180- </div>
181-
182- <div class="space-y-1.5">
183- <Label class="text-xs font-semibold uppercase tracking-wider text-muted-foreground">{t("questions.kind")}</Label>
184- <div class="grid grid-cols-2 gap-1 rounded-lg border bg-muted/40 p-1">
185- <For each={QUESTION_KINDS}>
186- {(k) => (
187- <button
188- type="button"
189- class={cn(
190- "h-8 rounded-md border text-xs font-semibold transition-colors",
191- kind() === k
192- ? "border-primary bg-primary text-primary-foreground shadow-sm"
193- : "border-transparent text-muted-foreground hover:bg-background/70 hover:text-foreground",
194- )}
195- onClick={() => setKind(k)}
196- >
197- {k === "choice" ? t("questions.kind.choice") : t("questions.kind.text")}
198- </button>
199- )}
200- </For>
201 </div>169 </div>
202 </div>170 </div>
171+ </div>
172+ </div>
203 173
204- <div class="space-y-1.5">174+ <div class="flex flex-wrap items-end gap-3 rounded-lg border bg-card px-3.5 py-3 shadow-sm">
205- <Label for="question-points">{t("questions.points")}</Label>175+ <div class="min-w-0 flex-1 basis-[10rem]">
206- <Input176+ <Label for="question-subject" class="mb-1 block text-xs font-semibold text-muted-foreground">{t("subjects.subject")}</Label>
207- id="question-points"177+ <Select id="question-subject" class="h-9 py-1.5 text-sm" value={subjectId()} required onChange={(e) => setSubjectId(e.currentTarget.value)}>
208- type="number"178+ <option value="">{t("subjects.select")}</option>
209- min={1}179+ <For each={props.subjects}>{(subject) => <option value={subject.id}>{subject.name}</option>}</For>
210- max={100}180+ </Select>
211- value={points()}181+ </div>
212- class="h-10"182+ <div>
213- required183+ <Label class="mb-1 block text-xs font-semibold text-muted-foreground">{t("questions.kind")}</Label>
214- onInput={(e) => setPoints(e.currentTarget.value)}184+ <div class="flex gap-0.5 rounded-md border bg-muted/40 p-0.5">
215- />185+ <For each={QUESTION_KINDS}>
186+ {(k) => (
187+ <button
188+ type="button"
189+ class={cn(
190+ "h-7 rounded-sm px-2.5 text-xs font-semibold transition-colors",
191+ kind() === k
192+ ? "bg-primary text-primary-foreground shadow-xs"
193+ : "text-muted-foreground hover:text-foreground",
194+ )}
195+ onClick={() => setKind(k)}
196+ >
197+ {k === "choice" ? t("questions.kind.choice") : t("questions.kind.text")}
198+ </button>
199+ )}
200+ </For>
216 </div>201 </div>
217 </div>202 </div>
203+ <div class="w-20">
204+ <Label for="question-points" class="mb-1 block text-xs font-semibold text-muted-foreground">{t("questions.points")}</Label>
205+ <Input
206+ id="question-points"
207+ type="number"
208+ min={1}
209+ max={100}
210+ value={points()}
211+ class="h-9 text-sm"
212+ required
213+ onInput={(e) => setPoints(e.currentTarget.value)}
214+ />
215+ </div>
218 </div>216 </div>
219 217
220 <Show when={kind() === "choice"}>218 <Show when={kind() === "choice"}>
221- <div class="space-y-3 rounded-lg border bg-card p-3.5 shadow-sm">219+ <div class="rounded-lg border bg-card p-3.5 shadow-sm">
222- <div class="flex items-center justify-between gap-2 border-b pb-2">220+ <div class="mb-3 flex items-center justify-between gap-2 border-b border-border/50 pb-2">
223- <div>221+ <Label class="text-sm font-semibold">{t("questions.choices")}</Label>
224- <Label class="text-sm font-semibold">{t("questions.choices")}</Label>222+ <Button type="button" variant="outline" size="sm" class="h-7 gap-1 text-xs" disabled={choices().length >= 10} onClick={addChoice}>
225- <p class="text-xs text-muted-foreground">{t("questions.correctAnswer")}: {String.fromCharCode(65 + correct())}</p>223+ <IconPlus class="h-3.5 w-3.5" />
226- </div>
227- <Button type="button" variant="outline" size="sm" disabled={choices().length >= 10} onClick={addChoice}>
228- <IconPlus class="h-4 w-4" />
229 {t("questions.addChoice")}224 {t("questions.addChoice")}
230 </Button>225 </Button>
231 </div>226 </div>
232- <div class="grid gap-3 sm:grid-cols-2">227+ <div class="space-y-2">
233 <Index each={choices()}>228 <Index each={choices()}>
234- {(choice, index) => (229+ {(choice, index) => {
235- <div class="rounded-md border bg-background p-3 shadow-xs">230+ const isCorrect = () => correct() === index;
236- <div class="mb-2 flex items-center justify-between gap-2">231+ return (
232+ <div
233+ class={cn(
234+ "flex items-start gap-2 rounded-md border p-2 transition-colors",
235+ isCorrect() ? "border-emerald-400/60 bg-emerald-50/60" : "border-border bg-background",
236+ )}
237+ >
237 <button238 <button
238 type="button"239 type="button"
239- class={240+ class={cn(
240- correct() === index241+ "mt-0.5 inline-flex h-6 w-6 shrink-0 items-center justify-center rounded text-xs font-bold transition-colors",
241- ? "inline-flex h-8 items-center gap-1.5 rounded-md bg-primary px-2.5 text-xs font-semibold text-primary-foreground shadow-xs"242+ isCorrect()
242- : "inline-flex h-8 items-center gap-1.5 rounded-md border border-input bg-background px-2.5 text-xs font-medium text-muted-foreground transition-colors hover:bg-accent hover:text-accent-foreground"243+ ? "bg-emerald-600 text-white shadow-xs"
243- }244+ : "border bg-background text-muted-foreground hover:border-emerald-400 hover:text-emerald-600",
245+ )}
244 onClick={() => setCorrect(index)}246 onClick={() => setCorrect(index)}
247+ title={t("questions.correct")}
245 >248 >
246- <span class="inline-flex h-4 w-4 items-center justify-center rounded-[3px] border bg-background text-[10px] font-bold text-foreground">249+ {isCorrect() ? <IconCheck class="h-3.5 w-3.5" /> : String.fromCharCode(65 + index)}
247- {String.fromCharCode(65 + index)}
248- </span>
249- {correct() === index ? <IconCheck class="h-3.5 w-3.5" /> : t("questions.correct")}
250 </button>250 </button>
251+ <div class="min-w-0 flex-1 space-y-1.5">
252+ <Input
253+ class="h-8 text-sm"
254+ value={choice()}
255+ maxlength={500}
256+ placeholder={t("questions.choicePlaceholder", { index: String.fromCharCode(65 + index) })}
257+ onInput={(e) => setChoice(index, e.currentTarget.value)}
258+ />
259+ <div class="flex items-center gap-2">
260+ <input
261+ id={`choice-image-${index}`}
262+ type="file"
263+ accept="image/png,image/jpeg,image/webp,image/gif"
264+ class="sr-only"
265+ onChange={(event) => setChoiceImage(index, event.currentTarget.files?.[0] ?? null)}
266+ />
267+ <label for={`choice-image-${index}`} class="flex cursor-pointer items-center gap-1 rounded-md border border-dashed bg-muted/20 px-2 py-0.5 text-[10px] font-medium text-muted-foreground transition-colors hover:bg-muted/60 hover:text-foreground">
268+ <IconFileImage class="h-3 w-3" />
269+ {choiceImages()[index]?.name ?? t("questions.choiceImage")}
270+ </label>
271+ <Show when={props.initial?.choice_images?.[index]}>
272+ <img
273+ src={`/api/exams/${props.initial!.exam}/questions/${props.initial!.id}/choices/${index}/image`}
274+ alt={t("questions.choiceImage")}
275+ class="h-8 w-12 rounded border bg-muted/20 object-contain"
276+ />
277+ </Show>
278+ </div>
279+ </div>
251 <Button280 <Button
252 type="button"281 type="button"
253 variant="ghost"282 variant="ghost"
254 size="sm"283 size="sm"
255 disabled={choices().length <= 2}284 disabled={choices().length <= 2}
256- class="h-8 w-8 p-0 text-destructive"285+ class="mt-0.5 h-6 w-6 p-0 text-muted-foreground hover:text-destructive"
257 onClick={() => removeChoice(index)}286 onClick={() => removeChoice(index)}
258 >287 >
259- <IconTrash class="h-4 w-4" />288+ <IconTrash class="h-3.5 w-3.5" />
260 </Button>289 </Button>
261 </div>290 </div>
262- <Input291+ );
263- class="h-9 text-sm"292+ }}
264- value={choice()}
265- maxlength={500}
266- placeholder={t("questions.choicePlaceholder", { index: String.fromCharCode(65 + index) })}
267- onInput={(e) => setChoice(index, e.currentTarget.value)}
268- />
269- <Show when={props.initial?.choice_images?.[index]}>
270- <img
271- src={`/api/exams/${props.initial!.exam}/questions/${props.initial!.id}/choices/${index}/image`}
272- alt={t("questions.choiceImage")}
273- class="mt-2 h-28 w-full max-w-sm rounded-md border bg-muted/20 object-contain"
274- />
275- </Show>
276- <div class="mt-2">
277- <input
278- id={`choice-image-${index}`}
279- type="file"
280- accept="image/png,image/jpeg,image/webp,image/gif"
281- class="sr-only"
282- onChange={(event) => setChoiceImage(index, event.currentTarget.files?.[0] ?? null)}
283- />
284- <label for={`choice-image-${index}`} class="flex cursor-pointer items-center gap-2 rounded-md border border-dashed bg-muted/30 px-2.5 py-1.5 text-xs font-medium text-muted-foreground transition-colors hover:bg-muted/60 hover:text-foreground">
285- <IconFileImage class="h-3.5 w-3.5" />
286- <span class="truncate">{choiceImages()[index]?.name ?? t("questions.choiceImage")}</span>
287- </label>
288- </div>
289- </div>
290- )}
291 </Index>293 </Index>
292 </div>294 </div>
293 </div>295 </div>
294 </Show>296 </Show>
295 297
296- {error() && <p class="text-sm text-destructive">{error()}</p>}298+ {error() && <p class="rounded-sm bg-destructive/10 px-3 py-1.5 text-sm text-destructive">{error()}</p>}
297 299
298- <div class="flex flex-wrap items-center gap-2 pt-2">300+ <div class="flex flex-wrap items-center gap-2 pt-1">
299- <Button type="submit" disabled={pending()}>301+ <Button type="submit" class="h-8 text-xs font-semibold" disabled={pending()}>
300 {props.initial ? t("common.update") : t("common.create")}302 {props.initial ? t("common.update") : t("common.create")}
301 </Button>303 </Button>
302- <Button type="button" variant="outline" onClick={props.onCancel}>304+ <Button type="button" variant="outline" class="h-8 text-xs font-semibold" onClick={props.onCancel}>
303 {t("common.cancel")}305 {t("common.cancel")}
304 </Button>306 </Button>
305 </div>307 </div>