Skip to content

Commit 49b38e6

Browse files
committed
Backport changes from mui/material-ui#22295.
1 parent 79aa12e commit 49b38e6

File tree

6 files changed

+67
-80
lines changed

6 files changed

+67
-80
lines changed

src/onepirate/Privacy.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ function Privacy() {
1919
.then((responseText) => setMarkdown(responseText));
2020
});
2121

22+
if (!markdown) {
23+
return <div />;
24+
}
25+
2226
return (
2327
<React.Fragment>
2428
<AppAppBar />

src/onepirate/Terms.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ function Terms() {
1919
.then((responseText) => setMarkdown(responseText));
2020
});
2121

22+
if (!markdown) {
23+
return <div />;
24+
}
25+
2226
return (
2327
<React.Fragment>
2428
<AppAppBar />

src/onepirate/modules/components/Paper.tsx

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@ import clsx from "clsx";
33
import MuiPaper, { PaperProps } from "@material-ui/core/Paper";
44
import { withStyles, Theme, WithStyles } from "@material-ui/core/styles";
55

6+
const backgroundStyleMapping = {
7+
light: "backgroundLight",
8+
main: "backgroundMain",
9+
dark: "backgroundDark",
10+
};
11+
612
const styles = (theme: Theme) => ({
713
[backgroundStyleMapping["light"]]: {
814
backgroundColor: theme.palette.secondary.light,
@@ -23,16 +29,10 @@ interface ExtraPaperProps {
2329
padding?: boolean;
2430
}
2531

26-
const backgroundStyleMapping = {
27-
light: "backgroundLight",
28-
main: "backgroundMain",
29-
dark: "backgroundDark",
30-
};
31-
3232
function Paper(
3333
props: PaperProps & ExtraPaperProps & WithStyles<typeof styles>
3434
) {
35-
const { background, classes, className, padding = false, ...other } = props;
35+
const { background, classes, className, padding, ...other } = props;
3636

3737
return (
3838
<MuiPaper
@@ -41,7 +41,7 @@ function Paper(
4141
className={clsx(
4242
classes[backgroundStyleMapping[background]],
4343
{
44-
[classes.padding]: padding,
44+
[classes.padding]: !!padding,
4545
},
4646
className
4747
)}
@@ -50,8 +50,4 @@ function Paper(
5050
);
5151
}
5252

53-
Paper.defaultProps = {
54-
padding: false,
55-
};
56-
5753
export default withStyles(styles)(Paper);

src/onepirate/modules/components/Snackbar.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,7 @@ function Snackbar(
7979
aria-label="close"
8080
color="inherit"
8181
className={classes.close}
82-
onClick={() => {
83-
closeFunc && closeFunc();
84-
}}
82+
onClick={() => closeFunc && closeFunc()}
8583
>
8684
<CloseIcon />
8785
</IconButton>,

src/onepirate/modules/components/TextField.tsx

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,13 @@ import clsx from "clsx";
33
import { withStyles, WithStyles, createStyles } from "@material-ui/core/styles";
44
import MuiTextField, { TextFieldProps } from "@material-ui/core/TextField";
55

6+
const inputSyleMapping = {
7+
small: "inputSizeSmall",
8+
medium: "inputSizeMedium",
9+
large: "inputSizeLarge",
10+
xlarge: "inputSizeXlarge",
11+
};
12+
613
const styles = (theme: any) =>
714
createStyles({
815
root: {
@@ -37,8 +44,8 @@ const styles = (theme: any) =>
3744
},
3845
[inputSyleMapping["large"]]: {
3946
fontSize: 18,
40-
padding: 22,
41-
width: `calc(100% - ${22 * 2}px)`,
47+
padding: 20,
48+
width: `calc(100% - ${20 * 2}px)`,
4249
},
4350
[inputSyleMapping["xlarge"]]: {
4451
fontSize: 20,
@@ -63,20 +70,13 @@ export interface OnePirateTextFieldProps extends Omit<TextFieldProps, "size"> {
6370
size?: "small" | "medium" | "large" | "xlarge";
6471
}
6572

66-
const inputSyleMapping = {
67-
small: "inputSizeSmall",
68-
medium: "inputSizeMedium",
69-
large: "inputSizeLarge",
70-
xlarge: "inputSizeXlarge",
71-
};
72-
7373
function TextField(props: OnePirateTextFieldProps & WithStyles<typeof styles>) {
7474
const {
7575
classes,
7676
InputProps = {},
7777
InputLabelProps,
78-
noBorder = false,
79-
size,
78+
noBorder,
79+
size = "medium",
8080
SelectProps,
8181
...other
8282
} = props;
@@ -98,7 +98,7 @@ function TextField(props: OnePirateTextFieldProps & WithStyles<typeof styles>) {
9898
root: classes.root,
9999
input: clsx(
100100
classes.input,
101-
classes[inputSyleMapping[size!]],
101+
classes[inputSyleMapping[size]],
102102
{
103103
[classes.inputBorder]: !noBorder,
104104
},
@@ -126,9 +126,4 @@ function TextField(props: OnePirateTextFieldProps & WithStyles<typeof styles>) {
126126
);
127127
}
128128

129-
TextField.defaultProps = {
130-
size: "medium" as const,
131-
noBorder: false,
132-
};
133-
134129
export default withStyles(styles)(TextField);

src/onepirate/modules/components/Typography.tsx

Lines changed: 38 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -7,36 +7,59 @@ import {
77
} from "@material-ui/core/styles";
88
import MuiTypography, { TypographyProps } from "@material-ui/core/Typography";
99

10-
export enum TypographyMarkType {
11-
Center = "center",
12-
Left = "left",
13-
None = "none",
14-
}
10+
const markSyleMapping: {
11+
[index: string]: { [subindex: string]: string };
12+
} = {
13+
center: {
14+
h1: "",
15+
h2: "markedH2Center",
16+
h3: "markedH3Center",
17+
h4: "markedH4Center",
18+
h5: "",
19+
h6: "",
20+
},
21+
left: {
22+
h1: "",
23+
h2: "",
24+
h3: "",
25+
h4: "",
26+
h5: "",
27+
h6: "markedH6Left",
28+
},
29+
none: {
30+
h1: "",
31+
h2: "",
32+
h3: "",
33+
h4: "",
34+
h5: "",
35+
h6: "",
36+
},
37+
};
1538

1639
const styles = (theme: Theme) =>
1740
createStyles({
18-
[markSyleMapping[TypographyMarkType.Center]["h2"]]: {
41+
[markSyleMapping["center"]["h2"]]: {
1942
height: 4,
2043
width: 73,
2144
display: "block",
2245
margin: `${theme.spacing(1)}px auto 0`,
2346
backgroundColor: theme.palette.secondary.main,
2447
},
25-
[markSyleMapping[TypographyMarkType.Center]["h3"]]: {
48+
[markSyleMapping["center"]["h3"]]: {
2649
height: 4,
2750
width: 55,
2851
display: "block",
2952
margin: `${theme.spacing(1)}px auto 0`,
3053
backgroundColor: theme.palette.secondary.main,
3154
},
32-
[markSyleMapping[TypographyMarkType.Center]["h4"]]: {
55+
[markSyleMapping["center"]["h4"]]: {
3356
height: 4,
3457
width: 55,
3558
display: "block",
3659
margin: `${theme.spacing(1)}px auto 0`,
3760
backgroundColor: theme.palette.secondary.main,
3861
},
39-
[markSyleMapping[TypographyMarkType.Left]["h6"]]: {
62+
[markSyleMapping["left"]["h6"]]: {
4063
height: 2,
4164
width: 28,
4265
display: "block",
@@ -46,7 +69,7 @@ const styles = (theme: Theme) =>
4669
});
4770

4871
interface ExtraTypographyProps {
49-
marked?: TypographyMarkType;
72+
marked?: "center" | "left" | "none";
5073
}
5174

5275
const variantMapping = {
@@ -59,57 +82,24 @@ const variantMapping = {
5982
subtitle1: "h3",
6083
};
6184

62-
const markSyleMapping: {
63-
[index: string]: { [subindex: string]: string };
64-
} = {
65-
[TypographyMarkType.Center]: {
66-
h1: "",
67-
h2: "markedH2Center",
68-
h3: "markedH3Center",
69-
h4: "markedH4Center",
70-
h5: "",
71-
h6: "",
72-
},
73-
[TypographyMarkType.Left]: {
74-
h1: "",
75-
h2: "",
76-
h3: "",
77-
h4: "",
78-
h5: "",
79-
h6: "markedH6Left",
80-
},
81-
[TypographyMarkType.None]: {
82-
h1: "",
83-
h2: "",
84-
h3: "",
85-
h4: "",
86-
h5: "",
87-
h6: "",
88-
},
89-
};
90-
9185
function Typography<C extends React.ElementType>(
9286
props: TypographyProps<C, { component?: C }> &
9387
WithStyles<typeof styles> &
9488
ExtraTypographyProps
9589
) {
96-
const { children, variant, classes, marked, ...other } = props;
90+
const { children, variant, classes, marked = "none", ...other } = props;
9791

98-
let className = "";
99-
if (marked && variant && variant in markSyleMapping[marked]) {
100-
className = classes[markSyleMapping[marked][variant]];
92+
let markedClassName = "";
93+
if (variant && variant in markSyleMapping[marked]) {
94+
markedClassName = classes[markSyleMapping[marked][variant]];
10195
}
10296

10397
return (
10498
<MuiTypography variantMapping={variantMapping} variant={variant} {...other}>
10599
{children}
106-
{marked ? <span className={className} /> : null}
100+
{markedClassName ? <span className={markedClassName} /> : null}
107101
</MuiTypography>
108102
);
109103
}
110104

111-
Typography.defaultProps = {
112-
marked: TypographyMarkType.None,
113-
};
114-
115105
export default withStyles(styles)(Typography);

0 commit comments

Comments
 (0)