@smart-react-components/ui 2.0.0-alpha-13 → 2.0.0-alpha-15

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/FixedBox/index.js CHANGED
@@ -22,16 +22,16 @@ const FixedBox = ({ afterHide, afterShow, beforeHide, beforeShow, breakpoint = '
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 = () => (0, fixed_box_1.calculatePosition)(getTriggerEl(), boxEl.current, position, maxWidth, minWidth, space);
25
+ const handlePosition = e => (0, fixed_box_1.calculatePosition)(getTriggerEl(), boxEl.current, e, position, maxWidth, minWidth, space);
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 }),
29
29
  react_1.default.createElement(CSSTransition_1.default, { afterHide: afterHide, afterShow: afterShow, beforeHide: beforeHide, beforeShow: handleBeforeShow, className: transitionClassName !== null && transitionClassName !== void 0 ? transitionClassName : 'src-fixed-box', duration: transitionDuration !== null && transitionDuration !== void 0 ? transitionDuration : theme.$.transition.fixedBoxDuration, hasHideAnimation: hasHideAnimation, hasShowAnimation: hasShowAnimation, status: getStatus() },
30
- react_1.default.createElement(Overlay_1.default, { breakpoint: breakpoint, elementProps: {
30
+ react_1.default.createElement(Overlay_1.default, { breakpoint: triggerInteraction & types_1.TriggerInteraction.RIGHT_CLICK ? null : breakpoint, elementProps: {
31
31
  as: OverlayElement_1.default,
32
32
  duration: transitionDuration !== null && transitionDuration !== void 0 ? transitionDuration : theme.$.transition.fixedBoxDuration,
33
- isDisplayedWhenBreakpointNull: false,
34
- } },
33
+ isDisplayedWhenBreakpointNull: triggerInteraction & types_1.TriggerInteraction.RIGHT_CLICK,
34
+ }, hasBackground: !(triggerInteraction & types_1.TriggerInteraction.RIGHT_CLICK) },
35
35
  react_1.default.createElement(FixedBoxElement_1.default, Object.assign({}, elementProps, { breakpoint: breakpoint, ref: boxEl }), children[1])))));
36
36
  };
37
37
  exports.default = FixedBox;
package/Grid/Column.d.ts CHANGED
@@ -2,8 +2,5 @@ import { StyledProps } from '@smart-react-components/core/styled-props';
2
2
  import { Partial, ResponsiveProp } from '@smart-react-components/core/types';
3
3
  export interface Props extends StyledProps, Partial<ResponsiveProp<'col', number>>, Partial<ResponsiveProp<'pos', number>> {
4
4
  }
5
- declare const _default: import("styled-components").StyledComponent<"div", any, StyledProps & {
6
- getCol: (v: any) => string;
7
- getPos: (v: any) => string;
8
- } & Props, "getCol" | "getPos">;
5
+ declare const _default: import("styled-components").StyledComponent<"div", any, StyledProps & Props, never>;
9
6
  export default _default;
package/Grid/Column.js CHANGED
@@ -6,7 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const Div_1 = __importDefault(require("@smart-react-components/core/Element/Div"));
7
7
  const styled_components_1 = __importDefault(require("styled-components"));
8
8
  const grid_1 = require("../constants/grid");
