@wonderflow/react-components 2.15.0 → 2.15.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/dropdown/dropdown.d.ts +1 -1
- package/dropdown/dropdown.js +33 -51
- package/dropdown/dropdown.module.css +0 -5
- package/package.json +1 -1
- package/themes/dark.css +1 -1
- package/themes/light.css +1 -1
- package/themes.css +3 -3
- package/tooltip/tooltip.js +16 -4
package/dropdown/dropdown.d.ts
CHANGED
|
@@ -7,7 +7,7 @@ export declare type DropdownProps = PropsWithClass & {
|
|
|
7
7
|
placement?: AutoPlacement | BasePlacement | VariationPlacement;
|
|
8
8
|
};
|
|
9
9
|
export declare const Dropdown: {
|
|
10
|
-
({ className, children, trigger, offset, placement
|
|
10
|
+
({ className, children, trigger, offset, placement }: DropdownProps): JSX.Element;
|
|
11
11
|
Menu: React.ForwardRefExoticComponent<PropsWithClass & {
|
|
12
12
|
children: React.ReactNode;
|
|
13
13
|
} & React.RefAttributes<HTMLUListElement>>;
|
package/dropdown/dropdown.js
CHANGED
|
@@ -1,49 +1,16 @@
|
|
|
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
1
|
import clsx from 'clsx';
|
|
13
|
-
import React, { useState,
|
|
14
|
-
import {
|
|
15
|
-
import { Dropdown as DropdownClass,
|
|
2
|
+
import React, { useState, Children, cloneElement, useCallback } from 'react';
|
|
3
|
+
import { useKey } from 'react-use';
|
|
4
|
+
import { Dropdown as DropdownClass, PopUp } from './dropdown.module.css';
|
|
16
5
|
import { useUIDSeed } from 'react-uid';
|
|
17
6
|
import { useFocusWithin } from '@react-aria/interactions';
|
|
18
7
|
import { DropdownMenu } from './dropdown-menu';
|
|
19
8
|
import { DropdownItem } from './dropdown-item';
|
|
20
|
-
import {
|
|
21
|
-
import { motion
|
|
22
|
-
export const Dropdown = (
|
|
23
|
-
var { className, children, trigger, offset = 8, placement = 'auto-start' } = _a, props = __rest(_a, ["className", "children", "trigger", "offset", "placement"]);
|
|
24
|
-
const DropDownRef = useRef(null);
|
|
25
|
-
const [isOpen, setIsOpen] = useState(false);
|
|
9
|
+
import { Popper, Target, Content } from 'react-nested-popper';
|
|
10
|
+
import { motion } from 'framer-motion';
|
|
11
|
+
export const Dropdown = ({ className, children, trigger, offset = 8, placement = 'auto-start' }) => {
|
|
26
12
|
const seedID = useUIDSeed();
|
|
27
|
-
const [
|
|
28
|
-
const [popUpElement, setPopUpElement] = useState(null);
|
|
29
|
-
const { styles: popUpStyles, attributes: popUpAttributes } = usePopper(triggerRef, popUpElement, {
|
|
30
|
-
placement: placement,
|
|
31
|
-
modifiers: [
|
|
32
|
-
{
|
|
33
|
-
name: 'flip',
|
|
34
|
-
enabled: true,
|
|
35
|
-
options: {
|
|
36
|
-
fallbackPlacements: ['bottom', 'top']
|
|
37
|
-
}
|
|
38
|
-
},
|
|
39
|
-
{
|
|
40
|
-
name: 'offset',
|
|
41
|
-
options: {
|
|
42
|
-
offset: [0, offset]
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
]
|
|
46
|
-
});
|
|
13
|
+
const [isOpen, setIsOpen] = useState(false);
|
|
47
14
|
const { focusWithinProps } = useFocusWithin({
|
|
48
15
|
onFocusWithin: () => null,
|
|
49
16
|
onBlurWithin: (e) => e.relatedTarget && setIsOpen(false),
|
|
@@ -52,22 +19,37 @@ export const Dropdown = (_a) => {
|
|
|
52
19
|
const handleOpen = useCallback((action) => () => {
|
|
53
20
|
setIsOpen(action);
|
|
54
21
|
}, []);
|
|
55
|
-
useKey('Escape', handleOpen(false));
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
React.createElement("div", { className: Trigger }, Children.map(trigger, (child) => cloneElement(child, {
|
|
59
|
-
onClick: handleOpen(!isOpen),
|
|
22
|
+
useKey('Escape', () => handleOpen(false));
|
|
23
|
+
return (React.createElement(Popper, { show: isOpen, outsideClickType: "all", onOutsideClick: handleOpen(false), onTargetClick: handleOpen(!isOpen), usePortal: false },
|
|
24
|
+
React.createElement(Target, { className: clsx(DropdownClass, className) }, Children.map(trigger, (child) => cloneElement(child, {
|
|
60
25
|
id: seedID('dropdown-trigger'),
|
|
61
|
-
ref: setTriggerRef,
|
|
62
26
|
'aria-haspopup': 'true',
|
|
63
27
|
'aria-controls': seedID('dropdown-menu'),
|
|
64
28
|
'aria-expanded': isOpen
|
|
65
29
|
}))),
|
|
66
|
-
React.createElement(
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
30
|
+
React.createElement(Content, { className: PopUp, popperOptions: {
|
|
31
|
+
placement: placement,
|
|
32
|
+
modifiers: [
|
|
33
|
+
{
|
|
34
|
+
name: 'flip',
|
|
35
|
+
enabled: true,
|
|
36
|
+
options: {
|
|
37
|
+
fallbackPlacements: ['bottom', 'top']
|
|
38
|
+
}
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
name: 'offset',
|
|
42
|
+
options: {
|
|
43
|
+
offset: [0, offset]
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
]
|
|
47
|
+
} },
|
|
48
|
+
React.createElement(motion.div, { animate: isOpen ? { y: 5, opacity: 1 } : { y: 0, opacity: 0 }, transition: { ease: 'easeOut', duration: 0.1 } },
|
|
49
|
+
React.createElement("div", Object.assign({}, focusWithinProps), Children.map(children, (child) => cloneElement(child, {
|
|
50
|
+
id: seedID('dropdown-menu'),
|
|
51
|
+
'aria-labelledby': seedID('dropdown-trigger')
|
|
52
|
+
})))))));
|
|
71
53
|
};
|
|
72
54
|
Dropdown.Menu = DropdownMenu;
|
|
73
55
|
Dropdown.Item = DropdownItem;
|
package/package.json
CHANGED
package/themes/dark.css
CHANGED
package/themes/light.css
CHANGED
package/themes.css
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
color: var(--global-foreground);
|
|
5
5
|
/**
|
|
6
6
|
* Do not edit directly
|
|
7
|
-
* Generated on Mon, 20 Sep 2021
|
|
7
|
+
* Generated on Mon, 20 Sep 2021 13:39:18 GMT
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
10
|
|
|
@@ -50,7 +50,7 @@
|
|
|
50
50
|
color: var(--global-foreground);
|
|
51
51
|
/**
|
|
52
52
|
* Do not edit directly
|
|
53
|
-
* Generated on Mon, 20 Sep 2021
|
|
53
|
+
* Generated on Mon, 20 Sep 2021 13:39:18 GMT
|
|
54
54
|
*/
|
|
55
55
|
|
|
56
56
|
|
|
@@ -97,7 +97,7 @@
|
|
|
97
97
|
color: var(--global-foreground);
|
|
98
98
|
/**
|
|
99
99
|
* Do not edit directly
|
|
100
|
-
* Generated on Mon, 20 Sep 2021
|
|
100
|
+
* Generated on Mon, 20 Sep 2021 13:39:18 GMT
|
|
101
101
|
*/
|
|
102
102
|
|
|
103
103
|
|
package/tooltip/tooltip.js
CHANGED
|
@@ -8,13 +8,20 @@ import { Popper, Target, Content } from 'react-nested-popper';
|
|
|
8
8
|
export const Tooltip = ({ children, className, trigger, placement = 'bottom-start', style, show, delay = 700 }) => {
|
|
9
9
|
const seedID = useUIDSeed();
|
|
10
10
|
const [visible, setVisible] = useState(false);
|
|
11
|
+
const [internalDelay, setInternalDelay] = useState(delay);
|
|
11
12
|
const [debouncedVisible, setDebouncedVisible] = useState(visible);
|
|
12
13
|
const [, cancel] = useDebounce(() => {
|
|
13
14
|
setDebouncedVisible(visible);
|
|
14
|
-
},
|
|
15
|
+
}, internalDelay, [visible]);
|
|
15
16
|
const { focusWithinProps } = useFocusWithin({
|
|
16
|
-
onFocusWithin: () =>
|
|
17
|
-
|
|
17
|
+
onFocusWithin: () => {
|
|
18
|
+
setInternalDelay(0);
|
|
19
|
+
setVisible(true);
|
|
20
|
+
},
|
|
21
|
+
onBlurWithin: () => {
|
|
22
|
+
setInternalDelay(delay);
|
|
23
|
+
setVisible(false);
|
|
24
|
+
},
|
|
18
25
|
onFocusWithinChange: () => null
|
|
19
26
|
});
|
|
20
27
|
useEffect(() => {
|
|
@@ -24,7 +31,12 @@ export const Tooltip = ({ children, className, trigger, placement = 'bottom-star
|
|
|
24
31
|
React.createElement(Target, Object.assign({ onMouseEnter: () => setVisible(true), onMouseLeave: () => setVisible(false), onClick: () => null, style: Object.assign({}, style), className: TriggerClass }, focusWithinProps), Children.map(trigger, (child) => cloneElement(child, {
|
|
25
32
|
'aria-describedby': seedID('tooltip-content')
|
|
26
33
|
}))),
|
|
27
|
-
React.createElement(Content, { className: clsx(TooltipClass, className),
|
|
34
|
+
React.createElement(Content, { className: clsx(TooltipClass, className), includeArrow: true, innerRef: (el) => {
|
|
35
|
+
if (el) {
|
|
36
|
+
el.dataset.elevation = '2';
|
|
37
|
+
el.dataset.theme = 'dark';
|
|
38
|
+
}
|
|
39
|
+
}, arrowClassName: Arrow, popperOptions: {
|
|
28
40
|
placement: placement,
|
|
29
41
|
modifiers: [
|
|
30
42
|
{
|