@constructor-io/constructorio-ui-quizzes 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (88) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +88 -0
  3. package/lib/cjs/components/BackButton/BackButton.js +12 -0
  4. package/lib/cjs/components/CTAButton/CTAButton.js +10 -0
  5. package/lib/cjs/components/CioQuiz/actions.js +12 -0
  6. package/lib/cjs/components/CioQuiz/context.js +5 -0
  7. package/lib/cjs/components/CioQuiz/index.js +115 -0
  8. package/lib/cjs/components/CioQuiz/reducer.js +32 -0
  9. package/lib/cjs/components/ControlBar/ControlBar.js +13 -0
  10. package/lib/cjs/components/CoverTypeQuestion/CoverTypeQuestion.js +42 -0
  11. package/lib/cjs/components/OpenTextTypeQuestion/OpenTextTypeQuestion.js +66 -0
  12. package/lib/cjs/components/QuestionDescription/QuestionDescription.js +9 -0
  13. package/lib/cjs/components/QuestionTitle/QuestionTitle.js +9 -0
  14. package/lib/cjs/components/QuizQuestions/index.js +17 -0
  15. package/lib/cjs/components/RedoButton/RedoButton.js +12 -0
  16. package/lib/cjs/components/RedoButton/RedoSVG.js +15 -0
  17. package/lib/cjs/components/ResultCard/ResultCard.js +45 -0
  18. package/lib/cjs/components/ResultContainer/ResultContainer.js +39 -0
  19. package/lib/cjs/components/ResultCtaButton/ResultCtaButton.js +16 -0
  20. package/lib/cjs/components/ResultFilters/ResultFilters.js +30 -0
  21. package/lib/cjs/components/Results/Results.js +16 -0
  22. package/lib/cjs/components/SelectTypeQuestion/SelectTypeQuestion.js +90 -0
  23. package/lib/cjs/components/Spinner/Spinner.js +12 -0
  24. package/lib/cjs/components/ZeroResults/ZeroResults.js +13 -0
  25. package/lib/cjs/constants.js +36 -0
  26. package/lib/cjs/hooks/useCioClient.js +11 -0
  27. package/lib/cjs/index.js +5 -0
  28. package/lib/cjs/stories/Quiz/argTypes.js +30 -0
  29. package/lib/cjs/types.js +2 -0
  30. package/lib/cjs/utils.js +97 -0
  31. package/lib/mjs/components/BackButton/BackButton.js +9 -0
  32. package/lib/mjs/components/CTAButton/CTAButton.js +7 -0
  33. package/lib/mjs/components/CioQuiz/actions.js +9 -0
  34. package/lib/mjs/components/CioQuiz/context.js +2 -0
  35. package/lib/mjs/components/CioQuiz/index.js +111 -0
  36. package/lib/mjs/components/CioQuiz/reducer.js +55 -0
  37. package/lib/mjs/components/ControlBar/ControlBar.js +10 -0
  38. package/lib/mjs/components/CoverTypeQuestion/CoverTypeQuestion.js +37 -0
  39. package/lib/mjs/components/OpenTextTypeQuestion/OpenTextTypeQuestion.js +61 -0
  40. package/lib/mjs/components/QuestionDescription/QuestionDescription.js +6 -0
  41. package/lib/mjs/components/QuestionTitle/QuestionTitle.js +6 -0
  42. package/lib/mjs/components/QuizQuestions/index.js +13 -0
  43. package/lib/mjs/components/RedoButton/RedoButton.js +9 -0
  44. package/lib/mjs/components/RedoButton/RedoSVG.js +12 -0
  45. package/lib/mjs/components/ResultCard/ResultCard.js +37 -0
  46. package/lib/mjs/components/ResultContainer/ResultContainer.js +34 -0
  47. package/lib/mjs/components/ResultCtaButton/ResultCtaButton.js +12 -0
  48. package/lib/mjs/components/ResultFilters/ResultFilters.js +27 -0
  49. package/lib/mjs/components/Results/Results.js +9 -0
  50. package/lib/mjs/components/SelectTypeQuestion/SelectTypeQuestion.js +85 -0
  51. package/lib/mjs/components/Spinner/Spinner.js +8 -0
  52. package/lib/mjs/components/ZeroResults/ZeroResults.js +10 -0
  53. package/lib/mjs/constants.js +33 -0
  54. package/lib/mjs/hooks/useCioClient.js +9 -0
  55. package/lib/mjs/index.js +2 -0
  56. package/lib/mjs/stories/Quiz/argTypes.js +27 -0
  57. package/lib/mjs/types.js +1 -0
  58. package/lib/mjs/utils.js +83 -0
  59. package/lib/styles.css +689 -0
  60. package/lib/types/components/BackButton/BackButton.d.ts +3 -0
  61. package/lib/types/components/CTAButton/CTAButton.d.ts +6 -0
  62. package/lib/types/components/CioQuiz/actions.d.ts +25 -0
  63. package/lib/types/components/CioQuiz/context.d.ts +17 -0
  64. package/lib/types/components/CioQuiz/index.d.ts +14 -0
  65. package/lib/types/components/CioQuiz/reducer.d.ts +12 -0
  66. package/lib/types/components/ControlBar/ControlBar.d.ts +10 -0
  67. package/lib/types/components/CoverTypeQuestion/CoverTypeQuestion.d.ts +2 -0
  68. package/lib/types/components/OpenTextTypeQuestion/OpenTextTypeQuestion.d.ts +7 -0
  69. package/lib/types/components/QuestionDescription/QuestionDescription.d.ts +6 -0
  70. package/lib/types/components/QuestionTitle/QuestionTitle.d.ts +6 -0
  71. package/lib/types/components/QuizQuestions/index.d.ts +5 -0
  72. package/lib/types/components/RedoButton/RedoButton.d.ts +6 -0
  73. package/lib/types/components/RedoButton/RedoSVG.d.ts +3 -0
  74. package/lib/types/components/ResultCard/ResultCard.d.ts +11 -0
  75. package/lib/types/components/ResultContainer/ResultContainer.d.ts +7 -0
  76. package/lib/types/components/ResultCtaButton/ResultCtaButton.d.ts +9 -0
  77. package/lib/types/components/ResultFilters/ResultFilters.d.ts +6 -0
  78. package/lib/types/components/Results/Results.d.ts +10 -0
  79. package/lib/types/components/SelectTypeQuestion/SelectTypeQuestion.d.ts +3 -0
  80. package/lib/types/components/Spinner/Spinner.d.ts +2 -0
  81. package/lib/types/components/ZeroResults/ZeroResults.d.ts +6 -0
  82. package/lib/types/constants.d.ts +11 -0
  83. package/lib/types/hooks/useCioClient.d.ts +8 -0
  84. package/lib/types/index.d.ts +2 -0
  85. package/lib/types/stories/Quiz/argTypes.d.ts +30 -0
  86. package/lib/types/types.d.ts +1 -0
  87. package/lib/types/utils.d.ts +31 -0
  88. package/package.json +91 -0
