Skip to content
This repository has been archived by the owner on Apr 14, 2024. It is now read-only.

Commit

Permalink
feat: добавление layout page (#23)
Browse files Browse the repository at this point in the history
  • Loading branch information
DieWerkself authored Oct 9, 2023
1 parent f7d5588 commit bf27d77
Show file tree
Hide file tree
Showing 8 changed files with 65 additions and 5 deletions.
25 changes: 21 additions & 4 deletions src/app/providers/router/config.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,29 @@ import { BlankPage } from '~/pages/BlankPage';
import { NotFound } from '~/pages/NotFound';
import { ProfilePage } from '~/pages/ProfilePage';

const appClosed = [{ path: '*', element: <BlankPage /> }];
const appClosed = [
{
path: '*',
view: {
base: <BlankPage />,
},
},
];

const normalRoutes = [
{ path: '404', element: <NotFound /> },
{ path: '*', element: <Navigate to={'404'} replace /> },
{ path: '/profile', element: <ProfilePage /> },
{
path: '404',
view: {
base: <NotFound />,
},
},
{ path: '/profile', view: { base: <ProfilePage /> } },
{
path: '*',
view: {
base: <Navigate to={'404'} replace />,
},
},
];

export const routes = import.meta.env.VITE_CLOSED ? appClosed : normalRoutes;
8 changes: 7 additions & 1 deletion src/app/providers/router/router.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { Suspense } from 'react';
import { Route, Routes, BrowserRouter } from 'react-router-dom';

import { Layout } from '~/pages/Layout';

import { Loader } from '~/shared/ui/Loader';

import { routes } from './config';
Expand All @@ -11,7 +13,11 @@ const Routing = () => {
<Suspense fallback={<Loader />}>
<Routes>
{routes.map((props) => (
<Route {...props} key={props.path} />
<Route
key={props.path}
path={props.path}
element={<Layout {...props.view} />}
/>
))}
</Routes>
</Suspense>
Expand Down
21 changes: 21 additions & 0 deletions src/pages/Layout/Layout.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { ChakraProvider, useBreakpointValue } from '@chakra-ui/react';

import { desktopTheme, mobileTheme } from '~/shared/config/theme';

interface LayoutProps {
base: JSX.Element;
desktop?: JSX.Element;
}

export const Layout = ({ base, desktop }: LayoutProps) => {
const breakpoint = useBreakpointValue({ base: 'base', md: 'desktop' }, { ssr: false });

const isBase = breakpoint === 'base' || !desktop;

return (
<ChakraProvider theme={isBase ? mobileTheme : desktopTheme}>
{isBase ? base : desktop}
{isBase ? <div>Mobile Menu</div> : <div>Desktop Menu</div>}
</ChakraProvider>
);
};
1 change: 1 addition & 0 deletions src/pages/Layout/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './Layout';
5 changes: 5 additions & 0 deletions src/shared/config/theme/desktopTheme.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { extendTheme } from '@chakra-ui/react';

import { basicTheme } from './theme';

export const desktopTheme = extendTheme(basicTheme);
2 changes: 2 additions & 0 deletions src/shared/config/theme/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
export { basicTheme } from './theme';
export { mobileTheme } from './mobileTheme';
export { desktopTheme } from './desktopTheme';
5 changes: 5 additions & 0 deletions src/shared/config/theme/mobileTheme.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { extendTheme } from '@chakra-ui/react';

import { basicTheme } from './theme';

export const mobileTheme = extendTheme(basicTheme);
3 changes: 3 additions & 0 deletions src/shared/config/theme/theme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,4 +111,7 @@ export const basicTheme = extendTheme({
900: '#111111',
},
},
breakpoints: {
md: '37.5rem',
},
});

0 comments on commit bf27d77

Please sign in to comment.