
Security News
Vite Releases Technical Preview of Rolldown-Vite, a Rust-Based Bundler
Vite releases Rolldown-Vite, a Rust-based bundler preview offering faster builds and lower memory usage as a drop-in replacement for Vite.
@ovos-media/generic-quiz
Advanced tools
A generic quiz widget which can display text, image, video or audio sources as answers or question.
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).
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'
];
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:
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'))}
/>
);
}
$ 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
(C) 2016 ovos media gmbh
FAQs
A generic quiz widget which can display text, image, video or audio sources as answers or question.
We found that @ovos-media/generic-quiz demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 13 open source maintainers collaborating on the project.
Did you know?
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.
Security News
Vite releases Rolldown-Vite, a Rust-based bundler preview offering faster builds and lower memory usage as a drop-in replacement for Vite.
Research
Security News
A malicious npm typosquat uses remote commands to silently delete entire project directories after a single mistyped install.
Research
Security News
Malicious PyPI package semantic-types steals Solana private keys via transitive dependency installs using monkey patching and blockchain exfiltration.