From ee4021581ee8bcf2ec75365b452fa414c00a4362 Mon Sep 17 00:00:00 2001 From: Hao Zhou Date: Wed, 4 Dec 2024 14:32:35 +0800 Subject: [PATCH] feat(TabList): separate the binding relationship between TabContext and RcTabList --- .../components/Tabs/TabContext/TabContext.tsx | 3 ++- .../src/components/Tabs/TabList/TabList.tsx | 25 +++++++++++++------ sync-github.json | 2 +- 3 files changed, 21 insertions(+), 9 deletions(-) diff --git a/packages/juno-core/src/components/Tabs/TabContext/TabContext.tsx b/packages/juno-core/src/components/Tabs/TabContext/TabContext.tsx index 2163c5ad..7082d0a2 100644 --- a/packages/juno-core/src/components/Tabs/TabContext/TabContext.tsx +++ b/packages/juno-core/src/components/Tabs/TabContext/TabContext.tsx @@ -4,6 +4,7 @@ import MuiTabContext, { getPanelId, getTabId, useTabContext, + TabContextValue, } from '@material-ui/lab/TabContext'; const RcTabContext = MuiTabContext as FunctionComponent< @@ -12,4 +13,4 @@ const RcTabContext = MuiTabContext as FunctionComponent< RcTabContext.displayName = 'RcTabContext'; -export { getPanelId, getTabId, RcTabContext, useTabContext }; +export { getPanelId, getTabId, RcTabContext, useTabContext, TabContextValue }; diff --git a/packages/juno-core/src/components/Tabs/TabList/TabList.tsx b/packages/juno-core/src/components/Tabs/TabList/TabList.tsx index d67de8bc..ea28237b 100644 --- a/packages/juno-core/src/components/Tabs/TabList/TabList.tsx +++ b/packages/juno-core/src/components/Tabs/TabList/TabList.tsx @@ -12,26 +12,37 @@ import { useThemeProps, } from '../../../foundation'; import { RcTabProps } from '../Tab/Tab'; -import { getPanelId, getTabId, useTabContext } from '../TabContext'; +import { + getPanelId, + getTabId, + useTabContext, + TabContextValue, +} from '../TabContext'; import { RcTabs, RcTabsProps } from '../Tabs'; import { TabListStyle } from './styles'; import { RcTabListClasses } from './utils'; -type RcTabListProps = {} & RcBaseProps; +type RcTabListProps = Partial & RcBaseProps; const _RcTabList = forwardRef( (inProps: RcTabListProps, ref) => { const props = useThemeProps({ props: inProps, name: 'RcTabList' }); - const { classes: classesProp, children: childrenProp, ...rest } = props; + const { + classes: classesProp, + children: childrenProp, + idPrefix = '', + value, + ...rest + } = props; const classes = useMemo( () => combineClasses(RcTabListClasses, classesProp), [classesProp], ); - const context = useTabContext(); - if (context === null) { - throw new TypeError('[RcTabList] No TabContext provided'); - } + const context = useTabContext() || { + value, + idPrefix, + }; const children = useMemo( () => diff --git a/sync-github.json b/sync-github.json index f3aa4273..dd030eb7 100644 --- a/sync-github.json +++ b/sync-github.json @@ -1,3 +1,3 @@ { - "latestCommitSHA": "d1f0e11c4041f850796e36ebc2e67def862b0b48" + "latestCommitSHA": "acd05954c6ebe53a00888d50324f5f0d94a5c44d" } \ No newline at end of file