Skip to content

Commit 4d162af

Browse files
committed
feat(pcc): copy values
1 parent 5a50b9e commit 4d162af

File tree

4 files changed

+39
-0
lines changed

4 files changed

+39
-0
lines changed

apps/paypal-commission-calculator/package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,8 @@
1919
},
2020
"devDependencies": {
2121
"shared": "workspace:*"
22+
},
23+
"dependencies": {
24+
"wc-toast": "1.3.1"
2225
}
2326
}

apps/paypal-commission-calculator/src/app.astro

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,5 +57,6 @@ const body: BodyProps = {
5757
<script src="@/logic/declare-refs.ts"></script>
5858
<script src="@/logic/events.ts"></script>
5959
</Fragment>
60+
<wc-toast></wc-toast>
6061
<slot />
6162
</BaseLayout>

apps/paypal-commission-calculator/src/logic/events.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { toast } from 'wc-toast'
12
import { getParsedValues, getRecieveValues, getSendValues } from './calculator-actions'
23
import { $send, $amount, $receive, $sendCommission, $receiveCommission } from './declare-refs'
34

@@ -8,6 +9,31 @@ function isOnlyNumberOrDot({ key }: KeyboardEvent): boolean {
89
return pattern.test(key)
910
}
1011

12+
document.addEventListener('click', (event: MouseEvent) => {
13+
const target = event.target
14+
15+
if (!(target instanceof Element)) return
16+
17+
const svg = target.closest('svg[id^="copy-btn-"]')
18+
if (svg === null) return
19+
20+
const targetId = svg.id.replace('copy-btn-', '')
21+
const input = document.getElementById(targetId)
22+
23+
if (!(input instanceof HTMLInputElement)) return
24+
25+
void navigator.clipboard
26+
.writeText(input.value)
27+
.then(() => {
28+
toast('Copied value!')
29+
})
30+
.catch((err: unknown) => {
31+
if (err instanceof Error) {
32+
console.error('Error coying:', err.message)
33+
}
34+
})
35+
})
36+
1137
$amount?.addEventListener('input', ({ target }) => {
1238
const { value } = target as HTMLInputElement
1339
const { parsedAmount, parsedFixedCommision, parsedPercentCommision } = getParsedValues(value)

pnpm-lock.yaml

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)