@molecule/app-quiz-card-vue
Feature · quiz-card · App (browser) · v1.1.3 · Apache-2.0
Question card with multiple-choice options, progress, optional timer, correct/incorrect feedback
npm install @molecule/app-quiz-card-vueHow it works
@molecule/app-quiz-card-vue is a ready-made quiz-card feature for the app (browser) side. It composes the core interfaces it needs, so it works with whichever providers your app has bonded.
import { defineComponent, h } from 'vue'
import { QuizCard } from '@molecule/app-quiz-card-vue'
const Question = defineComponent({
setup() {
return () =>
h(QuizCard, {
question: 'What is the capital of France?',
options: [
{ id: 'a', label: 'London' },
{ id: 'b', label: 'Paris' },
{ id: 'c', label: 'Berlin' },
],
correctId: 'b',
progress: '1 / 10',
explanation: 'Paris has been the capital of France since 987 AD.',
onAnswer: (id, correct) => console.log(id, correct),
})
},
})Works with: @molecule/app-ui, @molecule/app-ui-vue, @molecule/app-vue
Reference
Vue quiz / multiple-choice question card.
Exports <QuizCard> and the QuizOption type. The Vue counterpart of
@molecule/app-quiz-card-react: the same props (React names), the same DOM
for the same input and the same onAnswer(id, correct) calls.
Auto-generated, AI-first package reference for the molecule.dev ecosystem. It is written to be read by coding agents as much as by people, and is generated from this package's source — edit
src/index.tsJSDoc, not this file.
Quick Start
import { defineComponent, h } from 'vue'
import { QuizCard } from '@molecule/app-quiz-card-vue'
const Question = defineComponent({
setup() {
return () =>
h(QuizCard, {
question: 'What is the capital of France?',
options: [
{ id: 'a', label: 'London' },
{ id: 'b', label: 'Paris' },
{ id: 'c', label: 'Berlin' },
],
correctId: 'b',
progress: '1 / 10',
explanation: 'Paris has been the capital of France since 987 AD.',
onAnswer: (id, correct) => console.log(id, correct),
})
},
})
Type
feature
Installation
npm install @molecule/app-quiz-card-vue @molecule/app-ui @molecule/app-ui-vue @molecule/app-vue vue
API
Interfaces
QuizOption
A single selectable answer option in a quiz question.
interface QuizOption {
/** The option's identifier, used for selection and as the rendered key. */
id: string
/** The option's label. Passed as a prop or as a same-named slot. */
label: VNodeChild
}
QuizCardProps
Props accepted by the QuizCard component (React's names).
interface QuizCardProps {
/** The question text. Passed as a prop or as the same-named slot. */
question: VNodeChild
/** Answer options. */
options: QuizOption[]
/** Id of the correct option — when provided, the component reveals correct/incorrect on submit. */
correctId?: string
/** Called when the user submits an answer. */
onAnswer?: (optionId: string, correct?: boolean) => void
/** Progress display — e.g. `2 / 10`. Passed as a prop or as the same-named slot. */
progress?: VNodeChild
/** Optional countdown / timer node above the question. Passed as a prop or as the same-named slot. */
timer?: VNodeChild
/** Explanation shown after submit. Passed as a prop or as the same-named slot. */
explanation?: VNodeChild
/** Extra classes. */
className?: string
}
Constants
QuizCard
Single quiz question card with multiple-choice options. Tracks its own
submit state and reveals correct/incorrect when correctId is provided.
Vue counterpart of @molecule/app-quiz-card-react's QuizCard — the same
props (React names), the same ClassMap tokens, the same DOM for the same
input, and the same onAnswer(id, correct) calls. The card is single-shot:
after submit the options lock and the explanation replaces the button.
const QuizCard: DefineComponent<
ExtractPropTypes<{
question: { type: null; required: true }
options: { type: PropType<QuizOption[]>; required: true }
correctId: StringConstructor
onAnswer: PropType<(optionId: string, correct?: boolean) => void>
progress: null
timer: null
explanation: null
className: StringConstructor
}>,
() => VNode,
{},
{},
{},
ComponentOptionsMixin,
ComponentOptionsMixin,
{},
string,
PublicProps,
Readonly<
ExtractPropTypes<{
question: { type: null; required: true }
options: { type: PropType<QuizOption[]>; required: true }
correctId: StringConstructor
onAnswer: PropType<(optionId: string, correct?: boolean) => void>
progress: null
timer: null
explanation: null
className: StringConstructor
}>
> &
Readonly<{}>,
{},
{},
{},
{},
string,
ComponentProvideOptions,
true,
{},
any
>
props— Component props (seeQuizCardPropsin./types.js).
Returns: The quiz card component.
Injection Notes
Requirements
Peer dependencies:
@molecule/app-ui^1.1.0@molecule/app-ui-vue^1.1.0@molecule/app-vue^3.13.0 || ^4.0.0vue^3.4.0
Runtime Dependencies
@molecule/app-ui@molecule/app-ui-vue@molecule/app-vuevue
Companion locale bond: @molecule/app-locales-quiz-card (quizCard.submit).
The card is single-shot: after submit the options lock and the explanation
replaces the button — there is no reset prop, so advance quizzes by
remounting with a fresh key per question. Without correctId no
correct/incorrect state is revealed and onAnswer's second argument is
undefined. Requires the app-vue i18n provider and a wired ClassMap bond.
The question, progress, timer and explanation props are
node-valued: each may be passed as a prop or as the same-named Vue slot.
Translations
Translation strings are provided by @molecule/app-locales-quiz-card.