Rebuilds the look around the spec: an ice scene, one shared glass recipe, icy accents and glass on every large surface. Visual only — layout, behaviour, copy and functionality are untouched. Background - .ice-scene: fixed, z-index -1, pointer-events none. Navy base (#070b16 to #0c1426) in dark, pale (#f4f9ff to #e6f1fb) in light, four drifting glacier blobs (#38bdf8/#60a5fa/#818cf8, 30-60s transform-only loops), five glossy ice orbs (40-220px radial gradients with a highlight at 30% 25% and a blue shadow) placed so the glass blurs them, and an SVG feTurbulence grain at 4-5%. - prefers-reduced-motion stops the drift; phones get two blobs and two orbs fewer. Glass - One shared recipe (.glass-panel, .card, .sidebar-surface, .study-chrome, .tabbar, .glass, .gate-card): rgba(255,255,255,.06) dark / .55 light, blur(24px) saturate(140%) (16px on phones), a bright 1px rim, an inset top highlight and a blue-tinted outer shadow. - Nested glass (chips, inputs, secondary buttons) is more opaque and never adds a second blur layer. @supports fallback for no backdrop-filter. Radii: 24-28px cards/sheets, 14px inputs/buttons, pills for chips. Cards hover brighter + cyan rim + 2px lift, 180ms. Colour and type - Accent is glacier cyan (#38bdf8) to ice blue (#0ea5e9); progress bars and selected states use the gradient; the active sidebar item is a frosted highlight with a cyan rim. - Primary CTA: icy gradient — white to #bfe3ff with ink text in dark, deep blue in light (biased so the label sits on the darker half and keeps 5.6:1). - Leftover slate/black greys replaced with navy-tinted frost tokens. - Headings are semibold with tighter tracking. Screens - Dashboard: the sidebar is one tall inset rounded glass panel; deck cards are glass. - Gate: one centred glass card over the scene, orbs visible behind it. - Sheets/modals: glass over the dimmed, lightly blurred backdrop. - Study view: question card more opaque (.glass-solid); top bar and pager are slim glass pills. Perf: measured on a phone viewport with 4x CPU throttling. The animated blobs' filter: blur() was the whole cost (150ms vs 33ms per frame), so they are soft radial gradients with no filter now; idle 60fps, ~17ms median while scrolling. Tests updated for the new tokens: contrast 18/18 AA, deck chrome 15/15, key gate 49/49, install sheet 64/64, deck fixes 15/15, retry 14/14, zoom 6/6, final ux 12/12, security 8/8, pwa 16/16.
132 lines
4.9 KiB
TypeScript
132 lines
4.9 KiB
TypeScript
"use client";
|
|
|
|
import { Reorder } from "framer-motion";
|
|
import { useMemo, useState } from "react";
|
|
|
|
import type { Activity } from "@/lib/schemas";
|
|
import { cn, shuffle } from "@/lib/utils";
|
|
import { Button } from "@/components/ui";
|
|
|
|
import {
|
|
ActivityHeader,
|
|
FeedbackPanel,
|
|
Hint,
|
|
PromptCard,
|
|
type ActivityComponentProps,
|
|
} from "./shared";
|
|
|
|
type OrderingActivity = Extract<Activity, { type: "ordering" }>;
|
|
|
|
export function Ordering({ activity, onAnswered, onNext, isLast }: ActivityComponentProps<OrderingActivity>) {
|
|
const initial = useMemo(() => shuffle(activity.items), [activity]);
|
|
const [items, setItems] = useState<string[]>(initial);
|
|
const [checked, setChecked] = useState(false);
|
|
const [correct, setCorrect] = useState(false);
|
|
|
|
const isRight = (list: string[]) => list.every((item, index) => item === activity.items[index]);
|
|
|
|
const check = () => {
|
|
if (checked) return;
|
|
const result = isRight(items);
|
|
setChecked(true);
|
|
setCorrect(result);
|
|
onAnswered(result, { userAnswer: items.join(" → ") });
|
|
};
|
|
|
|
const move = (index: number, direction: -1 | 1) => {
|
|
if (checked) return;
|
|
const target = index + direction;
|
|
if (target < 0 || target >= items.length) return;
|
|
const next = [...items];
|
|
[next[index], next[target]] = [next[target], next[index]];
|
|
setItems(next);
|
|
};
|
|
|
|
return (
|
|
<>
|
|
<ActivityHeader type="ordering" topic={activity.topic} />
|
|
<PromptCard className="py-4">
|
|
<p className="text-lg font-bold text-frost-950 dark:text-frost-50">{activity.instruction}</p>
|
|
<Hint>
|
|
{checked ? "Here is the correct order:" : "Drag the cards, or use ▲▼, then check your order."}
|
|
</Hint>
|
|
</PromptCard>
|
|
|
|
{checked ? (
|
|
<ol className="flex flex-col gap-2.5">
|
|
{activity.items.map((item, index) => {
|
|
const wasRight = items[index] === item;
|
|
return (
|
|
<li
|
|
key={`solution-${item}`}
|
|
className={cn(
|
|
"flex items-center gap-3 rounded-2xl border-2 px-4 py-3 text-sm font-semibold",
|
|
wasRight
|
|
? "border-emerald-200/80 bg-emerald-50/85 text-emerald-900 dark:border-emerald-400/40 dark:bg-emerald-400/15 dark:text-emerald-100"
|
|
: "border-rose-200/80 bg-rose-50/85 text-rose-900 dark:border-rose-400/40 dark:bg-rose-400/15 dark:text-rose-100",
|
|
)}
|
|
>
|
|
<span className="grid size-7 shrink-0 place-items-center rounded-full bg-white/70 text-xs font-extrabold dark:bg-white/15">
|
|
{index + 1}
|
|
</span>
|
|
<span className="flex-1">{item}</span>
|
|
</li>
|
|
);
|
|
})}
|
|
</ol>
|
|
) : (
|
|
<Reorder.Group axis="y" values={items} onReorder={setItems} className="flex flex-col gap-2.5">
|
|
{items.map((item, index) => (
|
|
<Reorder.Item
|
|
key={item}
|
|
value={item}
|
|
className="flex cursor-grab items-center gap-2 rounded-2xl border border-white/60 bg-white/60 px-3 py-3 text-sm font-semibold text-frost-950 shadow-sm backdrop-blur-xl active:cursor-grabbing dark:border-white/12 dark:bg-white/[0.08] dark:text-frost-50"
|
|
>
|
|
<span className="grid size-7 shrink-0 place-items-center rounded-full bg-frost-100 text-xs font-extrabold text-frost-700 dark:bg-white/15 dark:text-frost-100">
|
|
{index + 1}
|
|
</span>
|
|
<span className="flex-1">{item}</span>
|
|
<span className="flex flex-col">
|
|
<button
|
|
type="button"
|
|
aria-label={`Move "${item}" up`}
|
|
onClick={() => move(index, -1)}
|
|
disabled={index === 0}
|
|
className="rounded px-1.5 text-xs text-frost-700 transition hover:bg-frost-100 disabled:opacity-30 dark:text-frost-100 dark:hover:bg-white/10"
|
|
>
|
|
▲
|
|
</button>
|
|
<button
|
|
type="button"
|
|
aria-label={`Move "${item}" down`}
|
|
onClick={() => move(index, 1)}
|
|
disabled={index === items.length - 1}
|
|
className="rounded px-1.5 text-xs text-frost-700 transition hover:bg-frost-100 disabled:opacity-30 dark:text-frost-100 dark:hover:bg-white/10"
|
|
>
|
|
▼
|
|
</button>
|
|
</span>
|
|
<span aria-hidden className="text-frost-400">
|
|
⠿
|
|
</span>
|
|
</Reorder.Item>
|
|
))}
|
|
</Reorder.Group>
|
|
)}
|
|
|
|
{!checked ? (
|
|
<Button size="lg" onClick={check} disabled={items.length < 2}>
|
|
Check order
|
|
</Button>
|
|
) : (
|
|
<FeedbackPanel
|
|
correct={correct}
|
|
explanation={activity.explanation}
|
|
xp={activity.xp}
|
|
isLast={isLast}
|
|
onNext={onNext}
|
|
/>
|
|
)}
|
|
</>
|
|
);
|
|
}
|