Skip to content

Commit 674345e

Browse files
committed
feat: new image transition
Signed-off-by: Innei <[email protected]>
1 parent 18d1dc6 commit 674345e

File tree

4 files changed

+33
-18
lines changed

4 files changed

+33
-18
lines changed

src/components/common/ToastCard.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export const ToastCard: FC<{
3131
layoutId={id}
3232
layout="position"
3333
className={clsx(
34-
'relative w-full overflow-hidden rounded-xl shadow-out-sm',
34+
'relative w-full overflow-hidden rounded-xl shadow-md shadow-slate-200 dark:shadow-stone-800',
3535
'my-4 mr-4 px-4 py-5',
3636
'bg-slate-50/90 backdrop-blur-sm dark:bg-neutral-900/90',
3737
'border border-slate-100/80 dark:border-neutral-900/80',
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
.error,
2+
.loading {
3+
@apply opacity-0;
4+
}
5+
6+
.loaded {
7+
animation: zoomIn 500ms ease-in-out forwards;
8+
}
9+
10+
@keyframes zoomIn {
11+
0% {
12+
opacity: 0;
13+
clip-path: inset(5%);
14+
transform: scale(111.11%);
15+
}
16+
100% {
17+
opacity: 1;
18+
clip-path: inset(0);
19+
transform: scale(1);
20+
}
21+
}

src/components/ui/image/ZoomedImage.tsx

+9-17
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import { isServer } from '@tanstack/react-query'
44
import { useCallback, useEffect, useMemo, useRef, useState } from 'react'
5-
import { motion, useAnimationControls } from 'framer-motion'
5+
import { useAnimationControls } from 'framer-motion'
66
import mediumZoom from 'medium-zoom'
77
import { tv } from 'tailwind-variants'
88
import type { Zoom } from 'medium-zoom'
@@ -16,6 +16,7 @@ import { useMarkdownImageRecord } from '~/providers/article/markdown-image-recor
1616
import { clsxm } from '~/utils/helper'
1717

1818
import { Divider } from '../divider'
19+
import imageStyles from './ZoomedImage.module.css'
1920

2021
type TImageProps = {
2122
src: string
@@ -109,33 +110,24 @@ export const ImageLazy: Component<TImageProps & BaseImageProps> = ({
109110
<span>
110111
{imageLoadStatus !== ImageLoadStatus.Loaded && placeholder}
111112
</span>
112-
<motion.img
113-
variants={{
114-
loading: {
115-
opacity: 0,
116-
// filter: 'blur(10px)',
117-
},
118-
loaded: {
119-
opacity: 1,
120-
// filter: 'blur(0px)',
121-
},
122-
}}
123-
initial="loading"
124-
animate={controls}
113+
<img
125114
src={src}
126115
title={title}
127116
alt={alt}
128117
ref={imageRef}
129118
onLoad={() => {
130119
setImageLoadStatusSafe(ImageLoadStatus.Loaded)
131-
requestAnimationFrame(() => {
132-
controls.start('loaded')
133-
})
134120
}}
135121
onError={() => setImageLoadStatusSafe(ImageLoadStatus.Error)}
136122
className={styles({
137123
status: imageLoadStatus,
124+
className: imageStyles[ImageLoadStatus.Loaded],
138125
})}
126+
onAnimationEnd={(e) => {
127+
if (ImageLoadStatus.Loaded) {
128+
(e.target as HTMLElement).classList.remove(imageStyles[ImageLoadStatus.Loaded])
129+
}
130+
}}
139131
/>
140132
</span>
141133

src/providers/root/index.tsx

+2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
'use client'
22

33
import { ReactQueryProvider } from './react-query-provider'
4+
import { Provider as BalancerProvider } from 'react-wrap-balancer'
45
import { ThemeProvider } from 'next-themes'
56
import type { PropsWithChildren } from 'react'
67

@@ -24,6 +25,7 @@ const contexts: JSX.Element[] = [
2425

2526
<PageScrollInfoProvider key="PageScrollInfoProvider" />,
2627
<DebugProvider key="debugProvider" />,
28+
<BalancerProvider key="balancerProvider" />,
2729
<ModalStackProvider key="modalStackProvider" />,
2830
]
2931
export function Providers({ children }: PropsWithChildren) {

0 commit comments

Comments
 (0)