Testimonial Orbit
NewCustomize
Interval5000ms
Speed6°/s
Size520px
Installation
npx shadcn@latest add https://uibrik.com/r/testimonial-orbit.jsonInstall the packages
npm install motion react-use-measureAdd the cn helper
Imports
cnfrom@/lib/utils, whichshadcn initcreates. Add it by hand without shadcn.Copy the source into your project
components/uibrik/testimonial-orbit/testimonial-orbit.tsx"use client"; import { useEffect, useLayoutEffect, useRef, useState, type KeyboardEvent } from "react"; import { motion, useAnimationFrame, useMotionValue, useReducedMotion, useTransform, type MotionValue } from "motion/react"; import useMeasure from "react-use-measure"; import { cn } from "@/lib/utils"; // Testimonial orbit. The people on a slow ring, the quote of one of them in // the middle. Picking a face (or autoplay stepping on) flies that photo out // of the ring into the middle while the quote cross-fades; the seat it left // stays marked by a faint dashed circle until the next person is picked. // // The ring is one rotating layer whose photos counter-rotate by the same // amount, so faces stay upright. Its speed eases toward a target every frame, // so pointing at it brings it to a stop without a jump. The flight is a // single transform on the middle photo, played from wherever the picked photo // is on screen at that moment, so it is correct mid-turn. // // Narrow containers have no room for a quote inside a ring, so there the // people sit still on an arch with the quote underneath. export type Testimonial = { quote: string; name: string;
Adds the files to
components/uibrik/testimonial-orbit and installs motion and react-use-measure. With the @uibrik namespace set up: npx shadcn@latest add @uibrik/testimonial-orbit.Usage
import { TestimonialOrbit } from "@/components/uibrik/testimonial-orbit/testimonial-orbit";<TestimonialOrbit autoplay interval={5000} speed={6} size={520} guide defaultValue={0} label="Testimonials" // testimonials={[{ quote: "…", name: "…", avatar: "…" }]} // value={0} // onChange={(index) => {}}/>Props
TestimonialOrbit- autoplay
- Type boolean
- true
- Step to the next person on its own. Holds while the pointer or focus is inside, and off screen.
- interval
- Type number
- 5000
- Time on each quote with autoplay.
- speed
- Type number
- 6
- How fast the ring turns. 0 holds it still. Eases to a stop while pointed at.
- size
- Type number
- 520
- Height of the orbit. The width fills the container up to the same size.
- guide
- Type boolean
- true
- Draw the ring line.
- testimonials
- Type { quote: string; name: string; role?: string; avatar: string }[]
- SAMPLE_TESTIMONIALS
- The people on the ring, in order.
- value / onChange
- Type number / (index) => void
- –
- Controlled quote in the middle.
- defaultValue
- Type number
- 0
- Quote in the middle to begin with.
- label
- Type string
- "Testimonials"
- Names the group for screen readers.
- className
- Type string
- –
- Classes for the wrapper.