lmscn

Match

A two-column term-to-definition matching activity with mistake tracking and a timer.

Installation

npx shadcn@latest add https://lmscn.vercel.app/r/match.json

Required primitives: button, progress, badge

npx shadcn@latest add button progress badge

Usage

import { Match } from "@/components/lms/match"
import type { MatchData, MatchResult } from "@/components/lms/match"

export function MyMatch() {
  return (
    <Match
      matchData={{
        title: "Capital Cities",
        description: "Match each country to its capital.",
        shuffle: true,
        pairs: [
          { id: "1", left: "France",  right: "Paris"  },
          { id: "2", left: "Japan",   right: "Tokyo"  },
          { id: "3", left: "Egypt",   right: "Cairo"  },
          { id: "4", left: "Brazil",  right: "Brasília" },
        ],
      }}
      onComplete={(result: MatchResult) => {
        console.log(`${result.mistakes} mistakes in ${result.durationMs}ms`)
      }}
    />
  )
}

Props

MatchProps

PropTypeRequiredDescription
matchDataMatchDataPairs configuration
onComplete(result: MatchResult) => voidCalled when all pairs are matched
classNamestringAdditional CSS classes

Data shape

MatchData

FieldTypeDefaultDescription
titlestringActivity title
descriptionstringSubtitle
pairsMatchPair[]Term / definition pairs
shufflebooleantrueRandomise the right column order on mount

MatchPair

FieldTypeDescription
idstringUnique identifier
leftstringTerm (left column)
rightstringDefinition (right column)
leftImagestringOptional image URL for the term
rightImagestringOptional image URL for the definition

Result

onComplete receives a MatchResult object:

FieldTypeDescription
matchedMatchPair[]All pairs in original order
mistakesnumberCount of incorrect pair attempts
durationMsnumberTotal time taken in milliseconds

Behaviour

  • Clicking a term selects it (highlighted in primary colour). Clicking a definition while a term is selected attempts the match.
  • A correct match locks both items green and removes them from play.
  • An incorrect match briefly flashes both items red, then deselects them after 600 ms.
  • The timer starts on mount and stops when the last pair is matched.
  • The completion screen shows the mistake count, elapsed seconds, and a Play Again button that resets state without remounting.

On this page