Skip to content

Commit dbe1c0c

Browse files
committed
emotion: AuditLogDiff
1 parent 4ffc84a commit dbe1c0c

File tree

1 file changed

+30
-42
lines changed

1 file changed

+30
-42
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
import { makeStyles } from "@mui/styles";
2-
import { AuditLog } from "api/typesGenerated";
1+
import { type Interpolation, type Theme } from "@emotion/react";
2+
import { type FC } from "react";
3+
import type { AuditLog } from "api/typesGenerated";
34
import { colors } from "theme/colors";
45
import { MONOSPACE_FONT_FAMILY } from "theme/constants";
5-
import { combineClasses } from "utils/combineClasses";
6-
import { FC } from "react";
76

87
const getDiffValue = (value: unknown): string => {
98
if (typeof value === "string") {
@@ -23,43 +22,32 @@ const getDiffValue = (value: unknown): string => {
2322
};
2423

2524
export const AuditLogDiff: FC<{ diff: AuditLog["diff"] }> = ({ diff }) => {
26-
const styles = useStyles();
2725
const diffEntries = Object.entries(diff);
2826

2927
return (
30-
<div className={styles.diff}>
31-
<div className={combineClasses([styles.diffColumn, styles.diffOld])}>
28+
<div css={styles.diff}>
29+
<div css={[styles.diffColumn, styles.diffOld]}>
3230
{diffEntries.map(([attrName, valueDiff], index) => (
33-
<div key={attrName} className={styles.diffRow}>
34-
<div className={styles.diffLine}>{index + 1}</div>
35-
<div className={styles.diffIcon}>-</div>
31+
<div key={attrName} css={styles.diffRow}>
32+
<div css={styles.diffLine}>{index + 1}</div>
33+
<div css={styles.diffIcon}>-</div>
3634
<div>
3735
{attrName}:{" "}
38-
<span
39-
className={combineClasses([
40-
styles.diffValue,
41-
styles.diffValueOld,
42-
])}
43-
>
36+
<span css={[styles.diffValue, styles.diffValueOld]}>
4437
{valueDiff.secret ? "••••••••" : getDiffValue(valueDiff.old)}
4538
</span>
4639
</div>
4740
</div>
4841
))}
4942
</div>
50-
<div className={combineClasses([styles.diffColumn, styles.diffNew])}>
43+
<div css={[styles.diffColumn, styles.diffNew]}>
5144
{diffEntries.map(([attrName, valueDiff], index) => (
52-
<div key={attrName} className={styles.diffRow}>
53-
<div className={styles.diffLine}>{index + 1}</div>
54-
<div className={styles.diffIcon}>+</div>
45+
<div key={attrName} css={styles.diffRow}>
46+
<div css={styles.diffLine}>{index + 1}</div>
47+
<div css={styles.diffIcon}>+</div>
5548
<div>
5649
{attrName}:{" "}
57-
<span
58-
className={combineClasses([
59-
styles.diffValue,
60-
styles.diffValueNew,
61-
])}
62-
>
50+
<span css={[styles.diffValue, styles.diffValueNew]}>
6351
{valueDiff.secret ? "••••••••" : getDiffValue(valueDiff.new)}
6452
</span>
6553
</div>
@@ -70,60 +58,60 @@ export const AuditLogDiff: FC<{ diff: AuditLog["diff"] }> = ({ diff }) => {
7058
);
7159
};
7260

73-
const useStyles = makeStyles((theme) => ({
74-
diff: {
61+
const styles = {
62+
diff: (theme) => ({
7563
display: "flex",
7664
alignItems: "flex-start",
7765
fontSize: theme.typography.body2.fontSize,
7866
borderTop: `1px solid ${theme.palette.divider}`,
7967
fontFamily: MONOSPACE_FONT_FAMILY,
8068
position: "relative",
8169
zIndex: 2,
82-
},
70+
}),
8371

84-
diffColumn: {
72+
diffColumn: (theme) => ({
8573
flex: 1,
8674
paddingTop: theme.spacing(2),
8775
paddingBottom: theme.spacing(2.5),
8876
paddingRight: theme.spacing(2),
8977
lineHeight: "160%",
9078
alignSelf: "stretch",
9179
overflowWrap: "anywhere",
92-
},
80+
}),
9381

94-
diffOld: {
82+
diffOld: (theme) => ({
9583
backgroundColor: theme.palette.error.dark,
9684
color: theme.palette.error.contrastText,
97-
},
85+
}),
9886

9987
diffRow: {
10088
display: "flex",
10189
alignItems: "baseline",
10290
},
10391

104-
diffLine: {
92+
diffLine: (theme) => ({
10593
opacity: 0.5,
10694
width: theme.spacing(6),
10795
textAlign: "right",
10896
flexShrink: 0,
109-
},
97+
}),
11098

111-
diffIcon: {
99+
diffIcon: (theme) => ({
112100
width: theme.spacing(4),
113101
textAlign: "center",
114102
fontSize: theme.typography.body1.fontSize,
115103
flexShrink: 0,
116-
},
104+
}),
117105

118-
diffNew: {
106+
diffNew: (theme) => ({
119107
backgroundColor: theme.palette.success.dark,
120108
color: theme.palette.success.contrastText,
121-
},
109+
}),
122110

123-
diffValue: {
111+
diffValue: (theme) => ({
124112
padding: 1,
125113
borderRadius: theme.shape.borderRadius / 2,
126-
},
114+
}),
127115

128116
diffValueOld: {
129117
backgroundColor: colors.red[12],
@@ -132,4 +120,4 @@ const useStyles = makeStyles((theme) => ({
132120
diffValueNew: {
133121
backgroundColor: colors.green[12],
134122
},
135-
}));
123+
} satisfies Record<string, Interpolation<Theme>>;

0 commit comments

Comments
 (0)