-
-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8351 from marmelab/tutorial-vite
[Doc] Update the tutorial to use Vite instead of create-react-app
- Loading branch information
Showing
26 changed files
with
653 additions
and
684 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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,13 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8" /> | ||
<link rel="icon" href="/favicon.ico" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
<title>Vite + React + TS</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 |
---|---|---|
@@ -1,25 +1,24 @@ | ||
{ | ||
"name": "tutorial", | ||
"version": "4.0.0", | ||
"private": true, | ||
"dependencies": { | ||
"@mui/icons-material": "^5.0.1", | ||
"@mui/material": "^5.0.2", | ||
"ra-data-json-server": "^4.0.0", | ||
"react": "^17.0.0", | ||
"react-admin": "^4.0.0", | ||
"react-dom": "^17.0.0", | ||
"react-scripts": "^5.0.0" | ||
}, | ||
"scripts": { | ||
"start": "react-scripts start", | ||
"build": "react-scripts build", | ||
"eject": "react-scripts eject" | ||
}, | ||
"browserslist": [ | ||
">0.2%", | ||
"not dead", | ||
"not ie <= 11", | ||
"not op_mini all" | ||
] | ||
"name": "tutorial", | ||
"version": "4.0.0", | ||
"private": true, | ||
"type": "module", | ||
"scripts": { | ||
"dev": "vite", | ||
"build": "tsc && vite build", | ||
"preview": "vite preview" | ||
}, | ||
"dependencies": { | ||
"ra-data-json-server": "^4.5.0", | ||
"react": "^18.2.0", | ||
"react-admin": "^4.5.0", | ||
"react-dom": "^18.2.0" | ||
}, | ||
"devDependencies": { | ||
"@types/react": "^18.0.22", | ||
"@types/react-dom": "^18.0.7", | ||
"@vitejs/plugin-react": "^2.2.0", | ||
"typescript": "^4.6.4", | ||
"vite": "^3.2.0" | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,41 @@ | ||
#root { | ||
max-width: 1280px; | ||
margin: 0 auto; | ||
padding: 2rem; | ||
text-align: center; | ||
} | ||
|
||
.logo { | ||
height: 6em; | ||
padding: 1.5em; | ||
will-change: filter; | ||
} | ||
.logo:hover { | ||
filter: drop-shadow(0 0 2em #646cffaa); | ||
} | ||
.logo.react:hover { | ||
filter: drop-shadow(0 0 2em #61dafbaa); | ||
} | ||
|
||
@keyframes logo-spin { | ||
from { | ||
transform: rotate(0deg); | ||
} | ||
to { | ||
transform: rotate(360deg); | ||
} | ||
} | ||
|
||
@media (prefers-reduced-motion: no-preference) { | ||
a:nth-of-type(2) .logo { | ||
animation: logo-spin infinite 20s linear; | ||
} | ||
} | ||
|
||
.card { | ||
padding: 2em; | ||
} | ||
|
||
.read-the-docs { | ||
color: #888; | ||
} |
29 changes: 16 additions & 13 deletions
29
examples/tutorial/src/App.js → examples/tutorial/src/App.tsx
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 |
---|---|---|
@@ -1,32 +1,35 @@ | ||
import * as React from 'react'; | ||
import { Admin, Resource } from 'react-admin'; | ||
import jsonServerProvider from 'ra-data-json-server'; | ||
import PostIcon from '@mui/icons-material/Book'; | ||
import UserIcon from '@mui/icons-material/Group'; | ||
import { Admin, Resource, ListGuesser } from 'react-admin'; | ||
import jsonServerProvider from 'ra-data-json-server'; | ||
|
||
import { PostList, PostEdit, PostCreate, PostShow } from './posts'; | ||
import { PostList, PostEdit, PostCreate } from './posts'; | ||
import { UserList } from './users'; | ||
import Dashboard from './Dashboard'; | ||
import authProvider from './authProvider'; | ||
import { Dashboard } from './Dashboard'; | ||
import { authProvider } from './authProvider'; | ||
|
||
const dataProvider = jsonServerProvider('https://jsonplaceholder.typicode.com'); | ||
|
||
const App = () => ( | ||
<Admin | ||
dataProvider={jsonServerProvider( | ||
'https://jsonplaceholder.typicode.com' | ||
)} | ||
authProvider={authProvider} | ||
dataProvider={dataProvider} | ||
dashboard={Dashboard} | ||
> | ||
<Resource | ||
name="posts" | ||
icon={PostIcon} | ||
list={PostList} | ||
edit={PostEdit} | ||
create={PostCreate} | ||
show={PostShow} | ||
icon={PostIcon} | ||
/> | ||
<Resource | ||
name="users" | ||
list={UserList} | ||
icon={UserIcon} | ||
recordRepresentation="name" | ||
/> | ||
<Resource name="users" icon={UserIcon} list={UserList} /> | ||
<Resource name="comments" list={ListGuesser} /> | ||
</Admin> | ||
); | ||
|
||
export default App; |
This file was deleted.
Oops, something went wrong.
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 @@ | ||
import { Card, CardContent, CardHeader } from '@mui/material'; | ||
|
||
export const Dashboard = () => ( | ||
<Card> | ||
<CardHeader title="Welcome to the administration" /> | ||
<CardContent>Lorem ipsum sic dolor amet...</CardContent> | ||
</Card> | ||
); |
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,15 @@ | ||
import { useRecordContext } from 'react-admin'; | ||
import { Link } from '@mui/material'; | ||
import LaunchIcon from '@mui/icons-material/Launch'; | ||
|
||
const MyUrlField = ({ source }: { source: string }) => { | ||
const record = useRecordContext(); | ||
return record ? ( | ||
<Link href={record[source]} sx={{ textDecoration: 'none' }}> | ||
{record[source]} | ||
<LaunchIcon sx={{ fontSize: 15, ml: 1 }} /> | ||
</Link> | ||
) : null; | ||
}; | ||
|
||
export default MyUrlField; |
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
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,9 @@ | ||
import React from 'react'; | ||
import ReactDOM from 'react-dom/client'; | ||
import App from './App'; | ||
|
||
ReactDOM.createRoot(document.getElementById('root') as HTMLElement).render( | ||
<React.StrictMode> | ||
<App /> | ||
</React.StrictMode> | ||
); |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.