Skip to content

Commit

Permalink
Add ability to copy age to clipboard
Browse files Browse the repository at this point in the history
  • Loading branch information
adipascu committed Oct 12, 2023
1 parent 096ada0 commit a2ad5d9
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
"@fontsource/sen": "^5.0.15",
"solid-icons": "^1.0.12",
"solid-js": "^1.8.1",
"solid-toast": "^0.5.0",
"temporal-polyfill": "^0.1.1"
},
"license": "MIT",
Expand Down
11 changes: 11 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 16 additions & 1 deletion src/Countdown.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { createSignal, onCleanup } from "solid-js";
import { Temporal } from "temporal-polyfill";
import { IoSettingsSharp } from "solid-icons/io";
import toast, { Toaster } from "solid-toast";
import FONT_FAMILY from "./font";
import { GIT_HASH } from "./config";
import { calculateAgeLocal } from "./calculate-age";
Expand Down Expand Up @@ -34,6 +35,15 @@ export default ({
const largeAge = () => Math.floor(age()).toString();
const smallAge = () => age().toFixed(11).split(".")[1];

const copyAgeToClipboard = async () => {
const ageString = `${largeAge()}.${smallAge()}`;
try {
await navigator.clipboard.writeText(ageString);
toast.success("Age copied to clipboard!");
} catch (err) {
toast.error("Failed to copy age to clipboard!");
}
};
return (
<div
style={{
Expand All @@ -43,6 +53,7 @@ export default ({
"background-color": colorBackground(),
}}
>
<Toaster position="top-center" />
<div
style={{
display: "flex",
Expand All @@ -64,7 +75,7 @@ export default ({
}}
title={`Birthday: ${birthDay.toLocaleString()}`}
>
<div>Age</div>
<div onClick={copyAgeToClipboard}>Age</div>
<IoSettingsSharp
fill={colorSecondary()}
style={{
Expand All @@ -80,13 +91,17 @@ export default ({
/>
</div>
<div
onClick={copyAgeToClipboard}
title="Click to copy age to clipboard"
style={{
display: "flex",
"flex-direction": "row",
"font-family": FONT_FAMILY,
"font-size": "96px",
"font-weight": "bold",
"line-height": "0.85",
"user-select": "none",
cursor: "text",
overflow: "hidden",
color: colorPrimary(),
}}
Expand Down

0 comments on commit a2ad5d9

Please sign in to comment.