New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details
Socket
Book a DemoSign in
Socket

react-quiz-maker

Package Overview
Dependencies
Maintainers
0
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-quiz-maker

This is a quiz building library which allows developers to implement a variety of animated quiz types with a custom design, without having to implement most of the quiz logic.

latest
npmnpm
Version
0.0.6
Version published
Maintainers
0
Created
Source

React Quiz Maker

This is a quiz building library which allows developers to implement a variety of animated quiz types with a custom design, without having to implement most of the quiz logic.

Show me some code | Demo

Installation

npm install react-quiz-maker

Config

OptionTypeValuesDefaultDescription
autoResumebooleanfalseThe quiz will resume automatically after the user has answered the question
autoResumeDelaynumber1000The delay after which the quiz will resume automatically
revealAnswerbooleanfalseReveal the correct answer after the user has chosen one of the answers
explainerEnabledbooleanfalseEnable an explanation box which appears after each question has been answered
explainerNewPagebooleanfalseHave the explanation box replace the question, instead of both being present at the same time
animationstring"mixed", "slideUp", "slideLeft", "scale", "disabled""mixed"Choose an animation style (or disable the animation)

API

To achieve a custom design, the API gives you control over how some of the quiz components are implemented. The API tries to balance ease-of-use vs customisability, i.e. to what extent you can modify the quiz vs how easy it is to implement a custom design and functionality. Over time the API can be extended to allow more customisability (especially around the animations).

Implementable components

ComponentPropsTypeDescription
<YourQuiz>config
data
QuizConfig
QuizData
An optional component you can name anything. It is recommended to create this, as it wraps all other components, so it's useful for styling.
<IntroPage>stateQuizStatePropsThis is the intro page for the quiz. Contains the <Quiz.StartBtn />.
<QuestionPage>childrenReact.ReactNodeThis is a presentational component which wraps the question page. All question-related subcomponents will be passed here as children
<QuestionHeader />stateQuizStatePropsThe header for the question, it contains the overall quiz progress.
<QuestionInnerWrapper>childrenReact.ReactNodePresentational wrapper component, the children passed to it are the <QuestionBody> and <Explainer> (if used). Useful for styling.
<QuestionBody>stateQuizStatePropsContains the question and answers.
<Explainer>stateQuizStatePropsContains the explanation box.
<ResultPage>stateQuizStatePropsContains the final quiz result.

Provided components

The library provides some additional components used for navigating the quiz and displaying progress, although you can implement your own (see code examples below). All these receive the same state prop in order to keep the API simple. You need to ensure you use them in the appropriate components, otherwise you will encounter bugs.

ComponentPropsTypeUsed InDescription
<Quiz />config
data
components?
QuizConfig
QuizData
QuizComponents
Main quiz component. Can be used on its own if you don't pass any components
<Quiz.StartButton>children
state
className?
style?
React.ReactNode
QuizStateProps
string
React.CSSProperties
<IntroPage>
<ResultPage>
Start (or restart) button - in
<Quiz.QuestionNextButton>children
state
className?
style?
React.ReactNode
QuizStateProps
string
React.CSSProperties
<QuestionBody>Question Next button
<Quiz.ExplainerNextButton>children
state
className?
style?
React.ReactNode
QuizStateProps
string
React.CSSProperties
<Explainer>Explainer Next button
<Quiz.AnswerButton>children
state
index
className?
style?
React.ReactNode
QuizStateProps
numberstring
React.CSSProperties
<QuestionBody>Answer button
<Quiz.AutoResumeProgress />state
className?
style?
QuizStateProps
string
React.CSSProperties
<QuestionBody>Show the remaining time until the next question when autoResume is on

Component structure

This visualises how the implementable components wrap each other to help you with styling.

Intro

Question

Question and explainer

Question

Result

Question

Code example

This is an example of a custom quiz which uses the available implementable components. Uses tailwind css for styling. If it's not clear what each component contains, look at the pictures above this section. This is the same design/implementation as in the demo.

App.tsx


import type { QuizData } from "react-quiz-maker";
import MyQuiz from "./components/MyQuiz";
import scoredQuizData from "./scoredQuiz.json";

const config = {
	autoResume: true,
	autoResumeDelay: 1200,
	revealAnswer: false,
	explainerEnabled: false,
	explainerNewPage: false,
	animation: "slideUp",
} as const;

function App() {
	return <MyQuiz config={config} data={scoredQuizData as QuizData} />;
}

export default App;

scoredQuiz.json

See here.

Important points

  • If you omit any of the implementable components, it will use a default one. If you wish to omit it entirely (for example QuestionHeader), you can create a component that returns null.
  • If you'd like to omit the intro page, you can create an IntroPage component which in its body calls the handleStartBtnClick() function from the state to automatically start the quiz (will add code example in the near future).

FAQs

Package last updated on 06 Aug 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts