@loomhq/lens 10.29.3 → 10.30.0

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.
@@ -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";
@@ -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: 'clippingParents' | Element;
14
+ };
15
+ export default Popover;
@@ -0,0 +1,94 @@
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
+ const placements = {
18
+ topLeft: 'top-start',
19
+ topCenter: 'top',
20
+ topRight: 'top-end',
21
+ bottomLeft: 'bottom-start',
22
+ bottomCenter: 'bottom',
23
+ bottomRight: 'bottom-end',
24
+ leftTop: 'left-start',
25
+ leftCenter: 'left',
26
+ leftBottom: 'left-end',
27
+ rightTop: 'right-start',
28
+ rightCenter: 'right',
29
+ rightBottom: 'right-end',
30
+ };
31
+ const Wrapper = styled.div `
32
+ position: relative;
33
+ `;
34
+ const ContentWrapper = styled.div `
35
+ ${props => props.zIndex && `z-index: ${props.zIndex}`};
36
+ `;
37
+ 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"]);
39
+ const unitOffset = offset * unit;
40
+ const unitBoundaryOffset = boundaryOffset * unit;
41
+ const { x, y, reference, floating, strategy, update, refs } = useFloating({
42
+ placement: placements[placement],
43
+ middleware: [
44
+ flip({ fallbackPlacements: ['top', 'bottom'] }),
45
+ shift({
46
+ padding: unitBoundaryOffset,
47
+ boundary: boundaryElement,
48
+ }),
49
+ floatingUiOffset(unitOffset),
50
+ ],
51
+ strategy: 'fixed',
52
+ });
53
+ useEffect(() => {
54
+ if (!refs.reference.current || !refs.floating.current) {
55
+ return;
56
+ }
57
+ const parents = [
58
+ ...getScrollParents(refs.reference.current),
59
+ ...getScrollParents(refs.floating.current),
60
+ ];
61
+ parents.forEach(parent => {
62
+ parent.addEventListener('scroll', update);
63
+ parent.addEventListener('resize', update);
64
+ });
65
+ return () => {
66
+ parents.forEach(parent => {
67
+ parent.removeEventListener('scroll', update);
68
+ parent.removeEventListener('resize', update);
69
+ });
70
+ };
71
+ }, [refs.reference, refs.floating, update, isOpen]);
72
+ const [rootNode, setRootNode] = useState(null);
73
+ useEffect(() => {
74
+ if (rootId) {
75
+ setRootNode(document.getElementById(rootId));
76
+ }
77
+ }, [rootId]);
78
+ const contentProps = {
79
+ zIndex,
80
+ ref: floating,
81
+ style: {
82
+ position: strategy,
83
+ top: y !== null && y !== void 0 ? y : '',
84
+ left: x !== null && x !== void 0 ? x : '',
85
+ },
86
+ };
87
+ return (React.createElement(Wrapper, null,
88
+ React.createElement("div", Object.assign({ ref: reference }, props), children),
89
+ isOpen && (React.createElement(React.Fragment, null,
90
+ !rootNode && (React.createElement(ContentWrapper, Object.assign({}, contentProps), content)),
91
+ rootNode &&
92
+ ReactDOM.createPortal(React.createElement(ContentWrapper, Object.assign({}, contentProps), content), rootNode)))));
93
+ };
94
+ export default Popover;
@@ -1 +1,2 @@
1
1
  export { default as useMedia } from "./use-media.js";
2
+ export { default as useOnClickOutside } from "./use-on-click-outside.js";
@@ -1 +1,2 @@
1
1
  export { default as useMedia } from './use-media.js';
2
+ export { default as useOnClickOutside } from './use-on-click-outside.js';
@@ -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.29.3",
3
+ "version": "10.30.0",
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",