@micromag/element-call-to-action 0.3.541 → 0.3.547

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.
package/es/index.js CHANGED
@@ -48,7 +48,6 @@ var Arrow = function Arrow(_ref) {
48
48
  };
49
49
  Arrow.propTypes = propTypes$1;
50
50
  Arrow.defaultProps = defaultProps$1;
51
- var ArrowIcon = Arrow;
52
51
 
53
52
  var styles = {"container":"micromag-element-call-to-action-container","arrow":"micromag-element-call-to-action-arrow","upAndDown":"micromag-element-call-to-action-upAndDown","icon":"micromag-element-call-to-action-icon","label":"micromag-element-call-to-action-label","button":"micromag-element-call-to-action-button","selfTargetLink":"micromag-element-call-to-action-selfTargetLink","leavingFrame":"micromag-element-call-to-action-leavingFrame","appear":"micromag-element-call-to-action-appear","animationDisabled":"micromag-element-call-to-action-animationDisabled","invalidUrl":"micromag-element-call-to-action-invalidUrl","withMargin":"micromag-element-call-to-action-withMargin"};
54
53
 
@@ -215,7 +214,7 @@ function CallToAction(_ref) {
215
214
  }) : null, swipeUpEnabled ? /*#__PURE__*/React.createElement("div", {
216
215
  className: classNames([styles.arrow, _defineProperty({}, arrowClassName, arrowClassName !== null)]),
217
216
  style: arrowStyle
218
- }, arrow || /*#__PURE__*/React.createElement(ArrowIcon, null)) : null, /*#__PURE__*/React.createElement("div", {
217
+ }, arrow || /*#__PURE__*/React.createElement(Arrow, null)) : null, /*#__PURE__*/React.createElement("div", {
219
218
  className: classNames([styles.buttonBorder, _defineProperty({}, buttonBorderClassName, buttonBorderClassName !== null)])
220
219
  }, /*#__PURE__*/React.createElement(Button, Object.assign({
221
220
  className: classNames([styles.button, _defineProperty({}, buttonClassName, buttonClassName !== null)]),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@micromag/element-call-to-action",
3
- "version": "0.3.541",
3
+ "version": "0.3.547",
4
4
  "private": false,
5
5
  "description": "",
6
6
  "keywords": [
@@ -30,11 +30,10 @@
30
30
  }
31
31
  ],
32
32
  "license": "ISC",
33
- "main": "lib/index.js",
33
+ "type": "module",
34
34
  "module": "es/index.js",
35
35
  "exports": {
36
36
  ".": {
37
- "require": "./lib/index.js",
38
37
  "import": "./es/index.js"
39
38
  },
40
39
  "./assets/css/styles": "./assets/css/styles.css",
@@ -63,10 +62,10 @@
63
62
  "@fortawesome/fontawesome-svg-core": "^6.5.2",
64
63
  "@fortawesome/free-solid-svg-icons": "^6.5.2",
65
64
  "@fortawesome/react-fontawesome": "^0.2.0",
66
- "@micromag/core": "^0.3.541",
67
- "@micromag/element-button": "^0.3.541",
68
- "@micromag/element-text": "^0.3.541",
69
- "@micromag/element-webview": "^0.3.541",
65
+ "@micromag/core": "^0.3.547",
66
+ "@micromag/element-button": "^0.3.547",
67
+ "@micromag/element-text": "^0.3.547",
68
+ "@micromag/element-webview": "^0.3.547",
70
69
  "@react-spring/core": "^9.6.1",
71
70
  "@react-spring/web": "^9.6.1",
72
71
  "@use-gesture/react": "^10.3.0",
@@ -80,5 +79,5 @@
80
79
  "access": "public",
81
80
  "registry": "https://registry.npmjs.org/"
82
81
  },
83
- "gitHead": "6c04a7e327b5fbc096785c11320b3fbd3c5751c8"
82
+ "gitHead": "3c2f5904ce61fcfa61f673c38c2a5ec56e9e2b07"
84
83
  }
package/lib/index.js DELETED
@@ -1,251 +0,0 @@
1
- 'use strict';
2
-
3
- var _defineProperty = require('@babel/runtime/helpers/defineProperty');
4
- var _slicedToArray = require('@babel/runtime/helpers/slicedToArray');
5
- var _objectSpread = require('@babel/runtime/helpers/objectSpread2');
6
- var react = require('@use-gesture/react');
7
- var classNames = require('classnames');
8
- var isString = require('lodash/isString');
9
- var PropTypes = require('prop-types');
10
- var React = require('react');
11
- var core = require('@micromag/core');
12
- var hooks = require('@micromag/core/hooks');
13
- var utils = require('@micromag/core/utils');
14
- var Button = require('@micromag/element-button');
15
- var Text = require('@micromag/element-text');
16
-
17
- var propTypes$1 = {
18
- color: PropTypes.string,
19
- className: PropTypes.string
20
- };
21
- var defaultProps$1 = {
22
- color: 'currentColor',
23
- className: null
24
- };
25
- var Arrow = function Arrow(_ref) {
26
- var color = _ref.color,
27
- className = _ref.className;
28
- return /*#__PURE__*/React.createElement("svg", {
29
- version: "1.1",
30
- xmlns: "http://www.w3.org/2000/svg",
31
- xmlnsXlink: "http://www.w3.org/1999/xlink",
32
- x: "0",
33
- y: "0px",
34
- width: "48.53px",
35
- height: "12.38px",
36
- viewBox: "0 0 48.53 12.38",
37
- className: className,
38
- xmlSpace: "preserve"
39
- }, /*#__PURE__*/React.createElement("g", {
40
- transform: "matrix(1, 0, 0, 1, 0, 0)"
41
- }, /*#__PURE__*/React.createElement("path", {
42
- id: "b",
43
- fill: "none",
44
- stroke: color,
45
- strokeWidth: "3px",
46
- strokeLinejoin: "round",
47
- strokeLinecap: "round",
48
- d: "M1.5,10.88L24.26,1.5l22.77,9.38"
49
- })));
50
- };
51
- Arrow.propTypes = propTypes$1;
52
- Arrow.defaultProps = defaultProps$1;
53
- var ArrowIcon = Arrow;
54
-
55
- var styles = {"container":"micromag-element-call-to-action-container","arrow":"micromag-element-call-to-action-arrow","upAndDown":"micromag-element-call-to-action-upAndDown","icon":"micromag-element-call-to-action-icon","label":"micromag-element-call-to-action-label","button":"micromag-element-call-to-action-button","selfTargetLink":"micromag-element-call-to-action-selfTargetLink","leavingFrame":"micromag-element-call-to-action-leavingFrame","appear":"micromag-element-call-to-action-appear","animationDisabled":"micromag-element-call-to-action-animationDisabled","invalidUrl":"micromag-element-call-to-action-invalidUrl","withMargin":"micromag-element-call-to-action-withMargin"};
56
-
57
- var propTypes = {
58
- type: PropTypes.oneOf(['click', 'swipe-up', null]),
59
- url: PropTypes.string,
60
- label: core.PropTypes.textElement,
61
- boxStyle: core.PropTypes.boxStyle,
62
- inWebView: PropTypes.bool,
63
- elRef: PropTypes.oneOfType([PropTypes.func, PropTypes.shape({
64
- current: PropTypes.any // eslint-disable-line
65
- })]),
66
- disabled: PropTypes.bool,
67
- animationDisabled: PropTypes.bool,
68
- icon: PropTypes.node,
69
- arrow: PropTypes.node,
70
- dragAmount: PropTypes.number,
71
- className: PropTypes.string,
72
- buttonClassName: PropTypes.string,
73
- buttonBorderClassName: PropTypes.string,
74
- labelClassName: PropTypes.string,
75
- arrowClassName: PropTypes.string,
76
- focusable: PropTypes.bool,
77
- openWebView: PropTypes.func,
78
- onClick: PropTypes.func
79
- };
80
- var defaultProps = {
81
- type: null,
82
- url: null,
83
- label: null,
84
- boxStyle: null,
85
- inWebView: false,
86
- elRef: null,
87
- disabled: false,
88
- animationDisabled: false,
89
- icon: null,
90
- arrow: null,
91
- dragAmount: 50,
92
- className: null,
93
- buttonClassName: null,
94
- buttonBorderClassName: null,
95
- labelClassName: null,
96
- arrowClassName: null,
97
- focusable: true,
98
- openWebView: null,
99
- onClick: null
100
- };
101
- function CallToAction(_ref) {
102
- var type = _ref.type,
103
- url = _ref.url,
104
- label = _ref.label,
105
- boxStyle = _ref.boxStyle,
106
- inWebView = _ref.inWebView,
107
- elRef = _ref.elRef,
108
- disabled = _ref.disabled,
109
- animationDisabled = _ref.animationDisabled,
110
- icon = _ref.icon,
111
- arrow = _ref.arrow,
112
- dragAmount = _ref.dragAmount,
113
- className = _ref.className,
114
- buttonClassName = _ref.buttonClassName,
115
- buttonBorderClassName = _ref.buttonBorderClassName,
116
- labelClassName = _ref.labelClassName,
117
- arrowClassName = _ref.arrowClassName,
118
- focusable = _ref.focusable,
119
- openWebView = _ref.openWebView,
120
- onClick = _ref.onClick;
121
- var trackEvent = hooks.useTrackEvent();
122
- var swipeUpEnabled = type === null || type === 'swipe-up';
123
- var validUrl = React.useMemo(function () {
124
- return utils.isValidUrl(url);
125
- }, [url]);
126
- var buttonRef = React.useRef(null);
127
- var _ref2 = label || {},
128
- _ref2$textStyle = _ref2.textStyle,
129
- textStyle = _ref2$textStyle === void 0 ? null : _ref2$textStyle;
130
- var _ref3 = textStyle || {},
131
- _ref3$fontSize = _ref3.fontSize,
132
- fontSize = _ref3$fontSize === void 0 ? null : _ref3$fontSize,
133
- _ref3$color = _ref3.color,
134
- color = _ref3$color === void 0 ? null : _ref3$color,
135
- _ref3$lineHeight = _ref3.lineHeight,
136
- lineHeight = _ref3$lineHeight === void 0 ? null : _ref3$lineHeight;
137
- var _ref4 = boxStyle || {},
138
- _ref4$backgroundColor = _ref4.backgroundColor,
139
- backgroundColor = _ref4$backgroundColor === void 0 ? null : _ref4$backgroundColor;
140
- var arrowStyle = React.useMemo(function () {
141
- return _objectSpread(_objectSpread({}, {
142
- fontSize: fontSize
143
- }), backgroundColor === null ? utils.getStyleFromColor(color, 'color') : utils.getStyleFromColor(backgroundColor, 'color'));
144
- }, [fontSize, backgroundColor, color]);
145
-
146
- // MobileSafari blocks popup no matter what
147
- var selfTargetLinkRef = React.useRef(null);
148
- var _useState = React.useState(false),
149
- _useState2 = _slicedToArray(_useState, 2),
150
- leaving = _useState2[0],
151
- setLeaving = _useState2[1];
152
- var _useState3 = React.useState(false),
153
- _useState4 = _slicedToArray(_useState3, 2),
154
- toggled = _useState4[0],
155
- setToggled = _useState4[1];
156
-
157
- // On click
158
- var onClickLink = React.useCallback(function (e) {
159
- var action = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'click';
160
- setToggled(!toggled);
161
- if (inWebView && openWebView !== null) {
162
- openWebView({
163
- url: url
164
- });
165
- }
166
- if (onClick !== null && action === 'cllick') {
167
- onClick(e);
168
- }
169
- if (trackEvent !== null) {
170
- trackEvent('call_to_action', isString(action) ? action : 'click', url);
171
- }
172
- }, [toggled, url, onClick, trackEvent, inWebView, openWebView]);
173
- var onDrag = React.useCallback(function (_ref5) {
174
- var event = _ref5.event;
175
- // fix firefox https://use-gesture.netlify.app/docs/faq/#why-cant-i-properly-drag-an-image-or-a-link
176
- event.preventDefault();
177
- }, []);
178
- var onDragEnd = React.useCallback(function (_ref6) {
179
- var _ref6$movement = _slicedToArray(_ref6.movement, 2),
180
- my = _ref6$movement[1];
181
- if (my < -dragAmount) {
182
- if (inWebView) {
183
- onClickLink(null, 'swipe');
184
- } else if (utils.isIos() && selfTargetLinkRef.current !== null) {
185
- selfTargetLinkRef.current.click();
186
- setLeaving(true);
187
- onClickLink(null, 'swipe');
188
- } else if (buttonRef.current) {
189
- buttonRef.current.click();
190
- onClickLink(null, 'swipe');
191
- }
192
- }
193
- }, [dragAmount, inWebView, onClickLink, setLeaving]);
194
- var bind = react.useGesture({
195
- onDrag: onDrag,
196
- onDragEnd: onDragEnd
197
- });
198
- React.useEffect(function () {
199
- var onPageHide = function onPageHide() {
200
- setLeaving(false);
201
- };
202
- window.addEventListener('pagehide', onPageHide);
203
- return function () {
204
- window.removeEventListener('pagehide', onPageHide);
205
- };
206
- }, [setLeaving]);
207
- return /*#__PURE__*/React.createElement("div", {
208
- className: classNames([styles.container, _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty({}, className, className !== null), styles.disabled, disabled), styles.animationDisabled, animationDisabled), styles.invalidUrl, !validUrl), styles.inWebView, inWebView)]),
209
- ref: elRef
210
- }, leaving ? /*#__PURE__*/React.createElement("div", {
211
- className: styles.leavingFrame
212
- }) : null, !inWebView && swipeUpEnabled ? /*#__PURE__*/React.createElement("a", {
213
- className: styles.selfTargetLink,
214
- href: url,
215
- ref: selfTargetLinkRef,
216
- tabIndex: focusable ? '0' : '-1'
217
- }) : null, swipeUpEnabled ? /*#__PURE__*/React.createElement("div", {
218
- className: classNames([styles.arrow, _defineProperty({}, arrowClassName, arrowClassName !== null)]),
219
- style: arrowStyle
220
- }, arrow || /*#__PURE__*/React.createElement(ArrowIcon, null)) : null, /*#__PURE__*/React.createElement("div", {
221
- className: classNames([styles.buttonBorder, _defineProperty({}, buttonBorderClassName, buttonBorderClassName !== null)])
222
- }, /*#__PURE__*/React.createElement(Button, Object.assign({
223
- className: classNames([styles.button, _defineProperty({}, buttonClassName, buttonClassName !== null)]),
224
- refButton: buttonRef,
225
- focusable: focusable,
226
- buttonStyle: boxStyle,
227
- inline: true,
228
- "aria-pressed": toggled,
229
- href: !inWebView ? url : null,
230
- external: true,
231
- onClick: onClickLink
232
- }, swipeUpEnabled && !disabled ? bind() : null), /*#__PURE__*/React.createElement("span", {
233
- className: classNames([styles.label, _defineProperty({}, labelClassName, labelClassName !== null)])
234
- }, icon !== null ? /*#__PURE__*/React.createElement("div", {
235
- className: styles.icon
236
- }, icon) : null, /*#__PURE__*/React.createElement(Text, Object.assign({}, label, {
237
- textStyle: _objectSpread(_objectSpread({}, textStyle), {}, {
238
- lineHeight: lineHeight || 1
239
- }),
240
- inline: true
241
- }))))));
242
- }
243
- CallToAction.propTypes = propTypes;
244
- CallToAction.defaultProps = defaultProps;
245
- var CallToAction$1 = /*#__PURE__*/React.forwardRef(function (props, ref) {
246
- return /*#__PURE__*/React.createElement(CallToAction, Object.assign({
247
- elRef: ref
248
- }, props));
249
- });
250
-
251
- module.exports = CallToAction$1;