@lumx/react 3.9.7-alpha.2 → 3.9.7-alpha.3
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/_internal/ClickAwayProvider.js +97 -0
- package/_internal/ClickAwayProvider.js.map +1 -0
- package/_internal/{index.d.ts → types.d.ts} +44 -1
- package/index.d.ts +3 -46
- package/index.js +208 -175
- package/index.js.map +1 -1
- package/package.json +12 -11
- package/src/components/tabs/Tab.tsx +10 -4
- package/src/components/tabs/Tabs.stories.tsx +1 -28
- package/utils/index.d.ts +1 -1
- package/utils/index.js +1 -96
- package/utils/index.js.map +1 -1
package/package.json
CHANGED
|
@@ -6,8 +6,8 @@
|
|
|
6
6
|
"url": "https://github.com/lumapps/design-system/issues"
|
|
7
7
|
},
|
|
8
8
|
"dependencies": {
|
|
9
|
-
"@lumx/core": "^3.9.7-alpha.
|
|
10
|
-
"@lumx/icons": "^3.9.7-alpha.
|
|
9
|
+
"@lumx/core": "^3.9.7-alpha.3",
|
|
10
|
+
"@lumx/icons": "^3.9.7-alpha.3",
|
|
11
11
|
"@popperjs/core": "^2.5.4",
|
|
12
12
|
"body-scroll-lock": "^3.1.5",
|
|
13
13
|
"classnames": "^2.3.2",
|
|
@@ -26,9 +26,8 @@
|
|
|
26
26
|
"@babel/preset-env": "^7.18.10",
|
|
27
27
|
"@babel/preset-react": "^7.18.6",
|
|
28
28
|
"@babel/preset-typescript": "^7.18.6",
|
|
29
|
-
"@rollup/plugin-
|
|
30
|
-
"@rollup/plugin-
|
|
31
|
-
"@rollup/plugin-node-resolve": "16.0.0",
|
|
29
|
+
"@rollup/plugin-commonjs": "^15.0.0",
|
|
30
|
+
"@rollup/plugin-node-resolve": "9.0.0",
|
|
32
31
|
"@storybook/addon-a11y": "^7.6.3",
|
|
33
32
|
"@storybook/addon-essentials": "^7.6.3",
|
|
34
33
|
"@storybook/addon-interactions": "^7.6.3",
|
|
@@ -59,13 +58,15 @@
|
|
|
59
58
|
"jest-environment-jsdom": "29.1.2",
|
|
60
59
|
"react": "^17.0.2",
|
|
61
60
|
"react-dom": "^17.0.2",
|
|
62
|
-
"rollup": "
|
|
63
|
-
"rollup-plugin-analyzer": "^
|
|
61
|
+
"rollup": "2.79.2",
|
|
62
|
+
"rollup-plugin-analyzer": "^3.3.0",
|
|
63
|
+
"rollup-plugin-babel": "^4.4.0",
|
|
64
64
|
"rollup-plugin-cleaner": "^1.0.0",
|
|
65
|
-
"rollup-plugin-copy": "^3.
|
|
66
|
-
"rollup-plugin-dts": "^
|
|
65
|
+
"rollup-plugin-copy": "^3.3.0",
|
|
66
|
+
"rollup-plugin-dts": "^4.2.2",
|
|
67
67
|
"rollup-plugin-peer-deps-external": "^2.2.4",
|
|
68
|
-
"rollup-plugin-ts-paths-resolve": "^1.
|
|
68
|
+
"rollup-plugin-ts-paths-resolve": "^1.3.0",
|
|
69
|
+
"rollup-plugin-typescript-paths": "^1.2.2",
|
|
69
70
|
"storybook": "^7.6.3",
|
|
70
71
|
"typescript": "^5.4.3",
|
|
71
72
|
"vite": "^4.2.1",
|
|
@@ -110,5 +111,5 @@
|
|
|
110
111
|
"build:storybook": "storybook build"
|
|
111
112
|
},
|
|
112
113
|
"sideEffects": false,
|
|
113
|
-
"version": "3.9.7-alpha.
|
|
114
|
+
"version": "3.9.7-alpha.3"
|
|
114
115
|
}
|
|
@@ -1,10 +1,12 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import React, { FocusEventHandler, forwardRef, KeyboardEventHandler, ReactNode, useCallback } from 'react';
|
|
2
|
+
|
|
3
|
+
import classNames from 'classnames';
|
|
4
|
+
|
|
5
|
+
import { Icon, IconProps, Size, Text } from '@lumx/react';
|
|
2
6
|
import { CSS_PREFIX } from '@lumx/react/constants';
|
|
3
7
|
import { Comp, GenericProps } from '@lumx/react/utils/type';
|
|
4
8
|
import { handleBasicClasses } from '@lumx/react/utils/className';
|
|
5
9
|
|
|
6
|
-
import classNames from 'classnames';
|
|
7
|
-
import React, { FocusEventHandler, forwardRef, KeyboardEventHandler, ReactNode, useCallback } from 'react';
|
|
8
10
|
import { useTabProviderContext } from './state';
|
|
9
11
|
|
|
10
12
|
/**
|
|
@@ -114,7 +116,11 @@ export const Tab: Comp<TabProps, HTMLButtonElement> = forwardRef((props, ref) =>
|
|
|
114
116
|
aria-controls={state?.tabPanelId}
|
|
115
117
|
>
|
|
116
118
|
{icon && <Icon icon={icon} size={Size.xs} {...iconProps} />}
|
|
117
|
-
{label &&
|
|
119
|
+
{label && (
|
|
120
|
+
<Text as="span" truncate>
|
|
121
|
+
{label}
|
|
122
|
+
</Text>
|
|
123
|
+
)}
|
|
118
124
|
</button>
|
|
119
125
|
);
|
|
120
126
|
});
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Button, Dialog, Tab, TabList, TabPanel, TabProvider } from '@lumx/react';
|
|
2
|
+
import { loremIpsum } from '@lumx/react/stories/utils/lorem';
|
|
2
3
|
import get from 'lodash/get';
|
|
3
4
|
import times from 'lodash/times';
|
|
4
5
|
import React, { useState } from 'react';
|
|
@@ -52,34 +53,6 @@ export const Controlled = ({ theme }: any) => {
|
|
|
52
53
|
);
|
|
53
54
|
};
|
|
54
55
|
|
|
55
|
-
/* Control active tab internally (with activate tab on focus). */
|
|
56
|
-
export const NotControlled = ({ theme }: any) => {
|
|
57
|
-
return (
|
|
58
|
-
<TabProvider shouldActivateOnFocus onChange={console.log}>
|
|
59
|
-
<TabList theme={theme} aria-label="Tab list">
|
|
60
|
-
<Tab label="Tab a" />
|
|
61
|
-
<Tab label="Tab b" />
|
|
62
|
-
</TabList>
|
|
63
|
-
<TabPanel className="lumx-spacing-padding-huge">Tab a content</TabPanel>
|
|
64
|
-
<TabPanel className="lumx-spacing-padding-huge">Tab b content</TabPanel>
|
|
65
|
-
</TabProvider>
|
|
66
|
-
);
|
|
67
|
-
};
|
|
68
|
-
|
|
69
|
-
/* Display tabs far from their tab panels. */
|
|
70
|
-
export const DisabledTab = ({ theme }: any) => (
|
|
71
|
-
<TabProvider shouldActivateOnFocus>
|
|
72
|
-
<TabList theme={theme} aria-label="Tab list">
|
|
73
|
-
<Tab label="Tab 1" />
|
|
74
|
-
<Tab label="Tab 2" isDisabled />
|
|
75
|
-
<Tab label="Tab 3" />
|
|
76
|
-
</TabList>
|
|
77
|
-
<TabPanel className="lumx-spacing-padding-huge">Tab 1 content</TabPanel>
|
|
78
|
-
<TabPanel className="lumx-spacing-padding-huge">Tab 2 content</TabPanel>
|
|
79
|
-
<TabPanel className="lumx-spacing-padding-huge">Tab 3 content</TabPanel>
|
|
80
|
-
</TabProvider>
|
|
81
|
-
);
|
|
82
|
-
|
|
83
56
|
/* Display tabs far from their tab panels. */
|
|
84
57
|
export const SplitTabListAndTabPanels = ({ theme }: any) => {
|
|
85
58
|
const [isOpen, setOpen] = useState(true);
|
package/utils/index.d.ts
CHANGED
package/utils/index.js
CHANGED
|
@@ -1,97 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
import isEmpty from 'lodash/isEmpty';
|
|
3
|
-
|
|
4
|
-
const EVENT_TYPES = ['mousedown', 'touchstart'];
|
|
5
|
-
function isClickAway(target, refs) {
|
|
6
|
-
// The target element is not contained in any of the listed element references.
|
|
7
|
-
return !refs.some(e => {
|
|
8
|
-
var _e$current;
|
|
9
|
-
return e === null || e === void 0 ? void 0 : (_e$current = e.current) === null || _e$current === void 0 ? void 0 : _e$current.contains(target);
|
|
10
|
-
});
|
|
11
|
-
}
|
|
12
|
-
/**
|
|
13
|
-
* Listen to clicks away from the given elements and callback the passed in function.
|
|
14
|
-
*
|
|
15
|
-
* Warning: If you need to detect click away on nested React portals, please use the `ClickAwayProvider` component.
|
|
16
|
-
*/
|
|
17
|
-
function useClickAway(_ref) {
|
|
18
|
-
let {
|
|
19
|
-
callback,
|
|
20
|
-
childrenRefs
|
|
21
|
-
} = _ref;
|
|
22
|
-
useEffect(() => {
|
|
23
|
-
const {
|
|
24
|
-
current: currentRefs
|
|
25
|
-
} = childrenRefs;
|
|
26
|
-
if (!callback || !currentRefs || isEmpty(currentRefs)) {
|
|
27
|
-
return undefined;
|
|
28
|
-
}
|
|
29
|
-
const listener = evt => {
|
|
30
|
-
if (isClickAway(evt.target, currentRefs)) {
|
|
31
|
-
callback(evt);
|
|
32
|
-
}
|
|
33
|
-
};
|
|
34
|
-
EVENT_TYPES.forEach(evtType => document.addEventListener(evtType, listener));
|
|
35
|
-
return () => {
|
|
36
|
-
EVENT_TYPES.forEach(evtType => document.removeEventListener(evtType, listener));
|
|
37
|
-
};
|
|
38
|
-
}, [callback, childrenRefs]);
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
const ClickAwayAncestorContext = /*#__PURE__*/createContext(null);
|
|
42
|
-
/**
|
|
43
|
-
* Component combining the `useClickAway` hook with a React context to hook into the React component tree and make sure
|
|
44
|
-
* we take into account both the DOM tree and the React tree to detect click away.
|
|
45
|
-
*
|
|
46
|
-
* @return the react component.
|
|
47
|
-
*/
|
|
48
|
-
const ClickAwayProvider = _ref => {
|
|
49
|
-
let {
|
|
50
|
-
children,
|
|
51
|
-
callback,
|
|
52
|
-
childrenRefs,
|
|
53
|
-
parentRef
|
|
54
|
-
} = _ref;
|
|
55
|
-
const parentContext = useContext(ClickAwayAncestorContext);
|
|
56
|
-
const currentContext = useMemo(() => {
|
|
57
|
-
const context = {
|
|
58
|
-
childrenRefs: [],
|
|
59
|
-
/**
|
|
60
|
-
* Add element refs to the current context and propagate to the parent context.
|
|
61
|
-
*/
|
|
62
|
-
addRefs() {
|
|
63
|
-
// Add element refs that should be considered as inside the click away context.
|
|
64
|
-
context.childrenRefs.push(...arguments);
|
|
65
|
-
if (parentContext) {
|
|
66
|
-
// Also add then to the parent context
|
|
67
|
-
parentContext.addRefs(...arguments);
|
|
68
|
-
if (parentRef) {
|
|
69
|
-
// The parent element is also considered as inside the parent click away context but not inside the current context
|
|
70
|
-
parentContext.addRefs(parentRef);
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
};
|
|
75
|
-
return context;
|
|
76
|
-
}, [parentContext, parentRef]);
|
|
77
|
-
useEffect(() => {
|
|
78
|
-
const {
|
|
79
|
-
current: currentRefs
|
|
80
|
-
} = childrenRefs;
|
|
81
|
-
if (!currentRefs) {
|
|
82
|
-
return;
|
|
83
|
-
}
|
|
84
|
-
currentContext.addRefs(...currentRefs);
|
|
85
|
-
}, [currentContext, childrenRefs]);
|
|
86
|
-
useClickAway({
|
|
87
|
-
callback,
|
|
88
|
-
childrenRefs: useRef(currentContext.childrenRefs)
|
|
89
|
-
});
|
|
90
|
-
return /*#__PURE__*/React__default.createElement(ClickAwayAncestorContext.Provider, {
|
|
91
|
-
value: currentContext
|
|
92
|
-
}, children);
|
|
93
|
-
};
|
|
94
|
-
ClickAwayProvider.displayName = 'ClickAwayProvider';
|
|
95
|
-
|
|
96
|
-
export { ClickAwayProvider };
|
|
1
|
+
export { C as ClickAwayProvider } from '../_internal/ClickAwayProvider.js';
|
|
97
2
|
//# sourceMappingURL=index.js.map
|
package/utils/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":[
|
|
1
|
+
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":""}
|