@ssa-ui-kit/core 2.23.2 → 2.25.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,3 +1,3 @@
|
|
|
1
1
|
import { SmallTabProps } from '../TabBar/types';
|
|
2
|
-
declare const Tab: ({ onClick, isActive, text, ariaControls, tabId, }: SmallTabProps) => import("@emotion/react/jsx-runtime").JSX.Element;
|
|
2
|
+
declare const Tab: ({ onClick, isActive, text, ariaControls, tabId, className, }: SmallTabProps) => import("@emotion/react/jsx-runtime").JSX.Element;
|
|
3
3
|
export default Tab;
|
|
@@ -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
|
@@ -7849,7 +7849,8 @@ const Tab = ({
|
|
|
7849
7849
|
isActive,
|
|
7850
7850
|
text,
|
|
7851
7851
|
ariaControls,
|
|
7852
|
-
tabId
|
|
7852
|
+
tabId,
|
|
7853
|
+
className
|
|
7853
7854
|
}) => {
|
|
7854
7855
|
return (0,jsx_runtime_namespaceObject.jsx)(TabBase, {
|
|
7855
7856
|
role: "tab",
|
|
@@ -7859,6 +7860,7 @@ const Tab = ({
|
|
|
7859
7860
|
tabIndex: 0,
|
|
7860
7861
|
isActive: isActive,
|
|
7861
7862
|
title: text,
|
|
7863
|
+
className: className,
|
|
7862
7864
|
onClick: () => {
|
|
7863
7865
|
// istanbul ignore else
|
|
7864
7866
|
if (typeof onClick === 'function') {
|
|
@@ -7880,30 +7882,30 @@ const defaultTab = {
|
|
|
7880
7882
|
};
|
|
7881
7883
|
const TabBarContext = /*#__PURE__*/(0,external_react_namespaceObject.createContext)({
|
|
7882
7884
|
activeTab: defaultTab,
|
|
7885
|
+
activeTabId: undefined,
|
|
7886
|
+
selectedTabId: undefined,
|
|
7883
7887
|
setActiveTab() {
|
|
7884
7888
|
/* default no-op */
|
|
7889
|
+
},
|
|
7890
|
+
setActiveTabId() {
|
|
7891
|
+
/* default no-op */
|
|
7885
7892
|
}
|
|
7886
7893
|
});
|
|
7887
7894
|
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
7895
|
const TabBarContextProvider = ({
|
|
7896
7896
|
initialTab = defaultTab,
|
|
7897
|
+
selectedTabId = defaultTab.tabId,
|
|
7897
7898
|
children
|
|
7898
7899
|
}) => {
|
|
7899
|
-
const
|
|
7900
|
-
|
|
7901
|
-
setActiveTab
|
|
7902
|
-
} = useTabBar(initialTab);
|
|
7900
|
+
const [activeTab, setActiveTab] = (0,external_react_namespaceObject.useState)(initialTab);
|
|
7901
|
+
const [activeTabId, setActiveTabId] = (0,external_react_namespaceObject.useState)(initialTab.tabId);
|
|
7903
7902
|
return (0,jsx_runtime_namespaceObject.jsx)(TabBarContext.Provider, {
|
|
7904
7903
|
value: {
|
|
7905
7904
|
activeTab,
|
|
7906
|
-
|
|
7905
|
+
activeTabId,
|
|
7906
|
+
selectedTabId,
|
|
7907
|
+
setActiveTab,
|
|
7908
|
+
setActiveTabId
|
|
7907
7909
|
},
|
|
7908
7910
|
children: children
|
|
7909
7911
|
});
|
|
@@ -7930,27 +7932,42 @@ const TabBar = ({
|
|
|
7930
7932
|
}) => {
|
|
7931
7933
|
const {
|
|
7932
7934
|
activeTab,
|
|
7933
|
-
|
|
7935
|
+
selectedTabId,
|
|
7936
|
+
setActiveTab,
|
|
7937
|
+
setActiveTabId
|
|
7934
7938
|
} = useTabBarContext();
|
|
7935
|
-
const
|
|
7939
|
+
const setSelectedTabId = tabId => {
|
|
7940
|
+
if (tabId && activeTab?.tabId !== tabId) {
|
|
7941
|
+
external_react_namespaceObject.Children.forEach(children, child => {
|
|
7942
|
+
if (/*#__PURE__*/(0,external_react_namespaceObject.isValidElement)(child) && child.props.tabId === tabId) {
|
|
7943
|
+
const {
|
|
7944
|
+
renderContent,
|
|
7945
|
+
...rest
|
|
7946
|
+
} = child.props;
|
|
7947
|
+
setActiveTab({
|
|
7948
|
+
tabId: rest.tabId,
|
|
7949
|
+
renderContent: renderContent.bind(null, rest)
|
|
7950
|
+
});
|
|
7951
|
+
}
|
|
7952
|
+
});
|
|
7953
|
+
}
|
|
7954
|
+
setActiveTabId(tabId);
|
|
7955
|
+
};
|
|
7956
|
+
(0,external_react_namespaceObject.useEffect)(() => {
|
|
7957
|
+
if (!Number.isNaN(selectedTabId) && activeTab?.tabId !== selectedTabId) {
|
|
7958
|
+
setSelectedTabId(selectedTabId);
|
|
7959
|
+
}
|
|
7960
|
+
}, [selectedTabId]);
|
|
7936
7961
|
return (0,jsx_runtime_namespaceObject.jsx)(TabBarBase, {
|
|
7937
7962
|
role: "tablist",
|
|
7938
7963
|
className: className,
|
|
7939
7964
|
children: external_react_namespaceObject.Children.map(children, child => {
|
|
7940
7965
|
// istanbul ignore else
|
|
7941
7966
|
if (/*#__PURE__*/(0,external_react_namespaceObject.isValidElement)(child)) {
|
|
7942
|
-
const {
|
|
7943
|
-
renderContent,
|
|
7944
|
-
...rest
|
|
7945
|
-
} = child.props;
|
|
7946
|
-
const tabId = rest.tabId;
|
|
7947
7967
|
return /*#__PURE__*/(0,external_react_namespaceObject.cloneElement)(child, {
|
|
7948
|
-
key: tabId,
|
|
7949
|
-
isActive:
|
|
7950
|
-
onClick: () =>
|
|
7951
|
-
tabId,
|
|
7952
|
-
renderContent: renderContent.bind(null, rest)
|
|
7953
|
-
})
|
|
7968
|
+
key: child.props.tabId,
|
|
7969
|
+
isActive: activeTab?.tabId === child.props.tabId,
|
|
7970
|
+
onClick: () => setSelectedTabId(child.props.tabId)
|
|
7954
7971
|
});
|
|
7955
7972
|
}
|
|
7956
7973
|
})
|