Skip to content

Commit ae71088

Browse files
committed
feat: gradient trancing
1 parent 6a3f347 commit ae71088

2 files changed

Lines changed: 52 additions & 12 deletions

File tree

src/components/stateless/GradientTracing/index.tsx

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React from 'react'
2-
import { motion } from 'motion/react'
2+
import { motion } from 'framer-motion'
33

44
interface GradientTracingProps {
55
width: number
@@ -8,6 +8,7 @@ interface GradientTracingProps {
88
gradientColors?: [string, string, string]
99
animationDuration?: number
1010
strokeWidth?: number
11+
path: string
1112
}
1213

1314
const GradientTracing: React.FC<GradientTracingProps> = ({
@@ -17,22 +18,15 @@ const GradientTracing: React.FC<GradientTracingProps> = ({
1718
gradientColors = ['#2EB9DF', '#2EB9DF', '#9E00FF'],
1819
animationDuration = 2,
1920
strokeWidth = 2,
21+
path,
2022
}) => {
2123
const gradientId = `pulse-${Math.random().toString(36).substring(2, 9)}`
2224

2325
return (
2426
<div className="relative" style={{ width, height }}>
2527
<svg width={width} height={height} viewBox={`0 0 ${width} ${height}`} fill="none">
26-
<line x1={0} y1={height / 2} x2={width} y2={height / 2} stroke={baseColor} strokeOpacity="0.2" />
27-
<line
28-
x1={0}
29-
y1={height / 2}
30-
x2={width}
31-
y2={height / 2}
32-
stroke={`url(#${gradientId})`}
33-
strokeLinecap="round"
34-
strokeWidth={strokeWidth}
35-
/>
28+
<path d={path} stroke={baseColor} strokeOpacity="0.2" />
29+
<path d={path} stroke={`url(#${gradientId})`} strokeLinecap="round" strokeWidth={strokeWidth} />
3630
<defs>
3731
<motion.linearGradient
3832
animate={{

src/pages/demo/index.jsx

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,8 +144,54 @@ const ProDemo = () => {
144144
path="M100,100 m0,-75 a75,75 0 1,1 -0.1,0 z"
145145
gradientColors={['#7B68EE', '#7B68EE', '#3498DB']}
146146
/>
147+
<GradientTracing width={300} height={100} path="M0,50 L75,25 L150,75 L225,25 L300,50" />
148+
</section>
149+
<section className="flex flex-row items-center justify-center gap-5">
150+
<GradientTracing
151+
width={200}
152+
height={50}
153+
path="M 20,25 L 180,25"
154+
gradientColors={['#FF5733', '#FF5733', '#C70039']}
155+
/>
156+
<GradientTracing
157+
width={250}
158+
height={200}
159+
path="M 50,20 L 50,120 L 50,60 L 200,60"
160+
gradientColors={['#FFA07A', '#FFA07A', '#FF6347']}
161+
/>
162+
<GradientTracing
163+
width={200}
164+
height={200}
165+
path="M 20,20 L 180,180"
166+
gradientColors={['#5733FF', '#5733FF', '#C700C7']}
167+
/>
168+
</section>
169+
<section className="flex flex-row items-center justify-center gap-5">
170+
<GradientTracing
171+
width={200}
172+
height={200}
173+
path="M 20,20 L 20,120 L 170,120"
174+
gradientColors={['#FF69B4', '#FF69B4', '#8A2BE2']}
175+
/>
176+
<GradientTracing
177+
width={200}
178+
height={200}
179+
path="M 150,20 L 150,120 L 20,120"
180+
gradientColors={['#FF1493', '#FF1493', '#9400D3']}
181+
/>
182+
<GradientTracing
183+
width={200}
184+
height={200}
185+
path="M 20,180 L 20,80 L 170,80"
186+
gradientColors={['#FFA500', '#FFA500', '#FF4500']}
187+
/>
188+
<GradientTracing
189+
width={200}
190+
height={200}
191+
path="M 180,180 L 180,80 L 30,80"
192+
gradientColors={['#00BFFF', '#00BFFF', '#1E90FF']}
193+
/>
147194
</section>
148-
149195
<div className="b relative mx-auto flex h-[20rem] w-full max-w-5xl flex-col items-start justify-start [perspective:1000px]">
150196
<AnimationTabs tabs={tabs} />
151197
</div>

0 commit comments

Comments
 (0)