@micromag/screen-quiz 0.3.362 → 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.
Files changed (3) hide show
  1. package/es/index.js +26 -14
  2. package/lib/index.js +25 -13
  3. package/package.json +2 -2
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 { useTransition, config, animated } from '@react-spring/web';
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
 
@@ -149,17 +149,20 @@ var Answers = function Answers(_ref) {
149
149
  var itemsRefs = useRef([]);
150
150
  var listOfItems = isPlaceholder || isEdit && items.length === 0 ? _toConsumableArray(new Array(2)) : items;
151
151
  var heights = useMemo(function () {
152
- var allHeights = listOfItems.reduce(function (acc, it, i) {
153
- if (itemsRefs.current[i] && collapseAnimated) {
154
- var _ref4 = itemsRefs.current[i].getBoundingClientRect() || {},
155
- _ref4$height = _ref4.height,
156
- height = _ref4$height === void 0 ? 0 : _ref4$height;
157
- acc.push(height);
158
- }
159
- return acc;
160
- }, []);
161
- return allHeights;
162
- }, [answeredIndex, shouldCollapse, collapseAnimated, listOfItems]);
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]);
163
166
  var showAnimation = isView || isEdit;
164
167
  var filteredListOfItems = listOfItems.map(function (answer, answerI) {
165
168
  var height = heights[answerI] ? heights[answerI] : 0;
@@ -199,10 +202,15 @@ var Answers = function Answers(_ref) {
199
202
  // Animate this, not height
200
203
  maxHeight:
201
204
  // eslint-disable-next-line no-nested-ternary
202
- hidden && showAnimation && !withoutGoodAnswer ? 0 : maxHeight > 0 ? maxHeight : null
205
+ hidden && showAnimation && !withoutGoodAnswer && collapseAnimated ? 0 : maxHeight > 0 ? maxHeight : null,
206
+ height: hidden && showAnimation && !withoutGoodAnswer && !collapseAnimated ? 0 : 'auto'
203
207
  };
204
208
  },
205
- config: config.gentle
209
+ // config: config.gentle,
210
+ config: {
211
+ tension: 300,
212
+ friction: 35
213
+ }
206
214
  });
207
215
  return /*#__PURE__*/React.createElement("div", {
208
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)])
@@ -667,6 +675,10 @@ var QuizScreen = function QuizScreen(_ref) {
667
675
  var onQuizReset = useCallback(function () {
668
676
  setUserAnswerIndex(null);
669
677
  }, [setUserAnswerIndex]);
678
+ var numberOfAnswers = (answers || []).length;
679
+ useEffect(function () {
680
+ onQuizReset();
681
+ }, [numberOfAnswers, onQuizReset]);
670
682
  var isSplitted = layout === 'split';
671
683
  var verticalAlign = isSplitted ? null : layout;
672
684
  var showReset = isEdit;
package/lib/index.js CHANGED
@@ -172,17 +172,20 @@ var Answers = function Answers(_ref) {
172
172
  var itemsRefs = React.useRef([]);
173
173
  var listOfItems = isPlaceholder || isEdit && items.length === 0 ? _toConsumableArray__default["default"](new Array(2)) : items;
174
174
  var heights = React.useMemo(function () {
175
- var allHeights = listOfItems.reduce(function (acc, it, i) {
176
- if (itemsRefs.current[i] && collapseAnimated) {
177
- var _ref4 = itemsRefs.current[i].getBoundingClientRect() || {},
178
- _ref4$height = _ref4.height,
179
- height = _ref4$height === void 0 ? 0 : _ref4$height;
180
- acc.push(height);
181
- }
182
- return acc;
183
- }, []);
184
- return allHeights;
185
- }, [answeredIndex, shouldCollapse, collapseAnimated, listOfItems]);
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]);
186
189
  var showAnimation = isView || isEdit;
187
190
  var filteredListOfItems = listOfItems.map(function (answer, answerI) {
188
191
  var height = heights[answerI] ? heights[answerI] : 0;
@@ -222,10 +225,15 @@ var Answers = function Answers(_ref) {
222
225
  // Animate this, not height
223
226
  maxHeight:
224
227
  // eslint-disable-next-line no-nested-ternary
225
- hidden && showAnimation && !withoutGoodAnswer ? 0 : maxHeight > 0 ? maxHeight : null
228
+ hidden && showAnimation && !withoutGoodAnswer && collapseAnimated ? 0 : maxHeight > 0 ? maxHeight : null,
229
+ height: hidden && showAnimation && !withoutGoodAnswer && !collapseAnimated ? 0 : 'auto'
226
230
  };
227
231
  },
228
- config: web.config.gentle
232
+ // config: config.gentle,
233
+ config: {
234
+ tension: 300,
235
+ friction: 35
236
+ }
229
237
  });
230
238
  return /*#__PURE__*/React__default["default"].createElement("div", {
231
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)])
@@ -690,6 +698,10 @@ var QuizScreen = function QuizScreen(_ref) {
690
698
  var onQuizReset = React.useCallback(function () {
691
699
  setUserAnswerIndex(null);
692
700
  }, [setUserAnswerIndex]);
701
+ var numberOfAnswers = (answers || []).length;
702
+ React.useEffect(function () {
703
+ onQuizReset();
704
+ }, [numberOfAnswers, onQuizReset]);
693
705
  var isSplitted = layout === 'split';
694
706
  var verticalAlign = isSplitted ? null : layout;
695
707
  var showReset = isEdit;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@micromag/screen-quiz",
3
- "version": "0.3.362",
3
+ "version": "0.3.363",
4
4
  "description": "",
5
5
  "keywords": [
6
6
  "javascript"
@@ -76,5 +76,5 @@
76
76
  "publishConfig": {
77
77
  "access": "public"
78
78
  },
79
- "gitHead": "21619f51536d95517afabfdf316ef8fc345f6562"
79
+ "gitHead": "d8cb1ed298c8536f0776716c9fd6063aeba06a08"
80
80
  }