material-survey

2.1.0 • Public • Published

Material Survey

npm version

A material ui survey library for displaying and retrieving input from complex forms. Demo

This survey powers surveys on collegeai.com.

import Survey from "material-survey/components/Survey"

const App = () => (
  <Survey
    onFinish={answers => {
      // Do something with the answers
    }}
    form={{
      questions: [
        {
          name: "favorite-fruit",
          title: "What is your favorite fruit?",
          type: "dropdown",
          choices: ["Apple", "Orange", "Watermelon"]
        }
      ]
    }}
  />
)

Want new features? Found a bug? Feel free to leave an issue or a pull request.

Interactive Demo

The entire storybook for Material Survey can be viewed here. Click the components on the left side of the page to see example components, at the bottom of the page shows the code to produce each component.

The most important component in Material Survey is the Survey component, click here to view the Survey component.

Survey Props

const App = () => (
  <Survey
    // See the "format" section, this is the SurveyJS/Material Survey format
    form={
      {
        /* ... */
      }
    }
    // Optional: Invoked when the user clicks submit or finishes survey
    // AnswerObject => any
    onFinish={answers => null}
    // Optional: Required for file upload. Must handle uploading and return URL of file.
    // File => Promise<string>
    onFileUpload={file => ""}
    // Optional: Handles autocomplete requests, should return list of options for a given query
    // (requestUrl: string, queryValue: string) => Promise<Array<{ value: string, label: string, subLabel?: string }>>
    autocompleteRequest={(requestUrl, queryValue) => Promise.resolve([])}
    // Optional: Called anytime a question is changed
    // (questionId: string, newValue: any, answers: Object) => null
    onQuestionChange={(questionId, newValue, answers) => null}
    // Optional: default answers or previous answers to Survey
    // Object
    defaultAnswers={{}}
    // Optional: Style variants for the survey
    // "flat" | "paper"
    variant="paper"
    // Optional: Whether or not to show complete/next/prev buttons
    // boolean
    noActions={false}
    // Optional: Customize complete text/content. Accepts React element.
    // string | React$Element
    completeText="Complete"
  />
)

Format

The MaterialSurvey format is based off the SurveyJS format. Check docs/material-survey-format.md.

Developing / Testing

This project uses storybook. To develop features or create visual tests just run yarn install && yarn storybook in the cloned repository.

Readme

Keywords

none

Package Sidebar

Install

npm i material-survey

Weekly Downloads

997

Version

2.1.0

License

ISC

Unpacked Size

205 kB

Total Files

52

Last publish

Collaborators

  • seveibar