-
Notifications
You must be signed in to change notification settings - Fork 887
fix: improve click UX and styling for Auth Token page #11863
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 25 commits
7e4d964
ece3f6d
bf6e73a
697bdf0
9b881c0
ccdca08
a7c7cc7
163db92
38b80a8
92f94d7
e0e5e6f
0ca1558
88b96df
15feb14
e3feffc
3ec5196
cf2d179
98bd1af
400e07c
3307432
f10134f
c4469f3
d8b6727
6157049
89c74da
b95cfd6
4ab6326
778560f
cf53114
97fed6f
83febe2
fb0f4b7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ import IconButton from "@mui/material/Button"; | |
import Tooltip from "@mui/material/Tooltip"; | ||
import Check from "@mui/icons-material/Check"; | ||
import { css, type Interpolation, type Theme } from "@emotion/react"; | ||
import { type FC, type ReactNode } from "react"; | ||
import { forwardRef, type MouseEventHandler, type ReactNode } from "react"; | ||
import { useClipboard } from "hooks/useClipboard"; | ||
import { FileCopyIcon } from "../Icons/FileCopyIcon"; | ||
|
||
|
@@ -13,6 +13,7 @@ interface CopyButtonProps { | |
wrapperStyles?: Interpolation<Theme>; | ||
buttonStyles?: Interpolation<Theme>; | ||
tooltipTitle?: string; | ||
onClick?: MouseEventHandler; | ||
} | ||
|
||
export const Language = { | ||
|
@@ -23,36 +24,44 @@ export const Language = { | |
/** | ||
* Copy button used inside the CodeBlock component internally | ||
*/ | ||
export const CopyButton: FC<CopyButtonProps> = ({ | ||
text, | ||
ctaCopy, | ||
wrapperStyles, | ||
buttonStyles, | ||
tooltipTitle = Language.tooltipTitle, | ||
}) => { | ||
const { isCopied, copy: copyToClipboard } = useClipboard(text); | ||
export const CopyButton = forwardRef<HTMLButtonElement, CopyButtonProps>( | ||
(props, ref) => { | ||
const { | ||
text, | ||
ctaCopy, | ||
wrapperStyles, | ||
buttonStyles, | ||
onClick: outsideOnClick, | ||
tooltipTitle = Language.tooltipTitle, | ||
} = props; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Generally try to keep prop definitions inlined, but Prettier's auto-formatting made the code super ugly to look at |
||
const { isCopied, copyToClipboard } = useClipboard(text); | ||
|
||
return ( | ||
<Tooltip title={tooltipTitle} placement="top"> | ||
<div css={[{ display: "flex" }, wrapperStyles]}> | ||
<IconButton | ||
css={[styles.button, buttonStyles]} | ||
onClick={copyToClipboard} | ||
size="small" | ||
aria-label={Language.ariaLabel} | ||
variant="text" | ||
> | ||
{isCopied ? ( | ||
<Check css={styles.copyIcon} /> | ||
) : ( | ||
<FileCopyIcon css={styles.copyIcon} /> | ||
)} | ||
{ctaCopy && <div css={{ marginLeft: 8 }}>{ctaCopy}</div>} | ||
</IconButton> | ||
</div> | ||
</Tooltip> | ||
); | ||
}; | ||
return ( | ||
<Tooltip title={tooltipTitle} placement="top"> | ||
<div css={[{ display: "flex" }, wrapperStyles]}> | ||
<IconButton | ||
ref={ref} | ||
css={[styles.button, buttonStyles]} | ||
size="small" | ||
aria-label={Language.ariaLabel} | ||
variant="text" | ||
onClick={(event) => { | ||
void copyToClipboard(); | ||
outsideOnClick?.(event); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why do we need this? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. More just for flexibility. It might be because I've been in a Backstage mindset, where we need a lot more API flexibility, but my thinking was this would let someone attach an There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In the Coder app context + this component context, what would be a common use case for this? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For this context, it is over-engineering, yeah. I'll remove it |
||
}} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is the only major change for the component. The rest of the diff is just from the |
||
> | ||
{isCopied ? ( | ||
<Check css={styles.copyIcon} /> | ||
) : ( | ||
<FileCopyIcon css={styles.copyIcon} /> | ||
)} | ||
{ctaCopy && <div css={{ marginLeft: 8 }}>{ctaCopy}</div>} | ||
</IconButton> | ||
</div> | ||
</Tooltip> | ||
); | ||
}, | ||
); | ||
|
||
const styles = { | ||
button: (theme) => css` | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's always good to share screenshots and demos when making UI changes or features. Some design improvements I see we can make:
