@wonderflow/react-components 2.15.2 → 2.16.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.
- package/dropdown/dropdown-item.js +2 -2
- package/dropdown/dropdown.js +25 -33
- package/package.json +2 -3
- package/themes/dark.css +1 -1
- package/themes/light.css +1 -1
- package/themes.css +3 -3
- package/tooltip/tooltip.d.ts +1 -0
- package/tooltip/tooltip.js +32 -47
- package/tooltip/tooltip.module.css +9 -4
|
@@ -28,11 +28,11 @@ export const DropdownItem = forwardRef((_a, forwardedRef) => {
|
|
|
28
28
|
onClick();
|
|
29
29
|
}
|
|
30
30
|
}, [handleClick, onClick]);
|
|
31
|
-
const InnerContent = useMemo(() => (React.createElement(Stack, { direction: "row", as: "span", fill: false, horizontalAlign: isIconRight ? 'space-between' : 'start', verticalAlign: "center", columnGap: 8, horizontalPadding: 16, verticalPadding: 8 },
|
|
31
|
+
const InnerContent = useMemo(() => (React.createElement(Stack, { direction: "row", as: "span", fill: false, horizontalAlign: isIconRight ? 'space-between' : 'start', verticalAlign: "center", columnGap: 8, horizontalPadding: 16, verticalPadding: 8, style: { inlineSize: '100%' } },
|
|
32
32
|
icon && (React.createElement(Icon, { "data-dropdown-icon-right": isIconRight, className: IconClass, name: icon, dimension: dimension === 'small' ? 14 : 16 })),
|
|
33
33
|
children)), [children, dimension, icon, isIconRight]);
|
|
34
34
|
return (React.createElement(Wrapper, Object.assign({ ref: itemRef, className: clsx(DropdownItemClass, className), onClick: triggerClick, onKeyDown: handleKeyDown, tabIndex: tabIndex, type: Wrapper === 'button' ? 'button' : undefined, "data-dropdown-item-dimension": dimension }, props), description
|
|
35
|
-
? (React.createElement(Tooltip, { show: focused, placement: "right-start",
|
|
35
|
+
? (React.createElement(Tooltip, { fill: true, show: focused, placement: "right-start", trigger: InnerContent }, description))
|
|
36
36
|
: InnerContent));
|
|
37
37
|
});
|
|
38
38
|
DropdownItem.displayName = 'Dropdown.Item';
|
package/dropdown/dropdown.js
CHANGED
|
@@ -1,55 +1,47 @@
|
|
|
1
1
|
import clsx from 'clsx';
|
|
2
|
-
import React, { useState, Children, cloneElement
|
|
2
|
+
import React, { useState, Children, cloneElement } from 'react';
|
|
3
3
|
import { useKey } from 'react-use';
|
|
4
4
|
import { Dropdown as DropdownClass, PopUp } from './dropdown.module.css';
|
|
5
5
|
import { useUIDSeed } from 'react-uid';
|
|
6
6
|
import { useFocusWithin } from '@react-aria/interactions';
|
|
7
7
|
import { DropdownMenu } from './dropdown-menu';
|
|
8
8
|
import { DropdownItem } from './dropdown-item';
|
|
9
|
-
import {
|
|
10
|
-
import { motion } from 'framer-motion';
|
|
9
|
+
import { usePopperTooltip } from 'react-popper-tooltip';
|
|
10
|
+
import { AnimatePresence, motion } from 'framer-motion';
|
|
11
11
|
export const Dropdown = ({ className, children, trigger, offset = 8, placement = 'auto-start' }) => {
|
|
12
12
|
const seedID = useUIDSeed();
|
|
13
13
|
const [isOpen, setIsOpen] = useState(false);
|
|
14
|
+
const { getTooltipProps, setTooltipRef, setTriggerRef, visible } = usePopperTooltip({
|
|
15
|
+
delayShow: 0,
|
|
16
|
+
delayHide: 200,
|
|
17
|
+
trigger: ['click'],
|
|
18
|
+
visible: isOpen,
|
|
19
|
+
closeOnTriggerHidden: true,
|
|
20
|
+
onVisibleChange: setIsOpen,
|
|
21
|
+
placement: placement,
|
|
22
|
+
offset: [0, offset]
|
|
23
|
+
}, {
|
|
24
|
+
strategy: 'fixed'
|
|
25
|
+
});
|
|
14
26
|
const { focusWithinProps } = useFocusWithin({
|
|
15
27
|
onFocusWithin: () => null,
|
|
16
28
|
onBlurWithin: (e) => e.relatedTarget && setIsOpen(false),
|
|
17
29
|
onFocusWithinChange: () => null
|
|
18
30
|
});
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
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, {
|
|
31
|
+
useKey('Escape', () => setIsOpen(false));
|
|
32
|
+
return (React.createElement("div", Object.assign({ className: clsx(DropdownClass, className) }, focusWithinProps),
|
|
33
|
+
Children.map(trigger, (child) => cloneElement(child, {
|
|
34
|
+
ref: setTriggerRef,
|
|
25
35
|
id: seedID('dropdown-trigger'),
|
|
26
36
|
'aria-haspopup': 'true',
|
|
27
37
|
'aria-controls': seedID('dropdown-menu'),
|
|
28
38
|
'aria-expanded': isOpen
|
|
29
|
-
}))
|
|
30
|
-
React.createElement(
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
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
|
-
})))))));
|
|
39
|
+
})),
|
|
40
|
+
React.createElement(AnimatePresence, null, visible && (React.createElement("div", Object.assign({ ref: setTooltipRef, role: "tooltip", id: seedID('tooltip-content'), className: PopUp }, getTooltipProps({ className: PopUp })),
|
|
41
|
+
React.createElement(motion.div, { animate: isOpen ? { y: 5, opacity: 1 } : { y: 0, opacity: 0 }, transition: { ease: 'easeOut', duration: 0.1 } }, Children.map(children, (child) => cloneElement(child, {
|
|
42
|
+
id: seedID('dropdown-menu'),
|
|
43
|
+
'aria-labelledby': seedID('dropdown-trigger')
|
|
44
|
+
}))))))));
|
|
53
45
|
};
|
|
54
46
|
Dropdown.Menu = DropdownMenu;
|
|
55
47
|
Dropdown.Item = DropdownItem;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wonderflow/react-components",
|
|
3
3
|
"description": "UI components from Wonderflow's Wanda design system",
|
|
4
|
-
"version": "2.
|
|
4
|
+
"version": "2.16.0",
|
|
5
5
|
"author": "Wonderflow",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"main": "index.js",
|
|
@@ -54,7 +54,6 @@
|
|
|
54
54
|
},
|
|
55
55
|
"dependencies": {
|
|
56
56
|
"@bumaga/tabs": "0.2.0",
|
|
57
|
-
"@popperjs/core": "2.10.1",
|
|
58
57
|
"@radix-ui/react-polymorphic": "0.0.13",
|
|
59
58
|
"@react-aria/interactions": "3.5.1",
|
|
60
59
|
"@wonderflow/config": "1.4.7",
|
|
@@ -67,7 +66,7 @@
|
|
|
67
66
|
"postcss": "8.3.6",
|
|
68
67
|
"react": ">=17.0.2",
|
|
69
68
|
"react-dom": ">=17.0.2",
|
|
70
|
-
"react-
|
|
69
|
+
"react-popper-tooltip": "4.3.0",
|
|
71
70
|
"react-roving-tabindex": "3.1.1",
|
|
72
71
|
"react-uid": "2.3.1",
|
|
73
72
|
"react-use": "17.3.1",
|
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
|
|
7
|
+
* Generated on Tue, 21 Sep 2021 07:30:12 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
|
|
53
|
+
* Generated on Tue, 21 Sep 2021 07:30:12 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
|
|
100
|
+
* Generated on Tue, 21 Sep 2021 07:30:12 GMT
|
|
101
101
|
*/
|
|
102
102
|
|
|
103
103
|
|
package/tooltip/tooltip.d.ts
CHANGED
package/tooltip/tooltip.js
CHANGED
|
@@ -1,61 +1,46 @@
|
|
|
1
|
-
import
|
|
2
|
-
import React, { Children, cloneElement, useEffect, useState } from 'react';
|
|
1
|
+
import React, { Children, cloneElement, useState } from 'react';
|
|
3
2
|
import { useUIDSeed } from 'react-uid';
|
|
4
|
-
import {
|
|
3
|
+
import { useKey } from 'react-use';
|
|
4
|
+
import { Elevator } from '../elevator';
|
|
5
5
|
import { useFocusWithin } from '@react-aria/interactions';
|
|
6
|
-
import { Tooltip as TooltipClass, Arrow, Trigger
|
|
7
|
-
import {
|
|
8
|
-
export const Tooltip = ({ children,
|
|
6
|
+
import { Tooltip as TooltipClass, Arrow, Trigger } from './tooltip.module.css';
|
|
7
|
+
import { usePopperTooltip } from 'react-popper-tooltip';
|
|
8
|
+
export const Tooltip = ({ children, trigger, placement = 'bottom-start', show, style, maxWidth = '40ch', fill = false, delay = 500 }) => {
|
|
9
9
|
const seedID = useUIDSeed();
|
|
10
|
-
const [
|
|
11
|
-
|
|
12
|
-
const
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
10
|
+
const [controlledVisible, setControlledVisible] = useState(false);
|
|
11
|
+
useKey('Escape', () => setControlledVisible(false));
|
|
12
|
+
const { getArrowProps, getTooltipProps, setTooltipRef, setTriggerRef, visible } = usePopperTooltip({
|
|
13
|
+
delayShow: delay,
|
|
14
|
+
delayHide: 200,
|
|
15
|
+
trigger: ['hover', 'focus'],
|
|
16
|
+
visible: show || controlledVisible,
|
|
17
|
+
closeOnTriggerHidden: true,
|
|
18
|
+
onVisibleChange: setControlledVisible,
|
|
19
|
+
placement: placement,
|
|
20
|
+
offset: [0, 16]
|
|
21
|
+
}, {
|
|
22
|
+
strategy: 'fixed'
|
|
23
|
+
});
|
|
16
24
|
const { focusWithinProps } = useFocusWithin({
|
|
17
|
-
onFocusWithin: () => {
|
|
18
|
-
|
|
19
|
-
|
|
25
|
+
onFocusWithin: (e) => {
|
|
26
|
+
console.log(e);
|
|
27
|
+
setControlledVisible(true);
|
|
20
28
|
},
|
|
21
29
|
onBlurWithin: () => {
|
|
22
|
-
|
|
23
|
-
setVisible(false);
|
|
30
|
+
setControlledVisible(false);
|
|
24
31
|
},
|
|
25
32
|
onFocusWithinChange: () => null
|
|
26
33
|
});
|
|
27
|
-
useEffect(() => {
|
|
28
|
-
cancel();
|
|
29
|
-
}, [cancel]);
|
|
30
34
|
const dynamycStyle = {
|
|
31
35
|
'--maxW': maxWidth
|
|
32
36
|
};
|
|
33
|
-
return (React.createElement(
|
|
34
|
-
|
|
37
|
+
return (React.createElement("div", Object.assign({ "data-tooltip-fill": fill, className: Trigger }, focusWithinProps, { style: Object.assign({}, style) }),
|
|
38
|
+
Children.map(trigger, (child) => cloneElement(child, {
|
|
39
|
+
ref: setTriggerRef,
|
|
35
40
|
'aria-describedby': seedID('tooltip-content')
|
|
36
|
-
}))
|
|
37
|
-
React.createElement(
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
}
|
|
42
|
-
}, popperOptions: {
|
|
43
|
-
placement: placement,
|
|
44
|
-
modifiers: [
|
|
45
|
-
{
|
|
46
|
-
name: 'flip',
|
|
47
|
-
enabled: true,
|
|
48
|
-
options: {
|
|
49
|
-
fallbackPlacements: ['right-start', 'left-start', 'bottom', 'top']
|
|
50
|
-
}
|
|
51
|
-
},
|
|
52
|
-
{
|
|
53
|
-
name: 'offset',
|
|
54
|
-
options: {
|
|
55
|
-
offset: [0, 16]
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
]
|
|
59
|
-
} },
|
|
60
|
-
React.createElement("div", { role: "tooltip", style: dynamycStyle, className: ContentClass, id: seedID('tooltip-content') }, children))));
|
|
41
|
+
})),
|
|
42
|
+
visible && (React.createElement(Elevator, { resting: 2 },
|
|
43
|
+
React.createElement("div", Object.assign({ ref: setTooltipRef, role: "tooltip", id: seedID('tooltip-content'), "data-theme": "dark" }, getTooltipProps({ className: TooltipClass, style: dynamycStyle })),
|
|
44
|
+
children,
|
|
45
|
+
React.createElement("div", Object.assign({}, getArrowProps({ className: Arrow }))))))));
|
|
61
46
|
};
|
|
@@ -4,6 +4,10 @@
|
|
|
4
4
|
border-radius: env(--radius-4);
|
|
5
5
|
background-color: hsl(env(--color-primary-80));
|
|
6
6
|
font-size: env(--font-size-16);
|
|
7
|
+
max-inline-size: var(--maxW);
|
|
8
|
+
word-wrap: break-word;
|
|
9
|
+
|
|
10
|
+
/* max-inline-size: var(--w, 40ch); */
|
|
7
11
|
z-index: 2;
|
|
8
12
|
|
|
9
13
|
&[data-popper-reference-hidden='true'] {
|
|
@@ -12,14 +16,15 @@
|
|
|
12
16
|
}
|
|
13
17
|
}
|
|
14
18
|
|
|
15
|
-
.Content {
|
|
16
|
-
max-inline-size: var(--maxW);
|
|
17
|
-
}
|
|
18
|
-
|
|
19
19
|
.Trigger {
|
|
20
20
|
display: inline-flex;
|
|
21
|
+
|
|
22
|
+
&[data-tooltip-fill='true'] {
|
|
23
|
+
display: flex;
|
|
24
|
+
}
|
|
21
25
|
}
|
|
22
26
|
|
|
27
|
+
|
|
23
28
|
.Arrow {
|
|
24
29
|
&::before {
|
|
25
30
|
content: '';
|