Skip to content

Commit 0f32dcc

Browse files
authored
feat(Stats): [UI] add hover to display full text on stats cards (#583)
* feat(Stats): [UI] add hover to display full text on stats cards * fix on mobile view
1 parent d5097bb commit 0f32dcc

File tree

1 file changed

+38
-20
lines changed

1 file changed

+38
-20
lines changed

src/components/Stats.tsx

Lines changed: 38 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { useState } from 'react';
12
import { motion } from 'framer-motion';
23
import { stats, statisticsData } from '@/constants/Stats.ts';
34
import {
@@ -9,6 +10,8 @@ import {
910
} from '@/styles/Animations';
1011

1112
const Stats = () => {
13+
const [activeCardIndex, setActiveCardIndex] = useState<number | null>(null);
14+
1215
return (
1316
<section className="max-w-7xl mx-auto py-10 sm:py-16 md:py-20 px-4 sm:px-6 bg-white dark:bg-gray-900">
1417
<div className="relative mb-12 sm:mb-16 md:mb-24">
@@ -205,27 +208,42 @@ const Stats = () => {
205208

206209
{/* Interactive Stats Summary - Grid Layout */}
207210
<div className="grid grid-cols-2 sm:grid-cols-3 lg:grid-cols-6 gap-2 sm:gap-3 md:gap-4 max-w-6xl mx-auto px-2">
208-
{statisticsData.map((stat, index) => (
209-
<motion.div
210-
key={index}
211-
className={`px-2 sm:px-3 md:px-4 py-2 sm:py-3 rounded-md sm:rounded-lg ${stat.bgColor} border ${stat.borderColor} flex flex-col items-center justify-center`}
212-
whileHover={{
213-
scale: 1.05,
214-
boxShadow: '0 4px 12px rgba(0,0,0,0.1)',
215-
}}
216-
transition={{ type: 'spring', stiffness: 400, damping: 10 }}
217-
>
218-
<span
219-
className={`font-bold text-transparent bg-clip-text bg-gradient-to-r ${stat.gradient} text-base sm:text-xl md:text-2xl`}
211+
{statisticsData.map((stat, index) => {
212+
const isActive = activeCardIndex === index;
213+
const showFullText = isActive;
214+
215+
return (
216+
<motion.div
217+
key={index}
218+
className={`px-2 sm:px-3 md:px-4 py-2 sm:py-3 rounded-md sm:rounded-lg ${stat.bgColor} border ${stat.borderColor} flex flex-col items-center justify-center relative group cursor-pointer`}
219+
whileHover={{
220+
scale: 1.05,
221+
boxShadow: '0 4px 12px rgba(0,0,0,0.1)',
222+
}}
223+
transition={{ type: 'spring', stiffness: 400, damping: 10 }}
224+
onClick={() => setActiveCardIndex(isActive ? null : index)}
220225
>
221-
{stat.value}
222-
</span>
223-
<span className="text-gray-700 dark:text-gray-300 text-2xs sm:text-xs md:text-sm text-center mt-0.5 sm:mt-1 line-clamp-1">
224-
{stat.title.split('.')[0].substring(0, 12)}
225-
{stat.title.split('.')[0].length > 12 ? '...' : ''}
226-
</span>
227-
</motion.div>
228-
))}
226+
<span
227+
className={`font-bold text-transparent bg-clip-text bg-gradient-to-r ${stat.gradient} text-base sm:text-xl md:text-2xl`}
228+
>
229+
{stat.value}
230+
</span>
231+
{/* Truncated text - visible by default, hidden on hover (desktop) or when active (mobile) */}
232+
<span
233+
className={`text-gray-700 dark:text-gray-300 text-2xs sm:text-xs md:text-sm text-center mt-0.5 sm:mt-1 line-clamp-1 ${showFullText ? 'hidden' : ''} lg:block lg:group-hover:hidden`}
234+
>
235+
{stat.title.split('.')[0].substring(0, 12)}
236+
{stat.title.split('.')[0].length > 12 ? '...' : ''}
237+
</span>
238+
{/* Full text - visible on hover (desktop) or when active (mobile) */}
239+
<span
240+
className={`text-gray-700 dark:text-gray-300 text-2xs sm:text-xs md:text-sm text-center mt-0.5 sm:mt-1 whitespace-normal px-1 ${showFullText ? 'block' : 'hidden'} lg:hidden lg:group-hover:block`}
241+
>
242+
{stat.title}
243+
</span>
244+
</motion.div>
245+
);
246+
})}
229247
</div>
230248
</motion.div>
231249
</section>

0 commit comments

Comments
 (0)