项目作者: AntonelaPrica

项目描述 :
Survey Builder/Viewer Component
高级语言: TypeScript
项目地址: git://github.com/AntonelaPrica/survey-ui.git
创建时间: 2021-05-29T12:32:24Z
项目社区:https://github.com/AntonelaPrica/survey-ui

开源协议:MIT License

下载


survey-ui

Prerequisites

  • Node.js

Project and Storybook setup

  • clone the repository git clone https://github.com/AntonelaPrica/survey-ui.git
  • run npm install to install the dependencies
  • run npm run storybook to start up the storybook

Library Installation

In order to use the survey library you should install it from npm using
npm install survey-component-lib.

Survey Usage

Use the tag <sv-survey> in your html with the following properties:

  • survey - object that must implement the interface Survey of the following form:
    1. {
    2. title: string;
    3. questions: SurveyQuestion[];
    4. }
    where a Survey Question is of the form:
    1. {
    2. text: string;
    3. type: QuestionType;
    4. data: QuestionVariant[] | string;
    5. }
    and a QuestionVariant:
    1. {
    2. isSelected: boolean;
    3. text: string;
    4. }

The allowed QuestionTypes are ‘Free Text’ or ‘Variant’.

  • isEditMode - boolean value; if the value passed is true, then the component can be used to create a new custom survey; in case of value false it will display the survey passed at the previous mentioned property (survey)

Pressing the Submit button at the end of the survey will emit the submitSurvey event which will contain the survey with questions or answers.

Usage Examples

Builder

<sv-survey [survey]="survey" [isEditMode]="true" (submitSurvey)="onSubmitSurvey($event)">

  1. survey: Survey = {
  2. title: '',
  3. questions: [{text: '', type: QuestionType.FreeText, data: ''}]
  4. };

builder

Viewer

<sv-survey [survey]="survey" [isEditMode]="false" (submitSurvey)="onSubmitSurvey($event)">

  1. survey: Survey = {
  2. title: 'Geography Test',
  3. questions: [{
  4. text: 'What is the official language of the Canadian province Quebec?',
  5. type: QuestionType.FreeText,
  6. data: ''
  7. },
  8. {
  9. text: 'How many countries are there in Africa?',
  10. type: QuestionType.Variants,
  11. data: [{text: '54'}, {text: '60'}, {text: '72'}] as QuestionVariant[]
  12. }]
  13. };

viewer