-
-
Notifications
You must be signed in to change notification settings - Fork 311
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[docs] Add
SignInPage
Vite + React Router example (#4335)
- Loading branch information
1 parent
3bb2a53
commit 90eaa01
Showing
20 changed files
with
540 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# Logs | ||
logs | ||
*.log | ||
npm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.log* | ||
pnpm-debug.log* | ||
lerna-debug.log* | ||
|
||
node_modules | ||
dist | ||
dist-ssr | ||
*.local | ||
|
||
# Editor directories and files | ||
.vscode/* | ||
!.vscode/extensions.json | ||
.idea | ||
.DS_Store | ||
*.suo | ||
*.ntvs* | ||
*.njsproj | ||
*.sln | ||
*.sw? |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# React + TypeScript + Vite | ||
|
||
This template provides a minimal setup to get React working in Vite with HMR. | ||
|
||
Currently, two official plugins are available: | ||
|
||
- [@vitejs/plugin-react](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react/README.md) uses [Babel](https://babeljs.io/) for Fast Refresh | ||
- [@vitejs/plugin-react-swc](https://github.com/vitejs/vite-plugin-react-swc) uses [SWC](https://swc.rs/) for Fast Refresh |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<!doctype html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="utf-8" /> | ||
<link rel="icon" type="image/svg+xml" href="/vite.svg" /> | ||
<meta name="viewport" content="initial-scale=1, width=device-width" /> | ||
<!-- Fonts to support Material Design --> | ||
<link rel="preconnect" href="https://fonts.googleapis.com" /> | ||
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin /> | ||
<link | ||
rel="stylesheet" | ||
href="https://fonts.googleapis.com/css2?family=Roboto:wght@300;400;500;700&display=swap" | ||
/> | ||
<title>Toolpad Core Vite with Auth</title> | ||
</head> | ||
<body> | ||
<div id="root"></div> | ||
<script type="module" src="/src/main.tsx"></script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
{ | ||
"name": "core-vite-auth", | ||
"version": "0.1.0", | ||
"type": "module", | ||
"scripts": { | ||
"dev": "vite", | ||
"build": "tsc -b && vite build", | ||
"preview": "vite preview" | ||
}, | ||
"dependencies": { | ||
"@emotion/react": "^11", | ||
"@emotion/styled": "^11", | ||
"@mui/icons-material": "^6", | ||
"@mui/material": "^6", | ||
"@toolpad/core": "workspace:*", | ||
"react": "^18", | ||
"react-dom": "^18", | ||
"react-router-dom": "^6" | ||
}, | ||
"devDependencies": { | ||
"@types/react": "^18", | ||
"@types/react-dom": "^18", | ||
"@vitejs/plugin-react": "^4.3.2", | ||
"typescript": "^5", | ||
"vite": "^5.4.8" | ||
} | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import * as React from 'react'; | ||
import DashboardIcon from '@mui/icons-material/Dashboard'; | ||
import ShoppingCartIcon from '@mui/icons-material/ShoppingCart'; | ||
import { AppProvider } from '@toolpad/core/react-router-dom'; | ||
import { Outlet, useNavigate } from 'react-router-dom'; | ||
import type { Navigation, Session } from '@toolpad/core'; | ||
import { SessionContext } from './SessionContext'; | ||
|
||
const NAVIGATION: Navigation = [ | ||
{ | ||
kind: 'header', | ||
title: 'Main items', | ||
}, | ||
{ | ||
title: 'Dashboard', | ||
icon: <DashboardIcon />, | ||
}, | ||
{ | ||
segment: 'orders', | ||
title: 'Orders', | ||
icon: <ShoppingCartIcon />, | ||
}, | ||
]; | ||
|
||
const BRANDING = { | ||
title: 'My Toolpad Core App', | ||
}; | ||
|
||
export default function App() { | ||
const [session, setSession] = React.useState<Session | null>(null); | ||
const navigate = useNavigate(); | ||
|
||
const signIn = React.useCallback(() => { | ||
navigate('/sign-in'); | ||
}, [navigate]); | ||
|
||
const signOut = React.useCallback(() => { | ||
setSession(null); | ||
navigate('/sign-in'); | ||
}, [navigate]); | ||
|
||
const sessionContextValue = React.useMemo(() => ({ session, setSession }), [session, setSession]); | ||
|
||
return ( | ||
<SessionContext.Provider value={sessionContextValue}> | ||
<AppProvider | ||
navigation={NAVIGATION} | ||
branding={BRANDING} | ||
session={session} | ||
authentication={{ signIn, signOut }} | ||
> | ||
<Outlet /> | ||
</AppProvider> | ||
</SessionContext.Provider> | ||
); | ||
} |
Oops, something went wrong.