@micromag/screen-urbania-horoscope 0.3.112 → 0.3.113

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 +42 -25
  2. package/lib/index.js +41 -24
  3. package/package.json +3 -3
package/es/index.js CHANGED
@@ -4,11 +4,12 @@ import _objectSpread from '@babel/runtime/helpers/objectSpread2';
4
4
  import _slicedToArray from '@babel/runtime/helpers/slicedToArray';
5
5
  import classNames from 'classnames';
6
6
  import PropTypes from 'prop-types';
7
- import React, { useCallback, useState, useMemo, useEffect } from 'react';
7
+ import React, { useState, useMemo, useCallback, useEffect } from 'react';
8
8
  import { TransitionGroup, CSSTransition } from 'react-transition-group';
9
9
  import { PropTypes as PropTypes$1 } from '@micromag/core';
10
10
  import { ScreenElement, PlaceholderTitle, TransitionsStagger } from '@micromag/core/components';
11
11
  import { useScreenRenderContext, useScreenState, useScreenSize, useViewer } from '@micromag/core/contexts';
12
+ import { useTrackScreenEvent } from '@micromag/core/hooks';
12
13
  import { isTextFilled } from '@micromag/core/utils';
13
14
  import Background from '@micromag/element-background';
14
15
  import Button from '@micromag/element-button';
@@ -205,8 +206,7 @@ var propTypes$1 = {
205
206
  description: PropTypes$1.textElement
206
207
  })),
207
208
  signSubtitle: PropTypes$1.headingElement,
208
- activeSignId: PropTypes.string,
209
- setActiveSignId: PropTypes.func,
209
+ currentSign: PropTypes.string,
210
210
  width: PropTypes.number,
211
211
  height: PropTypes.number,
212
212
  background: PropTypes$1.backgroundElement,
@@ -214,13 +214,14 @@ var propTypes$1 = {
214
214
  current: PropTypes.bool,
215
215
  active: PropTypes.bool,
216
216
  transitionDisabled: PropTypes.bool,
217
+ onClickSign: PropTypes.func,
218
+ onClickClose: PropTypes.func,
217
219
  className: PropTypes.string
218
220
  };
