Skip to content

Commit

Permalink
👍 イベントIDのコピーボタンにツールチップを追加
Browse files Browse the repository at this point in the history
  • Loading branch information
haruyuki-16278 committed Feb 25, 2024
1 parent 2048005 commit 003648b
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 3 deletions.
5 changes: 3 additions & 2 deletions islands/CopyToClipboard.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
export default function CopyToClipboard(
props: { body: string },
props: { body: string; tooltipText: string },
) {
const copyToClipboard = async () => {
await navigator.clipboard.writeText(props.body);
};
return (
<button
class="w-8 h-8 grid place-content-center fill-gray-500"
class="w-8 h-8 grid place-content-center fill-gray-500 tooltip"
data-tooltip={props.tooltipText}
onClick={copyToClipboard}
>
<svg
Expand Down
5 changes: 4 additions & 1 deletion routes/event/[hash].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,10 @@ export default function Event(event: PageProps<EventItem>) {
<section>
<h2 class="ev-title flex">
{item.title}
<CopyToClipboard body={item.hash} />
<CopyToClipboard
body={item.hash}
tooltipText="イベントIDをコピー"
/>
</h2>
<img
class="w-full h-fit object-cover object-center bg-gray-300"
Expand Down
16 changes: 16 additions & 0 deletions static/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,22 @@
@tailwind components;
@tailwind utilities;

@layer base {
.tooltip {
@apply relative;
}
.tooltip::before {
@apply content-[attr(data-tooltip)] absolute whitespace-nowrap bg-gray-700 text-center py-1 px-2 z-10 opacity-0 transition-opacity -top-8 left-0 rounded-md text-xs invisible text-white
}
.tooltip::after {
@apply content-[""] absolute -top-2 left-1/2 border-8 border-solid opacity-0 transition-opacity border-transparent border-t-gray-700 invisible
}

.tooltip:hover::before, .tooltip:hover::after {
@apply opacity-100 visible
}
}

@layer components {
.ev-button {
@apply w-fit mx-auto border-solid border-2 border-orange-500 px-4 py-2 rounded-full bg-white font-bold text-orange-500 transition-colors
Expand Down

0 comments on commit 003648b

Please sign in to comment.