Skip to content

Commit ec9d32e

Browse files
committed
port a couple more!
1 parent d34e687 commit ec9d32e

File tree

2 files changed

+60
-66
lines changed

2 files changed

+60
-66
lines changed

site/src/components/Avatar/Avatar.tsx

Lines changed: 43 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,58 @@
11
// This is the only place MuiAvatar can be used
22
// eslint-disable-next-line no-restricted-imports -- Read above
33
import MuiAvatar, { AvatarProps as MuiAvatarProps } from "@mui/material/Avatar";
4-
import { makeStyles } from "@mui/styles";
54
import { FC } from "react";
6-
import { combineClasses } from "utils/combineClasses";
5+
import { css, type Theme } from "@emotion/react";
76

87
export type AvatarProps = MuiAvatarProps & {
98
size?: "sm" | "md" | "xl";
109
colorScheme?: "light" | "darken";
1110
fitImage?: boolean;
1211
};
1312

13+
const sizeStyles = {
14+
sm: (theme: Theme) => ({
15+
width: theme.spacing(3),
16+
height: theme.spacing(3),
17+
fontSize: theme.spacing(1.5),
18+
}),
19+
md: {},
20+
xl: (theme: Theme) => ({
21+
width: theme.spacing(6),
22+
height: theme.spacing(6),
23+
fontSize: theme.spacing(3),
24+
}),
25+
};
26+
27+
const colorStyles = {
28+
light: {},
29+
darken: (theme: Theme) => ({
30+
background: theme.palette.divider,
31+
color: theme.palette.text.primary,
32+
}),
33+
};
34+
35+
const fitImageStyles = css`
36+
& .MuiAvatar-img {
37+
object-fit: contain;
38+
}
39+
`;
40+
1441
export const Avatar: FC<AvatarProps> = ({
1542
size = "md",
1643
colorScheme = "light",
1744
fitImage,
18-
className,
1945
children,
2046
...muiProps
2147
}) => {
22-
const styles = useStyles();
23-
2448
return (
2549
<MuiAvatar
2650
{...muiProps}
27-
className={combineClasses([
28-
className,
29-
styles[size],
30-
styles[colorScheme],
31-
fitImage && styles.fitImage,
32-
])}
51+
css={[
52+
sizeStyles[size],
53+
colorStyles[colorScheme],
54+
fitImage && fitImageStyles,
55+
]}
3356
>
3457
{typeof children === "string" ? firstLetter(children) : children}
3558
</MuiAvatar>
@@ -40,8 +63,15 @@ export const Avatar: FC<AvatarProps> = ({
4063
* Use it to make an img element behaves like a MaterialUI Icon component
4164
*/
4265
export const AvatarIcon: FC<{ src: string }> = ({ src }) => {
43-
const styles = useStyles();
44-
return <img src={src} alt="" className={styles.avatarIcon} />;
66+
return (
67+
<img
68+
src={src}
69+
alt=""
70+
css={{
71+
maxWidth: "50%",
72+
}}
73+
/>
74+
);
4575
};
4676

4777
const firstLetter = (str: string): string => {
@@ -51,36 +81,3 @@ const firstLetter = (str: string): string => {
5181

5282
return "";
5383
};
54-
55-
const useStyles = makeStyles((theme) => ({
56-
// Size styles
57-
sm: {
58-
width: theme.spacing(3),
59-
height: theme.spacing(3),
60-
fontSize: theme.spacing(1.5),
61-
},
62-
// Just use the default value from theme
63-
md: {},
64-
xl: {
65-
width: theme.spacing(6),
66-
height: theme.spacing(6),
67-
fontSize: theme.spacing(3),
68-
},
69-
// Colors
70-
// Just use the default value from theme
71-
light: {},
72-
darken: {
73-
background: theme.palette.divider,
74-
color: theme.palette.text.primary,
75-
},
76-
// Avatar icon
77-
avatarIcon: {
78-
maxWidth: "50%",
79-
},
80-
// Fit image
81-
fitImage: {
82-
"& .MuiAvatar-img": {
83-
objectFit: "contain",
84-
},
85-
},
86-
}));

site/src/pages/UserSettingsPage/TokensPage/TokensPage.tsx

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,26 @@
11
import { FC, PropsWithChildren, useState } from "react";
22
import { Section } from "components/SettingsLayout/Section";
33
import { TokensPageView } from "./TokensPageView";
4-
import makeStyles from "@mui/styles/makeStyles";
54
import { useTokensData } from "./hooks";
65
import { ConfirmDeleteDialog } from "./ConfirmDeleteDialog";
76
import { Stack } from "components/Stack/Stack";
87
import Button from "@mui/material/Button";
98
import { Link as RouterLink } from "react-router-dom";
109
import AddIcon from "@mui/icons-material/AddOutlined";
1110
import { APIKeyWithOwner } from "api/typesGenerated";
11+
import { css } from "@emotion/react";
1212

1313
export const TokensPage: FC<PropsWithChildren<unknown>> = () => {
14-
const styles = useStyles();
15-
1614
const cliCreateCommand = "coder tokens create";
1715

1816
const TokenActions = () => (
19-
<Stack direction="row" justifyContent="end" className={styles.tokenActions}>
17+
<Stack
18+
direction="row"
19+
justifyContent="end"
20+
css={(theme) => ({
21+
marginBottom: theme.spacing(1),
22+
})}
23+
>
2024
<Button startIcon={<AddIcon />} component={RouterLink} to="new">
2125
Add token
2226
</Button>
@@ -43,7 +47,15 @@ export const TokensPage: FC<PropsWithChildren<unknown>> = () => {
4347
<>
4448
<Section
4549
title="Tokens"
46-
className={styles.section}
50+
css={(theme) => css`
51+
& code {
52+
background: ${theme.palette.divider};
53+
fontsize: 12px;
54+
padding: 2px 4px;
55+
color: ${theme.palette.text.primary};
56+
borderradius: 2px;
57+
}
58+
`}
4759
description={
4860
<>
4961
Tokens are used to authenticate with the Coder API. You can create a
@@ -73,19 +85,4 @@ export const TokensPage: FC<PropsWithChildren<unknown>> = () => {
7385
);
7486
};
7587

76-
const useStyles = makeStyles((theme) => ({
77-
section: {
78-
"& code": {
79-
background: theme.palette.divider,
80-
fontSize: 12,
81-
padding: "2px 4px",
82-
color: theme.palette.text.primary,
83-
borderRadius: 2,
84-
},
85-
},
86-
tokenActions: {
87-
marginBottom: theme.spacing(1),
88-
},
89-
}));
90-
9188
export default TokensPage;

0 commit comments

Comments
 (0)