@wireapp/react-ui-kit 9.22.0 → 9.23.1

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.
@@ -12,7 +12,7 @@ const SelectContainer = (props) => {
12
12
  };
13
13
  exports.SelectContainer = SelectContainer;
14
14
  const isGroup = (options) => {
15
- return options.length > 0 && 'options' in options[0];
15
+ return options?.length > 0 && 'options' in options[0];
16
16
  };
17
17
  exports.isGroup = isGroup;
18
18
  const DropdownIndicator = (props) => {
@@ -1 +1 @@
1
- {"version":3,"file":"Tooltip.d.ts","sourceRoot":"","sources":["../../src/Form/Tooltip.tsx"],"names":[],"mappings":"AAmBA,OAAO,EAAC,SAAS,EAA0B,SAAS,EAAmB,MAAM,OAAO,CAAC;AAsHrF,UAAU,YAAY,CAAC,CAAC,GAAG,cAAc,CAAE,SAAQ,SAAS,CAAC,CAAC,CAAC;IAC7D,IAAI,EAAE,SAAS,CAAC;IAChB,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAID,eAAO,MAAM,OAAO,2BAA0B,YAAY,qDAiCzD,CAAC"}
1
+ {"version":3,"file":"Tooltip.d.ts","sourceRoot":"","sources":["../../src/Form/Tooltip.tsx"],"names":[],"mappings":"AAmBA,OAAO,EAAC,SAAS,EAA0B,SAAS,EAAmB,MAAM,OAAO,CAAC;AAoJrF,UAAU,YAAY,CAAC,CAAC,GAAG,cAAc,CAAE,SAAQ,SAAS,CAAC,CAAC,CAAC;IAC7D,IAAI,EAAE,SAAS,CAAC;IAChB,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAID,eAAO,MAAM,OAAO,2BAA0B,YAAY,qDAmCzD,CAAC"}
@@ -62,52 +62,78 @@ const tooltipStyle = theme => ({
62
62
  position: 'absolute',
63
63
  },
64
64
  });
