@pie-element/ebsr 9.0.2-next.13 → 9.0.2-next.15

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 (54) hide show
  1. package/configure/node_modules/@pie-element/multiple-choice/CHANGELOG.json +1972 -0
  2. package/configure/node_modules/@pie-element/multiple-choice/CHANGELOG.md +2478 -0
  3. package/configure/node_modules/@pie-element/multiple-choice/LICENSE.md +5 -0
  4. package/configure/node_modules/@pie-element/multiple-choice/PRINT.md +35 -0
  5. package/configure/node_modules/@pie-element/multiple-choice/README.md +56 -0
  6. package/configure/node_modules/@pie-element/multiple-choice/choice.png +0 -0
  7. package/configure/node_modules/@pie-element/multiple-choice/configure/CHANGELOG.json +1387 -0
  8. package/configure/node_modules/@pie-element/multiple-choice/configure/CHANGELOG.md +1949 -0
  9. package/configure/node_modules/@pie-element/multiple-choice/configure/lib/defaults.js +133 -0
  10. package/configure/node_modules/@pie-element/multiple-choice/configure/lib/defaults.js.map +1 -0
  11. package/configure/node_modules/@pie-element/multiple-choice/configure/lib/index.js +248 -0
  12. package/configure/node_modules/@pie-element/multiple-choice/configure/lib/index.js.map +1 -0
  13. package/configure/node_modules/@pie-element/multiple-choice/configure/lib/main.js +610 -0
  14. package/configure/node_modules/@pie-element/multiple-choice/configure/lib/main.js.map +1 -0
  15. package/configure/node_modules/@pie-element/multiple-choice/configure/lib/utils.js +18 -0
  16. package/configure/node_modules/@pie-element/multiple-choice/configure/lib/utils.js.map +1 -0
  17. package/configure/node_modules/@pie-element/multiple-choice/configure/package.json +18 -0
  18. package/configure/node_modules/@pie-element/multiple-choice/controller/CHANGELOG.json +527 -0
  19. package/configure/node_modules/@pie-element/multiple-choice/controller/CHANGELOG.md +869 -0
  20. package/configure/node_modules/@pie-element/multiple-choice/controller/lib/defaults.js +18 -0
  21. package/configure/node_modules/@pie-element/multiple-choice/controller/lib/defaults.js.map +1 -0
  22. package/configure/node_modules/@pie-element/multiple-choice/controller/lib/index.js +306 -0
  23. package/configure/node_modules/@pie-element/multiple-choice/controller/lib/index.js.map +1 -0
  24. package/configure/node_modules/@pie-element/multiple-choice/controller/lib/utils.js +36 -0
  25. package/configure/node_modules/@pie-element/multiple-choice/controller/lib/utils.js.map +1 -0
  26. package/configure/node_modules/@pie-element/multiple-choice/controller/package.json +15 -0
  27. package/configure/node_modules/@pie-element/multiple-choice/docs/config-schema.json +614 -0
  28. package/configure/node_modules/@pie-element/multiple-choice/docs/config-schema.json.md +469 -0
  29. package/configure/node_modules/@pie-element/multiple-choice/docs/demo/config.js +8 -0
  30. package/configure/node_modules/@pie-element/multiple-choice/docs/demo/generate.js +53 -0
  31. package/configure/node_modules/@pie-element/multiple-choice/docs/demo/index.html +1 -0
  32. package/configure/node_modules/@pie-element/multiple-choice/docs/demo/session.js +7 -0
  33. package/configure/node_modules/@pie-element/multiple-choice/docs/pie-schema.json +411 -0
  34. package/configure/node_modules/@pie-element/multiple-choice/docs/pie-schema.json.md +327 -0
  35. package/configure/node_modules/@pie-element/multiple-choice/lib/choice-input.js +332 -0
  36. package/configure/node_modules/@pie-element/multiple-choice/lib/choice-input.js.map +1 -0
  37. package/configure/node_modules/@pie-element/multiple-choice/lib/choice.js +165 -0
  38. package/configure/node_modules/@pie-element/multiple-choice/lib/choice.js.map +1 -0
  39. package/configure/node_modules/@pie-element/multiple-choice/lib/feedback-tick.js +174 -0
  40. package/configure/node_modules/@pie-element/multiple-choice/lib/feedback-tick.js.map +1 -0
  41. package/configure/node_modules/@pie-element/multiple-choice/lib/index.js +156 -0
  42. package/configure/node_modules/@pie-element/multiple-choice/lib/index.js.map +1 -0
  43. package/configure/node_modules/@pie-element/multiple-choice/lib/main.js +96 -0
  44. package/configure/node_modules/@pie-element/multiple-choice/lib/main.js.map +1 -0
  45. package/configure/node_modules/@pie-element/multiple-choice/lib/multiple-choice.js +359 -0
  46. package/configure/node_modules/@pie-element/multiple-choice/lib/multiple-choice.js.map +1 -0
  47. package/configure/node_modules/@pie-element/multiple-choice/lib/print.js +129 -0
  48. package/configure/node_modules/@pie-element/multiple-choice/lib/print.js.map +1 -0
  49. package/configure/node_modules/@pie-element/multiple-choice/lib/session-updater.js +35 -0
  50. package/configure/node_modules/@pie-element/multiple-choice/lib/session-updater.js.map +1 -0
  51. package/configure/node_modules/@pie-element/multiple-choice/package.json +31 -0
  52. package/configure/package.json +2 -2
  53. package/controller/package.json +1 -1
  54. package/package.json +3 -3
