Skip to content

Commit

Permalink
Add text hint for CopyButton
Browse files Browse the repository at this point in the history
  • Loading branch information
untunt committed Dec 14, 2024
1 parent 58639eb commit 375a3d4
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
18 changes: 14 additions & 4 deletions src/Components/Main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -116,10 +116,19 @@ const CopyButton = styled.button`
transition: color 0.2s;
color: #888;
cursor: pointer;
font-size: 0.8em;
font-weight: 400;
display: flex;
align-items: center;
gap: 0.25em;
&:hover,
&:focus {
color: #0078e7;
}
& > div {
font-size: 0.75em;
border-bottom: none;
}
`;
const CloseButton = styled.button`
position: absolute;
Expand Down Expand Up @@ -181,19 +190,19 @@ export default function Main({ evaluateHandlerRef }: { evaluateHandlerRef: Mutab

const [loading, setLoading] = useState(false);

const [copyTooltipText, setCopyTooltipText] = useState("複製到剪貼簿");
const [copyTooltipText, setCopyTooltipText] = useState("全部複製");
const copyEvaluationResult = useCallback(async () => {
const content = ref.current.textContent?.trim();
if (content) {
try {
await navigator.clipboard.writeText(content);
setCopyTooltipText("成功複製到剪貼簿");
setCopyTooltipText("已複製");
} catch {
setCopyTooltipText("無法複製到剪貼簿");
setCopyTooltipText("複製失敗");
}
}
}, []);
const onHideTooltip = useCallback(() => setCopyTooltipText("複製到剪貼簿"), []);
const onHideTooltip = useCallback(() => setCopyTooltipText("全部複製"), []);

// XXX Please Rewrite
useEffect(() => {
Expand Down Expand Up @@ -305,6 +314,7 @@ export default function Main({ evaluateHandlerRef }: { evaluateHandlerRef: Mutab
<TooltipLabel description={copyTooltipText} onHideTooltip={onHideTooltip}>
<CopyButton onClick={copyEvaluationResult}>
<FontAwesomeIcon icon={faCopy} size="sm" />
<div>全部複製</div>
</CopyButton>
</TooltipLabel>
<form method="dialog">
Expand Down
3 changes: 2 additions & 1 deletion src/Components/Tooltip.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ function TooltipAnchor({
outputContainerScrollLeft?: number;
}) {
useEffect(() => {
div.className = tooltipStyle + (fixedWidth ? " " + fixedWidthStyle : "");

const oneRemSize = parseFloat(getComputedStyle(document.documentElement).fontSize);
const margin = oneRemSize / 6;

Expand All @@ -75,7 +77,6 @@ function TooltipAnchor({
targetLeft = Math.min(outputContainerWidth - oneRemSize - divInnerBox.width, Math.max(oneRemSize, targetLeft));
targetLeft += outputContainerScrollLeft;

div.className = tooltipStyle + (fixedWidth ? " " + fixedWidthStyle : "");
div.style.top = targetTop + "px";
div.style.left = targetLeft + "px";
div.style.visibility = "visible";
Expand Down

0 comments on commit 375a3d4

Please sign in to comment.