Skip to content

Commit 5448489

Browse files
Check styles declaration against MUI Theme with TypeScript (#855)
* Add type * Check styles with TypeScript
1 parent e634795 commit 5448489

File tree

52 files changed

+251
-266
lines changed

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

+251
-266
lines changed

src/components/announcement/AnnouncementBanner.tsx

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,11 @@
66
*/
77
import type { UUID } from 'crypto';
88
import { type PropsWithChildren, type ReactNode, useCallback, useEffect, useState } from 'react';
9-
import {
10-
Alert,
11-
type AlertColor,
12-
type AlertProps,
13-
AlertTitle,
14-
Collapse,
15-
type SxProps,
16-
type Theme,
17-
Tooltip,
18-
useTheme,
19-
} from '@mui/material';
9+
import { Alert, type AlertColor, type AlertProps, AlertTitle, Collapse, Tooltip, useTheme } from '@mui/material';
2010
import { Campaign as CampaignIcon } from '@mui/icons-material';
2111
import type { User } from 'oidc-client';
2212
import { AnnouncementSeverity } from '../../utils/types';
13+
import type { MuiStyles } from '../../utils/styles';
2314

2415
// Pick the same color than Snackbar
2516
const snackbarInfo = '#2196f3';
@@ -37,7 +28,7 @@ const styles = {
3728
backgroundColor: snackbarInfo,
3829
},
3930
}),
40-
} as const satisfies Record<string, SxProps<Theme>>;
31+
} as const satisfies MuiStyles;
4132

