Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Doc] Fix add Roboto font integration step to vite tutorial #8419

Merged
merged 7 commits into from
Nov 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 25 additions & 3 deletions docs/Tutorial.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,11 @@ const App = () => <Admin dataProvider={dataProvider} />;
export default App;
```

Also, change the default Vite CSS file to look like this:
That's enough for react-admin to render an empty app and confirm that the setup is done:

[![Empty Admin](./img/tutorial_empty.png)](./img/tutorial_empty.png)

Also, you should change the default Vite CSS file to look like this:

```diff
// in src/index.css
Expand All @@ -89,9 +93,27 @@ body {
}
```

That's enough for react-admin to render an empty app and confirm that the setup is done:
Lastly, add the `Roboto` font to the `index.html` file:
WiXSL marked this conversation as resolved.
Show resolved Hide resolved

[![Empty Admin](./img/tutorial_empty.png)](./img/tutorial_empty.png)
```diff
// in ./index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>React Admin</title>
+ <link
+ rel="stylesheet"
+ href="https://fonts.googleapis.com/css?family=Roboto:300,400,500,700&display=swap"
+ />
</head>
<body>
<div id="root"></div>
<script type="module" src="/src/index.tsx"></script>
</body>
</html>
```

The `<App>` component renders an `<Admin>` component, which is the root component of a react-admin application. This component expects a `dataProvider` prop - a function capable of fetching data from an API. Since there is no standard for data exchanges between computers, you will probably have to write a custom provider to connect react-admin to your own APIs - but we'll dive into Data Providers later. For now, let's take advantage of the `ra-data-json-server` data provider, which speaks the same REST dialect as JSONPlaceholder.

Expand Down
38 changes: 27 additions & 11 deletions docs/Vite.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,19 +61,35 @@ const App = () => <MyAdmin />;
export default App;
```

Finally, remove the `index.css` from the `main.tsx` folder:
Then, change the `index.css` file to look like this:

```diff
import React from 'react';
import ReactDOM from 'react-dom/client';
import App from './App';
-import './index.css';

ReactDOM.createRoot(document.getElementById('root')).render(
<React.StrictMode>
<App />
</React.StrictMode>
);
// in src/index.css
body {
margin: 0;
}
```

Finally, add the `Roboto` font to your `index.html` file:

```diff
// in ./index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>React Admin</title>
+ <link
+ rel="stylesheet"
+ href="https://fonts.googleapis.com/css?family=Roboto:300,400,500,700&display=swap"
+ />
</head>
<body>
<div id="root"></div>
<script type="module" src="/src/index.tsx"></script>
</body>
</html>
```

Now, start the server with `yarn dev`, browse to `http://localhost:5173/`, and you should see the working admin:
Expand Down
4 changes: 4 additions & 0 deletions examples/tutorial/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
<link rel="icon" href="/favicon.ico" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Vite + React + TS</title>
<link
rel="stylesheet"
href="https://fonts.googleapis.com/css?family=Roboto:300,400,500,700&display=swap"
/>
</head>
<body>
<div id="root"></div>
Expand Down
41 changes: 0 additions & 41 deletions examples/tutorial/src/App.css

This file was deleted.

3 changes: 3 additions & 0 deletions examples/tutorial/src/index.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
body {
margin: 0;
}
1 change: 1 addition & 0 deletions examples/tutorial/src/main.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React from 'react';
import ReactDOM from 'react-dom/client';
import App from './App';
import './index.css';

ReactDOM.createRoot(document.getElementById('root') as HTMLElement).render(
<React.StrictMode>
Expand Down