File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ import { useState , useEffect , useRef } from "react" ;
12import { Campaign } from "../types/campaign" ;
23import { CopyButton } from "./CopyButton" ;
34import { AddressAvatar } from "./AddressAvatar" ;
@@ -13,6 +14,16 @@ export function CampaignCard({
1314 selectedCampaignId,
1415 onSelect,
1516} : CampaignCardProps ) {
17+ const prevPercentRef = useRef < number | null > ( null ) ;
18+ const [ animate , setAnimate ] = useState ( false ) ;
19+
20+ useEffect ( ( ) => {
21+ if ( prevPercentRef . current !== null && prevPercentRef . current !== campaign . progress . percentFunded ) {
22+ setAnimate ( true ) ;
23+ }
24+ prevPercentRef . current = campaign . progress . percentFunded ;
25+ } , [ campaign . progress . percentFunded ] ) ;
26+
1627 const formatTimestamp = ( unixSeconds : number ) =>
1728 new Date ( unixSeconds * 1000 ) . toLocaleString ( ) ;
1829
@@ -47,6 +58,7 @@ export function CampaignCard({
4758 </ div >
4859 < div className = "progress-bar" aria-hidden >
4960 < div
61+ className = { animate ? "progress-bar-fill" : undefined }
5062 style = { {
5163 width : `${ Math . min ( campaign . progress . percentFunded , 100 ) } %` ,
5264 } }
Original file line number Diff line number Diff line change @@ -1234,6 +1234,10 @@ tbody tr:hover td {
12341234 background : linear-gradient (90deg , var (--primary ), # 22c55e );
12351235}
12361236
1237+ .progress-bar-fill {
1238+ transition : width 0.4s cubic-bezier (0.4 , 0 , 0.2 , 1 );
1239+ }
1240+
12371241.badge ,
12381242.chip ,
12391243.chip-emphasis {
Original file line number Diff line number Diff line change 1+ ## Summary
2+
3+ - Smoothly animates the campaign progress bar when funding percentage changes after a pledge
4+ - Uses 0.4s cubic-bezier transition for responsive feel
5+ - Animation only triggers on update, not on initial page load
6+
7+ ## Changes
8+
9+ - ** CampaignCard.tsx** : Added useRef to track previous percent and useState to conditionally apply animation class after initial render
10+ - ** index.css** : Added ` .progress-bar-fill ` class with CSS transition on width
11+
12+ ## Acceptance criteria
13+
14+ - Progress bar animates on funding percentage change
15+ - Animation duration is short enough to feel responsive
16+ - Animation does not trigger on initial page load
You can’t perform that action at this time.
0 commit comments