lmscn

Flashcards

A flippable flashcard deck with optional self-rating and shuffle support.

Installation

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

Required primitives: button, card, progress, badge

npx shadcn@latest add button card progress badge

Usage

import { Flashcards } from "@/components/lms/flashcards"
import type { FlashcardsData, FlashcardsResult } from "@/components/lms/flashcards"

const data: FlashcardsData = {
  title: "Spanish Vocabulary",
  description: "Core greetings",
  shuffle: true,
  showRatings: true,
  cards: [
    { id: "1", front: "Hola",      back: "Hello",     tag: "Greetings" },
    { id: "2", front: "Gracias",   back: "Thank you", tag: "Greetings" },
    { id: "3", front: "Por favor", back: "Please",    tag: "Greetings" },
  ],
}

export function MyFlashcards() {
  return (
    <Flashcards
      flashcardsData={data}
      onComplete={(result: FlashcardsResult) => {
        console.log(result.counts)
        // { again: 1, hard: 0, good: 1, easy: 1 }
      }}
    />
  )
}

Props

FlashcardsProps

PropTypeRequiredDescription
flashcardsDataFlashcardsDataDeck configuration
onComplete(result: FlashcardsResult) => voidCalled after the last card is rated
classNamestringAdditional CSS classes

Data shape

FlashcardsData

FieldTypeDefaultDescription
titlestringDeck title
descriptionstringSubtitle
cardsFlashcard[]The cards in the deck
showRatingsbooleantrueShow Again / Hard / Good / Easy buttons after flipping
shufflebooleanfalseRandomise card order on mount

Flashcard

FieldTypeDescription
idstringUnique identifier
frontstringFront face text
backstringBack face text
frontImagestringURL for an image on the front face
backImagestringURL for an image on the back face
tagstringCategory badge shown on the front face

Result

onComplete receives a FlashcardsResult object:

FieldTypeDescription
ratingsFlashcardRating[]Per-card difficulty ratings in session order
countsRecord<FlashcardDifficulty, number>Tally of each rating across the session
type FlashcardDifficulty = "again" | "hard" | "good" | "easy"

interface FlashcardRating {
  cardId: string
  difficulty: FlashcardDifficulty
}

Behaviour

  • The card flips with a 3-D CSS rotation on click or Enter.
  • Navigation arrows allow jumping back to a previously seen card. Going back does not award another rating for the skipped card.
  • When showRatings is false, a single Next button advances the deck without recording difficulty.
  • The session completes after the last card is rated, showing a four-column summary (Again / Hard / Good / Easy counts) with a Restart button.

On this page