Skip to content

Commit 2f0c3bc

Browse files
ryan953c298lee
authored andcommitted
ref(tabs): Refactor to separate TabStateProvider from the TabsWrap styles (#77175)
I need to separate the state from the styles because the styles are difficult to use inside a flex/grid system. For the hydration error diff modal I need to insert some other css in there, and the api to override TabsWrap seemed more hacky than simply setting what's needed directly.
1 parent 22cd249 commit 2f0c3bc

File tree

1 file changed

+21
-6
lines changed

1 file changed

+21
-6
lines changed

static/app/components/tabs/index.tsx

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,25 @@ export const TabsContext = createContext<TabContext>({
5454
setTabListState: () => {},
5555
});
5656

57+
export function TabStateProvider<T extends string | number>({
58+
children,
59+
...props
60+
}: Omit<TabsProps<T>, 'className'>) {
61+
const [tabListState, setTabListState] = useState<TabListState<any>>();
62+
63+
return (
64+
<TabsContext.Provider
65+
value={{
66+
rootProps: {...props, orientation: 'horizontal'},
67+
tabListState,
68+
setTabListState,
69+
}}
70+
>
71+
{children}
72+
</TabsContext.Provider>
73+
);
74+
}
75+
5776
/**
5877
* Root tabs component. Provides the necessary data (via React context) for
5978
* child components (TabList and TabPanels) to work together. See example
@@ -65,16 +84,12 @@ export function Tabs<T extends string | number>({
6584
children,
6685
...props
6786
}: TabsProps<T>) {
68-
const [tabListState, setTabListState] = useState<TabListState<any>>();
69-
7087
return (
71-
<TabsContext.Provider
72-
value={{rootProps: {...props, orientation}, tabListState, setTabListState}}
73-
>
88+
<TabStateProvider orientation={orientation} {...props}>
7489
<TabsWrap orientation={orientation} className={className}>
7590
{children}
7691
</TabsWrap>
77-
</TabsContext.Provider>
92+
</TabStateProvider>
7893
);
7994
}
8095

0 commit comments

Comments
 (0)