65
- const PortalComponent = ({ children, bounding, selector = '#wire-app' }) => {
65
+ const TooltipArrow = ({ wrapperRect }) => {
66
+ const tooltipArrowRef = (element) => {
67
+ if (!element) {
68
+ return;
69
+ }
70
+ const { parentElement } = element;
71
+ if (!parentElement) {
72
+ return;
73
+ }
74
+ const tooltipRect = parentElement.getBoundingClientRect();
75
+ const isTouchingLeftEdge = wrapperRect.x <= tooltipRect.width / 2 + paddingDistance * 2;
76
+ const isTouchingRightEdge = wrapperRect.left + tooltipRect.width / 2 + paddingDistance * 2 >= window.innerWidth;
77
+ if (isTouchingLeftEdge) {
78
+ element.style.left = `${wrapperRect.left - paddingDistance}px`;
79
+ }
80
+ else if (isTouchingRightEdge) {
81
+ const calculateX = window.innerWidth - wrapperRect.right - paddingDistance;
82
+ element.style.right = `${calculateX}px`;
83
+ }
84
+ else {
85
+ element.style.left = `50%`;
86
+ element.style.transform = `translateX(-50%)`;
87
+ }
88
+ };
89
+ return (0, jsx_runtime_1.jsx)("div", { ref: tooltipArrowRef, className: "tooltip-arrow" });
90
+ };
91
+ const PortalComponent = ({ children, wrapperRect, selector = '#wire-app' }) => {
66
92
  const [isTouchingTop, setIsTouchingTop] = (0, react_1.useState)(false);
67
93
  const targetElement = document.querySelector(selector);
68
- if (!targetElement) {
94
+ if (!targetElement || !wrapperRect) {
69
95
  return null;
70
96
  }
71
97
  const tooltipRef = (element) => {
72
- if (!bounding || !element) {
98
+ if (!element) {
73
99
  return;
74
100
  }
75
- const isTouchingTopEdge = bounding.y <= element.clientHeight + paddingDistance * 2;
101
+ const tooltipRect = element.getBoundingClientRect();
102
+ const isTouchingTopEdge = wrapperRect.y <= tooltipRect.height + paddingDistance * 2;
76
103
  setIsTouchingTop(isTouchingTopEdge);
77
- const elementWidth = (element.scrollWidth - bounding.width) / 2;
78
- element.style.left = `${bounding.x - elementWidth}px`;
79
- if (isTouchingTopEdge) {
80
- element.style.top = `${bounding.y + bounding.height}px`;
104
+ const isTouchingLeftEdge = wrapperRect.x <= tooltipRect.width / 2 + paddingDistance * 2;
105
+ const isTouchingRightEdge = wrapperRect.left + tooltipRect.width / 2 + paddingDistance * 2 >= window.innerWidth;
106
+ if (isTouchingLeftEdge) {
107
+ element.style.left = `${paddingDistance}px`;
108
+ }
109
+ else if (isTouchingRightEdge) {
110
+ element.style.right = `${paddingDistance}px`;
81
111
  }
82
112
  else {
83
- element.style.top = `${bounding.y - element.clientHeight}px`;
113
+ const elementWidth = (element.scrollWidth - wrapperRect.width) / 2;
114
+ element.style.left = `${wrapperRect.x - elementWidth}px`;
84
115
  }
85
- };
86
- const tooltipArrowRef = (element) => {
87
- if (!element) {
88
- return;
116
+ if (isTouchingTopEdge) {
117
+ element.style.top = `${wrapperRect.y + wrapperRect.height}px`;
89
118
  }
90
- const { parentElement } = element;
91
- if (!parentElement) {
92
- return;
119
+ else {
120
+ element.style.top = `${wrapperRect.y - element.clientHeight}px`;
93
121
  }
94
- const parentElementRect = parentElement.getBoundingClientRect();
95
- element.style.left = `${parentElementRect.width / 2 - paddingDistance}px`;
96
122
  };
97
- return (0, react_dom_1.createPortal)((0, jsx_runtime_1.jsxs)("div", { ref: tooltipRef, className: "tooltip", css: (theme) => tooltipStyle(theme), "data-position": isTouchingTop ? 'bottom' : 'top', children: [(0, jsx_runtime_1.jsx)("div", { ref: tooltipArrowRef, className: "tooltip-arrow" }), (0, jsx_runtime_1.jsx)("div", { className: "tooltip-content", "data-testid": "tooltip-content", children: children })] }), targetElement);
123
+ return (0, react_dom_1.createPortal)((0, jsx_runtime_1.jsxs)("div", { ref: tooltipRef, className: "tooltip", css: (theme) => tooltipStyle(theme), "data-position": isTouchingTop ? 'bottom' : 'top', children: [(0, jsx_runtime_1.jsx)(TooltipArrow, { wrapperRect: wrapperRect }), (0, jsx_runtime_1.jsx)("div", { className: "tooltip-content", "data-testid": "tooltip-content", children: children })] }), targetElement);
98
124
  };
99
- const filterTooltipProps = (props) => (0, util_1.filterProps)(props, ['body']);
125
+ const filterTooltipProps = (props) => (0, util_1.filterProps)(props, ['body', 'selector']);
100
126
  const Tooltip = ({ children, ...props }) => {
101
127
  const [isHovered, setIsHovered] = (0, react_1.useState)(false);
102
- const boundingRectRef = (0, react_1.useRef)();
128
+ const wrapperRectRef = (0, react_1.useRef)();
103
129
  const filteredProps = filterTooltipProps(props);
104
130
  const { body, selector = '#wire-app' } = props;
105
- const onElementEnter = (event) => {
106
- const boundingRect = event.currentTarget.getBoundingClientRect();
131
+ const onElementEnter = ({ currentTarget }) => {
132
+ const wrapperRect = currentTarget.getBoundingClientRect();
107
133
  setIsHovered(true);
108
- boundingRectRef.current = boundingRect;
134
+ wrapperRectRef.current = wrapperRect;
109
135
  };
110
136
  const onElementLeave = () => setIsHovered(false);
111
- return ((0, jsx_runtime_1.jsxs)("div", { role: "presentation", ...filteredProps, "data-testid": "tooltip-wrapper", onMouseEnter: onElementEnter, onMouseLeave: onElementLeave, onFocus: onElementEnter, onBlur: onElementLeave, ...props, children: [children, isHovered && ((0, jsx_runtime_1.jsx)(PortalComponent, { bounding: boundingRectRef.current, selector: selector, children: body }))] }));
137
+ return ((0, jsx_runtime_1.jsxs)("div", { role: "presentation", "data-testid": "tooltip-wrapper", onMouseEnter: onElementEnter, onMouseLeave: onElementLeave, onFocus: onElementEnter, onBlur: onElementLeave, style: { width: 'max-content' }, ...filteredProps, children: [(0, jsx_runtime_1.jsx)("div", { id: "childrenElement", children: children }), isHovered && ((0, jsx_runtime_1.jsx)(PortalComponent, { wrapperRect: wrapperRectRef.current, selector: selector, children: body }))] }));
112
138
  };
113
139
  exports.Tooltip = Tooltip;
package/package.json CHANGED
@@ -16,8 +16,8 @@
16
16
  },
17
17
  "devDependencies": {
18
18
  "@babel/cli": "7.24.8",
19
- "@babel/core": "7.24.9",
20
- "@babel/preset-env": "7.25.0",
19
+ "@babel/core": "7.25.2",
20
+ "@babel/preset-env": "7.25.3",
21
21
  "@babel/preset-react": "7.24.7",
22
22
  "@babel/preset-typescript": "7.24.7",
23
23
  "@emotion/babel-preset-css-prop": "^11.10.0",
@@ -70,6 +70,6 @@
70
70
  "test:watch": "jest --watch",
71
71
  "test:update": "jest --updateSnapshot"
72
72
  },
73
- "version": "9.22.0",
74
- "gitHead": "4d0125c6e80d6f1753631221f1be493861a5cefd"
73
+ "version": "9.23.1",
74
+ "gitHead": "770b4a01d2b88aa3e07a0f737c481fcb0819bcc6"
75
75
  }