myquizbot-react 1.0.0

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.
package/README.md ADDED
@@ -0,0 +1,195 @@
1
+ # @myquizbot/react
2
+
3
+ A React component library for embedding interactive quizzes with API integration and event handling.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install @myquizbot/react
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ ```jsx
14
+ import { Quiz } from '@myquizbot/react';
15
+ import '@myquizbot/react/dist/style.css';
16
+
17
+ function App() {
18
+ return (
19
+ <Quiz
20
+ quizId="procrastinacao"
21
+ apiKey="pk_live"
22
+ mode="steps"
23
+ onStart={(e) => {
24
+ console.log('Quiz started:', e);
25
+ }}
26
+ onAnswer={(e) => {
27
+ console.log('Question answered:', e);
28
+ }}
29
+ onProgress={(e) => {
30
+ console.log('Progress:', e.percentage + '%');
31
+ }}
32
+ onComplete={(e) => {
33
+ console.log('Quiz completed:', e);
34
+ }}
35
+ onError={(e) => {
36
+ console.error('Error:', e.message);
37
+ }}
38
+ />
39
+ );
40
+ }
41
+ ```
42
+
43
+ ## Props
44
+
45
+ ### Required Props
46
+
47
+ | Prop | Type | Description |
48
+ |------|------|-------------|
49
+ | `quizId` | `string` | Unique identifier for the quiz to load |
50
+ | `apiKey` | `string` | API key for authentication |
51
+
52
+ ### Optional Props
53
+
54
+ | Prop | Type | Default | Description |
55
+ |------|------|---------|-------------|
56
+ | `mode` | `'steps' \| 'single' \| 'flow'` | `'steps'` | Render mode for the quiz |
57
+ | `baseUrl` | `string` | `http://localhost:5003` | Base URL for API calls |
58
+ | `className` | `string` | - | Custom CSS class name |
59
+ | `style` | `React.CSSProperties` | - | Custom inline styles |
60
+
61
+ ### Event Handlers
62
+
63
+ | Handler | Type | Description |
64
+ |---------|------|-------------|
65
+ | `onStart` | `(event: QuizStartEvent) => void` | Called when the quiz starts |
66
+ | `onAnswer` | `(event: QuizAnswerEvent) => void` | Called when a question is answered |
67
+ | `onProgress` | `(event: QuizProgressEvent) => void` | Called when progress is made |
68
+ | `onComplete` | `(event: QuizCompleteEvent) => void` | Called when the quiz is completed |
69
+ | `onError` | `(event: QuizErrorEvent) => void` | Called when an error occurs |
70
+
71
+ ## Event Types
72
+
73
+ ### QuizStartEvent
74
+
75
+ ```typescript
76
+ interface QuizStartEvent {
77
+ quizId: string;
78
+ timestamp: number;
79
+ }
80
+ ```
81
+
82
+ ### QuizAnswerEvent
83
+
84
+ ```typescript
85
+ interface QuizAnswerEvent {
86
+ questionId: string;
87
+ answer: any;
88
+ timestamp: number;
89
+ }
90
+ ```
91
+
92
+ ### QuizProgressEvent
93
+
94
+ ```typescript
95
+ interface QuizProgressEvent {
96
+ currentStep: number;
97
+ totalSteps: number;
98
+ percentage: number;
99
+ }
100
+ ```
101
+
102
+ ### QuizCompleteEvent
103
+
104
+ ```typescript
105
+ interface QuizCompleteEvent {
106
+ quizId: string;
107
+ answers: Record<string, any>;
108
+ timestamp: number;
109
+ sessionId?: string;
110
+ }
111
+ ```
112
+
113
+ ### QuizErrorEvent
114
+
115
+ ```typescript
116
+ interface QuizErrorEvent {
117
+ error: Error;
118
+ message: string;
119
+ timestamp: number;
120
+ }
121
+ ```
122
+
123
+ ## Modes
124
+
125
+ ### Steps Mode (default)
126
+
127
+ Displays questions one at a time with a progress bar and navigation.
128
+
129
+ ```jsx
130
+ <Quiz quizId="my-quiz" apiKey="pk_live" mode="steps" />
131
+ ```
132
+
133
+ ### Single Mode
134
+
135
+ *(Coming soon)* Displays all questions on a single page.
136
+
137
+ ### Flow Mode
138
+
139
+ *(Coming soon)* Displays questions in a visual flow diagram.
140
+
141
+ ## Customization
142
+
143
+ You can customize the appearance using CSS:
144
+
145
+ ```css
146
+ /* Override default styles */
147
+ .quiz-container {
148
+ max-width: 1000px;
149
+ }
150
+
151
+ .quiz-steps-option {
152
+ background: #your-color;
153
+ }
154
+ ```
155
+
156
+ Or pass custom styles via props:
157
+
158
+ ```jsx
159
+ <Quiz
160
+ quizId="my-quiz"
161
+ apiKey="pk_live"
162
+ className="my-custom-quiz"
163
+ style={{ maxWidth: '600px' }}
164
+ />
165
+ ```
166
+
167
+ ## API Configuration
168
+
169
+ By default, the component uses `http://localhost:5003` as the base URL. You can override this:
170
+
171
+ ```jsx
172
+ <Quiz
173
+ quizId="my-quiz"
174
+ apiKey="pk_live"
175
+ baseUrl="https://api.myquizbot.com"
176
+ />
177
+ ```
178
+
179
+ Or set it via environment variable:
180
+
181
+ ```bash
182
+ VITE_API_BASE_URL=https://api.myquizbot.com
183
+ ```
184
+
185
+ ## TypeScript Support
186
+
187
+ The library is written in TypeScript and includes full type definitions. Import types as needed:
188
+
189
+ ```typescript
190
+ import { Quiz, QuizProps, QuizCompleteEvent } from '@myquizbot/react';
191
+ ```
192
+
193
+ ## License
194
+
195
+ MIT
@@ -0,0 +1 @@
1
+ export {}