@@ -0,0 +1,327 @@
1
+ Model for the Choice Interaction
2
+
3
+ The schema defines the following properties:
4
+
5
+ # `choiceMode` (string, enum)
6
+
7
+ Indicates the choices are single or multiple selection
8
+
9
+ This element must be one of the following enum values:
10
+
11
+ * `checkbox`
12
+ * `radio`
13
+
14
+ # `choicePrefix` (string, enum)
15
+
16
+ What key should be displayed before choices. If undefined no key will be displayed.
17
+
18
+ This element must be one of the following enum values:
19
+
20
+ * `letters`
21
+ * `numbers`
22
+
23
+ Default: `": 'letters'"`
24
+
25
+ # `choices` (array, required)
26
+
27
+ The choice options for the question
28
+
29
+ The object is an array with all elements of the type `object`.
30
+
31
+ The array object has the following properties:
32
+
33
+ ## `correct` (boolean)
34
+
35
+ Indicates if the choice is correct
36
+
37
+ ## `value` (string, required)
38
+
39
+ the value that will be stored if this choice is selected
40
+
41
+ ## `label` (string, required)
42
+
43
+ the text label that will be presented to the user for this choice
44
+
45
+ ## `feedback` (object)
46
+
47
+ The type of feedback to use:
48
+ `default` = a standard feedback message
49
+ `custom` = a customized feedback message
50
+
51
+ Properties of the `feedback` object:
52
+
53
+ ### `type` (string, enum, required)
54
+
55
+ This element must be one of the following enum values:
56
+
57
+ * `custom`
58
+ * `default`
59
+ * `none`
60
+
61
+ Default: `"default"`
62
+
63
+ ### `value` (string)
64
+
65
+ Value for feedback
66
+
67
+ ### `custom` (string)
68
+
69
+ Custom value for feedback
70
+
71
+ ## `rationale` (string)
72
+
73
+ Rationale for the Choice
74
+
75
+ # `prompt` (string)
76
+
77
+ The question prompt or item stem
78
+
79
+ # `promptEnabled` (boolean)
80
+
81
+ Determines if prompt should show
82
+
83
+ # `choicesLayout` (string, enum)
84
+
85
+ Indicates the layout of choices for player
86
+
87
+ This element must be one of the following enum values:
88
+
89
+ * `grid`
90
+ * `horizontal`
91
+ * `vertical`
92
+
93
+ Default: `": 'vertical'"`
94
+
95
+ # `gridColumns` (number)
96
+
97
+ Indicates the number of columns for the grid layout
98
+
99
+ Default: `": 2"`
100
+
101
+ # `toolbarEditorPosition` (string, enum)
102
+
103
+ Indicates the editor's toolbar position which can be 'bottom' or 'top'
104
+
105
+ This element must be one of the following enum values:
106
+
107
+ * `bottom`
108
+ * `top`
109
+
110
+ Default: `": 'bottom'"`
111
+
112
+ # `lockChoiceOrder` (boolean)
113
+
114
+ Indicates the order of choices should be randomly ordered when presented to user
115
+
116
+ # `partialScoring` (boolean)
117
+
118
+ Indicates that the item should use partial scoring
119
+
120
+ # `scoringType` (string, enum)
121
+
122
+ Indicates scoring type
123
+
124
+ This element must be one of the following enum values:
125
+
126
+ * `auto`
127
+ * `rubric`
128
+
129
+ # `studentInstructions` (string)
130
+
131
+ Indicates student instructions
132
+
133
+ # `teacherInstructions` (string)
134
+
135
+ Indicates teacher instructions
136
+
137
+ # `feedbackEnabled` (boolean, required)
138
+
139
+ Indicates if feedback is enabled
140
+
141
+ # `rationaleEnabled` (boolean, required)
142
+
143
+ Indicates if Rationale are enabled
144
+
145
+ # `spellCheckEnabled` (boolean, required)
146
+
147
+ Indicates if spellcheck is enabled for the author. Default value is true
148
+
149
+ # `studentInstructionsEnabled` (boolean, required)
150
+
151
+ Indicates if Student Instructions are enabled
152
+
153
+ # `teacherInstructionsEnabled` (boolean, required)
154
+
155
+ Indicates if Teacher Instructions are enabled
156
+
157
+ # `accessibilityLabelsEnabled` (boolean, required)
158
+
159
+ Indicates if Accessibility Labels are enabled
160
+
161
+ # `rubricEnabled` (boolean, required)
162
+
163
+ Indicates if Rubric is enabled
164
+
165
+ # `language` (string)
166
+
167
+ Indicates the language of the component
168
+ Supported options: en, es, en_US, en-US, es_ES, es-ES, es_MX, es-MX
169
+
170
+ # `id` (string, required)
171
+
172
+ Identifier to identify the Pie Element in html markup, Must be unique within a pie item config.
173
+
174
+ # `element` (string, required)
175
+
176
+ The html Element tag name
177
+
178
+ ---
179
+
180
+ # Sub Schemas
181
+
182
+ The schema defines the following additional types:
183
+
184
+ ## `ConfigureProp` (object)
185
+
186
+ Properties of the `ConfigureProp` object:
187
+
188
+ ### `settings` (boolean)
189
+
190
+ Indicates if the item has to be displayed in the Settings Panel
191
+
192
+ ### `label` (string)
193
+
194
+ Indicates the label for the item that has to be displayed in the Settings Panel
195
+
196
+ ## `ConfigurePropWithEnabled` (object)
197
+
198
+ Properties of the `ConfigurePropWithEnabled` object:
199
+
200
+ ### `settings` (boolean)
201
+
202
+ Indicates if the item has to be displayed in the Settings Panel
203
+
204
+ ### `label` (string)
205
+
206
+ Indicates the label for the item that has to be displayed in the Settings Panel
207
+
208
+ ### `enabled` (boolean)
209
+
210
+ Indicates the value of the item if it affects config-ui
211
+ (eg.: if item is a switch and displaying an input on the config-ui depends on the switch value: on/off)
212
+
213
+ ## `ConfigureMaxImageDimensionsProp` (object)
214
+
215
+ Properties of the `ConfigureMaxImageDimensionsProp` object:
216
+
217
+ ### `teacherInstructions` (number)
218
+
219
+ Indicates the max dimension for images in teacher instructions
220
+
221
+ ### `prompt` (number)
222
+
223
+ Indicates the max dimension for images in prompt - this is also the default dimension for all other input fields if it's not specified
224
+
225
+ ### `rationale` (number)
226
+
227
+ Indicates the max dimension for images in rationale
228
+
229
+ ### `choices` (number)
230
+
231
+ Indicates the max dimension for images in choices
232
+
233
+ ## `ConfigureMathMLProp` (object)
234
+
235
+ Properties of the `ConfigureMathMLProp` object:
236
+
237
+ ### `mmlOutput` (number)
238
+
239
+ Indicates if model should have mathML output instead of latex
240
+
241
+ ### `mmlEditing` (number)
242
+
243
+ Indicates if mathML that's already in model should be editable
244
+
245
+ ## `ConfigureLanguageOptionsProp` (object)
246
+
247
+ Properties of the `ConfigureLanguageOptionsProp` object:
248
+
249
+ ### `value` (string, required)
250
+
251
+ Value of the language option
252
+
253
+ ### `label` (string, required)
254
+
255
+ Label of the language option
256
+
257
+ ## `Choice` (object)
258
+
259
+ Properties of the `Choice` object:
260
+
261
+ ### `correct` (boolean)
262
+
263
+ Indicates if the choice is correct
264
+
265
+ ### `value` (string, required)
266
+
267
+ the value that will be stored if this choice is selected
268
+
269
+ ### `label` (string, required)
270
+
271
+ the text label that will be presented to the user for this choice
272
+
273
+ ### `feedback` (object)
274
+
275
+ The type of feedback to use:
276
+ `default` = a standard feedback message
277
+ `custom` = a customized feedback message
278
+
279
+ Properties of the `feedback` object:
280
+
281
+ #### `type` (string, enum, required)
282
+
283
+ This element must be one of the following enum values:
284
+
285
+ * `custom`
286
+ * `default`
287
+ * `none`
288
+
289
+ Default: `"default"`
290
+
291
+ #### `value` (string)
292
+
293
+ Value for feedback
294
+
295
+ #### `custom` (string)
296
+
297
+ Custom value for feedback
298
+
299
+ ### `rationale` (string)
300
+
301
+ Rationale for the Choice
302
+
303
+ ## `Feedback` (object)
304
+
305
+ The type of feedback to use:
306
+ `default` = a standard feedback message
307
+ `custom` = a customized feedback message
308
+
309
+ Properties of the `Feedback` object:
310
+
311
+ ### `type` (string, enum, required)
312
+
313
+ This element must be one of the following enum values:
314
+
315
+ * `custom`
316
+ * `default`
317
+ * `none`
318
+
319
+ Default: `"default"`
320
+
321
+ ### `value` (string)
322
+
323
+ Value for feedback
324
+
325
+ ### `custom` (string)
326
+
327
+ Custom value for feedback
@@ -0,0 +1,332 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports["default"] = exports.StyledRadio = exports.StyledFormControlLabel = exports.StyledCheckbox = exports.ChoiceInput = void 0;
9
+
10
+ var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
11
+
12
+ var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
13
+
14
+ var _assertThisInitialized2 = _interopRequireDefault(require("@babel/runtime/helpers/assertThisInitialized"));
15
+
16
+ var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
17
+
18
+ var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));
19
+
20
+ var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
21
+
22
+ var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
23
+
24
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
25
+
26
+ var _FormControlLabel = _interopRequireDefault(require("@material-ui/core/FormControlLabel"));
27
+
28
+ var _react = _interopRequireDefault(require("react"));
29
+
30
+ var _propTypes = _interopRequireDefault(require("prop-types"));
31
+
32
+ var _styles = require("@material-ui/core/styles");
33
+
34
+ var _Checkbox = _interopRequireDefault(require("@material-ui/core/Checkbox"));
35
+
36
+ var _renderUi = require("@pie-lib/pie-toolbox/render-ui");
37
+
38
+ var _feedbackTick = _interopRequireDefault(require("./feedback-tick"));
39
+
40
+ var _Radio = _interopRequireDefault(require("@material-ui/core/Radio"));
41
+
42
+ var _classnames = _interopRequireDefault(require("classnames"));
43
+
44
+ function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = (0, _getPrototypeOf2["default"])(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = (0, _getPrototypeOf2["default"])(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return (0, _possibleConstructorReturn2["default"])(this, result); }; }
45
+
46
+ function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
47
+
48
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
49
+
50
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2["default"])(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
51
+
52
+ var CLASS_NAME = 'multiple-choice-component';
53
+
54
+ var styleSheet = function styleSheet(theme) {
55
+ return {
56
+ row: {
57
+ display: 'flex',
58
+ alignItems: 'center',
59
+ backgroundColor: _renderUi.color.background()
60
+ },
61
+ checkboxHolder: {
62
+ display: 'flex',
63
+ alignItems: 'center',
64
+ backgroundColor: _renderUi.color.background(),
65
+ flex: 1,
66
+ '& label': {
67
+ color: _renderUi.color.text(),
68
+ '& > span': {
69
+ fontSize: 'inherit'
70
+ }
71
+ }
72
+ },
73
+ horizontalLayout: (0, _defineProperty2["default"])({}, "& .".concat(CLASS_NAME), {
74
+ paddingRight: theme.spacing.unit
75
+ })
76
+ };
77
+ };
78
+
79
+ var formStyleSheet = {
80
+ label: {
81
+ color: "".concat(_renderUi.color.text(), " !important"),
82
+ //'var(--choice-input-color, black)'
83
+ backgroundColor: _renderUi.color.background()
84
+ }
85
+ };
86
+ var StyledFormControlLabel = (0, _styles.withStyles)(formStyleSheet, {
87
+ name: 'FormControlLabel'
88
+ })(function (props) {
89
+ return /*#__PURE__*/_react["default"].createElement(_FormControlLabel["default"], (0, _extends2["default"])({}, props, {
90
+ classes: {
91
+ label: props.classes.label
92
+ }
93
+ }));
94
+ });
95
+ exports.StyledFormControlLabel = StyledFormControlLabel;
96
+
97
+ var colorStyle = function colorStyle(varName, fallback) {
98
+ return (0, _defineProperty2["default"])({}, "&.".concat(CLASS_NAME), {
99
+ color: "var(--choice-input-".concat(varName, ", ").concat(fallback, ") !important")
100
+ });
101
+ };
102
+
103
+ var inputStyles = {
104
+ 'correct-root': colorStyle('correct-color', _renderUi.color.text()),
105
+ 'correct-checked': colorStyle('correct-selected-color', _renderUi.color.correct()),
106
+ //green[500]),
107
+ 'correct-disabled': colorStyle('correct-disabled-color', _renderUi.color.disabled()),
108
+ //'grey'),
109
+ 'incorrect-root': colorStyle('incorrect-color', _renderUi.color.incorrect()),
110
+ 'incorrect-checked': colorStyle('incorrect-checked', _renderUi.color.incorrect()),
111
+ //orange[500]),
112
+ 'incorrect-disabled': colorStyle('incorrect-disabled-color', _renderUi.color.disabled()),
113
+ root: _objectSpread(_objectSpread({}, colorStyle('color', _renderUi.color.text())), {}, {
114
+ '&:hover': {
115
+ color: "".concat(_renderUi.color.primaryLight(), " !important")
116
+ }
117
+ }),
118
+ checked: colorStyle('selected-color', _renderUi.color.primary()),
119
+ disabled: _objectSpread(_objectSpread({}, colorStyle('disabled-color', _renderUi.color.text())), {}, {
120
+ opacity: 0.6,
121
+ cursor: 'not-allowed !important',
122
+ pointerEvents: 'initial !important'
123
+ })
124
+ };
125
+ var StyledCheckbox = (0, _styles.withStyles)(inputStyles)(function (props) {
126
+ var correctness = props.correctness,
127
+ classes = props.classes,
128
+ checked = props.checked,
129
+ onChange = props.onChange,
130
+ disabled = props.disabled,
131
+ accessibility = props.accessibility,
132
+ value = props.value,
133
+ id = props.id;
134
+
135
+ var key = function key(k) {
136
+ return correctness ? "".concat(correctness, "-").concat(k) : k;
137
+ };
138
+
139
+ var resolved = {
140
+ root: classes[key('root')],
141
+ checked: classes[key('checked')],
142
+ disabled: classes[key('disabled')]
143
+ };
144
+ var miniProps = {
145
+ checked: checked,
146
+ onChange: onChange,
147
+ disabled: disabled,
148
+ value: value
149
+ };
150
+ return /*#__PURE__*/_react["default"].createElement(_Checkbox["default"], (0, _extends2["default"])({
151
+ id: id,
152
+ "aria-label": accessibility,
153
+ "aria-checked": checked
154
+ }, miniProps, {
155
+ className: CLASS_NAME,
156
+ classes: {
157
+ root: resolved.root,
158
+ checked: resolved.checked,
159
+ disabled: "".concat(correctness ? '' : resolved.disabled)
160
+ }
161
+ }));
162
+ });
163
+ exports.StyledCheckbox = StyledCheckbox;
164
+ var StyledRadio = (0, _styles.withStyles)(inputStyles)(function (props) {
165
+ var correctness = props.correctness,
166
+ classes = props.classes,
167
+ checked = props.checked,
168
+ onChange = props.onChange,
169
+ disabled = props.disabled,
170
+ accessibility = props.accessibility,
171
+ value = props.value,
172
+ id = props.id;
173
+
174
+ var key = function key(k) {
175
+ return correctness ? "".concat(correctness, "-").concat(k) : k;
176
+ };
177
+
178
+ var resolved = {
179
+ root: classes[key('root')],
180
+ checked: classes[key('checked')],
181
+ disabled: classes[key('disabled')]
182
+ };
183
+ var miniProps = {
184
+ checked: checked,
185
+ onChange: onChange,
186
+ disabled: disabled,
187
+ value: value
188
+ };
189
+ return /*#__PURE__*/_react["default"].createElement(_Radio["default"], (0, _extends2["default"])({
190
+ id: id,
191
+ "aria-label": accessibility,
192
+ "aria-checked": checked
193
+ }, miniProps, {
194
+ className: CLASS_NAME,
195
+ classes: {
196
+ root: resolved.root,
197
+ checked: resolved.checked,
198
+ disabled: "".concat(correctness ? '' : resolved.disabled)
199
+ }
200
+ }));
201
+ });
202
+ exports.StyledRadio = StyledRadio;
203
+
204
+ var ChoiceInput = /*#__PURE__*/function (_React$Component) {
205
+ (0, _inherits2["default"])(ChoiceInput, _React$Component);
206
+
207
+ var _super = _createSuper(ChoiceInput);
208
+
209
+ function ChoiceInput(props) {
210
+ var _this;
211
+
212
+ (0, _classCallCheck2["default"])(this, ChoiceInput);
213
+ _this = _super.call(this, props);
214
+ _this.onToggleChoice = _this.onToggleChoice.bind((0, _assertThisInitialized2["default"])(_this));
215
+ _this.choiceId = _this.generateChoiceId();
216
+ return _this;
217
+ }
218
+
219
+ (0, _createClass2["default"])(ChoiceInput, [{
220
+ key: "onToggleChoice",
221
+ value: function onToggleChoice(event) {
222
+ this.props.onChange(event);
223
+ this.props.updateSession({
224
+ value: this.props.value,
225
+ selected: !this.props.checked
226
+ });
227
+ }
228
+ }, {
229
+ key: "generateChoiceId",
230
+ value: function generateChoiceId() {
231
+ return 'choice-' + (Math.random() * 10000).toFixed();
232
+ }
233
+ }, {
234
+ key: "render",
235
+ value: function render() {
236
+ var _this$props = this.props,
237
+ choiceMode = _this$props.choiceMode,
238
+ disabled = _this$props.disabled,
239
+ displayKey = _this$props.displayKey,
240
+ feedback = _this$props.feedback,
241
+ label = _this$props.label,
242
+ correctness = _this$props.correctness,
243
+ classes = _this$props.classes,
244
+ className = _this$props.className,
245
+ rationale = _this$props.rationale,
246
+ accessibility = _this$props.accessibility,
247
+ hideTick = _this$props.hideTick,
248
+ isEvaluateMode = _this$props.isEvaluateMode,
249
+ choicesLayout = _this$props.choicesLayout,
250
+ value = _this$props.value,
251
+ checked = _this$props.checked;
252
+ var Tag = choiceMode === 'checkbox' ? StyledCheckbox : StyledRadio;
253
+ var classSuffix = choiceMode === 'checkbox' ? 'checkbox' : 'radio-button';
254
+ var holderClassNames = (0, _classnames["default"])(classes.checkboxHolder, (0, _defineProperty2["default"])({}, classes.horizontalLayout, choicesLayout === 'horizontal'));
255
+
256
+ var choicelabel = /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, displayKey ? /*#__PURE__*/_react["default"].createElement("span", {
257
+ className: classes.row
258
+ }, displayKey, ".", "\xA0", /*#__PURE__*/_react["default"].createElement(_renderUi.PreviewPrompt, {
259
+ className: "label",
260
+ prompt: label,
261
+ tagName: "span"
262
+ })) : /*#__PURE__*/_react["default"].createElement(_renderUi.PreviewPrompt, {
263
+ className: "label",
264
+ prompt: label,
265
+ tagName: "span"
266
+ }));
267
+
268
+ return /*#__PURE__*/_react["default"].createElement("div", {
269
+ className: (0, _classnames["default"])(className, 'corespring-' + classSuffix, 'choice-input')
270
+ }, /*#__PURE__*/_react["default"].createElement("div", {
271
+ className: classes.row
272
+ }, !hideTick && isEvaluateMode && /*#__PURE__*/_react["default"].createElement(_feedbackTick["default"], {
273
+ correctness: correctness
274
+ }), /*#__PURE__*/_react["default"].createElement("div", {
275
+ className: (0, _classnames["default"])(holderClassNames, 'checkbox-holder')
276
+ }, /*#__PURE__*/_react["default"].createElement(StyledFormControlLabel, {
277
+ label: choicelabel,
278
+ value: value,
279
+ htmlFor: this.choiceId,
280
+ control: /*#__PURE__*/_react["default"].createElement(Tag, {
281
+ accessibility: accessibility,
282
+ disabled: disabled,
283
+ checked: checked,
284
+ correctness: correctness,
285
+ value: value,
286
+ id: this.choiceId,
287
+ onChange: this.onToggleChoice
288
+ })
289
+ }))), rationale && /*#__PURE__*/_react["default"].createElement(_renderUi.PreviewPrompt, {
290
+ className: "rationale",
291
+ defaultClassName: "rationale",
292
+ prompt: rationale
293
+ }), /*#__PURE__*/_react["default"].createElement(_renderUi.Feedback, {
294
+ feedback: feedback,
295
+ correctness: correctness
296
+ }));
297
+ }
298
+ }]);
299
+ return ChoiceInput;
300
+ }(_react["default"].Component);
301
+
302
+ exports.ChoiceInput = ChoiceInput;
303
+ (0, _defineProperty2["default"])(ChoiceInput, "propTypes", {
304
+ choiceMode: _propTypes["default"].oneOf(['radio', 'checkbox']),
305
+ displayKey: _propTypes["default"].string.isRequired,
306
+ checked: _propTypes["default"].bool.isRequired,
307
+ correctness: _propTypes["default"].string,
308
+ disabled: _propTypes["default"].bool.isRequired,
309
+ feedback: _propTypes["default"].string,
310
+ label: _propTypes["default"].string.isRequired,
311
+ rationale: _propTypes["default"].string,
312
+ accessibility: _propTypes["default"].string,
313
+ onChange: _propTypes["default"].func.isRequired,
314
+ value: _propTypes["default"].string.isRequired,
315
+ classes: _propTypes["default"].object,
316
+ className: _propTypes["default"].string,
317
+ hideTick: _propTypes["default"].bool,
318
+ isEvaluateMode: _propTypes["default"].bool,
319
+ choicesLayout: _propTypes["default"].oneOf(['vertical', 'grid', 'horizontal']),
320
+ updateSession: _propTypes["default"].func
321
+ });
322
+ (0, _defineProperty2["default"])(ChoiceInput, "defaultProps", {
323
+ rationale: null,
324
+ accessibility: null,
325
+ checked: false,
326
+ isEvaluateMode: false
327
+ });
328
+
329
+ var _default = (0, _styles.withStyles)(styleSheet)(ChoiceInput);
330
+
331
+ exports["default"] = _default;
332
+ //# sourceMappingURL=choice-input.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/choice-input.jsx"],"names":["CLASS_NAME","styleSheet","theme","row","display","alignItems","backgroundColor","color","background","checkboxHolder","flex","text","fontSize","horizontalLayout","paddingRight","spacing","unit","formStyleSheet","label","StyledFormControlLabel","name","props","classes","colorStyle","varName","fallback","inputStyles","correct","disabled","incorrect","root","primaryLight","checked","primary","opacity","cursor","pointerEvents","StyledCheckbox","correctness","onChange","accessibility","value","id","key","k","resolved","miniProps","StyledRadio","ChoiceInput","onToggleChoice","bind","choiceId","generateChoiceId","event","updateSession","selected","Math","random","toFixed","choiceMode","displayKey","feedback","className","rationale","hideTick","isEvaluateMode","choicesLayout","Tag","classSuffix","holderClassNames","choicelabel","React","Component","PropTypes","oneOf","string","isRequired","bool","func","object"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;AACA;;AACA;;AACA;;AAEA;;AACA;;AACA;;AACA;;AACA;;;;;;;;;;AAEA,IAAMA,UAAU,GAAG,2BAAnB;;AAEA,IAAMC,UAAU,GAAG,SAAbA,UAAa,CAACC,KAAD;AAAA,SAAY;AAC7BC,IAAAA,GAAG,EAAE;AACHC,MAAAA,OAAO,EAAE,MADN;AAEHC,MAAAA,UAAU,EAAE,QAFT;AAGHC,MAAAA,eAAe,EAAEC,gBAAMC,UAAN;AAHd,KADwB;AAM7BC,IAAAA,cAAc,EAAE;AACdL,MAAAA,OAAO,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WhE,UAAX,EAAuB+C,WAAvB,C","sourcesContent":["import FormControlLabel from '@material-ui/core/FormControlLabel';\nimport React from 'react';\nimport PropTypes from 'prop-types';\nimport { withStyles } from '@material-ui/core/styles';\n\nimport Checkbox from '@material-ui/core/Checkbox';\nimport { Feedback, color, PreviewPrompt } from '@pie-lib/pie-toolbox/render-ui';\nimport FeedbackTick from './feedback-tick';\nimport Radio from '@material-ui/core/Radio';\nimport classNames from 'classnames';\n\nconst CLASS_NAME = 'multiple-choice-component';\n\nconst styleSheet = (theme) => ({\n row: {\n display: 'flex',\n alignItems: 'center',\n backgroundColor: color.background(),\n },\n checkboxHolder: {\n display: 'flex',\n alignItems: 'center',\n backgroundColor: color.background(),\n flex: 1,\n '& label': {\n color: color.text(),\n '& > span':{\n fontSize: 'inherit',\n }\n },\n },\n horizontalLayout: {\n [`& .${CLASS_NAME}`]: {\n paddingRight: theme.spacing.unit,\n },\n },\n});\n\nconst formStyleSheet = {\n label: {\n color: `${color.text()} !important`, //'var(--choice-input-color, black)'\n backgroundColor: color.background(),\n },\n};\n\nexport const StyledFormControlLabel = withStyles(formStyleSheet, {\n name: 'FormControlLabel',\n})((props) => <FormControlLabel {...props} classes={{ label: props.classes.label }} />);\n\nconst colorStyle = (varName, fallback) => ({\n [`&.${CLASS_NAME}`]: {\n color: `var(--choice-input-${varName}, ${fallback}) !important`,\n },\n});\n\nconst inputStyles = {\n 'correct-root': colorStyle('correct-color', color.text()),\n 'correct-checked': colorStyle('correct-selected-color', color.correct()), //green[500]),\n 'correct-disabled': colorStyle('correct-disabled-color', color.disabled()), //'grey'),\n 'incorrect-root': colorStyle('incorrect-color', color.incorrect()),\n 'incorrect-checked': colorStyle('incorrect-checked', color.incorrect()), //orange[500]),\n 'incorrect-disabled': colorStyle('incorrect-disabled-color', color.disabled()),\n root: {\n ...colorStyle('color', color.text()),\n '&:hover': { color: `${color.primaryLight()} !important` },\n },\n checked: colorStyle('selected-color', color.primary()),\n disabled: {\n ...colorStyle('disabled-color', color.text()),\n opacity: 0.6,\n cursor: 'not-allowed !important',\n pointerEvents: 'initial !important',\n },\n};\n\nexport const StyledCheckbox = withStyles(inputStyles)((props) => {\n const { correctness, classes, checked, onChange, disabled, accessibility, value, id } = props;\n const key = (k) => (correctness ? `${correctness}-${k}` : k);\n\n const resolved = {\n root: classes[key('root')],\n checked: classes[key('checked')],\n disabled: classes[key('disabled')],\n };\n\n const miniProps = { checked, onChange, disabled, value };\n\n return (\n <Checkbox\n id={id}\n aria-label={accessibility}\n aria-checked={checked}\n {...miniProps}\n className={CLASS_NAME}\n classes={{\n root: resolved.root,\n checked: resolved.checked,\n disabled: `${correctness ? '' : resolved.disabled}`,\n }}\n />\n );\n});\n\nexport const StyledRadio = withStyles(inputStyles)((props) => {\n const { correctness, classes, checked, onChange, disabled, accessibility, value, id } = props;\n const key = (k) => (correctness ? `${correctness}-${k}` : k);\n\n const resolved = {\n root: classes[key('root')],\n checked: classes[key('checked')],\n disabled: classes[key('disabled')],\n };\n\n const miniProps = { checked, onChange, disabled, value };\n\n return (\n <Radio\n id={id}\n aria-label={accessibility}\n aria-checked={checked}\n {...miniProps}\n className={CLASS_NAME}\n classes={{\n root: resolved.root,\n checked: resolved.checked,\n disabled: `${correctness ? '' : resolved.disabled}`,\n }}\n />\n );\n});\n\nexport class ChoiceInput extends React.Component {\n static propTypes = {\n choiceMode: PropTypes.oneOf(['radio', 'checkbox']),\n displayKey: PropTypes.string.isRequired,\n checked: PropTypes.bool.isRequired,\n correctness: PropTypes.string,\n disabled: PropTypes.bool.isRequired,\n feedback: PropTypes.string,\n label: PropTypes.string.isRequired,\n rationale: PropTypes.string,\n accessibility: PropTypes.string,\n onChange: PropTypes.func.isRequired,\n value: PropTypes.string.isRequired,\n classes: PropTypes.object,\n className: PropTypes.string,\n hideTick: PropTypes.bool,\n isEvaluateMode: PropTypes.bool,\n choicesLayout: PropTypes.oneOf(['vertical', 'grid', 'horizontal']),\n updateSession: PropTypes.func,\n };\n\n static defaultProps = {\n rationale: null,\n accessibility: null,\n checked: false,\n isEvaluateMode: false,\n };\n\n constructor(props) {\n super(props);\n this.onToggleChoice = this.onToggleChoice.bind(this);\n this.choiceId = this.generateChoiceId();\n }\n\n onToggleChoice(event) {\n this.props.onChange(event);\n this.props.updateSession({\n value: this.props.value,\n selected: !this.props.checked,\n });\n }\n\n generateChoiceId() {\n return 'choice-' + (Math.random() * 10000).toFixed();\n }\n\n render() {\n const {\n choiceMode,\n disabled,\n displayKey,\n feedback,\n label,\n correctness,\n classes,\n className,\n rationale,\n accessibility,\n hideTick,\n isEvaluateMode,\n choicesLayout,\n value,\n checked,\n } = this.props;\n\n const Tag = choiceMode === 'checkbox' ? StyledCheckbox : StyledRadio;\n const classSuffix = choiceMode === 'checkbox' ? 'checkbox' : 'radio-button';\n\n const holderClassNames = classNames(classes.checkboxHolder, {\n [classes.horizontalLayout]: choicesLayout === 'horizontal',\n });\n\n const choicelabel = (\n <>\n {displayKey ? (\n <span className={classes.row}>\n {displayKey}.{'\\u00A0'}\n <PreviewPrompt className=\"label\" prompt={label} tagName=\"span\" />\n </span>\n ) : (\n <PreviewPrompt className=\"label\" prompt={label} tagName=\"span\" />\n )}\n </>\n );\n\n return (\n <div className={classNames(className, 'corespring-' + classSuffix, 'choice-input')}>\n <div className={classes.row}>\n {!hideTick && isEvaluateMode && <FeedbackTick correctness={correctness} />}\n <div className={classNames(holderClassNames, 'checkbox-holder')}>\n <StyledFormControlLabel\n label={choicelabel}\n value={value}\n htmlFor={this.choiceId}\n control={\n <Tag\n accessibility={accessibility}\n disabled={disabled}\n checked={checked}\n correctness={correctness}\n value={value}\n id={this.choiceId}\n onChange={this.onToggleChoice}\n />\n }\n />\n </div>\n </div>\n {rationale && <PreviewPrompt className=\"rationale\" defaultClassName=\"rationale\" prompt={rationale} />}\n <Feedback feedback={feedback} correctness={correctness} />\n </div>\n );\n }\n}\n\nexport default withStyles(styleSheet)(ChoiceInput);\n"],"file":"choice-input.js"}