carbon-react 111.22.0 → 111.22.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/esm/__internal__/utils/storybook/partial-action.d.ts +3 -0
- package/esm/__internal__/utils/storybook/partial-action.js +13 -0
- package/esm/components/tabs/tab/tab.component.js +12 -18
- package/esm/components/tabs/tabs.component.js +12 -18
- package/lib/__internal__/utils/storybook/partial-action.d.ts +3 -0
- package/lib/__internal__/utils/storybook/partial-action.js +21 -0
- package/lib/components/tabs/tab/tab.component.js +12 -18
- package/lib/components/tabs/tabs.component.js +12 -18
- package/package.json +1 -1
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { action } from "@storybook/addon-actions";
|
|
2
|
+
|
|
3
|
+
function partialAction(actionName) {
|
|
4
|
+
return (eventObj, ...args) => {
|
|
5
|
+
action(actionName)(typeof eventObj === "string" ? {
|
|
6
|
+
view: undefined
|
|
7
|
+
} : { ...eventObj,
|
|
8
|
+
view: undefined
|
|
9
|
+
}, ...args);
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export default partialAction;
|
|
@@ -28,26 +28,20 @@ const Tab = ({
|
|
|
28
28
|
const [tabWarnings, setTabWarnings] = useState({});
|
|
29
29
|
const [tabInfos, setTabInfos] = useState({});
|
|
30
30
|
const setError = useCallback((childId, error) => {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
}
|
|
36
|
-
}, [tabErrors]);
|
|
31
|
+
setTabErrors(state => state[childId] !== error ? { ...state,
|
|
32
|
+
[childId]: error
|
|
33
|
+
} : state);
|
|
34
|
+
}, []);
|
|
37
35
|
const setWarning = useCallback((childId, warning) => {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
}
|
|
43
|
-
}, [tabWarnings]);
|
|
36
|
+
setTabWarnings(state => state[childId] !== warning ? { ...state,
|
|
37
|
+
[childId]: warning
|
|
38
|
+
} : state);
|
|
39
|
+
}, []);
|
|
44
40
|
const setInfo = useCallback((childId, info) => {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
}
|
|
50
|
-
}, [tabInfos]);
|
|
41
|
+
setTabInfos(state => state[childId] !== info ? { ...state,
|
|
42
|
+
[childId]: info
|
|
43
|
+
} : state);
|
|
44
|
+
}, []);
|
|
51
45
|
useEffect(() => {
|
|
52
46
|
if (updateErrors) {
|
|
53
47
|
updateErrors(tabId, tabErrors);
|
|
@@ -50,26 +50,20 @@ const Tabs = ({
|
|
|
50
50
|
const [tabsWarnings, setTabsWarnings] = useState({});
|
|
51
51
|
const [tabsInfos, setTabsInfos] = useState({});
|
|
52
52
|
const updateErrors = useCallback((id, error) => {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
}
|
|
58
|
-
}, [tabsErrors]);
|
|
53
|
+
setTabsErrors(state => ({ ...state,
|
|
54
|
+
[id]: error
|
|
55
|
+
}));
|
|
56
|
+
}, []);
|
|
59
57
|
const updateWarnings = useCallback((id, warning) => {
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
}
|
|
65
|
-
}, [tabsWarnings]);
|
|
58
|
+
setTabsWarnings(state => ({ ...state,
|
|
59
|
+
[id]: warning
|
|
60
|
+
}));
|
|
61
|
+
}, []);
|
|
66
62
|
const updateInfos = useCallback((id, info) => {
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
}
|
|
72
|
-
}, [tabsInfos]);
|
|
63
|
+
setTabsInfos(state => ({ ...state,
|
|
64
|
+
[id]: info
|
|
65
|
+
}));
|
|
66
|
+
}, []);
|
|
73
67
|
/** Returns true/false for if the given tab id is selected. */
|
|
74
68
|
|
|
75
69
|
const isTabSelected = useCallback(tabId => tabId === selectedTabIdState, [selectedTabIdState]);
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
|
|
8
|
+
var _addonActions = require("@storybook/addon-actions");
|
|
9
|
+
|
|
10
|
+
function partialAction(actionName) {
|
|
11
|
+
return (eventObj, ...args) => {
|
|
12
|
+
(0, _addonActions.action)(actionName)(typeof eventObj === "string" ? {
|
|
13
|
+
view: undefined
|
|
14
|
+
} : { ...eventObj,
|
|
15
|
+
view: undefined
|
|
16
|
+
}, ...args);
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
var _default = partialAction;
|
|
21
|
+
exports.default = _default;
|
|
@@ -49,26 +49,20 @@ const Tab = ({
|
|
|
49
49
|
const [tabWarnings, setTabWarnings] = (0, _react.useState)({});
|
|
50
50
|
const [tabInfos, setTabInfos] = (0, _react.useState)({});
|
|
51
51
|
const setError = (0, _react.useCallback)((childId, error) => {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
}
|
|
57
|
-
}, [tabErrors]);
|
|
52
|
+
setTabErrors(state => state[childId] !== error ? { ...state,
|
|
53
|
+
[childId]: error
|
|
54
|
+
} : state);
|
|
55
|
+
}, []);
|
|
58
56
|
const setWarning = (0, _react.useCallback)((childId, warning) => {
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
}
|
|
64
|
-
}, [tabWarnings]);
|
|
57
|
+
setTabWarnings(state => state[childId] !== warning ? { ...state,
|
|
58
|
+
[childId]: warning
|
|
59
|
+
} : state);
|
|
60
|
+
}, []);
|
|
65
61
|
const setInfo = (0, _react.useCallback)((childId, info) => {
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
}
|
|
71
|
-
}, [tabInfos]);
|
|
62
|
+
setTabInfos(state => state[childId] !== info ? { ...state,
|
|
63
|
+
[childId]: info
|
|
64
|
+
} : state);
|
|
65
|
+
}, []);
|
|
72
66
|
(0, _react.useEffect)(() => {
|
|
73
67
|
if (updateErrors) {
|
|
74
68
|
updateErrors(tabId, tabErrors);
|
|
@@ -80,26 +80,20 @@ const Tabs = ({
|
|
|
80
80
|
const [tabsWarnings, setTabsWarnings] = (0, _react.useState)({});
|
|
81
81
|
const [tabsInfos, setTabsInfos] = (0, _react.useState)({});
|
|
82
82
|
const updateErrors = (0, _react.useCallback)((id, error) => {
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
}
|
|
88
|
-
}, [tabsErrors]);
|
|
83
|
+
setTabsErrors(state => ({ ...state,
|
|
84
|
+
[id]: error
|
|
85
|
+
}));
|
|
86
|
+
}, []);
|
|
89
87
|
const updateWarnings = (0, _react.useCallback)((id, warning) => {
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
}
|
|
95
|
-
}, [tabsWarnings]);
|
|
88
|
+
setTabsWarnings(state => ({ ...state,
|
|
89
|
+
[id]: warning
|
|
90
|
+
}));
|
|
91
|
+
}, []);
|
|
96
92
|
const updateInfos = (0, _react.useCallback)((id, info) => {
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
}
|
|
102
|
-
}, [tabsInfos]);
|
|
93
|
+
setTabsInfos(state => ({ ...state,
|
|
94
|
+
[id]: info
|
|
95
|
+
}));
|
|
96
|
+
}, []);
|
|
103
97
|
/** Returns true/false for if the given tab id is selected. */
|
|
104
98
|
|
|
105
99
|
const isTabSelected = (0, _react.useCallback)(tabId => tabId === selectedTabIdState, [selectedTabIdState]);
|