9
- exports.default = (0, styled_components_1.default)(Div_1.default).attrs({
9
+ exports.default = (0, styled_components_1.default)(Div_1.default).attrs(({ paddingHorizontal = '$length.grid.space' }) => ({
10
10
  getCol: v => `
11
11
  flex: 0 0 ${grid_1.columns[v]}%;
12
12
  max-width: ${grid_1.columns[v]}%;
@@ -14,7 +14,8 @@ exports.default = (0, styled_components_1.default)(Div_1.default).attrs({
14
14
  getPos: v => `
15
15
  margin-left: ${v < 0 ? '-' : ''}${grid_1.columns[Math.abs(v)]}%;
16
16
  `,
17
- }) `
17
+ paddingHorizontal,
18
+ })) `
18
19
  box-sizing: border-box;
19
20
  width: 100%;
20
21
  `;
package/Grid/Container.js CHANGED
@@ -5,8 +5,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const Div_1 = __importDefault(require("@smart-react-components/core/Element/Div"));
7
7
  const styled_components_1 = __importDefault(require("styled-components"));
8
- exports.default = (0, styled_components_1.default)(Div_1.default).attrs(({ marginHorizontal = 'auto' }) => ({
8
+ exports.default = (0, styled_components_1.default)(Div_1.default).attrs(({ marginHorizontal = 'auto', paddingHorizontal = '$length.grid.space' }) => ({
9
9
  marginHorizontal,
10
+ paddingHorizontal,
10
11
  maxWidth: '100%',
11
12
  maxWidthSm: '{length.grid.containerWidth.small}px',
12
13
  maxWidthMd: '{length.grid.containerWidth.medium}px',
package/Grid/Row.js CHANGED
@@ -5,7 +5,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const Div_1 = __importDefault(require("@smart-react-components/core/Element/Div"));
7
7
  const styled_components_1 = __importDefault(require("styled-components"));
8
- exports.default = (0, styled_components_1.default)(Div_1.default) `
8
+ exports.default = (0, styled_components_1.default)(Div_1.default).attrs(({ marginHorizontal = '-{length.grid.space}' }) => ({
9
+ marginHorizontal,
10
+ })) `
9
11
  box-sizing: border-box;
10
12
  display: flex;
11
13
  flex-wrap: wrap;
@@ -6,7 +6,7 @@ interface Props {
6
6
  beforeShow?: TransitionBeforeCallback;
7
7
  boxEl: React.MutableRefObject<HTMLDivElement>;
8
8
  getTriggerEl: () => HTMLElement;
9
- handlePosition: () => void;
9
+ handlePosition: (e: MouseEvent) => void;
10
10
  isDismissible: boolean;
11
11
  key: string;
12
12
  setStatus?: SetState<boolean>;
@@ -15,21 +15,34 @@ const types_1 = require("../types");
15
15
  const dom_2 = require("../util/dom");
16
16
  const useFixedBoxMethods = ({ beforeShow, boxEl, getTriggerEl, handlePosition, isDismissible, key, setStatus, status, triggerInteraction }) => {
17
17
  const leaveTimeout = (0, react_1.useRef)(null);
18
+ const mouseEvent = (0, react_1.useRef)(null);
18
19
  const [localStatus, setLocalStatus] = (0, react_1.useState)(() => false);
19
20
  const getStatus = () => status !== null && status !== void 0 ? status : localStatus;
20
21
  const getSetStatus = () => setStatus !== null && setStatus !== void 0 ? setStatus : setLocalStatus;
21
22
  const handleTriggerClick = (e) => {
23
+ mouseEvent.current = null;
22
24
  const triggerEl = getTriggerEl();
23
25
  if ((0, dom_2.isTargetClickable)(e.target, triggerEl)) {
24
26
  getSetStatus()(!getStatus());
25
27
  }
26
28
  };
29
+ const handleTriggerRightClick = e => {
30
+ e.preventDefault();
31
+ mouseEvent.current = e;
32
+ const triggerEl = getTriggerEl();
33
+ if ((0, dom_2.isTargetClickable)(e.target, triggerEl)) {
34
+ getSetStatus()(true);
35
+ }
36
+ };
27
37
  const handleTriggerMouseEnter = e => {
38
+ mouseEvent.current = null;
28
39
  if (e.target === getTriggerEl()) {
29
40
  getSetStatus()(true);
30
41
  }
31
42
  };
32
43
  const handleWindowClick = (e) => {
44
+ e.preventDefault();
45
+ mouseEvent.current = null;
33
46
  const target = e.target;
34
47
  const triggerEl = getTriggerEl();
35
48
  if (!triggerEl.contains(target) && !boxEl.current.contains(target)) {
@@ -55,18 +68,19 @@ const useFixedBoxMethods = ({ beforeShow, boxEl, getTriggerEl, handlePosition, i
55
68
  };
56
69
  const handleBeforeShow = el => new Promise((resolve) => __awaiter(void 0, void 0, void 0, function* () {
57
70
  yield (beforeShow === null || beforeShow === void 0 ? void 0 : beforeShow(el));
58
- handlePosition();
71
+ handlePosition(mouseEvent.current);
59
72
  resolve();
60
73
  }));
61
74
  (0, react_1.useEffect)(() => {
62
75
  if (getStatus()) {
63
- handlePosition();
76
+ handlePosition(null);
64
77
  }
65
78
  }, []);
66
79
  (0, react_1.useEffect)(() => {
67
80
  const triggerEl = getTriggerEl();
68
81
  const debounceWindowMouseMove = (0, dom_1.debounce)(handleWindowMouseMove);
69
- const debouncePosition = (0, dom_1.debounce)(handlePosition);
82
+ const debouncePosition = (0, dom_1.debounce)(() => handlePosition(null));
83
+ const handlePositionBind = () => handlePosition(null);
70
84
  if (triggerInteraction & types_1.TriggerInteraction.CLICK) {
71
85
  (0, dom_1.addEventListener)(triggerEl, ['click'], handleTriggerClick);
72
86
  if (getStatus() && isDismissible) {
@@ -81,10 +95,17 @@ const useFixedBoxMethods = ({ beforeShow, boxEl, getTriggerEl, handlePosition, i
81
95
  (0, dom_1.addEventListener)(window, ['mousemove'], debounceWindowMouseMove);
82
96
  }
83
97
  }
98
+ if (triggerInteraction & types_1.TriggerInteraction.RIGHT_CLICK) {
99
+ (0, dom_1.addEventListener)(triggerEl, ['contextmenu'], handleTriggerRightClick);
100
+ if (getStatus()) {
101
+ (0, dom_1.addEventListener)(triggerEl, ['click'], handleTriggerClick);
102
+ (0, dom_1.addEventListener)(window, ['click', 'contextmenu'], handleWindowClick);
103
+ }
104
+ }
84
105
  if (getStatus()) {
85
106
  (0, dom_1.addEventListener)(window, ['resize', 'scroll'], debouncePosition);
86
107
  }
87
- (0, dom_1.addEventListener)(triggerEl, ['src.fixedBox.setPosition'], handlePosition);
108
+ (0, dom_1.addEventListener)(triggerEl, ['src.fixedBox.setPosition'], handlePositionBind);
88
109
  return () => {
89
110
  if (triggerInteraction & types_1.TriggerInteraction.CLICK) {
90
111
  (0, dom_1.removeEventListener)(triggerEl, ['click'], handleTriggerClick);
@@ -100,10 +121,17 @@ const useFixedBoxMethods = ({ beforeShow, boxEl, getTriggerEl, handlePosition, i
100
121
  (0, dom_1.removeEventListener)(window, ['mousemove'], debounceWindowMouseMove);
101
122
  }
102
123
  }
124
+ if (triggerInteraction & types_1.TriggerInteraction.RIGHT_CLICK) {
125
+ (0, dom_1.removeEventListener)(triggerEl, ['contextmenu'], handleTriggerRightClick);
126
+ if (getStatus()) {
127
+ (0, dom_1.removeEventListener)(triggerEl, ['click'], handleTriggerClick);
128
+ (0, dom_1.removeEventListener)(window, ['click', 'contextmenu'], handleWindowClick);
129
+ }
130
+ }
103
131
  if (getStatus()) {
104
132
  (0, dom_1.removeEventListener)(window, ['resize', 'scroll'], debouncePosition);
105
133
  }
106
- (0, dom_1.removeEventListener)(triggerEl, [`src.${key}.setPosition`], handlePosition);
134
+ (0, dom_1.removeEventListener)(triggerEl, [`src.${key}.setPosition`], handlePositionBind);
107
135
  };
108
136
  }, [status, setStatus, localStatus, setLocalStatus, triggerInteraction]);
109
137
  return {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@smart-react-components/ui",
3
- "version": "2.0.0-alpha-13",
3
+ "version": "2.0.0-alpha-15",
4
4
  "license": "MIT",
5
5
  "main": "index.js",
6
6
  "description": "SRC UI includes React and Styled components.",
@@ -64,9 +64,9 @@
64
64
  "test": "jest"
65
65
  },
66
66
  "devDependencies": {
67
- "@smart-react-components/core": "2.0.0-alpha-17",
68
- "@smart-react-components/router": "2.0.0-alpha-13",
69
- "@smart-react-components/transition": "2.0.0-alpha-13",
67
+ "@smart-react-components/core": "2.0.0-alpha-18",
68
+ "@smart-react-components/router": "2.0.0-alpha-14",
69
+ "@smart-react-components/transition": "2.0.0-alpha-14",
70
70
  "@testing-library/react": "13.4.0",
71
71
  "@types/jest": "29.0.1",
72
72
  "@types/react": "18.0.19",
@@ -83,9 +83,9 @@
83
83
  "typescript": "4.8.3"
84
84
  },
85
85
  "peerDependencies": {
86
- "@smart-react-components/core": "^2.0.0-alpha-17",
87
- "@smart-react-components/router": "^2.0.0-alpha-13",
88
- "@smart-react-components/transition": "^2.0.0-alpha-13",
86
+ "@smart-react-components/core": "^2.0.0-alpha-18",
87
+ "@smart-react-components/router": "^2.0.0-alpha-14",
88
+ "@smart-react-components/transition": "^2.0.0-alpha-14",
89
89
  "react": "^18.2.0",
90
90
  "react-dom": "^18.2.0",
91
91
  "styled-components": "^5.3.5"
package/types/index.d.ts CHANGED
@@ -21,5 +21,6 @@ export declare enum Position {
21
21
  export declare enum TriggerInteraction {
22
22
  NONE = 0,
23
23
  CLICK = 1,
24
- HOVER = 2
24
+ HOVER = 2,
25
+ RIGHT_CLICK = 4
25
26
  }
package/types/index.js CHANGED
@@ -27,4 +27,5 @@ var TriggerInteraction;
27
27
  TriggerInteraction[TriggerInteraction["NONE"] = 0] = "NONE";
28
28
  TriggerInteraction[TriggerInteraction["CLICK"] = 1] = "CLICK";
29
29
  TriggerInteraction[TriggerInteraction["HOVER"] = 2] = "HOVER";
30
+ TriggerInteraction[TriggerInteraction["RIGHT_CLICK"] = 4] = "RIGHT_CLICK";
30
31
  })(TriggerInteraction = exports.TriggerInteraction || (exports.TriggerInteraction = {}));
@@ -1,5 +1,6 @@
1
+ import { Nullable } from '@smart-react-components/core/types';
1
2
  import { Position } from '../types';
2
3
  /**
3
4
  * Calculated fixed box position and size.
4
5
  */
5
- export declare const calculatePosition: (triggerEl: HTMLElement, boxEl: HTMLDivElement | null, 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) => 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, position, maxWidth, minWidth, space) => {
9
+ const calculatePosition = (triggerEl, boxEl, e, position, maxWidth, minWidth, space) => {
10
10
  if (!boxEl) {
11
11
  return;
12
12
  }
@@ -27,39 +27,43 @@ const calculatePosition = (triggerEl, boxEl, position, maxWidth, minWidth, space
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, position, space, windowWidth, windowHeight)
31
- : calculatePositionBasedOnYAxis(triggerRect, boxEl, position, space, windowWidth, windowHeight));
30
+ ? calculatePositionBasedOnXAxis(triggerRect, boxEl, e, position, space, windowWidth, windowHeight)
31
+ : calculatePositionBasedOnYAxis(triggerRect, boxEl, e, position, space, windowWidth, windowHeight));
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, position, space, windowWidth, windowHeight) => {
37
+ const calculatePositionBasedOnXAxis = (triggerRect, boxEl, e, position, space, windowWidth, windowHeight) => {
38
+ var _a, _b;
38
39
  // left & width
39
40
  let left;
40
41
  const width = boxEl.offsetWidth;
42
+ const triggerLeft = (_a = e === null || e === void 0 ? void 0 : e.clientX) !== null && _a !== void 0 ? _a : triggerRect.left;
43
+ const triggerWidth = e ? 0 : triggerRect.width;
41
44
  const diffLeft = triggerRect.left - (space + width);
42
- const diffRight = windowWidth - (triggerRect.left + triggerRect.width + space + width);
45
+ const diffRight = windowWidth - (triggerLeft + triggerWidth + space + width);
43
46
  if ((position === types_1.Position.LEFT && (diffLeft >= 0 || diffLeft >= diffRight))
44
47
  || (position === types_1.Position.RIGHT && diffRight < 0 && diffLeft > diffRight)) {
45
48
  left = diffLeft;
46
49
  }
47
50
  else {
48
- left = triggerRect.left + triggerRect.width + space;
51
+ left = triggerLeft + triggerWidth + space;
49
52
  }
50
53
  // top & height
51
54
  let top;
52
55
  let height = boxEl.offsetHeight;
53
- const triggerHeight = triggerRect.height + triggerRect.top <= windowHeight ? triggerRect.height : (windowHeight - triggerRect.top);
56
+ const triggerTop = (_b = e === null || e === void 0 ? void 0 : e.clientY) !== null && _b !== void 0 ? _b : triggerRect.top;
57
+ const triggerHeight = e ? 0 : triggerRect.height + triggerRect.top <= windowHeight ? triggerRect.height : (windowHeight - triggerRect.top);
54
58
  const diffBottom = windowHeight - (triggerRect.top + height);
55
59
  const diffTop = (triggerRect.top + triggerHeight) - height;
56
60
  if (diffBottom >= 0 || diffBottom >= diffTop) {
57
- height = diffBottom > 0 ? height : windowHeight - (triggerRect.top + height);
58
- top = triggerRect.top;
61
+ height = diffBottom > 0 ? height : windowHeight - (triggerTop + height);
62
+ top = triggerTop;
59
63
  }
60
64
  else {
61
65
  height = height + Math.min(diffTop, 0);
62
- top = (height > triggerHeight) ? ((triggerRect.top + triggerHeight) - height) : triggerRect.top;
66
+ top = (height > triggerHeight) ? ((triggerTop + triggerHeight) - height) : triggerTop;
63
67
  }
64
68
  return `
65
69
  left: ${left}px;
@@ -71,31 +75,36 @@ const calculatePositionBasedOnXAxis = (triggerRect, boxEl, position, space, wind
71
75
  /**
72
76
  * Calculates fixed box position and sized based on Y axis position.
73
77
  */
74
- const calculatePositionBasedOnYAxis = (triggerRect, boxEl, position, space, windowWidth, windowHeight) => {
78
+ const calculatePositionBasedOnYAxis = (triggerRect, boxEl, e, position, space, windowWidth, windowHeight) => {
79
+ var _a, _b;
75
80
  // left & width
76
81
  let left;
77
82
  const width = boxEl.offsetWidth;
78
- const diffLeft = windowWidth - (triggerRect.left + width);
79
- const diffRight = triggerRect.left - width;
83
+ const triggerLeft = (_a = e === null || e === void 0 ? void 0 : e.clientX) !== null && _a !== void 0 ? _a : triggerRect.left;
84
+ const triggerWidth = e ? 0 : triggerRect.width;
85
+ const diffLeft = windowWidth - (triggerLeft + width);
86
+ const diffRight = triggerLeft - width;
80
87
  if (diffLeft >= 0 || diffLeft >= diffRight) {
81
- left = triggerRect.left;
88
+ left = triggerLeft;
82
89
  }
83
90
  else {
84
- left = triggerRect.left + triggerRect.width - width;
91
+ left = triggerLeft + triggerWidth - width;
85
92
  }
86
93
  // top & height
87
94
  let top;
88
95
  let height = boxEl.offsetHeight;
89
- const diffBottom = windowHeight - (triggerRect.top + triggerRect.height + height + space);
90
- const diffTop = (triggerRect.top + triggerRect.height) - (height + 1);
96
+ const triggerTop = (_b = e === null || e === void 0 ? void 0 : e.clientY) !== null && _b !== void 0 ? _b : triggerRect.top;
97
+ const triggerHeight = e ? 0 : triggerRect.height;
98
+ const diffBottom = windowHeight - (triggerTop + triggerHeight + height + space);
99
+ const diffTop = (triggerTop + triggerHeight) - (height + 1);
91
100
  if ((position === types_1.Position.BOTTOM && (diffBottom >= 0 || diffBottom >= diffTop))
92
101
  || (position === types_1.Position.TOP && diffTop < 0 && diffBottom > diffTop)) {
93
- height = diffBottom > 0 ? height : (windowHeight - (triggerRect.top + triggerRect.height + space));
94
- top = triggerRect.top + triggerRect.height + space;
102
+ height = diffBottom > 0 ? height : (windowHeight - (triggerTop + triggerHeight + space));
103
+ top = triggerTop + triggerHeight + space;
95
104
  }
96
105
  else {
97
106
  height = diffTop > 0 ? height : triggerRect.top;
98
- top = (triggerRect.top + triggerRect.height) - (height + 1);
107
+ top = (triggerTop + triggerHeight) - (height + 1);
99
108
  }
100
109
  return `
101
110
  left: ${left}px;