Skip to content

Commit e8cf6a0

Browse files
committed
add toast to copied action
1 parent 698f1bb commit e8cf6a0

File tree

3 files changed

+29
-2
lines changed

3 files changed

+29
-2
lines changed

www/js/main.js

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import {tint} from '../../dist/index.mjs'
22
import {copyToClipboard} from './copy.js'
3+
import Toastify from 'toastify-js'
4+
import 'toastify-js/src/toastify.css'
35

46
function generateShades(color) {
57
const darker = []
@@ -13,7 +15,6 @@ function generateShades(color) {
1315

1416
const tinter = tint(color)
1517

16-
// lighter colors
1718
for (let i = 1; ; ) {
1819
const _color = tinter(i * 5)
1920
lighter.push('#' + _color)
@@ -25,7 +26,6 @@ function generateShades(color) {
2526
i += 1
2627
}
2728

28-
// darker colors
2929
for (let i = 1; ; ) {
3030
const per = -(i * 5)
3131
const nextPer = -((i + 1) * 5)
@@ -58,9 +58,25 @@ function createColorCard(color, ping) {
5858
'hover:scale-110',
5959
],
6060
)
61+
6162
div.style.backgroundColor = color
63+
6264
div.addEventListener('click', () => {
6365
copyToClipboard(color)
66+
Toastify({
67+
text: `Copied ${color}`,
68+
duration: 3000,
69+
newWindow: true,
70+
close: true,
71+
gravity: 'top',
72+
position: 'right',
73+
style: {
74+
border: '2px solid var(--accent)',
75+
background: 'var(--base)',
76+
color: 'var(--accent)',
77+
'box-shadow': 'none',
78+
},
79+
}).showToast()
6480
})
6581

6682
const colorLabel = createColorLabel(color)

www/package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,8 @@
1010
"parcel": "^2.6.0",
1111
"postcss": "^8.4.14",
1212
"tailwindcss": "^3.0.24"
13+
},
14+
"dependencies": {
15+
"toastify-js": "^1.11.2"
1316
}
1417
}

www/pnpm-lock.yaml

Lines changed: 8 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)