This commit is contained in:
Shubhankar45
2026-11-13 12:14:55 +00:00
commit 53dbfa976b
191 changed files with 12074 additions and 0 deletions
+131
View File
@@ -0,0 +1,131 @@
import { useEffect, useMemo, useState } from 'react'
import { Link } from 'react-router-dom'
import { AnimatePresence, motion } from 'framer-motion'
import homeImg from '../assets/images/usecase-home.webp'
import businessImg from '../assets/images/usecase-business.webp'
import farmImg from '../assets/images/usecase-farm.webp'
import { ArrowButton, Tag } from '../components/ui'
import { useContent } from '../context/ContentContext'
import api from '../services/api'
const DESIGN_IMAGES = [homeImg, businessImg, farmImg]
/**
* "Powering Homes, Businesses & Beyond" — 3-page slider from the Figma "Use case section".
* Published services from the admin dashboard replace the design slides when they exist.
*/
export default function Solutions() {
const c = useContent('solutions')
const [services, setServices] = useState(null)
const [index, setIndex] = useState(0)
useEffect(() => {
api.get('/services').then((r) => setServices(r.data)).catch(() => setServices([]))
}, [])
const slides = useMemo(() => {
if (services?.length) {
return services.map((s, i) => {
const m = /^solar for (.+)$/i.exec(s.title)
return {
key: `svc-${s.id}`,
prefix: m ? s.title.slice(0, s.title.length - m[1].length) : '',
highlight: m ? m[1] : s.title,
text: s.description || s.short_description || '',
image: s.image_url || DESIGN_IMAGES[i % DESIGN_IMAGES.length],
thumb: s.thumbnail_url || s.image_url || DESIGN_IMAGES[i % DESIGN_IMAGES.length],
link: '/projects',
}
})
}
return c.slides.map((s, i) => ({
key: `design-${i}`,
...s,
image: DESIGN_IMAGES[i % DESIGN_IMAGES.length],
thumb: DESIGN_IMAGES[i % DESIGN_IMAGES.length],
link: s.category ? `/projects?category=${s.category}` : '/projects',
}))
}, [services, c.slides])
const count = slides.length
const current = slides[Math.min(index, count - 1)] || slides[0]
const go = (d) => setIndex((i) => (i + d + count) % count)
return (
<section id="solutions" className="bg-white py-16 lg:py-20" aria-roledescription="carousel" aria-label="Solar solutions">
<div className="container-site flex flex-col gap-10 lg:flex-row lg:items-center">
{/* gallery: thumbnails + main image (640 wide in Figma) */}
<div className="flex w-full gap-4 sm:gap-6 lg:w-[640px] lg:shrink-0">
<div className="hidden w-[160px] shrink-0 flex-col gap-4 sm:flex">
{slides.slice(0, 3).map((s, i) => (
<button
key={s.key}
type="button"
onClick={() => setIndex(i)}
className="relative h-[142px] overflow-hidden rounded-[12px] bg-slate"
aria-label={`Show ${s.highlight}`}
aria-current={i === index}
>
<img src={s.thumb} alt="" className="size-full object-cover transition duration-500 hover:scale-105" loading="lazy" />
</button>
))}
</div>
<Link
to={current.link}
className="group relative aspect-[456/458] w-full overflow-hidden rounded-[14px] bg-surface sm:h-[458px] sm:aspect-auto lg:w-[456px]"
aria-label={`View ${current.highlight} projects`}
>
<AnimatePresence mode="popLayout" initial={false}>
<motion.img
key={current.key}
src={current.image}
alt={`${current.prefix}${current.highlight}`}
className="absolute inset-0 size-full object-cover transition-transform duration-700 group-hover:scale-[1.03]"
initial={{ opacity: 0 }}
animate={{ opacity: 1 }}
exit={{ opacity: 0 }}
transition={{ duration: 0.45 }}
/>
</AnimatePresence>
<span className="absolute bottom-4 left-4 rounded-full bg-footer/80 px-4 py-2 text-[13px] font-semibold text-white opacity-0 backdrop-blur transition group-hover:opacity-100 group-focus-visible:opacity-100">
View projects →
</span>
</Link>
</div>
{/* copy */}
<div className="flex w-full flex-col justify-between gap-8 lg:min-h-[458px] lg:max-w-[600px]">
<div className="flex flex-col gap-3">
<Tag className="self-start">{c.tag}</Tag>
<div className="flex flex-col gap-6">
<h2 className="h2 text-navy">{c.title}</h2>
<AnimatePresence mode="wait" initial={false}>
<motion.div
key={current.key}
className="flex flex-col gap-4"
initial={{ opacity: 0, y: 8 }}
animate={{ opacity: 1, y: 0 }}
exit={{ opacity: 0, y: -8 }}
transition={{ duration: 0.3 }}
aria-live="polite"
>
<h3 className="text-[22px] leading-8 font-semibold text-navy lg:text-card">
{current.prefix}
<span className="text-green-text">{current.highlight}</span>
</h3>
<p className="text-[16px] leading-6 text-navy">{current.text}</p>
</motion.div>
</AnimatePresence>
</div>
</div>
{count > 1 && (
<div className="flex gap-3">
<ArrowButton direction="left" onClick={() => go(-1)} aria-label="Previous solution" />
<ArrowButton onClick={() => go(1)} aria-label="Next solution" />
</div>
)}
</div>
</div>
</section>
)
}