219
221
  var defaultProps$1 = {
220
222
  signs: null,
221
223
  signSubtitle: null,
222
- activeSignId: null,
223
- setActiveSignId: null,
224
+ currentSign: null,
224
225
  width: null,
225
226
  height: null,
226
227
  background: null,
@@ -228,14 +229,15 @@ var defaultProps$1 = {
228
229
  current: true,
229
230
  active: true,
230
231
  transitionDisabled: false,
232
+ onClickSign: null,
233
+ onClickClose: null,
231
234
  className: null
232
235
  };
233
236
 
234
237
  var SignsGrid = function SignsGrid(_ref) {
235
238
  var signs = _ref.signs,
236
239
  signSubtitle = _ref.signSubtitle,
237
- activeSignId = _ref.activeSignId,
238
- setActiveSignId = _ref.setActiveSignId,
240
+ currentSignId = _ref.currentSign,
239
241
  width = _ref.width,
240
242
  height = _ref.height,
241
243
  background = _ref.background,
@@ -243,16 +245,14 @@ var SignsGrid = function SignsGrid(_ref) {
243
245
  current = _ref.current,
244
246
  active = _ref.active,
245
247
  transitionDisabled = _ref.transitionDisabled,
248
+ onClickSign = _ref.onClickSign,
249
+ onClickClose = _ref.onClickClose,
246
250
  className = _ref.className;
247
- // const [activeSignId, setActiveSignId] = useState(null);
248
- var activeSign = signs.find(function (_ref2) {
251
+ var currentSign = signs.find(function (_ref2) {
249
252
  var _ref2$id = _ref2.id,
250
253
  id = _ref2$id === void 0 ? null : _ref2$id;
251
- return activeSignId === id;
254
+ return currentSignId === id;
252
255
  }) || null;
253
- var closeModal = useCallback(function () {
254
- return setActiveSignId(null);
255
- }, [activeSignId, setActiveSignId]);
256
256
 
257
257
  var _useScreenRenderConte = useScreenRenderContext(),
258
258
  isView = _useScreenRenderConte.isView,
@@ -281,7 +281,7 @@ var SignsGrid = function SignsGrid(_ref) {
281
281
  className: styles$1.closeButton
282
282
  }, /*#__PURE__*/React.createElement(Close, {
283
283
  className: styles$1.close
284
- })) : null, /*#__PURE__*/React.createElement(TransitionGroup, null, !activeSignId ? /*#__PURE__*/React.createElement(CSSTransition, {
284
+ })) : null, /*#__PURE__*/React.createElement(TransitionGroup, null, currentSign === null ? /*#__PURE__*/React.createElement(CSSTransition, {
285
285
  key: "grid",
286
286
  classNames: styles$1,
287
287
  timeout: transitionDisabled ? 0 : 1000
@@ -316,7 +316,9 @@ var SignsGrid = function SignsGrid(_ref) {
316
316
  className: styles$1.gridElement,
317
317
  type: "button",
318
318
  onClick: function onClick() {
319
- return setActiveSignId(id);
319
+ if (onClickSign !== null) {
320
+ onClickSign(id);
321
+ }
320
322
  }
321
323
  }, image !== null ? /*#__PURE__*/React.createElement("img", {
322
324
  className: styles$1.image,
@@ -337,7 +339,7 @@ var SignsGrid = function SignsGrid(_ref) {
337
339
  }, /*#__PURE__*/React.createElement("div", {
338
340
  className: styles$1.modalContainer
339
341
  }, /*#__PURE__*/React.createElement(Button, {
340
- onClick: closeModal,
342
+ onClick: onClickClose,
341
343
  className: styles$1.backButton
342
344
  }, /*#__PURE__*/React.createElement("span", {
343
345
  className: styles$1.arrow
@@ -353,7 +355,7 @@ var SignsGrid = function SignsGrid(_ref) {
353
355
  width: width,
354
356
  height: height,
355
357
  className: styles$1.signModal,
356
- sign: activeSign,
358
+ sign: currentSign,
357
359
  subtitle: signSubtitle,
358
360
  transitionDisabled: transitionDisabled
359
361
  })))))));
@@ -597,6 +599,7 @@ var propTypes = {
597
599
  disableInteraction: PropTypes.func,
598
600
  transitions: PropTypes$1.transitions,
599
601
  transitionStagger: PropTypes.number,
602
+ type: PropTypes.string,
600
603
  className: PropTypes.string
601
604
  };
602
605
  var defaultProps = {
@@ -612,6 +615,7 @@ var defaultProps = {
612
615
  popupBackground: null,
613
616
  current: true,
614
617
  active: true,
618
+ type: 'horoscope',
615
619
  enableInteraction: null,
616
620
  disableInteraction: null,
617
621
  transitions: null,
@@ -638,7 +642,9 @@ var Horoscope = function Horoscope(_ref) {
638
642
  disableInteraction = _ref.disableInteraction,
639
643
  transitions = _ref.transitions,
640
644
  transitionStagger = _ref.transitionStagger,
645
+ type = _ref.type,
641
646
  className = _ref.className;
647
+ var trackScreenEvent = useTrackScreenEvent(type);
642
648
 
643
649
  var _useState = useState(false),
644
650
  _useState2 = _slicedToArray(_useState, 2),
@@ -656,17 +662,27 @@ var Horoscope = function Horoscope(_ref) {
656
662
 
657
663
  var _useState3 = useState(null),
658
664
  _useState4 = _slicedToArray(_useState3, 2),
659
- activeSignId = _useState4[0],
660
- setActiveSignId = _useState4[1];
665
+ currentSign = _useState4[0],
666
+ setCurrentSign = _useState4[1];
661
667
 
662
668
  var openPopup = useCallback(function () {
663
669
  setHasPopup(true);
664
670
  disableInteraction();
665
- }, [hasPopup, setHasPopup, disableInteraction]);
671
+ trackScreenEvent('open');
672
+ }, [hasPopup, setHasPopup, disableInteraction, trackScreenEvent]);
666
673
  var closePopup = useCallback(function () {
667
674
  setHasPopup(false);
668
675
  enableInteraction();
676
+ trackScreenEvent('close');
669
677
  }, [hasPopup, setHasPopup, enableInteraction]);
678
+ var onClickSign = useCallback(function (signId) {
679
+ setCurrentSign(signId);
680
+ trackScreenEvent("open_sign_".concat(signId));
681
+ }, [setCurrentSign, trackScreenEvent]);
682
+ var onClickCloseSign = useCallback(function () {
683
+ setCurrentSign(null);
684
+ trackScreenEvent('close_sign');
685
+ }, [setCurrentSign, trackScreenEvent]);
670
686
  var screenState = useScreenState();
671
687
  useEffect(function () {
672
688
  if (screenState === 'intro') {
@@ -675,13 +691,13 @@ var Horoscope = function Horoscope(_ref) {
675
691
 
676
692
  if (screenState === 'grid') {
677
693
  setHasPopup(true);
678
- setActiveSignId(null);
694
+ setCurrentSign(null);
679
695
  }
680
696
 
681
697
  if (screenState !== null && screenState.includes('signs')) {
682
698
  var index = screenState.split('.').pop();
683
699
  setHasPopup(true);
684
- setActiveSignId(signs[index].id);
700
+ setCurrentSign(signs[index].id);
685
701
  }
686
702
  }, [screenState]);
687
703
 
@@ -790,7 +806,7 @@ var Horoscope = function Horoscope(_ref) {
790
806
  // signs={signs}
791
807
  // signSubtitle={signSubtitle}
792
808
  // activeSignId={activeSignId}
793
- // setActiveSignId={setActiveSignId}
809
+ // setCurrentSign={setCurrentSign}
794
810
  // />
795
811
  // </CSSTransition>
796
812
  // ) : null}
@@ -838,8 +854,9 @@ var Horoscope = function Horoscope(_ref) {
838
854
  background: popupBackground,
839
855
  signs: signs,
840
856
  signSubtitle: signSubtitle,
841
- activeSignId: activeSignId,
842
- setActiveSignId: setActiveSignId,
857
+ currentSign: currentSign,
858
+ onClickSign: onClickSign,
859
+ onClickClose: onClickCloseSign,
843
860
  transitionDisabled: transitionDisabled
844
861
  })) : null))));
845
862
  };
package/lib/index.js CHANGED
@@ -13,6 +13,7 @@ var reactTransitionGroup = require('react-transition-group');
13
13
  var core = require('@micromag/core');
14
14
  var components = require('@micromag/core/components');
15
15
  var contexts = require('@micromag/core/contexts');
16
+ var hooks = require('@micromag/core/hooks');
16
17
  var utils = require('@micromag/core/utils');
17
18
  var Background = require('@micromag/element-background');
18
19
  var Button = require('@micromag/element-button');
@@ -239,8 +240,7 @@ var propTypes$1 = {
239
240
  description: core.PropTypes.textElement
240
241
  })),
241
242
  signSubtitle: core.PropTypes.headingElement,
242
- activeSignId: PropTypes__default["default"].string,
243
- setActiveSignId: PropTypes__default["default"].func,
243
+ currentSign: PropTypes__default["default"].string,
244
244
  width: PropTypes__default["default"].number,
245
245
  height: PropTypes__default["default"].number,
246
246
  background: core.PropTypes.backgroundElement,
@@ -248,13 +248,14 @@ var propTypes$1 = {
248
248
  current: PropTypes__default["default"].bool,
249
249
  active: PropTypes__default["default"].bool,
250
250
  transitionDisabled: PropTypes__default["default"].bool,
251
+ onClickSign: PropTypes__default["default"].func,
252
+ onClickClose: PropTypes__default["default"].func,
251
253
  className: PropTypes__default["default"].string
252
254
  };
253
255
  var defaultProps$1 = {
254
256
  signs: null,
255
257
  signSubtitle: null,
256
- activeSignId: null,
257
- setActiveSignId: null,
258
+ currentSign: null,
258
259
  width: null,
259
260
  height: null,
260
261
  background: null,
@@ -262,14 +263,15 @@ var defaultProps$1 = {
262
263
  current: true,
263
264
  active: true,
264
265
  transitionDisabled: false,
266
+ onClickSign: null,
267
+ onClickClose: null,
265
268
  className: null
266
269
  };
267
270
 
268
271
  var SignsGrid = function SignsGrid(_ref) {
269
272
  var signs = _ref.signs,
270
273
  signSubtitle = _ref.signSubtitle,
271
- activeSignId = _ref.activeSignId,
272
- setActiveSignId = _ref.setActiveSignId,
274
+ currentSignId = _ref.currentSign,
273
275
  width = _ref.width,
274
276
  height = _ref.height,
275
277
  background = _ref.background,
@@ -277,16 +279,14 @@ var SignsGrid = function SignsGrid(_ref) {
277
279
  current = _ref.current,
278
280
  active = _ref.active,
279
281
  transitionDisabled = _ref.transitionDisabled,
282
+ onClickSign = _ref.onClickSign,
283
+ onClickClose = _ref.onClickClose,
280
284
  className = _ref.className;
281
- // const [activeSignId, setActiveSignId] = useState(null);
282
- var activeSign = signs.find(function (_ref2) {
285
+ var currentSign = signs.find(function (_ref2) {
283
286
  var _ref2$id = _ref2.id,
284
287
  id = _ref2$id === void 0 ? null : _ref2$id;
285
- return activeSignId === id;
288
+ return currentSignId === id;
286
289
  }) || null;
287
- var closeModal = React.useCallback(function () {
288
- return setActiveSignId(null);
289
- }, [activeSignId, setActiveSignId]);
290
290
 
291
291
  var _useScreenRenderConte = contexts.useScreenRenderContext(),
292
292
  isView = _useScreenRenderConte.isView,
@@ -315,7 +315,7 @@ var SignsGrid = function SignsGrid(_ref) {
315
315
  className: styles$1.closeButton
316
316
  }, /*#__PURE__*/React__default["default"].createElement(Close, {
317
317
  className: styles$1.close
318
- })) : null, /*#__PURE__*/React__default["default"].createElement(reactTransitionGroup.TransitionGroup, null, !activeSignId ? /*#__PURE__*/React__default["default"].createElement(reactTransitionGroup.CSSTransition, {
318
+ })) : null, /*#__PURE__*/React__default["default"].createElement(reactTransitionGroup.TransitionGroup, null, currentSign === null ? /*#__PURE__*/React__default["default"].createElement(reactTransitionGroup.CSSTransition, {
319
319
  key: "grid",
320
320
  classNames: styles$1,
321
321
  timeout: transitionDisabled ? 0 : 1000
@@ -350,7 +350,9 @@ var SignsGrid = function SignsGrid(_ref) {
350
350
  className: styles$1.gridElement,
351
351
  type: "button",
352
352
  onClick: function onClick() {
353
- return setActiveSignId(id);
353
+ if (onClickSign !== null) {
354
+ onClickSign(id);
355
+ }
354
356
  }
355
357
  }, image !== null ? /*#__PURE__*/React__default["default"].createElement("img", {
356
358
  className: styles$1.image,
@@ -371,7 +373,7 @@ var SignsGrid = function SignsGrid(_ref) {
371
373
  }, /*#__PURE__*/React__default["default"].createElement("div", {
372
374
  className: styles$1.modalContainer
373
375
  }, /*#__PURE__*/React__default["default"].createElement(Button__default["default"], {
374
- onClick: closeModal,
376
+ onClick: onClickClose,
375
377
  className: styles$1.backButton
376
378
  }, /*#__PURE__*/React__default["default"].createElement("span", {
377
379
  className: styles$1.arrow
@@ -387,7 +389,7 @@ var SignsGrid = function SignsGrid(_ref) {
387
389
  width: width,
388
390
  height: height,
389
391
  className: styles$1.signModal,
390
- sign: activeSign,
392
+ sign: currentSign,
391
393
  subtitle: signSubtitle,
392
394
  transitionDisabled: transitionDisabled
393
395
  })))))));
@@ -631,6 +633,7 @@ var propTypes = {
631
633
  disableInteraction: PropTypes__default["default"].func,
632
634
  transitions: core.PropTypes.transitions,
633
635
  transitionStagger: PropTypes__default["default"].number,
636
+ type: PropTypes__default["default"].string,
634
637
  className: PropTypes__default["default"].string
635
638
  };
636
639
  var defaultProps = {
@@ -646,6 +649,7 @@ var defaultProps = {
646
649
  popupBackground: null,
647
650
  current: true,
648
651
  active: true,
652
+ type: 'horoscope',
649
653
  enableInteraction: null,
650
654
  disableInteraction: null,
651
655
  transitions: null,
@@ -672,7 +676,9 @@ var Horoscope = function Horoscope(_ref) {
672
676
  disableInteraction = _ref.disableInteraction,
673
677
  transitions = _ref.transitions,
674
678
  transitionStagger = _ref.transitionStagger,
679
+ type = _ref.type,
675
680
  className = _ref.className;
681
+ var trackScreenEvent = hooks.useTrackScreenEvent(type);
676
682
 
677
683
  var _useState = React.useState(false),
678
684
  _useState2 = _slicedToArray__default["default"](_useState, 2),
@@ -690,17 +696,27 @@ var Horoscope = function Horoscope(_ref) {
690
696
 
691
697
  var _useState3 = React.useState(null),
692
698
  _useState4 = _slicedToArray__default["default"](_useState3, 2),
693
- activeSignId = _useState4[0],
694
- setActiveSignId = _useState4[1];
699
+ currentSign = _useState4[0],
700
+ setCurrentSign = _useState4[1];
695
701
 
696
702
  var openPopup = React.useCallback(function () {
697
703
  setHasPopup(true);
698
704
  disableInteraction();
699
- }, [hasPopup, setHasPopup, disableInteraction]);
705
+ trackScreenEvent('open');
706
+ }, [hasPopup, setHasPopup, disableInteraction, trackScreenEvent]);
700
707
  var closePopup = React.useCallback(function () {
701
708
  setHasPopup(false);
702
709
  enableInteraction();
710
+ trackScreenEvent('close');
703
711
  }, [hasPopup, setHasPopup, enableInteraction]);
712
+ var onClickSign = React.useCallback(function (signId) {
713
+ setCurrentSign(signId);
714
+ trackScreenEvent("open_sign_".concat(signId));
715
+ }, [setCurrentSign, trackScreenEvent]);
716
+ var onClickCloseSign = React.useCallback(function () {
717
+ setCurrentSign(null);
718
+ trackScreenEvent('close_sign');
719
+ }, [setCurrentSign, trackScreenEvent]);
704
720
  var screenState = contexts.useScreenState();
705
721
  React.useEffect(function () {
706
722
  if (screenState === 'intro') {
@@ -709,13 +725,13 @@ var Horoscope = function Horoscope(_ref) {
709
725
 
710
726
  if (screenState === 'grid') {
711
727
  setHasPopup(true);
712
- setActiveSignId(null);
728
+ setCurrentSign(null);
713
729
  }
714
730
 
715
731
  if (screenState !== null && screenState.includes('signs')) {
716
732
  var index = screenState.split('.').pop();
717
733
  setHasPopup(true);
718
- setActiveSignId(signs[index].id);
734
+ setCurrentSign(signs[index].id);
719
735
  }
720
736
  }, [screenState]);
721
737
 
@@ -824,7 +840,7 @@ var Horoscope = function Horoscope(_ref) {
824
840
  // signs={signs}
825
841
  // signSubtitle={signSubtitle}
826
842
  // activeSignId={activeSignId}
827
- // setActiveSignId={setActiveSignId}
843
+ // setCurrentSign={setCurrentSign}
828
844
  // />
829
845
  // </CSSTransition>
830
846
  // ) : null}
@@ -872,8 +888,9 @@ var Horoscope = function Horoscope(_ref) {
872
888
  background: popupBackground,
873
889
  signs: signs,
874
890
  signSubtitle: signSubtitle,
875
- activeSignId: activeSignId,
876
- setActiveSignId: setActiveSignId,
891
+ currentSign: currentSign,
892
+ onClickSign: onClickSign,
893
+ onClickClose: onClickCloseSign,
877
894
  transitionDisabled: transitionDisabled
878
895
  })) : null))));
879
896
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@micromag/screen-urbania-horoscope",
3
- "version": "0.3.112",
3
+ "version": "0.3.113",
4
4
  "description": "",
5
5
  "keywords": [
6
6
  "javascript"
@@ -53,7 +53,7 @@
53
53
  "@micromag/core": "^0.3.112",
54
54
  "@micromag/element-background": "^0.3.112",
55
55
  "@micromag/element-button": "^0.3.112",
56
- "@micromag/element-call-to-action": "^0.3.112",
56
+ "@micromag/element-call-to-action": "^0.3.113",
57
57
  "@micromag/element-container": "^0.3.112",
58
58
  "@micromag/element-grid": "^0.3.112",
59
59
  "@micromag/element-heading": "^0.3.112",
@@ -72,5 +72,5 @@
72
72
  "publishConfig": {
73
73
  "access": "public"
74
74
  },
75
- "gitHead": "f85362071b76115397f9a77537ac6e66b91f59f3"
75
+ "gitHead": "4c6a28244ace23a23cfe3a61429c79afb04750ca"
76
76
  }