Skip to content

Commit e175c95

Browse files
add copy icon, keep hover neutral
1 parent cd0d64b commit e175c95

2 files changed

Lines changed: 42 additions & 2 deletions

File tree

src/components/InstallCommand/index.js

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,31 @@ const UNIX_COMMAND =
1010
const WINDOWS_COMMAND =
1111
'powershell -c "irm https://github.com/php-debugger/installer/releases/latest/download/install.ps1 | iex"';
1212

13+
const iconProps = {
14+
width: 15,
15+
height: 15,
16+
viewBox: '0 0 24 24',
17+
fill: 'none',
18+
stroke: 'currentColor',
19+
strokeWidth: 2,
20+
strokeLinecap: 'round',
21+
strokeLinejoin: 'round',
22+
'aria-hidden': true,
23+
};
24+
25+
const CopyIcon = () => (
26+
<svg {...iconProps}>
27+
<rect x="9" y="9" width="11" height="11" rx="2" />
28+
<path d="M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1" />
29+
</svg>
30+
);
31+
32+
const CheckIcon = () => (
33+
<svg {...iconProps}>
34+
<path d="M20 6 9 17l-5-5" />
35+
</svg>
36+
);
37+
1338
const PLATFORMS = [
1439
{id: 'macos', label: 'macOS', language: 'bash', command: UNIX_COMMAND},
1540
{id: 'linux', label: 'Linux', language: 'bash', command: UNIX_COMMAND},
@@ -74,7 +99,8 @@ export default function InstallCommand() {
7499
return ok;
75100
}
76101

77-
async function copy() {
102+
async function copy(event) {
103+
event.currentTarget.blur();
78104
let ok = false;
79105
try {
80106
await navigator.clipboard.writeText(active.command);
@@ -111,9 +137,10 @@ export default function InstallCommand() {
111137
</div>
112138
<button
113139
type="button"
114-
className={styles.copy}
140+
className={clsx(styles.copy, copied && styles.copied)}
115141
onClick={copy}
116142
aria-label={`Copy the ${active.label} install command`}>
143+
{copied ? <CheckIcon /> : <CopyIcon />}
117144
{copied ? 'Copied' : 'Copy'}
118145
</button>
119146
</div>

src/components/InstallCommand/styles.module.css

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@
3939
}
4040

4141
.copy {
42+
display: inline-flex;
43+
align-items: center;
44+
gap: 0.4rem;
4245
border: 1px solid var(--phpdbg-card-border);
4346
background: transparent;
4447
color: var(--ifm-color-emphasis-700);
@@ -50,7 +53,17 @@
5053
flex-shrink: 0;
5154
}
5255

56+
/* Hover stays deliberately neutral. The brand red is what the tabs beside this
57+
button use to mean "selected", so an accented Copy button reads as still being
58+
active -- which is exactly how it looked after a click, with the pointer still
59+
resting on it. The accent is reserved for the moment the copy succeeds. */
5360
.copy:hover {
61+
border-color: var(--ifm-color-emphasis-400);
62+
color: var(--ifm-color-emphasis-800);
63+
}
64+
65+
.copied,
66+
.copied:hover {
5467
border-color: var(--ifm-color-primary);
5568
color: var(--ifm-color-primary);
5669
}

0 commit comments

Comments
 (0)