1.2.5 • Published 9 months ago

@rinxun/custom-questions v1.2.5

Weekly downloads
-
License
MIT
Repository
github
Last release
9 months ago

custom-questions is available as an npm package.

// with npm
npm install @rinxun/custom-questions

// with yarn
yarn add @rinxun/custom-questions

This project is licensed under the terms of the MIT license.

Here is a quick example to get you started:

TypeScript

import { useState } from 'react';
import { Enums, AnswerGroup, TextAnswerProps } from '@rinxun/custom-questions';

function CustomQuestionDemo() {
  const [textValue, setTextValue] = useState('');
  
  return (
      <AnswerGroup
        answerType={Enums.AnswerTypeEnum.shortText}
        question="What's your name?"
        answer={
          {
            name: 'demo',
            value: textValue,
            onChange: (val: string) => {
              setTextValue(val);
            },
            viewType: Enums.ViewTypeEnum.answer
          } as TextAnswerProps
        }
      />
  )
}

JavaScript

import { useState } from 'react';
import { Enums, AnswerGroup, TextAnswerProps } from '@rinxun/custom-questions';

function CustomQuestionDemo() {
  const [textValue, setTextValue] = useState('');
  
  return (
      <AnswerGroup
        answerType={Enums.AnswerTypeEnum.shortText}
        question="What's your name?"
        answer={
          {
            name: 'demo',
            value: textValue,
            onChange: (val) => {
              setTextValue(val);
            },
            viewType: Enums.ViewTypeEnum.answer
          }
        }
      />
  )
}

We prepared a live and interactive demo for you to get started.

NameDescription
shortTextIf you select it, we will render a text input box for you to answer.
longTextIf you select it, we will render a text area for you to answer.
uploadIf you select it, we will render an uploader for you to upload.
linkIf you select it, we will render a link input box for you to type.
singleChoiceIf you select it, we will render a radio group for you to pick.
multiChoiceIf you select it, we will render a checkbox group for you to pick.
NameDescription
httpHypertext Transfer Protocol, for loading web pages using hypertext links.
httpsHypertext Transfer Protocol Secure, a secure version of the HTTP protocol.
mailtoA type of HTML link that activates the default mail client on the computer for sending an e-mail.
ftpFile Transfer Protocol, for transferring files between computers.
sftpSecure File Transfer Protocol, for transferring large files over the web.
NameDescription
answerIf you select it, you can answer the question.
editIf you select it, you can edit the question.
previewIf you select it, you can preview the answer area.

You can use it to switch different answer types.

import { AnswerTypeSelector } from '@rinxun/custom-questions';
NameTypeDefaultRequiredDescription
colorstring (keyword, rgb, hex, etc)falseThe main color of the component.
labelstring'Select Answer Type'falseThe label of the Select element.
onChangefunctrueCallback fired when the Select value is changed.Signature:function(value: AnswerTypeEnum) => voidvalue: The value of the Select element.
valueAnswerTypeEnumtrueThe value of the Select element, required for a controlled component.
hiddenOptionsArray\<AnswerTypeEnum>[]falseThe options (answer types) you don't want to show in the options list of the selector.

It will help you to render a URL input component for answering.

import { LinkAnswer } from '@rinxun/custom-questions';
NameTypeDefaultRequiredDescription
colorstring (keyword, rgb, hex, etc)falseThe main color of the component.
disabledboolfalsefalseIf true, the component is disabled.
labelstringfalseThe label of the Input element.
linkTypeLinkTypeEnumtrueThe value of the Select element, required for a controlled component.
maxLengthnumberfalseMaximum number of length to type.
minLengthnumberfalseMinimum number of length to type.
namestringfalseThe name of the Input element.
onChangefunctrueCallback fired when the Input value is changed.Signature:function(value: string) => voidvalue: The value of the Input element.
onToggleLinkTypefunctrueCallback fired when the Select value is changed.Signature:function(value: LinkTypeEnum) => voidvalue: The value of the Select element.
requiredboolfalsefalseIf true, the Input is required.
valuestringtrueThe value of the Input element, required for a controlled component.
viewTypeViewTypeEnumtrueIf previewor edit you can preview the answer component;If answer you can answer the question.

You can use it to define the total score and the pass score.

import { Scoring } from '@rinxun/custom-questions';
NameTypeDefaultRequiredDescription
colorstring (keyword, rgb, hex, etc)falseThe main color of the component.
exceededErrTextstring'Pass Score should be less than the Total Score'falseThe error message when Pass Score is greater then Total Score.
onChangePassScorefunctrueCallback fired when the Pass Score Input value is changed.Signature:function(value: string) => voidvalue: The value of the Input element for Pass Score.
onChangeTotalScorefunctrueCallback fired when the Total Score Input value is changed.Signature:function(value: string) => voidvalue: The value of the Input element for Total Score.
onToggleScoringfunctrueCallback fired when the Switch value is changed.Signature:function(value: bool) => voidvalue: The value of the Switch element.
passScorestring | numbertrueThe value of the Input element for Pass Score.
passScoreLabelstring'Pass Score'falseThe label of the Input element for Pass Score.
totalScorestring | numbertrueThe value of the Input element for Total Score.
totalScoreLabelstring'Total Score'falseThe label of the Input element for Total Score.
turnOffScoringbooltrueThe value of the Switch element.
turnOffScoringLabelstring'Turn off scoring'falseThe label of the Switch element.

