Skip to content

Commit

Permalink
Merge pull request #542 from daileytj/feature/convert-example-project…
Browse files Browse the repository at this point in the history
…-to-vite

Add vite example project
  • Loading branch information
JeffGreiner-eaton authored Feb 1, 2024
2 parents ef264aa + 1e03308 commit fe78039
Show file tree
Hide file tree
Showing 46 changed files with 13,052 additions and 1 deletion.
18 changes: 18 additions & 0 deletions login-workflow/example-vite/.eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
module.exports = {
root: true,
env: { browser: true, es2020: true },
extends: [
'eslint:recommended',
'plugin:@typescript-eslint/recommended',
'plugin:react-hooks/recommended',
],
ignorePatterns: ['dist', '.eslintrc.cjs'],
parser: '@typescript-eslint/parser',
plugins: ['react-refresh'],
rules: {
'react-refresh/only-export-components': [
'warn',
{ allowConstantExport: true },
],
},
}
24 changes: 24 additions & 0 deletions login-workflow/example-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?
30 changes: 30 additions & 0 deletions login-workflow/example-vite/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# React + TypeScript + Vite

This template provides a minimal setup to get React working in Vite with HMR and some ESLint rules.

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

## Expanding the ESLint configuration

If you are developing a production application, we recommend updating the configuration to enable type aware lint rules:

- Configure the top-level `parserOptions` property like this:

```js
export default {
// other rules...
parserOptions: {
ecmaVersion: 'latest',
sourceType: 'module',
project: ['./tsconfig.json', './tsconfig.node.json'],
tsconfigRootDir: __dirname,
},
}
```

- Replace `plugin:@typescript-eslint/recommended` to `plugin:@typescript-eslint/recommended-type-checked` or `plugin:@typescript-eslint/strict-type-checked`
- Optionally add `plugin:@typescript-eslint/stylistic-type-checked`
- Install [eslint-plugin-react](https://github.com/jsx-eslint/eslint-plugin-react) and add `plugin:react/recommended` & `plugin:react/jsx-runtime` to the `extends` list
13 changes: 13 additions & 0 deletions login-workflow/example-vite/index.html
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" type="image/svg+xml" href="/vite.svg" />
<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>
81 changes: 81 additions & 0 deletions login-workflow/example-vite/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
{
"name": "vite-example",
"private": true,
"version": "0.0.0",
"type": "module",
"scripts": {
"start": "vite",
"dev": "vite",
"build": "vite build",
"lint": "eslint \"src/**/**.{ts,tsx}\"",
"lint:fix": "eslint \"src/**/**.{ts,tsx}\" --fix",
"prettier": "prettier \"src/**/**.{ts,tsx,js,jsx,json,css,scss,html}\" --write",
"prettier:check": "prettier \"src/**/**.{ts,tsx,js,jsx,json,css,scss,html}\" --check",
"preview": "vite preview"
},
"dependencies": {
"@brightlayer-ui/colors": "^3.0.1",
"@brightlayer-ui/icons-mui": "^3.3.0",
"@brightlayer-ui/react-auth-workflow": "^4.0.2",
"@brightlayer-ui/react-components": "^6.1.2",
"@brightlayer-ui/react-themes": "^7.1.0",
"@emotion/react": "^11.7.1",
"@emotion/styled": "^11.10.8",
"@mui/icons-material": "^5.11.11",
"@mui/material": "^5.10.15",
"date-fns": "^3.0.6",
"i18next": "^23.7.13",
"i18next-browser-languagedetector": "^7.2.0",
"react": "^18.2.0",
"react-app-polyfill": "^3.0.0",
"react-dom": "^18.2.0",
"react-i18next": "^13.0.3",
"react-router-dom": "^6.8.0",
"react-scripts": "^5.0.0",
"typescript": "^5.3.3"
},
"devDependencies": {
"@brightlayer-ui/eslint-config": "^3.0.1",
"@brightlayer-ui/prettier-config": "^1.0.3",
"@emotion/css": "^11.11.2",
"@testing-library/jest-dom": "^6.4.0",
"@testing-library/react": "^14.1.2",
"@testing-library/user-event": "^14.5.2",
"@types/jest": "^29.5.11",
"@types/react": "^18.2.43",
"@types/react-dom": "^18.2.17",
"@typescript-eslint/eslint-plugin": "^6.14.0",
"@typescript-eslint/parser": "^6.14.0",
"@vitejs/plugin-react": "^4.2.1",
"babel-plugin-istanbul": "^6.1.1",
"eslint": "^8.56.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-react": "^7.33.2",
"eslint-plugin-react-hooks": "^4.6.0",
"eslint-plugin-react-refresh": "^0.4.5",
"jest": "^29.7.0",
"prettier": "^3.2.4",
"vite": "^5.0.12",
"yarn-audit-fix": "^10.0.7"
},
"prettier": "@brightlayer-ui/prettier-config",
"eslintConfig": {
"extends": "react-app"
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all",
"IE 11",
"not IE 9-10"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version",
"ie 11",
"not ie 9-10"
]
}
}
1 change: 1 addition & 0 deletions login-workflow/example-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.
42 changes: 42 additions & 0 deletions login-workflow/example-vite/src/App.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#root {
max-width: 1280px;
margin: 0 auto;
padding: 2rem;
text-align: center;
}

