@jobber/components 6.5.4 → 6.6.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/dist/Tabs/Tabs.d.ts +7 -1
- package/dist/Tabs-cjs.js +7 -4
- package/dist/Tabs-es.js +7 -4
- package/package.json +2 -2
package/dist/Tabs/Tabs.d.ts
CHANGED
|
@@ -7,13 +7,19 @@ interface TabsProps {
|
|
|
7
7
|
* @default 0
|
|
8
8
|
*/
|
|
9
9
|
readonly defaultTab?: number;
|
|
10
|
+
/**
|
|
11
|
+
* Specifies the index of the active tab.
|
|
12
|
+
* If provided, the component will be controlled and the active tab will be determined by this prop.
|
|
13
|
+
* If not provided, the component will manage its own state internally.
|
|
14
|
+
*/
|
|
15
|
+
readonly activeTab?: number;
|
|
10
16
|
/**
|
|
11
17
|
* Callback that fires when the active tab changes
|
|
12
18
|
* @param newTabIndex
|
|
13
19
|
*/
|
|
14
20
|
onTabChange?(newTabIndex: number): void;
|
|
15
21
|
}
|
|
16
|
-
export declare function Tabs({ children, defaultTab, onTabChange }: TabsProps): JSX.Element;
|
|
22
|
+
export declare function Tabs({ children, defaultTab, activeTab: controlledActiveTab, onTabChange, }: TabsProps): JSX.Element;
|
|
17
23
|
interface TabProps {
|
|
18
24
|
readonly label: string | ReactNode;
|
|
19
25
|
readonly children: ReactNode | ReactNode[];
|
package/dist/Tabs-cjs.js
CHANGED
|
@@ -38,10 +38,11 @@ function useTabsOverflow() {
|
|
|
38
38
|
};
|
|
39
39
|
}
|
|
40
40
|
|
|
41
|
-
function Tabs({ children, defaultTab = 0, onTabChange }) {
|
|
41
|
+
function Tabs({ children, defaultTab = 0, activeTab: controlledActiveTab, onTabChange, }) {
|
|
42
42
|
var _a;
|
|
43
43
|
const activeTabInitialValue = defaultTab < React.Children.count(children) ? defaultTab : 0;
|
|
44
|
-
const [
|
|
44
|
+
const [internalActiveTab, setInternalActiveTab] = React.useState(activeTabInitialValue);
|
|
45
|
+
const activeTab = controlledActiveTab !== undefined ? controlledActiveTab : internalActiveTab;
|
|
45
46
|
const { overflowRight, overflowLeft, tabRow } = useTabsOverflow();
|
|
46
47
|
const overflowClassNames = classnames(styles.overflow, {
|
|
47
48
|
[styles.overflowRight]: overflowRight,
|
|
@@ -49,7 +50,9 @@ function Tabs({ children, defaultTab = 0, onTabChange }) {
|
|
|
49
50
|
});
|
|
50
51
|
const activateTab = (index) => {
|
|
51
52
|
return () => {
|
|
52
|
-
|
|
53
|
+
if (controlledActiveTab === undefined) {
|
|
54
|
+
setInternalActiveTab(index);
|
|
55
|
+
}
|
|
53
56
|
if (onTabChange) {
|
|
54
57
|
onTabChange(index);
|
|
55
58
|
}
|
|
@@ -58,7 +61,7 @@ function Tabs({ children, defaultTab = 0, onTabChange }) {
|
|
|
58
61
|
const activeTabProps = (_a = React.Children.toArray(children)[activeTab]) === null || _a === void 0 ? void 0 : _a.props;
|
|
59
62
|
React.useEffect(() => {
|
|
60
63
|
if (activeTab > React.Children.count(children) - 1) {
|
|
61
|
-
|
|
64
|
+
setInternalActiveTab(activeTabInitialValue);
|
|
62
65
|
}
|
|
63
66
|
}, [React.Children.count(children)]);
|
|
64
67
|
return (React.createElement("div", { className: styles.tabs },
|
package/dist/Tabs-es.js
CHANGED
|
@@ -36,10 +36,11 @@ function useTabsOverflow() {
|
|
|
36
36
|
};
|
|
37
37
|
}
|
|
38
38
|
|
|
39
|
-
function Tabs({ children, defaultTab = 0, onTabChange }) {
|
|
39
|
+
function Tabs({ children, defaultTab = 0, activeTab: controlledActiveTab, onTabChange, }) {
|
|
40
40
|
var _a;
|
|
41
41
|
const activeTabInitialValue = defaultTab < React.Children.count(children) ? defaultTab : 0;
|
|
42
|
-
const [
|
|
42
|
+
const [internalActiveTab, setInternalActiveTab] = useState(activeTabInitialValue);
|
|
43
|
+
const activeTab = controlledActiveTab !== undefined ? controlledActiveTab : internalActiveTab;
|
|
43
44
|
const { overflowRight, overflowLeft, tabRow } = useTabsOverflow();
|
|
44
45
|
const overflowClassNames = classnames(styles.overflow, {
|
|
45
46
|
[styles.overflowRight]: overflowRight,
|
|
@@ -47,7 +48,9 @@ function Tabs({ children, defaultTab = 0, onTabChange }) {
|
|
|
47
48
|
});
|
|
48
49
|
const activateTab = (index) => {
|
|
49
50
|
return () => {
|
|
50
|
-
|
|
51
|
+
if (controlledActiveTab === undefined) {
|
|
52
|
+
setInternalActiveTab(index);
|
|
53
|
+
}
|
|
51
54
|
if (onTabChange) {
|
|
52
55
|
onTabChange(index);
|
|
53
56
|
}
|
|
@@ -56,7 +59,7 @@ function Tabs({ children, defaultTab = 0, onTabChange }) {
|
|
|
56
59
|
const activeTabProps = (_a = React.Children.toArray(children)[activeTab]) === null || _a === void 0 ? void 0 : _a.props;
|
|
57
60
|
useEffect(() => {
|
|
58
61
|
if (activeTab > React.Children.count(children) - 1) {
|
|
59
|
-
|
|
62
|
+
setInternalActiveTab(activeTabInitialValue);
|
|
60
63
|
}
|
|
61
64
|
}, [React.Children.count(children)]);
|
|
62
65
|
return (React.createElement("div", { className: styles.tabs },
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jobber/components",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.6.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.cjs",
|
|
@@ -487,5 +487,5 @@
|
|
|
487
487
|
"> 1%",
|
|
488
488
|
"IE 10"
|
|
489
489
|
],
|
|
490
|
-
"gitHead": "
|
|
490
|
+
"gitHead": "8cb3c997c952f9319a5881b5cf0cb0a7aecb4d49"
|
|
491
491
|
}
|