@micromag/screen-quiz 0.3.4 → 0.3.9

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.
@@ -1,5 +1,5 @@
1
1
  .micromag-screen-quiz-answers-emptyAnswer{margin:5px auto;border:2px dashed #343434;color:#343434}.micromag-screen-quiz-answers-button:focus-visible{outline:3px solid #a13dff}.micromag-screen-quiz-answers-container,.micromag-screen-quiz-answers-items{position:relative}.micromag-screen-quiz-answers-emptyAnswer{width:100%;height:40px;margin:0 auto;font-size:.75em}.micromag-screen-quiz-answers-item{-webkit-transition-property:opacity;-o-transition-property:opacity;transition-property:opacity;-webkit-transition-duration:.5s;-o-transition-duration:.5s;transition-duration:.5s;-webkit-transition-timing-function:ease;-o-transition-timing-function:ease;transition-timing-function:ease}.micromag-screen-quiz-answers-item.micromag-screen-quiz-answers-rightAnswer{-webkit-transition-property:-webkit-transform;transition-property:-webkit-transform;-o-transition-property:transform;transition-property:transform;transition-property:transform, -webkit-transform;-webkit-transition-duration:1s;-o-transition-duration:1s;transition-duration:1s}.micromag-screen-quiz-answers-answered .micromag-screen-quiz-answers-item{opacity:.3}.micromag-screen-quiz-answers-answered .micromag-screen-quiz-answers-item.micromag-screen-quiz-answers-rightAnswer,.micromag-screen-quiz-answers-answered .micromag-screen-quiz-answers-item.micromag-screen-quiz-answers-userAnswer{opacity:.99}.micromag-screen-quiz-answers-willCollapse .micromag-screen-quiz-answers-item,.micromag-screen-quiz-answers-willCollapse .micromag-screen-quiz-answers-item.micromag-screen-quiz-answers-userAnswer{-webkit-transition-duration:.2s;-o-transition-duration:.2s;transition-duration:.2s;opacity:0}.micromag-screen-quiz-answers-willCollapse .micromag-screen-quiz-answers-item.micromag-screen-quiz-answers-rightAnswer{-webkit-transition-duration:1s;-o-transition-duration:1s;transition-duration:1s;opacity:1}.micromag-screen-quiz-answers-didCollapsed .micromag-screen-quiz-answers-item.micromag-screen-quiz-answers-rightAnswer{-webkit-transition:none;-o-transition:none;transition:none}.micromag-screen-quiz-answers-withoutGoodAnswer .micromag-screen-quiz-answers-item.micromag-screen-quiz-answers-userAnswer{-webkit-transition-duration:1s;-o-transition-duration:1s;transition-duration:1s}.micromag-screen-quiz-answers-isPlaceholder .micromag-screen-quiz-answers-item{padding:1px 0}.micromag-screen-quiz-answers-button{position:relative;width:100%;padding:10px;color:#fff;border:1px solid #fff;border-radius:10px}.micromag-screen-quiz-answers-button:disabled{opacity:1;pointer-events:none}.micromag-screen-quiz-answers-withGoodAnswer .micromag-screen-quiz-answers-button{padding-right:42px!important;padding-left:42px!important}.micromag-screen-quiz-answers-resultIcon{display:-webkit-flex;display:-ms-flexbox;display:flex;position:absolute;top:50%;left:5px;-webkit-align-items:center;-ms-flex-align:center;align-items:center;-webkit-justify-content:center;-ms-flex-pack:center;justify-content:center;width:32px;height:32px;margin-top:-16px;padding:5px;-webkit-transition:opacity .15s ease;-o-transition:opacity .15s ease;transition:opacity .15s ease;border:2px solid #1c1c1c;border-radius:50%;opacity:0;background-color:#ff2945}.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-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{margin:5px auto;border:2px dashed #343434;color:#343434}.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;width:100%;margin-bottom:1em;text-align:center}.micromag-screen-quiz-question-container .micromag-screen-quiz-question-result{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;opacity:0;pointer-events:none}.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{width:100%;margin:0 auto}.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{position:relative;opacity:1;pointer-events:all}.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);mix-blend-mode:difference;font-size:8px}
3
3
  .micromag-screen-quiz-container{position:relative;width:100%;height:100%;overflow:hidden}.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{position:relative;padding:6px}.micromag-screen-quiz-layout{top:0;right:0}.micromag-screen-quiz-callToAction,.micromag-screen-quiz-layout{position:absolute;bottom:0;left:0}.micromag-screen-quiz-callToAction{width:100%}.micromag-screen-quiz-transition{position:absolute;top:0;right:0;bottom:0;left: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{-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}.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{-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}.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{-webkit-transition:opacity 1s ease;-o-transition:opacity 1s ease;transition:opacity 1s ease;opacity:1}.micromag-screen-quiz-background.micromag-screen-quiz-exit{opacity:1}.micromag-screen-quiz-background.micromag-screen-quiz-exitActive{-webkit-transition:opacity 1s ease;-o-transition:opacity 1s ease;transition:opacity 1s ease;opacity:0}
4
- .micromag-screen-quiz-title-container .micromag-screen-quiz-title-emptyDescription,.micromag-screen-quiz-title-container .micromag-screen-quiz-title-emptyTitle{margin:5px auto;border:2px dashed #343434;color:#343434}.micromag-screen-quiz-title-container .micromag-screen-quiz-title-title{margin-bottom:10px}.micromag-screen-quiz-title-container .micromag-screen-quiz-title-emptyDescription,.micromag-screen-quiz-title-container .micromag-screen-quiz-title-emptyTitle{width:100%;margin:0 auto}.micromag-screen-quiz-title-container .micromag-screen-quiz-title-emptyTitle{height:60px}.micromag-screen-quiz-title-container .micromag-screen-quiz-title-emptyDescription{height:100px}.micromag-screen-quiz-title-container.micromag-screen-quiz-title-isPlaceholder{padding:10px}
4
+ .micromag-screen-quiz-title-container .micromag-screen-quiz-title-emptyDescription,.micromag-screen-quiz-title-container .micromag-screen-quiz-title-emptyTitle{margin:5px auto;border:2px dashed #343434;color:#343434}.micromag-screen-quiz-title-container .micromag-screen-quiz-title-description,.micromag-screen-quiz-title-container .micromag-screen-quiz-title-title{margin-bottom:10px}.micromag-screen-quiz-title-container .micromag-screen-quiz-title-emptyDescription,.micromag-screen-quiz-title-container .micromag-screen-quiz-title-emptyTitle{width:100%;margin:0 auto 10px}.micromag-screen-quiz-title-container .micromag-screen-quiz-title-emptyTitle{height:60px}.micromag-screen-quiz-title-container .micromag-screen-quiz-title-emptyDescription{height:100px}.micromag-screen-quiz-title-container.micromag-screen-quiz-title-isPlaceholder{padding:10px}
5
5
  .micromag-screen-quiz-results-container .micromag-screen-quiz-results-emptyDescription,.micromag-screen-quiz-results-container .micromag-screen-quiz-results-emptyTitle{margin:5px auto;border:2px dashed #343434;color:#343434}.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{width:100%;margin:0 auto}.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
@@ -162,7 +162,6 @@ var Answers = function Answers(_ref) {
162
162
  }
163
163
  }
164
164
  }, [shouldCollapse, answersCollapsed, answersDidCollapsed, setAnswersCollapsed, onCollapsed, onTransitionEnd]);
165
- console.log(items);
166
165
  return /*#__PURE__*/React.createElement("div", {
167
166
  className: classNames([styles$4.container, (_ref5 = {}, _defineProperty(_ref5, styles$4.answered, answered), _defineProperty(_ref5, styles$4.withoutGoodAnswer, withoutGoodAnswer), _defineProperty(_ref5, styles$4.withGoodAnswer, !withoutGoodAnswer), _defineProperty(_ref5, styles$4.willCollapse, shouldCollapse && answersCollapsed), _defineProperty(_ref5, styles$4.didCollapsed, shouldCollapse && answersDidCollapsed), _defineProperty(_ref5, styles$4.isPlaceholder, isPlaceholder), _defineProperty(_ref5, className, className !== null), _ref5)]),
168
167
  ref: answerRef,
@@ -371,13 +370,13 @@ var Question = function Question(_ref) {
371
370
  placeholder: /*#__PURE__*/React.createElement("div", {
372
371
  className: styles$3.index
373
372
  }, "1 / 10")
374
- }, /*#__PURE__*/React.createElement(Transitions, {
373
+ }, totalCount > 1 ? /*#__PURE__*/React.createElement(Transitions, {
375
374
  transitions: transitions,
376
375
  playing: transitionPlaying,
377
376
  disabled: transitionDisabled
378
377
  }, /*#__PURE__*/React.createElement("div", {
379
378
  className: styles$3.index
380
- }, index + 1, " / ", totalCount))) : null, /*#__PURE__*/React.createElement(ScreenElement, {
379
+ }, index + 1, " / ", totalCount)) : null) : null, /*#__PURE__*/React.createElement(ScreenElement, {
381
380
  key: "question",
382
381
  placeholder: "title",
383
382
  emptyLabel: /*#__PURE__*/React.createElement(FormattedMessage, {
@@ -638,45 +637,60 @@ var QuizScreen = function QuizScreen(_ref) {
638
637
  QuizScreen.propTypes = propTypes$3;
639
638
  QuizScreen.defaultProps = defaultProps$3;
640
639
 
641
- var styles$1 = {"container":"micromag-screen-quiz-title-container","emptyDescription":"micromag-screen-quiz-title-emptyDescription","emptyTitle":"micromag-screen-quiz-title-emptyTitle","title":"micromag-screen-quiz-title-title","isPlaceholder":"micromag-screen-quiz-title-isPlaceholder"};
640
+ var styles$1 = {"container":"micromag-screen-quiz-title-container","emptyDescription":"micromag-screen-quiz-title-emptyDescription","emptyTitle":"micromag-screen-quiz-title-emptyTitle","description":"micromag-screen-quiz-title-description","title":"micromag-screen-quiz-title-title","isPlaceholder":"micromag-screen-quiz-title-isPlaceholder"};
642
641
 
643
642
  var propTypes$2 = {
644
643
  title: PropTypes.textElement,
645
644
  description: PropTypes.textElement,
645
+ button: PropTypes.textElement,
646
646
  layout: PropTypes$1.string,
647
+ focusable: PropTypes$1.bool,
647
648
  transitions: PropTypes.transitions,
648
649
  transitionPlaying: PropTypes$1.bool,
649
650
  transitionStagger: PropTypes$1.number,
650
651
  transitionDisabled: PropTypes$1.bool,
651
652
  className: PropTypes$1.string,
652
- style: PropTypes$1.objectOf(PropTypes$1.oneOfType([PropTypes$1.string, PropTypes$1.number]))
653
+ style: PropTypes$1.objectOf(PropTypes$1.oneOfType([PropTypes$1.string, PropTypes$1.number])),
654
+ onClickButton: PropTypes$1.func
653
655
  };
654
656
  var defaultProps$2 = {
655
657
  title: null,
656
658
  description: null,
657
659
  layout: null,
660
+ button: null,
661
+ focusable: false,
658
662
  transitions: null,
659
663
  transitionPlaying: false,
660
664
  transitionStagger: 100,
661
665
  transitionDisabled: false,
662
666
  className: null,
663
- style: null
667
+ style: null,
668
+ onClickButton: null
664
669
  };
665
670
 
666
671
  var Title = function Title(_ref) {
667
672
  var layout = _ref.layout,
668
673
  title = _ref.title,
669
674
  description = _ref.description,
675
+ button = _ref.button,
676
+ focusable = _ref.focusable,
670
677
  transitions = _ref.transitions,
671
678
  transitionPlaying = _ref.transitionPlaying,
672
679
  transitionStagger = _ref.transitionStagger,
673
680
  transitionDisabled = _ref.transitionDisabled,
674
681
  className = _ref.className,
675
- style = _ref.style;
682
+ style = _ref.style,
683
+ onClickButton = _ref.onClickButton;
684
+
685
+ var _useScreenRenderConte = useScreenRenderContext(),
686
+ isPreview = _useScreenRenderConte.isPreview,
687
+ isEdit = _useScreenRenderConte.isEdit;
688
+
676
689
  var isSplitted = layout === 'split';
677
690
  var verticalAlign = isSplitted ? null : layout;
678
691
  var hasTitle = isTextFilled(title);
679
692
  var hasDescription = isTextFilled(description);
693
+ var hasButton = isTextFilled(button);
680
694
  return /*#__PURE__*/React.createElement(Layout, {
681
695
  className: classNames([styles$1.container, _defineProperty({}, className, className !== null)]),
682
696
  fullscreen: true,
@@ -700,9 +714,7 @@ var Title = function Title(_ref) {
700
714
  disabled: transitionDisabled
701
715
  }, /*#__PURE__*/React.createElement(Heading, Object.assign({}, title, {
702
716
  className: styles$1.title
703
- }))) : null), isSplitted ? /*#__PURE__*/React.createElement(Spacer, {
704
- key: "spacer"
705
- }) : null, /*#__PURE__*/React.createElement(ScreenElement, {
717
+ }))) : null), /*#__PURE__*/React.createElement(ScreenElement, {
706
718
  key: "description",
707
719
  placeholder: "text",
708
720
  emptyLabel: /*#__PURE__*/React.createElement(FormattedMessage, {
@@ -714,14 +726,38 @@ var Title = function Title(_ref) {
714
726
  }),
715
727
  emptyClassName: styles$1.emptyDescription,
716
728
  isEmpty: !hasDescription
717
- }, hasTitle ? /*#__PURE__*/React.createElement(Transitions, {
729
+ }, hasDescription ? /*#__PURE__*/React.createElement(Transitions, {
718
730
  transitions: transitions,
719
731
  playing: transitionPlaying,
720
732
  disabled: transitionDisabled,
721
733
  delay: transitionStagger
722
734
  }, /*#__PURE__*/React.createElement(Text, Object.assign({}, description, {
723
735
  className: styles$1.description
724
- }))) : null)]);
736
+ }))) : null), isSplitted ? /*#__PURE__*/React.createElement(Spacer, {
737
+ key: "spacer"
738
+ }) : null, /*#__PURE__*/React.createElement(ScreenElement, {
739
+ key: "button",
740
+ placeholder: "button"
741
+ }, /*#__PURE__*/React.createElement(Transitions, {
742
+ transitions: transitions,
743
+ playing: transitionPlaying,
744
+ disabled: transitionDisabled,
745
+ delay: transitionStagger * 2
746
+ }, /*#__PURE__*/React.createElement(Button, {
747
+ disabled: isPreview || isEdit,
748
+ focusable: focusable,
749
+ buttonStyle: button !== null ? button.buttonStyle : null,
750
+ className: styles$1.button,
751
+ onClick: onClickButton
752
+ }, hasButton ? /*#__PURE__*/React.createElement(Text, Object.assign({}, button, {
753
+ className: styles$1.label
754
+ })) : /*#__PURE__*/React.createElement(FormattedMessage, {
755
+ id: "fzeHjj",
756
+ defaultMessage: [{
757
+ "type": 0,
758
+ "value": "Enter"
759
+ }]
760
+ }))))]);
725
761
  };
