@smart-react-components/ui 2.0.0-alpha-78 → 2.0.0-alpha-79

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.
@@ -15,6 +15,7 @@ export interface Props {
15
15
  hasHideAnimation?: boolean;
16
16
  hasShowAnimation?: boolean;
17
17
  isDismissible?: boolean;
18
+ isOverflowPrevented?: boolean;
18
19
  maxWidth?: number;
19
20
  minWidth?: number;
20
21
  position?: Position;
package/FixedBox/index.js CHANGED
@@ -16,13 +16,13 @@ const OverlayElement_1 = __importDefault(require("../components/FixedBox/Overlay
16
16
  var types_2 = require("../types");
17
17
  Object.defineProperty(exports, "Position", { enumerable: true, get: function () { return types_2.Position; } });
18
18
  Object.defineProperty(exports, "TriggerInteraction", { enumerable: true, get: function () { return types_2.TriggerInteraction; } });
19
- const FixedBox = ({ afterHide, afterShow, beforeHide, beforeShow, breakpoint = 'medium', children, elementProps = {}, hasHideAnimation = true, hasShowAnimation = true, isDismissible = true, maxWidth, minWidth, position = types_1.Position.BOTTOM, setStatus, space = 0, status, transitionClassName, transitionDuration, triggerInteraction = types_1.TriggerInteraction.CLICK, }) => {
19
+ const FixedBox = ({ afterHide, afterShow, beforeHide, beforeShow, breakpoint = 'medium', children, elementProps = {}, hasHideAnimation = true, hasShowAnimation = true, isDismissible = true, isOverflowPrevented, maxWidth, minWidth, position = types_1.Position.BOTTOM, setStatus, space = 0, status, transitionClassName, transitionDuration, triggerInteraction = types_1.TriggerInteraction.CLICK, }) => {
20
20
  var _a;
21
21
  const theme = react_1.default.useContext(styled_components_1.ThemeContext);
22
22
  const triggerEl = react_1.default.useRef(null);
23
23
  const boxEl = react_1.default.useRef(null);
24
24
  const getTriggerEl = () => { var _a; return ((_a = children[0].ref) !== null && _a !== void 0 ? _a : triggerEl).current; };
25
- const handlePosition = e => (0, fixed_box_1.calculatePosition)(getTriggerEl(), boxEl.current, e, position, maxWidth, minWidth, space);
25
+ const handlePosition = e => (0, fixed_box_1.calculatePosition)(getTriggerEl(), boxEl.current, e, position, maxWidth, minWidth, space, isOverflowPrevented);
26
26
  const { getStatus, handleBeforeShow, } = (0, useFixedBoxMethods_1.default)({ beforeShow, boxEl, getTriggerEl, handlePosition, isDismissible, key: 'fixed-box', setStatus, status, triggerInteraction });
27
27
  return (react_1.default.createElement(react_1.default.Fragment, null,
28
28
  react_1.default.cloneElement(children[0], { ref: (_a = children[0].ref) !== null && _a !== void 0 ? _a : triggerEl }),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@smart-react-components/ui",
3
- "version": "2.0.0-alpha-78",
3
+ "version": "2.0.0-alpha-79",
4
4
  "license": "MIT",
5
5
  "main": "index.js",
6
6
  "description": "SRC UI includes React and Styled components.",
@@ -3,4 +3,4 @@ import { Position } from '../types';
3
3
  /**
4
4
  * Calculated fixed box position and size.
5
5
  */
6
- export declare const calculatePosition: (triggerEl: HTMLElement, boxEl: HTMLDivElement | null, e: Nullable<MouseEvent>, position: Position, maxWidth: number | undefined, minWidth: number | undefined, space: number) => void;
6
+ export declare const calculatePosition: (triggerEl: HTMLElement, boxEl: HTMLDivElement | null, e: Nullable<MouseEvent>, position: Position, maxWidth: number | undefined, minWidth: number | undefined, space: number, isOverflowPrevented: boolean) => void;
package/util/fixed-box.js CHANGED
@@ -6,7 +6,7 @@ const dom_1 = require("./dom");
6
6
  /**
7
7
  * Calculated fixed box position and size.
8
8
  */
9
- const calculatePosition = (triggerEl, boxEl, e, position, maxWidth, minWidth, space) => {
9
+ const calculatePosition = (triggerEl, boxEl, e, position, maxWidth, minWidth, space, isOverflowPrevented) => {
10
10
  if (!boxEl) {
11
11
  return;
12
12
  }
@@ -27,14 +27,14 @@ const calculatePosition = (triggerEl, boxEl, e, position, maxWidth, minWidth, sp
27
27
  }
28
28
  boxEl.style.width = `${width}px`;
29
29
  boxEl.setAttribute('style', position & (types_1.Position.LEFT | types_1.Position.RIGHT)
30
- ? calculatePositionBasedOnXAxis(triggerRect, boxEl, e, position, space, windowWidth, windowHeight)
31
- : calculatePositionBasedOnYAxis(triggerRect, boxEl, e, position, space, windowWidth, windowHeight));
30
+ ? calculatePositionBasedOnXAxis(triggerRect, boxEl, e, position, space, windowWidth, windowHeight, isOverflowPrevented)
31
+ : calculatePositionBasedOnYAxis(triggerRect, boxEl, e, position, space, windowWidth, windowHeight, isOverflowPrevented));
32
32
  };
33
33
  exports.calculatePosition = calculatePosition;
34
34
  /**
35
35
  * Calculates fixed box position and sized based on X axis position.
36
36
  */
37
- const calculatePositionBasedOnXAxis = (triggerRect, boxEl, e, position, space, windowWidth, windowHeight) => {
37
+ const calculatePositionBasedOnXAxis = (triggerRect, boxEl, e, position, space, windowWidth, windowHeight, isOverflowPrevented) => {
38
38
  var _a, _b;
39
39
  // left & width
40
40
  let left;
@@ -50,6 +50,9 @@ const calculatePositionBasedOnXAxis = (triggerRect, boxEl, e, position, space, w
50
50
  else {
51
51
  left = triggerLeft + triggerWidth + space;
52
52
  }
53
+ if (isOverflowPrevented) {
54
+ left = Math.max(0, Math.min(windowWidth - width, left));
55
+ }
53
56
  // top & height
54
57
  let top;
55
58
  let height = boxEl.offsetHeight;
@@ -75,7 +78,7 @@ const calculatePositionBasedOnXAxis = (triggerRect, boxEl, e, position, space, w
75
78
  /**
76
79
  * Calculates fixed box position and sized based on Y axis position.
77
80
  */
78
- const calculatePositionBasedOnYAxis = (triggerRect, boxEl, e, position, space, windowWidth, windowHeight) => {
81
+ const calculatePositionBasedOnYAxis = (triggerRect, boxEl, e, position, space, windowWidth, windowHeight, isOverflowPrevented) => {
79
82
  var _a, _b;
80
83
  // left & width
81
84
  let left;
@@ -90,6 +93,9 @@ const calculatePositionBasedOnYAxis = (triggerRect, boxEl, e, position, space, w
90
93
  else {
91
94
  left = triggerLeft + triggerWidth - width;
92
95
  }
96
+ if (isOverflowPrevented) {
97
+ left = Math.max(0, Math.min(windowWidth - width, left));
98
+ }
93
99
  // top & height
94
100
  let top;
95
101
  let height = boxEl.offsetHeight;