Skip to content

Vue 3 Flashcards Documentation

A Tinder-like flashcards component for Vue 3 with dragging and flipping animations. Built with TypeScript and Vue 3 Composition API.

⚠️ Development Notice: This package is currently in development. The API may change between minor versions until v1.0.0 is released

Installation

bash
npm install vue3-flashcards

Usage

Basic Example

Here's a simple example showing how to create a basic flashcards component:

vue
<script setup>
import { ref } from 'vue'
import { FlashCards } from 'vue3-flashcards'

const cards = ref([
  { text: 'Front 1' },
  { text: 'Front 2' },
  { text: 'Front 3' },
])
</script>

<template>
  <div class="w-full flex justify-center items-center min-h-screen">
    <div class="max-w-sm w-full">
      <FlashCards :items="cards" #="{ item }">
        <div class="p-5 bg-base-200 border border-base-300 shadow-lg rounded-lg h-40 flex justify-center items-center">
          <div>{{ item.text }}</div>
        </div>
      </FlashCards>
    </div>
  </div>
</template>

Props

Prop NameTypeRequiredDefaultDescription
itemsT[]Yes-Array of items to display as cards. Each item will be passed to the default and back slots.
flipbooleanNofalseEnable card flipping functionality. When enabled, cards can be flipped to reveal content in the back slot.
maxRotationnumberNo20Maximum rotation angle in degrees.
thresholdnumberNo150Threshold in pixels for swipe actions.
virtualBuffernumberNo2Number of cards to render before/after the current card. Used for virtual rendering with large datasets. A value of 2 means 5 cards total will be rendered (current + 2 before + 2 after).

Slots

Slot NamePropsDescription
default{ item: T }Main content of the card (front side)
back{ item: T }Content shown when card is flipped (requires flip prop)
actions{ restore: () => void, reject: () => void, approve: () => void, isEnd: boolean, canRestore: boolean }Custom actions UI. restore returns to previous card, reject/approve trigger swipe animations, isEnd whether all cards have been swiped, canRestore whether there is a previous card to restore to
approve{ item: T, delta: number }Content shown when swiping right (approval indicator). delta is a value from 0 to 1, where 0 means the card is static and 1 means the card is at the approval threshold. Used for opacity transitions. Based on threshold prop
reject{ item: T, delta: number }Content shown when swiping left (rejection indicator). delta is a value from 0 to 1, where 0 means the card is static and 1 means the card is at the rejection threshold. Used for opacity transitions. Based on threshold prop
empty-Content shown when all cards have been swiped

Events

Event NamePayloadDescription
approveitem: TEmitted when a card is approved (swiped right or approved via actions)
rejectitem: TEmitted when a card is rejected (swiped left or rejected via actions)

Exposed

Method/PropertyTypeDescription
restore() => voidReturns to the previous card if available
approve() => voidTriggers approval animation on current card
reject() => voidTriggers rejection animation on current card
canRestorebooleanWhether there is a previous card to restore to
isEndbooleanWhether all cards have been swiped

⚠️ Development Notice: This package is currently in development. The API may change between minor versions until v1.0.0 is released.