Skip to content

Commit 781b73f

Browse files
committed
emotion: CodeExample
1 parent 4df5c1d commit 781b73f

File tree

1 file changed

+33
-41
lines changed

1 file changed

+33
-41
lines changed
Lines changed: 33 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
1-
import { makeStyles } from "@mui/styles";
2-
import { FC } from "react";
1+
import { type FC } from "react";
2+
import { useTheme } from "@emotion/react";
33
import { MONOSPACE_FONT_FAMILY } from "theme/constants";
4-
import { combineClasses } from "utils/combineClasses";
54
import { CopyButton } from "../CopyButton/CopyButton";
6-
import { Theme } from "@mui/material/styles";
75

86
export interface CodeExampleProps {
97
code: string;
@@ -14,46 +12,40 @@ export interface CodeExampleProps {
1412
/**
1513
* Component to show single-line code examples, with a copy button
1614
*/
17-
export const CodeExample: FC<CodeExampleProps> = ({
18-
code,
19-
password,
20-
className,
21-
}) => {
22-
const styles = useStyles({ password });
15+
export const CodeExample: FC<CodeExampleProps> = (props) => {
16+
const { code, password, className } = props;
17+
const theme = useTheme();
2318

2419
return (
25-
<div className={combineClasses([styles.root, className])}>
26-
<code className={styles.code}>{code}</code>
20+
<div
21+
css={{
22+
display: "flex",
23+
flexDirection: "row",
24+
alignItems: "center",
25+
background: "rgb(0 0 0 / 30%)",
26+
color: theme.palette.primary.contrastText,
27+
fontFamily: MONOSPACE_FONT_FAMILY,
28+
fontSize: 14,
29+
borderRadius: theme.shape.borderRadius,
30+
padding: theme.spacing(1),
31+
lineHeight: "150%",
32+
border: `1px solid ${theme.palette.divider}`,
33+
}}
34+
className={className}
35+
>
36+
<code
37+
css={{
38+
padding: theme.spacing(0, 1),
39+
width: "100%",
40+
display: "flex",
41+
alignItems: "center",
42+
wordBreak: "break-all",
43+
"-webkit-text-security": password ? "disc" : undefined,
44+
}}
45+
>
46+
{code}
47+
</code>
2748
<CopyButton text={code} />
2849
</div>
2950
);
3051
};
31-
32-
interface styleProps {
33-
inline?: boolean;
34-
password?: boolean;
35-
}
36-
37-
const useStyles = makeStyles<Theme, styleProps>((theme) => ({
38-
root: (props) => ({
39-
display: props.inline ? "inline-flex" : "flex",
40-
flexDirection: "row",
41-
alignItems: "center",
42-
background: "rgb(0 0 0 / 30%)",
43-
color: theme.palette.primary.contrastText,
44-
fontFamily: MONOSPACE_FONT_FAMILY,
45-
fontSize: 14,
46-
borderRadius: theme.shape.borderRadius,
47-
padding: theme.spacing(1),
48-
lineHeight: "150%",
49-
border: `1px solid ${theme.palette.divider}`,
50-
}),
51-
code: {
52-
padding: theme.spacing(0, 1),
53-
width: "100%",
54-
display: "flex",
55-
alignItems: "center",
56-
wordBreak: "break-all",
57-
"-webkit-text-security": (props) => (props.password ? "disc" : undefined),
58-
},
59-
}));

0 commit comments

Comments
 (0)