@wonderflow/react-components 3.0.0-beta.6 → 3.0.0-beta.7

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.
@@ -1,10 +1,9 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import clsx from 'clsx';
3
3
  import { useState, Children, cloneElement, useRef, forwardRef } from 'react';
4
- import { useKeyPress, useClickAway } from 'ahooks';
4
+ import { useKeyPress, useClickAway, useFocusWithin } from 'ahooks';
5
5
  import { Dropdown as DropdownClass, PopUp } from './dropdown.module.css';
6
6
  import { useUIDSeed } from 'react-uid';
7
- import { useFocusWithin } from '../hooks';
8
7
  import { DropdownMenu } from './menu/dropdown-menu';
9
8
  import { DropdownItem } from './item/dropdown-item';
10
9
  import { DropdownItemCheckbox } from './item-checkbox/dropdown-item-checkbox';
@@ -26,16 +25,17 @@ export const Dropdown = forwardRef(({ className, children, trigger, offset = 8,
26
25
  offset: [0, offset],
27
26
  closeOnOutsideClick: false
28
27
  });
28
+ const isFocusWithin = useFocusWithin(popupRef, {
29
+ onBlur: (e) => e.relatedTarget && setIsOpen(false),
30
+ onChange: (isFocusWithin) => {
31
+ !isFocusWithin && setIsOpen(false);
32
+ }
33
+ });
29
34
  useClickAway(() => {
30
35
  setIsOpen(false);
31
36
  }, popupRef);
32
- const { focusWithinProps } = useFocusWithin({
33
- onFocusWithin: () => null,
34
- onBlurWithin: (e) => e.relatedTarget && setIsOpen(false),
35
- onFocusWithinChange: () => null
36
- });
37
37
  useKeyPress('esc', () => setIsOpen(false));
38
- return (_jsxs("div", { ref: popupRef, className: clsx(DropdownClass, className), ...focusWithinProps, children: [Children.map(trigger, (child) => cloneElement(child, {
38
+ return (_jsxs("div", { ref: popupRef, "data-dropdown-has-focus-within": isFocusWithin, className: clsx(DropdownClass, className), children: [Children.map(trigger, (child) => cloneElement(child, {
39
39
  ref: setTriggerRef,
40
40
  id: seedID('dropdown-trigger'),
41
41
  'aria-haspopup': 'true',
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": "3.0.0-beta.6",
4
+ "version": "3.0.0-beta.7",
5
5
  "author": "Wonderflow",
6
6
  "license": "MIT",
7
7
  "main": "index.js",
@@ -64,14 +64,13 @@
64
64
  "postbuild": "run-s prepare:package"
65
65
  },
66
66
  "dependencies": {
67
- "@react-aria/interactions": "3.7.0",
68
67
  "@wonderflow/tokens": "1.3.7",
69
- "ahooks": "3.0.8",
68
+ "ahooks": "3.1.1",
70
69
  "clsx": "1.1.1",
71
70
  "framer-motion": "4.1.17",
72
71
  "postcss": "^8.4.5",
73
72
  "react": "^17.0",
74
- "react-data-table-component": "7.4.5",
73
+ "react-data-table-component": "7.4.6",
75
74
  "react-dom": "^17.0",
76
75
  "react-focus-on": "3.5.4",
77
76
  "react-loading-skeleton": "3.0.1",
@@ -107,8 +106,8 @@
107
106
  "@storybook/react": "6.5.0-alpha.4",
108
107
  "@storybook/theming": "6.5.0-alpha.4",
109
108
  "@types/react-dom": "17.0.11",
110
- "@typescript-eslint/eslint-plugin": "5.7.0",
111
- "@typescript-eslint/parser": "5.7.0",
109
+ "@typescript-eslint/eslint-plugin": "5.8.0",
110
+ "@typescript-eslint/parser": "5.8.0",
112
111
  "@wonderflow/config": "3.0.3",
113
112
  "@wonderflow/eslint-config": "1.1.8",
114
113
  "@wonderflow/stylelint-config": "1.1.3",
@@ -119,7 +118,7 @@
119
118
  "cz-conventional-changelog": "3.3.0",
120
119
  "directory-tree": "3.0.1",
121
120
  "eslint": "7.32.0",
122
- "eslint-plugin-react": "7.27.1",
121
+ "eslint-plugin-react": "7.28.0",
123
122
  "eslint-plugin-storybook": "0.5.5",
124
123
  "fs-extra": "10.0.0",
125
124
  "husky": "7.0.4",
package/themes/dark.css CHANGED
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * Do not edit directly
3
- * Generated on Wed, 22 Dec 2021 16:43:19 GMT
3
+ * Generated on Thu, 23 Dec 2021 10:40:26 GMT
4
4
  */
5
5
 
6
6
  :root {
package/themes/light.css CHANGED
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * Do not edit directly
3
- * Generated on Wed, 22 Dec 2021 16:43:19 GMT
3
+ * Generated on Thu, 23 Dec 2021 10:40:26 GMT
4
4
  */
5
5
 
6
6
  :root {
@@ -1,19 +1,19 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
- import { Children, cloneElement, useState } from 'react';
2
+ import { Children, cloneElement, useState, useRef } from 'react';
3
3
  import { useUIDSeed } from 'react-uid';
4
- import { useKeyPress } from 'ahooks';
4
+ import { useKeyPress, useFocusWithin } from 'ahooks';
5
5
  import { Elevator } from '../';
6
- import { useFocusWithin } from '../hooks';
7
6
  import { Tooltip as TooltipClass, Arrow, Trigger } from './tooltip.module.css';
8
7
  import { usePopperTooltip } from 'react-popper-tooltip';
9
8
  export const Tooltip = ({ children, trigger, placement = 'bottom-start', show, style, maxWidth = '40ch', fill = false, interactive = false, delay = 500 }) => {
10
9
  const seedID = useUIDSeed();
11
10
  const [controlledVisible, setControlledVisible] = useState(false);
11
+ const tooltipContainerRef = useRef(null);
12
12
  useKeyPress('esc', () => setControlledVisible(false));
13
13
  const { getArrowProps, getTooltipProps, setTooltipRef, setTriggerRef, visible } = usePopperTooltip({
14
14
  delayShow: delay,
15
15
  delayHide: 300,
16
- trigger: ['hover', 'focus'],
16
+ trigger: ['hover'],
17
17
  visible: show || controlledVisible,
18
18
  closeOnTriggerHidden: true,
19
19
  interactive: interactive,
@@ -23,19 +23,18 @@ export const Tooltip = ({ children, trigger, placement = 'bottom-start', show, s
23
23
  }, {
24
24
  strategy: 'fixed'
25
25
  });
26
- const { focusWithinProps } = useFocusWithin({
27
- onFocusWithin: () => {
26
+ const isFocusWithin = useFocusWithin(tooltipContainerRef, {
27
+ onFocus: () => {
28
28
  setControlledVisible(true);
29
29
  },
30
- onBlurWithin: () => {
31
- setControlledVisible(false);
32
- },
33
- onFocusWithinChange: () => null
30
+ onBlur: (e) => {
31
+ (e.target?.parentElement !== tooltipContainerRef.current) && setControlledVisible(false);
32
+ }
34
33
  });
35
34
  const dynamycStyle = {
36
35
  '--maxW': maxWidth
37
36
  };
38
- return (_jsxs("div", { "data-tooltip-fill": fill, className: Trigger, ...focusWithinProps, style: { ...style }, children: [Children.map(trigger, (child) => cloneElement(child, {
37
+ return (_jsxs("div", { "data-tooltip-fill": fill, className: Trigger, ref: tooltipContainerRef, "data-tooltip-has-focus-within": isFocusWithin, style: { ...style }, children: [Children.map(trigger, (child) => cloneElement(child, {
39
38
  ref: setTriggerRef,
40
39
  'aria-describedby': seedID('tooltip-content')
41
40
  })), visible && (_jsx(Elevator, { resting: 2, children: _jsxs("div", { ref: setTooltipRef, role: "tooltip", id: seedID('tooltip-content'), "data-theme": "dark", ...getTooltipProps({ className: TooltipClass, style: dynamycStyle }), children: [children, _jsx("div", { ...getArrowProps({ className: Arrow }) }, void 0)] }, void 0) }, void 0))] }, void 0));
package/hooks/index.d.ts DELETED
@@ -1 +0,0 @@
1
- export { useFocusWithin } from './useFocusWithin';
package/hooks/index.js DELETED
@@ -1 +0,0 @@
1
- export { useFocusWithin } from './useFocusWithin';
@@ -1,20 +0,0 @@
1
- import { FocusEvent, HTMLAttributes } from 'react';
2
- interface FocusWithinProps {
3
- /** Whether the focus within events should be disabled. */
4
- isDisabled?: boolean;
5
- /** Handler that is called when the target element or a descendant receives focus. */
6
- onFocusWithin?: (e: FocusEvent) => void;
7
- /** Handler that is called when the target element and all descendants lose focus. */
8
- onBlurWithin?: (e: FocusEvent) => void;
9
- /** Handler that is called when the the focus within state changes. */
10
- onFocusWithinChange?: (isFocusWithin: boolean) => void;
11
- }
12
- interface FocusWithinResult {
13
- /** Props to spread onto the target element. */
14
- focusWithinProps: HTMLAttributes<HTMLElement>;
15
- }
16
- /**
17
- * Handles focus events for the target and its descendants.
18
- */
19
- export declare function useFocusWithin(props: FocusWithinProps): FocusWithinResult;
20
- export {};
@@ -1,37 +0,0 @@
1
- import { useRef } from 'react';
2
- export function useFocusWithin(props) {
3
- const state = useRef({
4
- isFocusWithin: false
5
- }).current;
6
- if (props.isDisabled) {
7
- return { focusWithinProps: {} };
8
- }
9
- const onFocus = (e) => {
10
- if (!state.isFocusWithin) {
11
- if (props.onFocusWithin) {
12
- props.onFocusWithin(e);
13
- }
14
- if (props.onFocusWithinChange) {
15
- props.onFocusWithinChange(true);
16
- }
17
- state.isFocusWithin = true;
18
- }
19
- };
20
- const onBlur = (e) => {
21
- if (state.isFocusWithin && !e.currentTarget.contains(e.relatedTarget)) {
22
- if (props.onBlurWithin) {
23
- props.onBlurWithin(e);
24
- }
25
- if (props.onFocusWithinChange) {
26
- props.onFocusWithinChange(false);
27
- }
28
- state.isFocusWithin = false;
29
- }
30
- };
31
- return {
32
- focusWithinProps: {
33
- onFocus: onFocus,
34
- onBlur: onBlur
35
- }
36
- };
37
- }