@wonderflow/react-components 2.38.0 → 3.0.0-next.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/package.json +1 -1
- package/tab/index.d.ts +2 -2
- package/tab/index.js +1 -1
- package/tab/tab-item.d.ts +6 -0
- package/tab/tab-item.js +20 -0
- package/tab/tab-list.d.ts +2 -0
- package/tab/tab-list.js +6 -0
- package/tab/tab-panel.d.ts +7 -0
- package/tab/tab-panel.js +10 -0
- package/tab/tab.d.ts +8 -13
- package/tab/tab.js +11 -36
- package/themes/dark.css +1 -1
- package/themes/light.css +1 -1
- package/themes.css +3 -3
package/package.json
CHANGED
package/tab/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { Tab } from './tab';
|
|
2
|
-
export type { TabProps
|
|
1
|
+
export { TabRoot as Tab } from './tab';
|
|
2
|
+
export type { TabProps } from './tab';
|
package/tab/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { Tab } from './tab';
|
|
1
|
+
export { TabRoot as Tab } from './tab';
|
package/tab/tab-item.js
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import React, { useCallback, useRef } from 'react';
|
|
2
|
+
import { useRovingTabIndex, useFocusEffect } from 'react-roving-tabindex';
|
|
3
|
+
import clsx from 'clsx';
|
|
4
|
+
import { Stack, Icon } from '../';
|
|
5
|
+
import { useTabState } from './primitive-tab';
|
|
6
|
+
import { TabItem as TabItemClass } from './tab.module.css';
|
|
7
|
+
export const TabItem = ({ children, className, icon, ...props }) => {
|
|
8
|
+
const { onClick, isActive } = useTabState(children);
|
|
9
|
+
const internalRef = useRef(null);
|
|
10
|
+
const [, focused, handleKeyDown, handleClick] = useRovingTabIndex(internalRef, false);
|
|
11
|
+
useFocusEffect(focused, internalRef);
|
|
12
|
+
const fireClick = useCallback(() => {
|
|
13
|
+
onClick();
|
|
14
|
+
handleClick();
|
|
15
|
+
}, [handleClick, onClick]);
|
|
16
|
+
return (React.createElement(Stack, { as: "button", direction: "row", verticalAlign: "center", horizontalAlign: "start", fill: false, columnGap: 8, role: "tab", ref: internalRef, className: clsx(TabItemClass, className), "aria-selected": isActive, onClick: fireClick, onKeyDown: handleKeyDown, onFocus: fireClick, type: "button", tabIndex: isActive ? 0 : -1, ...props },
|
|
17
|
+
icon && React.createElement(Icon, { name: icon, dimension: 16 }),
|
|
18
|
+
children));
|
|
19
|
+
};
|
|
20
|
+
TabItem.displayName = 'Tab.Item';
|
package/tab/tab-list.js
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import React, { forwardRef } from 'react';
|
|
2
|
+
import { RovingTabIndexProvider } from 'react-roving-tabindex';
|
|
3
|
+
import clsx from 'clsx';
|
|
4
|
+
import { TabList as TabListClass } from './tab.module.css';
|
|
5
|
+
export const TabList = forwardRef(({ children, className, ...props }, forwardedRef) => (React.createElement("div", { ref: forwardedRef, role: "tablist", tabIndex: -1, className: clsx(TabListClass, className), ...props },
|
|
6
|
+
React.createElement(RovingTabIndexProvider, null, children))));
|
package/tab/tab-panel.js
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import React, { forwardRef } from 'react';
|
|
2
|
+
import clsx from 'clsx';
|
|
3
|
+
import { usePanelState } from './primitive-tab';
|
|
4
|
+
import { TabPanel as TabPanelClass } from './tab.module.css';
|
|
5
|
+
export const TabPanel = forwardRef(({ children, className, ...props }, forwardedRef) => {
|
|
6
|
+
const isActive = usePanelState(children);
|
|
7
|
+
return isActive
|
|
8
|
+
? (React.createElement("div", { ref: forwardedRef, tabIndex: 0, className: clsx(TabPanelClass, className), ...props }, children))
|
|
9
|
+
: null;
|
|
10
|
+
});
|
package/tab/tab.d.ts
CHANGED
|
@@ -1,20 +1,15 @@
|
|
|
1
|
-
import React, { ReactNode
|
|
2
|
-
import { IconNames } from '../icons/types';
|
|
1
|
+
import React, { ReactNode } from 'react';
|
|
3
2
|
export declare type TabProps = PropsWithClass & {
|
|
4
3
|
children: ReactNode;
|
|
5
4
|
state?: [number, React.Dispatch<React.SetStateAction<number>>];
|
|
6
5
|
onChange?(index: number): void;
|
|
7
6
|
};
|
|
8
|
-
export declare
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
};
|
|
15
|
-
export declare const Tab: {
|
|
16
|
-
Root: React.FC<TabProps>;
|
|
7
|
+
export declare const TabRoot: React.ForwardRefExoticComponent<PropsWithClass & {
|
|
8
|
+
children: ReactNode;
|
|
9
|
+
state?: [number, React.Dispatch<React.SetStateAction<number>>] | undefined;
|
|
10
|
+
onChange?(index: number): void;
|
|
11
|
+
} & React.RefAttributes<HTMLDivElement>> & {
|
|
12
|
+
Item: React.FC<import("./tab-item").TabItemProps>;
|
|
17
13
|
List: React.FC<PropsWithClass>;
|
|
18
|
-
|
|
19
|
-
Panel: React.FC<TabPanelProps>;
|
|
14
|
+
Panel: React.FC<import("./tab-panel").TabPanelProps>;
|
|
20
15
|
};
|
package/tab/tab.js
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
import React, {
|
|
2
|
-
import { useRovingTabIndex, useFocusEffect, RovingTabIndexProvider } from 'react-roving-tabindex';
|
|
1
|
+
import React, { useEffect, useState, forwardRef, Children, cloneElement } from 'react';
|
|
3
2
|
import clsx from 'clsx';
|
|
4
3
|
import { useUIDSeed } from 'react-uid';
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
|
|
4
|
+
import { TabItem } from './tab-item';
|
|
5
|
+
import { TabList } from './tab-list';
|
|
6
|
+
import { TabPanel } from './tab-panel';
|
|
7
|
+
import { Tabs as TabsWrapper } from './primitive-tab';
|
|
8
|
+
import { Tab as TabClass } from './tab.module.css';
|
|
9
|
+
const Tab = forwardRef(({ children, className, state, onChange, ...props }, forwardedRef) => {
|
|
9
10
|
const renderedChildren = Children.toArray(children).filter(Boolean);
|
|
10
11
|
const innerState = useState(0);
|
|
11
12
|
const tabState = state || innerState;
|
|
@@ -18,40 +19,14 @@ const TabRoot = forwardRef(({ children, className, state, onChange, ...props },
|
|
|
18
19
|
}, [currentTab, onChange]);
|
|
19
20
|
return (React.createElement("div", { ref: forwardedRef, className: clsx(TabClass, className), ...props },
|
|
20
21
|
React.createElement(TabsWrapper, { state: tabState },
|
|
21
|
-
React.createElement(TabList, null, Children.map(renderedChildren, (child, index) => (React.createElement(
|
|
22
|
+
React.createElement(TabList, null, Children.map(renderedChildren, (child, index) => (React.createElement(TabItem, { id: seedID(`tab-item-${index}`), "aria-controls": seedID(`tab-panel-${index}`), icon: child.props.icon }, child.props.label)))),
|
|
22
23
|
Children.map(renderedChildren, (child, index) => cloneElement(child, {
|
|
23
24
|
id: seedID(`tab-panel-${index}`),
|
|
24
25
|
'aria-labelledby': seedID(`tab-item-${index}`)
|
|
25
26
|
})))));
|
|
26
27
|
});
|
|
27
|
-
const
|
|
28
|
-
React.createElement(RovingTabIndexProvider, null, children))));
|
|
29
|
-
const TabPanel = forwardRef(({ children, className, ...props }, forwardedRef) => {
|
|
30
|
-
const isActive = usePanelState(children);
|
|
31
|
-
return isActive
|
|
32
|
-
? (React.createElement("div", { ref: forwardedRef, tabIndex: 0, className: clsx(TabPanelClass, className), ...props }, children))
|
|
33
|
-
: null;
|
|
34
|
-
});
|
|
35
|
-
const TabItem = ({ children, className, icon, ...props }) => {
|
|
36
|
-
const { onClick, isActive } = useTabState(children);
|
|
37
|
-
const internalRef = useRef(null);
|
|
38
|
-
const [, focused, handleKeyDown, handleClick] = useRovingTabIndex(internalRef, false);
|
|
39
|
-
useFocusEffect(focused, internalRef);
|
|
40
|
-
const fireClick = useCallback(() => {
|
|
41
|
-
onClick();
|
|
42
|
-
handleClick();
|
|
43
|
-
}, [handleClick, onClick]);
|
|
44
|
-
return (React.createElement(Stack, { as: "button", direction: "row", verticalAlign: "center", horizontalAlign: "start", fill: false, columnGap: 8, role: "tab", ref: internalRef, className: clsx(TabItemClass, className), "aria-selected": isActive, onClick: fireClick, onKeyDown: handleKeyDown, onFocus: fireClick, type: "button", tabIndex: isActive ? 0 : -1, ...props },
|
|
45
|
-
icon && React.createElement(Icon, { name: icon, dimension: 16 }),
|
|
46
|
-
children));
|
|
47
|
-
};
|
|
48
|
-
export const Tab = {
|
|
49
|
-
Root: TabRoot,
|
|
50
|
-
List: TabList,
|
|
28
|
+
export const TabRoot = Object.assign(Tab, {
|
|
51
29
|
Item: TabItem,
|
|
30
|
+
List: TabList,
|
|
52
31
|
Panel: TabPanel
|
|
53
|
-
};
|
|
54
|
-
Tab.Root.displayName = 'Tab.Root';
|
|
55
|
-
Tab.List.displayName = 'Tab.List';
|
|
56
|
-
Tab.Panel.displayName = 'Tab.Panel';
|
|
57
|
-
Tab.Item.displayName = 'Tab.Item';
|
|
32
|
+
});
|
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, 29 Nov 2021
|
|
7
|
+
* Generated on Mon, 29 Nov 2021 10:40:48 GMT
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
10
|
|
|
@@ -51,7 +51,7 @@
|
|
|
51
51
|
color: var(--global-foreground);
|
|
52
52
|
/**
|
|
53
53
|
* Do not edit directly
|
|
54
|
-
* Generated on Mon, 29 Nov 2021
|
|
54
|
+
* Generated on Mon, 29 Nov 2021 10:40:48 GMT
|
|
55
55
|
*/
|
|
56
56
|
|
|
57
57
|
|
|
@@ -99,7 +99,7 @@
|
|
|
99
99
|
color: var(--global-foreground);
|
|
100
100
|
/**
|
|
101
101
|
* Do not edit directly
|
|
102
|
-
* Generated on Mon, 29 Nov 2021
|
|
102
|
+
* Generated on Mon, 29 Nov 2021 10:40:48 GMT
|
|
103
103
|
*/
|
|
104
104
|
|
|
105
105
|
|