@micromag/screen-quiz 0.3.361 → 0.3.363
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/assets/css/styles.css +1 -1
- package/es/index.js +73 -61
- package/lib/index.js +72 -60
- package/package.json +14 -14
package/assets/css/styles.css
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
.micromag-screen-quiz-answers-emptyAnswer{border:2px dashed #343434;color:#343434;margin:5px auto}.micromag-screen-quiz-answers-button:focus-visible{outline:3px solid #a13dff;outline-offset:4px}.micromag-screen-quiz-answers-container,.micromag-screen-quiz-answers-items{position:relative}.micromag-screen-quiz-answers-emptyAnswer{font-size:.75em;height:40px;margin:0 auto;width:100%}.micromag-screen-quiz-answers-item{position:relative;-webkit-transition:opacity .15s ease-out;-o-transition:opacity .15s ease-out;transition:opacity .15s ease-out}.micromag-screen-quiz-answers-isPlaceholder .micromag-screen-quiz-answers-item{padding:1px 0}.micromag-screen-quiz-answers-item.micromag-screen-quiz-answers-userAnswer{opacity:1!important}.micromag-screen-quiz-answers-item.micromag-screen-quiz-answers-otherAnswer{opacity:.7!important}.micromag-screen-quiz-answers-button{color:#fff;padding:10px;position:relative;width:100%}.micromag-screen-quiz-answers-button:disabled{opacity:1;pointer-events:none}.micromag-screen-quiz-answers-withIcon .micromag-screen-quiz-answers-button{padding-left:42px;padding-right:42px}.micromag-screen-quiz-answers-resultIcon{-ms-flex-align:center;-ms-flex-pack:center;align-items:center;background-color:#ff2945;border:2px solid #1c1c1c;border-radius:50%;display:-ms-flexbox;display:flex;height:32px;justify-content:center;left:5px;margin-top:-16px;opacity:0;padding:5px;position:absolute;top:50%;-webkit-transition:opacity .15s ease;-o-transition:opacity .15s ease;transition:opacity .15s ease;width:32px}.micromag-screen-quiz-answers-answered .micromag-screen-quiz-answers-resultIcon{opacity:1}.micromag-screen-quiz-answers-rightAnswer .micromag-screen-quiz-answers-resultIcon{background-color:#0ed88f}.micromag-screen-quiz-answers-resultIcon .micromag-screen-quiz-answers-faIcon{display:block}.micromag-screen-quiz-answers-itemContent{padding:5px 0}
|
|
1
|
+
.micromag-screen-quiz-answers-emptyAnswer{border:2px dashed #343434;color:#343434;margin:5px auto}.micromag-screen-quiz-answers-button:focus-visible{outline:3px solid #a13dff;outline-offset:4px}.micromag-screen-quiz-answers-container,.micromag-screen-quiz-answers-items{position:relative}.micromag-screen-quiz-answers-emptyAnswer{font-size:.75em;height:40px;margin:0 auto;width:100%}.micromag-screen-quiz-answers-item{margin:0;padding:0;position:relative;-webkit-transition:opacity .15s ease-out;-o-transition:opacity .15s ease-out;transition:opacity .15s ease-out}.micromag-screen-quiz-answers-isPlaceholder .micromag-screen-quiz-answers-item{padding:1px 0}.micromag-screen-quiz-answers-item.micromag-screen-quiz-answers-userAnswer{opacity:1!important}.micromag-screen-quiz-answers-item.micromag-screen-quiz-answers-otherAnswer{opacity:.7!important}.micromag-screen-quiz-answers-button{color:#fff;padding:10px;position:relative;width:100%}.micromag-screen-quiz-answers-button:disabled{opacity:1;pointer-events:none}.micromag-screen-quiz-answers-withIcon .micromag-screen-quiz-answers-button{padding-left:42px;padding-right:42px}.micromag-screen-quiz-answers-resultIcon{-ms-flex-align:center;-ms-flex-pack:center;align-items:center;background-color:#ff2945;border:2px solid #1c1c1c;border-radius:50%;display:-ms-flexbox;display:flex;height:32px;justify-content:center;left:5px;margin-top:-16px;opacity:0;padding:5px;position:absolute;top:50%;-webkit-transition:opacity .15s ease;-o-transition:opacity .15s ease;transition:opacity .15s ease;width:32px}.micromag-screen-quiz-answers-answered .micromag-screen-quiz-answers-resultIcon{opacity:1}.micromag-screen-quiz-answers-rightAnswer .micromag-screen-quiz-answers-resultIcon{background-color:#0ed88f}.micromag-screen-quiz-answers-resultIcon .micromag-screen-quiz-answers-faIcon{display:block}.micromag-screen-quiz-answers-itemContent{padding:5px 0}
|
|
2
2
|
.micromag-screen-quiz-question-container .micromag-screen-quiz-question-emptyQuestion,.micromag-screen-quiz-question-container .micromag-screen-quiz-question-emptyResult{border:2px dashed #343434;color:#343434;margin:5px auto}.micromag-screen-quiz-question-container .micromag-screen-quiz-question-question{margin-bottom:10px}.micromag-screen-quiz-question-container .micromag-screen-quiz-question-index{display:block;margin-bottom:1em;text-align:center;width:100%}.micromag-screen-quiz-question-container .micromag-screen-quiz-question-result{opacity:0;pointer-events:none;position:absolute;-webkit-transition:opacity .5s ease;-o-transition:opacity .5s ease;transition:opacity .5s ease;-webkit-transition-delay:.3s;-o-transition-delay:.3s;transition-delay:.3s}.micromag-screen-quiz-question-container .micromag-screen-quiz-question-resultContent{padding:20px 0}.micromag-screen-quiz-question-container .micromag-screen-quiz-question-emptyQuestion,.micromag-screen-quiz-question-container .micromag-screen-quiz-question-emptyResult{margin:0 auto;width:100%}.micromag-screen-quiz-question-container .micromag-screen-quiz-question-emptyQuestion{height:60px;margin-bottom:10px}.micromag-screen-quiz-question-container .micromag-screen-quiz-question-emptyResult{height:100px}.micromag-screen-quiz-question-container.micromag-screen-quiz-question-resultVisible .micromag-screen-quiz-question-result{opacity:1;pointer-events:all;position:relative}.micromag-screen-quiz-question-container.micromag-screen-quiz-question-isPlaceholder{padding:10px}.micromag-screen-quiz-question-container.micromag-screen-quiz-question-isPlaceholder .micromag-screen-quiz-question-index{color:hsla(0,0%,100%,.6);font-size:8px;mix-blend-mode:difference}
|
|
3
3
|
.micromag-screen-quiz-container .micromag-screen-quiz-background{height:100%;left:0;position:absolute;top:0;width:100%}.micromag-screen-quiz-container{height:100%;overflow:hidden;position:relative;width:100%}.micromag-screen-quiz-disabled.micromag-screen-quiz-container{overflow:hidden;pointer-events:none}.micromag-screen-quiz-hidden.micromag-screen-quiz-container{display:none;visibility:hidden}.micromag-screen-quiz-placeholder.micromag-screen-quiz-container .micromag-screen-quiz-content{padding:6px;position:relative}.micromag-screen-quiz-container .micromag-screen-quiz-background{z-index:0}.micromag-screen-quiz-container .micromag-screen-quiz-content{z-index:2}.micromag-screen-quiz-container.micromag-screen-quiz-disabled{pointer-events:none}.micromag-screen-quiz-reset{border:0;padding:10px;position:absolute;right:0;top:0;-webkit-transform-origin:center;-ms-transform-origin:center;transform-origin:center;-webkit-transition:opacity .15s ease-out,-webkit-transform .15s ease-out;transition:opacity .15s ease-out,-webkit-transform .15s ease-out;-o-transition:opacity .15s ease-out,transform .15s ease-out;transition:opacity .15s ease-out,transform .15s ease-out;transition:opacity .15s ease-out,transform .15s ease-out,-webkit-transform .15s ease-out;z-index:1000}.micromag-screen-quiz-reset:hover{border:0;opacity:.8}.micromag-screen-quiz-reset:hover:active{-webkit-transform:rotate(30deg);-ms-transform:rotate(30deg);transform:rotate(30deg)}.micromag-screen-quiz-points{color:#fff;left:0;padding:10px;position:absolute;top:0;z-index:1000}.micromag-screen-quiz-layout{bottom:0;left:0;position:absolute;right:0;top:0}.micromag-screen-quiz-header{left:0;position:absolute;top:0;-webkit-transition:opacity .2s ease-out;-o-transition:opacity .2s ease-out;transition:opacity .2s ease-out;width:100%}.micromag-screen-quiz-header.micromag-screen-quiz-disabled{opacity:0;pointer-events:none}.micromag-screen-quiz-footer{bottom:0;left:0;position:absolute;-webkit-transition:opacity .2s ease-out;-o-transition:opacity .2s ease-out;transition:opacity .2s ease-out;width:100%}.micromag-screen-quiz-footer a{padding:0}.micromag-screen-quiz-footer.micromag-screen-quiz-disabled{opacity:0;pointer-events:none}.micromag-screen-quiz-transition{bottom:0;left:0;position:absolute;right:0;top:0}.micromag-screen-quiz-intro,.micromag-screen-quiz-question,.micromag-screen-quiz-results{overflow:hidden}.micromag-screen-quiz-intro.micromag-screen-quiz-enter,.micromag-screen-quiz-question.micromag-screen-quiz-enter,.micromag-screen-quiz-results.micromag-screen-quiz-enter{-webkit-transform:translateX(100%);-ms-transform:translateX(100%);transform:translateX(100%)}.micromag-screen-quiz-left .micromag-screen-quiz-intro.micromag-screen-quiz-enter,.micromag-screen-quiz-left .micromag-screen-quiz-question.micromag-screen-quiz-enter,.micromag-screen-quiz-left .micromag-screen-quiz-results.micromag-screen-quiz-enter{-webkit-transform:translateX(-100%);-ms-transform:translateX(-100%);transform:translateX(-100%)}.micromag-screen-quiz-intro.micromag-screen-quiz-enterActive,.micromag-screen-quiz-left .micromag-screen-quiz-intro.micromag-screen-quiz-enterActive,.micromag-screen-quiz-left .micromag-screen-quiz-question.micromag-screen-quiz-enterActive,.micromag-screen-quiz-left .micromag-screen-quiz-results.micromag-screen-quiz-enterActive,.micromag-screen-quiz-question.micromag-screen-quiz-enterActive,.micromag-screen-quiz-results.micromag-screen-quiz-enterActive{left:0;min-height:100%;position:absolute;top:0;-webkit-transform:translateX(0);-ms-transform:translateX(0);transform:translateX(0);-webkit-transition:-webkit-transform 1s ease;transition:-webkit-transform 1s ease;-o-transition:transform 1s ease;transition:transform 1s ease;transition:transform 1s ease,-webkit-transform 1s ease;width:100%}.micromag-screen-quiz-intro.micromag-screen-quiz-exit,.micromag-screen-quiz-question.micromag-screen-quiz-exit,.micromag-screen-quiz-results.micromag-screen-quiz-exit{-webkit-transform:translateX(0);-ms-transform:translateX(0);transform:translateX(0)}.micromag-screen-quiz-intro.micromag-screen-quiz-exitActive,.micromag-screen-quiz-question.micromag-screen-quiz-exitActive,.micromag-screen-quiz-results.micromag-screen-quiz-exitActive{left:0;min-height:100%;position:absolute;top:0;-webkit-transform:translateX(-100%);-ms-transform:translateX(-100%);transform:translateX(-100%);-webkit-transition:-webkit-transform 1s ease;transition:-webkit-transform 1s ease;-o-transition:transform 1s ease;transition:transform 1s ease;transition:transform 1s ease,-webkit-transform 1s ease;width:100%}.micromag-screen-quiz-left .micromag-screen-quiz-intro.micromag-screen-quiz-exitActive,.micromag-screen-quiz-left .micromag-screen-quiz-question.micromag-screen-quiz-exitActive,.micromag-screen-quiz-left .micromag-screen-quiz-results.micromag-screen-quiz-exitActive{-webkit-transform:translateX(100%);-ms-transform:translateX(100%);transform:translateX(100%)}.micromag-screen-quiz-background.micromag-screen-quiz-enter{opacity:0}.micromag-screen-quiz-background.micromag-screen-quiz-enterActive{opacity:1;-webkit-transition:opacity 1s ease;-o-transition:opacity 1s ease;transition:opacity 1s ease;z-index:1}.micromag-screen-quiz-background.micromag-screen-quiz-exit{opacity:1}.micromag-screen-quiz-background.micromag-screen-quiz-exitActive{opacity:0;-webkit-transition:opacity 1s ease;-o-transition:opacity 1s ease;transition:opacity 1s ease;z-index:0}
|
|
4
4
|
.micromag-screen-quiz-results-container .micromag-screen-quiz-results-emptyDescription,.micromag-screen-quiz-results-container .micromag-screen-quiz-results-emptyTitle{border:2px dashed #343434;color:#343434;margin:5px auto}.micromag-screen-quiz-results-container .micromag-screen-quiz-results-title{margin-bottom:10px}.micromag-screen-quiz-results-container .micromag-screen-quiz-results-emptyDescription,.micromag-screen-quiz-results-container .micromag-screen-quiz-results-emptyTitle{margin:0 auto;width:100%}.micromag-screen-quiz-results-container .micromag-screen-quiz-results-emptyTitle{height:60px}.micromag-screen-quiz-results-container .micromag-screen-quiz-results-emptyDescription{height:100px}.micromag-screen-quiz-results-container.micromag-screen-quiz-results-isPlaceholder{padding:10px}
|
package/es/index.js
CHANGED
|
@@ -24,7 +24,7 @@ import Text from '@micromag/element-text';
|
|
|
24
24
|
import _toConsumableArray from '@babel/runtime/helpers/toConsumableArray';
|
|
25
25
|
import { faCheck } from '@fortawesome/free-solid-svg-icons/faCheck';
|
|
26
26
|
import { faTimes } from '@fortawesome/free-solid-svg-icons/faTimes';
|
|
27
|
-
import {
|
|
27
|
+
import { animated, useTransition } from '@react-spring/web';
|
|
28
28
|
import Button from '@micromag/element-button';
|
|
29
29
|
import { TransitionGroup, CSSTransition } from 'react-transition-group';
|
|
30
30
|
|
|
@@ -42,6 +42,7 @@ var propTypes$5 = {
|
|
|
42
42
|
withoutGoodAnswer: PropTypes$1.bool,
|
|
43
43
|
withoutIcon: PropTypes$1.bool,
|
|
44
44
|
focusable: PropTypes$1.bool,
|
|
45
|
+
animated: PropTypes$1.bool,
|
|
45
46
|
collapsed: PropTypes$1.bool,
|
|
46
47
|
onClick: PropTypes$1.func,
|
|
47
48
|
onCollapse: PropTypes$1.func,
|
|
@@ -60,6 +61,7 @@ var defaultProps$5 = {
|
|
|
60
61
|
withoutGoodAnswer: false,
|
|
61
62
|
withoutIcon: false,
|
|
62
63
|
focusable: false,
|
|
64
|
+
animated: false,
|
|
63
65
|
collapsed: false,
|
|
64
66
|
onClick: null,
|
|
65
67
|
onCollapse: null,
|
|
@@ -68,7 +70,7 @@ var defaultProps$5 = {
|
|
|
68
70
|
className: null
|
|
69
71
|
};
|
|
70
72
|
var Answers = function Answers(_ref) {
|
|
71
|
-
var
|
|
73
|
+
var _ref8;
|
|
72
74
|
var items = _ref.items,
|
|
73
75
|
answeredIndex = _ref.answeredIndex,
|
|
74
76
|
answersCollapseDelay = _ref.answersCollapseDelay,
|
|
@@ -80,6 +82,7 @@ var Answers = function Answers(_ref) {
|
|
|
80
82
|
withoutGoodAnswer = _ref.withoutGoodAnswer,
|
|
81
83
|
withoutIcon = _ref.withoutIcon,
|
|
82
84
|
focusable = _ref.focusable,
|
|
85
|
+
collapseAnimated = _ref.animated,
|
|
83
86
|
initialCollapsed = _ref.collapsed,
|
|
84
87
|
onClick = _ref.onClick,
|
|
85
88
|
onCollapse = _ref.onCollapse,
|
|
@@ -145,24 +148,28 @@ var Answers = function Answers(_ref) {
|
|
|
145
148
|
}, [shouldCollapse, answersCollapsed, answersDidCollapse, setAnswersCollapsed, onCollapsed, onTransitionEnd]);
|
|
146
149
|
var itemsRefs = useRef([]);
|
|
147
150
|
var listOfItems = isPlaceholder || isEdit && items.length === 0 ? _toConsumableArray(new Array(2)) : items;
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
151
|
+
var heights = useMemo(function () {
|
|
152
|
+
if (animated) {
|
|
153
|
+
var allHeights = listOfItems.reduce(function (acc, it, i) {
|
|
154
|
+
if (itemsRefs.current[i] && collapseAnimated) {
|
|
155
|
+
var _ref4 = itemsRefs.current[i].getBoundingClientRect() || {},
|
|
156
|
+
_ref4$height = _ref4.height,
|
|
157
|
+
height = _ref4$height === void 0 ? 0 : _ref4$height;
|
|
158
|
+
acc.push(height);
|
|
159
|
+
}
|
|
160
|
+
return acc;
|
|
161
|
+
}, []);
|
|
162
|
+
return allHeights;
|
|
163
|
+
}
|
|
164
|
+
return [];
|
|
165
|
+
}, [animated, answeredIndex, shouldCollapse, collapseAnimated, listOfItems]);
|
|
159
166
|
var showAnimation = isView || isEdit;
|
|
160
167
|
var filteredListOfItems = listOfItems.map(function (answer, answerI) {
|
|
161
|
-
|
|
168
|
+
var height = heights[answerI] ? heights[answerI] : 0;
|
|
162
169
|
var userAnswer = answerI === answeredIndex;
|
|
163
|
-
var
|
|
164
|
-
|
|
165
|
-
rightAnswer =
|
|
170
|
+
var _ref5 = answer || {},
|
|
171
|
+
_ref5$good = _ref5.good,
|
|
172
|
+
rightAnswer = _ref5$good === void 0 ? false : _ref5$good;
|
|
166
173
|
var hidden = false;
|
|
167
174
|
if (answeredIndex !== null && showAnimation && answersDidCollapse && !rightAnswer && (hasRightAnswer || !userAnswer)) {
|
|
168
175
|
hidden = true;
|
|
@@ -173,71 +180,67 @@ var Answers = function Answers(_ref) {
|
|
|
173
180
|
return _objectSpread(_objectSpread({}, answer), {}, {
|
|
174
181
|
hidden: hidden,
|
|
175
182
|
userAnswer: userAnswer,
|
|
176
|
-
index: answerI
|
|
183
|
+
index: answerI,
|
|
184
|
+
maxHeight: height
|
|
177
185
|
});
|
|
178
186
|
});
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
var transitions = useTransition(filteredListOfItems.map(function (data) {
|
|
187
|
-
return _objectSpread(_objectSpread({}, data), {}, {
|
|
188
|
-
hidden: data.hidden
|
|
189
|
-
});
|
|
190
|
-
}), {
|
|
191
|
-
key: function key(_ref5) {
|
|
192
|
-
var _ref5$index = _ref5.index,
|
|
193
|
-
index = _ref5$index === void 0 ? 0 : _ref5$index,
|
|
194
|
-
_ref5$label = _ref5.label,
|
|
195
|
-
label = _ref5$label === void 0 ? null : _ref5$label;
|
|
187
|
+
var transitions = useTransition(filteredListOfItems, {
|
|
188
|
+
key: function key(_ref6) {
|
|
189
|
+
var _ref6$index = _ref6.index,
|
|
190
|
+
index = _ref6$index === void 0 ? 0 : _ref6$index,
|
|
191
|
+
_ref6$label = _ref6.label,
|
|
192
|
+
label = _ref6$label === void 0 ? null : _ref6$label;
|
|
196
193
|
return "key-".concat(index, "-").concat((label === null || label === void 0 ? void 0 : label.body) || null);
|
|
197
194
|
},
|
|
198
|
-
update: function update(
|
|
199
|
-
var
|
|
200
|
-
hidden =
|
|
195
|
+
update: function update(_ref7) {
|
|
196
|
+
var _ref7$hidden = _ref7.hidden,
|
|
197
|
+
hidden = _ref7$hidden === void 0 ? false : _ref7$hidden,
|
|
198
|
+
_ref7$maxHeight = _ref7.maxHeight,
|
|
199
|
+
maxHeight = _ref7$maxHeight === void 0 ? 0 : _ref7$maxHeight;
|
|
201
200
|
return {
|
|
202
201
|
opacity: hidden && showAnimation && !withoutGoodAnswer ? 0 : 1,
|
|
203
|
-
|
|
202
|
+
// Animate this, not height
|
|
203
|
+
maxHeight:
|
|
204
|
+
// eslint-disable-next-line no-nested-ternary
|
|
205
|
+
hidden && showAnimation && !withoutGoodAnswer && collapseAnimated ? 0 : maxHeight > 0 ? maxHeight : null,
|
|
206
|
+
height: hidden && showAnimation && !withoutGoodAnswer && !collapseAnimated ? 0 : 'auto'
|
|
204
207
|
};
|
|
205
208
|
},
|
|
206
|
-
config: config.gentle
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
209
|
+
// config: config.gentle,
|
|
210
|
+
config: {
|
|
211
|
+
tension: 300,
|
|
212
|
+
friction: 35
|
|
213
|
+
}
|
|
210
214
|
});
|
|
211
|
-
|
|
212
215
|
return /*#__PURE__*/React.createElement("div", {
|
|
213
|
-
className: classNames([styles$4.container, (
|
|
216
|
+
className: classNames([styles$4.container, (_ref8 = {}, _defineProperty(_ref8, styles$4.answered, answered), _defineProperty(_ref8, styles$4.withIcon, !withoutIcon), _defineProperty(_ref8, styles$4.isPlaceholder, isPlaceholder), _defineProperty(_ref8, className, className !== null), _ref8)])
|
|
214
217
|
}, filteredListOfItems !== null || isPlaceholder ? /*#__PURE__*/React.createElement("div", {
|
|
215
218
|
className: styles$4.items
|
|
216
219
|
}, transitions(function (style, answer, t, answerI) {
|
|
217
|
-
var
|
|
220
|
+
var _ref11;
|
|
218
221
|
var userAnswer = answerI === answeredIndex;
|
|
219
|
-
var
|
|
220
|
-
|
|
221
|
-
rightAnswer =
|
|
222
|
-
|
|
223
|
-
label =
|
|
224
|
-
|
|
225
|
-
answerButtonStyle =
|
|
226
|
-
_ref8$textStyle = _ref8.textStyle,
|
|
227
|
-
answerButtonTextStyle = _ref8$textStyle === void 0 ? null : _ref8$textStyle;
|
|
228
|
-
var _ref9 = label || {},
|
|
222
|
+
var _ref9 = answer || {},
|
|
223
|
+
_ref9$good = _ref9.good,
|
|
224
|
+
rightAnswer = _ref9$good === void 0 ? null : _ref9$good,
|
|
225
|
+
_ref9$label = _ref9.label,
|
|
226
|
+
label = _ref9$label === void 0 ? null : _ref9$label,
|
|
227
|
+
_ref9$buttonStyle = _ref9.buttonStyle,
|
|
228
|
+
answerButtonStyle = _ref9$buttonStyle === void 0 ? null : _ref9$buttonStyle,
|
|
229
229
|
_ref9$textStyle = _ref9.textStyle,
|
|
230
|
-
|
|
230
|
+
answerButtonTextStyle = _ref9$textStyle === void 0 ? null : _ref9$textStyle;
|
|
231
|
+
var _ref10 = label || {},
|
|
232
|
+
_ref10$textStyle = _ref10.textStyle,
|
|
233
|
+
textStyle = _ref10$textStyle === void 0 ? null : _ref10$textStyle;
|
|
231
234
|
var hasAnswer = isTextFilled(label);
|
|
232
235
|
return /*#__PURE__*/React.createElement(animated.div, {
|
|
233
236
|
key: "answer-".concat(answerI),
|
|
234
|
-
className: classNames([styles$4.item, (
|
|
235
|
-
style: _objectSpread({}, style)
|
|
237
|
+
className: classNames([styles$4.item, (_ref11 = {}, _defineProperty(_ref11, styles$4.rightAnswer, !withoutGoodAnswer && rightAnswer === true), _defineProperty(_ref11, styles$4.userAnswer, withoutGoodAnswer && userAnswer), _defineProperty(_ref11, styles$4.otherAnswer, withoutGoodAnswer && !userAnswer), _ref11)]),
|
|
238
|
+
style: _objectSpread({}, style)
|
|
239
|
+
}, /*#__PURE__*/React.createElement("div", {
|
|
240
|
+
className: styles$4.itemContent,
|
|
236
241
|
ref: function ref(el) {
|
|
237
242
|
itemsRefs.current[answerI] = el;
|
|
238
243
|
}
|
|
239
|
-
}, /*#__PURE__*/React.createElement("div", {
|
|
240
|
-
className: styles$4.itemContent
|
|
241
244
|
}, /*#__PURE__*/React.createElement(ScreenElement, {
|
|
242
245
|
placeholder: "quizAnswer",
|
|
243
246
|
placeholderProps: {
|
|
@@ -303,6 +306,7 @@ var propTypes$4 = {
|
|
|
303
306
|
goodAnswerColor: PropTypes.color,
|
|
304
307
|
badAnswerColor: PropTypes.color,
|
|
305
308
|
focusable: PropTypes$1.bool,
|
|
309
|
+
animated: PropTypes$1.bool,
|
|
306
310
|
layout: PropTypes$1.string,
|
|
307
311
|
showInstantAnswer: PropTypes$1.bool,
|
|
308
312
|
withResult: PropTypes$1.bool,
|
|
@@ -331,6 +335,7 @@ var defaultProps$4 = {
|
|
|
331
335
|
goodAnswerColor: null,
|
|
332
336
|
badAnswerColor: null,
|
|
333
337
|
focusable: false,
|
|
338
|
+
animated: false,
|
|
334
339
|
layout: null,
|
|
335
340
|
showInstantAnswer: false,
|
|
336
341
|
withResult: false,
|
|
@@ -360,6 +365,7 @@ var Question = function Question(_ref) {
|
|
|
360
365
|
goodAnswerColor = _ref.goodAnswerColor,
|
|
361
366
|
badAnswerColor = _ref.badAnswerColor,
|
|
362
367
|
focusable = _ref.focusable,
|
|
368
|
+
animated = _ref.animated,
|
|
363
369
|
showInstantAnswer = _ref.showInstantAnswer,
|
|
364
370
|
withResult = _ref.withResult,
|
|
365
371
|
withoutGoodAnswer = _ref.withoutGoodAnswer,
|
|
@@ -446,6 +452,7 @@ var Question = function Question(_ref) {
|
|
|
446
452
|
buttonsStyle: buttonsStyle,
|
|
447
453
|
buttonsTextStyle: buttonsTextStyle,
|
|
448
454
|
focusable: focusable,
|
|
455
|
+
animated: animated,
|
|
449
456
|
transitions: transitions,
|
|
450
457
|
transitionStagger: transitionStagger,
|
|
451
458
|
transitionPlaying: transitionPlaying,
|
|
@@ -668,6 +675,10 @@ var QuizScreen = function QuizScreen(_ref) {
|
|
|
668
675
|
var onQuizReset = useCallback(function () {
|
|
669
676
|
setUserAnswerIndex(null);
|
|
670
677
|
}, [setUserAnswerIndex]);
|
|
678
|
+
var numberOfAnswers = (answers || []).length;
|
|
679
|
+
useEffect(function () {
|
|
680
|
+
onQuizReset();
|
|
681
|
+
}, [numberOfAnswers, onQuizReset]);
|
|
671
682
|
var isSplitted = layout === 'split';
|
|
672
683
|
var verticalAlign = isSplitted ? null : layout;
|
|
673
684
|
var showReset = isEdit;
|
|
@@ -713,6 +724,7 @@ var QuizScreen = function QuizScreen(_ref) {
|
|
|
713
724
|
withoutTrueFalse: withoutTrueFalse,
|
|
714
725
|
withoutGoodAnswer: withoutGoodAnswer,
|
|
715
726
|
focusable: current && isView,
|
|
727
|
+
animated: isView,
|
|
716
728
|
showInstantAnswer: showInstantAnswer,
|
|
717
729
|
withResult: true,
|
|
718
730
|
layout: layout,
|
package/lib/index.js
CHANGED
|
@@ -65,6 +65,7 @@ var propTypes$5 = {
|
|
|
65
65
|
withoutGoodAnswer: PropTypes__default["default"].bool,
|
|
66
66
|
withoutIcon: PropTypes__default["default"].bool,
|
|
67
67
|
focusable: PropTypes__default["default"].bool,
|
|
68
|
+
animated: PropTypes__default["default"].bool,
|
|
68
69
|
collapsed: PropTypes__default["default"].bool,
|
|
69
70
|
onClick: PropTypes__default["default"].func,
|
|
70
71
|
onCollapse: PropTypes__default["default"].func,
|
|
@@ -83,6 +84,7 @@ var defaultProps$5 = {
|
|
|
83
84
|
withoutGoodAnswer: false,
|
|
84
85
|
withoutIcon: false,
|
|
85
86
|
focusable: false,
|
|
87
|
+
animated: false,
|
|
86
88
|
collapsed: false,
|
|
87
89
|
onClick: null,
|
|
88
90
|
onCollapse: null,
|
|
@@ -91,7 +93,7 @@ var defaultProps$5 = {
|
|
|
91
93
|
className: null
|
|
92
94
|
};
|
|
93
95
|
var Answers = function Answers(_ref) {
|
|
94
|
-
var
|
|
96
|
+
var _ref8;
|
|
95
97
|
var items = _ref.items,
|
|
96
98
|
answeredIndex = _ref.answeredIndex,
|
|
97
99
|
answersCollapseDelay = _ref.answersCollapseDelay,
|
|
@@ -103,6 +105,7 @@ var Answers = function Answers(_ref) {
|
|
|
103
105
|
withoutGoodAnswer = _ref.withoutGoodAnswer,
|
|
104
106
|
withoutIcon = _ref.withoutIcon,
|
|
105
107
|
focusable = _ref.focusable,
|
|
108
|
+
collapseAnimated = _ref.animated,
|
|
106
109
|
initialCollapsed = _ref.collapsed,
|
|
107
110
|
onClick = _ref.onClick,
|
|
108
111
|
onCollapse = _ref.onCollapse,
|
|
@@ -168,24 +171,28 @@ var Answers = function Answers(_ref) {
|
|
|
168
171
|
}, [shouldCollapse, answersCollapsed, answersDidCollapse, setAnswersCollapsed, onCollapsed, onTransitionEnd]);
|
|
169
172
|
var itemsRefs = React.useRef([]);
|
|
170
173
|
var listOfItems = isPlaceholder || isEdit && items.length === 0 ? _toConsumableArray__default["default"](new Array(2)) : items;
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
174
|
+
var heights = React.useMemo(function () {
|
|
175
|
+
if (web.animated) {
|
|
176
|
+
var allHeights = listOfItems.reduce(function (acc, it, i) {
|
|
177
|
+
if (itemsRefs.current[i] && collapseAnimated) {
|
|
178
|
+
var _ref4 = itemsRefs.current[i].getBoundingClientRect() || {},
|
|
179
|
+
_ref4$height = _ref4.height,
|
|
180
|
+
height = _ref4$height === void 0 ? 0 : _ref4$height;
|
|
181
|
+
acc.push(height);
|
|
182
|
+
}
|
|
183
|
+
return acc;
|
|
184
|
+
}, []);
|
|
185
|
+
return allHeights;
|
|
186
|
+
}
|
|
187
|
+
return [];
|
|
188
|
+
}, [web.animated, answeredIndex, shouldCollapse, collapseAnimated, listOfItems]);
|
|
182
189
|
var showAnimation = isView || isEdit;
|
|
183
190
|
var filteredListOfItems = listOfItems.map(function (answer, answerI) {
|
|
184
|
-
|
|
191
|
+
var height = heights[answerI] ? heights[answerI] : 0;
|
|
185
192
|
var userAnswer = answerI === answeredIndex;
|
|
186
|
-
var
|
|
187
|
-
|
|
188
|
-
rightAnswer =
|
|
193
|
+
var _ref5 = answer || {},
|
|
194
|
+
_ref5$good = _ref5.good,
|
|
195
|
+
rightAnswer = _ref5$good === void 0 ? false : _ref5$good;
|
|
189
196
|
var hidden = false;
|
|
190
197
|
if (answeredIndex !== null && showAnimation && answersDidCollapse && !rightAnswer && (hasRightAnswer || !userAnswer)) {
|
|
191
198
|
hidden = true;
|
|
@@ -196,71 +203,67 @@ var Answers = function Answers(_ref) {
|
|
|
196
203
|
return _objectSpread__default["default"](_objectSpread__default["default"]({}, answer), {}, {
|
|
197
204
|
hidden: hidden,
|
|
198
205
|
userAnswer: userAnswer,
|
|
199
|
-
index: answerI
|
|
206
|
+
index: answerI,
|
|
207
|
+
maxHeight: height
|
|
200
208
|
});
|
|
201
209
|
});
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
var transitions = web.useTransition(filteredListOfItems.map(function (data) {
|
|
210
|
-
return _objectSpread__default["default"](_objectSpread__default["default"]({}, data), {}, {
|
|
211
|
-
hidden: data.hidden
|
|
212
|
-
});
|
|
213
|
-
}), {
|
|
214
|
-
key: function key(_ref5) {
|
|
215
|
-
var _ref5$index = _ref5.index,
|
|
216
|
-
index = _ref5$index === void 0 ? 0 : _ref5$index,
|
|
217
|
-
_ref5$label = _ref5.label,
|
|
218
|
-
label = _ref5$label === void 0 ? null : _ref5$label;
|
|
210
|
+
var transitions = web.useTransition(filteredListOfItems, {
|
|
211
|
+
key: function key(_ref6) {
|
|
212
|
+
var _ref6$index = _ref6.index,
|
|
213
|
+
index = _ref6$index === void 0 ? 0 : _ref6$index,
|
|
214
|
+
_ref6$label = _ref6.label,
|
|
215
|
+
label = _ref6$label === void 0 ? null : _ref6$label;
|
|
219
216
|
return "key-".concat(index, "-").concat((label === null || label === void 0 ? void 0 : label.body) || null);
|
|
220
217
|
},
|
|
221
|
-
update: function update(
|
|
222
|
-
var
|
|
223
|
-
hidden =
|
|
218
|
+
update: function update(_ref7) {
|
|
219
|
+
var _ref7$hidden = _ref7.hidden,
|
|
220
|
+
hidden = _ref7$hidden === void 0 ? false : _ref7$hidden,
|
|
221
|
+
_ref7$maxHeight = _ref7.maxHeight,
|
|
222
|
+
maxHeight = _ref7$maxHeight === void 0 ? 0 : _ref7$maxHeight;
|
|
224
223
|
return {
|
|
225
224
|
opacity: hidden && showAnimation && !withoutGoodAnswer ? 0 : 1,
|
|
226
|
-
|
|
225
|
+
// Animate this, not height
|
|
226
|
+
maxHeight:
|
|
227
|
+
// eslint-disable-next-line no-nested-ternary
|
|
228
|
+
hidden && showAnimation && !withoutGoodAnswer && collapseAnimated ? 0 : maxHeight > 0 ? maxHeight : null,
|
|
229
|
+
height: hidden && showAnimation && !withoutGoodAnswer && !collapseAnimated ? 0 : 'auto'
|
|
227
230
|
};
|
|
228
231
|
},
|
|
229
|
-
config:
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
232
|
+
// config: config.gentle,
|
|
233
|
+
config: {
|
|
234
|
+
tension: 300,
|
|
235
|
+
friction: 35
|
|
236
|
+
}
|
|
233
237
|
});
|
|
234
|
-
|
|
235
238
|
return /*#__PURE__*/React__default["default"].createElement("div", {
|
|
236
|
-
className: classNames__default["default"]([styles$4.container, (
|
|
239
|
+
className: classNames__default["default"]([styles$4.container, (_ref8 = {}, _defineProperty__default["default"](_ref8, styles$4.answered, answered), _defineProperty__default["default"](_ref8, styles$4.withIcon, !withoutIcon), _defineProperty__default["default"](_ref8, styles$4.isPlaceholder, isPlaceholder), _defineProperty__default["default"](_ref8, className, className !== null), _ref8)])
|
|
237
240
|
}, filteredListOfItems !== null || isPlaceholder ? /*#__PURE__*/React__default["default"].createElement("div", {
|
|
238
241
|
className: styles$4.items
|
|
239
242
|
}, transitions(function (style, answer, t, answerI) {
|
|
240
|
-
var
|
|
243
|
+
var _ref11;
|
|
241
244
|
var userAnswer = answerI === answeredIndex;
|
|
242
|
-
var
|
|
243
|
-
|
|
244
|
-
rightAnswer =
|
|
245
|
-
|
|
246
|
-
label =
|
|
247
|
-
|
|
248
|
-
answerButtonStyle =
|
|
249
|
-
_ref8$textStyle = _ref8.textStyle,
|
|
250
|
-
answerButtonTextStyle = _ref8$textStyle === void 0 ? null : _ref8$textStyle;
|
|
251
|
-
var _ref9 = label || {},
|
|
245
|
+
var _ref9 = answer || {},
|
|
246
|
+
_ref9$good = _ref9.good,
|
|
247
|
+
rightAnswer = _ref9$good === void 0 ? null : _ref9$good,
|
|
248
|
+
_ref9$label = _ref9.label,
|
|
249
|
+
label = _ref9$label === void 0 ? null : _ref9$label,
|
|
250
|
+
_ref9$buttonStyle = _ref9.buttonStyle,
|
|
251
|
+
answerButtonStyle = _ref9$buttonStyle === void 0 ? null : _ref9$buttonStyle,
|
|
252
252
|
_ref9$textStyle = _ref9.textStyle,
|
|
253
|
-
|
|
253
|
+
answerButtonTextStyle = _ref9$textStyle === void 0 ? null : _ref9$textStyle;
|
|
254
|
+
var _ref10 = label || {},
|
|
255
|
+
_ref10$textStyle = _ref10.textStyle,
|
|
256
|
+
textStyle = _ref10$textStyle === void 0 ? null : _ref10$textStyle;
|
|
254
257
|
var hasAnswer = utils.isTextFilled(label);
|
|
255
258
|
return /*#__PURE__*/React__default["default"].createElement(web.animated.div, {
|
|
256
259
|
key: "answer-".concat(answerI),
|
|
257
|
-
className: classNames__default["default"]([styles$4.item, (
|
|
258
|
-
style: _objectSpread__default["default"]({}, style)
|
|
260
|
+
className: classNames__default["default"]([styles$4.item, (_ref11 = {}, _defineProperty__default["default"](_ref11, styles$4.rightAnswer, !withoutGoodAnswer && rightAnswer === true), _defineProperty__default["default"](_ref11, styles$4.userAnswer, withoutGoodAnswer && userAnswer), _defineProperty__default["default"](_ref11, styles$4.otherAnswer, withoutGoodAnswer && !userAnswer), _ref11)]),
|
|
261
|
+
style: _objectSpread__default["default"]({}, style)
|
|
262
|
+
}, /*#__PURE__*/React__default["default"].createElement("div", {
|
|
263
|
+
className: styles$4.itemContent,
|
|
259
264
|
ref: function ref(el) {
|
|
260
265
|
itemsRefs.current[answerI] = el;
|
|
261
266
|
}
|
|
262
|
-
}, /*#__PURE__*/React__default["default"].createElement("div", {
|
|
263
|
-
className: styles$4.itemContent
|
|
264
267
|
}, /*#__PURE__*/React__default["default"].createElement(components.ScreenElement, {
|
|
265
268
|
placeholder: "quizAnswer",
|
|
266
269
|
placeholderProps: {
|
|
@@ -326,6 +329,7 @@ var propTypes$4 = {
|
|
|
326
329
|
goodAnswerColor: core.PropTypes.color,
|
|
327
330
|
badAnswerColor: core.PropTypes.color,
|
|
328
331
|
focusable: PropTypes__default["default"].bool,
|
|
332
|
+
animated: PropTypes__default["default"].bool,
|
|
329
333
|
layout: PropTypes__default["default"].string,
|
|
330
334
|
showInstantAnswer: PropTypes__default["default"].bool,
|
|
331
335
|
withResult: PropTypes__default["default"].bool,
|
|
@@ -354,6 +358,7 @@ var defaultProps$4 = {
|
|
|
354
358
|
goodAnswerColor: null,
|
|
355
359
|
badAnswerColor: null,
|
|
356
360
|
focusable: false,
|
|
361
|
+
animated: false,
|
|
357
362
|
layout: null,
|
|
358
363
|
showInstantAnswer: false,
|
|
359
364
|
withResult: false,
|
|
@@ -383,6 +388,7 @@ var Question = function Question(_ref) {
|
|
|
383
388
|
goodAnswerColor = _ref.goodAnswerColor,
|
|
384
389
|
badAnswerColor = _ref.badAnswerColor,
|
|
385
390
|
focusable = _ref.focusable,
|
|
391
|
+
animated = _ref.animated,
|
|
386
392
|
showInstantAnswer = _ref.showInstantAnswer,
|
|
387
393
|
withResult = _ref.withResult,
|
|
388
394
|
withoutGoodAnswer = _ref.withoutGoodAnswer,
|
|
@@ -469,6 +475,7 @@ var Question = function Question(_ref) {
|
|
|
469
475
|
buttonsStyle: buttonsStyle,
|
|
470
476
|
buttonsTextStyle: buttonsTextStyle,
|
|
471
477
|
focusable: focusable,
|
|
478
|
+
animated: animated,
|
|
472
479
|
transitions: transitions,
|
|
473
480
|
transitionStagger: transitionStagger,
|
|
474
481
|
transitionPlaying: transitionPlaying,
|
|
@@ -691,6 +698,10 @@ var QuizScreen = function QuizScreen(_ref) {
|
|
|
691
698
|
var onQuizReset = React.useCallback(function () {
|
|
692
699
|
setUserAnswerIndex(null);
|
|
693
700
|
}, [setUserAnswerIndex]);
|
|
701
|
+
var numberOfAnswers = (answers || []).length;
|
|
702
|
+
React.useEffect(function () {
|
|
703
|
+
onQuizReset();
|
|
704
|
+
}, [numberOfAnswers, onQuizReset]);
|
|
694
705
|
var isSplitted = layout === 'split';
|
|
695
706
|
var verticalAlign = isSplitted ? null : layout;
|
|
696
707
|
var showReset = isEdit;
|
|
@@ -736,6 +747,7 @@ var QuizScreen = function QuizScreen(_ref) {
|
|
|
736
747
|
withoutTrueFalse: withoutTrueFalse,
|
|
737
748
|
withoutGoodAnswer: withoutGoodAnswer,
|
|
738
749
|
focusable: current && isView,
|
|
750
|
+
animated: isView,
|
|
739
751
|
showInstantAnswer: showInstantAnswer,
|
|
740
752
|
withResult: true,
|
|
741
753
|
layout: layout,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@micromag/screen-quiz",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.363",
|
|
4
4
|
"description": "",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"javascript"
|
|
@@ -52,18 +52,18 @@
|
|
|
52
52
|
"@fortawesome/fontawesome-svg-core": "^1.2.32",
|
|
53
53
|
"@fortawesome/free-solid-svg-icons": "^5.15.1",
|
|
54
54
|
"@fortawesome/react-fontawesome": "^0.1.13",
|
|
55
|
-
"@micromag/core": "^0.3.
|
|
56
|
-
"@micromag/data": "^0.3.
|
|
57
|
-
"@micromag/element-background": "^0.3.
|
|
58
|
-
"@micromag/element-button": "^0.3.
|
|
59
|
-
"@micromag/element-container": "^0.3.
|
|
60
|
-
"@micromag/element-footer": "^0.3.
|
|
61
|
-
"@micromag/element-header": "^0.3.
|
|
62
|
-
"@micromag/element-heading": "^0.3.
|
|
63
|
-
"@micromag/element-layout": "^0.3.
|
|
64
|
-
"@micromag/element-scroll": "^0.3.
|
|
65
|
-
"@micromag/element-text": "^0.3.
|
|
66
|
-
"@micromag/transforms": "^0.3.
|
|
55
|
+
"@micromag/core": "^0.3.362",
|
|
56
|
+
"@micromag/data": "^0.3.362",
|
|
57
|
+
"@micromag/element-background": "^0.3.362",
|
|
58
|
+
"@micromag/element-button": "^0.3.362",
|
|
59
|
+
"@micromag/element-container": "^0.3.362",
|
|
60
|
+
"@micromag/element-footer": "^0.3.362",
|
|
61
|
+
"@micromag/element-header": "^0.3.362",
|
|
62
|
+
"@micromag/element-heading": "^0.3.362",
|
|
63
|
+
"@micromag/element-layout": "^0.3.362",
|
|
64
|
+
"@micromag/element-scroll": "^0.3.362",
|
|
65
|
+
"@micromag/element-text": "^0.3.362",
|
|
66
|
+
"@micromag/transforms": "^0.3.362",
|
|
67
67
|
"@react-spring/core": "^9.6.1",
|
|
68
68
|
"@react-spring/web": "^9.6.1",
|
|
69
69
|
"classnames": "^2.2.6",
|
|
@@ -76,5 +76,5 @@
|
|
|
76
76
|
"publishConfig": {
|
|
77
77
|
"access": "public"
|
|
78
78
|
},
|
|
79
|
-
"gitHead": "
|
|
79
|
+
"gitHead": "d8cb1ed298c8536f0776716c9fd6063aeba06a08"
|
|
80
80
|
}
|