@micromag/screen-quiz 0.3.362 → 0.3.364

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 +43 -15
  2. package/lib/index.js +42 -14
  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
 
@@ -52,7 +52,7 @@ var propTypes$5 = {
52
52
  };
53
53
  var defaultProps$5 = {
54
54
  answeredIndex: null,
55
- answersCollapseDelay: 2000,
55
+ answersCollapseDelay: 1000,
56
56
  buttonsStyle: null,
57
57
  buttonsTextStyle: null,
58
58
  goodAnswerColor: null,
@@ -117,6 +117,10 @@ var Answers = function Answers(_ref) {
117
117
  _useState6 = _slicedToArray(_useState5, 2),
118
118
  answersDidCollapse = _useState6[0],
119
119
  setAnswersDidCollapse = _useState6[1];
120
+ var _useState7 = useState(initialCollapsed || answeredIndex !== null),
121
+ _useState8 = _slicedToArray(_useState7, 2),
122
+ answersFinalCollapse = _useState8[0],
123
+ setAnswersFinalCollapse = _useState8[1];
120
124
  useEffect(function () {
121
125
  var timeout = null;
122
126
  if (answeredIndex !== null && shouldCollapse) {
@@ -135,6 +139,19 @@ var Answers = function Answers(_ref) {
135
139
  }
136
140
  };
137
141
  }, [answeredIndex, withoutGoodAnswer, setAnswersCollapsed, onCollapse, answersCollapseDelay, hasAnsweredRight, finalShowUserAnswer]);
142
+ useEffect(function () {
143
+ var timeout = null;
144
+ if (answersCollapsed) {
145
+ timeout = setTimeout(function () {
146
+ setAnswersFinalCollapse(true);
147
+ }, 200);
148
+ }
149
+ return function () {
150
+ if (timeout !== null) {
151
+ clearTimeout(timeout);
152
+ }
153
+ };
154
+ }, [answersCollapsed]);
138
155
  var onAnswerTransitionEnd = useCallback(function () {
139
156
  if (onTransitionEnd !== null) {
140
157
  onTransitionEnd();
@@ -149,17 +166,20 @@ var Answers = function Answers(_ref) {
149
166
  var itemsRefs = useRef([]);
150
167
  var listOfItems = isPlaceholder || isEdit && items.length === 0 ? _toConsumableArray(new Array(2)) : items;
151
168
  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]);
169
+ if (animated) {
170
+ var allHeights = listOfItems.reduce(function (acc, it, i) {
171
+ if (itemsRefs.current[i] && collapseAnimated) {
172
+ var _ref4 = itemsRefs.current[i].getBoundingClientRect() || {},
173
+ _ref4$height = _ref4.height,
174
+ height = _ref4$height === void 0 ? 0 : _ref4$height;
175
+ acc.push(height);
176
+ }
177
+ return acc;
178
+ }, []);
179
+ return allHeights;
180
+ }
181
+ return [];
182
+ }, [animated, answeredIndex, shouldCollapse, collapseAnimated, listOfItems]);
163
183
  var showAnimation = isView || isEdit;
164
184
  var filteredListOfItems = listOfItems.map(function (answer, answerI) {
165
185
  var height = heights[answerI] ? heights[answerI] : 0;
@@ -199,10 +219,14 @@ var Answers = function Answers(_ref) {
199
219
  // Animate this, not height
200
220
  maxHeight:
201
221
  // eslint-disable-next-line no-nested-ternary
202
- hidden && showAnimation && !withoutGoodAnswer ? 0 : maxHeight > 0 ? maxHeight : null
222
+ hidden && showAnimation && !withoutGoodAnswer && collapseAnimated && answersFinalCollapse ? 0 : maxHeight > 0 ? maxHeight : null,
223
+ height: hidden && showAnimation && !withoutGoodAnswer && !collapseAnimated && answersFinalCollapse ? 0 : 'auto'
203
224
  };
204
225
  },
205
- config: config.gentle
226
+ config: {
227
+ tension: 300,
228
+ friction: 35
229
+ }
206
230
  });
207
231
  return /*#__PURE__*/React.createElement("div", {
208
232
  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 +691,10 @@ var QuizScreen = function QuizScreen(_ref) {
667
691
  var onQuizReset = useCallback(function () {
668
692
  setUserAnswerIndex(null);
669
693
  }, [setUserAnswerIndex]);
694
+ var numberOfAnswers = (answers || []).length;
695
+ useEffect(function () {
696
+ onQuizReset();
697
+ }, [numberOfAnswers, onQuizReset]);
670
698
  var isSplitted = layout === 'split';
671
699
  var verticalAlign = isSplitted ? null : layout;
672
700
  var showReset = isEdit;
package/lib/index.js CHANGED
@@ -75,7 +75,7 @@ var propTypes$5 = {
75
75
  };
76
76
  var defaultProps$5 = {
77
77
  answeredIndex: null,
78
- answersCollapseDelay: 2000,
78
+ answersCollapseDelay: 1000,
79
79
  buttonsStyle: null,
80
80
  buttonsTextStyle: null,
81
81
  goodAnswerColor: null,
@@ -140,6 +140,10 @@ var Answers = function Answers(_ref) {
140
140
  _useState6 = _slicedToArray__default["default"](_useState5, 2),
141
141
  answersDidCollapse = _useState6[0],
142
142
  setAnswersDidCollapse = _useState6[1];
143
+ var _useState7 = React.useState(initialCollapsed || answeredIndex !== null),
144
+ _useState8 = _slicedToArray__default["default"](_useState7, 2),
145
+ answersFinalCollapse = _useState8[0],
146
+ setAnswersFinalCollapse = _useState8[1];
143
147
  React.useEffect(function () {
144
148
  var timeout = null;
145
149
  if (answeredIndex !== null && shouldCollapse) {
@@ -158,6 +162,19 @@ var Answers = function Answers(_ref) {
158
162
  }
159
163
  };
160
164
  }, [answeredIndex, withoutGoodAnswer, setAnswersCollapsed, onCollapse, answersCollapseDelay, hasAnsweredRight, finalShowUserAnswer]);
165
+ React.useEffect(function () {
166
+ var timeout = null;
167
+ if (answersCollapsed) {
168
+ timeout = setTimeout(function () {
169
+ setAnswersFinalCollapse(true);
170
+ }, 200);
171
+ }
172
+ return function () {
173
+ if (timeout !== null) {
174
+ clearTimeout(timeout);
175
+ }
176
+ };
177
+ }, [answersCollapsed]);
161
178
  var onAnswerTransitionEnd = React.useCallback(function () {
162
179
  if (onTransitionEnd !== null) {
163
180
  onTransitionEnd();
@@ -172,17 +189,20 @@ var Answers = function Answers(_ref) {
172
189
  var itemsRefs = React.useRef([]);
173
190
  var listOfItems = isPlaceholder || isEdit && items.length === 0 ? _toConsumableArray__default["default"](new Array(2)) : items;
174
191
  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]);
192
+ if (web.animated) {
193
+ var allHeights = listOfItems.reduce(function (acc, it, i) {
194
+ if (itemsRefs.current[i] && collapseAnimated) {
195
+ var _ref4 = itemsRefs.current[i].getBoundingClientRect() || {},
196
+ _ref4$height = _ref4.height,
197
+ height = _ref4$height === void 0 ? 0 : _ref4$height;
198
+ acc.push(height);
199
+ }
200
+ return acc;
201
+ }, []);
202
+ return allHeights;
203
+ }
204
+ return [];
205
+ }, [web.animated, answeredIndex, shouldCollapse, collapseAnimated, listOfItems]);
186
206
  var showAnimation = isView || isEdit;
187
207
  var filteredListOfItems = listOfItems.map(function (answer, answerI) {
188
208
  var height = heights[answerI] ? heights[answerI] : 0;
@@ -222,10 +242,14 @@ var Answers = function Answers(_ref) {
222
242
  // Animate this, not height
223
243
  maxHeight:
224
244
  // eslint-disable-next-line no-nested-ternary
225
- hidden && showAnimation && !withoutGoodAnswer ? 0 : maxHeight > 0 ? maxHeight : null
245
+ hidden && showAnimation && !withoutGoodAnswer && collapseAnimated && answersFinalCollapse ? 0 : maxHeight > 0 ? maxHeight : null,
246
+ height: hidden && showAnimation && !withoutGoodAnswer && !collapseAnimated && answersFinalCollapse ? 0 : 'auto'
226
247
  };
227
248
  },
228
- config: web.config.gentle
249
+ config: {
250
+ tension: 300,
251
+ friction: 35
252
+ }
229
253
  });
230
254
  return /*#__PURE__*/React__default["default"].createElement("div", {
231
255
  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 +714,10 @@ var QuizScreen = function QuizScreen(_ref) {
690
714
  var onQuizReset = React.useCallback(function () {
691
715
  setUserAnswerIndex(null);
692
716
  }, [setUserAnswerIndex]);
717
+ var numberOfAnswers = (answers || []).length;
718
+ React.useEffect(function () {
719
+ onQuizReset();
720
+ }, [numberOfAnswers, onQuizReset]);
693
721
  var isSplitted = layout === 'split';
694
722
  var verticalAlign = isSplitted ? null : layout;
695
723
  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.364",
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": "7c8047d061894da9a5e278f2e56e559643665728"
80
80
  }