npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

react-mcqview

v1.0.7

Published

A customizable multiple choice question react component that is based on the superflows design language.

Downloads

12

Readme

react-mcqview

A customizable multiple choice question react component that is based on the superflows design language.

NPM JavaScript Style Guide

Install

npm install --save react-mcqview

Install the dependencies.

Dependencies

npm install --save bootstrap
npm install --save react-bootstrap
npm install --save react-bootstrap-icons
npm install --save react-ui-components-superflows

Functionality

This package allows you to easily create customizable multiple choice question forms in React. You can either choose a single question component, which is called McqView, or a complete form McqForm. This package also allows conditional rendering, wherein certain questions are displayed based on the answer of previous questions.

Components

McqView - a multiple choice question component

Props

  • question: text of the question
  • answers: array of answers, every answer needs to have text, id
  • multiSelect: allow selecting multiple answers
  • selectedValue: array of answer ids, used to prepopulate answers
  • setValue: function to be called when value is set
  • onChange: function to be called when value is changed

Demo

Demo

Usage


import React from 'react';
import { useState, useRef } from 'react';
import { McqView } from 'react-mcqview';
import 'bootstrap/dist/css/bootstrap.min.css';

const App = () => {
  // Stores the stringified representation
  const [value, setValue] = useState('');

  function onChange(value) {
    console.log('value changed', value);
  }

  return (
    <McqView
      question="Do you love fried noodles?"
      answers={[
        { answer: 'Yes', id: 1 },
        { answer: 'No', id: 2 },
        { answer: "Can't Say", id: 3 },
      ]}
      multiSelect={true}
      selectedValue={[1, 2]}
      setValue={setValue}
      onChange={onChange}
    />
  );
};

export default App;

McqForm - a multiple choice question form component

Props

  • formData: data of questions in json array format
  • onComplete: callback after the form is completely filled
  • showSubmit: show submit button
  • onSubmit: callback after submit button clicked (applicable on when showSubmit is set as true)

Formdata

A sample formdata is show below in the usage section. Form data is an array of question data. Each question data contains the following

  • id of the question (you will have to specify that)
  • text of the questions
  • possible list of answers to the question, each answer needs to have its own id
  • a flag to allow selecting multiple answers for that question
  • display condition, if the question depends on some answer(s) of any of the previous questions

Demo

Demo

Usage


import React from 'react'
import { useState, useRef } from "react";
import { Col, Row, Container } from 'react-bootstrap';
import { McqForm } from 'react-mcqview'
import 'bootstrap/dist/css/bootstrap.min.css';

const App = () => {

  // Stores the stringified representation
  const [value, setValue] = useState('');

  function onSubmit(values) {
    console.log('form submitted changed', values);
  }

  const data = [
    {
      id: 1,
      question: "Do you love fried noodles?",
      answers: [
        {answer: "Yes", id: 1},
        {answer: "No", id: 2},
        {answer: "Can't Say", id: 3}
      ],
      multiSelect: true
    },
    {
      id: 2,
      condition: {
        question: 1, answer: [2]
      },
      question: "Okay, then do you love fried rice?",
      answers: [
        {answer: "Yes", id: 1},
        {answer: "No", id: 2},
        {answer: "Can't Say", id: 3}
      ],
      multiSelect: true
    },
    {
      id: 3,
      condition: {
        question: 2, answer: [2]
      },
      question: "What about chicken soup?",
      answers: [
        {answer: "I love it!", id: 1},
        {answer: "Next, please", id: 2},
      ],
      multiSelect: true
    }
  
  ]

  return  ( 
  
    <Container className='mt-5'>
      <Row className='justify-content-center'>
        <Col sm={12} xs={12} md={6} xxl={6}>
          <McqForm 
            formData={data}
            onComplete={(result) => {console.log('result', result);}}
            showSubmit={true}
            onSubmit={(result) => {console.log('onsubmit result', result);}} />
        </Col>
      </Row>
    </Container>

  )
  
}

export default App

Tests

PASS src/index.test.js (15.952s)

  • ✓ McqView: Render of McqView without preselected values (39ms)
  • ✓ McqView: Render of McqView with preselected values (7ms)
  • ✓ McqView: Select answer (multiselect) (1019ms)
  • ✓ McqView: Select answer (singleselect) (2017ms)
  • ✓ McqView: Unselect answer 1 (multiselect) (2017ms)
  • ✓ McqView: Unselect answer 2 (multiselect) (2013ms)
  • ✓ McqView: Unselect answers 1 (singleselect) (2018ms)
  • ✓ McqView: Unselect answers 1 (singleselect) (2019ms)
  • ✓ McqForm: Basic Render (11ms)
  • ✓ McqForm: Complete without conditionals (1021ms)
  • ✓ McqForm: Render conditionals (2037ms)

----------------|----------|----------|----------|----------|-------------------| File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s | ----------------|----------|----------|----------|----------|-------------------| All files | 93.86 | 86.49 | 92 | 93.2 | | src | 0 | 0 | 0 | 0 | | index.js | 0 | 0 | 0 | 0 | | src/components | 93.86 | 86.49 | 92 | 93.2 | | McqForm.js | 91.55 | 86.36 | 87.5 | 90.77 |... 46,147,148,206 | McqView.js | 97.67 | 86.67 | 100 | 97.37 | 82 | ----------------|----------|----------|----------|----------|-------------------| Test Suites: 1 passed, 1 total Tests: 11 passed, 11 total Snapshots: 0 total Time: 16.743s Ran all test suites.

License

MIT © superflows-dev