2022-10-19 14:32:37 +02:00
|
|
|
---
|
|
|
|
title: "ADR: preferred styling method"
|
|
|
|
---
|
|
|
|
|
2024-02-09 17:50:08 +01:00
|
|
|
This document supersedes [ADR: preferred styles import placement](./deprecated/preferred-styles-import-placement.md)
|
2022-10-19 14:32:37 +02:00
|
|
|
|
|
|
|
|
|
|
|
## Background
|
|
|
|
|
|
|
|
In the codebase, we need to have a uniform way of performing style updates.
|
|
|
|
|
|
|
|
## Decision
|
|
|
|
|
|
|
|
We have decided to move away from using makeStyles as it's currently deprecated from @material/ui, and kept alive with an
|
|
|
|
external interop package to maintain compatability with the latest version. The preferred path forward is to use styled components which is
|
|
|
|
supported natively in @material/ui and sparingly use the sx prop available on all mui components.
|
2023-01-03 14:52:10 +01:00
|
|
|
|
|
|
|
### Consequences: code sharing
|
|
|
|
|
|
|
|
With makeStyles it was common to reuse CSS fragments via library utilities.
|
|
|
|
In the styled components approach we use themeable functions and object literals
|
|
|
|
|
|
|
|
```ts
|
|
|
|
import { Theme } from '@mui/material';
|
|
|
|
|
|
|
|
export const focusable = (theme: Theme) => ({
|
|
|
|
color: theme.palette.primary.main,
|
|
|
|
});
|
|
|
|
|
|
|
|
export const flexRow = {
|
|
|
|
display: 'flex',
|
|
|
|
alignItems: 'center',
|
|
|
|
};
|
|
|
|
```
|
|
|
|
|
|
|
|
Usage:
|
|
|
|
```ts
|
|
|
|
const StyledLink = styled(Link)(({ theme }) => ({
|
|
|
|
...focusable(theme),
|
|
|
|
}));
|
|
|
|
|
|
|
|
<IconButton sx={focusable}/>
|
|
|
|
```
|