Skip to content

Commit

Permalink
Add Toolpad Core Vite example
Browse files Browse the repository at this point in the history
  • Loading branch information
apedroferreira committed Oct 9, 2024
1 parent 1070431 commit db3b554
Show file tree
Hide file tree
Showing 21 changed files with 441 additions and 8 deletions.
6 changes: 5 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,11 @@ You can also test the example apps to make sure they work as expected.
pnpm --filter @toolpad/core dev
```

3. Run the example app
3. Install then run the example app

```bash
pnpm --filter core-nextjs install
```

```bash
pnpm --filter core-nextjs dev
Expand Down
2 changes: 1 addition & 1 deletion examples/core-auth-nextjs-pages-nextauth-4/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Toolpad Core Playground - Next.js Pages Router with Next Auth 4
# Toolpad Core - Next.js Pages Router with Next Auth 4

This is a [Next.js](https://nextjs.org/) project bootstrapped with [`create-next-app`](https://github.com/vercel/next.js/tree/canary/packages/create-next-app).

Expand Down
2 changes: 1 addition & 1 deletion examples/core-auth-nextjs-pages/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Toolpad Core Playground - Next.js Pages Router
# Toolpad Core - Next.js Pages Router

This is a [Next.js](https://nextjs.org/) project bootstrapped with [`create-next-app`](https://github.com/vercel/next.js/tree/canary/packages/create-next-app).

Expand Down
2 changes: 1 addition & 1 deletion examples/core-auth-nextjs/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Toolpad Core Playground - Next.js App Router
# Toolpad Core - Next.js App Router

This is a [Next.js](https://nextjs.org/) project bootstrapped with [`create-next-app`](https://github.com/vercel/next.js/tree/canary/packages/create-next-app).

Expand Down
24 changes: 24 additions & 0 deletions examples/core-vite/.gitignore
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?
23 changes: 23 additions & 0 deletions examples/core-vite/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Toolpad Core - Vite & React Router

This example provides a minimal setup to get Toolpad Core working in Vite with HMR and some ESLint rules, as well as routing with React Router.

## Getting Started

First, run the development server:

```bash
npm run dev
# or
yarn dev
# or
pnpm dev
# or
bun dev
```

Open [http://localhost:5173](http://localhost:5173) with your browser to see the result.

## The source

[Check out the source code](https://github.com/mui/toolpad/tree/master/examples/core-vite)
28 changes: 28 additions & 0 deletions examples/core-vite/eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import js from '@eslint/js'
import globals from 'globals'
import reactHooks from 'eslint-plugin-react-hooks'
import reactRefresh from 'eslint-plugin-react-refresh'
import tseslint from 'typescript-eslint'

export default tseslint.config(
{ ignores: ['dist'] },
{
extends: [js.configs.recommended, ...tseslint.configs.recommended],
files: ['**/*.{ts,tsx}'],
languageOptions: {
ecmaVersion: 2020,
globals: globals.browser,
},
plugins: {
'react-hooks': reactHooks,
'react-refresh': reactRefresh,
},
rules: {
...reactHooks.configs.recommended.rules,
'react-refresh/only-export-components': [
'warn',
{ allowConstantExport: true },
],
},
},
)
20 changes: 20 additions & 0 deletions examples/core-vite/index.html
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</title>
</head>
<body>
<div id="root"></div>
<script type="module" src="/src/main.tsx"></script>
</body>
</html>
34 changes: 34 additions & 0 deletions examples/core-vite/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
"name": "core-vite",
"version": "0.1.0",
"type": "module",
"scripts": {
"dev": "vite",
"build": "tsc -b && vite build",
"lint": "eslint .",
"preview": "vite preview"
},
"dependencies": {
"@emotion/react": "^11",
"@emotion/styled": "^11",
"@mui/icons-material": "^6",
"@mui/material": "^6",
"@toolpad/core": "latest",
"react": "^18",
"react-dom": "^18",
"react-router-dom": "^6"
},
"devDependencies": {
"@eslint/js": "^9.11.1",
"@types/react": "^18",
"@types/react-dom": "^18",
"@vitejs/plugin-react": "^4.3.2",
"eslint": "^9",
"eslint-plugin-react-hooks": "^5.1.0-rc.0",
"eslint-plugin-react-refresh": "^0.4.12",
"globals": "^15.9.0",
"typescript": "^5",
"typescript-eslint": "^8.7.0",
"vite": "^5.4.8"
}
}
1 change: 1 addition & 0 deletions examples/core-vite/public/vite.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
33 changes: 33 additions & 0 deletions examples/core-vite/src/App.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import DashboardIcon from '@mui/icons-material/Dashboard';
import ShoppingCartIcon from '@mui/icons-material/ShoppingCart';
import { Outlet } from 'react-router-dom';
import { AppProvider } from '@toolpad/core/react-router-dom';
import type { Navigation } from '@toolpad/core';

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() {
return (
<AppProvider navigation={NAVIGATION} branding={BRANDING}>
<Outlet />
</AppProvider>
);
}
Empty file.
11 changes: 11 additions & 0 deletions examples/core-vite/src/layouts/dashboard.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import * as React from 'react';
import { DashboardLayout } from '@toolpad/core/DashboardLayout';
import { PageContainer } from '@toolpad/core/PageContainer';

export default function Layout(props: { children: React.ReactNode }) {
return (
<DashboardLayout>
<PageContainer>{props.children}</PageContainer>
</DashboardLayout>
);
}
28 changes: 28 additions & 0 deletions examples/core-vite/src/main.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import * as React from 'react';
import * as ReactDOM from 'react-dom/client';
import { createBrowserRouter, RouterProvider } from 'react-router-dom';
import App from './App';
import DashboardPage from './pages';
import OrdersPage from './pages/orders';

const router = createBrowserRouter([
{
Component: App,
children: [
{
path: '/',
Component: DashboardPage,
},
{
path: '/orders',
Component: OrdersPage,
},
],
},
]);

ReactDOM.createRoot(document.getElementById('root')!).render(
<React.StrictMode>
<RouterProvider router={router} />
</React.StrictMode>,
);
11 changes: 11 additions & 0 deletions examples/core-vite/src/pages/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import * as React from 'react';
import Typography from '@mui/material/Typography';
import Layout from '../layouts/dashboard';

export default function DashboardPage() {
return (
<Layout>
<Typography>Welcome to Toolpad!</Typography>
</Layout>
);
}
11 changes: 11 additions & 0 deletions examples/core-vite/src/pages/orders.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import * as React from 'react';
import Typography from '@mui/material/Typography';
import Layout from '../layouts/dashboard';

export default function OrdersPage() {
return (
<Layout>
<Typography>Welcome to the Toolpad orders!</Typography>
</Layout>
);
}
1 change: 1 addition & 0 deletions examples/core-vite/src/vite-env.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/// <reference types="vite/client" />
21 changes: 21 additions & 0 deletions examples/core-vite/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"compilerOptions": {
"target": "ESNext",
"useDefineForClassFields": true,
"lib": ["DOM", "DOM.Iterable", "ESNext"],
"allowJs": false,
"skipLibCheck": true,
"esModuleInterop": false,
"allowSyntheticDefaultImports": true,
"strict": true,
"forceConsistentCasingInFileNames": true,
"module": "ESNext",
"moduleResolution": "Node",
"resolveJsonModule": true,
"isolatedModules": true,
"noEmit": true,
"jsx": "react-jsx"
},
"include": ["src"],
"references": [{ "path": "./tsconfig.node.json" }]
}
9 changes: 9 additions & 0 deletions examples/core-vite/tsconfig.node.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"compilerOptions": {
"composite": true,
"module": "ESNext",
"moduleResolution": "Node",
"allowSyntheticDefaultImports": true
},
"include": ["vite.config.ts"]
}
7 changes: 7 additions & 0 deletions examples/core-vite/vite.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'

// https://vitejs.dev/config/
export default defineConfig({
plugins: [react()],
})
Loading

0 comments on commit db3b554

Please sign in to comment.