@loomhq/lens 10.29.3 → 10.31.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.
- package/dist/components/index.d.ts +1 -0
- package/dist/components/index.js +1 -0
- package/dist/components/popover/popover.d.ts +15 -0
- package/dist/components/popover/popover.js +127 -0
- package/dist/hooks/index.d.ts +1 -0
- package/dist/hooks/index.js +1 -0
- package/dist/hooks/use-on-click-outside.d.ts +1 -0
- package/dist/hooks/use-on-click-outside.js +17 -0
- package/package.json +2 -1
|
@@ -22,6 +22,7 @@ export { default as Switch } from "./switch/switch";
|
|
|
22
22
|
export { default as Logo } from "./logo/logo";
|
|
23
23
|
export { default as Radio } from "./radio/radio";
|
|
24
24
|
export { default as Pill } from "./pill/pill";
|
|
25
|
+
export { default as Popover } from "./popover/popover";
|
|
25
26
|
export { default as Illustration } from "./illustration/illustration";
|
|
26
27
|
export { default as Arrange } from "./arrange/arrange";
|
|
27
28
|
export { default as ColorPicker } from "./color-picker/color-picker";
|
package/dist/components/index.js
CHANGED
|
@@ -34,6 +34,7 @@ export { ListRow } from './list/list';
|
|
|
34
34
|
export { default as Tabs } from './tabs/tabs';
|
|
35
35
|
export { Tab } from './tabs/tabs';
|
|
36
36
|
export { default as Pill } from './pill/pill';
|
|
37
|
+
export { default as Popover } from './popover/popover';
|
|
37
38
|
export { default as Illustration } from './illustration/illustration';
|
|
38
39
|
export { default as Arrange } from './arrange/arrange';
|
|
39
40
|
export { default as Split } from './split/split';
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
declare type PlacementProps = 'topLeft' | 'topCenter' | 'topRight' | 'bottomLeft' | 'bottomCenter' | 'bottomRight' | 'leftTop' | 'leftCenter' | 'leftBottom' | 'rightTop' | 'rightCenter' | 'rightBottom';
|
|
3
|
+
declare const Popover: ({ children, content, offset, boundaryOffset, isOpen, zIndex, placement, rootId, boundaryElement, ...props }: PopoverProps) => JSX.Element;
|
|
4
|
+
declare type PopoverProps = {
|
|
5
|
+
children?: React.ReactNode;
|
|
6
|
+
content?: React.ReactNode;
|
|
7
|
+
offset?: number;
|
|
8
|
+
boundaryOffset?: number;
|
|
9
|
+
zIndex?: number | string;
|
|
10
|
+
isOpen?: boolean;
|
|
11
|
+
placement?: PlacementProps;
|
|
12
|
+
rootId?: string;
|
|
13
|
+
boundaryElement?: 'body' | Element;
|
|
14
|
+
};
|
|
15
|
+
export default Popover;
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
2
|
+
var t = {};
|
|
3
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
4
|
+
t[p] = s[p];
|
|
5
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
6
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
7
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
8
|
+
t[p[i]] = s[p[i]];
|
|
9
|
+
}
|
|
10
|
+
return t;
|
|
11
|
+
};
|
|
12
|
+
import { flip, offset as floatingUiOffset, getScrollParents, shift, useFloating, } from '@floating-ui/react-dom';
|
|
13
|
+
import React, { useEffect, useState } from 'react';
|
|
14
|
+
import ReactDOM from 'react-dom';
|
|
15
|
+
import styled from '@emotion/styled';
|
|
16
|
+
import { unit } from '../../variables';
|
|
17
|
+
import { CSSTransitionGroup } from 'react-transition-group';
|
|
18
|
+
const duration = 200;
|
|
19
|
+
const placements = {
|
|
20
|
+
topLeft: 'top-start',
|
|
21
|
+
topCenter: 'top',
|
|
22
|
+
topRight: 'top-end',
|
|
23
|
+
bottomLeft: 'bottom-start',
|
|
24
|
+
bottomCenter: 'bottom',
|
|
25
|
+
bottomRight: 'bottom-end',
|
|
26
|
+
leftTop: 'left-start',
|
|
27
|
+
leftCenter: 'left',
|
|
28
|
+
leftBottom: 'left-end',
|
|
29
|
+
rightTop: 'right-start',
|
|
30
|
+
rightCenter: 'right',
|
|
31
|
+
rightBottom: 'right-end',
|
|
32
|
+
};
|
|
33
|
+
const Wrapper = styled.div `
|
|
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
|
+
}
|
|
53
|
+
`;
|
|
54
|
+
const ContentWrapper = styled.div `
|
|
55
|
+
${props => props.zIndex && `z-index: ${props.zIndex}`};
|
|
56
|
+
`;
|
|
57
|
+
const Popover = (_a) => {
|
|
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"]);
|
|
59
|
+
const unitOffset = offset * unit;
|
|
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
|
+
};
|
|
74
|
+
const { x, y, reference, floating, strategy, update, refs } = useFloating({
|
|
75
|
+
placement: placements[placement],
|
|
76
|
+
middleware: [
|
|
77
|
+
flip({ fallbackPlacements: ['top', 'bottom'] }),
|
|
78
|
+
shift({
|
|
79
|
+
padding: unitBoundaryOffset,
|
|
80
|
+
boundary: getBoundaryElement(),
|
|
81
|
+
}),
|
|
82
|
+
floatingUiOffset(unitOffset),
|
|
83
|
+
],
|
|
84
|
+
strategy: rootId ? 'fixed' : 'absolute',
|
|
85
|
+
});
|
|
86
|
+
useEffect(() => {
|
|
87
|
+
if (!refs.reference.current || !refs.floating.current) {
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
const parents = [
|
|
91
|
+
...getScrollParents(refs.reference.current),
|
|
92
|
+
...getScrollParents(refs.floating.current),
|
|
93
|
+
];
|
|
94
|
+
parents.forEach(parent => {
|
|
95
|
+
parent.addEventListener('scroll', update);
|
|
96
|
+
parent.addEventListener('resize', update);
|
|
97
|
+
});
|
|
98
|
+
return () => {
|
|
99
|
+
parents.forEach(parent => {
|
|
100
|
+
parent.removeEventListener('scroll', update);
|
|
101
|
+
parent.removeEventListener('resize', update);
|
|
102
|
+
});
|
|
103
|
+
};
|
|
104
|
+
}, [refs.reference, refs.floating, update, isOpen]);
|
|
105
|
+
const [rootNode, setRootNode] = useState(null);
|
|
106
|
+
useEffect(() => {
|
|
107
|
+
if (rootId) {
|
|
108
|
+
setRootNode(document === null || document === void 0 ? void 0 : document.getElementById(rootId));
|
|
109
|
+
}
|
|
110
|
+
}, [rootId]);
|
|
111
|
+
const contentProps = {
|
|
112
|
+
zIndex,
|
|
113
|
+
ref: floating,
|
|
114
|
+
style: {
|
|
115
|
+
position: strategy,
|
|
116
|
+
top: y !== null && y !== void 0 ? y : '',
|
|
117
|
+
left: x !== null && x !== void 0 ? x : '',
|
|
118
|
+
},
|
|
119
|
+
};
|
|
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,
|
|
123
|
+
!rootNode && (React.createElement(ContentWrapper, Object.assign({}, contentProps), content)),
|
|
124
|
+
rootNode &&
|
|
125
|
+
ReactDOM.createPortal(React.createElement(ContentWrapper, Object.assign({}, contentProps), content), rootNode))))));
|
|
126
|
+
};
|
|
127
|
+
export default Popover;
|
package/dist/hooks/index.d.ts
CHANGED
package/dist/hooks/index.js
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function useOnClickOutside(ref: any, handler: any): void;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
export default function useOnClickOutside(ref, handler) {
|
|
3
|
+
React.useEffect(() => {
|
|
4
|
+
const listener = event => {
|
|
5
|
+
if (!ref.current || ref.current.contains(event.target)) {
|
|
6
|
+
return;
|
|
7
|
+
}
|
|
8
|
+
handler(event);
|
|
9
|
+
};
|
|
10
|
+
document.addEventListener('mousedown', listener);
|
|
11
|
+
document.addEventListener('touchstart', listener);
|
|
12
|
+
return () => {
|
|
13
|
+
document.removeEventListener('mousedown', listener);
|
|
14
|
+
document.removeEventListener('touchstart', listener);
|
|
15
|
+
};
|
|
16
|
+
}, [ref, handler]);
|
|
17
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@loomhq/lens",
|
|
3
|
-
"version": "10.
|
|
3
|
+
"version": "10.31.1",
|
|
4
4
|
"scripts": {
|
|
5
5
|
"dev": "next",
|
|
6
6
|
"build:next": "next build",
|
|
@@ -22,6 +22,7 @@
|
|
|
22
22
|
]
|
|
23
23
|
},
|
|
24
24
|
"dependencies": {
|
|
25
|
+
"@floating-ui/react-dom": "^0.4.3",
|
|
25
26
|
"downshift": "^5.4.7",
|
|
26
27
|
"lodash": "^4.17.21",
|
|
27
28
|
"react-color": "^2.19.3",
|