Spinning Text

Texte dispose en cercle qui tourne en continu. Installez Spinning Text depuis le registre VLLNT UI avec la CLI shadcn.

Signaler un bug

Texte dispose en cercle qui tourne en continu. Fait partie de la famille content dans VLLNT UI, il est publie comme entree de registre lisible par machine — copiez la source directement dans votre application avec la CLI shadcn et possedez-la, sans dependance d'execution a une bibliotheque de composants.

Apercu

Basculez entre clair et sombre pour inspecter l'apercu Storybook integre.

Installation

Ajoutez Spinning Text a votre projet avec la CLI shadcn. La source arrive dans votre code, prete a etre adaptee :

pnpm dlx shadcn@latest add https://ui.vllnt.ai/r/spinning-text.json

Source

import * as React from "react"; import { cn } from "../../lib/utils"; /** Props for {@link SpinningText}. */ export type SpinningTextProps = React.ComponentPropsWithoutRef<"div"> & { /** Text laid out around the ring. */ children: string; /** Seconds for one full revolution. Defaults to `20`. */ duration?: number; /** Radius of the text ring in pixels. Defaults to `80`. */ radius?: number; /** Spin counter-clockwise when true. Defaults to `false`. */ reverse?: boolean; }; function splitCharacters(value: string): string[] { return value.match(/[\s\S]/gu) ?? []; } function characterStyle( index: number, total: number, radius: number, ): React.CSSProperties { return { left: "50%", position: "absolute", top: "50%", transform: `rotate(${(360 / total) * index}deg) translateY(${-radius}px)`, transformOrigin: "0 0", }; } /** * Lays a string evenly around a circle and rotates the ring on a loop. * * Respects `prefers-reduced-motion`: the layout holds but the spin stops. * * @example * ```tsx * <SpinningText>vllnt design system</SpinningText> * ``` */ export const SpinningText = ({ children, className, duration = 20, radius = 80, ref, reverse = false, style, ...props }: SpinningTextProps & { ref?: React.Ref<HTMLDivElement> }) => { const characters = splitCharacters(children); return ( <div aria-label={children} className={cn( "relative animate-spin motion-reduce:animate-none", className, )} ref={ref} style={{ animationDirection: reverse ? "reverse" : "normal", animationDuration: `${duration}s`, height: radius * 2, width: radius * 2, ...style, }} {...props} > {characters.map((character, index) => ( <span aria-hidden="true" key={`${character}-${index.toString()}`} style={characterStyle(index, characters.length, radius)} > {character} </span> ))} </div> ); }; SpinningText.displayName = "SpinningText";

Stories

Explorez chaque variante et etat dans le Storybook interactif :

Apercu

Basculez entre clair et sombre pour inspecter l'apercu Storybook integre.

Dependances

  • @vllnt/ui@^0.3.0