@ssa-ui-kit/core 2.23.2 → 2.24.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.
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { TabProps, TabBarContextProps } from './types';
|
|
2
2
|
export declare const TabBarContext: import("react").Context<TabBarContextProps>;
|
|
3
3
|
export declare const useTabBarContext: () => TabBarContextProps;
|
|
4
|
-
export declare const TabBarContextProvider: ({ initialTab, children, }: {
|
|
4
|
+
export declare const TabBarContextProvider: ({ initialTab, selectedTabId, children, }: {
|
|
5
5
|
initialTab?: TabProps;
|
|
6
|
+
selectedTabId?: TabProps["tabId"];
|
|
6
7
|
children: React.ReactNode;
|
|
7
8
|
}) => import("@emotion/react/jsx-runtime").JSX.Element;
|
|
@@ -23,5 +23,8 @@ export interface TabBarProps {
|
|
|
23
23
|
}
|
|
24
24
|
export interface TabBarContextProps {
|
|
25
25
|
activeTab?: TabProps;
|
|
26
|
+
activeTabId?: TabProps['tabId'];
|
|
27
|
+
selectedTabId?: TabProps['tabId'];
|
|
26
28
|
setActiveTab: (tab?: TabProps) => void;
|
|
29
|
+
setActiveTabId: (tabId?: number | string) => void;
|
|
27
30
|
}
|
package/dist/index.js
CHANGED
|
@@ -7880,30 +7880,30 @@ const defaultTab = {
|
|
|
7880
7880
|
};
|
|
7881
7881
|
const TabBarContext = /*#__PURE__*/(0,external_react_namespaceObject.createContext)({
|
|
7882
7882
|
activeTab: defaultTab,
|
|
7883
|
+
activeTabId: undefined,
|
|
7884
|
+
selectedTabId: undefined,
|
|
7883
7885
|
setActiveTab() {
|
|
7884
7886
|
/* default no-op */
|
|
7887
|
+
},
|
|
7888
|
+
setActiveTabId() {
|
|
7889
|
+
/* default no-op */
|
|
7885
7890
|
}
|
|
7886
7891
|
});
|
|
7887
7892
|
const useTabBarContext = () => (0,external_react_namespaceObject.useContext)(TabBarContext);
|
|
7888
|
-
const useTabBar = initialTab => {
|
|
7889
|
-
const [tab, setTab] = (0,external_react_namespaceObject.useState)(initialTab);
|
|
7890
|
-
return {
|
|
7891
|
-
activeTab: tab,
|
|
7892
|
-
setActiveTab: tab => setTab(tab)
|
|
7893
|
-
};
|
|
7894
|
-
};
|
|
7895
7893
|
const TabBarContextProvider = ({
|
|
7896
7894
|
initialTab = defaultTab,
|
|
7895
|
+
selectedTabId = defaultTab.tabId,
|
|
7897
7896
|
children
|
|
7898
7897
|
}) => {
|
|
7899
|
-
const
|
|
7900
|
-
|
|
7901
|
-
setActiveTab
|
|
7902
|
-
} = useTabBar(initialTab);
|
|
7898
|
+
const [activeTab, setActiveTab] = (0,external_react_namespaceObject.useState)(initialTab);
|
|
7899
|
+
const [activeTabId, setActiveTabId] = (0,external_react_namespaceObject.useState)(initialTab.tabId);
|
|
7903
7900
|
return (0,jsx_runtime_namespaceObject.jsx)(TabBarContext.Provider, {
|
|
7904
7901
|
value: {
|
|
7905
7902
|
activeTab,
|
|
7906
|
-
|
|
7903
|
+
activeTabId,
|
|
7904
|
+
selectedTabId,
|
|
7905
|
+
setActiveTab,
|
|
7906
|
+
setActiveTabId
|
|
7907
7907
|
},
|
|
7908
7908
|
children: children
|
|
7909
7909
|
});
|
|
@@ -7930,27 +7930,42 @@ const TabBar = ({
|
|
|
7930
7930
|
}) => {
|
|
7931
7931
|
const {
|
|
7932
7932
|
activeTab,
|
|
7933
|
-
|
|
7933
|
+
selectedTabId,
|
|
7934
|
+
setActiveTab,
|
|
7935
|
+
setActiveTabId
|
|
7934
7936
|
} = useTabBarContext();
|
|
7935
|
-
const
|
|
7937
|
+
const setSelectedTabId = tabId => {
|
|
7938
|
+
if (tabId && activeTab?.tabId !== tabId) {
|
|
7939
|
+
external_react_namespaceObject.Children.forEach(children, child => {
|
|
7940
|
+
if (/*#__PURE__*/(0,external_react_namespaceObject.isValidElement)(child) && child.props.tabId === tabId) {
|
|
7941
|
+
const {
|
|
7942
|
+
renderContent,
|
|
7943
|
+
...rest
|
|
7944
|
+
} = child.props;
|
|
7945
|
+
setActiveTab({
|
|
7946
|
+
tabId: rest.tabId,
|
|
7947
|
+
renderContent: renderContent.bind(null, rest)
|
|
7948
|
+
});
|
|
7949
|
+
}
|
|
7950
|
+
});
|
|
7951
|
+
}
|
|
7952
|
+
setActiveTabId(tabId);
|
|
7953
|
+
};
|
|
7954
|
+
(0,external_react_namespaceObject.useEffect)(() => {
|
|
7955
|
+
if (!Number.isNaN(selectedTabId) && activeTab?.tabId !== selectedTabId) {
|
|
7956
|
+
setSelectedTabId(selectedTabId);
|
|
7957
|
+
}
|
|
7958
|
+
}, [selectedTabId]);
|
|
7936
7959
|
return (0,jsx_runtime_namespaceObject.jsx)(TabBarBase, {
|
|
7937
7960
|
role: "tablist",
|
|
7938
7961
|
className: className,
|
|
7939
7962
|
children: external_react_namespaceObject.Children.map(children, child => {
|
|
7940
7963
|
// istanbul ignore else
|
|
7941
7964
|
if (/*#__PURE__*/(0,external_react_namespaceObject.isValidElement)(child)) {
|
|
7942
|
-
const {
|
|
7943
|
-
renderContent,
|
|
7944
|
-
...rest
|
|
7945
|
-
} = child.props;
|
|
7946
|
-
const tabId = rest.tabId;
|
|
7947
7965
|
return /*#__PURE__*/(0,external_react_namespaceObject.cloneElement)(child, {
|
|
7948
|
-
key: tabId,
|
|
7949
|
-
isActive:
|
|
7950
|
-
onClick: () =>
|
|
7951
|
-
tabId,
|
|
7952
|
-
renderContent: renderContent.bind(null, rest)
|
|
7953
|
-
})
|
|
7966
|
+
key: child.props.tabId,
|
|
7967
|
+
isActive: activeTab?.tabId === child.props.tabId,
|
|
7968
|
+
onClick: () => setSelectedTabId(child.props.tabId)
|
|
7954
7969
|
});
|
|
7955
7970
|
}
|
|
7956
7971
|
})
|