It will help you to render a text input component for answering..

import { TextAnswer } from '@rinxun/custom-questions';
NameTypeDefaultRequiredDescription
answerTypeAnswerTypeEnumtrueshortText or longText.
colorstring (keyword, rgb, hex, etc)falseThe main color of the component.
disabledboolfalsefalseIf true, the component is disabled.
labelstringfalseThe label of the Input element.
maxLengthnumberfalseMaximum number of length to type.
namestringfalseThe name of the Input element.
minLengthnumberfalseMinimum number of length to type.
onBlurfunctrueCallback fired when the Input value is blurred.
onChangefunctrueCallback fired when the Input value is changed.Signature:function(value: string) => voidvalue: The value of the Input element.
onFocusfunctrueCallback fired when the Input value is focused.
placeholderstring'Type your answer here...'falseThe placeholder of the Input element.
requiredboolfalsefalseIf true, the Input is required.
valuestringtrueThe value of the Input element, required for a controlled component.
viewTypeViewTypeEnumtrueIf previewor edit you can preview the answer component;If answer you can answer the question.

It will help you to render a Uploader component for uploading files.

import { UploaderAnswer } from '@rinxun/custom-questions';
NameTypeDefaultRequiredDescription
idstring|numbertrueThe unique id of the file.
fileNamestringtrueThe name of the file.
fileKeystringfalseThe unique key of the file, like from AWS S3.
NameTypeDefaultRequiredDescription
chooseFileTextstring'Choose a file'falseThe text of the Choose button.
colorstring (keyword, rgb, hex, etc)falseThe main color of the component.
dropFileTextstring'Drop files here'falseThe text of the Drop File Area.
filesArray\<FileProps>trueSee File Props above.
maxSizenumber5 (MB)falseMaximum of the uploading file size, UOM is MB.
multiplebooleanfalsefalseIf true then you can upload multiple files
onDownloadfunctrueCallback fired when downloaded the file.Signature:function(id: string) => voidid: The unique id of the file, but if fileKeyis not null/undefined, here you will get the fileKey instead of the id.
onRemovefunctrueCallback fired when removed the file.Signature:function(id: string) => voidid: The unique id of the removing file, but if fileKeyis not null/undefined, here you will get the fileKey instead of the id.
onUploadfunctrueCallback fired when uploaded a file.Signature:function(files: Array<File>, index?: number) => voidfiles: Acceptable files you uploaded.index: If more than 1 Uploader in the same page, you can define the index.
sizeExceededErrTextstringYour file exceed the max size of x MB.falseThe alert message when you uploaded a size exceeded file.x is the maximum of the uploading file size, if you set the maxSize that's it, otherwise, default to 5.
viewTypeViewTypeEnumtrueIf previewor edit you can preview the Uploader component;If answer you can upload files.
warmingTipsstring'Documents can be uploaded in pdf, xls, doc & jpeg formats. Maximum size allowed is x MB.'falseThe tip of the Uploader as helper text.x is the maximum of the uploading file size, if you set the maxSize that's it, otherwise, default to 5.
wrongFileTypeErrTextstring'The type of the file you uploaded is not accepted, please reupload!'falseThe alert message when you uploaded an unacceptable file.

You can use it to create/edit choices.

import { EditChoiceItems } from '@rinxun/custom-questions';
NameTypeDefaultRequiredDescription
correctAnswerboolfalseIf true that means this answer is the correct one.Required when needDefineCorrectAnswer (in the next table) is true.
labelstring'Choice x'falseThe label of the Input.x is an index number.
namestringtrueThe name of the Input. Also it is the unique id of the choice item.
valuestringtrueThe value of the Input.
NameTypeDefaultRequiredDescription
answerTypeAnswerTypeEnumtrueWhich kind of component you want to render for the answer.
colorstring (keyword, rgb, hex, etc)falseThe main color of the component.
correctAnswerIconTipTextstring'Toggle it as correct / incorrect answer'falseThe tooltip text of the tick icon button.
maxItemsnumberfalseMaximum number of items to add, it must be greater than 2.If null then unlimited.
maxItemsTipTextstring'A maximum of x choices can be set!'falseA warming tip to tell users the maximum number of items to add. Only be displayed when maxItems is not null.x is the maxItem value.
needDefineCorrectAnswerboolfalseIf true that means you have to define correct answers.At this moment, onToggleCorrectAnswer and correctAnswer are required.
onAddMorefunctrueCallback fired when the Add More button is clicked.Signature:function() => void
onChangefunctrueCallback fired when the Input value is changed.Signature:function(name: string, value: string) => voidname: The name of the Input element.value: The value of the Input element.
onRemovefunctrueCallback fired when removed the choice item.Signature:function(name: string) => voidname: The name of the Input element.
onToggleCorrectAnswerfuncfalseCallback fired when toggle the tick icon button at the end of the choice item.Signature:function(name: string) => voidname: The name of the Input element.Required when needDefineCorrectAnswer is true.
optionsArray\<ChoiceItemProps>trueSee Choice Item Props above.The length of options must be greater than 2.

