@loomhq/lens 10.30.0 → 10.31.2

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.
@@ -10,6 +10,6 @@ declare type PopoverProps = {
10
10
  isOpen?: boolean;
11
11
  placement?: PlacementProps;
12
12
  rootId?: string;
13
- boundaryElement: 'clippingParents' | Element;
13
+ boundaryElement?: 'body' | Element;
14
14
  };
15
15
  export default Popover;
@@ -14,6 +14,8 @@ import React, { useEffect, useState } from 'react';
14
14
  import ReactDOM from 'react-dom';
15
15
  import styled from '@emotion/styled';
16
16
  import { unit } from '../../variables';
17
+ import { CSSTransitionGroup } from 'react-transition-group';
18
+ const duration = 200;
17
19
  const placements = {
18
20
  topLeft: 'top-start',
19
21
  topCenter: 'top',
@@ -30,21 +32,52 @@ const placements = {
30
32
  };
31
33
  const Wrapper = styled.div `
32
34
  position: relative;
35
+
36
+ .Popover-enter {
37
+ opacity: 0.01;
38
+ }
39
+
40
+ .Popover-enter.Popover-enter-active {
41
+ opacity: 1;
42
+ transition: opacity ${duration}ms;
43
+ }
44
+
45
+ .Popover-leave {
46
+ opacity: 1;
47
+ }
48
+
49
+ .Popover-leave.Popover-leave-active {
50
+ opacity: 0.01;
51
+ transition: opacity ${duration}ms;
52
+ }
33
53
  `;
34
54
  const ContentWrapper = styled.div `
35
55
  ${props => props.zIndex && `z-index: ${props.zIndex}`};
36
56
  `;
37
57
  const Popover = (_a) => {
38
- var { children, content, offset = 1, boundaryOffset = 1, isOpen, zIndex = 1100, placement = 'topCenter', rootId, boundaryElement = 'clippingParents' } = _a, props = __rest(_a, ["children", "content", "offset", "boundaryOffset", "isOpen", "zIndex", "placement", "rootId", "boundaryElement"]);
58
+ var { children, content, offset = 1, boundaryOffset = 1, isOpen, zIndex = 1100, placement = 'topCenter', rootId, boundaryElement = 'body' } = _a, props = __rest(_a, ["children", "content", "offset", "boundaryOffset", "isOpen", "zIndex", "placement", "rootId", "boundaryElement"]);
39
59
  const unitOffset = offset * unit;
40
60
  const unitBoundaryOffset = boundaryOffset * unit;
61
+ const [bodyElement, setBodyElement] = useState(null);
62
+ useEffect(() => {
63
+ setBodyElement(document === null || document === void 0 ? void 0 : document.querySelector('body'));
64
+ }, []);
65
+ const getBoundaryElement = () => {
66
+ if (boundaryElement) {
67
+ if (boundaryElement === 'body') {
68
+ return bodyElement;
69
+ }
70
+ return boundaryElement;
71
+ }
72
+ return 'clippingParents';
73
+ };
41
74
  const { x, y, reference, floating, strategy, update, refs } = useFloating({
42
75
  placement: placements[placement],
43
76
  middleware: [
44
77
  flip({ fallbackPlacements: ['top', 'bottom'] }),
45
78
  shift({
46
79
  padding: unitBoundaryOffset,
47
- boundary: boundaryElement,
80
+ boundary: getBoundaryElement(),
48
81
  }),
49
82
  floatingUiOffset(unitOffset),
50
83
  ],
@@ -72,7 +105,7 @@ const Popover = (_a) => {
72
105
  const [rootNode, setRootNode] = useState(null);
73
106
  useEffect(() => {
74
107
  if (rootId) {
75
- setRootNode(document.getElementById(rootId));
108
+ setRootNode(document === null || document === void 0 ? void 0 : document.getElementById(rootId));
76
109
  }
77
110
  }, [rootId]);
78
111
  const contentProps = {
@@ -84,11 +117,11 @@ const Popover = (_a) => {
84
117
  left: x !== null && x !== void 0 ? x : '',
85
118
  },
86
119
  };
87
- return (React.createElement(Wrapper, null,
88
- React.createElement("div", Object.assign({ ref: reference }, props), children),
89
- isOpen && (React.createElement(React.Fragment, null,
120
+ return (React.createElement(Wrapper, Object.assign({ ref: reference }, props),
121
+ children,
122
+ React.createElement(CSSTransitionGroup, { transitionName: "Popover", transitionEnterTimeout: duration, transitionLeaveTimeout: duration }, isOpen && (React.createElement(React.Fragment, null,
90
123
  !rootNode && (React.createElement(ContentWrapper, Object.assign({}, contentProps), content)),
91
124
  rootNode &&
92
- ReactDOM.createPortal(React.createElement(ContentWrapper, Object.assign({}, contentProps), content), rootNode)))));
125
+ ReactDOM.createPortal(React.createElement(ContentWrapper, Object.assign({}, contentProps), content), rootNode))))));
93
126
  };
94
127
  export default Popover;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@loomhq/lens",
3
- "version": "10.30.0",
3
+ "version": "10.31.2",
4
4
  "scripts": {
5
5
  "dev": "next",
6
6
  "build:next": "next build",