feat: add basic headline and testimonials components
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
"use client";
|
||||
|
||||
import { useEffect, useState } from "react";
|
||||
|
||||
type RotatingHeadlineProps = {
|
||||
items: string[];
|
||||
subtext: string;
|
||||
intervalSeconds?: number;
|
||||
};
|
||||
|
||||
export default function RotatingHeadline({
|
||||
items,
|
||||
subtext,
|
||||
intervalSeconds = 3,
|
||||
}: RotatingHeadlineProps) {
|
||||
const [activeIndex, setActiveIndex] = useState(0);
|
||||
|
||||
useEffect(() => {
|
||||
if (items.length <= 1) return;
|
||||
|
||||
const id = setInterval(() => {
|
||||
setActiveIndex((i) => (i + 1) % items.length);
|
||||
}, intervalSeconds * 1000);
|
||||
|
||||
return () => clearInterval(id);
|
||||
}, [items.length, intervalSeconds]);
|
||||
|
||||
return (
|
||||
<div className="space-y-2">
|
||||
{/* rotating row — key forces remount so a CSS transition can fire */}
|
||||
<div className="text-2xl">
|
||||
<span key={activeIndex}>{items[activeIndex]}</span>
|
||||
</div>
|
||||
|
||||
{/* static row */}
|
||||
<div className="text-neutral-400">{subtext}</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
"use client";
|
||||
|
||||
import { useState } from "react";
|
||||
|
||||
type Testimonial = {
|
||||
name: string;
|
||||
title: string;
|
||||
avatar?: string;
|
||||
quote: string;
|
||||
};
|
||||
|
||||
type TestimonialsProps = {
|
||||
items: Testimonial[];
|
||||
};
|
||||
|
||||
export default function Testimonials({ items }: TestimonialsProps) {
|
||||
const [activeIndex, setActiveIndex] = useState(0);
|
||||
const active = items[activeIndex];
|
||||
|
||||
if (!active) return null;
|
||||
|
||||
return (
|
||||
<section className="w-full">
|
||||
{/* header: avatar + name + title */}
|
||||
<header className="flex items-center gap-3">
|
||||
{/* TODO: avatar */}
|
||||
<div>
|
||||
<div>{active.name}</div>
|
||||
<div>{active.title}</div>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
{/* quote */}
|
||||
<blockquote>{active.quote}</blockquote>
|
||||
|
||||
{/* controls: pagination dots + play/pause */}
|
||||
<footer className="flex items-center justify-between">
|
||||
<div className="flex gap-2">
|
||||
{items.map((_, i) => (
|
||||
<button
|
||||
key={i}
|
||||
onClick={() => setActiveIndex(i)}
|
||||
aria-label={`Go to testimonial ${i + 1}`}
|
||||
>
|
||||
{/* TODO: dot styling */}
|
||||
{i === activeIndex ? "●" : "○"}
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
|
||||
{/* TODO: play/pause button + auto-rotate timer */}
|
||||
<button aria-label="Pause">⏸</button>
|
||||
</footer>
|
||||
</section>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user