Skip to content

Commit

Permalink
fix(LayoutProvider): layoutProvider merged with ThemeProvider
Browse files Browse the repository at this point in the history
  • Loading branch information
IsaevAlexandr committed Apr 19, 2024
1 parent bf3bed8 commit 80c8cda
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 58 deletions.
22 changes: 13 additions & 9 deletions src/components/layout/LayoutProvider/LayoutProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {useCurrentActiveMediaQuery} from '../hooks/useCurrentActiveMediaQuery';
import type {LayoutTheme, MediaType, RecursivePartial} from '../types';
import {makeLayoutDefaultTheme} from '../utils/makeLayoutDefaultTheme';

interface LayoutProviderProps {
export interface LayoutProviderProps {
theme?: RecursivePartial<LayoutTheme>;
/**
* During ssr you can override default (`s`) media screen size if needed
Expand All @@ -15,14 +15,7 @@ interface LayoutProviderProps {
children: React.ReactNode;
}

/**
* @deprecated - pass theme directly to `ThemeProvider`
*
* Provide context for layout components and current media queries.
* ---
* Storybook - https://preview.gravity-ui.com/uikit/?path=/docs/layout--playground#layoutprovider-and-layouttheme
*/
export function LayoutProvider({
export function PrivateLayoutProvider({
children,
theme: override,
initialMediaQuery,
Expand All @@ -41,3 +34,14 @@ export function LayoutProvider({
</LayoutContext.Provider>
);
}

/**
* @deprecated - already used as part of ThemeProvider. To override layout theme use `layout` prop
*
* Provide context for layout components and current media queries.
* ---
* Storybook - https://preview.gravity-ui.com/uikit/?path=/docs/layout--playground#layoutprovider-and-layouttheme
*/
export function LayoutProvider({children}: LayoutProviderProps) {
return children;
}
2 changes: 1 addition & 1 deletion src/components/layout/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export * from './Row/Row';
export * from './Flex/Flex';
export * from './Box/Box';
export * from './Container/Container';
export * from './LayoutProvider/LayoutProvider';
export {LayoutProvider} from './LayoutProvider/LayoutProvider';
export * from './spacing/spacing';

export * from './hooks/useLayoutContext';
Expand Down
79 changes: 31 additions & 48 deletions src/components/theme/ThemeProvider.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import React from 'react';

import {LayoutProvider} from '../layout';
import type {LayoutTheme} from '../layout';
import type {MediaType, RecursivePartial} from '../layout/types';
import {PrivateLayoutProvider} from '../layout/LayoutProvider/LayoutProvider';
import type {LayoutProviderProps} from '../layout/LayoutProvider/LayoutProvider';
import {block} from '../utils/cn';

import {ThemeContext} from './ThemeContext';
Expand All @@ -29,14 +28,7 @@ export interface ThemeProviderProps extends React.PropsWithChildren<{}> {
nativeScrollbar?: boolean;
scoped?: boolean;
rootClassName?: string;
/**
* Pass theme to override default breakpoint or spacing
*/
layoutTheme?: RecursivePartial<LayoutTheme>;
/**
* During ssr you can override default (`s`) media screen size if needed
*/
initialMediaQuery?: MediaType;
layout?: Omit<LayoutProviderProps, 'children'>;
}

export function ThemeProvider({
Expand All @@ -48,8 +40,7 @@ export function ThemeProvider({
scoped: scopedProp = false,
rootClassName = '',
children,
layoutTheme,
initialMediaQuery,
layout,
}: ThemeProviderProps) {
const parentThemeState = React.useContext(ThemeContext);
const systemThemeState = React.useContext(ThemeSettingsContext);
Expand Down Expand Up @@ -98,42 +89,34 @@ export function ThemeProvider({
[systemLightTheme, systemDarkTheme],
);

let node = (
<ThemeContext.Provider value={contextValue}>
<ThemeSettingsContext.Provider value={themeSettingsContext}>
{scoped ? (
<div
className={b(
{
theme: themeValue,
'native-scrollbar': nativeScrollbar !== false,
},
rootClassName,
)}
dir={
hasParentProvider && direction === parentDirection
? undefined
: direction
}
>
{children}
</div>
) : (
children
)}
</ThemeSettingsContext.Provider>
</ThemeContext.Provider>
return (
<PrivateLayoutProvider {...layout}>
<ThemeContext.Provider value={contextValue}>
<ThemeSettingsContext.Provider value={themeSettingsContext}>
{scoped ? (
<div
className={b(
{
theme: themeValue,
'native-scrollbar': nativeScrollbar !== false,
},
rootClassName,
)}
dir={
hasParentProvider && direction === parentDirection
? undefined
: direction
}
>
{children}
</div>
) : (
children
)}
</ThemeSettingsContext.Provider>
</ThemeContext.Provider>
</PrivateLayoutProvider>
);

if (layoutTheme || initialMediaQuery) {
node = (
<LayoutProvider theme={layoutTheme} initialMediaQuery={initialMediaQuery}>
{node}
</LayoutProvider>
);
}

return node;
}

ThemeProvider.displayName = 'ThemeProvider';

0 comments on commit 80c8cda

Please sign in to comment.