@lumx/react 3.9.7-alpha.2 → 3.9.7-alpha.4
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/index.js +4 -1
- package/index.js.map +1 -1
- package/package.json +3 -3
- package/src/components/tabs/Tab.tsx +10 -4
- package/src/components/tabs/Tabs.stories.tsx +147 -112
- package/src/stories/utils/concatPath.tsx +17 -0
- package/src/stories/utils/toFlattenProps.ts +28 -0
- package/src/stories/utils/withCategory.ts +12 -0
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.4",
|
|
10
|
+
"@lumx/icons": "^3.9.7-alpha.4",
|
|
11
11
|
"@popperjs/core": "^2.5.4",
|
|
12
12
|
"body-scroll-lock": "^3.1.5",
|
|
13
13
|
"classnames": "^2.3.2",
|
|
@@ -110,5 +110,5 @@
|
|
|
110
110
|
"build:storybook": "storybook build"
|
|
111
111
|
},
|
|
112
112
|
"sideEffects": false,
|
|
113
|
-
"version": "3.9.7-alpha.
|
|
113
|
+
"version": "3.9.7-alpha.4"
|
|
114
114
|
}
|
|
@@ -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,135 +1,170 @@
|
|
|
1
|
-
|
|
1
|
+
/* eslint-disable react-hooks/rules-of-hooks */
|
|
2
|
+
|
|
3
|
+
import { Alignment, Button, Dialog, Tab, TabList, TabListLayout, TabPanel, TabProvider } from '@lumx/react';
|
|
4
|
+
import { iconArgType } from '@lumx/react/stories/controls/icons';
|
|
5
|
+
import { getSelectArgType } from '@lumx/react/stories/controls/selectArgType';
|
|
6
|
+
import { withNestedProps } from '@lumx/react/stories/decorators/withNestedProps';
|
|
7
|
+
import { toFlattenProps } from '@lumx/react/stories/utils/toFlattenProps';
|
|
8
|
+
import { withCategory } from '@lumx/react/stories/utils/withCategory';
|
|
2
9
|
import get from 'lodash/get';
|
|
3
10
|
import times from 'lodash/times';
|
|
4
11
|
import React, { useState } from 'react';
|
|
5
12
|
|
|
6
|
-
export default {
|
|
13
|
+
export default {
|
|
14
|
+
title: 'LumX components/tabs',
|
|
15
|
+
decorators: [withNestedProps()],
|
|
16
|
+
parameters: { controls: { sort: 'alpha' } },
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
/** Default tab behavior with some controllable args */
|
|
20
|
+
export const Default = {
|
|
21
|
+
render: ({ theme, tabProviderProps, tabListProps, tabProps }: any) => (
|
|
22
|
+
<TabProvider {...tabProviderProps}>
|
|
23
|
+
<TabList theme={theme} aria-label="Tab list" {...tabListProps}>
|
|
24
|
+
<Tab {...tabProps[0]} />
|
|
25
|
+
<Tab {...tabProps[1]} />
|
|
26
|
+
<Tab {...tabProps[2]} />
|
|
27
|
+
</TabList>
|
|
28
|
+
<TabPanel className="lumx-spacing-padding-huge">{tabProps[0].label} content</TabPanel>
|
|
29
|
+
<TabPanel className="lumx-spacing-padding-huge">{tabProps[1].label} content</TabPanel>
|
|
30
|
+
<TabPanel className="lumx-spacing-padding-huge">{tabProps[2].label} content</TabPanel>
|
|
31
|
+
</TabProvider>
|
|
32
|
+
),
|
|
33
|
+
args: toFlattenProps({
|
|
34
|
+
tabProps: [
|
|
35
|
+
{ label: 'Tab 1' },
|
|
36
|
+
{
|
|
37
|
+
label: 'Tab 2',
|
|
38
|
+
isDisabled: true,
|
|
39
|
+
},
|
|
40
|
+
{ label: 'Tab 3' },
|
|
41
|
+
],
|
|
42
|
+
}),
|
|
43
|
+
argTypes: toFlattenProps({
|
|
44
|
+
tabProviderProps: withCategory('Tab Provider', {
|
|
45
|
+
isLazy: { control: 'boolean' },
|
|
46
|
+
shouldActivateOnFocus: { control: 'boolean' },
|
|
47
|
+
}),
|
|
48
|
+
tabListProps: withCategory('Tab List', {
|
|
49
|
+
layout: getSelectArgType(TabListLayout),
|
|
50
|
+
position: getSelectArgType([Alignment.left, Alignment.center, Alignment.right]),
|
|
51
|
+
}),
|
|
52
|
+
tabProps: times(3, (index) =>
|
|
53
|
+
withCategory(`Tab ${index + 1}`, {
|
|
54
|
+
label: { control: 'text' },
|
|
55
|
+
icon: iconArgType,
|
|
56
|
+
isDisabled: { control: 'boolean' },
|
|
57
|
+
}),
|
|
58
|
+
),
|
|
59
|
+
}),
|
|
60
|
+
};
|
|
7
61
|
|
|
8
62
|
/* Control active tab externally (with activate tab on focus). */
|
|
9
|
-
export const Controlled =
|
|
10
|
-
|
|
11
|
-
|
|
63
|
+
export const Controlled = {
|
|
64
|
+
render({ theme }: any) {
|
|
65
|
+
const [activeTab, setActiveTab] = useState(1);
|
|
66
|
+
const changeActiveTabIndex = (evt: any) => setActiveTab(parseInt(get(evt, 'target.value', '0'), 10));
|
|
12
67
|
|
|
13
|
-
|
|
14
|
-
|
|
68
|
+
const [isLazy, setIsLazy] = useState(true);
|
|
69
|
+
const changeIsLazy = (evt: any) => setIsLazy(get(evt, 'target.checked'));
|
|
15
70
|
|
|
16
|
-
|
|
17
|
-
|
|
71
|
+
const [shouldActivateOnFocus, setShouldActivateOnFocus] = useState(true);
|
|
72
|
+
const changeShouldActivateOnFocus = (evt: any) => setShouldActivateOnFocus(get(evt, 'target.checked'));
|
|
18
73
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
74
|
+
return (
|
|
75
|
+
<>
|
|
76
|
+
<div>
|
|
77
|
+
Active tab index:
|
|
78
|
+
<input type="number" min={0} max={2} value={activeTab} onChange={changeActiveTabIndex} />
|
|
79
|
+
</div>
|
|
25
80
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
81
|
+
<div>
|
|
82
|
+
Lazy render tab panel content:
|
|
83
|
+
<input type="checkbox" checked={isLazy} onChange={changeIsLazy} />
|
|
84
|
+
</div>
|
|
30
85
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
<TabPanel className="lumx-spacing-padding-huge">Tab a content</TabPanel>
|
|
48
|
-
<TabPanel className="lumx-spacing-padding-huge">Tab b content</TabPanel>
|
|
49
|
-
<TabPanel className="lumx-spacing-padding-huge">Tab c content</TabPanel>
|
|
50
|
-
</TabProvider>
|
|
51
|
-
</>
|
|
52
|
-
);
|
|
53
|
-
};
|
|
86
|
+
<div>
|
|
87
|
+
Activate tab on focus:
|
|
88
|
+
<input type="checkbox" checked={shouldActivateOnFocus} onChange={changeShouldActivateOnFocus} />
|
|
89
|
+
</div>
|
|
90
|
+
<TabProvider
|
|
91
|
+
activeTabIndex={activeTab}
|
|
92
|
+
onChange={setActiveTab}
|
|
93
|
+
isLazy={isLazy}
|
|
94
|
+
shouldActivateOnFocus={shouldActivateOnFocus}
|
|
95
|
+
>
|
|
96
|
+
<TabList theme={theme} aria-label="Tab list">
|
|
97
|
+
<Tab label="Tab a" />
|
|
98
|
+
<Tab label="Tab b" />
|
|
99
|
+
<Tab label="Tab c" />
|
|
100
|
+
</TabList>
|
|
54
101
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
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
|
-
);
|
|
102
|
+
<TabPanel className="lumx-spacing-padding-huge">Tab a content</TabPanel>
|
|
103
|
+
<TabPanel className="lumx-spacing-padding-huge">Tab b content</TabPanel>
|
|
104
|
+
<TabPanel className="lumx-spacing-padding-huge">Tab c content</TabPanel>
|
|
105
|
+
</TabProvider>
|
|
106
|
+
</>
|
|
107
|
+
);
|
|
108
|
+
},
|
|
109
|
+
chromatic: { disable: true },
|
|
67
110
|
};
|
|
68
111
|
|
|
69
112
|
/* Display tabs far from their tab panels. */
|
|
70
|
-
export const
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
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
|
-
);
|
|
113
|
+
export const SplitTabListAndTabPanels = {
|
|
114
|
+
render({ theme }: any) {
|
|
115
|
+
const [isOpen, setOpen] = useState(true);
|
|
116
|
+
const [activeTabIndex, onChange] = useState(1);
|
|
82
117
|
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
</Button>
|
|
98
|
-
<Dialog isOpen={isOpen} forceFooterDivider onClose={() => setOpen(false)}>
|
|
99
|
-
<TabPanel className="lumx-spacing-padding-huge">Tab 1 content</TabPanel>
|
|
100
|
-
<TabPanel className="lumx-spacing-padding-huge">Tab 2 content</TabPanel>
|
|
101
|
-
<TabPanel className="lumx-spacing-padding-huge">Tab 3 content</TabPanel>
|
|
118
|
+
return (
|
|
119
|
+
<TabProvider activeTabIndex={activeTabIndex} onChange={onChange} isLazy={false}>
|
|
120
|
+
<Button
|
|
121
|
+
onClick={() => {
|
|
122
|
+
setOpen(!isOpen);
|
|
123
|
+
onChange(1);
|
|
124
|
+
}}
|
|
125
|
+
>
|
|
126
|
+
Open dialog with tabs in footer
|
|
127
|
+
</Button>
|
|
128
|
+
<Dialog isOpen={isOpen} forceFooterDivider onClose={() => setOpen(false)}>
|
|
129
|
+
<TabPanel className="lumx-spacing-padding-huge">Tab 1 content</TabPanel>
|
|
130
|
+
<TabPanel className="lumx-spacing-padding-huge">Tab 2 content</TabPanel>
|
|
131
|
+
<TabPanel className="lumx-spacing-padding-huge">Tab 3 content</TabPanel>
|
|
102
132
|
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
133
|
+
<footer>
|
|
134
|
+
<TabList theme={theme} aria-label="Tab list">
|
|
135
|
+
<Tab label="Tab 1" />
|
|
136
|
+
<Tab label="Tab 2" />
|
|
137
|
+
<Tab label="Tab 3" />
|
|
138
|
+
</TabList>
|
|
139
|
+
</footer>
|
|
140
|
+
</Dialog>
|
|
141
|
+
</TabProvider>
|
|
142
|
+
);
|
|
143
|
+
},
|
|
144
|
+
chromatic: { disable: true },
|
|
113
145
|
};
|
|
114
146
|
|
|
115
147
|
/* Dynamically generate tabs. */
|
|
116
|
-
export const DynamicTabs =
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
<
|
|
148
|
+
export const DynamicTabs = {
|
|
149
|
+
render({ theme, tabCount }: any) {
|
|
150
|
+
return (
|
|
151
|
+
<TabProvider>
|
|
152
|
+
<TabList theme={theme} aria-label="Tab list">
|
|
153
|
+
{times(tabCount, (tabNumber) => (
|
|
154
|
+
<Tab key={tabNumber} label={`Tab ${tabNumber}`} />
|
|
155
|
+
))}
|
|
156
|
+
</TabList>
|
|
157
|
+
|
|
120
158
|
{times(tabCount, (tabNumber) => (
|
|
121
|
-
<
|
|
159
|
+
<TabPanel key={tabNumber} className="lumx-spacing-padding-huge">
|
|
160
|
+
Tab {tabNumber} content
|
|
161
|
+
</TabPanel>
|
|
122
162
|
))}
|
|
123
|
-
</
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
</TabProvider>
|
|
131
|
-
);
|
|
132
|
-
};
|
|
133
|
-
DynamicTabs.args = {
|
|
134
|
-
tabCount: 3,
|
|
163
|
+
</TabProvider>
|
|
164
|
+
);
|
|
165
|
+
},
|
|
166
|
+
args: {
|
|
167
|
+
tabCount: 3,
|
|
168
|
+
},
|
|
169
|
+
chromatic: { disable: true },
|
|
135
170
|
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export type PathPart = string | number;
|
|
2
|
+
export type Path = PathPart | Array<PathPart>;
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Concat flatten object path
|
|
6
|
+
*
|
|
7
|
+
* @example concatPath('foo', 'bar') // => 'foo.bar'
|
|
8
|
+
* @example concatPath(['foo', 0]) // => 'foo[0]'
|
|
9
|
+
* @example concatPath('foo', 0, ['bar']) // => 'foo[0].bar'
|
|
10
|
+
*/
|
|
11
|
+
export const concatPath = (...prefix: Path[]) => {
|
|
12
|
+
const [first, ...rest] = prefix.flat();
|
|
13
|
+
return rest.reduce<string>((acc, part) => {
|
|
14
|
+
if (typeof part === 'number') return `${acc}[${part}]`;
|
|
15
|
+
return `${acc}.${part}`;
|
|
16
|
+
}, String(first));
|
|
17
|
+
};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import castArray from 'lodash/castArray';
|
|
2
|
+
import { concatPath } from './concatPath';
|
|
3
|
+
|
|
4
|
+
type Props = Record<string, any>;
|
|
5
|
+
type OneOrMoreProps = Props | Array<Props>;
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Build a flat props object from the given nested props
|
|
9
|
+
*
|
|
10
|
+
* @example toFlattenProps({ foo: { bar: 4 } }) // => { 'foo.bar': 4 }
|
|
11
|
+
* @example toFlattenProps({ foo: [{ bar: 4 }, { bar: 5 }] }) // => { 'foo[0].bar': 4, 'foo[0].bar': 5 }
|
|
12
|
+
*/
|
|
13
|
+
export function toFlattenProps(props: { [prefix: string]: OneOrMoreProps }): Props {
|
|
14
|
+
const out: Props = {};
|
|
15
|
+
for (const [prefix, oneOrMoreProps] of Object.entries(props)) {
|
|
16
|
+
const propsArray = castArray(oneOrMoreProps);
|
|
17
|
+
|
|
18
|
+
for (let i = 0; i < propsArray.length; i += 1) {
|
|
19
|
+
const path = Array.isArray(oneOrMoreProps) ? concatPath(prefix, i) : prefix;
|
|
20
|
+
const subProps = propsArray[i];
|
|
21
|
+
|
|
22
|
+
for (const [key, value] of Object.entries(subProps)) {
|
|
23
|
+
out[concatPath(path, key)] = value;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
return out;
|
|
28
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import setWith from 'lodash/setWith';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Add table.category to the provided argTypes
|
|
5
|
+
*/
|
|
6
|
+
export function withCategory(category: string, argTypes: Record<string, any>) {
|
|
7
|
+
const out: typeof argTypes = {};
|
|
8
|
+
for (const [key, value] of Object.entries(argTypes)) {
|
|
9
|
+
out[key] = setWith({ ...value }, 'table.category', category);
|
|
10
|
+
}
|
|
11
|
+
return out;
|
|
12
|
+
}
|