Skip to content

Commit 308367e

Browse files
authored
Merge pull request #2 from karpolan/dev
Dev -> Master
2 parents e9eb120 + 0001b60 commit 308367e

File tree

27 files changed

+18204
-1770
lines changed

27 files changed

+18204
-1770
lines changed

package-lock.json

Lines changed: 16153 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: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-typescript-material",
3-
"version": "1.0.0",
3+
"version": "1.1.5",
44
"description": "React + Material UI + Auth starter using TypeScript",
55
"author": {
66
"name": "Anton Karpenko",
@@ -19,28 +19,28 @@
1919
"url": "https://github.com/karpolan/react-typescript-material-ui-with-auth-starter.git"
2020
},
2121
"dependencies": {
22-
"@material-ui/core": "^4.11.3",
22+
"@material-ui/core": "^4.12.3",
2323
"@material-ui/icons": "^4.11.2",
24-
"@material-ui/lab": "^4.0.0-alpha.57",
25-
"date-fns": "^2.21.1",
24+
"@material-ui/lab": "^4.0.0-alpha.60",
25+
"date-fns": "^2.23.0",
2626
"react": "^17.0.2",
2727
"react-dom": "^17.0.2",
2828
"react-router-dom": "^5.2.0",
2929
"react-scripts": "4.0.3",
30-
"typescript": "^4.1.2",
30+
"typescript": "^4.3.5",
3131
"validate.js": "^0.13.1",
32-
"web-vitals": "^1.0.1"
32+
"web-vitals": "^1.1.2"
3333
},
3434
"devDependencies": {
35-
"@testing-library/jest-dom": "^5.11.4",
36-
"@testing-library/react": "^11.1.0",
35+
"@testing-library/jest-dom": "^5.14.1",
36+
"@testing-library/react": "^11.2.7",
3737
"@testing-library/user-event": "^12.1.10",
38-
"@types/jest": "^26.0.15",
39-
"@types/node": "^12.0.0",
40-
"@types/react": "^17.0.0",
41-
"@types/react-dom": "^17.0.0",
42-
"@types/react-router-dom": "^5.1.7",
43-
"prettier": "^2.2.1"
38+
"@types/jest": "^26.0.24",
39+
"@types/node": "^12.20.19",
40+
"@types/react": "^17.0.19",
41+
"@types/react-dom": "^17.0.9",
42+
"@types/react-router-dom": "^5.1.8",
43+
"prettier": "^2.3.2"
4444
},
4545
"scripts": {
4646
"start": "react-scripts start",

src/components/AppAlert/AppAlert.tsx

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,12 @@ import clsx from 'clsx';
22
import { Theme, makeStyles } from '@material-ui/core/styles';
33
import MuiAlert, { AlertProps as MuiAlertProps } from '@material-ui/lab/Alert';
44

5+
/**
6+
* Note: You can change these const to control default appearance of the AppAlert component
7+
*/
58
const APP_ALERT_SEVERITY = 'info'; // 'error' | 'info'| 'success' | 'warning'
69
const APP_ALERT_VARIANT = 'standard'; // 'filled' | 'outlined' | 'standard'
10+
const APP_ALERT_ELEVATION = 5;
711

812
const useStyles = makeStyles((theme: Theme) => ({
913
root: {
@@ -18,14 +22,24 @@ const useStyles = makeStyles((theme: Theme) => ({
1822
const AppAlert: React.FC<MuiAlertProps> = ({
1923
severity = APP_ALERT_SEVERITY,
2024
variant = APP_ALERT_VARIANT,
25+
elevation = APP_ALERT_ELEVATION,
2126
className,
2227
onClose,
2328
...restOfProps
2429
}) => {
2530
const classes = useStyles();
2631
const classRoot = clsx(classes.root, className);
2732

28-
return <MuiAlert className={classRoot} severity={severity} variant={variant} onClose={onClose} {...restOfProps} />;
33+
return (
34+
<MuiAlert
35+
className={classRoot}
36+
severity={severity}
37+
variant={variant}
38+
elevation={elevation}
39+
onClose={onClose}
40+
{...restOfProps}
41+
/>
42+
);
2943
};
3044

3145
export default AppAlert;

src/components/AppButton/AppButton.test.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ function testButtonColor(colorName: string, expectedClassName = colorName, ignor
1818

1919
let button = await span.closest('button'); // parent <button> element
2020
expect(button).toBeDefined();
21+
// console.log('button.className:', button?.className)
2122
if (!ignoreClassName) {
2223
expect(button?.className?.includes(`makeStyles-${expectedClassName}`)).toBeTruthy(); // There is "makeStyles-[expectedClassName]-xxx" class
2324
}

src/components/AppButton/AppButton.tsx

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,11 @@ import Box from '@material-ui/core/Box';
44
import Button, { ButtonProps } from '@material-ui/core/Button';
55
import { buttonStylesByNames, ColorName } from '../../utils/style';
66

7+
/**
8+
* Note: You can change these const to control default appearance of the AppButton component
9+
*/
710
const APP_BUTTON_VARIANT = 'contained'; // | 'text' | 'outlined'
11+
const APP_BUTTON_MARGIN = 1;
812

913
const useStyles = makeStyles((theme: Theme) => ({
1014
box: {
@@ -27,28 +31,29 @@ interface Props extends Omit<ButtonProps, 'color'> {
2731
component?: React.ElementType; // Could be RouterLink, AppLink, etc.
2832
to?: string; // Link prop
2933
href?: string; // Link prop
34+
openInNewTab?: boolean; // Link prop
3035
underline?: 'none' | 'hover' | 'always'; // Link prop
3136
}
3237

3338
/**
34-
* Application styled Material UI Button
39+
* Application styled Material UI Button with Box around to specify margins using props
3540
* @class AppButton
3641
* @param {string} [color] - name of color from Material UI palette 'primary', 'secondary', 'warning', and so on
3742
* @param {string} [children] - content to render, overrides .label and .text
3843
* @param {string} [label] - text to render, alternate to .text
3944
* @param {string} [text] - text to render, alternate to .label
4045
*/
4146
const AppButton: React.FC<Props> = ({
42-
className,
4347
children,
48+
className,
4449
color = 'default',
4550
label,
46-
text,
4751
m = 0,
48-
mt = 1,
49-
mb = 1,
50-
ml = 1,
51-
mr = 1,
52+
mt = APP_BUTTON_MARGIN,
53+
mb = APP_BUTTON_MARGIN,
54+
ml = APP_BUTTON_MARGIN,
55+
mr = APP_BUTTON_MARGIN,
56+
text,
5257
underline = 'none',
5358
...restOfProps
5459
}) => {

src/components/AppIconButton/AppIconButton.tsx

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,19 +30,25 @@ interface Props extends Omit<IconButtonProps, 'color'> {
3030
to?: string; // Link prop
3131
href?: string; // Link prop
3232
}
33-
const AppIconButton: React.FC<Props> = ({ color, className, children, icon, title, ...restOfProps }) => {
33+
const AppIconButton: React.FC<Props> = ({ color, className, children, disabled, icon, title, ...restOfProps }) => {
3434
const classes = useStyles();
3535
const classButton = clsx(classes[color as ColorName], className);
3636
const colorButton = getValidMuiColor(color);
3737

3838
const renderIcon = () => (
39-
<IconButton className={classButton} color={colorButton} {...restOfProps}>
39+
<IconButton className={classButton} color={colorButton} disabled={disabled} {...restOfProps}>
4040
<AppIcon icon={icon} />
4141
{children}
4242
</IconButton>
4343
);
4444

45-
return title ? <Tooltip title={title}>{renderIcon()}</Tooltip> : renderIcon();
45+
// When title is set, wrap te IconButton with Tooltip.
46+
// Note: when IconButton is disabled the Tooltip is not working, so we don't need it
47+
if (title && !disabled) {
48+
return <Tooltip title={title}>{renderIcon()}</Tooltip>;
49+
}
50+
51+
return title && !disabled ? <Tooltip title={title}>{renderIcon()}</Tooltip> : renderIcon();
4652
};
4753

4854
export default AppIconButton;

src/components/SideBar/SideBarNavigation.tsx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,9 @@ const useStyles = makeStyles((theme: Theme) => ({
3535
}));
3636

3737
/**
38-
* Renders list of Navigation Items for SideBar
39-
* @param {array} props.links - list of objects to render as navigation links
38+
* Renders list of Navigation Items inside SideBar
39+
* @param {string} [prop.className] - optional className for styling
40+
* @param {array} props.items - list of objects to render as navigation links
4041
* @param {boolean} [props.showIcons] - icons in links are visible when true
4142
* @param {func} [props.afterLinkClink] - optional callback called when some link was clicked
4243
*/
@@ -59,11 +60,11 @@ const SideBarNavigation: React.FC<Props> = ({
5960
<nav>
6061
<List className={classRoot} {...restOfProps}>
6162
{items.map((link) => (
62-
<ListItem key={`${link.title}-${link.href}`} className={classes.item} disableGutters>
63+
<ListItem key={`${link.title}-${link.path}`} className={classes.item} disableGutters>
6364
<Button
6465
className={classes.button}
6566
component={SideBarLink}
66-
to={link.href as string}
67+
to={link.path as string}
6768
onClick={afterLinkClick}
6869
>
6970
<div className={classes.iconOrMargin}>{showIcons && link.icon ? <AppIcon icon={link.icon} /> : null}</div>

src/components/TopBar/TopBar.tsx

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
import clsx from 'clsx';
2-
import { Theme, makeStyles } from '@material-ui/core/styles';
3-
import AppBar from '@material-ui/core/AppBar';
4-
import Toolbar from '@material-ui/core/Toolbar';
5-
import Typography from '@material-ui/core/Typography';
2+
import { makeStyles, Theme, AppBar, Toolbar, Typography } from '@material-ui/core';
63
import AppIconButton from '../AppIconButton';
74

85
const useStyles = makeStyles((theme: Theme) => ({

src/components/UserInfo/UserInfo.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ interface UserInfoProps {
3636
const UserInfo = ({ className, showAvatar = false, user, ...restOfProps }: UserInfoProps) => {
3737
const classes = useStyles();
3838

39-
const fullName = [user?.first_name || '', user?.last_name || ''].join(' ').trim();
39+
const fullName = user?.name || [user?.nameFirst || '', user?.nameLast || ''].join(' ').trim();
4040
const srcAvatar = user?.avatar ? user?.avatar : undefined;
4141
const userPhoneOrEmail = user?.phone || (user?.email as string);
4242

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
import { ReactNode, useCallback } from 'react';
2+
import { makeStyles, createStyles, Dialog, DialogActions, DialogContent, DialogProps } from '@material-ui/core';
3+
import { AppButton } from '..';
4+
import { AppDialogTitle } from './components';
5+
import { ColorName, dialogStyles } from '../../utils/style';
6+
7+
const useStyles = makeStyles((theme) =>
8+
createStyles({
9+
root: {},
10+
...dialogStyles(theme),
11+
})
12+
);
13+
14+
/**
15+
* Shows generic "Common" dialog
16+
* @param {function} props.onConfirm - event for Confirm button, called as onConfirm(data)
17+
* @param {function} props.onClose - event for Close and Cancel buttons and the backdrop
18+
*/
19+
interface Props extends DialogProps {
20+
data?: unknown;
21+
title?: string;
22+
text?: string;
23+
body?: ReactNode;
24+
hideCancelButton?: boolean;
25+
confirmButtonText?: string;
26+
confirmButtonColor?: ColorName;
27+
onConfirm?: (data: unknown) => void;
28+
onClose?: (event: {}) => void;
29+
}
30+
const CommonDialog: React.FC<Props> = ({
31+
open = false, // Don't show dialog by default
32+
data, // optional data passed to onConfirm callback
33+
title = 'Missing title...',
34+
text = 'Text is missing...',
35+
body, // JSX to render instead of .text
36+
hideCancelButton = false,
37+
confirmButtonText = 'Confirm',
38+
confirmButtonColor = 'primary',
39+
onConfirm,
40+
onClose,
41+
...props
42+
}) => {
43+
const classes = useStyles();
44+
45+
const handleOnConfirm = useCallback(() => {
46+
if (onConfirm && typeof onConfirm === 'function') {
47+
onConfirm(data);
48+
}
49+
}, [data, onConfirm]);
50+
51+
return (
52+
<Dialog
53+
className={classes.root}
54+
classes={{ paper: classes.paper }}
55+
open={open}
56+
onClose={onClose}
57+
aria-labelledby="form-dialog-title"
58+
{...props}
59+
>
60+
<AppDialogTitle id="form-dialog-title" onClose={onClose}>
61+
{title}
62+
</AppDialogTitle>
63+
<DialogContent>{body || text}</DialogContent>
64+
<DialogActions className={classes.actions}>
65+
{!hideCancelButton && <AppButton onClick={onClose}>Cancel</AppButton>}
66+
<AppButton onClick={handleOnConfirm} color={confirmButtonColor} mr={0}>
67+
{confirmButtonText}
68+
</AppButton>
69+
</DialogActions>
70+
</Dialog>
71+
);
72+
};
73+
74+
export default CommonDialog;

0 commit comments

Comments
 (0)