4233
export type AnnouncementBannerProps = PropsWithChildren<{
4334
// message only visible if user logged

src/components/authentication/Login.tsx

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,30 +4,31 @@
44
* License, v. 2.0. If a copy of the MPL was not distributed with this
55
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
66
*/
7-
import { Avatar, Box, Button, Container, Link, Theme, Typography } from '@mui/material';
7+
import { Avatar, Box, Button, Container, Link, Typography } from '@mui/material';
88
import { LockOutlined as LockOutlinedIcon } from '@mui/icons-material';
99
import { FormattedMessage } from 'react-intl';
10+
import type { MuiStyles } from '../../utils/styles';
1011

1112
const styles = {
12-
paper: (theme: Theme) => ({
13+
paper: (theme) => ({
1314
marginTop: theme.spacing(8),
1415
display: 'flex',
1516
flexDirection: 'column',
1617
alignItems: 'center',
1718
}),
18-
avatar: (theme: Theme) => ({
19+
avatar: (theme) => ({
1920
margin: theme.spacing(1),
2021
backgroundColor: theme.palette.secondary.main,
2122
}),
22-
submit: (theme: Theme) => ({
23+
submit: (theme) => ({
2324
margin: theme.spacing(3, 0, 2),
2425
borderRadius: '30px',
2526
}),
2627
logo: {
2728
width: 64,
2829
height: 64,
2930
},
30-
};
31+
} as const satisfies MuiStyles;
3132

3233
export interface LoginProps {
3334
onLoginClick: () => void;

src/components/authentication/Logout.tsx

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,26 +5,27 @@
55
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
66
*/
77

8-
import { Avatar, Box, Button, Container, Link, Theme, Typography } from '@mui/material';
8+
import { Avatar, Box, Button, Container, Link, Typography } from '@mui/material';
99
import { LogoutOutlined as LogoutOutlinedIcon } from '@mui/icons-material';
1010
import { FormattedMessage } from 'react-intl';
11+
import type { MuiStyles } from '../../utils/styles';
1112

1213
const styles = {
13-
paper: (theme: Theme) => ({
14+
paper: (theme) => ({
1415
marginTop: theme.spacing(8),
1516
display: 'flex',
1617
flexDirection: 'column',
1718
alignItems: 'center',
1819
}),
19-
avatar: (theme: Theme) => ({
20+
avatar: (theme) => ({
2021
margin: theme.spacing(1),
2122
backgroundColor: theme.palette.error.main,
2223
}),
23-
submit: (theme: Theme) => ({
24+
submit: (theme) => ({
2425
margin: theme.spacing(3, 0, 2),
2526
borderRadius: '30px',
2627
}),
27-
};
28+
} as const satisfies MuiStyles;
2829

2930
export interface LogoutProps {
3031
onLogoutClick: () => void;

src/components/cardErrorBoundary/CardErrorBoundary.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import {
2020
IconButton,
2121
type IconButtonProps,
2222
styled,
23-
Theme,
2423
Typography,
2524
} from '@mui/material';
2625
import { Component, type ErrorInfo, type PropsWithChildren } from 'react';
@@ -33,7 +32,7 @@ export interface ExpandMoreProps extends IconButtonProps {
3332
const ExpandMore = styled((props: ExpandMoreProps) => {
3433
const { expand, ...other } = props;
3534
return <IconButton {...other} />;
36-
})(({ theme, expand }: { theme: Theme; expand: boolean }) => ({
35+
})(({ theme, expand }) => ({
3736
transform: !expand ? 'rotate(0deg)' : 'rotate(180deg)',
3837
marginLeft: 'auto',
3938
transition: theme.transitions.create('transform', {

src/components/checkBoxList/CheckBoxListItem.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { ListItem, ListItemButton } from '@mui/material';
1010
import { CheckBoxListItemProps } from './checkBoxList.type';
1111
import { CheckBoxListItemContent } from './CheckBoxListItemContent';
1212
import { mergeSx } from '../../utils';
13+
import type { MuiStyles } from '../../utils/styles';
1314

1415
const styles = {
1516
checkboxListItem: {
@@ -27,7 +28,7 @@ const styles = {
2728
paddingRight: '0px',
2829
},
2930
},
30-
};
31+
} as const satisfies MuiStyles;
3132

3233
export function CheckBoxListItem<T>({
3334
item,

src/components/checkBoxList/DraggableCheckBoxListItem.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { ListItem, ListItemButton } from '@mui/material';
1010
import { DraggableCheckBoxListItemProps } from './checkBoxList.type';
1111
import { DraggableCheckBoxListItemContent } from './DraggableCheckBoxListItemContent';
1212
import { mergeSx } from '../../utils';
13+
import type { MuiStyles } from '../../utils/styles';
1314

1415
const styles = {
1516
checkboxListItem: {
@@ -28,7 +29,7 @@ const styles = {
2829
paddingRight: '0px',
2930
},
3031
},
31-
};
32+
} as const satisfies MuiStyles;
3233

3334
export function DraggableCheckBoxListItem<T>({
3435
item,

src/components/checkBoxList/checkBoxList.type.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,21 @@
77

88
import type { ReactElement, ReactNode } from 'react';
99
import type { DraggableProvided, DragStart, DropResult } from '@hello-pangea/dnd';
10-
import type { SxProps, Theme } from '@mui/material';
10+
import type { SxStyle } from '../../utils/styles';
1111

1212
export type CheckBoxListItemSx = {
13-
checkBoxIcon?: SxProps<Theme>;
14-
listItemText?: SxProps<Theme>;
15-
label?: SxProps<Theme>;
16-
checkboxListItem?: SxProps<Theme>;
17-
checkboxButton?: SxProps<Theme>;
18-
checkbox?: SxProps<Theme>;
19-
dragButton?: SxProps<Theme>;
13+
checkBoxIcon?: SxStyle;
14+
listItemText?: SxStyle;
15+
label?: SxStyle;
16+
checkboxListItem?: SxStyle;
17+
checkboxButton?: SxStyle;
18+
checkbox?: SxStyle;
19+
dragButton?: SxStyle;
2020
};
2121

2222
export type CheckBoxListSx = {
23-
dragAndDropContainer?: SxProps<Theme>;
24-
checkboxList?: SxProps<Theme>;
23+
dragAndDropContainer?: SxStyle;
24+
checkboxList?: SxStyle;
2525
};
2626

2727
export type CheckBoxListItemSxMethod<T> = (item: T) => CheckBoxListItemSx;

src/components/customAGGrid/customAggrid.style.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* License, v. 2.0. If a copy of the MPL was not distributed with this
55
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
66
*/
7-
import type { SxProps, Theme } from '@mui/material';
7+
import type { MuiStyles } from '../../utils/styles';
88

99
export const CUSTOM_AGGRID_THEME = 'custom-aggrid-theme';
1010

@@ -42,4 +42,4 @@ export const styles = {
4242
border: 'none !important',
4343
},
4444
}),
45-
} as const satisfies Record<string, SxProps<Theme>>;
45+
} as const satisfies MuiStyles;

src/components/customAGGrid/customAggrid.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import 'ag-grid-community/styles/ag-theme-alpine.css';
1212
import type { ColumnResizedEvent } from 'ag-grid-community';
1313
import { AG_GRID_LOCALE_EN, AG_GRID_LOCALE_FR } from '@ag-grid-community/locale';
1414
import { useIntl } from 'react-intl';
15-
import { Box, type BoxProps, type Theme, useTheme } from '@mui/material';
15+
import { Box, type BoxProps, useTheme } from '@mui/material';
1616
import { mergeSx } from '../../utils/styles';
1717
import { CUSTOM_AGGRID_THEME, styles } from './customAggrid.style';
1818
import { type GsLangUser, LANG_ENGLISH, LANG_FRENCH } from '../../utils/langs';
@@ -55,7 +55,7 @@ function onColumnResized({ api, column, finished, source }: ColumnResizedEvent)
5555

5656
export const CustomAGGrid = forwardRef<AgGridReact, CustomAGGridProps>(
5757
({ overrideLocales, sx, ...agGridReactProps }, ref) => {
58-
const theme = useTheme<Theme>();
58+
const theme = useTheme();
5959

6060
return (
6161
<Box

src/components/dialogs/customMuiDialog/CustomMuiDialog.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import { CancelButton } from '../../inputs/reactHookForm/utils/CancelButton';
1515
import { CustomFormProvider } from '../../inputs/reactHookForm/provider/CustomFormProvider';
1616
import { PopupConfirmationDialog } from '../popupConfirmationDialog/PopupConfirmationDialog';
1717
import { GsLang } from '../../../utils';
18+
import type { MuiStyles } from '../../../utils/styles';
1819

1920
export type CustomMuiDialogProps<T extends FieldValues = FieldValues> = DialogProps & {
2021
open: boolean;
@@ -42,7 +43,7 @@ const styles = {
4243
margin: 'auto',
4344
},
4445
},
45-
};
46+
} as const satisfies MuiStyles;
4647

4748
/**
4849
* all those styles are made to work with each other in order to control the scroll behavior:
@@ -75,7 +76,7 @@ export const unscrollableDialogStyles = {
7576
overflowY: 'auto',
7677
padding: 1,
7778
},
78-
};
79+
} as const satisfies MuiStyles;
7980

8081
export function CustomMuiDialog<T extends FieldValues = FieldValues>({
8182
open,

0 commit comments

Comments
 (0)