New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@ovos-media/generic-quiz

Package Overview
Dependencies
Maintainers
13
Versions
33
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@ovos-media/generic-quiz

A generic quiz widget which can display text, image, video or audio sources as answers or question.

  • 1.6.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
13
Created
Source

[widget] generic quiz

A generic quiz widget which can display text, image, video or audio sources as answers or question. You may even define nested data structures as well as provide custom react components as answer or question elements.

This widget is a purely presentational component. It does not handle logic for you (e.g. correct/incorrect).

Usage

The easiest way to use the generic quiz widget is by specifying a string question, and an array of answer strings.

To handle correct / incorrect choices, pass a onChange prop to the Quiz element to get notified about "which" answer has been clicked. This callback will get the original answer data-object as a parameter so you can check if the answer was correct and do your stuff.

import { Quiz } from '@ovos-media/generic-quiz';

const question = 'Some Question';
const answers = ['Answer 1', 'Answer 2', 'Answer 3'];

function handleChange(answer) {
  if (answer.data === answers[0]) {
    console.log('Answer correct!');
  } else {
    console.log('Answer incorrect :(');
  }
}

export default function MyCoolQuiz() {
  return (
    <Quiz
      question={question}
      answers={answers}
      onChange={handleChange}
    />
  );
}

It is also possible to use so-called data objects as your question or answers.

const question = { type: 'image', src: 'pen.jpg' };
const answers = [
  { type: 'image', src: 'apple.jpg' },
  { type: 'image', src: 'pineapple.jpg' },
  { type: 'image', src: 'pen-pineapple-apple-pen.jpg' }
];

// other types would be
const video = { type: 'video', src: 'apple-pen.mp4' };
const audio = { type: 'audio', src: 'pineapple-pen.mp4' };
const string = { type: 'string', text: 'Pen-Pineapple-Apple-Pen' };

// in order to nest these objects, you just put them into an array
const multipleVideos = [
  { type: 'video', src: 'apple-pen.mp4' },
  'This is cool',
  { type: 'video', src: 'pineapple-pen.mp4' }
];

// these can also be nested. it's a recursive operation
const multipleImages = [
  [
    { type: 'image', src: 'whoop.jpg' },
    { type: 'image', src: 'whoop-whoop.jpg' }
  ],
  'Oppa Gangnam Style'
];

Theming

This block utilizes the fabulous amazing react-themeit library which allows you to customize the look of the widget easily.

Currently available elements for theming are:

  • container: container of the widget
  • question: the question
  • answers: the container for answers
  • answer: a single answer

To style the block you can utilize the various possibilities which react-themeit gives you, the simplest example is passing a js style object to the element:

import { Quiz } from '@ovos-media/generic-quiz';

export default function MyCoolQuiz() {
  const question = 'Some Question';
  const answers = ['Answer 1', 'Answer 2', 'Answer 3'];

  return (
    <Quiz
      question={question}
      answers={answers}
      styles={{
        container: {
          fontSize: 12
        },
        answer: {
          ':hover': {
            cursor: 'pointer'
          }
        }
      }}
      addFiles={cb => cb(require('myQuizTheme.less'))}
    />
  );
}

Development Commands

$ builder run start:dev # starts the dev version of the application (HMR, sourcemaps, ...)

$ builder run test-client # runs client tests using karma & runs tests in chrome
$ builder run test-server # runs server tests using mocha

$ builder run test-all:watch # watch mode for tests

License

(C) 2016 ovos media gmbh

FAQs

Package last updated on 15 May 2018

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc