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

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,26 @@ const useFixedBoxMethods = ({ beforeShow, boxEl, getTriggerEl, handlePosition, h
36
39
  getSetStatus()(true);
37
40
  }
38
41
  };
42
+ const handleTriggerRightTouchStart = e => {
43
+ mouseEvent.current = e;
44
+ touchStartDate.current = Date.now();
45
+ const triggerEl = getTriggerEl();
46
+ (0, dom_1.addEventListener)(triggerEl, ['touchend'], handleTriggerRightTouchEnd);
47
+ setTimeout(() => {
48
+ if (touchStartDate.current) {
49
+ touchStartDate.current = null;
50
+ (0, dom_1.removeEventListener)(triggerEl, ['touchend'], handleTriggerRightTouchEnd);
51
+ setStatus(true);
52
+ }
53
+ }, 1500);
54
+ };
55
+ const handleTriggerRightTouchEnd = e => {
56
+ if (touchStartDate.current) {
57
+ touchStartDate.current = null;
58
+ const triggerEl = getTriggerEl();
59
+ (0, dom_1.removeEventListener)(triggerEl, ['touchend'], handleTriggerRightTouchEnd);
60
+ }
61
+ };
39
62
  const handleTriggerMouseEnter = e => {
40
63
  mouseEvent.current = null;
41
64
  if (e.target === getTriggerEl()) {
@@ -117,7 +140,12 @@ const useFixedBoxMethods = ({ beforeShow, boxEl, getTriggerEl, handlePosition, h
117
140
  }
118
141
  }
119
142
  if (triggerInteraction & types_1.TriggerInteraction.RIGHT_CLICK) {
120
- (0, dom_1.addEventListener)(triggerEl, ['contextmenu'], handleTriggerRightClick);
143
+ if (theme.$.vars.isMobile) {
144
+ (0, dom_1.addEventListener)(triggerEl, ['touchstart'], handleTriggerRightTouchStart);
145
+ }
146
+ else {
147
+ (0, dom_1.addEventListener)(triggerEl, ['contextmenu'], handleTriggerRightClick);
148
+ }
121
149
  if (getStatus()) {
122
150
  (0, dom_1.addEventListener)(triggerEl, ['click'], handleTriggerClick);
123
151
  (0, dom_1.addEventListener)(window, ['click', 'contextmenu'], handleWindowClick);
@@ -143,7 +171,12 @@ const useFixedBoxMethods = ({ beforeShow, boxEl, getTriggerEl, handlePosition, h
143
171
  }
144
172
  }
145
173
  if (triggerInteraction & types_1.TriggerInteraction.RIGHT_CLICK) {
146
- (0, dom_1.removeEventListener)(triggerEl, ['contextmenu'], handleTriggerRightClick);
174
+ if (theme.$.vars.isMobile) {
175
+ (0, dom_1.removeEventListener)(triggerEl, ['touchstart'], handleTriggerRightTouchStart);
176
+ }
177
+ else {
178
+ (0, dom_1.removeEventListener)(triggerEl, ['contextmenu'], handleTriggerRightClick);
179
+ }
147
180
  if (getStatus()) {
148
181
  (0, dom_1.removeEventListener)(triggerEl, ['click'], handleTriggerClick);
149
182
  (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-85",
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);