Skip to content

Commit de38386

Browse files
committed
update: Rect Router v6+
refactor: theme and colors refactor: Layout is outside Routes feat: more utils feat: env.sample
1 parent 061e3bb commit de38386

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+34231
-12354
lines changed

.env.sample

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
REACT_APP_VERSION = $npm_package_version
2+
REACT_APP_URL_API = http://localhost:3030/api

package-lock.json

Lines changed: 33757 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-typescript-material",
3-
"version": "1.2.7",
3+
"version": "1.3.8",
44
"description": "React + Material UI + Auth starter using TypeScript",
55
"author": {
66
"name": "Anton Karpenko",
@@ -18,6 +18,14 @@
1818
"type": "git",
1919
"url": "https://github.com/karpolan/react-typescript-material-ui-with-auth-starter.git"
2020
},
21+
"scripts": {
22+
"start": "react-scripts start",
23+
"dev": "npm i --force && react-scripts start",
24+
"build": "react-scripts build",
25+
"type": "tsc",
26+
"format": "node_modules/.bin/prettier src --write",
27+
"test": "react-scripts test"
28+
},
2129
"dependencies": {
2230
"@emotion/react": "latest",
2331
"@emotion/styled": "latest",
@@ -29,7 +37,6 @@
2937
"react-dom": "latest",
3038
"react-router-dom": "latest",
3139
"react-scripts": "latest",
32-
"typescript": "latest",
3340
"validate.js": "latest",
3441
"web-vitals": "latest"
3542
},
@@ -42,15 +49,8 @@
4249
"@types/react": "latest",
4350
"@types/react-dom": "latest",
4451
"@types/react-router-dom": "latest",
45-
"prettier": "latest"
46-
},
47-
"scripts": {
48-
"start": "react-scripts start",
49-
"dev": "yarn -s && react-scripts start",
50-
"build": "react-scripts build",
51-
"type": "tsc",
52-
"format": "node_modules/.bin/prettier src --write",
53-
"test": "react-scripts test"
52+
"prettier": "latest",
53+
"typescript": "latest"
5454
},
5555
"eslintConfig": {
5656
"extends": [

src/App.tsx

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,23 @@
11
import { AppStore } from './store';
2-
import { AppRouter, Routes } from './routes';
3-
import { ErrorBoundary } from './components';
42
import { AppThemeProvider } from './theme';
3+
import Routes from './routes';
4+
import Layout from './layout';
5+
import { ErrorBoundary } from './components';
6+
import { BrowserRouter } from 'react-router-dom';
57

68
/**
79
* Root Application Component
8-
* @class App
910
*/
1011
const App = () => {
1112
return (
1213
<ErrorBoundary name="App">
1314
<AppStore>
1415
<AppThemeProvider>
15-
<AppRouter>
16-
<Routes />
17-
</AppRouter>
16+
<BrowserRouter>
17+
<Layout>
18+
<Routes />
19+
</Layout>
20+
</BrowserRouter>
1821
</AppThemeProvider>
1922
</AppStore>
2023
</ErrorBoundary>

src/components/AppButton/AppButton.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ interface Props extends Omit<ButtonProps, 'color'> {
3838

3939
/**
4040
* Application styled Material UI Button with Box around to specify margins using props
41-
* @class AppButton
4241
* @param {string} [color] - name of color from Material UI palette 'primary', 'secondary', 'warning', and so on
4342
* @param {string} [children] - content to render, overrides .label and .text
4443
* @param {string} [label] - text to render, alternate to .text

src/components/AppLink/AppLink.test.tsx

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
import React from 'react';
22
import { render, screen } from '@testing-library/react';
33
import AppLink from './AppLink';
4-
import { AppRouter } from '../../routes/';
4+
import { BrowserRouter } from 'react-router-dom';
55

66
describe('AppLink component', () => {
77
it('renders itself', async () => {
88
const text = 'sample text';
99
const url = 'https://example.com/';
1010
await render(
11-
<AppRouter>
11+
<BrowserRouter>
1212
<AppLink href={url}>{text}</AppLink>
13-
</AppRouter>
13+
</BrowserRouter>
1414
);
1515
const link = await screen.getByText(text);
1616
expect(link).toBeDefined();
@@ -22,9 +22,9 @@ describe('AppLink component', () => {
2222
const text = 'external link';
2323
const url = 'https://example.com/';
2424
await render(
25-
<AppRouter>
25+
<BrowserRouter>
2626
<AppLink href={url}>{text}</AppLink>
27-
</AppRouter>
27+
</BrowserRouter>
2828
);
2929
const link = await screen.getByText(text);
3030
expect(link).toBeDefined();
@@ -41,9 +41,9 @@ describe('AppLink component', () => {
4141
const text = 'internal link';
4242
const url = '/internal-link';
4343
await render(
44-
<AppRouter>
44+
<BrowserRouter>
4545
<AppLink to={url}>{text}</AppLink>
46-
</AppRouter>
46+
</BrowserRouter>
4747
);
4848
const link = await screen.getByText(text);
4949
expect(link).toBeDefined();
@@ -58,11 +58,11 @@ describe('AppLink component', () => {
5858
let text = 'external link in same tab';
5959
let url = 'https://example.com/';
6060
await render(
61-
<AppRouter>
61+
<BrowserRouter>
6262
<AppLink href={url} openInNewTab={false}>
6363
{text}
6464
</AppLink>
65-
</AppRouter>
65+
</BrowserRouter>
6666
);
6767
let link = await screen.getByText(text);
6868
expect(link).toBeDefined();
@@ -75,11 +75,11 @@ describe('AppLink component', () => {
7575
text = 'internal link in new tab';
7676
url = '/internal-link-in-new-tab';
7777
await render(
78-
<AppRouter>
78+
<BrowserRouter>
7979
<AppLink to={url} openInNewTab>
8080
{text}
8181
</AppLink>
82-
</AppRouter>
82+
</BrowserRouter>
8383
);
8484
link = await screen.getByText(text);
8585
expect(link).toBeDefined();
@@ -97,11 +97,11 @@ describe('AppLink component', () => {
9797
let url = '/internal-link-with-class';
9898
let className = 'someClassName';
9999
await render(
100-
<AppRouter>
100+
<BrowserRouter>
101101
<AppLink to={url} className={className}>
102102
{text}
103103
</AppLink>
104-
</AppRouter>
104+
</BrowserRouter>
105105
);
106106
let link = await screen.getByText(text);
107107
expect(link).toBeDefined();

src/components/AppLink/AppLink.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ interface Props extends MuiLinkProps {
1414

1515
/**
1616
* Restyled Link for navigation in the App, support internal links by "to" prop and external links by "href" prop
17-
* @class AppLink
1817
* @param {object|function} children - content to wrap with <a> tag
1918
* @param {string} [to] - internal link URI
2019
* @param {string} [href] - external link URI

src/components/SideBar/SideBar.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { useAppStore } from '../../store/AppStore';
1111
import { AppIconButton } from '../../components';
1212
import UserInfo from '../UserInfo/UserInfo';
1313
import SideBarNavigation from './SideBarNavigation';
14-
import { SIDEBAR_WIDTH } from '../../routes/Layout/PrivateLayout';
14+
import { SIDEBAR_WIDTH } from '../../layout/PrivateLayout';
1515
import { LinkToPage } from '../../utils/type';
1616

1717
const useStyles = makeStyles((theme: Theme) => ({
@@ -45,7 +45,6 @@ const useStyles = makeStyles((theme: Theme) => ({
4545
/**
4646
* Renders SideBar with Menu and User details
4747
* Actually for Authenticated users only, rendered in "Private Layout"
48-
* @class SideBar
4948
* @param {string} [prop.anchor] - 'left' or 'right'
5049
* @param {string} [prop.className] - optional className for <div> tag
5150
* @param {boolean} props.open - the Drawer is visible when true

src/components/SideBar/SideBarLink.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,11 @@ const SideBarLink = forwardRef<any, NavLinkProps>(({ className, ...restOfProps }
2525
const classLink = clsx(className, classes.link);
2626
return (
2727
<div ref={ref} className={classes.root}>
28-
<NavLink exact className={classLink} activeClassName={classes.linkActive} {...restOfProps} />
28+
<NavLink
29+
end
30+
className={({ isActive }) => classLink + (isActive ? ` ${classes.linkActive}` : '')}
31+
{...restOfProps}
32+
/>
2933
</div>
3034
);
3135
});

src/index.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
import React from 'react';
2-
import ReactDOM from 'react-dom';
2+
import ReactDOM from 'react-dom/client';
33
import './index.css';
44
import App from './App';
55
import reportWebVitals from './reportWebVitals';
66

7-
ReactDOM.render(
7+
const root = ReactDOM.createRoot(document.getElementById('root') as HTMLElement);
8+
root.render(
89
<React.StrictMode>
910
<App />
10-
</React.StrictMode>,
11-
document.getElementById('root')
11+
</React.StrictMode>
1212
);
1313

1414
// If you want to start measuring performance in your app, pass a function
1515
// to log results (for example: reportWebVitals(console.log))
1616
// or send to an analytics endpoint. Learn more: https://bit.ly/CRA-vitals
17-
reportWebVitals(console.log);
17+
reportWebVitals();

0 commit comments

Comments
 (0)