Skip to content

Commit 8029e9b

Browse files
luisdlopezLuis Doebbel
andauthored
More theme customization and typing. (#21)
* Theme customization and typing. Some values used in both MUI theme and custom css. * Animation times use properties defined in theme --------- Co-authored-by: Luis Doebbel <luis.doebbel@nventive.com>
1 parent bc5db82 commit 8029e9b

15 files changed

Lines changed: 225 additions & 122 deletions

frontend/src/app/components/errorHelperText/ErrorHelperText.tsx

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,30 @@
11
import Typography from "@mui/material/Typography";
22
import { RefObject, useEffect, useRef, useState } from "react";
33
import { CSSTransition, TransitionGroup } from "react-transition-group";
4-
import classes from "./error-helper-text.module.css";
4+
import { css } from "@mui/material-pigment-css";
55

66
interface IErrorBox {
77
message: string;
88
}
99

10+
const enter = css`
11+
opacity: 0;
12+
`;
13+
14+
const enterActive = css(({ theme }) => ({
15+
opacity: 1,
16+
transition: `opacity ${theme.transitions.duration.short}ms ${theme.transitions.easing.easeIn}`,
17+
}));
18+
19+
const exit = css`
20+
opacity: 0;
21+
`;
22+
23+
const exitActive = css(({ theme }) => ({
24+
opacity: 0,
25+
transition: `opacity ${theme.transitions.duration.short}ms ${theme.transitions.easing.easeOut}`,
26+
}));
27+
1028
export default function ErrorHelperText({ message }: IErrorBox) {
1129
const [activeMessage, setActiveMessage] = useState<string | undefined>(
1230
undefined,
@@ -21,10 +39,10 @@ export default function ErrorHelperText({ message }: IErrorBox) {
2139
{activeMessage && (
2240
<CSSTransition
2341
classNames={{
24-
enter: classes["enter"],
25-
enterActive: classes["enter-active"],
26-
exit: classes["exit"],
27-
exitActive: classes["exit-active"],
42+
enter: enter,
43+
enterActive: enterActive,
44+
exit: exit,
45+
exitActive: exitActive,
2846
}}
2947
timeout={350}
3048
nodeRef={nodeRef}

frontend/src/app/components/errorHelperText/error-helper-text.module.css

Lines changed: 0 additions & 21 deletions
This file was deleted.

frontend/src/app/components/loading/Loading.tsx

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,17 @@ import Spinner from "@components/spinner/Spinner";
22
import { RefObject, useRef } from "react";
33
import { CSSTransition, TransitionGroup } from "react-transition-group";
44
import classes from "./loading.module.css";
5+
import { css } from "@mui/material-pigment-css";
6+
7+
const enterActive = css(({ theme }) => ({
8+
opacity: 1,
9+
transition: `opacity ${theme.transitions.duration.standard}ms ${theme.transitions.easing.easeIn}`,
10+
}));
11+
12+
const exitActive = css(({ theme }) => ({
13+
opacity: 0,
14+
transition: `opacity ${theme.transitions.duration.standard}ms ${theme.transitions.easing.easeOut}`,
15+
}));
516

617
interface ILoading {
718
isLoading?: boolean;
@@ -16,9 +27,9 @@ export default function Loading({ isLoading = true }: ILoading) {
1627
<CSSTransition
1728
classNames={{
1829
enter: classes["enter"],
19-
enterActive: classes["enter-active"],
30+
enterActive: enterActive,
2031
exit: classes["exit"],
21-
exitActive: classes["exit-active"],
32+
exitActive: exitActive,
2233
}}
2334
timeout={500}
2435
nodeRef={nodeRef}

frontend/src/app/components/loading/loading.module.css

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,6 @@
1515
opacity: 0;
1616
}
1717

18-
.enter-active {
19-
opacity: 1;
20-
transition: opacity 0.5s ease-in;
21-
}
22-
2318
.exit {
2419
opacity: 1;
2520
}
26-
27-
.enter-active {
28-
opacity: 0;
29-
transition: opacity 0.5s ease-out;
30-
}

frontend/src/app/components/spinner/Spinner.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ export default function Spinner() {
44
return (
55
<span
66
sx={(theme) => ({
7-
backgroundImage: `linear-gradient(${theme.palette.primary.main} 16px,transparent 0),
7+
backgroundImage: `linear-gradient(${theme.palette.primary.dark} 16px,transparent 0),
88
linear-gradient(${theme.palette.primary.main} 16px, transparent 0),
99
linear-gradient(${theme.palette.primary.main} 16px, transparent 0),
1010
linear-gradient(${theme.palette.primary.dark} 16px, transparent 0)`,

frontend/src/material-ui-pigment-css.d.ts

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,58 @@
11
import { Theme, SxProps } from "@mui/material/styles";
22
import {} from "@mui/material/themeCssVarsAugmentation";
33

4+
// Extend the Pigment CSS theme types with Material UI Theme
45
declare module "@mui/material-pigment-css" {
56
interface ThemeArgs {
67
theme: Theme;
78
}
89
}
910

1011
declare module "@mui/material/styles" {
12+
// Named like this to augment the existing ZIndex theme type
1113
interface ZIndex {
1214
debugBanner: number;
1315
cookieBanner: number;
1416
loading: number;
1517
}
1618

19+
interface CustomSpacing {
20+
a: string;
21+
xxs: string;
22+
xs: string;
23+
sm: string;
24+
md: string;
25+
lg: string;
26+
xl: string;
27+
xxl: string;
28+
}
29+
30+
interface CustomBorderRadius {
31+
xs: string;
32+
sm: string;
33+
md: string;
34+
lg: string;
35+
}
36+
1737
interface Theme {
1838
zIndex: ZIndex;
1939
customProperties: {
20-
borderRadius: {
21-
xs: string;
22-
sm: string;
23-
md: string;
24-
lg: string;
25-
};
26-
time: {
27-
normal: string;
28-
slow: string;
29-
};
40+
spacing: CustomSpacing;
41+
borderRadius: CustomBorderRadius;
3042
};
3143
}
3244

3345
// allow configuration using `createTheme`
3446
interface ThemeOptions {
3547
zIndex?: Partial<ZIndex>;
3648
customProperties?: {
37-
borderRadius?: {
38-
xs: string;
39-
sm: string;
40-
md: string;
41-
lg: string;
42-
};
43-
time?: {
44-
normal: string;
45-
slow: string;
46-
};
49+
spacing?: Partial<CustomSpacing>;
50+
borderRadius?: Partial<CustomBorderRadius>;
4751
};
4852
}
4953
}
5054

55+
// Allows typescript to recognize sx prop on HTML elements
5156
declare global {
5257
namespace React {
5358
interface HTMLAttributes {

frontend/src/styles/_animations.scss

Lines changed: 0 additions & 23 deletions
This file was deleted.

frontend/src/styles/_fonts.scss

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
@font-face {
2+
font-family: InterTight;
3+
font-style: normal;
4+
font-weight: 400;
5+
font-display: swap;
6+
src:
7+
url("@assets/fonts/InterTight/InterTight-Regular.woff2") format("woff2"),
8+
url("@assets/fonts/InterTight/InterTight-Regular.ttf") format("truetype");
9+
}
10+
11+
@font-face {
12+
font-family: InterTight;
13+
font-style: normal;
14+
font-weight: 500;
15+
font-display: swap;
16+
src:
17+
url("@assets/fonts/InterTight/InterTight-Medium.woff2") format("woff2"),
18+
url("@assets/fonts/InterTight/InterTight-Medium.ttf") format("truetype");
19+
}
20+
21+
@font-face {
22+
font-family: InterTight;
23+
font-style: normal;
24+
font-weight: 600;
25+
font-display: swap;
26+
src:
27+
url("@assets/fonts/InterTight/InterTight-SemiBold.woff2") format("woff2"),
28+
url("@assets/fonts/InterTight/InterTight-SemiBold.ttf") format("truetype");
29+
}
30+
31+
@font-face {
32+
font-family: InterTight;
33+
font-style: normal;
34+
font-weight: 700;
35+
font-display: swap;
36+
src:
37+
url("@assets/fonts/InterTight/InterTight-Bold.woff2") format("woff2"),
38+
url("@assets/fonts/InterTight/InterTight-Bold.ttf") format("truetype");
39+
}

frontend/src/styles/_globals.scss

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@ body {
1212
flex-direction: column;
1313
min-height: 100%;
1414
width: 100%;
15-
font-family: InterTight, sans-serif;
16-
font-size: 16px;
1715
overflow-y: scroll;
1816
}
1917

@@ -23,7 +21,6 @@ body {
2321
flex: 1 1 auto;
2422
height: 100%;
2523
width: 100%;
26-
animation: 0.5s fade-in forwards;
2724
}
2825

2926
.flex {

frontend/src/styles/_variables.scss

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,16 @@
22
= Variables =
33
============================================ */
44

5-
// ideally, these should match the spacing from MUI
5+
// Allow utility classes to use the same spacing properties defined in the MUI theme
66
$spacing: (
7-
0: 0,
8-
a: auto,
9-
xxs: 0.25rem,
10-
xs: 0.5rem,
11-
sm: 0.75rem,
12-
md: 1rem,
13-
lg: 1.5rem,
14-
xl: 2rem,
15-
xxl: 3rem,
7+
a: var(--mui-customProperties-spacing-a),
8+
xxs: var(--mui-customProperties-spacing-xxs),
9+
xs: var(--mui-customProperties-spacing-xs),
10+
sm: var(--mui-customProperties-spacing-sm),
11+
md: var(--mui-customProperties-spacing-md),
12+
lg: var(--mui-customProperties-spacing-lg),
13+
xl: var(--mui-customProperties-spacing-xl),
14+
xxl: var(--mui-customProperties-spacing-xxl),
1615
);
1716

1817
$direction: (

0 commit comments

Comments
 (0)