@smart-react-components/ui 2.0.0-alpha-83 → 2.0.0-alpha-84

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.
@@ -6,7 +6,7 @@ interface Props {
6
6
  beforeShow?: TransitionBeforeCallback;
7
7
  boxEl: React.MutableRefObject<HTMLDivElement>;
8
8
  getTriggerEl: () => HTMLElement;
9
- handlePosition: (e: MouseEvent) => void;
9
+ handlePosition: (e: MouseEvent | TouchEvent) => void;
10
10
  hoverDelay?: number;
11
11
  isDismissible: boolean;
12
12
  key: string;
@@ -11,13 +11,16 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  const dom_1 = require("@smart-react-components/core/util/dom");
13
13
  const react_1 = require("react");
14
+ const styled_components_1 = require("styled-components");
14
15
  const types_1 = require("../types");
15
16
  const dom_2 = require("../util/dom");
16
17
  const useFixedBoxMethods = ({ beforeShow, boxEl, getTriggerEl, handlePosition, hoverDelay, isDismissible, key, setStatus, status, triggerInteraction }) => {
18
+ const theme = (0, styled_components_1.useTheme)();
17
19
  const enterTimeout = (0, react_1.useRef)(null);
18
20
  const enterTimeoutMouseMove = (0, react_1.useRef)(null);
19
21
  const leaveTimeout = (0, react_1.useRef)(null);
20
22
  const mouseEvent = (0, react_1.useRef)(null);
23
+ const touchStartDate = (0, react_1.useRef)(null);
21
24
  const [localStatus, setLocalStatus] = (0, react_1.useState)(() => false);
22
25
  const getStatus = () => status !== null && status !== void 0 ? status : localStatus;
23
26
  const getSetStatus = () => setStatus !== null && setStatus !== void 0 ? setStatus : setLocalStatus;
@@ -36,6 +39,28 @@ const useFixedBoxMethods = ({ beforeShow, boxEl, getTriggerEl, handlePosition, h
36
39
  getSetStatus()(true);
37
40
  }
38
41
  };
42
+ const handleTriggerRightTouchStart = e => {
43
+ e.preventDefault();
44
+ mouseEvent.current = e;
45
+ touchStartDate.current = Date.now();
46
+ const triggerEl = getTriggerEl();
47
+ (0, dom_1.addEventListener)(triggerEl, ['touchend'], handleTriggerRightTouchEnd);
48
+ setTimeout(() => {
49
+ if (touchStartDate.current) {
50
+ touchStartDate.current = null;
51
+ (0, dom_1.removeEventListener)(triggerEl, ['touchend'], handleTriggerRightTouchEnd);
52
+ setStatus(true);
53
+ }
54
+ }, 1500);
55
+ };
56
+ const handleTriggerRightTouchEnd = e => {
57
+ e.preventDefault();
58
+ if (touchStartDate.current) {
59
+ touchStartDate.current = null;
60
+ const triggerEl = getTriggerEl();
61
+ (0, dom_1.removeEventListener)(triggerEl, ['touchend'], handleTriggerRightTouchEnd);
62
+ }
63
+ };
39
64
  const handleTriggerMouseEnter = e => {
40
65
  mouseEvent.current = null;
41
66
  if (e.target === getTriggerEl()) {
@@ -117,7 +142,12 @@ const useFixedBoxMethods = ({ beforeShow, boxEl, getTriggerEl, handlePosition, h
117
142
  }
118
143
  }
119
144
  if (triggerInteraction & types_1.TriggerInteraction.RIGHT_CLICK) {
120
- (0, dom_1.addEventListener)(triggerEl, ['contextmenu'], handleTriggerRightClick);
145
+ if (theme.$.vars.isMobile) {
146
+ (0, dom_1.addEventListener)(triggerEl, ['touchstart'], handleTriggerRightTouchStart);
147
+ }
148
+ else {
149
+ (0, dom_1.addEventListener)(triggerEl, ['contextmenu'], handleTriggerRightClick);
150
+ }
121
151
  if (getStatus()) {
122
152
  (0, dom_1.addEventListener)(triggerEl, ['click'], handleTriggerClick);
123
153
  (0, dom_1.addEventListener)(window, ['click', 'contextmenu'], handleWindowClick);
@@ -143,7 +173,12 @@ const useFixedBoxMethods = ({ beforeShow, boxEl, getTriggerEl, handlePosition, h
143
173
  }
144
174
  }
145
175
  if (triggerInteraction & types_1.TriggerInteraction.RIGHT_CLICK) {
146
- (0, dom_1.removeEventListener)(triggerEl, ['contextmenu'], handleTriggerRightClick);
176
+ if (theme.$.vars.isMobile) {
177
+ (0, dom_1.removeEventListener)(triggerEl, ['touchstart'], handleTriggerRightTouchStart);
178
+ }
179
+ else {
180
+ (0, dom_1.removeEventListener)(triggerEl, ['contextmenu'], handleTriggerRightClick);
181
+ }
147
182
  if (getStatus()) {
148
183
  (0, dom_1.removeEventListener)(triggerEl, ['click'], handleTriggerClick);
149
184
  (0, dom_1.removeEventListener)(window, ['click', 'contextmenu'], handleWindowClick);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@smart-react-components/ui",
3
- "version": "2.0.0-alpha-83",
3
+ "version": "2.0.0-alpha-84",
4
4
  "license": "MIT",
5
5
  "main": "index.js",
6
6
  "description": "SRC UI includes React and Styled components.",
package/util/fixed-box.js CHANGED
@@ -35,11 +35,11 @@ exports.calculatePosition = calculatePosition;
35
35
  * Calculates fixed box position and sized based on X axis position.
36
36
  */
37
37
  const calculatePositionBasedOnXAxis = (triggerRect, boxEl, e, position, space, windowWidth, windowHeight, isOverflowPrevented) => {
38
- var _a, _b;
38
+ var _a, _b, _c, _d, _e, _f, _g, _h;
39
39
  // left & width
40
40
  let left;
41
41
  const width = boxEl.offsetWidth + .5;
42
- const triggerLeft = (_a = e === null || e === void 0 ? void 0 : e.clientX) !== null && _a !== void 0 ? _a : triggerRect.left;
42
+ const triggerLeft = (_d = (_a = e === null || e === void 0 ? void 0 : e.clientX) !== null && _a !== void 0 ? _a : (_c = (_b = e === null || e === void 0 ? void 0 : e.touches) === null || _b === void 0 ? void 0 : _b[0]) === null || _c === void 0 ? void 0 : _c.pageX) !== null && _d !== void 0 ? _d : triggerRect.left;
43
43
  const triggerWidth = e ? 0 : triggerRect.width;
44
44
  const diffLeft = triggerRect.left - (space + width);
45
45
  const diffRight = windowWidth - (triggerLeft + triggerWidth + space + width);
@@ -56,7 +56,7 @@ const calculatePositionBasedOnXAxis = (triggerRect, boxEl, e, position, space, w
56
56
  // top & height
57
57
  let top;
58
58
  let height = boxEl.offsetHeight;
59
- const triggerTop = (_b = e === null || e === void 0 ? void 0 : e.clientY) !== null && _b !== void 0 ? _b : triggerRect.top;
59
+ const triggerTop = (_h = (_e = e === null || e === void 0 ? void 0 : e.clientY) !== null && _e !== void 0 ? _e : (_g = (_f = e === null || e === void 0 ? void 0 : e.touches) === null || _f === void 0 ? void 0 : _f[0]) === null || _g === void 0 ? void 0 : _g.pageY) !== null && _h !== void 0 ? _h : triggerRect.top;
60
60
  const triggerHeight = e ? 0 : triggerRect.height + triggerRect.top <= windowHeight ? triggerRect.height : (windowHeight - triggerRect.top);
61
61
  const diffBottom = windowHeight - (triggerRect.top + height);
62
62
  const diffTop = (triggerRect.top + triggerHeight) - height;
@@ -79,11 +79,11 @@ const calculatePositionBasedOnXAxis = (triggerRect, boxEl, e, position, space, w
79
79
  * Calculates fixed box position and sized based on Y axis position.
80
80
  */
81
81
  const calculatePositionBasedOnYAxis = (triggerRect, boxEl, e, position, space, windowWidth, windowHeight, isOverflowPrevented) => {
82
- var _a, _b;
82
+ var _a, _b, _c, _d, _e, _f, _g, _h;
83
83
  // left & width
84
84
  let left;
85
85
  const width = boxEl.offsetWidth + .5;
86
- const triggerLeft = (_a = e === null || e === void 0 ? void 0 : e.clientX) !== null && _a !== void 0 ? _a : triggerRect.left;
86
+ const triggerLeft = (_d = (_a = e === null || e === void 0 ? void 0 : e.clientX) !== null && _a !== void 0 ? _a : (_c = (_b = e === null || e === void 0 ? void 0 : e.touches) === null || _b === void 0 ? void 0 : _b[0]) === null || _c === void 0 ? void 0 : _c.pageX) !== null && _d !== void 0 ? _d : triggerRect.left;
87
87
  const triggerWidth = e ? 0 : triggerRect.width;
88
88
  const diffLeft = windowWidth - (triggerLeft + width);
89
89
  const diffRight = triggerLeft - width;
@@ -99,7 +99,7 @@ const calculatePositionBasedOnYAxis = (triggerRect, boxEl, e, position, space, w
99
99
  // top & height
100
100
  let top;
101
101
  let height = boxEl.offsetHeight;
102
- const triggerTop = (_b = e === null || e === void 0 ? void 0 : e.clientY) !== null && _b !== void 0 ? _b : triggerRect.top;
102
+ const triggerTop = (_h = (_e = e === null || e === void 0 ? void 0 : e.clientY) !== null && _e !== void 0 ? _e : (_g = (_f = e === null || e === void 0 ? void 0 : e.touches) === null || _f === void 0 ? void 0 : _f[0]) === null || _g === void 0 ? void 0 : _g.pageY) !== null && _h !== void 0 ? _h : triggerRect.top;
103
103
  const triggerHeight = e ? 0 : triggerRect.height;
104
104
  const diffBottom = windowHeight - (triggerTop + triggerHeight + height + space);
105
105
  const diffTop = (triggerTop + triggerHeight) - (height + 1);