It will help you to render a radio group component for answering.

import { SingleChoiseAnswer } from '@rinxun/custom-questions';
NameTypeDefaultRequiredDescription
colorstring (keyword, rgb, hex, etc)falseThe main color of the component.
namestringfalseThe name of the RadioGroup element.
optionsArray\<{ label: string; value: string }>trueThe radio options for rendering.
onChangefunctrueCallback fired when the Radio value is changed.Signature:function(value: string) => voidvalue: The value of the selected Radio element.
valuestringtrueThe selected value of the RadioGroup element.
viewTypeViewTypeEnumtrueIf previewor edit you can preview the RadioGroup component;If answer you can do single select.

It will help you to render a checkbox group component for answering.

import { MultiChoiseAnswer } from '@rinxun/custom-questions';
NameTypeDefaultRequiredDescription
colorstring (keyword, rgb, hex, etc)falseThe main color of the component.
namestringfalseThe name of the Form element.
onChangefunctrueCallback fired when the Radio value is changed.Signature:function(value: string, checked: boolean) => voidvalue: The value of the checked checkbox element.checked: if true that means the checkbox is checked, otherwise, unchecked.
optionsArray\<{ label: string; value: string }>trueThe checkbox options for rendering.
valueArray\<string>trueThe values of all checkedcheckbox elements.
viewTypeViewTypeEnumtrueIf previewor edit you can preview the checkbox component;If answer you can do multiple select.

You can use it to create/edit a question.

import { QuestionGroup } from '@rinxun/custom-questions';
NameTypeDefaultRequiredDescription
answerTypeAnswerTypeSelectorPropstrueSee props of AnswerTypeSelector .
choicesEditChoiceItemsPropstrueSee props of EditChoiceItems.
colorstring (keyword, rgb, hex, etc)falseThe main color of the component.
inputLabelstring'Preview'falseThe label of the TextAnswer and LinkAnswer .
onChangeQuestionfunctrueCallback fired when the Input value is changed.Signature:function(value: string) => voidvalue: The value of the Input element.
questionstringtrueThe value of the Question Input element.
questionLabelstring'Enter Question'falseThe label of the Question Input element.
scoringScoringPropsfalseSee props of Scoring. Required if showScoring is true.
showScoringbooleanfalsefalseIf true, the Scoring will be rendered.

You can use it to render a component for answering.

import { AnswerGroup } from '@rinxun/custom-questions';
NameTypeDefaultRequiredDescription
answerLinkAnswerProps | TextAnswerProps | UploaderAnswerProps | SingleChoiceAnswerProps | MultiChoiceAnswerPropstrueSee the corresponding props above.
answerTypeAnswerTypeEnumtrueWhich kind of component you want to render for the answer.
questionstringtrueThe text to describe the question.
requiredbooleanfalsefalseIf true the red asterisk would be shown next to the question.

If you have recently updated, please read the changelog for details of what has changed.

1.2.5

9 months ago

1.2.5-alpha.1

10 months ago

1.2.5-alpha.2

10 months ago

1.2.5-alpha.3

10 months ago

1.2.5-alpha.4

10 months ago

1.2.5-alpha.5

10 months ago

1.2.5-alpha.6

10 months ago

1.2.0

2 years ago

1.2.4

2 years ago

1.2.3

2 years ago

1.2.2

2 years ago

1.2.1

2 years ago

1.1.15

2 years ago

1.1.14

2 years ago

1.1.12

2 years ago

1.1.11

2 years ago

1.1.10

2 years ago

1.1.13

2 years ago

1.1.9

2 years ago

1.1.1

2 years ago

1.1.0

2 years ago

1.1.8

2 years ago

1.0.9

2 years ago

1.1.7

2 years ago

1.0.8

2 years ago

1.1.6

2 years ago

1.1.5

2 years ago

1.1.4

2 years ago

1.1.3

2 years ago

1.1.2

2 years ago

1.0.7

3 years ago

1.0.6

3 years ago

1.0.5

3 years ago

1.0.4

3 years ago

1.0.3

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago

1.0.0-rc3

3 years ago

1.0.0-rc2

3 years ago

1.0.0-rc1

3 years ago