Skip to content

Commit c3c60b0

Browse files
committed
Show toolbar to copy, paste and delete input
1 parent 38d3fe1 commit c3c60b0

File tree

5 files changed

+76
-6
lines changed

5 files changed

+76
-6
lines changed

src/components/IconSpan/index.tsx

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import styles from "./styles.module.css";
2+
import cn from "classnames";
3+
4+
export default function IconSpan({
5+
icon,
6+
hover, // means the parent is hovered
7+
onClick,
8+
}: {
9+
icon: React.ReactNode;
10+
hover: boolean;
11+
onClick: () => void;
12+
}) {
13+
return (
14+
<span
15+
onClick={onClick}
16+
className={cn(styles.iconSpan, hover && styles.hover)}
17+
>
18+
{icon}
19+
</span>
20+
);
21+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
.iconSpan {
2+
cursor: pointer;
3+
padding-inline: 2px;
4+
border-radius: 3px;
5+
opacity: 0;
6+
transition: opacity 0.1s, background-color 0.1s;
7+
}
8+
9+
.hover {
10+
opacity: 1;
11+
}
12+
13+
.iconSpan:hover {
14+
background-color: #003705;
15+
}

src/components/Text.tsx

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { useEffect, useState } from "react";
22
import TextField from "@mui/material/TextField";
33
import Decimal from "decimal.js";
4+
import IconSpan from "./IconSpan";
45

56
export default function Text({
67
label,
@@ -16,6 +17,7 @@ export default function Text({
1617
error: boolean;
1718
}) {
1819
const [stringValue, setStringValue] = useState<string>("");
20+
const [hover, setHover] = useState<boolean>(false);
1921

2022
useEffect(() => {
2123
if (value === undefined) setStringValue("");
@@ -36,11 +38,38 @@ export default function Text({
3638
} else onChange(undefined);
3739
}, [onChange, stringValue]);
3840

41+
const helperText = (
42+
<>
43+
{label}{" "}
44+
<IconSpan
45+
icon="📋"
46+
hover={hover}
47+
onClick={
48+
() =>
49+
navigator.clipboard
50+
.readText()
51+
.then((text) => setStringValue(text))
52+
.catch(() => {}) // Ignore error
53+
}
54+
/>{" "}
55+
<IconSpan
56+
icon="📑"
57+
hover={hover}
58+
onClick={
59+
() => navigator.clipboard.writeText(stringValue).catch(() => {}) // Ignore error
60+
}
61+
/>{" "}
62+
<IconSpan icon="❌" hover={hover} onClick={() => setStringValue("")} />
63+
</>
64+
);
65+
3966
return (
4067
<TextField
68+
onPointerEnter={() => setHover(true)}
69+
onPointerLeave={() => setHover(false)}
4170
error={error}
42-
helperText={label}
43-
sx={xs ? { maxWidth: 130 } : undefined}
71+
helperText={helperText}
72+
sx={xs ? { maxWidth: 140 } : undefined}
4473
variant="outlined"
4574
value={stringValue}
4675
onChange={(e) => setStringValue(e.target.value)}

src/index.css

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,18 @@
11
body {
22
margin: 0;
3-
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen',
4-
'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue',
3+
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Roboto", "Oxygen",
4+
"Ubuntu", "Cantarell", "Fira Sans", "Droid Sans", "Helvetica Neue",
55
sans-serif;
66
-webkit-font-smoothing: antialiased;
77
-moz-osx-font-smoothing: grayscale;
88
}
99

1010
code {
11-
font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New',
11+
font-family: source-code-pro, Menlo, Monaco, Consolas, "Courier New",
1212
monospace;
1313
}
14+
15+
.MuiFormHelperText-root {
16+
margin-left: 0px !important;
17+
margin-right: 0px !important;
18+
}

src/positions/LongPosition.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ export default function LongPosition() {
108108
error={error.rewardPercent}
109109
/>
110110
<Text
111-
label="Reward Amount"
111+
label="Reward Amt" // "Reward Amount"
112112
xs
113113
value={rewardAmount}
114114
onChange={setRewardAmount}

0 commit comments

Comments
 (0)