726
762
 
727
763
  Title.propTypes = propTypes$2;
@@ -835,6 +871,7 @@ var propTypes = {
835
871
  badAnswerColor: PropTypes.color,
836
872
  spacing: PropTypes$1.number,
837
873
  background: PropTypes.backgroundElement,
874
+ introButton: PropTypes.textElement,
838
875
  introBackground: PropTypes.backgroundElement,
839
876
  callToAction: PropTypes.callToAction,
840
877
  current: PropTypes$1.bool,
@@ -857,6 +894,7 @@ var defaultProps = {
857
894
  badAnswerColor: null,
858
895
  spacing: 20,
859
896
  background: null,
897
+ introButton: null,
860
898
  introBackground: null,
861
899
  callToAction: null,
862
900
  current: true,
@@ -883,6 +921,7 @@ var QuizMultipleScreen = function QuizMultipleScreen(_ref) {
883
921
  spacing = _ref.spacing,
884
922
  background = _ref.background,
885
923
  introBackground = _ref.introBackground,
924
+ introButton = _ref.introButton,
886
925
  callToAction = _ref.callToAction,
887
926
  current = _ref.current,
888
927
  active = _ref.active,
@@ -941,13 +980,24 @@ var QuizMultipleScreen = function QuizMultipleScreen(_ref) {
941
980
  userAnswers = _useState2[0],
942
981
  setUserAnswers = _useState2[1];
943
982
 
944
- var initialQuestionIndex = stateId === 'questions' ? parseInt(stateIndex, 10) : stateId;
983
+ var initialQuestionIndex = 'intro';
984
+
985
+ if (stateId !== null) {
986
+ initialQuestionIndex = stateId === 'questions' ? parseInt(stateIndex, 10) : stateId;
987
+ } else if (isPlaceholder || !hasIntro) {
988
+ initialQuestionIndex = 0;
989
+ }
945
990
 
946
- var _useState3 = useState(initialQuestionIndex !== null || !hasIntro || isPlaceholder ? initialQuestionIndex || 0 : 'intro'),
991
+ var _useState3 = useState(initialQuestionIndex),
947
992
  _useState4 = _slicedToArray(_useState3, 2),
948
993
  questionIndex = _useState4[0],
949
994
  setQuestionIndex = _useState4[1];
950
995
 
996
+ useEffect(function () {
997
+ if (isPreview && hasIntro && questionIndex !== 'intro') {
998
+ setQuestionIndex('intro');
999
+ }
1000
+ }, [isPreview, hasIntro, questionIndex, setQuestionIndex]);
951
1001
  var onAnswerClick = useCallback(function (answer, answerIndex) {
952
1002
  setUserAnswers(_objectSpread(_objectSpread({}, userAnswers), {}, _defineProperty({}, questionIndex, answerIndex)));
953
1003
  trackScreenEvent('click_answer', "Question #".concat(questionIndex + 1, " ").concat(answerIndex + 1, ": ").concat(answer.label.body), {
@@ -967,6 +1017,9 @@ var QuizMultipleScreen = function QuizMultipleScreen(_ref) {
967
1017
  setQuestionIndex('results');
968
1018
  }
969
1019
  }, [questions, questionIndex, setQuestionIndex]);
1020
+ var onClickIntroButton = useCallback(function () {
1021
+ setQuestionIndex(0);
1022
+ }, [setQuestionIndex]);
970
1023
  useEffect(function () {
971
1024
  if (!current && isEdit && userAnswers !== null) {
972
1025
  setUserAnswers(null);
@@ -1125,6 +1178,8 @@ var QuizMultipleScreen = function QuizMultipleScreen(_ref) {
1125
1178
  title: title,
1126
1179
  description: description,
1127
1180
  layout: introLayout || layout,
1181
+ button: introButton,
1182
+ focusable: current && isView,
1128
1183
  transitions: transitions,
1129
1184
  transitionPlaying: transitionPlaying,
1130
1185
  transitionStagger: transitionStagger,
@@ -1133,7 +1188,8 @@ var QuizMultipleScreen = function QuizMultipleScreen(_ref) {
1133
1188
  style: !isPlaceholder ? {
1134
1189
  padding: spacing,
1135
1190
  paddingTop: (menuOverScreen && !isPreview ? menuSize : 0) + spacing
1136
- } : null
1191
+ } : null,
1192
+ onClickButton: onClickIntroButton
1137
1193
  })) : null, isQuestion ? /*#__PURE__*/React.createElement(CSSTransition, {
1138
1194
  key: "question-".concat(questionIndex),
1139
1195
  classNames: styles$2,
@@ -1276,24 +1332,14 @@ var definition = [{
1276
1332
  }),
1277
1333
  fields: [{
1278
1334
  name: 'buttonsStyle',
1279
- type: 'field-with-form',
1335
+ type: 'box-style-form',
1280
1336
  label: defineMessage({
1281
1337
  id: "l5uLMd",
1282
1338
  defaultMessage: [{
1283
1339
  "type": 0,
1284
1340
  "value": "Buttons"
1285
1341
  }]
1286
- }),
1287
- noValueLabel: defineMessage({
1288
- id: "65rc70",
1289
- defaultMessage: [{
1290
- "type": 0,
1291
- "value": "Edit style..."
1292
- }]
1293
- }),
1294
- field: {
1295
- type: 'box-style'
1296
- }
1342
+ })
1297
1343
  }, {
1298
1344
  name: 'goodAnswerColor',
1299
1345
  type: 'color',
@@ -1403,6 +1449,19 @@ var definition = [{
1403
1449
  "value": "Description"
1404
1450
  }]
1405
1451
  })
1452
+ }, {
1453
+ name: 'introButton',
1454
+ type: 'button-element',
1455
+ theme: {
1456
+ textStyle: 'button'
1457
+ },
1458
+ label: defineMessage({
1459
+ id: "i6bmbD",
1460
+ defaultMessage: [{
1461
+ "type": 0,
1462
+ "value": "Button"
1463
+ }]
1464
+ })
1406
1465
  }, {
1407
1466
  name: 'introBackground',
1408
1467
  type: 'background',
@@ -1558,7 +1617,7 @@ var definition = [{
1558
1617
  isList: true,
1559
1618
  fields: [{
1560
1619
  name: 'buttonsStyle',
1561
- type: 'box-style',
1620
+ type: 'box-style-form',
1562
1621
  label: defineMessage({
1563
1622
  id: "l5uLMd",
1564
1623
  defaultMessage: [{
package/lib/index.js CHANGED
@@ -183,7 +183,6 @@ var Answers = function Answers(_ref) {
183
183
  }
184
184
  }
185
185
  }, [shouldCollapse, answersCollapsed, answersDidCollapsed, setAnswersCollapsed, onCollapsed, onTransitionEnd]);
186
- console.log(items);
187
186
  return /*#__PURE__*/React__default["default"].createElement("div", {
188
187
  className: classNames__default["default"]([styles$4.container, (_ref5 = {}, _defineProperty__default["default"](_ref5, styles$4.answered, answered), _defineProperty__default["default"](_ref5, styles$4.withoutGoodAnswer, withoutGoodAnswer), _defineProperty__default["default"](_ref5, styles$4.withGoodAnswer, !withoutGoodAnswer), _defineProperty__default["default"](_ref5, styles$4.willCollapse, shouldCollapse && answersCollapsed), _defineProperty__default["default"](_ref5, styles$4.didCollapsed, shouldCollapse && answersDidCollapsed), _defineProperty__default["default"](_ref5, styles$4.isPlaceholder, isPlaceholder), _defineProperty__default["default"](_ref5, className, className !== null), _ref5)]),
189
188
  ref: answerRef,
@@ -392,13 +391,13 @@ var Question = function Question(_ref) {
392
391
  placeholder: /*#__PURE__*/React__default["default"].createElement("div", {
393
392
  className: styles$3.index
394
393
  }, "1 / 10")
395
- }, /*#__PURE__*/React__default["default"].createElement(components.Transitions, {
394
+ }, totalCount > 1 ? /*#__PURE__*/React__default["default"].createElement(components.Transitions, {
396
395
  transitions: transitions,
397
396
  playing: transitionPlaying,
398
397
  disabled: transitionDisabled
399
398
  }, /*#__PURE__*/React__default["default"].createElement("div", {
400
399
  className: styles$3.index
401
- }, index + 1, " / ", totalCount))) : null, /*#__PURE__*/React__default["default"].createElement(components.ScreenElement, {
400
+ }, index + 1, " / ", totalCount)) : null) : null, /*#__PURE__*/React__default["default"].createElement(components.ScreenElement, {
402
401
  key: "question",
403
402
  placeholder: "title",
404
403
  emptyLabel: /*#__PURE__*/React__default["default"].createElement(reactIntl.FormattedMessage, {
@@ -659,45 +658,60 @@ var QuizScreen = function QuizScreen(_ref) {
659
658
  QuizScreen.propTypes = propTypes$3;
660
659
  QuizScreen.defaultProps = defaultProps$3;
661
660
 
662
- var styles$1 = {"container":"micromag-screen-quiz-title-container","emptyDescription":"micromag-screen-quiz-title-emptyDescription","emptyTitle":"micromag-screen-quiz-title-emptyTitle","title":"micromag-screen-quiz-title-title","isPlaceholder":"micromag-screen-quiz-title-isPlaceholder"};
661
+ var styles$1 = {"container":"micromag-screen-quiz-title-container","emptyDescription":"micromag-screen-quiz-title-emptyDescription","emptyTitle":"micromag-screen-quiz-title-emptyTitle","description":"micromag-screen-quiz-title-description","title":"micromag-screen-quiz-title-title","isPlaceholder":"micromag-screen-quiz-title-isPlaceholder"};
663
662
 
664
663
  var propTypes$2 = {
665
664
  title: core.PropTypes.textElement,
666
665
  description: core.PropTypes.textElement,
666
+ button: core.PropTypes.textElement,
667
667
  layout: PropTypes__default["default"].string,
668
+ focusable: PropTypes__default["default"].bool,
668
669
  transitions: core.PropTypes.transitions,
669
670
  transitionPlaying: PropTypes__default["default"].bool,
670
671
  transitionStagger: PropTypes__default["default"].number,
671
672
  transitionDisabled: PropTypes__default["default"].bool,
672
673
  className: PropTypes__default["default"].string,
673
- style: PropTypes__default["default"].objectOf(PropTypes__default["default"].oneOfType([PropTypes__default["default"].string, PropTypes__default["default"].number]))
674
+ style: PropTypes__default["default"].objectOf(PropTypes__default["default"].oneOfType([PropTypes__default["default"].string, PropTypes__default["default"].number])),
675
+ onClickButton: PropTypes__default["default"].func
674
676
  };
675
677
  var defaultProps$2 = {
676
678
  title: null,
677
679
  description: null,
678
680
  layout: null,
681
+ button: null,
682
+ focusable: false,
679
683
  transitions: null,
680
684
  transitionPlaying: false,
681
685
  transitionStagger: 100,
682
686
  transitionDisabled: false,
683
687
  className: null,
684
- style: null
688
+ style: null,
689
+ onClickButton: null
685
690
  };
686
691
 
687
692
  var Title = function Title(_ref) {
688
693
  var layout = _ref.layout,
689
694
  title = _ref.title,
690
695
  description = _ref.description,
696
+ button = _ref.button,
697
+ focusable = _ref.focusable,
691
698
  transitions = _ref.transitions,
692
699
  transitionPlaying = _ref.transitionPlaying,
693
700
  transitionStagger = _ref.transitionStagger,
694
701
  transitionDisabled = _ref.transitionDisabled,
695
702
  className = _ref.className,
696
- style = _ref.style;
703
+ style = _ref.style,
704
+ onClickButton = _ref.onClickButton;
705
+
706
+ var _useScreenRenderConte = contexts.useScreenRenderContext(),
707
+ isPreview = _useScreenRenderConte.isPreview,
708
+ isEdit = _useScreenRenderConte.isEdit;
709
+
697
710
  var isSplitted = layout === 'split';
698
711
  var verticalAlign = isSplitted ? null : layout;
699
712
  var hasTitle = utils.isTextFilled(title);
700
713
  var hasDescription = utils.isTextFilled(description);
714
+ var hasButton = utils.isTextFilled(button);
701
715
  return /*#__PURE__*/React__default["default"].createElement(Layout__default["default"], {
702
716
  className: classNames__default["default"]([styles$1.container, _defineProperty__default["default"]({}, className, className !== null)]),
703
717
  fullscreen: true,
@@ -721,9 +735,7 @@ var Title = function Title(_ref) {
721
735
  disabled: transitionDisabled
722
736
  }, /*#__PURE__*/React__default["default"].createElement(Heading__default["default"], Object.assign({}, title, {
723
737
  className: styles$1.title
724
- }))) : null), isSplitted ? /*#__PURE__*/React__default["default"].createElement(Layout.Spacer, {
725
- key: "spacer"
726
- }) : null, /*#__PURE__*/React__default["default"].createElement(components.ScreenElement, {
738
+ }))) : null), /*#__PURE__*/React__default["default"].createElement(components.ScreenElement, {
727
739
  key: "description",
728
740
  placeholder: "text",
729
741
  emptyLabel: /*#__PURE__*/React__default["default"].createElement(reactIntl.FormattedMessage, {
@@ -735,14 +747,38 @@ var Title = function Title(_ref) {
735
747
  }),
736
748
  emptyClassName: styles$1.emptyDescription,
737
749
  isEmpty: !hasDescription
738
- }, hasTitle ? /*#__PURE__*/React__default["default"].createElement(components.Transitions, {
750
+ }, hasDescription ? /*#__PURE__*/React__default["default"].createElement(components.Transitions, {
739
751
  transitions: transitions,
740
752
  playing: transitionPlaying,
741
753
  disabled: transitionDisabled,
742
754
  delay: transitionStagger
743
755
  }, /*#__PURE__*/React__default["default"].createElement(Text__default["default"], Object.assign({}, description, {
744
756
  className: styles$1.description
745
- }))) : null)]);
757
+ }))) : null), isSplitted ? /*#__PURE__*/React__default["default"].createElement(Layout.Spacer, {
758
+ key: "spacer"
759
+ }) : null, /*#__PURE__*/React__default["default"].createElement(components.ScreenElement, {
760
+ key: "button",
761
+ placeholder: "button"
762
+ }, /*#__PURE__*/React__default["default"].createElement(components.Transitions, {
763
+ transitions: transitions,
764
+ playing: transitionPlaying,
765
+ disabled: transitionDisabled,
766
+ delay: transitionStagger * 2
767
+ }, /*#__PURE__*/React__default["default"].createElement(Button__default["default"], {
768
+ disabled: isPreview || isEdit,
769
+ focusable: focusable,
770
+ buttonStyle: button !== null ? button.buttonStyle : null,
771
+ className: styles$1.button,
772
+ onClick: onClickButton
773
+ }, hasButton ? /*#__PURE__*/React__default["default"].createElement(Text__default["default"], Object.assign({}, button, {
774
+ className: styles$1.label
775
+ })) : /*#__PURE__*/React__default["default"].createElement(reactIntl.FormattedMessage, {
776
+ id: "fzeHjj",
777
+ defaultMessage: [{
778
+ "type": 0,
779
+ "value": "Enter"
780
+ }]
781
+ }))))]);
746
782
  };
747
783
 
748
784
  Title.propTypes = propTypes$2;
@@ -856,6 +892,7 @@ var propTypes = {
856
892
  badAnswerColor: core.PropTypes.color,
857
893
  spacing: PropTypes__default["default"].number,
858
894
  background: core.PropTypes.backgroundElement,
895
+ introButton: core.PropTypes.textElement,
859
896
  introBackground: core.PropTypes.backgroundElement,
860
897
  callToAction: core.PropTypes.callToAction,
861
898
  current: PropTypes__default["default"].bool,
@@ -878,6 +915,7 @@ var defaultProps = {
878
915
  badAnswerColor: null,
879
916
  spacing: 20,
880
917
  background: null,
918
+ introButton: null,
881
919
  introBackground: null,
882
920
  callToAction: null,
883
921
  current: true,
@@ -904,6 +942,7 @@ var QuizMultipleScreen = function QuizMultipleScreen(_ref) {
904
942
  spacing = _ref.spacing,
905
943
  background = _ref.background,
906
944
  introBackground = _ref.introBackground,
945
+ introButton = _ref.introButton,
907
946
  callToAction = _ref.callToAction,
908
947
  current = _ref.current,
909
948
  active = _ref.active,
@@ -962,13 +1001,24 @@ var QuizMultipleScreen = function QuizMultipleScreen(_ref) {
962
1001
  userAnswers = _useState2[0],
963
1002
  setUserAnswers = _useState2[1];
964
1003
 
965
- var initialQuestionIndex = stateId === 'questions' ? parseInt(stateIndex, 10) : stateId;
1004
+ var initialQuestionIndex = 'intro';
1005
+
1006
+ if (stateId !== null) {
1007
+ initialQuestionIndex = stateId === 'questions' ? parseInt(stateIndex, 10) : stateId;
1008
+ } else if (isPlaceholder || !hasIntro) {
1009
+ initialQuestionIndex = 0;
1010
+ }
966
1011
 
967
- var _useState3 = React.useState(initialQuestionIndex !== null || !hasIntro || isPlaceholder ? initialQuestionIndex || 0 : 'intro'),
1012
+ var _useState3 = React.useState(initialQuestionIndex),
968
1013
  _useState4 = _slicedToArray__default["default"](_useState3, 2),
969
1014
  questionIndex = _useState4[0],
970
1015
  setQuestionIndex = _useState4[1];
971
1016
 
1017
+ React.useEffect(function () {
1018
+ if (isPreview && hasIntro && questionIndex !== 'intro') {
1019
+ setQuestionIndex('intro');
1020
+ }
1021
+ }, [isPreview, hasIntro, questionIndex, setQuestionIndex]);
972
1022
  var onAnswerClick = React.useCallback(function (answer, answerIndex) {
973
1023
  setUserAnswers(_objectSpread__default["default"](_objectSpread__default["default"]({}, userAnswers), {}, _defineProperty__default["default"]({}, questionIndex, answerIndex)));
974
1024
  trackScreenEvent('click_answer', "Question #".concat(questionIndex + 1, " ").concat(answerIndex + 1, ": ").concat(answer.label.body), {
@@ -988,6 +1038,9 @@ var QuizMultipleScreen = function QuizMultipleScreen(_ref) {
988
1038
  setQuestionIndex('results');
989
1039
  }
990
1040
  }, [questions, questionIndex, setQuestionIndex]);
1041
+ var onClickIntroButton = React.useCallback(function () {
1042
+ setQuestionIndex(0);
1043
+ }, [setQuestionIndex]);
991
1044
  React.useEffect(function () {
992
1045
  if (!current && isEdit && userAnswers !== null) {
993
1046
  setUserAnswers(null);
@@ -1146,6 +1199,8 @@ var QuizMultipleScreen = function QuizMultipleScreen(_ref) {
1146
1199
  title: title,
1147
1200
  description: description,
1148
1201
  layout: introLayout || layout,
1202
+ button: introButton,
1203
+ focusable: current && isView,
1149
1204
  transitions: transitions,
1150
1205
  transitionPlaying: transitionPlaying,
1151
1206
  transitionStagger: transitionStagger,
@@ -1154,7 +1209,8 @@ var QuizMultipleScreen = function QuizMultipleScreen(_ref) {
1154
1209
  style: !isPlaceholder ? {
1155
1210
  padding: spacing,
1156
1211
  paddingTop: (menuOverScreen && !isPreview ? menuSize : 0) + spacing
1157
- } : null
1212
+ } : null,
1213
+ onClickButton: onClickIntroButton
1158
1214
  })) : null, isQuestion ? /*#__PURE__*/React__default["default"].createElement(reactTransitionGroup.CSSTransition, {
1159
1215
  key: "question-".concat(questionIndex),
1160
1216
  classNames: styles$2,
@@ -1297,24 +1353,14 @@ var definition = [{
1297
1353
  }),
1298
1354
  fields: [{
1299
1355
  name: 'buttonsStyle',
1300
- type: 'field-with-form',
1356
+ type: 'box-style-form',
1301
1357
  label: reactIntl.defineMessage({
1302
1358
  id: "l5uLMd",
1303
1359
  defaultMessage: [{
1304
1360
  "type": 0,
1305
1361
  "value": "Buttons"
1306
1362
  }]
1307
- }),
1308
- noValueLabel: reactIntl.defineMessage({
1309
- id: "65rc70",
1310
- defaultMessage: [{
1311
- "type": 0,
1312
- "value": "Edit style..."
1313
- }]
1314
- }),
1315
- field: {
1316
- type: 'box-style'
1317
- }
1363
+ })
1318
1364
  }, {
1319
1365
  name: 'goodAnswerColor',
1320
1366
  type: 'color',
@@ -1424,6 +1470,19 @@ var definition = [{
1424
1470
  "value": "Description"
1425
1471
  }]
1426
1472
  })
1473
+ }, {
1474
+ name: 'introButton',
1475
+ type: 'button-element',
1476
+ theme: {
1477
+ textStyle: 'button'
1478
+ },
1479
+ label: reactIntl.defineMessage({
1480
+ id: "i6bmbD",
1481
+ defaultMessage: [{
1482
+ "type": 0,
1483
+ "value": "Button"
1484
+ }]
1485
+ })
1427
1486
  }, {
1428
1487
  name: 'introBackground',
1429
1488
  type: 'background',
@@ -1579,7 +1638,7 @@ var definition = [{
1579
1638
  isList: true,
1580
1639
  fields: [{
1581
1640
  name: 'buttonsStyle',
1582
- type: 'box-style',
1641
+ type: 'box-style-form',
1583
1642
  label: reactIntl.defineMessage({
1584
1643
  id: "l5uLMd",
1585
1644
  defaultMessage: [{
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@micromag/screen-quiz",
3
- "version": "0.3.4",
3
+ "version": "0.3.9",
4
4
  "description": "",
5
5
  "keywords": [
6
6
  "javascript"
@@ -52,16 +52,16 @@
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.4",
56
- "@micromag/data": "^0.3.4",
57
- "@micromag/element-background": "^0.3.4",
58
- "@micromag/element-button": "^0.3.4",
59
- "@micromag/element-call-to-action": "^0.3.4",
60
- "@micromag/element-container": "^0.3.4",
61
- "@micromag/element-heading": "^0.3.4",
62
- "@micromag/element-layout": "^0.3.4",
63
- "@micromag/element-text": "^0.3.4",
64
- "@micromag/transforms": "^0.3.4",
55
+ "@micromag/core": "^0.3.7",
56
+ "@micromag/data": "^0.3.7",
57
+ "@micromag/element-background": "^0.3.7",
58
+ "@micromag/element-button": "^0.3.7",
59
+ "@micromag/element-call-to-action": "^0.3.7",
60
+ "@micromag/element-container": "^0.3.7",
61
+ "@micromag/element-heading": "^0.3.7",
62
+ "@micromag/element-layout": "^0.3.7",
63
+ "@micromag/element-text": "^0.3.7",
64
+ "@micromag/transforms": "^0.3.7",
65
65
  "classnames": "^2.2.6",
66
66
  "lodash": "^4.17.21",
67
67
  "prop-types": "^15.7.2",
@@ -72,5 +72,5 @@
72
72
  "publishConfig": {
73
73
  "access": "public"
74
74
  },
75
- "gitHead": "a85c206472bc1d8615b6cd756f98a3602b3740f0"
75
+ "gitHead": "aa563abb7ea0ce1692a4191b47260b503dda50c7"
76
76
  }