@@ -0,0 +1,17 @@
1
+ import React from 'react';
2
+ import { RequestStates } from '../../constants';
3
+ import { NextQuestionResponse, GetBrowseResultsResponse } from '../../types';
4
+ import { ActionAnswerQuestion } from './actions';
5
+ import { QuizReducerState } from './reducer';
6
+ interface QuizContextValue {
7
+ state: QuizReducerState;
8
+ requestState: RequestStates;
9
+ questionResponse: NextQuestionResponse;
10
+ resultsResponse: GetBrowseResultsResponse;
11
+ isFirstQuestion: boolean;
12
+ quizNextHandler: (action?: ActionAnswerQuestion) => void;
13
+ quizBackHandler: () => void;
14
+ dispatch: React.Dispatch<ActionAnswerQuestion>;
15
+ }
16
+ declare const _default: React.Context<Partial<QuizContextValue>>;
17
+ export default _default;
@@ -0,0 +1,14 @@
1
+ /// <reference types="react" />
2
+ import ConstructorIOClient from '@constructor-io/constructorio-client-javascript';
3
+ import { ResultsProps } from '../Results/Results';
4
+ export interface ResultsPageOptions extends ResultsProps {
5
+ numResultsToDisplay?: number;
6
+ }
7
+ export interface IQuizProps {
8
+ quizId: string;
9
+ apiKey?: string;
10
+ cioJsClient?: ConstructorIOClient;
11
+ resultsPageOptions: ResultsPageOptions;
12
+ quizVersionId?: string;
13
+ }
14
+ export default function CioQuiz(props: IQuizProps): JSX.Element | null;
@@ -0,0 +1,12 @@
1
+ import { ActionAnswerQuestion, OpenTextQuestionPayload, SelectQuestionPayload } from './actions';
2
+ export type Answers = string[][];
3
+ export type QuizReducerState = {
4
+ answers: Answers;
5
+ answerInputs: {};
6
+ isLastAnswer: boolean;
7
+ };
8
+ export type AnswerInputState = {
9
+ [key: string]: OpenTextQuestionPayload | SelectQuestionPayload;
10
+ };
11
+ export declare const initialState: QuizReducerState;
12
+ export default function reducer(state: QuizReducerState, action: ActionAnswerQuestion): QuizReducerState;
@@ -0,0 +1,10 @@
1
+ /// <reference types="react" />
2
+ interface ControlBarProps {
3
+ showBackButton?: boolean;
4
+ isNextButtonDisabled?: boolean;
5
+ backButtonHandler?: () => void;
6
+ nextButtonHandler: () => void;
7
+ ctaButtonText?: string;
8
+ }
9
+ declare function ControlBar(props: ControlBarProps): JSX.Element;
10
+ export default ControlBar;
@@ -0,0 +1,2 @@
1
+ /// <reference types="react" />
2
+ export default function CoverTypeQuestion(): JSX.Element | null;
@@ -0,0 +1,7 @@
1
+ import React from 'react';
2
+ interface OpenTextQuestionProps {
3
+ initialValue?: string;
4
+ onChangeHandler?: React.ChangeEventHandler<HTMLInputElement>;
5
+ }
6
+ declare function OpenTextQuestion(props: OpenTextQuestionProps): JSX.Element | null;
7
+ export default OpenTextQuestion;
@@ -0,0 +1,6 @@
1
+ /// <reference types="react" />
2
+ interface QuestionDescriptionProps {
3
+ description: string;
4
+ }
5
+ declare function QuestionDescription(props: QuestionDescriptionProps): JSX.Element;
6
+ export default QuestionDescription;
@@ -0,0 +1,6 @@
1
+ /// <reference types="react" />
2
+ interface QuestionTitleProps {
3
+ title: string;
4
+ }
5
+ declare function QuestionTitle(props: QuestionTitleProps): JSX.Element;
6
+ export default QuestionTitle;
@@ -0,0 +1,5 @@
1
+ /// <reference types="react" />
2
+ import { NextQuestionResponse } from '../../types';
3
+ export default function QuizQuestions(props: {
4
+ questionResponse: NextQuestionResponse;
5
+ }): JSX.Element;
@@ -0,0 +1,6 @@
1
+ import React from 'react';
2
+ interface RedoButtonProps extends React.ButtonHTMLAttributes<HTMLButtonElement> {
3
+ redoText?: string;
4
+ }
5
+ declare function RedoButton(props: RedoButtonProps): JSX.Element;
6
+ export default RedoButton;
@@ -0,0 +1,3 @@
1
+ /// <reference types="react" />
2
+ declare function RedoSVG(): JSX.Element;
3
+ export default RedoSVG;
@@ -0,0 +1,11 @@
1
+ /// <reference types="react" />
2
+ import { BrowseResultData } from '../../types';
3
+ interface ResultCardProps {
4
+ result: Partial<BrowseResultData>;
5
+ addToCartCallback: (clickedResult: Partial<BrowseResultData>) => any;
6
+ clickItemCallback?: (clickedResult: Partial<BrowseResultData>) => any;
7
+ salePriceKey?: string;
8
+ regularPriceKey?: string;
9
+ }
10
+ export default function ResultCard(props: ResultCardProps): JSX.Element;
11
+ export {};
@@ -0,0 +1,7 @@
1
+ /// <reference types="react" />
2
+ import { ResultsProps } from '../Results/Results';
3
+ export interface IResultContainerProps {
4
+ options: ResultsProps;
5
+ resetQuizSessionId: () => void;
6
+ }
7
+ export default function ResultContainer(props: IResultContainerProps): JSX.Element;
@@ -0,0 +1,9 @@
1
+ /// <reference types="react" />
2
+ import { BrowseResultData } from '../../types';
3
+ interface ResultCtaButtonProps {
4
+ item: Partial<BrowseResultData>;
5
+ className?: string;
6
+ callback?: (item: Partial<BrowseResultData>) => any;
7
+ }
8
+ export default function ResultCtaButton(props: ResultCtaButtonProps): JSX.Element;
9
+ export {};
@@ -0,0 +1,6 @@
1
+ import React from 'react';
2
+ interface ResultFiltersProps extends React.ButtonHTMLAttributes<HTMLButtonElement> {
3
+ filters?: any;
4
+ }
5
+ declare function ResultFilters(props: ResultFiltersProps): JSX.Element;
6
+ export default ResultFilters;
@@ -0,0 +1,10 @@
1
+ /// <reference types="react" />
2
+ import { BrowseResultData } from '../../types';
3
+ export interface ResultsProps {
4
+ addToCartCallback: (item: Partial<BrowseResultData>) => any;
5
+ clickItemCallback?: (item: Partial<BrowseResultData>) => any;
6
+ resultCardSalePriceKey?: string;
7
+ resultCardRegularPriceKey?: string;
8
+ }
9
+ declare function Results(props: ResultsProps): JSX.Element;
10
+ export default Results;
@@ -0,0 +1,3 @@
1
+ /// <reference types="react" />
2
+ declare function SelectTypeQuestion(): JSX.Element | null;
3
+ export default SelectTypeQuestion;
@@ -0,0 +1,2 @@
1
+ /// <reference types="react" />
2
+ export default function Spinner(): JSX.Element;
@@ -0,0 +1,6 @@
1
+ import React from 'react';
2
+ interface ZeroResultsProps extends React.ButtonHTMLAttributes<HTMLButtonElement> {
3
+ onResetClick?: () => {};
4
+ }
5
+ declare function ZeroResults(props: ZeroResultsProps): JSX.Element;
6
+ export default ZeroResults;
@@ -0,0 +1,11 @@
1
+ export declare const apiKey = "key_wJSdZSiesX5hiVLt";
2
+ export declare const quizId = "coffee-quiz";
3
+ export declare const componentDescription = "- import `CioQuiz` to render in your JSX.\n- This component handles state management, data fetching, and rendering logic.\n- To use this component, `quizId`, `resultsPageOptions`, and one of `apiKey` or `cioJsClient` are required.\n- `resultsPageOptions` lets you configure the results page\n - `addToCartCallback` is a callback function that will be called when the \"Add to cart\" button is clicked\n - `clickItemCallback` is an optional callback function that will be called when the result card is clicked. The default behavior is redirecting the user to the item's URL\n - `resultCardRegularPriceKey` is a parameter that specifies the metadata field name for the regular price\n - `resultCardSalePriceKey` is an optional parameter that specifies the metadata field name for the sale price\n- Use different props to configure the behavior of this component.\n- The following stories show how different props affect the component's behavior\n\n> Note: `cioJsClient` refers to an instance of the [constructorio-client-javascript](https://www.npmjs.com/package/@constructor-io/constructorio-client-javascript)\n";
4
+ export declare const basicDescription = "Pass an `apiKey` and a `quizId` to request questions and quiz results from Constructor's servers";
5
+ export declare const cioJsClientDescription = "If you are already using an instance of the `ConstructorIOClient`, you can pass a `cioJsClient` instead of an `apiKey` to request results from Constructor's servers\n\n> Note: `cioJsClient` refers to an instance of the [constructorio-client-javascript](https://www.npmjs.com/package/@constructor-io/constructorio-client-javascript)";
6
+ export declare enum RequestStates {
7
+ Stale = 0,
8
+ Loading = 1,
9
+ Success = 2,
10
+ Error = 3
11
+ }
@@ -0,0 +1,8 @@
1
+ import ConstructorIOClient from '@constructor-io/constructorio-client-javascript';
2
+ export type CioClientConfig = {
3
+ apiKey?: string;
4
+ cioJsClient?: ConstructorIOClient;
5
+ };
6
+ type UseCioClient = (cioClientConfig: CioClientConfig) => ConstructorIOClient | null;
7
+ declare const useCioClient: UseCioClient;
8
+ export default useCioClient;
@@ -0,0 +1,2 @@
1
+ import CioQuiz from './components/CioQuiz';
2
+ export default CioQuiz;
@@ -0,0 +1,30 @@
1
+ export declare const argTypes: {
2
+ apiKey: {
3
+ type: {
4
+ name: string;
5
+ };
6
+ description: string;
7
+ table: {
8
+ type: {
9
+ summary: string;
10
+ };
11
+ };
12
+ control: {
13
+ type: string;
14
+ };
15
+ };
16
+ quizId: {
17
+ type: {
18
+ name: string;
19
+ };
20
+ description: string;
21
+ table: {
22
+ type: {
23
+ summary: string;
24
+ };
25
+ };
26
+ control: {
27
+ type: string;
28
+ };
29
+ };
30
+ };
@@ -0,0 +1 @@
1
+ export type { QuestionOption, QuestionImages, Question, NextQuestionResponse, QuizResultsResponse, GetBrowseResultsResponse, BrowseResultData, BrowseRequestType, QuizzesParameters, QuizzesResultsParameters, } from '@constructor-io/constructorio-client-javascript/lib/types';
@@ -0,0 +1,31 @@
1
+ import ConstructorIOClient from '@constructor-io/constructorio-client-javascript';
2
+ import { QuestionTypes } from './components/CioQuiz/actions';
3
+ import { QuestionImages, QuizzesParameters, QuizzesResultsParameters, NextQuestionResponse, QuizResultsResponse } from './types';
4
+ export declare const renderImages: (images: Partial<QuestionImages>, cssClasses?: string) => JSX.Element | "";
5
+ export declare const getStoryParams: (storyCode: any, templateCode: any, importCode: any) => {
6
+ docs: {
7
+ source: {
8
+ code: string;
9
+ language: string;
10
+ format: boolean;
11
+ type: string;
12
+ };
13
+ };
14
+ };
15
+ export declare const defaultAddToCartCallbackCode = "\"addToCartCallback\": (item) => console.dir(item)";
16
+ export declare const stringifyWithDefaults: (obj: {
17
+ cioJsClient?: any;
18
+ addToCartCallback: any;
19
+ }) => string;
20
+ export declare const stringify: (obj: any) => string;
21
+ export declare const getNextQuestion: (cioClient: ConstructorIOClient, quizId: string, parameters: QuizzesParameters) => Promise<NextQuestionResponse>;
22
+ export declare const getQuizResults: (cioClient: ConstructorIOClient, quizId: string, parameters: QuizzesResultsParameters) => Promise<QuizResultsResponse>;
23
+ export declare const getQuestionTypes: (questionType?: `${QuestionTypes}`) => {
24
+ isOpenQuestion: boolean;
25
+ isCoverQuestion: boolean;
26
+ isSingleQuestion: boolean;
27
+ isMultipleQuestion: boolean;
28
+ isSelectQuestion: boolean;
29
+ };
30
+ export declare const getCioClient: (apiKey?: string) => ConstructorIOClient | null;
31
+ export declare function getPreferredColorScheme(): string;
package/package.json ADDED
@@ -0,0 +1,91 @@
1
+ {
2
+ "name": "@constructor-io/constructorio-ui-quizzes",
3
+ "version": "1.0.1",
4
+ "description": "Constructor.io Quizzes UI library for web applications",
5
+ "author": "constructor.io",
6
+ "license": "MIT",
7
+ "homepage": "https://github.com/Constructor-io/constructorio-ui-quizzes#readme",
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "git+https://github.com/Constructor-io/constructorio-ui-quizzes.git"
11
+ },
12
+ "bugs": {
13
+ "url": "https://github.com/Constructor-io/constructorio-ui-quizzes/issues"
14
+ },
15
+ "main": "lib/cjs/index.js",
16
+ "module": "lib/mjs/index.js",
17
+ "exports": {
18
+ "./styles.css": {
19
+ "import": "./lib/styles.css",
20
+ "require": "./lib/styles.css"
21
+ },
22
+ ".": {
23
+ "import": "./lib/mjs/index.js",
24
+ "require": "./lib/cjs/index.js"
25
+ }
26
+ },
27
+ "files": [
28
+ "lib/**/*"
29
+ ],
30
+ "engines": {
31
+ "node": ">=14"
32
+ },
33
+ "types": "lib/types/index.d.ts",
34
+ "scripts": {
35
+ "lint": "eslint src --ext js,ts,jsx,tsx",
36
+ "check-types": "npx tsc --noEmit",
37
+ "copy-styles": "cp src/styles.css lib/styles.css",
38
+ "prepare": "husky install",
39
+ "dev": "storybook dev -p 6006",
40
+ "storybook:ci": "storybook dev --ci --quiet -p 6006",
41
+ "test-storybook": "test-storybook",
42
+ "test-storybook:watch": "test-storybook --watch",
43
+ "test-storybook:ci": "start-server-and-test storybook:ci http://localhost:6006 test-storybook",
44
+ "build-storybook": "storybook build -o 'docs'",
45
+ "serve-built-storybook": "npx http-server docs",
46
+ "verify-node-version": "chmod +x ./scripts/verify-node-version.sh && ./scripts/verify-node-version.sh",
47
+ "version": "npm run verify-node-version && npm run build-storybook && git add -u ./docs && git add ./docs/* && npm run compile",
48
+ "compile": "rm -rf lib && tsc -p tsconfig.json && tsc -p tsconfig-cjs.json && npm run copy-styles",
49
+ "check-license": "license-checker --production --onlyAllow 'Apache-2.0;BSD-3-Clause;MIT;0BSD;BSD-2-Clause'"
50
+ },
51
+ "peerDependencies": {
52
+ "@constructor-io/constructorio-client-javascript": "^2.35.2",
53
+ "react": ">=16.12.0",
54
+ "react-dom": ">=16.12.0",
55
+ "tslib": "^2.4.0"
56
+ },
57
+ "devDependencies": {
58
+ "@cspell/eslint-plugin": "^6.18.1",
59
+ "@storybook/addon-a11y": "^7.0.0-beta.40",
60
+ "@storybook/addon-actions": "7.0.0-beta.40",
61
+ "@storybook/addon-essentials": "7.0.0-beta.40",
62
+ "@storybook/addon-interactions": "^7.0.0-beta.40",
63
+ "@storybook/addon-links": "7.0.0-beta.40",
64
+ "@storybook/jest": "^0.0.11-next.0",
65
+ "@storybook/react-webpack5": "7.0.0-beta.40",
66
+ "@storybook/test-runner": "0.10.0-next.8",
67
+ "@storybook/testing-library": "^0.0.14-next.1",
68
+ "@types/react": "^18.0.26",
69
+ "@types/react-dom": "^18.0.9",
70
+ "@typescript-eslint/eslint-plugin": "^5.47.0",
71
+ "@typescript-eslint/parser": "^5.47.0",
72
+ "eslint": "^8.30.0",
73
+ "eslint-config-airbnb": "^19.0.4",
74
+ "eslint-config-airbnb-typescript": "^17.0.0",
75
+ "eslint-config-prettier": "^8.5.0",
76
+ "eslint-plugin-import": "^2.26.0",
77
+ "eslint-plugin-jsx-a11y": "^6.7.1",
78
+ "eslint-plugin-prettier": "^4.2.1",
79
+ "eslint-plugin-react": "^7.31.11",
80
+ "eslint-plugin-react-hooks": "^4.6.0",
81
+ "eslint-plugin-storybook": "^0.6.8",
82
+ "husky": "^8.0.1",
83
+ "license-checker": "^25.0.1",
84
+ "react": "^18.2.0",
85
+ "react-dom": "^18.2.0",
86
+ "start-server-and-test": "^2.0.0",
87
+ "storybook": "7.0.0-beta.40",
88
+ "typescript": "^4.9.4",
89
+ "webpack": "^5.75.0"
90
+ }
91
+ }