.logo {
height: 6em;
padding: 1.5em;
will-change: filter;
transition: filter 300ms;
}
.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;
}
90 changes: 90 additions & 0 deletions login-workflow/example-vite/src/App.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
import React, { useState, useEffect } from 'react';
import { AppContext, AppContextType } from './contexts/AppContextProvider';
import { BrowserRouter } from 'react-router-dom';
import { AppRouter } from './navigation/AppRouter';
import { I18nextProvider } from 'react-i18next';
import i18nAppInstance from './translations/i18n';
import { LocalStorage } from './store/local-storage';
import { Box, CircularProgress, SxProps, Theme } from '@mui/material';

const containerStyles: SxProps<Theme> = {
width: '100%',
height: (t) => ({ xs: `calc(100vh - ${t.spacing(7)})`, md: `calc(100vh - ${t.spacing(8)})` }),
display: 'flex',
padding: 0,
overflow: 'auto',
position: 'relative',
flexDirection: 'column',
alignItems: 'center',
justifyContent: 'center',
};

const emptyStateContainerStyles = {
margin: 'auto',
display: 'flex',
zIndex: 4,
position: 'absolute',
alignItems: 'center',
justifyContent: 'center',
};

export const App = (): JSX.Element => {
const [isAuthenticated, setIsAuthenticated] = useState(false);
const [language, setLanguage] = useState(window.localStorage.getItem('app-i18nextLng')?.toString() ?? 'en');
const [loginData, setLoginData] = useState<AppContextType['loginData']>({
email: '',
rememberMe: false,
});
const [showChangePasswordDialog, setShowChangePasswordDialog] = useState(false);

const [isLoading, setIsLoading] = useState(true);

// handle initialization of auth data on first load
useEffect(() => {
const initialize = async (): Promise<void> => {
try {
const userData = await LocalStorage.readAuthData();
setLoginData({ email: userData.rememberMeData.user, rememberMe: userData.rememberMeData.rememberMe });
setIsAuthenticated(Boolean(userData.userId));
} catch (e) {
// handle any error state, rejected promises, etc..
} finally {
setIsLoading(false);
}
};
// eslint-disable-next-line
initialize();
}, []);

return isLoading ? (
<Box sx={containerStyles}>
<CircularProgress sx={emptyStateContainerStyles} size={70} variant={'indeterminate'} />
</Box>
) : (
<I18nextProvider i18n={i18nAppInstance} defaultNS={'app'}>
<AppContext.Provider
value={{
isAuthenticated,
onUserAuthenticated: (userData): void => {
setIsAuthenticated(true);
setLoginData(userData);
},
// eslint-disable-next-line
onUserNotAuthenticated: (userData): void => {
setIsAuthenticated(false);
},
loginData,
setLoginData,
language,
setLanguage,
showChangePasswordDialog,
setShowChangePasswordDialog,
}}
>
<BrowserRouter basename={'/'}>
<AppRouter />
</BrowserRouter>
</AppContext.Provider>
</I18nextProvider>
);
};
Loading

0 comments on commit fe78039

Please sign in to comment.