@micromag/element-call-to-action 0.3.98 → 0.3.105

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 +1 @@
1
- @-webkit-keyframes micromag-element-call-to-action-appear{0%{-webkit-transform:scale(0);transform:scale(0);opacity:1}to{-webkit-transform:scale(1);transform:scale(1);opacity:1}}@keyframes micromag-element-call-to-action-appear{0%{-webkit-transform:scale(0);transform:scale(0);opacity:1}to{-webkit-transform:scale(1);transform:scale(1);opacity:1}}.micromag-element-call-to-action-container{position:relative;z-index:100;padding-bottom:5px;-webkit-transition:opacity .3s ease;-o-transition:opacity .3s ease;transition:opacity .3s ease;opacity:1;text-align:center}.micromag-element-call-to-action-container .micromag-element-call-to-action-arrow{display:block;margin:0 auto 3px;-webkit-animation:micromag-element-call-to-action-upAndDown .5s ease-in-out infinite alternate;animation:micromag-element-call-to-action-upAndDown .5s ease-in-out infinite alternate}.micromag-element-call-to-action-container .micromag-element-call-to-action-icon,.micromag-element-call-to-action-container .micromag-element-call-to-action-label{display:inline-block}.micromag-element-call-to-action-container .micromag-element-call-to-action-label{line-height:1}.micromag-element-call-to-action-container .micromag-element-call-to-action-button{display:block;margin:0 auto;padding:5px 10px;background-color:rgba(0,0,0,0);-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none;-ms-touch-action:none;touch-action:none;-webkit-user-drag:none}.micromag-element-call-to-action-container .micromag-element-call-to-action-button:hover{text-decoration:none}.micromag-element-call-to-action-container .micromag-element-call-to-action-selfTargetLink{display:none}.micromag-element-call-to-action-container .micromag-element-call-to-action-leavingFrame{position:fixed;top:0;left:0;width:100vw;height:100vh;-webkit-transform:scale(0);-ms-transform:scale(0);transform:scale(0);-webkit-animation:micromag-element-call-to-action-appear .5s ease both;animation:micromag-element-call-to-action-appear .5s ease both;opacity:0;background-color:#fff}.micromag-element-call-to-action-container.micromag-element-call-to-action-animationDisabled .micromag-element-call-to-action-arrow{-webkit-animation:none;animation:none}.micromag-element-call-to-action-container.micromag-element-call-to-action-invalidUrl{opacity:.5;pointer-events:none}.micromag-element-call-to-action-container.micromag-element-call-to-action-invalidUrl .micromag-element-call-to-action-arrow{-webkit-animation:none;animation:none}.micromag-element-call-to-action-container.micromag-element-call-to-action-disabled{opacity:0;pointer-events:none}.micromag-element-call-to-action-container.micromag-element-call-to-action-inWebView{width:100%}.micromag-element-call-to-action-container.micromag-element-call-to-action-withMargin{margin-bottom:5px}.micromag-element-call-to-action-webView{position:absolute;z-index:9999;top:100%;width:100%;height:100%;-webkit-transition:-webkit-transform .3s ease;transition:-webkit-transform .3s ease;-o-transition:transform .3s ease;transition:transform .3s ease;transition:transform .3s ease, -webkit-transform .3s ease}.micromag-element-call-to-action-webView.micromag-element-call-to-action-visible{-webkit-transform:translateY(-100%);-ms-transform:translateY(-100%);transform:translateY(-100%)}@-webkit-keyframes micromag-element-call-to-action-upAndDown{0%{-webkit-transform:translateY(0);transform:translateY(0)}to{-webkit-transform:translateY(-20%);transform:translateY(-20%)}}@keyframes micromag-element-call-to-action-upAndDown{0%{-webkit-transform:translateY(0);transform:translateY(0)}to{-webkit-transform:translateY(-20%);transform:translateY(-20%)}}
1
+ @-webkit-keyframes micromag-element-call-to-action-appear{0%{-webkit-transform:scale(0);transform:scale(0);opacity:1}to{-webkit-transform:scale(1);transform:scale(1);opacity:1}}@keyframes micromag-element-call-to-action-appear{0%{-webkit-transform:scale(0);transform:scale(0);opacity:1}to{-webkit-transform:scale(1);transform:scale(1);opacity:1}}.micromag-element-call-to-action-container{position:relative;z-index:100;padding-bottom:5px;-webkit-transition:opacity .3s ease;-o-transition:opacity .3s ease;transition:opacity .3s ease;opacity:1;text-align:center}.micromag-element-call-to-action-container .micromag-element-call-to-action-arrow{display:block;margin:0 auto 3px;-webkit-animation:micromag-element-call-to-action-upAndDown .5s ease-in-out infinite alternate;animation:micromag-element-call-to-action-upAndDown .5s ease-in-out infinite alternate}.micromag-element-call-to-action-container .micromag-element-call-to-action-icon,.micromag-element-call-to-action-container .micromag-element-call-to-action-label{display:inline-block;vertical-align:middle}.micromag-element-call-to-action-container .micromag-element-call-to-action-label{line-height:1}.micromag-element-call-to-action-container .micromag-element-call-to-action-button{display:block;margin:0 auto;padding:5px 10px;background-color:rgba(0,0,0,0);-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none;-ms-touch-action:none;touch-action:none;-webkit-user-drag:none}.micromag-element-call-to-action-container .micromag-element-call-to-action-button:hover{text-decoration:none}.micromag-element-call-to-action-container .micromag-element-call-to-action-selfTargetLink{display:none}.micromag-element-call-to-action-container .micromag-element-call-to-action-leavingFrame{position:fixed;top:0;left:0;width:100vw;height:100vh;-webkit-transform:scale(0);-ms-transform:scale(0);transform:scale(0);-webkit-animation:micromag-element-call-to-action-appear .5s ease both;animation:micromag-element-call-to-action-appear .5s ease both;opacity:0;background-color:#fff}.micromag-element-call-to-action-container.micromag-element-call-to-action-animationDisabled .micromag-element-call-to-action-arrow{-webkit-animation:none;animation:none}.micromag-element-call-to-action-container.micromag-element-call-to-action-invalidUrl{opacity:.5;pointer-events:none}.micromag-element-call-to-action-container.micromag-element-call-to-action-invalidUrl .micromag-element-call-to-action-arrow{-webkit-animation:none;animation:none}.micromag-element-call-to-action-container.micromag-element-call-to-action-disabled{opacity:0;pointer-events:none}.micromag-element-call-to-action-container.micromag-element-call-to-action-inWebView{width:100%}.micromag-element-call-to-action-container.micromag-element-call-to-action-withMargin{margin-bottom:5px}.micromag-element-call-to-action-webView{position:absolute;z-index:9999;top:100%;width:100%;height:100%;-webkit-transition:-webkit-transform .3s ease;transition:-webkit-transform .3s ease;-o-transition:transform .3s ease;transition:transform .3s ease;transition:transform .3s ease, -webkit-transform .3s ease}.micromag-element-call-to-action-webView.micromag-element-call-to-action-visible{-webkit-transform:translateY(-100%);-ms-transform:translateY(-100%);transform:translateY(-100%)}@-webkit-keyframes micromag-element-call-to-action-upAndDown{0%{-webkit-transform:translateY(0);transform:translateY(0)}to{-webkit-transform:translateY(-20%);transform:translateY(-20%)}}@keyframes micromag-element-call-to-action-upAndDown{0%{-webkit-transform:translateY(0);transform:translateY(0)}to{-webkit-transform:translateY(-20%);transform:translateY(-20%)}}
package/es/index.js CHANGED
@@ -4,8 +4,9 @@ import _slicedToArray from '@babel/runtime/helpers/slicedToArray';
4
4
  import { useGesture } from '@use-gesture/react';
5
5
  import classNames from 'classnames';
6
6
  import PropTypes from 'prop-types';
7
- import React, { useState, useMemo, useRef, useEffect, useCallback } from 'react';
7
+ import React, { useState, useMemo, useRef, useCallback, useEffect } from 'react';
8
8
  import { PropTypes as PropTypes$1 } from '@micromag/core';
9
+ import { useTrackEvent } from '@micromag/core/hooks';
9
10
  import { isValidUrl, getStyleFromColor, isIos } from '@micromag/core/utils';
10
11
  import Button from '@micromag/element-button';
11
12
  import Text from '@micromag/element-text';
@@ -74,7 +75,8 @@ var propTypes = {
74
75
  arrowClassName: PropTypes.string,
75
76
  focusable: PropTypes.bool,
76
77
  enableInteraction: PropTypes.func,
77
- disableInteraction: PropTypes.func
78
+ disableInteraction: PropTypes.func,
79
+ onClick: PropTypes.func
78
80
  };
79
81
  var defaultProps = {
80
82
  elRef: null,
@@ -92,7 +94,8 @@ var defaultProps = {
92
94
  arrowClassName: null,
93
95
  focusable: true,
94
96
  enableInteraction: null,
95
- disableInteraction: null
97
+ disableInteraction: null,
98
+ onClick: null
96
99
  };
97
100
 
98
101
  function CallToAction(_ref) {
@@ -113,7 +116,8 @@ function CallToAction(_ref) {
113
116
  arrowClassName = _ref.arrowClassName,
114
117
  focusable = _ref.focusable,
115
118
  enableInteraction = _ref.enableInteraction,
116
- disableInteraction = _ref.disableInteraction;
119
+ disableInteraction = _ref.disableInteraction,
120
+ onClick = _ref.onClick;
117
121
 
118
122
  var _ref2 = callToAction || {},
119
123
  _ref2$active = _ref2.active,
@@ -129,6 +133,8 @@ function CallToAction(_ref) {
129
133
  _ref2$inWebView = _ref2.inWebView,
130
134
  inWebView = _ref2$inWebView === void 0 ? false : _ref2$inWebView;
131
135
 
136
+ var trackEvent = useTrackEvent();
137
+
132
138
  var _useState = useState(false),
133
139
  _useState2 = _slicedToArray(_useState, 2),
134
140
  showWebView = _useState2[0],
@@ -172,8 +178,25 @@ function CallToAction(_ref) {
172
178
  var _useState5 = useState(false),
173
179
  _useState6 = _slicedToArray(_useState5, 2),
174
180
  leaving = _useState6[0],
175
- setLeaving = _useState6[1];
181
+ setLeaving = _useState6[1]; // On click
182
+
183
+
184
+ var onClickLink = useCallback(function () {
185
+ var action = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'click';
186
+
187
+ if (trackEvent !== null) {
188
+ trackEvent('call_to_action', action, url);
189
+ }
176
190
 
191
+ if (onClick !== null) {
192
+ onClick();
193
+ }
194
+ }, [url, onClick, trackEvent]);
195
+ var onClickClose = useCallback(function () {
196
+ if (trackEvent !== null) {
197
+ trackEvent('call_to_action', 'close', url);
198
+ }
199
+ }, [url, trackEvent]);
177
200
  var bind = useGesture({
178
201
  onDrag: function onDrag(_ref6) {
179
202
  var event = _ref6.event;
@@ -188,11 +211,14 @@ function CallToAction(_ref) {
188
211
  if (inWebView) {
189
212
  setShowWebView(true);
190
213
  setDisabledWebView(false);
214
+ onClickLink('swipe');
191
215
  } else if (isIos() && selfTargetLinkRef.current !== null) {
192
216
  selfTargetLinkRef.current.click();
193
217
  setLeaving(true);
218
+ onClickLink('swipe');
194
219
  } else if (buttonRef.current) {
195
220
  buttonRef.current.click();
221
+ onClickLink('swipe');
196
222
  }
197
223
  }
198
224
  }
@@ -231,14 +257,18 @@ function CallToAction(_ref) {
231
257
  if (disableInteraction !== null) {
232
258
  disableInteraction();
233
259
  }
234
- }, [setShowWebView, setDisabledWebView, disableInteraction]);
260
+
261
+ onClickLink('click');
262
+ }, [setShowWebView, setDisabledWebView, disableInteraction, onClickLink]);
235
263
  var onCloseWebView = useCallback(function () {
236
264
  setShowWebView(false);
237
265
 
238
266
  if (enableInteraction !== null) {
239
267
  enableInteraction();
240
268
  }
241
- }, [setShowWebView, enableInteraction]);
269
+
270
+ onClickClose();
271
+ }, [setShowWebView, enableInteraction, onClickClose]);
242
272
  var ArrowElement = arrow !== null ? /*#__PURE__*/React.createElement("div", {
243
273
  className: classNames([styles.arrow, _defineProperty({}, arrowClassName, arrowClassName !== null)]),
244
274
  style: arrowStyle
@@ -270,7 +300,8 @@ function CallToAction(_ref) {
270
300
  onClick: onOpenWebView
271
301
  } : {
272
302
  href: url,
273
- external: true
303
+ external: true,
304
+ onClick: onClickLink
274
305
  }), /*#__PURE__*/React.createElement("span", {
275
306
  className: classNames([styles.label, _defineProperty({}, labelClassName, labelClassName !== null)])
276
307
  }, icon !== null ? /*#__PURE__*/React.createElement("div", {
package/lib/index.js CHANGED
@@ -8,6 +8,7 @@ var classNames = require('classnames');
8
8
  var PropTypes = require('prop-types');
9
9
  var React = require('react');
10
10
  var core = require('@micromag/core');
11
+ var hooks = require('@micromag/core/hooks');
11
12
  var utils = require('@micromag/core/utils');
12
13
  var Button = require('@micromag/element-button');
13
14
  var Text = require('@micromag/element-text');
@@ -88,7 +89,8 @@ var propTypes = {
88
89
  arrowClassName: PropTypes__default["default"].string,
89
90
  focusable: PropTypes__default["default"].bool,
90
91
  enableInteraction: PropTypes__default["default"].func,
91
- disableInteraction: PropTypes__default["default"].func
92
+ disableInteraction: PropTypes__default["default"].func,
93
+ onClick: PropTypes__default["default"].func
92
94
  };
93
95
  var defaultProps = {
94
96
  elRef: null,
@@ -106,7 +108,8 @@ var defaultProps = {
106
108
  arrowClassName: null,
107
109
  focusable: true,
108
110
  enableInteraction: null,
109
- disableInteraction: null
111
+ disableInteraction: null,
112
+ onClick: null
110
113
  };
111
114
 
112
115
  function CallToAction(_ref) {
@@ -127,7 +130,8 @@ function CallToAction(_ref) {
127
130
  arrowClassName = _ref.arrowClassName,
128
131
  focusable = _ref.focusable,
129
132
  enableInteraction = _ref.enableInteraction,
130
- disableInteraction = _ref.disableInteraction;
133
+ disableInteraction = _ref.disableInteraction,
134
+ onClick = _ref.onClick;
131
135
 
132
136
  var _ref2 = callToAction || {},
133
137
  _ref2$active = _ref2.active,
@@ -143,6 +147,8 @@ function CallToAction(_ref) {
143
147
  _ref2$inWebView = _ref2.inWebView,
144
148
  inWebView = _ref2$inWebView === void 0 ? false : _ref2$inWebView;
145
149
 
150
+ var trackEvent = hooks.useTrackEvent();
151
+
146
152
  var _useState = React.useState(false),
147
153
  _useState2 = _slicedToArray__default["default"](_useState, 2),
148
154
  showWebView = _useState2[0],
@@ -186,8 +192,25 @@ function CallToAction(_ref) {
186
192
  var _useState5 = React.useState(false),
187
193
  _useState6 = _slicedToArray__default["default"](_useState5, 2),
188
194
  leaving = _useState6[0],
189
- setLeaving = _useState6[1];
195
+ setLeaving = _useState6[1]; // On click
196
+
197
+
198
+ var onClickLink = React.useCallback(function () {
199
+ var action = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'click';
200
+
201
+ if (trackEvent !== null) {
202
+ trackEvent('call_to_action', action, url);
203
+ }
190
204
 
205
+ if (onClick !== null) {
206
+ onClick();
207
+ }
208
+ }, [url, onClick, trackEvent]);
209
+ var onClickClose = React.useCallback(function () {
210
+ if (trackEvent !== null) {
211
+ trackEvent('call_to_action', 'close', url);
212
+ }
213
+ }, [url, trackEvent]);
191
214
  var bind = react.useGesture({
192
215
  onDrag: function onDrag(_ref6) {
193
216
  var event = _ref6.event;
@@ -202,11 +225,14 @@ function CallToAction(_ref) {
202
225
  if (inWebView) {
203
226
  setShowWebView(true);
204
227
  setDisabledWebView(false);
228
+ onClickLink('swipe');
205
229
  } else if (utils.isIos() && selfTargetLinkRef.current !== null) {
206
230
  selfTargetLinkRef.current.click();
207
231
  setLeaving(true);
232
+ onClickLink('swipe');
208
233
  } else if (buttonRef.current) {
209
234
  buttonRef.current.click();
235
+ onClickLink('swipe');
210
236
  }
211
237
  }
212
238
  }
@@ -245,14 +271,18 @@ function CallToAction(_ref) {
245
271
  if (disableInteraction !== null) {
246
272
  disableInteraction();
247
273
  }
248
- }, [setShowWebView, setDisabledWebView, disableInteraction]);
274
+
275
+ onClickLink('click');
276
+ }, [setShowWebView, setDisabledWebView, disableInteraction, onClickLink]);
249
277
  var onCloseWebView = React.useCallback(function () {
250
278
  setShowWebView(false);
251
279
 
252
280
  if (enableInteraction !== null) {
253
281
  enableInteraction();
254
282
  }
255
- }, [setShowWebView, enableInteraction]);
283
+
284
+ onClickClose();
285
+ }, [setShowWebView, enableInteraction, onClickClose]);
256
286
  var ArrowElement = arrow !== null ? /*#__PURE__*/React__default["default"].createElement("div", {
257
287
  className: classNames__default["default"]([styles.arrow, _defineProperty__default["default"]({}, arrowClassName, arrowClassName !== null)]),
258
288
  style: arrowStyle
@@ -284,7 +314,8 @@ function CallToAction(_ref) {
284
314
  onClick: onOpenWebView
285
315
  } : {
286
316
  href: url,
287
- external: true
317
+ external: true,
318
+ onClick: onClickLink
288
319
  }), /*#__PURE__*/React__default["default"].createElement("span", {
289
320
  className: classNames__default["default"]([styles.label, _defineProperty__default["default"]({}, labelClassName, labelClassName !== null)])
290
321
  }, icon !== null ? /*#__PURE__*/React__default["default"].createElement("div", {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@micromag/element-call-to-action",
3
- "version": "0.3.98",
3
+ "version": "0.3.105",
4
4
  "description": "",
5
5
  "keywords": [
6
6
  "javascript"
@@ -40,22 +40,22 @@
40
40
  "prepare": "../../scripts/prepare-package.sh"
41
41
  },
42
42
  "devDependencies": {
43
- "react": "^16.8.0 || ^17.0.0",
44
- "react-dom": "^16.8.0 || ^17.0.0"
43
+ "react": "^16.8.0 || ^17.0.0 || ^18.0.0",
44
+ "react-dom": "^16.8.0 || ^17.0.0 || ^18.0.0"
45
45
  },
46
46
  "peerDependencies": {
47
- "react": "^16.8.0 || ^17.0.0",
48
- "react-dom": "^16.8.0 || ^17.0.0"
47
+ "react": "^16.8.0 || ^17.0.0 || ^18.0.0",
48
+ "react-dom": "^16.8.0 || ^17.0.0 || ^18.0.0"
49
49
  },
50
50
  "dependencies": {
51
51
  "@babel/runtime": "^7.13.10",
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.91",
56
- "@micromag/element-button": "^0.3.91",
57
- "@micromag/element-text": "^0.3.91",
58
- "@micromag/element-webview": "^0.3.98",
55
+ "@micromag/core": "^0.3.105",
56
+ "@micromag/element-button": "^0.3.105",
57
+ "@micromag/element-text": "^0.3.105",
58
+ "@micromag/element-webview": "^0.3.105",
59
59
  "@react-spring/core": "^9.1.1",
60
60
  "@react-spring/web": "^9.1.1",
61
61
  "@use-gesture/react": "^10.2.4",
@@ -68,5 +68,5 @@
68
68
  "publishConfig": {
69
69
  "access": "public"
70
70
  },
71
- "gitHead": "240a044625270e640a9df457eaf6c3b1edf3466e"
71
+ "gitHead": "fb6c28846c08f30c035ebbc162a4135b8b4d42a5"
72
72
  }