Skip to content

Commit

Permalink
feat: show toast after copy to clipboard
Browse files Browse the repository at this point in the history
  • Loading branch information
lxchapu committed May 20, 2024
1 parent a352aca commit 6aadea0
Show file tree
Hide file tree
Showing 10 changed files with 61 additions and 6 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
"qrcode.react": "^3.1.0",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-toastify": "^10.0.5",
"reading-time": "^1.5.0",
"remark-directive": "^3.0.0",
"tailwindcss": "^3.4.3",
Expand Down
14 changes: 14 additions & 0 deletions pnpm-lock.yaml

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

Binary file modified public/fonts/iconfont.ttf
Binary file not shown.
Binary file modified public/fonts/iconfont.woff
Binary file not shown.
Binary file modified public/fonts/iconfont.woff2
Binary file not shown.
14 changes: 14 additions & 0 deletions src/components/ToastContainer.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { ToastContainer as ReactToastContainer } from 'react-toastify'
import 'react-toastify/dist/ReactToastify.css';

export function ToastContainer() {
return <ReactToastContainer position='bottom-right' autoClose={3000} hideProgressBar closeButton={CloseButton}
toastClassName="!bg-primary !text-primary text-sm border border-primary"
/>
}

function CloseButton({ closeToast }: { closeToast: (event: React.MouseEvent<HTMLElement>) => void }) {
return <button type="button" aria-label='Close Toast' className='text-lg opacity-50 hover:opacity-100' onClick={closeToast}>
<i className='iconfont icon-close'></i>
</button>
}
2 changes: 2 additions & 0 deletions src/components/post/ActionAside.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import * as QR from 'qrcode.react'
import { useAtomValue } from 'jotai'
import { metaSlugAtom, metaTitleAtom } from '@/store/metaInfo'
import clsx from 'clsx'
import { toast } from 'react-toastify'

const contentZIndex = 900
const overlayZIndex = contentZIndex - 1
Expand All @@ -30,6 +31,7 @@ const shareList = [
icon: 'icon-link',
onClick: (data: ShareData) => {
navigator.clipboard.writeText(data.url)
toast.success('已复制到剪贴板')
},
},
]
Expand Down
2 changes: 2 additions & 0 deletions src/components/post/PostCopyright.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { author, site } from '@/config.json'
import { getFormattedDateTime } from '@/utils/date'
import { AnimatedSignature } from '../AnimatedSignature'
import { useEffect, useState } from 'react'
import { toast } from "react-toastify";

function getPostUrl(slug: string) {
return new URL(slug, site.url).href
Expand All @@ -21,6 +22,7 @@ export function PostCopyright({

function handleCopyUrl() {
navigator.clipboard.writeText(url)
toast.success('已复制文章链接')
}

useEffect(() => {
Expand Down
5 changes: 3 additions & 2 deletions src/layouts/Layout.astro
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import ThemeLoader from '@/components/ThemeLoader.astro'
import { ViewTransitions } from 'astro:transitions'
import { site } from '@/config.json'
import '@/styles/global.css'
import { ToastContainer } from '@/components/ToastContainer'
interface Props {
title?: string
Expand All @@ -24,15 +25,15 @@ const { title, description, image } = Astro.props
<AccentColorInjector />
<script>
import { version } from '../../package.json'

console.log(
`%c Gyoza ${version} %c https://gyoza.lxchapu.com `,
'color: #fff; margin: 1em 0; padding: 5px 0; background: #ef8f99;',
'margin: 1em 0; padding: 5px 0; background: #efefef;',
'margin: 1em 0; padding: 5px 0; background: #efefef;'
)
</script>
</head>
<body>
<slot />
<ToastContainer client:only="react" />
</body>
</html>
29 changes: 25 additions & 4 deletions src/styles/iconfont.css
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
@font-face {
font-family: 'iconfont'; /* Project id 4528205 */
font-family: 'iconfont';
/* Project id 4528205 */
src:
url('/fonts/iconfont.woff2?t=1715047888381') format('woff2'),
url('/fonts/iconfont.woff?t=1715047888381') format('woff'),
url('/fonts/iconfont.ttf?t=1715047888381') format('truetype');
url('/fonts/iconfont.woff2?t=1716210197380') format('woff2'),
url('/fonts/iconfont.woff?t=1716210197380') format('woff'),
url('/fonts/iconfont.ttf?t=1716210197380') format('truetype');
}

.iconfont {
Expand All @@ -13,6 +14,26 @@
-moz-osx-font-smoothing: grayscale;
}

.icon-alert:before {
content: '\e83a';
}

.icon-check:before {
content: '\e847';
}

.icon-error:before {
content: '\e854';
}

.icon-info:before {
content: '\e85f';
}

.icon-close:before {
content: '\e84a';
}

.icon-user-heart:before {
content: '\e88c';
}
Expand Down

0 comments on commit 6aadea0

Please sign in to comment.